cleanup and formating

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@261 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2006-01-03 01:17:59 +00:00
parent 900c08571b
commit bedcabb8ec
20 changed files with 1075 additions and 1167 deletions

View File

@ -75,8 +75,8 @@ extern "C" {
if (!(jrtp4c->session = new JRTP4C)) { if (!(jrtp4c->session = new JRTP4C)) {
*err = "Memory Error!\n"; *err = "Memory Error!\n";
delete jrtp4c->transparams; delete jrtp4c->transparams;
delete jrtp4c; delete jrtp4c;
return NULL; return NULL;
} }
if ((status = jrtp4c->session->Create(sessparams, jrtp4c->transparams)) < 0) { if ((status = jrtp4c->session->Create(sessparams, jrtp4c->transparams)) < 0) {

View File

@ -76,14 +76,14 @@ static switch_status switch_gsm_destroy(switch_codec *codec)
static switch_status switch_gsm_encode(switch_codec *codec, static switch_status switch_gsm_encode(switch_codec *codec,
switch_codec *other_codec, switch_codec *other_codec,
void *decoded_data, void *decoded_data,
size_t decoded_data_len, size_t decoded_data_len,
int decoded_rate, int decoded_rate,
void *encoded_data, void *encoded_data,
size_t *encoded_data_len, size_t *encoded_data_len,
int *encoded_rate, int *encoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
struct gsm_context *context = codec->private; struct gsm_context *context = codec->private;
int cbret = 0; int cbret = 0;
@ -116,14 +116,14 @@ static switch_status switch_gsm_encode(switch_codec *codec,
static switch_status switch_gsm_decode(switch_codec *codec, static switch_status switch_gsm_decode(switch_codec *codec,
switch_codec *other_codec, switch_codec *other_codec,
void *encoded_data, void *encoded_data,
size_t encoded_data_len, size_t encoded_data_len,
int encoded_rate, int encoded_rate,
void *decoded_data, void *decoded_data,
size_t *decoded_data_len, size_t *decoded_data_len,
int *decoded_rate, int *decoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
struct gsm_context *context = codec->private; struct gsm_context *context = codec->private;
@ -140,7 +140,7 @@ static switch_status switch_gsm_decode(switch_codec *codec,
unsigned int new_len = 0; unsigned int new_len = 0;
for(x = 0; x < loops && new_len < *decoded_data_len; x++) { for(x = 0; x < loops && new_len < *decoded_data_len; x++) {
gsm_decode(context->decoder, edp, ddp); gsm_decode(context->decoder, edp, ddp);
ddp += 160; ddp += 160;
edp += 33; edp += 33;
new_len += 320; new_len += 320;
} }

View File

@ -61,12 +61,12 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj)
switch_channel_state b_state = switch_channel_get_state(chan_b); switch_channel_state b_state = switch_channel_get_state(chan_b);
switch (b_state) { switch (b_state) {
case CS_HANGUP: case CS_HANGUP:
data->running = -1; data->running = -1;
continue; continue;
break; break;
default: default:
break; break;
} }
if (switch_channel_has_dtmf(chan_a)) { if (switch_channel_has_dtmf(chan_a)) {
@ -137,7 +137,7 @@ static const switch_event_handler_table audio_bridge_peer_event_handlers = {
/*.on_init*/ NULL, /*.on_init*/ NULL,
/*.on_ring*/ audio_bridge_on_ring, /*.on_ring*/ audio_bridge_on_ring,
/*.on_execute*/ NULL, /*.on_execute*/ NULL,
/*.on_hangup*/ audio_bridge_on_hangup, /*.on_hangup*/ audio_bridge_on_hangup,
/*.on_loopback*/ NULL, /*.on_loopback*/ NULL,
/*.on_transmit*/ NULL /*.on_transmit*/ NULL
}; };
@ -146,7 +146,7 @@ static const switch_event_handler_table audio_bridge_caller_event_handlers = {
/*.on_init*/ NULL, /*.on_init*/ NULL,
/*.on_ring*/ NULL, /*.on_ring*/ NULL,
/*.on_execute*/ NULL, /*.on_execute*/ NULL,
/*.on_hangup*/ audio_bridge_on_hangup, /*.on_hangup*/ audio_bridge_on_hangup,
/*.on_loopback*/ NULL, /*.on_loopback*/ NULL,
/*.on_transmit*/ NULL /*.on_transmit*/ NULL
}; };
@ -171,13 +171,13 @@ static void audio_bridge_function(switch_core_session *session, char *data)
caller_caller_profile = switch_channel_get_caller_profile(caller_channel); caller_caller_profile = switch_channel_get_caller_profile(caller_channel);
caller_profile = switch_caller_profile_new(session, caller_profile = switch_caller_profile_new(session,
caller_caller_profile->dialplan, caller_caller_profile->dialplan,
caller_caller_profile->caller_id_name, caller_caller_profile->caller_id_name,
caller_caller_profile->caller_id_number, caller_caller_profile->caller_id_number,
caller_caller_profile->network_addr, caller_caller_profile->network_addr,
NULL, NULL,
NULL, NULL,
chan_data); chan_data);
@ -217,10 +217,10 @@ static void audio_bridge_function(switch_core_session *session, char *data)
time(&start); time(&start);
while(switch_channel_get_state(caller_channel) == CS_EXECUTE && while(switch_channel_get_state(caller_channel) == CS_EXECUTE &&
switch_channel_get_state(peer_channel) == CS_TRANSMIT && switch_channel_get_state(peer_channel) == CS_TRANSMIT &&
!switch_channel_test_flag(peer_channel, CF_ANSWERED) && !switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
((time(NULL) - start) < timelimit)) { ((time(NULL) - start) < timelimit)) {
switch_yield(20000); switch_yield(20000);
} }
if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) { if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) {

View File

@ -71,14 +71,14 @@ static switch_status switch_g729_destroy(switch_codec *codec)
static switch_status switch_g729_encode(switch_codec *codec, static switch_status switch_g729_encode(switch_codec *codec,
switch_codec *other_codec, switch_codec *other_codec,
void *decoded_data, void *decoded_data,
size_t decoded_data_len, size_t decoded_data_len,
int decoded_rate, int decoded_rate,
void *encoded_data, void *encoded_data,
size_t *encoded_data_len, size_t *encoded_data_len,
int *encoded_rate, int *encoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
struct g729_context *context = codec->private; struct g729_context *context = codec->private;
int cbret = 0; int cbret = 0;
@ -111,14 +111,14 @@ static switch_status switch_g729_encode(switch_codec *codec,
static switch_status switch_g729_decode(switch_codec *codec, static switch_status switch_g729_decode(switch_codec *codec,
switch_codec *other_codec, switch_codec *other_codec,
void *encoded_data, void *encoded_data,
size_t encoded_data_len, size_t encoded_data_len,
int encoded_rate, int encoded_rate,
void *decoded_data, void *decoded_data,
size_t *decoded_data_len, size_t *decoded_data_len,
int *decoded_rate, int *decoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
struct g729_context *context = codec->private; struct g729_context *context = codec->private;

View File

@ -122,7 +122,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul
/* indicate that the module should continue to be loaded */ /* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }

View File

@ -30,7 +30,6 @@
* *
*/ */
#define HAVE_APR #define HAVE_APR
#include <switch.h> #include <switch.h>
#include <jrtp4c.h> #include <jrtp4c.h>
@ -191,25 +190,25 @@ static int sdp_add_codec(struct osip_rfc3264 *cnf, int codec_type, int payload,
} }
switch (codec_type) { switch (codec_type) {
case SWITCH_CODEC_TYPE_AUDIO: case SWITCH_CODEC_TYPE_AUDIO:
med->m_media = osip_strdup("audio"); med->m_media = osip_strdup("audio");
osip_rfc3264_add_audio_media(cnf, med, -1); osip_rfc3264_add_audio_media(cnf, med, -1);
break; break;
case SWITCH_CODEC_TYPE_VIDEO: case SWITCH_CODEC_TYPE_VIDEO:
med->m_media = osip_strdup("video"); med->m_media = osip_strdup("video");
osip_rfc3264_add_video_media(cnf, med, -1); osip_rfc3264_add_video_media(cnf, med, -1);
break; break;
default: default:
break; break;
} }
return 0; return 0;
} }
/* /*
State methods they get called when the state changes to the specific state State methods they get called when the state changes to the specific state
returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it. so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
*/ */
static switch_status exosip_on_init(switch_core_session *session) static switch_status exosip_on_init(switch_core_session *session)
{ {
@ -454,25 +453,25 @@ static void activate_rtp(struct private_object *tech_pvt)
} }
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activating RTP %s:%d->%s:%d codec: %d ms: %d\n", switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activating RTP %s:%d->%s:%d codec: %d ms: %d\n",
tech_pvt->local_sdp_audio_ip, tech_pvt->local_sdp_audio_ip,
tech_pvt->local_sdp_audio_port, tech_pvt->local_sdp_audio_port,
tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip,
tech_pvt->remote_sdp_audio_port, tech_pvt->remote_sdp_audio_port,
tech_pvt->read_codec.codec_interface->ianacode, tech_pvt->read_codec.codec_interface->ianacode,
ms ms
); );
tech_pvt->rtp_session = jrtp4c_new( tech_pvt->rtp_session = jrtp4c_new(
tech_pvt->local_sdp_audio_ip, tech_pvt->local_sdp_audio_ip,
tech_pvt->local_sdp_audio_port, tech_pvt->local_sdp_audio_port,
tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip,
tech_pvt->remote_sdp_audio_port, tech_pvt->remote_sdp_audio_port,
tech_pvt->read_codec.codec_interface->ianacode, tech_pvt->read_codec.codec_interface->ianacode,
tech_pvt->read_codec.implementation->samples_per_second, tech_pvt->read_codec.implementation->samples_per_second,
&err); &err);
if (tech_pvt->rtp_session) { if (tech_pvt->rtp_session) {
tech_pvt->ssrc = jrtp4c_get_ssrc(tech_pvt->rtp_session); tech_pvt->ssrc = jrtp4c_get_ssrc(tech_pvt->rtp_session);
@ -555,8 +554,8 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
while(!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) { while(!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) {
tech_pvt->read_frame.datalen = jrtp4c_read(tech_pvt->rtp_session, tech_pvt->read_frame.datalen = jrtp4c_read(tech_pvt->rtp_session,
tech_pvt->read_frame.data, tech_pvt->read_frame.data,
sizeof(tech_pvt->read_buf)); sizeof(tech_pvt->read_buf));
if (tech_pvt->read_frame.datalen > 0) { if (tech_pvt->read_frame.datalen > 0) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame; bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
@ -794,14 +793,14 @@ static switch_status exosip_create_call(eXosip_event_t *event)
} }
if ((tech_pvt->caller_profile = switch_caller_profile_new(session, if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
globals.dialplan, globals.dialplan,
event->request->from->displayname, event->request->from->displayname,
event->request->from->url->username, event->request->from->url->username,
event->request->from->url->host, event->request->from->url->host,
NULL, NULL,
NULL, NULL,
event->request->req_uri->username))) { event->request->req_uri->username))) {
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
} }
switch_set_flag(tech_pvt, TFLAG_INBOUND); switch_set_flag(tech_pvt, TFLAG_INBOUND);
@ -887,28 +886,28 @@ static switch_status exosip_create_call(eXosip_event_t *event)
int rate = atoi(drate); int rate = atoi(drate);
if (switch_core_codec_init(&tech_pvt->read_codec, if (switch_core_codec_init(&tech_pvt->read_codec,
dname, dname,
rate, rate,
globals.codec_ms, globals.codec_ms,
1, 1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
} else {
if (switch_core_codec_init(&tech_pvt->write_codec,
dname,
rate,
globals.codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel); switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} else {
if (switch_core_codec_init(&tech_pvt->write_codec,
dname,
rate,
globals.codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
} else { } else {
int ms; int ms;
tech_pvt->read_frame.rate = rate; tech_pvt->read_frame.rate = rate;
@ -1052,28 +1051,28 @@ static void handle_answer(eXosip_event_t *event)
if (switch_core_codec_init(&tech_pvt->read_codec, if (switch_core_codec_init(&tech_pvt->read_codec,
dname, dname,
rate, rate,
globals.codec_ms, globals.codec_ms,
1, 1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, NULL,
switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return;
} else {
if (switch_core_codec_init(&tech_pvt->write_codec,
dname,
rate,
globals.codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
NULL,
switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel); switch_channel_hangup(channel);
return; return;
} else {
if (switch_core_codec_init(&tech_pvt->write_codec,
dname,
rate,
globals.codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
NULL,
switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return;
} else { } else {
int ms; int ms;
tech_pvt->read_frame.rate = rate; tech_pvt->read_frame.rate = rate;
@ -1119,78 +1118,78 @@ static void log_event(eXosip_event_t *je)
} else if (je->type == EXOSIP_CALL_RELEASED) { } else if (je->type == EXOSIP_CALL_RELEASED) {
snprintf (buf, 99, "<- (%i %i) Call released", je->cid, je->did); snprintf (buf, 99, "<- (%i %i) Call released", je->cid, je->did);
} else if (je->type == EXOSIP_MESSAGE_NEW } else if (je->type == EXOSIP_MESSAGE_NEW
&& je->request!=NULL && MSG_IS_MESSAGE(je->request)) { && je->request!=NULL && MSG_IS_MESSAGE(je->request)) {
char *tmp = NULL; char *tmp = NULL;
if (je->request != NULL) { if (je->request != NULL) {
osip_body_t *body; osip_body_t *body;
osip_from_to_str (je->request->from, &tmp); osip_from_to_str (je->request->from, &tmp);
osip_message_get_body (je->request, 0, &body); osip_message_get_body (je->request, 0, &body);
if (body != NULL && body->body != NULL) { if (body != NULL && body->body != NULL) {
snprintf (buf, 99, "<- (%i) from: %s TEXT: %s", snprintf (buf, 99, "<- (%i) from: %s TEXT: %s",
je->tid, tmp, body->body); je->tid, tmp, body->body);
}
osip_free (tmp);
} else {
snprintf (buf, 99, "<- (%i) New event for unknown request?", je->tid);
} }
osip_free (tmp);
} else {
snprintf (buf, 99, "<- (%i) New event for unknown request?", je->tid);
}
} else if (je->type == EXOSIP_MESSAGE_NEW) { } else if (je->type == EXOSIP_MESSAGE_NEW) {
char *tmp = NULL; char *tmp = NULL;
osip_from_to_str (je->request->from, &tmp); osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (%i) %s from: %s", snprintf (buf, 99, "<- (%i) %s from: %s",
je->tid, je->request->sip_method, tmp); je->tid, je->request->sip_method, tmp);
osip_free (tmp); osip_free (tmp);
} else if (je->type == EXOSIP_MESSAGE_PROCEEDING } else if (je->type == EXOSIP_MESSAGE_PROCEEDING
|| je->type == EXOSIP_MESSAGE_ANSWERED || je->type == EXOSIP_MESSAGE_ANSWERED
|| je->type == EXOSIP_MESSAGE_REDIRECTED || je->type == EXOSIP_MESSAGE_REDIRECTED
|| je->type == EXOSIP_MESSAGE_REQUESTFAILURE || je->type == EXOSIP_MESSAGE_REQUESTFAILURE
|| je->type == EXOSIP_MESSAGE_SERVERFAILURE || je->type == EXOSIP_MESSAGE_SERVERFAILURE
|| je->type == EXOSIP_MESSAGE_GLOBALFAILURE) { || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) {
if (je->response != NULL && je->request != NULL) { if (je->response != NULL && je->request != NULL) {
char *tmp = NULL; char *tmp = NULL;
osip_to_to_str (je->request->to, &tmp); osip_to_to_str (je->request->to, &tmp);
snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s", snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s",
je->tid, je->response->status_code, je->tid, je->response->status_code,
je->response->reason_phrase, je->request->sip_method, tmp); je->response->reason_phrase, je->request->sip_method, tmp);
osip_free (tmp); osip_free (tmp);
} else if (je->request != NULL) { } else if (je->request != NULL) {
snprintf (buf, 99, "<- (%i) Error for %s request", snprintf (buf, 99, "<- (%i) Error for %s request",
je->tid, je->request->sip_method); je->tid, je->request->sip_method);
} else { } else {
snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid); snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid);
} }
} else if (je->response == NULL && je->request != NULL && je->cid > 0) { } else if (je->response == NULL && je->request != NULL && je->cid > 0) {
char *tmp = NULL; char *tmp = NULL;
osip_from_to_str (je->request->from, &tmp); osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (%i %i) %s from: %s", snprintf (buf, 99, "<- (%i %i) %s from: %s",
je->cid, je->did, je->request->cseq->method, tmp); je->cid, je->did, je->request->cseq->method, tmp);
osip_free (tmp); osip_free (tmp);
} else if (je->response != NULL && je->cid > 0) { } else if (je->response != NULL && je->cid > 0) {
char *tmp = NULL; char *tmp = NULL;
osip_to_to_str (je->request->to, &tmp); osip_to_to_str (je->request->to, &tmp);
snprintf (buf, 99, "<- (%i %i) [%i %s] for %s to: %s", snprintf (buf, 99, "<- (%i %i) [%i %s] for %s to: %s",
je->cid, je->did, je->response->status_code, je->cid, je->did, je->response->status_code,
je->response->reason_phrase, je->request->sip_method, tmp); je->response->reason_phrase, je->request->sip_method, tmp);
osip_free (tmp); osip_free (tmp);
} else if (je->response == NULL && je->request != NULL && je->rid > 0) { } else if (je->response == NULL && je->request != NULL && je->rid > 0) {
char *tmp = NULL; char *tmp = NULL;
osip_from_to_str (je->request->from, &tmp); osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (%i) %s from: %s", snprintf (buf, 99, "<- (%i) %s from: %s",
je->rid, je->request->cseq->method, tmp); je->rid, je->request->cseq->method, tmp);
osip_free (tmp); osip_free (tmp);
} else if (je->response != NULL && je->rid > 0) { } else if (je->response != NULL && je->rid > 0) {
char *tmp = NULL; char *tmp = NULL;
osip_from_to_str (je->request->from, &tmp); osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (%i) [%i %s] from: %s", snprintf (buf, 99, "<- (%i) [%i %s] from: %s",
je->rid, je->response->status_code, je->rid, je->response->status_code,
je->response->reason_phrase, tmp); je->response->reason_phrase, tmp);
osip_free (tmp); osip_free (tmp);
} else if (je->response == NULL && je->request != NULL && je->sid > 0) { } else if (je->response == NULL && je->request != NULL && je->sid > 0) {
char *tmp = NULL; char *tmp = NULL;
@ -1198,42 +1197,42 @@ static void log_event(eXosip_event_t *je)
osip_header_t *sub_state; osip_header_t *sub_state;
osip_message_header_get_byname (je->request, "subscription-state", osip_message_header_get_byname (je->request, "subscription-state",
0, &sub_state); 0, &sub_state);
if (sub_state != NULL && sub_state->hvalue != NULL) if (sub_state != NULL && sub_state->hvalue != NULL)
stat = sub_state->hvalue; stat = sub_state->hvalue;
osip_uri_to_str (je->request->from->url, &tmp); osip_uri_to_str (je->request->from->url, &tmp);
snprintf (buf, 99, "<- (%i) [%s] %s from: %s", snprintf (buf, 99, "<- (%i) [%s] %s from: %s",
je->sid, stat, je->request->cseq->method, tmp); je->sid, stat, je->request->cseq->method, tmp);
osip_free (tmp); osip_free (tmp);
} else if (je->response != NULL && je->sid > 0) { } else if (je->response != NULL && je->sid > 0) {
char *tmp = NULL; char *tmp = NULL;
osip_uri_to_str (je->request->to->url, &tmp); osip_uri_to_str (je->request->to->url, &tmp);
snprintf (buf, 99, "<- (%i) [%i %s] from: %s", snprintf (buf, 99, "<- (%i) [%i %s] from: %s",
je->sid, je->response->status_code, je->sid, je->response->status_code,
je->response->reason_phrase, tmp); je->response->reason_phrase, tmp);
osip_free (tmp); osip_free (tmp);
} else if (je->response == NULL && je->request != NULL) { } else if (je->response == NULL && je->request != NULL) {
char *tmp = NULL; char *tmp = NULL;
osip_from_to_str (je->request->from, &tmp); osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s", snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s",
je->cid, je->did, je->sid, je->nid, je->cid, je->did, je->sid, je->nid,
je->request->sip_method, tmp); je->request->sip_method, tmp);
osip_free (tmp); osip_free (tmp);
} else if (je->response != NULL) { } else if (je->response != NULL) {
char *tmp = NULL; char *tmp = NULL;
osip_from_to_str (je->request->from, &tmp); osip_from_to_str (je->request->from, &tmp);
snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s", snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s",
je->cid, je->did, je->sid, je->nid, je->cid, je->did, je->sid, je->nid,
je->response->status_code, je->response->reason_phrase, je->response->status_code, je->response->reason_phrase,
je->request->sip_method, tmp); je->request->sip_method, tmp);
osip_free (tmp); osip_free (tmp);
} else { } else {
snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s", snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s",
je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo); je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo);
} }
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\n%s\n", buf); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\n%s\n", buf);
/* Print it out */ /* Print it out */
@ -1259,64 +1258,64 @@ static void *monitor_thread_run(void)
log_event(event); log_event(event);
switch(event->type) { switch(event->type) {
case EXOSIP_CALL_INVITE: case EXOSIP_CALL_INVITE:
exosip_create_call(event); exosip_create_call(event);
break; break;
case EXOSIP_CALL_REINVITE: case EXOSIP_CALL_REINVITE:
/* See what the reinvite is about - on hold or whatever */ /* See what the reinvite is about - on hold or whatever */
//handle_reinvite(event); //handle_reinvite(event);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got a reinvite.\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got a reinvite.\n");
break; break;
case EXOSIP_CALL_MESSAGE_NEW: case EXOSIP_CALL_MESSAGE_NEW:
if (event->request != NULL && MSG_IS_REFER(event->request)) { if (event->request != NULL && MSG_IS_REFER(event->request)) {
//handle_call_transfer(event); //handle_call_transfer(event);
} }
break; break;
case EXOSIP_CALL_ACK: case EXOSIP_CALL_ACK:
/* If audio is not flowing and this has SDP - fire it up! */ /* If audio is not flowing and this has SDP - fire it up! */
break; break;
case EXOSIP_CALL_ANSWERED: case EXOSIP_CALL_ANSWERED:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was answered.\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was answered.\n");
handle_answer(event); handle_answer(event);
break; break;
case EXOSIP_CALL_PROCEEDING: case EXOSIP_CALL_PROCEEDING:
/* This is like a 100 Trying... yeah */ /* This is like a 100 Trying... yeah */
break; break;
case EXOSIP_CALL_RINGING: case EXOSIP_CALL_RINGING:
//handle_ringing(event); //handle_ringing(event);
break; break;
case EXOSIP_CALL_REDIRECTED: case EXOSIP_CALL_REDIRECTED:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call was redirect\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call was redirect\n");
break; break;
case EXOSIP_CALL_CLOSED: case EXOSIP_CALL_CLOSED:
destroy_call_by_event(event); destroy_call_by_event(event);
break; break;
case EXOSIP_CALL_RELEASED: case EXOSIP_CALL_RELEASED:
destroy_call_by_event(event); destroy_call_by_event(event);
break; break;
case EXOSIP_CALL_NOANSWER: case EXOSIP_CALL_NOANSWER:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was not answered.\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was not answered.\n");
destroy_call_by_event(event); destroy_call_by_event(event);
break; break;
case EXOSIP_CALL_REQUESTFAILURE: case EXOSIP_CALL_REQUESTFAILURE:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Request failure\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Request failure\n");
destroy_call_by_event(event); destroy_call_by_event(event);
break; break;
case EXOSIP_CALL_SERVERFAILURE: case EXOSIP_CALL_SERVERFAILURE:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Server failure\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Server failure\n");
destroy_call_by_event(event); destroy_call_by_event(event);
break; break;
case EXOSIP_CALL_GLOBALFAILURE: case EXOSIP_CALL_GLOBALFAILURE:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Global failure\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Global failure\n");
destroy_call_by_event(event); destroy_call_by_event(event);
break; break;
/* Registration related stuff */ /* Registration related stuff */
case EXOSIP_REGISTRATION_NEW: case EXOSIP_REGISTRATION_NEW:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Received registration attempt\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Received registration attempt\n");
break; break;
default: default:
/* Unknown event... casually absorb it for now */ /* Unknown event... casually absorb it for now */
break; break;
} }
//switch_console_printf(SWITCH_CHANNEL_CONSOLE, "There was an event (%d) [%s]\n", event->type, event->textinfo); //switch_console_printf(SWITCH_CHANNEL_CONSOLE, "There was an event (%d) [%s]\n", event->type, event->textinfo);

View File

@ -52,14 +52,14 @@ static switch_status switch_g711u_init(switch_codec *codec, switch_codec_flag fl
static switch_status switch_g711u_encode(switch_codec *codec, static switch_status switch_g711u_encode(switch_codec *codec,
switch_codec *other_codec, switch_codec *other_codec,
void *decoded_data, void *decoded_data,
size_t decoded_data_len, size_t decoded_data_len,
int decoded_rate, int decoded_rate,
void *encoded_data, void *encoded_data,
size_t *encoded_data_len, size_t *encoded_data_len,
int *encoded_rate, int *encoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
short *dbuf; short *dbuf;
unsigned char *ebuf; unsigned char *ebuf;
@ -78,14 +78,14 @@ static switch_status switch_g711u_encode(switch_codec *codec,
} }
static switch_status switch_g711u_decode(switch_codec *codec, static switch_status switch_g711u_decode(switch_codec *codec,
switch_codec *other_codec, switch_codec *other_codec,
void *encoded_data, void *encoded_data,
size_t encoded_data_len, size_t encoded_data_len,
int encoded_rate, int encoded_rate,
void *decoded_data, void *decoded_data,
size_t *decoded_data_len, size_t *decoded_data_len,
int *decoded_rate, int *decoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
short *dbuf; short *dbuf;
unsigned char *ebuf; unsigned char *ebuf;
@ -130,14 +130,14 @@ static switch_status switch_g711a_init(switch_codec *codec, switch_codec_flag fl
static switch_status switch_g711a_encode(switch_codec *codec, static switch_status switch_g711a_encode(switch_codec *codec,
switch_codec *other_codec, switch_codec *other_codec,
void *decoded_data, void *decoded_data,
size_t decoded_data_len, size_t decoded_data_len,
int decoded_rate, int decoded_rate,
void *encoded_data, void *encoded_data,
size_t *encoded_data_len, size_t *encoded_data_len,
int *encoded_rate, int *encoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
short *dbuf; short *dbuf;
unsigned char *ebuf; unsigned char *ebuf;
@ -156,14 +156,14 @@ static switch_status switch_g711a_encode(switch_codec *codec,
} }
static switch_status switch_g711a_decode(switch_codec *codec, static switch_status switch_g711a_decode(switch_codec *codec,
switch_codec *other_codec, switch_codec *other_codec,
void *encoded_data, void *encoded_data,
size_t encoded_data_len, size_t encoded_data_len,
int encoded_rate, int encoded_rate,
void *decoded_data, void *decoded_data,
size_t *decoded_data_len, size_t *decoded_data_len,
int *decoded_rate, int *decoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
short *dbuf; short *dbuf;
unsigned char *ebuf; unsigned char *ebuf;

View File

@ -75,7 +75,7 @@ static struct {
struct private_object { struct private_object {
unsigned int flags; unsigned int flags;
switch_codec read_codec; switch_codec read_codec;
switch_codec write_codec; switch_codec write_codec;
struct switch_frame read_frame; struct switch_frame read_frame;
unsigned char databuf[1024]; unsigned char databuf[1024];
switch_core_session *session; switch_core_session *session;
@ -174,12 +174,12 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s
if (globals.codec_string) { if (globals.codec_string) {
if (!(num_codecs = loadable_module_get_codecs_sorted(switch_core_session_get_pool(tech_pvt->session), if (!(num_codecs = loadable_module_get_codecs_sorted(switch_core_session_get_pool(tech_pvt->session),
codecs, codecs,
SWITCH_MAX_CODECS, SWITCH_MAX_CODECS,
globals.codec_order, globals.codec_order,
globals.codec_order_last)) > 0) { globals.codec_order_last)) > 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
} else if (!(num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs, SWITCH_MAX_CODECS)) > 0) { } else if (!(num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs, SWITCH_MAX_CODECS)) > 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n");
@ -272,27 +272,27 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s
switch_set_flag(tech_pvt, TFLAG_LINEAR); switch_set_flag(tech_pvt, TFLAG_LINEAR);
} }
if (switch_core_codec_init(&tech_pvt->read_codec, if (switch_core_codec_init(&tech_pvt->read_codec,
dname, dname,
0, 0,
0, 0,
1, 1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, NULL,
switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} else { } else {
if (switch_core_codec_init(&tech_pvt->write_codec, if (switch_core_codec_init(&tech_pvt->write_codec,
dname, dname,
0, 0,
0, 0,
1, 1,
SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
NULL, NULL,
switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_core_codec_destroy(&tech_pvt->read_codec); switch_core_codec_destroy(&tech_pvt->read_codec);
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} else { } else {
int ms; int ms;
int rate; int rate;
@ -344,9 +344,9 @@ static void iax_out_cb(const char *s)
/* /*
State methods they get called when the state changes to the specific state State methods they get called when the state changes to the specific state
returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it. so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
*/ */
static switch_status channel_on_init(switch_core_session *session) static switch_status channel_on_init(switch_core_session *session)
{ {
@ -475,7 +475,7 @@ static switch_status channel_on_transmit(switch_core_session *session)
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines /* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool! that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/ */
static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session) static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session)
{ {
@ -523,10 +523,10 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit
iax_call(tech_pvt->iax_session, iax_call(tech_pvt->iax_session,
caller_profile->caller_id_number, caller_profile->caller_id_number,
caller_profile->caller_id_name, caller_profile->caller_id_name,
caller_profile->destination_number, caller_profile->destination_number,
NULL, 0, req, cap); NULL, 0, req, cap);
switch_channel_set_flag(channel, CF_OUTBOUND); switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND); switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
@ -572,7 +572,7 @@ static switch_status channel_send_dtmf(switch_core_session *session, char *dtmf)
} }
} }
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags) static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags)
@ -776,8 +776,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
} }
iax_set_error(iax_err_cb); iax_set_error(iax_err_cb);
iax_set_output(iax_out_cb); iax_set_output(iax_out_cb);
netfd = iax_get_fd(); netfd = iax_get_fd();
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "IAX Ready Port %d\n", globals.port); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "IAX Ready Port %d\n", globals.port);
@ -796,164 +796,164 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
if (globals.debug && iaxevent->etype != IAX_EVENT_VOICE) { if (globals.debug && iaxevent->etype != IAX_EVENT_VOICE) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Event %d [%s]!\n", switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Event %d [%s]!\n",
iaxevent->etype, IAXNAMES[iaxevent->etype]); iaxevent->etype, IAXNAMES[iaxevent->etype]);
} }
switch (iaxevent->etype) { switch (iaxevent->etype) {
case IAX_EVENT_REGACK: case IAX_EVENT_REGACK:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration completed successfully.\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration completed successfully.\n");
if (iaxevent->ies.refresh) refresh = iaxevent->ies.refresh; if (iaxevent->ies.refresh) refresh = iaxevent->ies.refresh;
break; break;
case IAX_EVENT_REGREJ: case IAX_EVENT_REGREJ:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration failed.\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration failed.\n");
break; break;
case IAX_EVENT_TIMEOUT: case IAX_EVENT_TIMEOUT:
break; break;
case IAX_EVENT_ACCEPT: case IAX_EVENT_ACCEPT:
if (tech_pvt) { if (tech_pvt) {
unsigned int cap = iax_session_get_capability(iaxevent->session); unsigned int cap = iax_session_get_capability(iaxevent->session);
unsigned int format = iaxevent->ies.format; unsigned int format = iaxevent->ies.format;
if (iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, IAX_SET) != SWITCH_STATUS_SUCCESS) { if (iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, IAX_SET) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF? %d %d\n",iaxevent->ies.format, iaxevent->ies.capability); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF? %d %d\n",iaxevent->ies.format, iaxevent->ies.capability);
}
} }
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call accepted.\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call accepted.\n");
break; break;
case IAX_EVENT_RINGA: case IAX_EVENT_RINGA:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Ringing heard.\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Ringing heard.\n");
break; break;
case IAX_EVENT_PONG: case IAX_EVENT_PONG:
// informative only // informative only
break; break;
case IAX_EVENT_ANSWER: case IAX_EVENT_ANSWER:
// the other side answered our call // the other side answered our call
if (tech_pvt) { if (tech_pvt) {
switch_channel *channel; switch_channel *channel;
if ((channel = switch_core_session_get_channel(tech_pvt->session))) { if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer %s\n", switch_channel_get_name(channel)); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer %s\n", switch_channel_get_name(channel));
switch_channel_answer(channel); switch_channel_answer(channel);
}
} }
}
break; break;
case IAX_EVENT_CONNECT: case IAX_EVENT_CONNECT:
// incoming call detected // incoming call detected
switch_console_printf(SWITCH_CHANNEL_CONSOLE, switch_console_printf(SWITCH_CHANNEL_CONSOLE,
"Incoming call connected %s, %s, %s %d/%d\n", "Incoming call connected %s, %s, %s %d/%d\n",
iaxevent->ies.called_number, iaxevent->ies.called_number,
iaxevent->ies.calling_number, iaxevent->ies.calling_number,
iaxevent->ies.calling_name, iaxevent->ies.calling_name,
iaxevent->ies.format, iaxevent->ies.format,
iaxevent->ies.capability); iaxevent->ies.capability);
if (iaxevent) { if (iaxevent) {
switch_core_session *session; switch_core_session *session;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "New Inbound Channel %s!\n", iaxevent->ies.calling_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "New Inbound Channel %s!\n", iaxevent->ies.calling_name);
if ((session = switch_core_session_request(&channel_endpoint_interface, NULL))) { if ((session = switch_core_session_request(&channel_endpoint_interface, NULL))) {
struct private_object *tech_pvt; struct private_object *tech_pvt;
switch_channel *channel;
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
channel = switch_core_session_get_channel(session);
switch_core_session_set_private(session, tech_pvt);
tech_pvt->session = session;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hey where is my memory pool?\n");
switch_core_session_destroy(&session);
break;
}
if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
globals.dialplan,
iaxevent->ies.calling_name,
iaxevent->ies.calling_number,
iax_get_peer_ip(iaxevent->session),
iaxevent->ies.calling_ani,
NULL,
iaxevent->ies.called_number))) {
char name[128];
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
switch_channel_set_name(channel, name);
}
if (iax_set_codec(tech_pvt, iaxevent->session,
&iaxevent->ies.format,
&iaxevent->ies.capability,
IAX_SET) != SWITCH_STATUS_SUCCESS) {
iax_reject(iaxevent->session, "Codec Error!");
switch_core_session_destroy(&session);
} else {
tech_pvt->iax_session = iaxevent->session;
tech_pvt->session = session;
iax_accept(tech_pvt->iax_session, tech_pvt->codec);
iax_ring_announce(tech_pvt->iax_session);
switch_channel_set_state(channel, CS_INIT);
switch_core_session_thread_launch(session);
}
}
}
break;
case IAX_EVENT_REJECT:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Rejected call.\n");
case IAX_EVENT_BUSY:
case IAX_EVENT_HANGUP:
if (tech_pvt) {
switch_channel *channel; switch_channel *channel;
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) { switch_clear_flag(tech_pvt, TFLAG_IO);
memset(tech_pvt, 0, sizeof(*tech_pvt)); switch_clear_flag(tech_pvt, TFLAG_VOICE);
channel = switch_core_session_get_channel(session); if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
switch_core_session_set_private(session, tech_pvt); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hangup %s\n", switch_channel_get_name(channel));
tech_pvt->session = session; switch_set_flag(tech_pvt, TFLAG_HANGUP);
switch_channel_hangup(channel);
switch_thread_cond_signal(tech_pvt->cond);
iaxevent->session = NULL;
} else { } else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hey where is my memory pool?\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Session? %s\n", switch_test_flag(tech_pvt, TFLAG_VOICE) ? "yes" : "no");
switch_core_session_destroy(&session);
break;
}
if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
globals.dialplan,
iaxevent->ies.calling_name,
iaxevent->ies.calling_number,
iax_get_peer_ip(iaxevent->session),
iaxevent->ies.calling_ani,
NULL,
iaxevent->ies.called_number))) {
char name[128];
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
switch_channel_set_name(channel, name);
}
if (iax_set_codec(tech_pvt, iaxevent->session,
&iaxevent->ies.format,
&iaxevent->ies.capability,
IAX_SET) != SWITCH_STATUS_SUCCESS) {
iax_reject(iaxevent->session, "Codec Error!");
switch_core_session_destroy(&session);
} else {
tech_pvt->iax_session = iaxevent->session;
tech_pvt->session = session;
iax_accept(tech_pvt->iax_session, tech_pvt->codec);
iax_ring_announce(tech_pvt->iax_session);
switch_channel_set_state(channel, CS_INIT);
switch_core_session_thread_launch(session);
} }
} }
} break;
break; case IAX_EVENT_CNG:
case IAX_EVENT_REJECT: // pseudo-silence
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Rejected call.\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sending silence\n");
case IAX_EVENT_BUSY: break;
case IAX_EVENT_HANGUP: case IAX_EVENT_VOICE:
if (tech_pvt) { if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen)) {
switch_channel *channel; int bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
int frames = (int)(tech_pvt->read_frame.datalen / bytes);
switch_clear_flag(tech_pvt, TFLAG_IO); tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
switch_clear_flag(tech_pvt, TFLAG_VOICE); memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen);
if ((channel = switch_core_session_get_channel(tech_pvt->session))) { /* wake up the i/o thread*/
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hangup %s\n", switch_channel_get_name(channel)); switch_set_flag(tech_pvt, TFLAG_VOICE);
switch_set_flag(tech_pvt, TFLAG_HANGUP);
switch_channel_hangup(channel);
switch_thread_cond_signal(tech_pvt->cond); switch_thread_cond_signal(tech_pvt->cond);
iaxevent->session = NULL;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Session? %s\n", switch_test_flag(tech_pvt, TFLAG_VOICE) ? "yes" : "no");
} }
} break;
break; case IAX_EVENT_TRANSFER:
case IAX_EVENT_CNG: switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call transfer occurred.\n");
// pseudo-silence //session[0] = iaxevent->session;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sending silence\n"); break;
break; case IAX_EVENT_DTMF:
case IAX_EVENT_VOICE: if (tech_pvt) {
if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen)) { switch_channel *channel;
int bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame; if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
int frames = (int)(tech_pvt->read_frame.datalen / bytes); char str[2] = {iaxevent->subclass};
tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame; if (globals.debug) {
memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s DTMF %s\n", str, switch_channel_get_name(channel));
/* wake up the i/o thread*/ }
switch_set_flag(tech_pvt, TFLAG_VOICE); switch_channel_queue_dtmf(channel, str);
switch_thread_cond_signal(tech_pvt->cond);
}
break;
case IAX_EVENT_TRANSFER:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call transfer occurred.\n");
//session[0] = iaxevent->session;
break;
case IAX_EVENT_DTMF:
if (tech_pvt) {
switch_channel *channel;
if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
char str[2] = {iaxevent->subclass};
if (globals.debug) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s DTMF %s\n", str, switch_channel_get_name(channel));
} }
switch_channel_queue_dtmf(channel, str);
} }
}
break; break;
default: default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n", iaxevent->etype); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n", iaxevent->etype);
break; break;
} }
iax_event_free(iaxevent); iax_event_free(iaxevent);

View File

@ -58,11 +58,11 @@ void playback_function(switch_core_session *session, char *data)
assert(channel != NULL); assert(channel != NULL);
if (switch_core_file_open(&fh, if (switch_core_file_open(&fh,
data, data,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel); switch_channel_hangup(channel);
return; return;
} }
switch_channel_answer(channel); switch_channel_answer(channel);
@ -80,15 +80,15 @@ void playback_function(switch_core_session *session, char *data)
codec_name = "L16"; codec_name = "L16";
if (switch_core_codec_init(&codec, if (switch_core_codec_init(&codec,
codec_name, codec_name,
fh.samplerate, fh.samplerate,
interval, interval,
fh.channels, fh.channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, NULL,
pool) == SWITCH_STATUS_SUCCESS) { pool) == SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
write_frame.codec = &codec; write_frame.codec = &codec;
} else { } else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d channels %dms\n", codec_name, fh.samplerate, fh.channels, interval); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d channels %dms\n", codec_name, fh.samplerate, fh.channels, interval);
switch_core_file_close(&fh); switch_core_file_close(&fh);
@ -188,8 +188,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul
} }
/* 'switch_module_runtime' will start up in a thread by itself just by having it exist /* 'switch_module_runtime' will start up in a thread by itself just by having it exist
if it returns anything but SWITCH_STATUS_TERM it will be called again automaticly if it returns anything but SWITCH_STATUS_TERM it will be called again automaticly
*/ */
//switch_status switch_module_runtime(void) //switch_status switch_module_runtime(void)

View File

@ -95,40 +95,6 @@ static switch_status switch_raw_destroy(switch_codec *codec)
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
#if 0
switch_status raw_file_open(switch_file_handle *handle, char *path)
{
return SWITCH_STATUS_SUCCESS;
}
switch_status raw_file_close(switch_file_handle *handle)
{
return SWITCH_STATUS_SUCCESS;
}
switch_status raw_file_seek(switch_file_handle *handle, unsigned int *cur_sample, unsigned int samples, int whence)
{
return SWITCH_STATUS_NOTIMPL;
}
/* Registration */
static char *supported_formats[] = {"raw", "r8k", NULL};
static const switch_file_interface raw_file_interface = {
/*.interface_name*/ "raw",
/*.file_open*/ raw_file_open,
/*.file_close*/ raw_file_close,
/*.file_read*/ NULL,
/*.file_write*/ NULL,
/*.file_seek*/ raw_file_seek,
/*.extens*/ supported_formats,
/*.next*/ NULL,
};
#endif
static const switch_codec_implementation raw_32k_implementation = { static const switch_codec_implementation raw_32k_implementation = {
/*.samples_per_second = */ 32000, /*.samples_per_second = */ 32000,
/*.bits_per_second = */ 512000, /*.bits_per_second = */ 512000,

View File

@ -150,7 +150,7 @@ struct private_object {
struct woomera_profile *profile; struct woomera_profile *profile;
char dest[WOOMERA_STRLEN]; char dest[WOOMERA_STRLEN];
int port; int port;
struct timeval started; switch_time_t started;
int timeout; int timeout;
char dtmfbuf[WOOMERA_STRLEN]; char dtmfbuf[WOOMERA_STRLEN];
switch_caller_profile *caller_profile; switch_caller_profile *caller_profile;

View File

@ -163,9 +163,9 @@ SWITCH_DECLARE(int) switch_channel_dequeue_dtmf(switch_channel *channel, char *d
} }
SWITCH_DECLARE(switch_status) switch_channel_init(switch_channel *channel, SWITCH_DECLARE(switch_status) switch_channel_init(switch_channel *channel,
switch_core_session *session, switch_core_session *session,
switch_channel_state state, switch_channel_state state,
switch_channel_flag flags) switch_channel_flag flags)
{ {
assert(channel != NULL); assert(channel != NULL);
channel->state = state; channel->state = state;
@ -278,104 +278,104 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_set_state(switch_channel *ch
/* STUB for more dev /* STUB for more dev
case CS_INIT: case CS_INIT:
switch(state) { switch(state) {
case CS_NEW: case CS_NEW:
case CS_INIT: case CS_INIT:
case CS_LOOPBACK: case CS_LOOPBACK:
case CS_TRANSMIT: case CS_TRANSMIT:
case CS_RING: case CS_RING:
case CS_EXECUTE: case CS_EXECUTE:
case CS_HANGUP: case CS_HANGUP:
case CS_DONE: case CS_DONE:
default: default:
break; break;
} }
break; break;
*/ */
switch(last_state) { switch(last_state) {
case CS_NEW: case CS_NEW:
switch(state) { switch(state) {
default: default:
ok++; ok++;
break; break;
} }
break; break;
case CS_INIT: case CS_INIT:
switch(state) { switch(state) {
case CS_LOOPBACK: case CS_LOOPBACK:
case CS_TRANSMIT: case CS_TRANSMIT:
case CS_RING: case CS_RING:
case CS_EXECUTE: case CS_EXECUTE:
case CS_HANGUP: case CS_HANGUP:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_LOOPBACK: case CS_LOOPBACK:
switch(state) { switch(state) {
case CS_TRANSMIT: case CS_TRANSMIT:
case CS_RING: case CS_RING:
case CS_EXECUTE: case CS_EXECUTE:
case CS_HANGUP: case CS_HANGUP:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_TRANSMIT: case CS_TRANSMIT:
switch(state) { switch(state) {
case CS_LOOPBACK: case CS_LOOPBACK:
case CS_RING: case CS_RING:
case CS_EXECUTE: case CS_EXECUTE:
case CS_HANGUP: case CS_HANGUP:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_RING: case CS_RING:
switch(state) { switch(state) {
case CS_LOOPBACK: case CS_LOOPBACK:
case CS_EXECUTE: case CS_EXECUTE:
case CS_HANGUP: case CS_HANGUP:
case CS_TRANSMIT: case CS_TRANSMIT:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_EXECUTE: case CS_EXECUTE:
switch(state) { switch(state) {
case CS_LOOPBACK: case CS_LOOPBACK:
case CS_TRANSMIT: case CS_TRANSMIT:
case CS_RING: case CS_RING:
case CS_HANGUP: case CS_HANGUP:
ok++; ok++;
default: default:
break; break;
} }
break; break;
case CS_HANGUP: case CS_HANGUP:
switch(state) { switch(state) {
case CS_DONE: case CS_DONE:
ok++; ok++;
default: default:
break; break;
} }
break; break;
default: default:
break; break;
} }

View File

@ -34,8 +34,8 @@
static int switch_console_process(char *cmd) static int switch_console_process(char *cmd)
{ {
char *arg = NULL; char *arg = NULL;
char retbuf[1024] = ""; char retbuf[1024] = "";
#ifdef EMBED_PERL #ifdef EMBED_PERL
const char *perlhelp = "perl - execute some perl. (print to STDERR if you want to see it.)\n"; const char *perlhelp = "perl - execute some perl. (print to STDERR if you want to see it.)\n";
@ -48,12 +48,12 @@ char *arg = NULL;
} }
if (!strcmp(cmd, "help")) { if (!strcmp(cmd, "help")) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, switch_console_printf(SWITCH_CHANNEL_CONSOLE,
"\n" "\n"
"Valid Commands:\n\n" "Valid Commands:\n\n"
"help - umm yeah..\n" "help - umm yeah..\n"
"%sshutdown - stop the program\n\n", "%sshutdown - stop the program\n\n",
perlhelp perlhelp
); );
return 1; return 1;
} }
@ -119,14 +119,14 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel channel, char *fi
} }
else if (channel == SWITCH_CHANNEL_ID_EVENT && else if (channel == SWITCH_CHANNEL_ID_EVENT &&
switch_event_running() == SWITCH_STATUS_SUCCESS && switch_event_running() == SWITCH_STATUS_SUCCESS &&
switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) { switch_event_create(&event, SWITCH_EVENT_LOG) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Data", "%s", data);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-File", "%s", filep);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", func); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Function", "%s", func);
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Log-Line", "%d", line);
switch_event_fire(&event); switch_event_fire(&event);
} }
free(data); free(data);
} }

View File

@ -161,13 +161,13 @@ SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel channel)
FILE *handle = stdout; FILE *handle = stdout;
switch (channel) { switch (channel) {
case SWITCH_CHANNEL_ID_CONSOLE: case SWITCH_CHANNEL_ID_CONSOLE:
case SWITCH_CHANNEL_ID_CONSOLE_CLEAN: case SWITCH_CHANNEL_ID_CONSOLE_CLEAN:
handle = runtime.console; handle = runtime.console;
break; break;
default: default:
handle = stdout; handle = stdout;
break; break;
} }
return handle; return handle;
@ -225,8 +225,8 @@ SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *
if ((!rate || rate == iptr->samples_per_second) && if ((!rate || rate == iptr->samples_per_second) &&
(!ms || ms == (iptr->microseconds_per_frame / 1000)) && (!ms || ms == (iptr->microseconds_per_frame / 1000)) &&
(!channels || channels == iptr->number_of_channels)) { (!channels || channels == iptr->number_of_channels)) {
implementation = iptr; implementation = iptr;
break; break;
} }
} }
@ -256,14 +256,14 @@ SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *
} }
SWITCH_DECLARE(switch_status) switch_core_codec_encode(switch_codec *codec, SWITCH_DECLARE(switch_status) switch_core_codec_encode(switch_codec *codec,
switch_codec *other_codec, switch_codec *other_codec,
void *decoded_data, void *decoded_data,
size_t decoded_data_len, size_t decoded_data_len,
int decoded_rate, int decoded_rate,
void *encoded_data, void *encoded_data,
size_t *encoded_data_len, size_t *encoded_data_len,
int *encoded_rate, int *encoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
assert(codec != NULL); assert(codec != NULL);
assert(encoded_data != NULL); assert(encoded_data != NULL);
@ -283,14 +283,14 @@ SWITCH_DECLARE(switch_status) switch_core_codec_encode(switch_codec *codec,
} }
SWITCH_DECLARE(switch_status) switch_core_codec_decode(switch_codec *codec, SWITCH_DECLARE(switch_status) switch_core_codec_decode(switch_codec *codec,
switch_codec *other_codec, switch_codec *other_codec,
void *encoded_data, void *encoded_data,
size_t encoded_data_len, size_t encoded_data_len,
int encoded_rate, int encoded_rate,
void *decoded_data, void *decoded_data,
size_t *decoded_data_len, size_t *decoded_data_len,
int *decoded_rate, int *decoded_rate,
unsigned int *flag) unsigned int *flag)
{ {
assert(codec != NULL); assert(codec != NULL);
assert(encoded_data != NULL); assert(encoded_data != NULL);
@ -335,7 +335,7 @@ SWITCH_DECLARE(switch_status) switch_core_file_open(switch_file_handle *fh, char
memset(fh, 0, sizeof(*fh)); memset(fh, 0, sizeof(*fh));
if (!(ext = strrchr(file_path, '.'))) { if (!(ext = strrchr(file_path, '.'))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Format\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Format\n");
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
ext++; ext++;
@ -350,9 +350,9 @@ SWITCH_DECLARE(switch_status) switch_core_file_open(switch_file_handle *fh, char
fh->memory_pool = pool; fh->memory_pool = pool;
} else { } else {
if ((status = switch_core_new_memory_pool(&fh->memory_pool)) != SWITCH_STATUS_SUCCESS) { if ((status = switch_core_new_memory_pool(&fh->memory_pool)) != SWITCH_STATUS_SUCCESS) {
return status; return status;
} }
switch_set_flag(fh, SWITCH_TIMER_FLAG_FREE_POOL); switch_set_flag(fh, SWITCH_TIMER_FLAG_FREE_POOL);
} }
return fh->file_interface->file_open(fh, file_path); return fh->file_interface->file_open(fh, file_path);
@ -458,14 +458,14 @@ static void *switch_core_service_thread(switch_thread *thread, void *obj)
while(data->running > 0) { while(data->running > 0) {
switch(switch_core_session_read_frame(session, &read_frame, -1)) { switch(switch_core_session_read_frame(session, &read_frame, -1)) {
case SWITCH_STATUS_SUCCESS: case SWITCH_STATUS_SUCCESS:
break; break;
case SWITCH_STATUS_TIMEOUT: case SWITCH_STATUS_TIMEOUT:
break; break;
default: default:
data->running = -1; data->running = -1;
continue; continue;
break; break;
} }
switch_yield(100); switch_yield(100);
@ -504,7 +504,7 @@ SWITCH_DECLARE(switch_memory_pool *) switch_core_session_get_pool(switch_core_se
} }
/* **ONLY** alloc things with this function that **WILL NOT** outlive /* **ONLY** alloc things with this function that **WILL NOT** outlive
the session itself or expect an earth shattering KABOOM!*/ the session itself or expect an earth shattering KABOOM!*/
SWITCH_DECLARE(void *)switch_core_session_alloc(switch_core_session *session, size_t memory) SWITCH_DECLARE(void *)switch_core_session_alloc(switch_core_session *session, size_t memory)
{ {
void *ptr = NULL; void *ptr = NULL;
@ -518,7 +518,7 @@ SWITCH_DECLARE(void *)switch_core_session_alloc(switch_core_session *session, si
} }
/* **ONLY** alloc things with these functions that **WILL NOT** need /* **ONLY** alloc things with these functions that **WILL NOT** need
to be freed *EVER* ie this is for *PERMENANT* memory allocation */ to be freed *EVER* ie this is for *PERMENANT* memory allocation */
SWITCH_DECLARE(void *) switch_core_permenant_alloc(size_t memory) SWITCH_DECLARE(void *) switch_core_permenant_alloc(size_t memory)
{ {
@ -597,9 +597,9 @@ SWITCH_DECLARE(switch_status) switch_core_session_set_private(switch_core_sessio
} }
SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_session *session, SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_session *session,
char *endpoint_name, char *endpoint_name,
switch_caller_profile *caller_profile, switch_caller_profile *caller_profile,
switch_core_session **new_session) switch_core_session **new_session)
{ {
struct switch_io_event_hook_outgoing_channel *ptr; struct switch_io_event_hook_outgoing_channel *ptr;
switch_status status = SWITCH_STATUS_FALSE; switch_status status = SWITCH_STATUS_FALSE;
@ -710,35 +710,35 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
unsigned int flag = 0; unsigned int flag = 0;
session->raw_read_frame.datalen = session->raw_read_frame.buflen; session->raw_read_frame.datalen = session->raw_read_frame.buflen;
status = switch_core_codec_decode(read_frame->codec, status = switch_core_codec_decode(read_frame->codec,
session->read_codec, session->read_codec,
read_frame->data, read_frame->data,
read_frame->datalen, read_frame->datalen,
read_frame->rate, read_frame->rate,
session->raw_read_frame.data, session->raw_read_frame.data,
&session->raw_read_frame.datalen, &session->raw_read_frame.datalen,
&session->raw_read_frame.rate, &session->raw_read_frame.rate,
&flag); &flag);
switch (status) { switch (status) {
case SWITCH_STATUS_RESAMPLE: case SWITCH_STATUS_RESAMPLE:
if (!session->read_resampler) { if (!session->read_resampler) {
switch_resample_create(&session->read_resampler, switch_resample_create(&session->read_resampler,
read_frame->codec->implementation->samples_per_second, read_frame->codec->implementation->samples_per_second,
read_frame->codec->implementation->bytes_per_frame * 10, read_frame->codec->implementation->bytes_per_frame * 10,
session->read_codec->implementation->samples_per_second, session->read_codec->implementation->samples_per_second,
session->read_codec->implementation->bytes_per_frame * 10, session->read_codec->implementation->bytes_per_frame * 10,
session->pool); session->pool);
} }
case SWITCH_STATUS_SUCCESS: case SWITCH_STATUS_SUCCESS:
read_frame = &session->raw_read_frame; read_frame = &session->raw_read_frame;
break; break;
case SWITCH_STATUS_NOOP: case SWITCH_STATUS_NOOP:
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
break; break;
default: default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name);
return status; return status;
break; break;
} }
} }
if (session->read_resampler) { if (session->read_resampler) {
@ -778,36 +778,36 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
enc_frame = *frame; enc_frame = *frame;
} else { } else {
session->raw_read_frame.datalen = switch_buffer_read(session->raw_read_buffer, session->raw_read_frame.datalen = switch_buffer_read(session->raw_read_buffer,
session->raw_read_frame.data, session->raw_read_frame.data,
session->read_codec->implementation->bytes_per_frame); session->read_codec->implementation->bytes_per_frame);
session->raw_read_frame.rate = session->read_codec->implementation->samples_per_second; session->raw_read_frame.rate = session->read_codec->implementation->samples_per_second;
enc_frame = &session->raw_read_frame; enc_frame = &session->raw_read_frame;
} }
session->enc_read_frame.datalen = session->enc_read_frame.buflen; session->enc_read_frame.datalen = session->enc_read_frame.buflen;
status = switch_core_codec_encode(session->read_codec, status = switch_core_codec_encode(session->read_codec,
(*frame)->codec, (*frame)->codec,
session->raw_read_frame.data, session->raw_read_frame.data,
session->raw_read_frame.datalen, session->raw_read_frame.datalen,
session->raw_read_frame.rate, session->raw_read_frame.rate,
session->enc_read_frame.data, session->enc_read_frame.data,
&session->enc_read_frame.datalen, &session->enc_read_frame.datalen,
&session->enc_read_frame.rate, &session->enc_read_frame.rate,
&flag); &flag);
switch (status) { switch (status) {
case SWITCH_STATUS_SUCCESS: case SWITCH_STATUS_SUCCESS:
*frame = &session->enc_read_frame; *frame = &session->enc_read_frame;
break; break;
case SWITCH_STATUS_NOOP: case SWITCH_STATUS_NOOP:
*frame = &session->raw_read_frame; *frame = &session->raw_read_frame;
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
break; break;
default: default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
*frame = NULL; *frame = NULL;
status = SWITCH_STATUS_GENERR; status = SWITCH_STATUS_GENERR;
break; break;
} }
} }
} }
@ -857,38 +857,38 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
if (frame->codec) { if (frame->codec) {
session->raw_write_frame.datalen = session->raw_write_frame.buflen; session->raw_write_frame.datalen = session->raw_write_frame.buflen;
status = switch_core_codec_decode(frame->codec, status = switch_core_codec_decode(frame->codec,
session->write_codec, session->write_codec,
frame->data, frame->data,
frame->datalen, frame->datalen,
frame->rate, frame->rate,
session->raw_write_frame.data, session->raw_write_frame.data,
&session->raw_write_frame.datalen, &session->raw_write_frame.datalen,
&session->raw_write_frame.rate, &session->raw_write_frame.rate,
&flag); &flag);
switch (status) { switch (status) {
case SWITCH_STATUS_RESAMPLE: case SWITCH_STATUS_RESAMPLE:
write_frame = &session->raw_write_frame; write_frame = &session->raw_write_frame;
if (!session->write_resampler) { if (!session->write_resampler) {
status = switch_resample_create(&session->write_resampler, status = switch_resample_create(&session->write_resampler,
frame->codec->implementation->samples_per_second, frame->codec->implementation->samples_per_second,
frame->codec->implementation->bytes_per_frame * 10, frame->codec->implementation->bytes_per_frame * 10,
session->write_codec->implementation->samples_per_second, session->write_codec->implementation->samples_per_second,
session->write_codec->implementation->bytes_per_frame * 10, session->write_codec->implementation->bytes_per_frame * 10,
session->pool); session->pool);
} }
break; break;
case SWITCH_STATUS_SUCCESS: case SWITCH_STATUS_SUCCESS:
write_frame = &session->raw_write_frame; write_frame = &session->raw_write_frame;
break; break;
case SWITCH_STATUS_NOOP: case SWITCH_STATUS_NOOP:
write_frame = frame; write_frame = frame;
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
break; break;
default: default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name);
return status; return status;
break; break;
} }
} }
if (session->write_resampler) { if (session->write_resampler) {
@ -913,10 +913,10 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
if (!session->raw_write_buffer) { if (!session->raw_write_buffer) {
int bytes = session->write_codec->implementation->bytes_per_frame * 10; int bytes = session->write_codec->implementation->bytes_per_frame * 10;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, switch_console_printf(SWITCH_CHANNEL_CONSOLE,
"Engaging Write Buffer at %d bytes to accomidate %d->%d\n", "Engaging Write Buffer at %d bytes to accomidate %d->%d\n",
bytes, bytes,
write_frame->datalen, write_frame->datalen,
session->write_codec->implementation->bytes_per_frame); session->write_codec->implementation->bytes_per_frame);
if ((status = switch_buffer_create(session->pool, &session->raw_write_buffer, bytes)) != SWITCH_STATUS_SUCCESS) { if ((status = switch_buffer_create(session->pool, &session->raw_write_buffer, bytes)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Write Buffer Failed!\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Write Buffer Failed!\n");
return status; return status;
@ -932,28 +932,28 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
session->enc_write_frame.datalen = session->enc_write_frame.buflen; session->enc_write_frame.datalen = session->enc_write_frame.buflen;
status = switch_core_codec_encode(session->write_codec, status = switch_core_codec_encode(session->write_codec,
frame->codec, frame->codec,
enc_frame->data, enc_frame->data,
enc_frame->datalen, enc_frame->datalen,
enc_frame->rate, enc_frame->rate,
session->enc_write_frame.data, session->enc_write_frame.data,
&session->enc_write_frame.datalen, &session->enc_write_frame.datalen,
&session->enc_write_frame.rate, &session->enc_write_frame.rate,
&flag); &flag);
switch (status) { switch (status) {
case SWITCH_STATUS_SUCCESS: case SWITCH_STATUS_SUCCESS:
write_frame = &session->enc_write_frame; write_frame = &session->enc_write_frame;
break; break;
case SWITCH_STATUS_NOOP: case SWITCH_STATUS_NOOP:
write_frame = enc_frame; write_frame = enc_frame;
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
break; break;
default: default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
write_frame = NULL; write_frame = NULL;
return status; return status;
break; break;
} }
status = perform_write(session, write_frame, timeout, io_flag); status = perform_write(session, write_frame, timeout, io_flag);
@ -968,40 +968,40 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
int x; int x;
for (x = 0; x < frames; x++) { for (x = 0; x < frames; x++) {
if ((session->raw_write_frame.datalen = if ((session->raw_write_frame.datalen =
switch_buffer_read(session->raw_write_buffer, switch_buffer_read(session->raw_write_buffer,
session->raw_write_frame.data, session->raw_write_frame.data,
bytes))) { bytes))) {
enc_frame = &session->raw_write_frame; enc_frame = &session->raw_write_frame;
session->raw_write_frame.rate = session->write_codec->implementation->samples_per_second; session->raw_write_frame.rate = session->write_codec->implementation->samples_per_second;
session->enc_write_frame.datalen = session->enc_write_frame.buflen; session->enc_write_frame.datalen = session->enc_write_frame.buflen;
status = switch_core_codec_encode(session->write_codec, status = switch_core_codec_encode(session->write_codec,
frame->codec, frame->codec,
enc_frame->data, enc_frame->data,
enc_frame->datalen, enc_frame->datalen,
enc_frame->rate, enc_frame->rate,
session->enc_write_frame.data, session->enc_write_frame.data,
&session->enc_write_frame.datalen, &session->enc_write_frame.datalen,
&session->enc_write_frame.rate, &session->enc_write_frame.rate,
&flag); &flag);
switch (status) { switch (status) {
case SWITCH_STATUS_SUCCESS: case SWITCH_STATUS_SUCCESS:
write_frame = &session->enc_write_frame; write_frame = &session->enc_write_frame;
break; break;
case SWITCH_STATUS_NOOP: case SWITCH_STATUS_NOOP:
write_frame = enc_frame; write_frame = enc_frame;
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
break; break;
default: default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
write_frame = NULL; write_frame = NULL;
return status; return status;
break; break;
} }
status = perform_write(session, write_frame, timeout, io_flag); status = perform_write(session, write_frame, timeout, io_flag);
} }
} }
return status; return status;
@ -1324,7 +1324,7 @@ static void switch_core_standard_on_ring(switch_core_session *session)
} }
} }
} }
} }
static void switch_core_standard_on_execute(switch_core_session *session) static void switch_core_standard_on_execute(switch_core_session *session)
{ {
@ -1341,7 +1341,7 @@ static void switch_core_standard_on_execute(switch_core_session *session)
while (switch_channel_get_state(session->channel) == CS_EXECUTE && extension->current_application) { while (switch_channel_get_state(session->channel) == CS_EXECUTE && extension->current_application) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Execute %s(%s)\n", extension->current_application->application_name, switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Execute %s(%s)\n", extension->current_application->application_name,
extension->current_application->application_data); extension->current_application->application_data);
if (!(application_interface = loadable_module_get_application_interface(extension->current_application->application_name))) { if (!(application_interface = loadable_module_get_application_interface(extension->current_application->application_name))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Application %s\n", extension->current_application->application_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Application %s\n", extension->current_application->application_name);
switch_channel_set_state(session->channel, CS_HANGUP); switch_channel_set_state(session->channel, CS_HANGUP);
@ -1394,17 +1394,17 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
const switch_event_handler_table *application_event_handlers = NULL; const switch_event_handler_table *application_event_handlers = NULL;
/* /*
Life of the channel. you have channel and pool in your session Life of the channel. you have channel and pool in your session
everywhere you go you use the session to malloc with everywhere you go you use the session to malloc with
switch_core_session_alloc(session, <size>) switch_core_session_alloc(session, <size>)
The enpoint module gets the first crack at implementing the state The enpoint module gets the first crack at implementing the state
if it wants to, it can cancel the default behaviour by returning SWITCH_STATUS_FALSE if it wants to, it can cancel the default behaviour by returning SWITCH_STATUS_FALSE
Next comes the channel's event handler table that can be set by an application Next comes the channel's event handler table that can be set by an application
which also can veto the next behaviour in line by returning SWITCH_STATUS_FALSE which also can veto the next behaviour in line by returning SWITCH_STATUS_FALSE
Finally the default state behaviour is called. Finally the default state behaviour is called.
*/ */
@ -1431,97 +1431,97 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
} }
switch ( state ) { switch ( state ) {
case CS_NEW: /* Just created, Waiting for first instructions */ case CS_NEW: /* Just created, Waiting for first instructions */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State NEW\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State NEW\n");
break; break;
case CS_DONE: case CS_DONE:
continue; continue;
break; break;
case CS_HANGUP: /* Deactivate and end the thread */ case CS_HANGUP: /* Deactivate and end the thread */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State HANGUP\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State HANGUP\n");
if (!driver_event_handlers->on_hangup || if (!driver_event_handlers->on_hangup ||
(driver_event_handlers->on_hangup && (driver_event_handlers->on_hangup &&
driver_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS && driver_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
if (!application_event_handlers || !application_event_handlers->on_hangup || if (!application_event_handlers || !application_event_handlers->on_hangup ||
(application_event_handlers->on_hangup && (application_event_handlers->on_hangup &&
application_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS && application_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
switch_core_standard_on_hangup(session); switch_core_standard_on_hangup(session);
} }
} }
switch_channel_set_state(session->channel, CS_DONE); switch_channel_set_state(session->channel, CS_DONE);
break; break;
case CS_INIT: /* Basic setup tasks */ case CS_INIT: /* Basic setup tasks */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State INIT\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State INIT\n");
if (!driver_event_handlers->on_init || if (!driver_event_handlers->on_init ||
(driver_event_handlers->on_init && (driver_event_handlers->on_init &&
driver_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS && driver_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
if (!application_event_handlers || !application_event_handlers->on_init || if (!application_event_handlers || !application_event_handlers->on_init ||
(application_event_handlers->on_init && (application_event_handlers->on_init &&
application_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS && application_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
switch_core_standard_on_init(session); switch_core_standard_on_init(session);
} }
} }
break; break;
case CS_RING: /* Look for a dialplan and find something to do */ case CS_RING: /* Look for a dialplan and find something to do */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State RING\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State RING\n");
if (!driver_event_handlers->on_ring || if (!driver_event_handlers->on_ring ||
(driver_event_handlers->on_ring && (driver_event_handlers->on_ring &&
driver_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS && driver_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
if (!application_event_handlers || !application_event_handlers->on_ring || if (!application_event_handlers || !application_event_handlers->on_ring ||
(application_event_handlers->on_ring && (application_event_handlers->on_ring &&
application_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS && application_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
switch_core_standard_on_ring(session); switch_core_standard_on_ring(session);
} }
} }
break; break;
case CS_EXECUTE: /* Execute an Operation*/ case CS_EXECUTE: /* Execute an Operation*/
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State EXECUTE\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State EXECUTE\n");
if (!driver_event_handlers->on_execute || if (!driver_event_handlers->on_execute ||
(driver_event_handlers->on_execute && (driver_event_handlers->on_execute &&
driver_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS && driver_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
if (!application_event_handlers || !application_event_handlers->on_execute || if (!application_event_handlers || !application_event_handlers->on_execute ||
(application_event_handlers->on_execute && (application_event_handlers->on_execute &&
application_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS && application_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
switch_core_standard_on_execute(session); switch_core_standard_on_execute(session);
} }
} }
break; break;
case CS_LOOPBACK: /* loop all data back to source */ case CS_LOOPBACK: /* loop all data back to source */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State LOOPBACK\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State LOOPBACK\n");
if (!driver_event_handlers->on_loopback || if (!driver_event_handlers->on_loopback ||
(driver_event_handlers->on_loopback && (driver_event_handlers->on_loopback &&
driver_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS && driver_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
if (!application_event_handlers || !application_event_handlers->on_loopback || if (!application_event_handlers || !application_event_handlers->on_loopback ||
(application_event_handlers->on_loopback && (application_event_handlers->on_loopback &&
application_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS && application_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
switch_core_standard_on_loopback(session); switch_core_standard_on_loopback(session);
} }
} }
break; break;
case CS_TRANSMIT: /* send/recieve data to/from another channel */ case CS_TRANSMIT: /* send/recieve data to/from another channel */
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State TRANSMIT\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State TRANSMIT\n");
if (!driver_event_handlers->on_transmit || if (!driver_event_handlers->on_transmit ||
(driver_event_handlers->on_transmit && (driver_event_handlers->on_transmit &&
driver_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS && driver_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
if (!application_event_handlers || !application_event_handlers->on_transmit || if (!application_event_handlers || !application_event_handlers->on_transmit ||
(application_event_handlers->on_transmit && (application_event_handlers->on_transmit &&
application_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS && application_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
midstate == switch_channel_get_state(session->channel))) { midstate == switch_channel_get_state(session->channel))) {
switch_core_standard_on_transmit(session); switch_core_standard_on_transmit(session);
} }
} }
break; break;
} }
laststate = midstate; laststate = midstate;
@ -1581,16 +1581,16 @@ SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash *hash, char *key)
} }
/* This function abstracts the thread creation for modules by allowing you to pass a function ptr and /* This function abstracts the thread creation for modules by allowing you to pass a function ptr and
a void object and trust that that the function will be run in a thread with arg This lets a void object and trust that that the function will be run in a thread with arg This lets
you request and activate a thread without giving up any knowledge about what is in the thread you request and activate a thread without giving up any knowledge about what is in the thread
neither the core nor the calling module know anything about each other. neither the core nor the calling module know anything about each other.
This thread is expected to never exit until the application exits so the func is responsible This thread is expected to never exit until the application exits so the func is responsible
to make sure that is the case. to make sure that is the case.
The typical use for this is so switch_loadable_module.c can start up a thread for each module The typical use for this is so switch_loadable_module.c can start up a thread for each module
passing the table of module methods as a session obj into the core without actually allowing passing the table of module methods as a session obj into the core without actually allowing
the core to have any clue and keeping switch_loadable_module.c from needing any thread code. the core to have any clue and keeping switch_loadable_module.c from needing any thread code.
*/ */
@ -1605,9 +1605,9 @@ SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void
switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_detach_set(thd_attr, 1);
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n");
return; return;
} }
if (!(ts = switch_core_alloc(pool, sizeof(*ts)))) { if (!(ts = switch_core_alloc(pool, sizeof(*ts)))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory\n");
@ -1616,11 +1616,11 @@ SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void
ts->objs[0] = obj; ts->objs[0] = obj;
switch_thread_create(&thread, switch_thread_create(&thread,
thd_attr, thd_attr,
func, func,
ts, ts,
ts->pool ts->pool
); );
} }
} }
@ -1655,12 +1655,12 @@ SWITCH_DECLARE(void) switch_core_session_thread_launch(switch_core_session *sess
switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_detach_set(thd_attr, 1);
if (switch_thread_create(&thread, if (switch_thread_create(&thread,
thd_attr, thd_attr,
switch_core_session_thread, switch_core_session_thread,
session, session,
session->pool session->pool
) != APR_SUCCESS) { ) != APR_SUCCESS) {
switch_core_session_destroy(&session); switch_core_session_destroy(&session);
} }
} }
@ -1673,11 +1673,11 @@ SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *sess
switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_detach_set(thd_attr, 1);
switch_thread_create(&thread, switch_thread_create(&thread,
thd_attr, thd_attr,
func, func,
obj, obj,
session->pool session->pool
); );
} }
@ -1723,7 +1723,7 @@ SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_e
switch_channel_init(session->channel, session, CS_NEW, CF_SEND_AUDIO | CF_RECV_AUDIO); switch_channel_init(session->channel, session, CS_NEW, CF_SEND_AUDIO | CF_RECV_AUDIO);
/* The session *IS* the pool you may not alter it because you have no idea how /* The session *IS* the pool you may not alter it because you have no idea how
its all private it will be passed to the thread run function */ its all private it will be passed to the thread run function */
switch_uuid_get(&uuid); switch_uuid_get(&uuid);
switch_uuid_format(session->uuid_str, &uuid); switch_uuid_format(session->uuid_str, &uuid);
@ -1766,13 +1766,13 @@ static void core_event_handler (switch_event *event)
char buf[1024]; char buf[1024];
switch(event->event_id) { switch(event->event_id) {
case SWITCH_EVENT_LOG: case SWITCH_EVENT_LOG:
return; return;
break; break;
default: default:
switch_event_serialize(event, buf, sizeof(buf), NULL); switch_event_serialize(event, buf, sizeof(buf), NULL);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nCORE EVENT\n--------------------------------\n%s\n", buf); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nCORE EVENT\n--------------------------------\n%s\n", buf);
break; break;
} }
} }

View File

@ -84,7 +84,7 @@ static void *locked_dup(char *str)
#endif #endif
/* make sure this is synced with the switch_event_t enum in switch_types.h /* make sure this is synced with the switch_event_t enum in switch_types.h
also never put any new ones before EVENT_ALL also never put any new ones before EVENT_ALL
*/ */
static char *EVENT_NAMES[] = { static char *EVENT_NAMES[] = {
"CUSTOM", "CUSTOM",
@ -243,23 +243,23 @@ SWITCH_DECLARE(switch_status) switch_event_shutdown(void)
SWITCH_DECLARE(switch_status) switch_event_init(switch_memory_pool *pool) SWITCH_DECLARE(switch_status) switch_event_init(switch_memory_pool *pool)
{ {
switch_thread *thread; switch_thread *thread;
switch_threadattr_t *thd_attr;; switch_threadattr_t *thd_attr;;
switch_threadattr_create(&thd_attr, pool); switch_threadattr_create(&thd_attr, pool);
switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_detach_set(thd_attr, 1);
assert(pool != NULL); assert(pool != NULL);
RUNTIME_POOL = pool; RUNTIME_POOL = pool;
if (switch_core_new_memory_pool(&APOOL) != SWITCH_STATUS_SUCCESS) { if (switch_core_new_memory_pool(&APOOL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n");
return SWITCH_STATUS_MEMERR; return SWITCH_STATUS_MEMERR;
} }
if (switch_core_new_memory_pool(&BPOOL) != SWITCH_STATUS_SUCCESS) { if (switch_core_new_memory_pool(&BPOOL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n");
return SWITCH_STATUS_MEMERR; return SWITCH_STATUS_MEMERR;
} }
THRUNTIME_POOL = APOOL; THRUNTIME_POOL = APOOL;
switch_queue_create(&EVENT_QUEUE, POOL_COUNT_MAX + 10, THRUNTIME_POOL); switch_queue_create(&EVENT_QUEUE, POOL_COUNT_MAX + 10, THRUNTIME_POOL);
@ -268,12 +268,12 @@ SWITCH_DECLARE(switch_status) switch_event_init(switch_memory_pool *pool)
switch_mutex_init(&BLOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL); switch_mutex_init(&BLOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL);
switch_mutex_init(&POOL_LOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL); switch_mutex_init(&POOL_LOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL);
switch_core_hash_init(&CUSTOM_HASH, RUNTIME_POOL); switch_core_hash_init(&CUSTOM_HASH, RUNTIME_POOL);
switch_thread_create(&thread, switch_thread_create(&thread,
thd_attr, thd_attr,
switch_event_thread, switch_event_thread,
NULL, NULL,
RUNTIME_POOL RUNTIME_POOL
); );
while(!THREAD_RUNNING) { while(!THREAD_RUNNING) {
switch_yield(1000); switch_yield(1000);
@ -321,10 +321,10 @@ SWITCH_DECLARE(char *) switch_event_get_header(switch_event *event, char *header
SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name, char *fmt, ...) SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switch_stack_t stack, char *header_name, char *fmt, ...)
{ {
int ret = 0; int ret = 0;
char data[2048]; char data[2048];
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(data, sizeof(data), fmt, ap); vsnprintf(data, sizeof(data), fmt, ap);
va_end(ap); va_end(ap);
@ -366,10 +366,10 @@ SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switc
SWITCH_DECLARE(switch_status) switch_event_add_body(switch_event *event, char *fmt, ...) SWITCH_DECLARE(switch_status) switch_event_add_body(switch_event *event, char *fmt, ...)
{ {
int ret = 0; int ret = 0;
char data[2048]; char data[2048];
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(data, sizeof(data), fmt, ap); vsnprintf(data, sizeof(data), fmt, ap);
va_end(ap); va_end(ap);
@ -441,9 +441,9 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char *
{ {
size_t len = 0; size_t len = 0;
switch_event_header *hp; switch_event_header *hp;
char *data = NULL, *body = NULL; char *data = NULL, *body = NULL;
int ret = 0; int ret = 0;
va_list ap; va_list ap;
if (fmt) { if (fmt) {
va_start(ap, fmt); va_start(ap, fmt);

View File

@ -250,8 +250,8 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
for (ptr = new_module->interface->endpoint_interface; ptr; ptr = ptr->next) { for (ptr = new_module->interface->endpoint_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Endpoint '%s'\n", ptr->interface_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Endpoint '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.endpoint_hash, switch_core_hash_insert(loadable_modules.endpoint_hash,
(char *) ptr->interface_name, (char *) ptr->interface_name,
(void *) ptr); (void *) ptr);
} }
} }
@ -262,16 +262,16 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
for(ptr = new_module->interface->codec_interface; ptr; ptr = ptr->next) { for(ptr = new_module->interface->codec_interface; ptr; ptr = ptr->next) {
for(impl = ptr->implementations; impl ; impl = impl->next) { for(impl = ptr->implementations; impl ; impl = impl->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, switch_console_printf(SWITCH_CHANNEL_CONSOLE,
"Adding Codec '%s' (%s) %dkhz %dms\n", "Adding Codec '%s' (%s) %dkhz %dms\n",
ptr->iananame, ptr->iananame,
ptr->interface_name, ptr->interface_name,
impl->samples_per_second, impl->samples_per_second,
impl->microseconds_per_frame / 1000); impl->microseconds_per_frame / 1000);
} }
switch_core_hash_insert(loadable_modules.codec_hash, switch_core_hash_insert(loadable_modules.codec_hash,
(char *) ptr->iananame, (char *) ptr->iananame,
(void *) ptr); (void *) ptr);
} }
} }
@ -281,8 +281,8 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
for(ptr = new_module->interface->dialplan_interface; ptr; ptr = ptr->next) { for(ptr = new_module->interface->dialplan_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Dialplan '%s'\n", ptr->interface_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Dialplan '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.dialplan_hash, switch_core_hash_insert(loadable_modules.dialplan_hash,
(char *) ptr->interface_name, (char *) ptr->interface_name,
(void *) ptr); (void *) ptr);
} }
} }
@ -292,8 +292,8 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
for(ptr = new_module->interface->timer_interface; ptr; ptr = ptr->next) { for(ptr = new_module->interface->timer_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Timer '%s'\n", ptr->interface_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Timer '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.timer_hash, switch_core_hash_insert(loadable_modules.timer_hash,
(char *) ptr->interface_name, (char *) ptr->interface_name,
(void *) ptr); (void *) ptr);
} }
} }
@ -303,8 +303,8 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
for(ptr = new_module->interface->application_interface; ptr; ptr = ptr->next) { for(ptr = new_module->interface->application_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Application '%s'\n", ptr->interface_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Application '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.application_hash, switch_core_hash_insert(loadable_modules.application_hash,
(char *) ptr->interface_name, (char *) ptr->interface_name,
(void *) ptr); (void *) ptr);
} }
} }
@ -314,8 +314,8 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
for(ptr = new_module->interface->api_interface; ptr; ptr = ptr->next) { for(ptr = new_module->interface->api_interface; ptr; ptr = ptr->next) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding API Function '%s'\n", ptr->interface_name); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding API Function '%s'\n", ptr->interface_name);
switch_core_hash_insert(loadable_modules.api_hash, switch_core_hash_insert(loadable_modules.api_hash,
(char *) ptr->interface_name, (char *) ptr->interface_name,
(void *) ptr); (void *) ptr);
} }
} }
@ -327,8 +327,8 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init()
for (i = 0 ; ptr->extens[i]; i++) { for (i = 0 ; ptr->extens[i]; i++) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding File Format '%s'\n", ptr->extens[i]); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding File Format '%s'\n", ptr->extens[i]);
switch_core_hash_insert(loadable_modules.file_hash, switch_core_hash_insert(loadable_modules.file_hash,
(char *) ptr->extens[i], (char *) ptr->extens[i],
(void *) ptr); (void *) ptr);
} }
} }
} }

View File

@ -32,8 +32,8 @@
#include <switch_mutex.h> #include <switch_mutex.h>
SWITCH_DECLARE(switch_status) switch_mutex_init(switch_mutex_t **lock, SWITCH_DECLARE(switch_status) switch_mutex_init(switch_mutex_t **lock,
switch_lock_flag flags, switch_lock_flag flags,
switch_memory_pool *pool) switch_memory_pool *pool)
{ {
return (apr_thread_mutex_create(lock, flags, pool) == APR_SUCCESS) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR; return (apr_thread_mutex_create(lock, flags, pool) == APR_SUCCESS) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR;

View File

@ -77,23 +77,23 @@ SWITCH_DECLARE(switch_status) switch_resample_create(switch_audio_resampler **ne
SWITCH_DECLARE(int) switch_resample_process(switch_audio_resampler *resampler, float *src, int srclen, float *dst, int dstlen, int last) SWITCH_DECLARE(int) switch_resample_process(switch_audio_resampler *resampler, float *src, int srclen, float *dst, int dstlen, int last)
{ {
int o=0, srcused=0, srcpos=0, out=0; int o=0, srcused=0, srcpos=0, out=0;
for(;;) { for(;;) {
int srcBlock = MIN(srclen-srcpos, srclen); int srcBlock = MIN(srclen-srcpos, srclen);
int lastFlag = (last && (srcBlock == srclen-srcpos)); int lastFlag = (last && (srcBlock == srclen-srcpos));
o = resample_process(resampler->resampler, resampler->factor, &src[srcpos], srcBlock, lastFlag, &srcused, &dst[out], dstlen-out); o = resample_process(resampler->resampler, resampler->factor, &src[srcpos], srcBlock, lastFlag, &srcused, &dst[out], dstlen-out);
//printf("resampling %d/%d (%d) %d %f\n", srcpos, srclen, MIN(dstlen-out, dstlen), srcused, factor); //printf("resampling %d/%d (%d) %d %f\n", srcpos, srclen, MIN(dstlen-out, dstlen), srcused, factor);
srcpos += srcused; srcpos += srcused;
if (o >= 0) { if (o >= 0) {
out += o; out += o;
} }
if (o < 0 || (o == 0 && srcpos == srclen)) { if (o < 0 || (o == 0 && srcpos == srclen)) {
break; break;
} }
} }
return out; return out;
} }
SWITCH_DECLARE(void) switch_resample_destroy(switch_audio_resampler *resampler) SWITCH_DECLARE(void) switch_resample_destroy(switch_audio_resampler *resampler)

View File

@ -72,21 +72,16 @@ SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll,
switch_pollset_t *pollset; switch_pollset_t *pollset;
switch_status status; switch_status status;
if ((status = switch_pollset_create(&pollset, 1, pool, flags)) != SWITCH_STATUS_SUCCESS) { if ((status = switch_pollset_create(&pollset, 1, pool, flags)) != SWITCH_STATUS_SUCCESS) {
return status; return status;
} }
poll->desc_type = SWITCH_POLL_SOCKET; poll->desc_type = SWITCH_POLL_SOCKET;
poll->reqevents = flags; poll->reqevents = flags;
poll->desc.s = sock; poll->desc.s = sock;
poll->client_data = sock; poll->client_data = sock;
return switch_pollset_add(pollset, poll); return switch_pollset_add(pollset, poll);
} }
@ -102,54 +97,6 @@ SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms)
return nsds; return nsds;
} }
#ifdef HAVE_TIMEVAL_STRUCT
#define ONE_MILLION 1000000
/*
* put timeval in a valid range. usec is 0..999999
* negative values are not allowed and truncated.
*/
static struct timeval tvfix(struct timeval a)
{
if (a.tv_usec >= ONE_MILLION) {
a.tv_sec += a.tv_usec % ONE_MILLION;
a.tv_usec %= ONE_MILLION;
} else if (a.tv_usec < 0) {
a.tv_usec = 0;
}
return a;
}
struct timeval switch_tvadd(struct timeval a, struct timeval b)
{
/* consistency checks to guarantee usec in 0..999999 */
a = tvfix(a);
b = tvfix(b);
a.tv_sec += b.tv_sec;
a.tv_usec += b.tv_usec;
if (a.tv_usec >= ONE_MILLION) {
a.tv_sec++;
a.tv_usec -= ONE_MILLION;
}
return a;
}
struct timeval switch_tvsub(struct timeval a, struct timeval b)
{
/* consistency checks to guarantee usec in 0..999999 */
a = tvfix(a);
b = tvfix(b);
a.tv_sec -= b.tv_sec;
a.tv_usec -= b.tv_usec;
if (a.tv_usec < 0) {
a.tv_sec-- ;
a.tv_usec += ONE_MILLION;
}
return a;
}
#undef ONE_MILLION
#endif
#ifdef WIN32 #ifdef WIN32
//this forces certain symbols to not be optimized out of the dll //this forces certain symbols to not be optimized out of the dll
void include_me(void) void include_me(void)