diff --git a/libs/jrtp4c/src/jrtp4c.cpp b/libs/jrtp4c/src/jrtp4c.cpp index ac35ead75d..6db264e4e5 100644 --- a/libs/jrtp4c/src/jrtp4c.cpp +++ b/libs/jrtp4c/src/jrtp4c.cpp @@ -37,7 +37,7 @@ extern "C" { RTPIPv4Address addr(destip, tx_port); RTPSessionParams sessparams; int status; - + #ifdef WIN32 if (!WSOCKON) { WSADATA dat; @@ -70,13 +70,13 @@ extern "C" { jrtp4c->transparams->SetPortbase(rx_port); - + if (!(jrtp4c->session = new JRTP4C)) { *err = "Memory Error!\n"; delete jrtp4c->transparams; - delete jrtp4c; - return NULL; + delete jrtp4c; + return NULL; } if ((status = jrtp4c->session->Create(sessparams, jrtp4c->transparams)) < 0) { @@ -128,7 +128,7 @@ extern "C" { return 0; } - + if ((pack = jrtp4c->session->GetNextPacket())) { slen = (int)pack->GetPayloadLength(); diff --git a/src/mod/codec/mod_codec_gsm/mod_codec_gsm.c b/src/mod/codec/mod_codec_gsm/mod_codec_gsm.c index 62460f450b..b0e3e04258 100644 --- a/src/mod/codec/mod_codec_gsm/mod_codec_gsm.c +++ b/src/mod/codec/mod_codec_gsm/mod_codec_gsm.c @@ -43,10 +43,10 @@ static switch_status switch_gsm_init(switch_codec *codec, switch_codec_flag flag { struct gsm_context *context; int encoding, decoding; - + encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); decoding = (flags & SWITCH_CODEC_FLAG_DECODE); - + if (!(encoding || decoding)) { return SWITCH_STATUS_FALSE; } else { @@ -56,9 +56,9 @@ static switch_status switch_gsm_init(switch_codec *codec, switch_codec_flag flag } codec->private = context; - + return SWITCH_STATUS_SUCCESS; - + } static switch_status switch_gsm_destroy(switch_codec *codec) @@ -76,14 +76,14 @@ static switch_status switch_gsm_destroy(switch_codec *codec) static switch_status switch_gsm_encode(switch_codec *codec, - switch_codec *other_codec, - void *decoded_data, - size_t decoded_data_len, - int decoded_rate, - void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *decoded_data, + size_t decoded_data_len, + int decoded_rate, + void *encoded_data, + size_t *encoded_data_len, + int *encoded_rate, + unsigned int *flag) { struct gsm_context *context = codec->private; int cbret = 0; @@ -116,17 +116,17 @@ static switch_status switch_gsm_encode(switch_codec *codec, static switch_status switch_gsm_decode(switch_codec *codec, - switch_codec *other_codec, - void *encoded_data, - size_t encoded_data_len, - int encoded_rate, - void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *encoded_data, + size_t encoded_data_len, + int encoded_rate, + void *decoded_data, + size_t *decoded_data_len, + int *decoded_rate, + unsigned int *flag) { struct gsm_context *context = codec->private; - + if (!context) { return SWITCH_STATUS_FALSE; } @@ -140,7 +140,7 @@ static switch_status switch_gsm_decode(switch_codec *codec, unsigned int new_len = 0; for(x = 0; x < loops && new_len < *decoded_data_len; x++) { gsm_decode(context->decoder, edp, ddp); - ddp += 160; + ddp += 160; edp += 33; new_len += 320; } @@ -153,7 +153,7 @@ static switch_status switch_gsm_decode(switch_codec *codec, } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len); } - + return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/mod_bridgecall/mod_bridgecall.c b/src/mod/mod_bridgecall/mod_bridgecall.c index d36cf91201..facdca0734 100644 --- a/src/mod/mod_bridgecall/mod_bridgecall.c +++ b/src/mod/mod_bridgecall/mod_bridgecall.c @@ -50,7 +50,7 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj) switch_channel *chan_a, *chan_b; switch_frame *read_frame; switch_core_session *session_a, *session_b; - + session_a = data->objs[0]; session_b = data->objs[1]; @@ -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 (b_state) { - case CS_HANGUP: - data->running = -1; - continue; - break; - default: - break; +case CS_HANGUP: + data->running = -1; + continue; + break; +default: + break; } if (switch_channel_has_dtmf(chan_a)) { @@ -110,7 +110,7 @@ static switch_status audio_bridge_on_hangup(switch_core_session *session) switch_core_session_kill_channel(other_session, SWITCH_SIG_KILL); switch_core_session_kill_channel(session, SWITCH_SIG_KILL); - + return SWITCH_STATUS_SUCCESS; } @@ -137,7 +137,7 @@ static const switch_event_handler_table audio_bridge_peer_event_handlers = { /*.on_init*/ NULL, /*.on_ring*/ audio_bridge_on_ring, /*.on_execute*/ NULL, - /*.on_hangup*/ audio_bridge_on_hangup, + /*.on_hangup*/ audio_bridge_on_hangup, /*.on_loopback*/ NULL, /*.on_transmit*/ NULL }; @@ -146,7 +146,7 @@ static const switch_event_handler_table audio_bridge_caller_event_handlers = { /*.on_init*/ NULL, /*.on_ring*/ NULL, /*.on_execute*/ NULL, - /*.on_hangup*/ audio_bridge_on_hangup, + /*.on_hangup*/ audio_bridge_on_hangup, /*.on_loopback*/ NULL, /*.on_transmit*/ NULL }; @@ -171,16 +171,16 @@ static void audio_bridge_function(switch_core_session *session, char *data) caller_caller_profile = switch_channel_get_caller_profile(caller_channel); caller_profile = switch_caller_profile_new(session, - caller_caller_profile->dialplan, - caller_caller_profile->caller_id_name, - caller_caller_profile->caller_id_number, - caller_caller_profile->network_addr, - NULL, - NULL, - chan_data); - + caller_caller_profile->dialplan, + caller_caller_profile->caller_id_name, + caller_caller_profile->caller_id_number, + caller_caller_profile->network_addr, + NULL, + NULL, + chan_data); + + - if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session) != SWITCH_STATUS_SUCCESS) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DOH!\n"); switch_channel_hangup(caller_channel); @@ -188,18 +188,18 @@ static void audio_bridge_function(switch_core_session *session, char *data) } else { struct switch_core_thread_session this_audio_thread, other_audio_thread; time_t start; - + peer_channel = switch_core_session_get_channel(peer_session); memset(&other_audio_thread, 0, sizeof(other_audio_thread)); memset(&this_audio_thread, 0, sizeof(this_audio_thread)); other_audio_thread.objs[0] = session; other_audio_thread.objs[1] = peer_session; other_audio_thread.running = 5; - + this_audio_thread.objs[0] = peer_session; this_audio_thread.objs[1] = session; this_audio_thread.running = 2; - + switch_channel_set_private(caller_channel, peer_session); switch_channel_set_private(peer_channel, session); @@ -217,10 +217,10 @@ static void audio_bridge_function(switch_core_session *session, char *data) time(&start); while(switch_channel_get_state(caller_channel) == CS_EXECUTE && - switch_channel_get_state(peer_channel) == CS_TRANSMIT && - !switch_channel_test_flag(peer_channel, CF_ANSWERED) && - ((time(NULL) - start) < timelimit)) { - switch_yield(20000); + switch_channel_get_state(peer_channel) == CS_TRANSMIT && + !switch_channel_test_flag(peer_channel, CF_ANSWERED) && + ((time(NULL) - start) < timelimit)) { + switch_yield(20000); } if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) { @@ -262,7 +262,7 @@ static const switch_loadable_module_interface mod_bridgecall_module_interface = }; SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { - + /* connect my internal structure to the blank pointer passed to me */ *interface = &mod_bridgecall_module_interface; diff --git a/src/mod/mod_codec_g729/mod_codec_g729.c b/src/mod/mod_codec_g729/mod_codec_g729.c index 05c4d3d768..e85d461ea1 100644 --- a/src/mod/mod_codec_g729/mod_codec_g729.c +++ b/src/mod/mod_codec_g729/mod_codec_g729.c @@ -43,10 +43,10 @@ static switch_status switch_g729_init(switch_codec *codec, switch_codec_flag fla { struct g729_context *context = NULL; int encoding, decoding; - + encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); decoding = (flags & SWITCH_CODEC_FLAG_DECODE); - + if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g729_context))))) { return SWITCH_STATUS_FALSE; } else { @@ -58,7 +58,7 @@ static switch_status switch_g729_init(switch_codec *codec, switch_codec_flag fla } codec->private = context; - + return SWITCH_STATUS_SUCCESS; } } @@ -71,14 +71,14 @@ static switch_status switch_g729_destroy(switch_codec *codec) static switch_status switch_g729_encode(switch_codec *codec, - switch_codec *other_codec, - void *decoded_data, - size_t decoded_data_len, - int decoded_rate, - void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *decoded_data, + size_t decoded_data_len, + int decoded_rate, + void *encoded_data, + size_t *encoded_data_len, + int *encoded_rate, + unsigned int *flag) { struct g729_context *context = codec->private; int cbret = 0; @@ -92,7 +92,7 @@ static switch_status switch_g729_encode(switch_codec *codec, char *edp = encoded_data; int x; int loops = (int) decoded_data_len / 160; - + for(x = 0; x < loops && new_len < *encoded_data_len; x++) { g729_coder(&context->encoder_object, ddp, edp, &cbret); edp += 10; @@ -111,17 +111,17 @@ static switch_status switch_g729_encode(switch_codec *codec, static switch_status switch_g729_decode(switch_codec *codec, - switch_codec *other_codec, - void *encoded_data, - size_t encoded_data_len, - int encoded_rate, - void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *encoded_data, + size_t encoded_data_len, + int encoded_rate, + void *decoded_data, + size_t *decoded_data_len, + int *decoded_rate, + unsigned int *flag) { struct g729_context *context = codec->private; - + if (!context) { return SWITCH_STATUS_FALSE; } @@ -148,8 +148,8 @@ static switch_status switch_g729_decode(switch_codec *codec, } else { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len); } - - + + return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/mod_dialplan_demo/mod_dialplan_demo.c b/src/mod/mod_dialplan_demo/mod_dialplan_demo.c index 27742716f2..c071f613bb 100644 --- a/src/mod/mod_dialplan_demo/mod_dialplan_demo.c +++ b/src/mod/mod_dialplan_demo/mod_dialplan_demo.c @@ -59,7 +59,7 @@ switch_caller_extension *demo_dialplan_hunt(switch_core_session *session) switch_channel_hangup(channel); return NULL; } - + while (switch_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "extensions")) { if (!strcmp(var, caller_profile->destination_number) && val) { @@ -67,7 +67,7 @@ switch_caller_extension *demo_dialplan_hunt(switch_core_session *session) memset(app, 0, sizeof(app)); strncpy(app, val, sizeof(app)); - + if ((data = strchr(app, ' '))) { *data = '\0'; data++; @@ -94,7 +94,7 @@ switch_caller_extension *demo_dialplan_hunt(switch_core_session *session) } else { switch_channel_hangup(channel); } - + return extension; } @@ -115,14 +115,10 @@ static const switch_loadable_module_interface demo_dialplan_module_interface = { }; SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { - + /* connect my internal structure to the blank pointer passed to me */ *interface = &demo_dialplan_module_interface; /* indicate that the module should continue to be loaded */ return SWITCH_STATUS_SUCCESS; } - - - - diff --git a/src/mod/mod_event_test/mod_event_test.c b/src/mod/mod_event_test/mod_event_test.c index 1769777ef1..58c406c719 100644 --- a/src/mod/mod_event_test/mod_event_test.c +++ b/src/mod/mod_event_test/mod_event_test.c @@ -47,7 +47,7 @@ static void event_handler (switch_event *event) break; } } - + static switch_loadable_module_interface event_test_module_interface = { /*.module_name*/ modname, diff --git a/src/mod/mod_exosip/mod_exosip.c b/src/mod/mod_exosip/mod_exosip.c index 024d544b30..972797c379 100644 --- a/src/mod/mod_exosip/mod_exosip.c +++ b/src/mod/mod_exosip/mod_exosip.c @@ -30,7 +30,6 @@ * */ - #define HAVE_APR #include #include @@ -136,7 +135,7 @@ static void set_global_dialplan(char *dialplan) free(globals.dialplan); globals.dialplan = NULL; } - + globals.dialplan = strdup(dialplan); } @@ -191,25 +190,25 @@ static int sdp_add_codec(struct osip_rfc3264 *cnf, int codec_type, int payload, } switch (codec_type) { - case SWITCH_CODEC_TYPE_AUDIO: - med->m_media = osip_strdup("audio"); - osip_rfc3264_add_audio_media(cnf, med, -1); - break; - case SWITCH_CODEC_TYPE_VIDEO: - med->m_media = osip_strdup("video"); - osip_rfc3264_add_video_media(cnf, med, -1); - break; - default: - break; +case SWITCH_CODEC_TYPE_AUDIO: + med->m_media = osip_strdup("audio"); + osip_rfc3264_add_audio_media(cnf, med, -1); + break; +case SWITCH_CODEC_TYPE_VIDEO: + med->m_media = osip_strdup("video"); + osip_rfc3264_add_video_media(cnf, med, -1); + break; +default: + break; } - return 0; + return 0; } /* - 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 - so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it. +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 +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) { @@ -333,7 +332,7 @@ static switch_status exosip_on_hangup(switch_core_session *session) switch_core_hash_delete(globals.call_hash, tech_pvt->call_id); - + switch_set_flag(tech_pvt, TFLAG_BYE); switch_clear_flag(tech_pvt, TFLAG_IO); @@ -395,7 +394,7 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc switch_core_session_destroy(new_session); return SWITCH_STATUS_GENERR; } - + switch_channel_set_flag(channel, CF_OUTBOUND); switch_set_flag(tech_pvt, TFLAG_OUTBOUND); switch_channel_set_state(channel, CS_INIT); @@ -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", - tech_pvt->local_sdp_audio_ip, - tech_pvt->local_sdp_audio_port, - tech_pvt->remote_sdp_audio_ip, - tech_pvt->remote_sdp_audio_port, - tech_pvt->read_codec.codec_interface->ianacode, - ms - ); + tech_pvt->local_sdp_audio_ip, + tech_pvt->local_sdp_audio_port, + tech_pvt->remote_sdp_audio_ip, + tech_pvt->remote_sdp_audio_port, + tech_pvt->read_codec.codec_interface->ianacode, + ms + ); tech_pvt->rtp_session = jrtp4c_new( - tech_pvt->local_sdp_audio_ip, - tech_pvt->local_sdp_audio_port, - tech_pvt->remote_sdp_audio_ip, - tech_pvt->remote_sdp_audio_port, - tech_pvt->read_codec.codec_interface->ianacode, - tech_pvt->read_codec.implementation->samples_per_second, - &err); + tech_pvt->local_sdp_audio_ip, + tech_pvt->local_sdp_audio_port, + tech_pvt->remote_sdp_audio_ip, + tech_pvt->remote_sdp_audio_port, + tech_pvt->read_codec.codec_interface->ianacode, + tech_pvt->read_codec.implementation->samples_per_second, + &err); if (tech_pvt->rtp_session) { tech_pvt->ssrc = jrtp4c_get_ssrc(tech_pvt->rtp_session); @@ -548,15 +547,15 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram if (!switch_test_flag(tech_pvt, TFLAG_RTP)) { return SWITCH_STATUS_GENERR; } - + assert(tech_pvt->rtp_session != NULL); 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.data, - sizeof(tech_pvt->read_buf)); + tech_pvt->read_frame.data, + sizeof(tech_pvt->read_buf)); if (tech_pvt->read_frame.datalen > 0) { bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame; @@ -567,7 +566,7 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram tech_pvt->read_frame.samples = (int)samples; break; } - + switch_yield(100); } @@ -575,7 +574,7 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram //printf("%s %s->%s recv %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->local_sdp_audio_ip, tech_pvt->read_frame.datalen, samples, frames, ms, tech_pvt->timestamp_recv); - + //switch_mutex_unlock(tech_pvt->rtp_lock); @@ -585,7 +584,7 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram } switch_clear_flag(tech_pvt, TFLAG_READING); - + if (switch_test_flag(tech_pvt, TFLAG_BYE)) { switch_channel_hangup(channel); return SWITCH_STATUS_FALSE; @@ -593,7 +592,7 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram *frame = &tech_pvt->read_frame; - + return SWITCH_STATUS_SUCCESS; } @@ -610,7 +609,7 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + if (!switch_test_flag(tech_pvt, TFLAG_RTP)) { return SWITCH_STATUS_GENERR; } @@ -635,8 +634,8 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra } else { assert(0); } - - + + //printf("%s %s->%s send %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, ms, tech_pvt->timestamp_send); @@ -664,7 +663,7 @@ static switch_status exosip_kill_channel(switch_core_session *session, int sig) switch_clear_flag(tech_pvt, TFLAG_IO); switch_set_flag(tech_pvt, TFLAG_BYE); - + return SWITCH_STATUS_SUCCESS; } @@ -694,11 +693,11 @@ static switch_status exosip_waitfor_write(switch_core_session *session, int ms) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + return SWITCH_STATUS_SUCCESS; } - + static const switch_io_routines exosip_io_routines = { /*.outgoing_channel*/ exosip_outgoing_channel, /*.answer_channel*/ exosip_answer_channel, @@ -754,7 +753,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n"); return SWITCH_STATUS_TERM; } - + /* connect my internal structure to the blank pointer passed to me */ *interface = &exosip_module_interface; @@ -792,16 +791,16 @@ static switch_status exosip_create_call(eXosip_event_t *event) switch_core_session_destroy(&session); return SWITCH_STATUS_MEMERR; } - + if ((tech_pvt->caller_profile = switch_caller_profile_new(session, - globals.dialplan, - event->request->from->displayname, - event->request->from->url->username, - event->request->from->url->host, - NULL, - NULL, - event->request->req_uri->username))) { - switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); + globals.dialplan, + event->request->from->displayname, + event->request->from->url->username, + event->request->from->url->host, + NULL, + NULL, + event->request->req_uri->username))) { + switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); } switch_set_flag(tech_pvt, TFLAG_INBOUND); @@ -811,7 +810,7 @@ static switch_status exosip_create_call(eXosip_event_t *event) snprintf(name, sizeof(name), "Exosip/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff); switch_channel_set_name(channel, name); - + if (!(remote_sdp = eXosip_get_sdp_info(event->request))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Find Remote SDP!\n"); exosip_on_hangup(session); @@ -823,7 +822,7 @@ static switch_status exosip_create_call(eXosip_event_t *event) tech_pvt->local_sdp_audio_port = next_rtp_port(); osip_rfc3264_init(&tech_pvt->sdp_config); /* Add in what codecs we support locally */ - + if ((num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) { int i; static const switch_codec_implementation *imp; @@ -841,7 +840,7 @@ static switch_status exosip_create_call(eXosip_event_t *event) sdp_message_to_str(remote_sdp, &remote_sdp_str); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str,remote_sdp_str); - + mline = 0; while (0==osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) { if (audio_tab[0] == NULL && video_tab[0] == NULL && t38_tab[0] == NULL && app_tab[0] == NULL) { @@ -870,7 +869,7 @@ static switch_status exosip_create_call(eXosip_event_t *event) snprintf(tech_pvt->remote_sdp_audio_ip, 50, conn->c_addr); tech_pvt->remote_sdp_audio_port = atoi(remote_med->m_port); - + snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", event->cid); switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); @@ -887,28 +886,28 @@ static switch_status exosip_create_call(eXosip_event_t *event) int rate = atoi(drate); if (switch_core_codec_init(&tech_pvt->read_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 { - 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) { + 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 { + 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 { int ms; tech_pvt->read_frame.rate = rate; @@ -921,9 +920,9 @@ static switch_status exosip_create_call(eXosip_event_t *event) } } } - + activate_rtp(tech_pvt); - + if (switch_test_flag(tech_pvt, TFLAG_RTP)) { switch_core_session_thread_launch(session); } else { @@ -955,7 +954,7 @@ static void destroy_call_by_event(eXosip_event_t *event) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "destroy %s\n", switch_channel_get_name(channel)); exosip_kill_channel(tech_pvt->session, SWITCH_SIG_KILL); switch_channel_hangup(channel); - + } static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload) @@ -1045,35 +1044,35 @@ static void handle_answer(eXosip_event_t *event) /* Assign them thar IDs */ tech_pvt->did = event->did; tech_pvt->tid = event->tid; - + if (1) { int rate = atoi(drate); if (switch_core_codec_init(&tech_pvt->read_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 { - 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) { + 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 { + 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 { int ms; tech_pvt->read_frame.rate = rate; @@ -1092,7 +1091,7 @@ static void handle_answer(eXosip_event_t *event) eXosip_call_build_ack(event->did, &ack); eXosip_call_send_ack(event->did, ack); eXosip_unlock(); - + free(dname); free(drate); free(dpayload); @@ -1119,121 +1118,121 @@ static void log_event(eXosip_event_t *je) } else if (je->type == EXOSIP_CALL_RELEASED) { snprintf (buf, 99, "<- (%i %i) Call released", je->cid, je->did); } else if (je->type == EXOSIP_MESSAGE_NEW - && je->request!=NULL && MSG_IS_MESSAGE(je->request)) { - char *tmp = NULL; - - if (je->request != NULL) { - osip_body_t *body; - osip_from_to_str (je->request->from, &tmp); - - osip_message_get_body (je->request, 0, &body); - if (body != NULL && body->body != NULL) { - snprintf (buf, 99, "<- (%i) from: %s TEXT: %s", - je->tid, tmp, body->body); + && je->request!=NULL && MSG_IS_MESSAGE(je->request)) { + char *tmp = NULL; + + if (je->request != NULL) { + osip_body_t *body; + osip_from_to_str (je->request->from, &tmp); + + osip_message_get_body (je->request, 0, &body); + if (body != NULL && body->body != NULL) { + snprintf (buf, 99, "<- (%i) from: %s TEXT: %s", + 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) { char *tmp = NULL; - + osip_from_to_str (je->request->from, &tmp); snprintf (buf, 99, "<- (%i) %s from: %s", - je->tid, je->request->sip_method, tmp); + je->tid, je->request->sip_method, tmp); osip_free (tmp); } else if (je->type == EXOSIP_MESSAGE_PROCEEDING - || je->type == EXOSIP_MESSAGE_ANSWERED - || je->type == EXOSIP_MESSAGE_REDIRECTED - || je->type == EXOSIP_MESSAGE_REQUESTFAILURE - || je->type == EXOSIP_MESSAGE_SERVERFAILURE - || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) { - if (je->response != NULL && je->request != NULL) { - char *tmp = NULL; - - osip_to_to_str (je->request->to, &tmp); - snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s", - je->tid, je->response->status_code, - je->response->reason_phrase, je->request->sip_method, tmp); - osip_free (tmp); - } else if (je->request != NULL) { - snprintf (buf, 99, "<- (%i) Error for %s request", - je->tid, je->request->sip_method); - } else { - snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid); - } + || je->type == EXOSIP_MESSAGE_ANSWERED + || je->type == EXOSIP_MESSAGE_REDIRECTED + || je->type == EXOSIP_MESSAGE_REQUESTFAILURE + || je->type == EXOSIP_MESSAGE_SERVERFAILURE + || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) { + if (je->response != NULL && je->request != NULL) { + char *tmp = NULL; + + osip_to_to_str (je->request->to, &tmp); + snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s", + je->tid, je->response->status_code, + je->response->reason_phrase, je->request->sip_method, tmp); + osip_free (tmp); + } else if (je->request != NULL) { + snprintf (buf, 99, "<- (%i) Error for %s request", + je->tid, je->request->sip_method); + } else { + snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid); + } } else if (je->response == NULL && je->request != NULL && je->cid > 0) { char *tmp = NULL; - + osip_from_to_str (je->request->from, &tmp); 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); } else if (je->response != NULL && je->cid > 0) { char *tmp = NULL; - + osip_to_to_str (je->request->to, &tmp); snprintf (buf, 99, "<- (%i %i) [%i %s] for %s to: %s", - je->cid, je->did, je->response->status_code, - je->response->reason_phrase, je->request->sip_method, tmp); + je->cid, je->did, je->response->status_code, + je->response->reason_phrase, je->request->sip_method, tmp); osip_free (tmp); } else if (je->response == NULL && je->request != NULL && je->rid > 0) { char *tmp = NULL; - + osip_from_to_str (je->request->from, &tmp); snprintf (buf, 99, "<- (%i) %s from: %s", - je->rid, je->request->cseq->method, tmp); + je->rid, je->request->cseq->method, tmp); osip_free (tmp); } else if (je->response != NULL && je->rid > 0) { char *tmp = NULL; - + osip_from_to_str (je->request->from, &tmp); snprintf (buf, 99, "<- (%i) [%i %s] from: %s", - je->rid, je->response->status_code, - je->response->reason_phrase, tmp); + je->rid, je->response->status_code, + je->response->reason_phrase, tmp); osip_free (tmp); } else if (je->response == NULL && je->request != NULL && je->sid > 0) { char *tmp = NULL; char *stat = NULL; osip_header_t *sub_state; - + osip_message_header_get_byname (je->request, "subscription-state", - 0, &sub_state); + 0, &sub_state); if (sub_state != NULL && sub_state->hvalue != NULL) stat = sub_state->hvalue; - + osip_uri_to_str (je->request->from->url, &tmp); 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); } else if (je->response != NULL && je->sid > 0) { char *tmp = NULL; - + osip_uri_to_str (je->request->to->url, &tmp); snprintf (buf, 99, "<- (%i) [%i %s] from: %s", - je->sid, je->response->status_code, - je->response->reason_phrase, tmp); + je->sid, je->response->status_code, + je->response->reason_phrase, tmp); osip_free (tmp); } else if (je->response == NULL && je->request != NULL) { char *tmp = NULL; - + osip_from_to_str (je->request->from, &tmp); snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s", - je->cid, je->did, je->sid, je->nid, - je->request->sip_method, tmp); + je->cid, je->did, je->sid, je->nid, + je->request->sip_method, tmp); osip_free (tmp); } else if (je->response != NULL) { char *tmp = NULL; - + 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", - je->cid, je->did, je->sid, je->nid, - je->response->status_code, je->response->reason_phrase, - je->request->sip_method, tmp); + je->cid, je->did, je->sid, je->nid, + je->response->status_code, je->response->reason_phrase, + je->request->sip_method, tmp); osip_free (tmp); } else { 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); /* Print it out */ @@ -1244,7 +1243,7 @@ static void log_event(eXosip_event_t *je) static void *monitor_thread_run(void) { eXosip_event_t *event = NULL; - + globals.running = 1; while (globals.running > 0) { if (!(event = eXosip_event_wait(0,100))) { @@ -1259,64 +1258,64 @@ static void *monitor_thread_run(void) log_event(event); switch(event->type) { - case EXOSIP_CALL_INVITE: - exosip_create_call(event); - break; - case EXOSIP_CALL_REINVITE: - /* See what the reinvite is about - on hold or whatever */ - //handle_reinvite(event); - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got a reinvite.\n"); - break; - case EXOSIP_CALL_MESSAGE_NEW: - if (event->request != NULL && MSG_IS_REFER(event->request)) { - //handle_call_transfer(event); - } - break; - case EXOSIP_CALL_ACK: - /* If audio is not flowing and this has SDP - fire it up! */ - break; - case EXOSIP_CALL_ANSWERED: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was answered.\n"); - handle_answer(event); - break; - case EXOSIP_CALL_PROCEEDING: - /* This is like a 100 Trying... yeah */ - break; - case EXOSIP_CALL_RINGING: - //handle_ringing(event); - break; - case EXOSIP_CALL_REDIRECTED: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call was redirect\n"); - break; - case EXOSIP_CALL_CLOSED: - destroy_call_by_event(event); - break; - case EXOSIP_CALL_RELEASED: - destroy_call_by_event(event); - break; - case EXOSIP_CALL_NOANSWER: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was not answered.\n"); - destroy_call_by_event(event); - break; - case EXOSIP_CALL_REQUESTFAILURE: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Request failure\n"); - destroy_call_by_event(event); - break; - case EXOSIP_CALL_SERVERFAILURE: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Server failure\n"); - destroy_call_by_event(event); - break; - case EXOSIP_CALL_GLOBALFAILURE: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Global failure\n"); - destroy_call_by_event(event); - break; - /* Registration related stuff */ - case EXOSIP_REGISTRATION_NEW: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Received registration attempt\n"); - break; - default: - /* Unknown event... casually absorb it for now */ - break; + case EXOSIP_CALL_INVITE: + exosip_create_call(event); + break; + case EXOSIP_CALL_REINVITE: + /* See what the reinvite is about - on hold or whatever */ + //handle_reinvite(event); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got a reinvite.\n"); + break; + case EXOSIP_CALL_MESSAGE_NEW: + if (event->request != NULL && MSG_IS_REFER(event->request)) { + //handle_call_transfer(event); + } + break; + case EXOSIP_CALL_ACK: + /* If audio is not flowing and this has SDP - fire it up! */ + break; + case EXOSIP_CALL_ANSWERED: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was answered.\n"); + handle_answer(event); + break; + case EXOSIP_CALL_PROCEEDING: + /* This is like a 100 Trying... yeah */ + break; + case EXOSIP_CALL_RINGING: + //handle_ringing(event); + break; + case EXOSIP_CALL_REDIRECTED: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call was redirect\n"); + break; + case EXOSIP_CALL_CLOSED: + destroy_call_by_event(event); + break; + case EXOSIP_CALL_RELEASED: + destroy_call_by_event(event); + break; + case EXOSIP_CALL_NOANSWER: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was not answered.\n"); + destroy_call_by_event(event); + break; + case EXOSIP_CALL_REQUESTFAILURE: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Request failure\n"); + destroy_call_by_event(event); + break; + case EXOSIP_CALL_SERVERFAILURE: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Server failure\n"); + destroy_call_by_event(event); + break; + case EXOSIP_CALL_GLOBALFAILURE: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Global failure\n"); + destroy_call_by_event(event); + break; + /* Registration related stuff */ + case EXOSIP_REGISTRATION_NEW: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Received registration attempt\n"); + break; + default: + /* Unknown event... casually absorb it for now */ + break; } //switch_console_printf(SWITCH_CHANNEL_CONSOLE, "There was an event (%d) [%s]\n", event->type, event->textinfo); @@ -1364,7 +1363,7 @@ static int config_exosip(int reload) } } } - + if (!globals.codec_ms) { globals.codec_ms = 20; } @@ -1387,7 +1386,7 @@ static int config_exosip(int reload) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_listen_addr failed!\n"); return SWITCH_STATUS_GENERR; } - + switch_mutex_init(&globals.port_lock, SWITCH_MUTEX_NESTED, module_pool); /* Setup the user agent */ diff --git a/src/mod/mod_g711codec/mod_g711codec.c b/src/mod/mod_g711codec/mod_g711codec.c index 0bc9c57046..e1cd6fce69 100644 --- a/src/mod/mod_g711codec/mod_g711codec.c +++ b/src/mod/mod_g711codec/mod_g711codec.c @@ -39,7 +39,7 @@ static const char modname[] = "mod_g711codec"; static switch_status switch_g711u_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings) { int encoding, decoding; - + encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); decoding = (flags & SWITCH_CODEC_FLAG_DECODE); @@ -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, - switch_codec *other_codec, - void *decoded_data, - size_t decoded_data_len, - int decoded_rate, - void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *decoded_data, + size_t decoded_data_len, + int decoded_rate, + void *encoded_data, + size_t *encoded_data_len, + int *encoded_rate, + unsigned int *flag) { short *dbuf; unsigned char *ebuf; @@ -67,25 +67,25 @@ static switch_status switch_g711u_encode(switch_codec *codec, dbuf = decoded_data; ebuf = encoded_data; - + for (i = 0; i < decoded_data_len / sizeof(short); i++) { ebuf[i] = linear2ulaw(dbuf[i]); } - + *encoded_data_len = i; return SWITCH_STATUS_SUCCESS; } static switch_status switch_g711u_decode(switch_codec *codec, - switch_codec *other_codec, - void *encoded_data, - size_t encoded_data_len, - int encoded_rate, - void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *encoded_data, + size_t encoded_data_len, + int encoded_rate, + void *decoded_data, + size_t *decoded_data_len, + int *decoded_rate, + unsigned int *flag) { short *dbuf; unsigned char *ebuf; @@ -117,7 +117,7 @@ static switch_status switch_g711u_destroy(switch_codec *codec) static switch_status switch_g711a_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings) { int encoding, decoding; - + encoding = (flags & SWITCH_CODEC_FLAG_ENCODE); decoding = (flags & SWITCH_CODEC_FLAG_DECODE); @@ -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, - switch_codec *other_codec, - void *decoded_data, - size_t decoded_data_len, - int decoded_rate, - void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *decoded_data, + size_t decoded_data_len, + int decoded_rate, + void *encoded_data, + size_t *encoded_data_len, + int *encoded_rate, + unsigned int *flag) { short *dbuf; unsigned char *ebuf; @@ -145,25 +145,25 @@ static switch_status switch_g711a_encode(switch_codec *codec, dbuf = decoded_data; ebuf = encoded_data; - + for (i = 0; i < decoded_data_len / sizeof(short); i++) { ebuf[i] = linear2alaw(dbuf[i]); } - + *encoded_data_len = i; return SWITCH_STATUS_SUCCESS; } static switch_status switch_g711a_decode(switch_codec *codec, - switch_codec *other_codec, - void *encoded_data, - size_t encoded_data_len, - int encoded_rate, - void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *encoded_data, + size_t encoded_data_len, + int encoded_rate, + void *decoded_data, + size_t *decoded_data_len, + int *decoded_rate, + unsigned int *flag) { short *dbuf; unsigned char *ebuf; diff --git a/src/mod/mod_iaxchan/mod_iaxchan.c b/src/mod/mod_iaxchan/mod_iaxchan.c index ee1a644801..b3faf65c5e 100644 --- a/src/mod/mod_iaxchan/mod_iaxchan.c +++ b/src/mod/mod_iaxchan/mod_iaxchan.c @@ -75,7 +75,7 @@ static struct { struct private_object { unsigned int flags; switch_codec read_codec; - switch_codec write_codec; + switch_codec write_codec; struct switch_frame read_frame; unsigned char databuf[1024]; switch_core_session *session; @@ -152,7 +152,7 @@ static unsigned int iana2ast(int iana) break; } } - + return ast; } @@ -174,12 +174,12 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s if (globals.codec_string) { if (!(num_codecs = loadable_module_get_codecs_sorted(switch_core_session_get_pool(tech_pvt->session), - codecs, - SWITCH_MAX_CODECS, - globals.codec_order, - globals.codec_order_last)) > 0) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n"); - return SWITCH_STATUS_GENERR; + codecs, + SWITCH_MAX_CODECS, + globals.codec_order, + globals.codec_order_last)) > 0) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n"); + 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) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n"); @@ -193,7 +193,7 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s } local_cap |= codec; } - + if (io == IAX_SET) { mixed_cap = (local_cap & *cababilities); } else { @@ -219,14 +219,14 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s if (len) { /*they sent us a pref and we don't want to be codec master*/ char pref_str[256] = "("; - + for (x = 0; x < len; x++) { strncat(pref_str, ast2str(prefs[x]), sizeof(pref_str)); strncat(pref_str, x == len - 1 ? ")" : ",", sizeof(pref_str)); } switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec Prefs Detected: %s\n", pref_str); - + for (x = 0; x < len; x++) { if ((prefs[x] & mixed_cap)) { int z; @@ -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); } if (switch_core_codec_init(&tech_pvt->read_codec, - dname, - 0, - 0, - 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"); - return SWITCH_STATUS_GENERR; + dname, + 0, + 0, + 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"); + return SWITCH_STATUS_GENERR; } else { if (switch_core_codec_init(&tech_pvt->write_codec, - dname, - 0, - 0, - 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_core_codec_destroy(&tech_pvt->read_codec); - return SWITCH_STATUS_GENERR; + dname, + 0, + 0, + 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_core_codec_destroy(&tech_pvt->read_codec); + return SWITCH_STATUS_GENERR; } else { int ms; 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 - 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. +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 +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) { @@ -364,7 +364,7 @@ static switch_status channel_on_init(switch_core_session *session) iax_set_private(tech_pvt->iax_session, tech_pvt); switch_set_flag(tech_pvt, TFLAG_IO); - + switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session)); switch_mutex_lock(tech_pvt->mutex); @@ -402,7 +402,7 @@ static switch_status channel_on_execute(switch_core_session *session) tech_pvt = switch_core_session_get_private(session); assert(tech_pvt != NULL); - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel)); @@ -413,7 +413,7 @@ static switch_status channel_on_hangup(switch_core_session *session) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; - + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -425,7 +425,7 @@ static switch_status channel_on_hangup(switch_core_session *session) switch_core_codec_destroy(&tech_pvt->read_codec); switch_core_codec_destroy(&tech_pvt->write_codec); - + if (tech_pvt->iax_session) { if (!switch_test_flag(tech_pvt, TFLAG_HANGUP)) { iax_hangup(tech_pvt->iax_session, "Hangup"); @@ -443,7 +443,7 @@ static switch_status channel_kill_channel(switch_core_session *session, int sig) { switch_channel *channel = NULL; struct private_object *tech_pvt = NULL; - + channel = switch_core_session_get_channel(session); assert(channel != NULL); @@ -454,10 +454,10 @@ static switch_status channel_kill_channel(switch_core_session *session, int sig) switch_clear_flag(tech_pvt, TFLAG_VOICE); switch_channel_hangup(channel); switch_thread_cond_signal(tech_pvt->cond); - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL KILL\n", switch_channel_get_name(channel)); - + return SWITCH_STATUS_SUCCESS; } @@ -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 - 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) { @@ -523,10 +523,10 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit iax_call(tech_pvt->iax_session, - caller_profile->caller_id_number, - caller_profile->caller_id_name, - caller_profile->destination_number, - NULL, 0, req, cap); + caller_profile->caller_id_number, + caller_profile->caller_id_name, + caller_profile->destination_number, + NULL, 0, req, cap); switch_channel_set_flag(channel, CF_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) @@ -592,13 +592,13 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra if (!switch_test_flag(tech_pvt, TFLAG_IO)) { return SWITCH_STATUS_FALSE; } - + if (switch_test_flag(tech_pvt, TFLAG_IO)) { switch_clear_flag(tech_pvt, TFLAG_VOICE); if(!tech_pvt->read_frame.datalen) { continue; } - + *frame = &tech_pvt->read_frame; return SWITCH_STATUS_SUCCESS; } @@ -632,7 +632,7 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr iax_send_voice(tech_pvt->iax_session, tech_pvt->codec, frame->data, (int)frame->datalen, tech_pvt->write_codec.implementation->samples_per_frame); return SWITCH_STATUS_SUCCESS; - + } static switch_status channel_answer_channel(switch_core_session *session) @@ -718,14 +718,14 @@ static switch_status load_config(void) switch_config cfg; char *var, *val; char *cf = "iax.conf"; - + memset(&globals, 0, sizeof(globals)); - + if (!switch_config_open_file(&cfg, cf)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf); return SWITCH_STATUS_TERM; } - + while (switch_config_next_pair(&cfg, &var, &val)) { if (!strcasecmp(cfg.category, "settings")) { if (!strcmp(var, "debug")) { @@ -774,13 +774,13 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Binding Port!\n"); return SWITCH_STATUS_TERM; } - + iax_set_error(iax_err_cb); - iax_set_output(iax_out_cb); - netfd = iax_get_fd(); - + iax_set_output(iax_out_cb); + netfd = iax_get_fd(); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "IAX Ready Port %d\n", globals.port); - + for(;;) { if (running == -1) { @@ -796,171 +796,171 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) if (globals.debug && iaxevent->etype != IAX_EVENT_VOICE) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Event %d [%s]!\n", - iaxevent->etype, IAXNAMES[iaxevent->etype]); + iaxevent->etype, IAXNAMES[iaxevent->etype]); } switch (iaxevent->etype) { - case IAX_EVENT_REGACK: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration completed successfully.\n"); - if (iaxevent->ies.refresh) refresh = iaxevent->ies.refresh; - break; - case IAX_EVENT_REGREJ: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration failed.\n"); - break; - case IAX_EVENT_TIMEOUT: - break; - case IAX_EVENT_ACCEPT: - if (tech_pvt) { - unsigned int cap = iax_session_get_capability(iaxevent->session); - unsigned int format = iaxevent->ies.format; - - 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); + case IAX_EVENT_REGACK: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration completed successfully.\n"); + if (iaxevent->ies.refresh) refresh = iaxevent->ies.refresh; + break; + case IAX_EVENT_REGREJ: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration failed.\n"); + break; + case IAX_EVENT_TIMEOUT: + break; + case IAX_EVENT_ACCEPT: + if (tech_pvt) { + unsigned int cap = iax_session_get_capability(iaxevent->session); + unsigned int format = iaxevent->ies.format; + + 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, "Call accepted.\n"); - break; - case IAX_EVENT_RINGA: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Ringing heard.\n"); - break; - case IAX_EVENT_PONG: - // informative only - break; - case IAX_EVENT_ANSWER: - // the other side answered our call - if (tech_pvt) { - switch_channel *channel; - 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_channel_answer(channel); + + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call accepted.\n"); + break; + case IAX_EVENT_RINGA: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Ringing heard.\n"); + break; + case IAX_EVENT_PONG: + // informative only + break; + case IAX_EVENT_ANSWER: + // the other side answered our call + if (tech_pvt) { + switch_channel *channel; + 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_channel_answer(channel); + } } - } - break; - case IAX_EVENT_CONNECT: - // incoming call detected - switch_console_printf(SWITCH_CHANNEL_CONSOLE, - "Incoming call connected %s, %s, %s %d/%d\n", - iaxevent->ies.called_number, - iaxevent->ies.calling_number, - iaxevent->ies.calling_name, - iaxevent->ies.format, - iaxevent->ies.capability); + break; + case IAX_EVENT_CONNECT: + // incoming call detected + switch_console_printf(SWITCH_CHANNEL_CONSOLE, + "Incoming call connected %s, %s, %s %d/%d\n", + iaxevent->ies.called_number, + iaxevent->ies.calling_number, + iaxevent->ies.calling_name, + iaxevent->ies.format, + iaxevent->ies.capability); - if (iaxevent) { - switch_core_session *session; - - 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))) { - struct private_object *tech_pvt; + if (iaxevent) { + switch_core_session *session; + + 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))) { + 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; - 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; + switch_clear_flag(tech_pvt, TFLAG_IO); + switch_clear_flag(tech_pvt, TFLAG_VOICE); + if ((channel = switch_core_session_get_channel(tech_pvt->session))) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hangup %s\n", switch_channel_get_name(channel)); + switch_set_flag(tech_pvt, TFLAG_HANGUP); + switch_channel_hangup(channel); + switch_thread_cond_signal(tech_pvt->cond); + iaxevent->session = NULL; } 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); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Session? %s\n", switch_test_flag(tech_pvt, TFLAG_VOICE) ? "yes" : "no"); } } - } - 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_clear_flag(tech_pvt, TFLAG_IO); - switch_clear_flag(tech_pvt, TFLAG_VOICE); - if ((channel = switch_core_session_get_channel(tech_pvt->session))) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hangup %s\n", switch_channel_get_name(channel)); - switch_set_flag(tech_pvt, TFLAG_HANGUP); - switch_channel_hangup(channel); + break; + case IAX_EVENT_CNG: + // pseudo-silence + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sending silence\n"); + break; + case IAX_EVENT_VOICE: + if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen)) { + int bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame; + int frames = (int)(tech_pvt->read_frame.datalen / bytes); + tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame; + memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen); + /* wake up the i/o thread*/ + switch_set_flag(tech_pvt, TFLAG_VOICE); 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; - case IAX_EVENT_CNG: - // pseudo-silence - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sending silence\n"); - break; - case IAX_EVENT_VOICE: - if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen)) { - int bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame; - int frames = (int)(tech_pvt->read_frame.datalen / bytes); - tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame; - memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen); - /* wake up the i/o thread*/ - switch_set_flag(tech_pvt, TFLAG_VOICE); - 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)); + } + 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); } - switch_channel_queue_dtmf(channel, str); } - } - break; - default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n", iaxevent->etype); - break; + break; + default: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n", iaxevent->etype); + break; } - + iax_event_free(iaxevent); } } - + running = 0; return SWITCH_STATUS_TERM; diff --git a/src/mod/mod_playback/mod_playback.c b/src/mod/mod_playback/mod_playback.c index 19284e52bf..757f7e7906 100644 --- a/src/mod/mod_playback/mod_playback.c +++ b/src/mod/mod_playback/mod_playback.c @@ -58,11 +58,11 @@ void playback_function(switch_core_session *session, char *data) assert(channel != NULL); if (switch_core_file_open(&fh, - data, - SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, - switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { - switch_channel_hangup(channel); - return; + data, + SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, + switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) { + switch_channel_hangup(channel); + return; } switch_channel_answer(channel); @@ -70,25 +70,25 @@ void playback_function(switch_core_session *session, char *data) write_frame.data = buf; write_frame.buflen = sizeof(buf); - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OPEN FILE %s %dhz %d channels\n", data, fh.samplerate, fh.channels); - + interval = 20; samples = (fh.samplerate / 50) * fh.channels; len = samples * 2; - + codec_name = "L16"; - + if (switch_core_codec_init(&codec, - codec_name, - fh.samplerate, - interval, - fh.channels, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, - NULL, - pool) == SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n"); - write_frame.codec = &codec; + codec_name, + fh.samplerate, + interval, + fh.channels, + SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, + NULL, + pool) == SWITCH_STATUS_SUCCESS) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n"); + write_frame.codec = &codec; } 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_core_file_close(&fh); @@ -115,7 +115,7 @@ void playback_function(switch_core_session *session, char *data) if (switch_channel_has_dtmf(channel)) { switch_channel_dequeue_dtmf(channel, dtmf, sizeof(dtmf)); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DTMF [%s]\n", dtmf); - + switch (*dtmf) { case '*': done = 1; @@ -124,17 +124,17 @@ void playback_function(switch_core_session *session, char *data) break; } } - + if (done) { break; } - + switch_core_file_read(&fh, buf, &ilen); if (ilen <= 0) { break; } - + write_frame.datalen = ilen * 2; write_frame.samples = (int)ilen; #ifdef SWAP_LINEAR @@ -149,7 +149,7 @@ void playback_function(switch_core_session *session, char *data) break; } } - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "done playing file\n"); switch_core_file_close(&fh); @@ -178,7 +178,7 @@ static const switch_loadable_module_interface mod_playback_module_interface = { }; SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) { - + /* connect my internal structure to the blank pointer passed to me */ *interface = &mod_playback_module_interface; @@ -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 - 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) diff --git a/src/mod/mod_rawaudio/mod_rawaudio.c b/src/mod/mod_rawaudio/mod_rawaudio.c index 1310a6c504..7dca8096a4 100644 --- a/src/mod/mod_rawaudio/mod_rawaudio.c +++ b/src/mod/mod_rawaudio/mod_rawaudio.c @@ -95,40 +95,6 @@ static switch_status switch_raw_destroy(switch_codec *codec) 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 = { /*.samples_per_second = */ 32000, /*.bits_per_second = */ 512000, diff --git a/src/mod/mod_woomerachan/mod_woomerachan.c b/src/mod/mod_woomerachan/mod_woomerachan.c index f974cb2eab..9ecbf59f11 100644 --- a/src/mod/mod_woomerachan/mod_woomerachan.c +++ b/src/mod/mod_woomerachan/mod_woomerachan.c @@ -150,7 +150,7 @@ struct private_object { struct woomera_profile *profile; char dest[WOOMERA_STRLEN]; int port; - struct timeval started; + switch_time_t started; int timeout; char dtmfbuf[WOOMERA_STRLEN]; switch_caller_profile *caller_profile; diff --git a/src/switch_channel.c b/src/switch_channel.c index a13090c4c1..a2ee9b891e 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -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_core_session *session, - switch_channel_state state, - switch_channel_flag flags) + switch_core_session *session, + switch_channel_state state, + switch_channel_flag flags) { assert(channel != NULL); channel->state = state; @@ -278,104 +278,104 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_set_state(switch_channel *ch /* STUB for more dev case CS_INIT: - switch(state) { + switch(state) { - case CS_NEW: - case CS_INIT: - case CS_LOOPBACK: - case CS_TRANSMIT: - case CS_RING: - case CS_EXECUTE: - case CS_HANGUP: - case CS_DONE: + case CS_NEW: + case CS_INIT: + case CS_LOOPBACK: + case CS_TRANSMIT: + case CS_RING: + case CS_EXECUTE: + case CS_HANGUP: + case CS_DONE: - default: - break; - } - break; + default: + break; + } + break; */ switch(last_state) { - case CS_NEW: - switch(state) { - default: - ok++; - break; - } - break; +case CS_NEW: + switch(state) { +default: + ok++; + break; + } + break; - case CS_INIT: - switch(state) { - case CS_LOOPBACK: - case CS_TRANSMIT: - case CS_RING: - case CS_EXECUTE: - case CS_HANGUP: - ok++; - default: - break; - } - break; +case CS_INIT: + switch(state) { +case CS_LOOPBACK: +case CS_TRANSMIT: +case CS_RING: +case CS_EXECUTE: +case CS_HANGUP: + ok++; +default: + break; + } + break; - case CS_LOOPBACK: - switch(state) { - case CS_TRANSMIT: - case CS_RING: - case CS_EXECUTE: - case CS_HANGUP: - ok++; - default: - break; - } - break; +case CS_LOOPBACK: + switch(state) { +case CS_TRANSMIT: +case CS_RING: +case CS_EXECUTE: +case CS_HANGUP: + ok++; +default: + break; + } + break; - case CS_TRANSMIT: - switch(state) { - case CS_LOOPBACK: - case CS_RING: - case CS_EXECUTE: - case CS_HANGUP: - ok++; - default: - break; - } - break; +case CS_TRANSMIT: + switch(state) { +case CS_LOOPBACK: +case CS_RING: +case CS_EXECUTE: +case CS_HANGUP: + ok++; +default: + break; + } + break; - case CS_RING: - switch(state) { - case CS_LOOPBACK: - case CS_EXECUTE: - case CS_HANGUP: - case CS_TRANSMIT: - ok++; - default: - break; - } - break; +case CS_RING: + switch(state) { +case CS_LOOPBACK: +case CS_EXECUTE: +case CS_HANGUP: +case CS_TRANSMIT: + ok++; +default: + break; + } + break; - case CS_EXECUTE: - switch(state) { - case CS_LOOPBACK: - case CS_TRANSMIT: - case CS_RING: - case CS_HANGUP: - ok++; - default: - break; - } - break; +case CS_EXECUTE: + switch(state) { +case CS_LOOPBACK: +case CS_TRANSMIT: +case CS_RING: +case CS_HANGUP: + ok++; +default: + break; + } + break; - case CS_HANGUP: - switch(state) { - case CS_DONE: - ok++; - default: - break; - } - break; +case CS_HANGUP: + switch(state) { +case CS_DONE: + ok++; +default: + break; + } + break; - default: - break; +default: + break; } @@ -406,7 +406,7 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit caller_profile = switch_channel_get_caller_profile(channel); originator_caller_profile = switch_channel_get_originator_caller_profile(channel); originatee_caller_profile = switch_channel_get_originatee_caller_profile(channel); - + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-State", (char *) switch_channel_state_name(channel->state)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Name", switch_channel_get_name(channel)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Unique-ID", switch_core_session_get_uuid(channel->session)); @@ -416,7 +416,7 @@ SWITCH_DECLARE(void) switch_channel_event_set_data(switch_channel *channel, swit if (caller_profile) { switch_caller_profile_event_set_data(caller_profile, "Caller", event); } - + /* Index Originator's Profile */ if (originator_caller_profile) { switch_caller_profile_event_set_data(originator_caller_profile, "Originator", event); diff --git a/src/switch_console.c b/src/switch_console.c index 96f5c28d5a..bd958f3dab 100644 --- a/src/switch_console.c +++ b/src/switch_console.c @@ -34,8 +34,8 @@ static int switch_console_process(char *cmd) { -char *arg = NULL; - char retbuf[1024] = ""; + char *arg = NULL; + char retbuf[1024] = ""; #ifdef EMBED_PERL 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")) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, - "\n" - "Valid Commands:\n\n" - "help - umm yeah..\n" - "%sshutdown - stop the program\n\n", - perlhelp - ); + "\n" + "Valid Commands:\n\n" + "help - umm yeah..\n" + "%sshutdown - stop the program\n\n", + perlhelp + ); 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 && - switch_event_running() == 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-File", "%s", filep); - 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_fire(&event); + switch_event_running() == 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-File", "%s", filep); + 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_fire(&event); } free(data); } diff --git a/src/switch_core.c b/src/switch_core.c index 6c0013922a..ee97640ebb 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -146,7 +146,7 @@ SWITCH_DECLARE(switch_core_db *) switch_core_db_open_file(char *filename) { switch_core_db *db; char path[1024]; - + db_pick_path(filename, path, sizeof(path)); if (switch_core_db_open(path, &db)) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "SQL ERR [%s]\n", switch_core_db_errmsg(db)); @@ -161,13 +161,13 @@ SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel channel) FILE *handle = stdout; switch (channel) { - case SWITCH_CHANNEL_ID_CONSOLE: - case SWITCH_CHANNEL_ID_CONSOLE_CLEAN: - handle = runtime.console; - break; - default: - handle = stdout; - break; +case SWITCH_CHANNEL_ID_CONSOLE: +case SWITCH_CHANNEL_ID_CONSOLE_CLEAN: + handle = runtime.console; + break; +default: + handle = stdout; + break; } 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) && (!ms || ms == (iptr->microseconds_per_frame / 1000)) && (!channels || channels == iptr->number_of_channels)) { - implementation = iptr; - break; + implementation = iptr; + 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_codec *other_codec, - void *decoded_data, - size_t decoded_data_len, - int decoded_rate, - void *encoded_data, - size_t *encoded_data_len, - int *encoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *decoded_data, + size_t decoded_data_len, + int decoded_rate, + void *encoded_data, + size_t *encoded_data_len, + int *encoded_rate, + unsigned int *flag) { assert(codec != 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_codec *other_codec, - void *encoded_data, - size_t encoded_data_len, - int encoded_rate, - void *decoded_data, - size_t *decoded_data_len, - int *decoded_rate, - unsigned int *flag) + switch_codec *other_codec, + void *encoded_data, + size_t encoded_data_len, + int encoded_rate, + void *decoded_data, + size_t *decoded_data_len, + int *decoded_rate, + unsigned int *flag) { assert(codec != 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)); 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; } ext++; @@ -344,15 +344,15 @@ SWITCH_DECLARE(switch_status) switch_core_file_open(switch_file_handle *fh, char switch_console_printf(SWITCH_CHANNEL_CONSOLE, "invalid file format [%s]!\n", ext); return SWITCH_STATUS_GENERR; } - + fh->flags = flags; if (pool) { fh->memory_pool = pool; } else { if ((status = switch_core_new_memory_pool(&fh->memory_pool)) != SWITCH_STATUS_SUCCESS) { - return status; - } - switch_set_flag(fh, SWITCH_TIMER_FLAG_FREE_POOL); + return status; + } + switch_set_flag(fh, SWITCH_TIMER_FLAG_FREE_POOL); } return fh->file_interface->file_open(fh, file_path); @@ -361,14 +361,14 @@ SWITCH_DECLARE(switch_status) switch_core_file_open(switch_file_handle *fh, char SWITCH_DECLARE(switch_status) switch_core_file_read(switch_file_handle *fh, void *data, size_t *len) { assert(fh != NULL); - + return fh->file_interface->file_read(fh, data, len); } SWITCH_DECLARE(switch_status) switch_core_file_write(switch_file_handle *fh, void *data, size_t *len) { assert(fh != NULL); - + return fh->file_interface->file_write(fh, data, len); } @@ -458,14 +458,14 @@ static void *switch_core_service_thread(switch_thread *thread, void *obj) while(data->running > 0) { switch(switch_core_session_read_frame(session, &read_frame, -1)) { - case SWITCH_STATUS_SUCCESS: - break; - case SWITCH_STATUS_TIMEOUT: - break; - default: - data->running = -1; - continue; - break; +case SWITCH_STATUS_SUCCESS: + break; +case SWITCH_STATUS_TIMEOUT: + break; +default: + data->running = -1; + continue; + break; } 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 - 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) { 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 - 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) { @@ -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, - char *endpoint_name, - switch_caller_profile *caller_profile, - switch_core_session **new_session) + char *endpoint_name, + switch_caller_profile *caller_profile, + switch_core_session **new_session) { struct switch_io_event_hook_outgoing_channel *ptr; 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; session->raw_read_frame.datalen = session->raw_read_frame.buflen; status = switch_core_codec_decode(read_frame->codec, - session->read_codec, - read_frame->data, - read_frame->datalen, - read_frame->rate, - session->raw_read_frame.data, - &session->raw_read_frame.datalen, - &session->raw_read_frame.rate, - &flag); + session->read_codec, + read_frame->data, + read_frame->datalen, + read_frame->rate, + session->raw_read_frame.data, + &session->raw_read_frame.datalen, + &session->raw_read_frame.rate, + &flag); switch (status) { - case SWITCH_STATUS_RESAMPLE: - if (!session->read_resampler) { - switch_resample_create(&session->read_resampler, - read_frame->codec->implementation->samples_per_second, - read_frame->codec->implementation->bytes_per_frame * 10, - session->read_codec->implementation->samples_per_second, - session->read_codec->implementation->bytes_per_frame * 10, - session->pool); - } - case SWITCH_STATUS_SUCCESS: - read_frame = &session->raw_read_frame; - break; - case SWITCH_STATUS_NOOP: - status = SWITCH_STATUS_SUCCESS; - break; - default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name); - return status; - break; +case SWITCH_STATUS_RESAMPLE: + if (!session->read_resampler) { + switch_resample_create(&session->read_resampler, + read_frame->codec->implementation->samples_per_second, + read_frame->codec->implementation->bytes_per_frame * 10, + session->read_codec->implementation->samples_per_second, + session->read_codec->implementation->bytes_per_frame * 10, + session->pool); + } +case SWITCH_STATUS_SUCCESS: + read_frame = &session->raw_read_frame; + break; +case SWITCH_STATUS_NOOP: + status = SWITCH_STATUS_SUCCESS; + break; +default: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name); + return status; + break; } } if (session->read_resampler) { @@ -778,36 +778,36 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session enc_frame = *frame; } else { session->raw_read_frame.datalen = switch_buffer_read(session->raw_read_buffer, - session->raw_read_frame.data, - session->read_codec->implementation->bytes_per_frame); + session->raw_read_frame.data, + session->read_codec->implementation->bytes_per_frame); session->raw_read_frame.rate = session->read_codec->implementation->samples_per_second; enc_frame = &session->raw_read_frame; } session->enc_read_frame.datalen = session->enc_read_frame.buflen; status = switch_core_codec_encode(session->read_codec, - (*frame)->codec, - session->raw_read_frame.data, - session->raw_read_frame.datalen, - session->raw_read_frame.rate, - session->enc_read_frame.data, - &session->enc_read_frame.datalen, - &session->enc_read_frame.rate, - &flag); + (*frame)->codec, + session->raw_read_frame.data, + session->raw_read_frame.datalen, + session->raw_read_frame.rate, + session->enc_read_frame.data, + &session->enc_read_frame.datalen, + &session->enc_read_frame.rate, + &flag); switch (status) { - case SWITCH_STATUS_SUCCESS: - *frame = &session->enc_read_frame; - break; - case SWITCH_STATUS_NOOP: - *frame = &session->raw_read_frame; - status = SWITCH_STATUS_SUCCESS; - break; - default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); - *frame = NULL; - status = SWITCH_STATUS_GENERR; - break; +case SWITCH_STATUS_SUCCESS: + *frame = &session->enc_read_frame; + break; +case SWITCH_STATUS_NOOP: + *frame = &session->raw_read_frame; + status = SWITCH_STATUS_SUCCESS; + break; +default: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); + *frame = NULL; + status = SWITCH_STATUS_GENERR; + break; } } } @@ -857,38 +857,38 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio if (frame->codec) { session->raw_write_frame.datalen = session->raw_write_frame.buflen; status = switch_core_codec_decode(frame->codec, - session->write_codec, - frame->data, - frame->datalen, - frame->rate, - session->raw_write_frame.data, - &session->raw_write_frame.datalen, - &session->raw_write_frame.rate, - &flag); + session->write_codec, + frame->data, + frame->datalen, + frame->rate, + session->raw_write_frame.data, + &session->raw_write_frame.datalen, + &session->raw_write_frame.rate, + &flag); switch (status) { - case SWITCH_STATUS_RESAMPLE: - write_frame = &session->raw_write_frame; - if (!session->write_resampler) { - status = switch_resample_create(&session->write_resampler, - frame->codec->implementation->samples_per_second, - frame->codec->implementation->bytes_per_frame * 10, - session->write_codec->implementation->samples_per_second, - session->write_codec->implementation->bytes_per_frame * 10, - session->pool); - } - break; - case SWITCH_STATUS_SUCCESS: - write_frame = &session->raw_write_frame; - break; - case SWITCH_STATUS_NOOP: - write_frame = frame; - status = SWITCH_STATUS_SUCCESS; - break; - default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name); - return status; - break; +case SWITCH_STATUS_RESAMPLE: + write_frame = &session->raw_write_frame; + if (!session->write_resampler) { + status = switch_resample_create(&session->write_resampler, + frame->codec->implementation->samples_per_second, + frame->codec->implementation->bytes_per_frame * 10, + session->write_codec->implementation->samples_per_second, + session->write_codec->implementation->bytes_per_frame * 10, + session->pool); + } + break; +case SWITCH_STATUS_SUCCESS: + write_frame = &session->raw_write_frame; + break; +case SWITCH_STATUS_NOOP: + write_frame = frame; + status = SWITCH_STATUS_SUCCESS; + break; +default: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name); + return status; + break; } } 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) { int bytes = session->write_codec->implementation->bytes_per_frame * 10; switch_console_printf(SWITCH_CHANNEL_CONSOLE, - "Engaging Write Buffer at %d bytes to accomidate %d->%d\n", - bytes, - write_frame->datalen, - session->write_codec->implementation->bytes_per_frame); + "Engaging Write Buffer at %d bytes to accomidate %d->%d\n", + bytes, + write_frame->datalen, + session->write_codec->implementation->bytes_per_frame); 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"); 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; status = switch_core_codec_encode(session->write_codec, - frame->codec, - enc_frame->data, - enc_frame->datalen, - enc_frame->rate, - session->enc_write_frame.data, - &session->enc_write_frame.datalen, - &session->enc_write_frame.rate, - &flag); + frame->codec, + enc_frame->data, + enc_frame->datalen, + enc_frame->rate, + session->enc_write_frame.data, + &session->enc_write_frame.datalen, + &session->enc_write_frame.rate, + &flag); switch (status) { - case SWITCH_STATUS_SUCCESS: - write_frame = &session->enc_write_frame; - break; - case SWITCH_STATUS_NOOP: - write_frame = enc_frame; - status = SWITCH_STATUS_SUCCESS; - break; - default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); - write_frame = NULL; - return status; - break; +case SWITCH_STATUS_SUCCESS: + write_frame = &session->enc_write_frame; + break; +case SWITCH_STATUS_NOOP: + write_frame = enc_frame; + status = SWITCH_STATUS_SUCCESS; + break; +default: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); + write_frame = NULL; + return status; + break; } 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; for (x = 0; x < frames; x++) { if ((session->raw_write_frame.datalen = - switch_buffer_read(session->raw_write_buffer, - session->raw_write_frame.data, - bytes))) { + switch_buffer_read(session->raw_write_buffer, + session->raw_write_frame.data, + bytes))) { - enc_frame = &session->raw_write_frame; - session->raw_write_frame.rate = session->write_codec->implementation->samples_per_second; - session->enc_write_frame.datalen = session->enc_write_frame.buflen; - status = switch_core_codec_encode(session->write_codec, - frame->codec, - enc_frame->data, - enc_frame->datalen, - enc_frame->rate, - session->enc_write_frame.data, - &session->enc_write_frame.datalen, - &session->enc_write_frame.rate, - &flag); + enc_frame = &session->raw_write_frame; + session->raw_write_frame.rate = session->write_codec->implementation->samples_per_second; + session->enc_write_frame.datalen = session->enc_write_frame.buflen; + status = switch_core_codec_encode(session->write_codec, + frame->codec, + enc_frame->data, + enc_frame->datalen, + enc_frame->rate, + session->enc_write_frame.data, + &session->enc_write_frame.datalen, + &session->enc_write_frame.rate, + &flag); - switch (status) { - case SWITCH_STATUS_SUCCESS: - write_frame = &session->enc_write_frame; - break; - case SWITCH_STATUS_NOOP: - write_frame = enc_frame; - status = SWITCH_STATUS_SUCCESS; - break; - default: - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); - write_frame = NULL; - return status; - break; - } - status = perform_write(session, write_frame, timeout, io_flag); + switch (status) { +case SWITCH_STATUS_SUCCESS: + write_frame = &session->enc_write_frame; + break; +case SWITCH_STATUS_NOOP: + write_frame = enc_frame; + status = SWITCH_STATUS_SUCCESS; + break; +default: + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name); + write_frame = NULL; + return status; + break; + } + status = perform_write(session, write_frame, timeout, io_flag); } } return status; @@ -1298,7 +1298,7 @@ static void switch_core_standard_on_init(switch_core_session *session) static void switch_core_standard_on_hangup(switch_core_session *session) { - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Standard HANGUP %s\n", switch_channel_get_name(session->channel)); } @@ -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) { @@ -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) { 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))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Application %s\n", extension->current_application->application_name); 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; /* - Life of the channel. you have channel and pool in your session - everywhere you go you use the session to malloc with - switch_core_session_alloc(session, ) + Life of the channel. you have channel and pool in your session + everywhere you go you use the session to malloc with + switch_core_session_alloc(session, ) - 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 + 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 - 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 + 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 - 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 ) { - case CS_NEW: /* Just created, Waiting for first instructions */ - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State NEW\n"); - break; - case CS_DONE: - continue; - break; - case CS_HANGUP: /* Deactivate and end the thread */ - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State HANGUP\n"); - if (!driver_event_handlers->on_hangup || - (driver_event_handlers->on_hangup && - driver_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - if (!application_event_handlers || !application_event_handlers->on_hangup || - (application_event_handlers->on_hangup && - application_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - switch_core_standard_on_hangup(session); - } - } - switch_channel_set_state(session->channel, CS_DONE); - break; - case CS_INIT: /* Basic setup tasks */ - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State INIT\n"); - if (!driver_event_handlers->on_init || - (driver_event_handlers->on_init && - driver_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - if (!application_event_handlers || !application_event_handlers->on_init || - (application_event_handlers->on_init && - application_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - switch_core_standard_on_init(session); - } - } - break; - case CS_RING: /* Look for a dialplan and find something to do */ - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State RING\n"); - if (!driver_event_handlers->on_ring || - (driver_event_handlers->on_ring && - driver_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - if (!application_event_handlers || !application_event_handlers->on_ring || - (application_event_handlers->on_ring && - application_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - switch_core_standard_on_ring(session); - } - } - break; - case CS_EXECUTE: /* Execute an Operation*/ - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State EXECUTE\n"); - if (!driver_event_handlers->on_execute || - (driver_event_handlers->on_execute && - driver_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - if (!application_event_handlers || !application_event_handlers->on_execute || - (application_event_handlers->on_execute && - application_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - switch_core_standard_on_execute(session); - } - } - break; - case CS_LOOPBACK: /* loop all data back to source */ - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State LOOPBACK\n"); - if (!driver_event_handlers->on_loopback || - (driver_event_handlers->on_loopback && - driver_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - if (!application_event_handlers || !application_event_handlers->on_loopback || - (application_event_handlers->on_loopback && - application_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - switch_core_standard_on_loopback(session); - } - } - break; - case CS_TRANSMIT: /* send/recieve data to/from another channel */ - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State TRANSMIT\n"); - if (!driver_event_handlers->on_transmit || - (driver_event_handlers->on_transmit && - driver_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - if (!application_event_handlers || !application_event_handlers->on_transmit || - (application_event_handlers->on_transmit && - application_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS && - midstate == switch_channel_get_state(session->channel))) { - switch_core_standard_on_transmit(session); - } - } - break; +case CS_NEW: /* Just created, Waiting for first instructions */ + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State NEW\n"); + break; +case CS_DONE: + continue; + break; +case CS_HANGUP: /* Deactivate and end the thread */ + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State HANGUP\n"); + if (!driver_event_handlers->on_hangup || + (driver_event_handlers->on_hangup && + driver_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + if (!application_event_handlers || !application_event_handlers->on_hangup || + (application_event_handlers->on_hangup && + application_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + switch_core_standard_on_hangup(session); + } + } + switch_channel_set_state(session->channel, CS_DONE); + break; +case CS_INIT: /* Basic setup tasks */ + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State INIT\n"); + if (!driver_event_handlers->on_init || + (driver_event_handlers->on_init && + driver_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + if (!application_event_handlers || !application_event_handlers->on_init || + (application_event_handlers->on_init && + application_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + switch_core_standard_on_init(session); + } + } + break; +case CS_RING: /* Look for a dialplan and find something to do */ + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State RING\n"); + if (!driver_event_handlers->on_ring || + (driver_event_handlers->on_ring && + driver_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + if (!application_event_handlers || !application_event_handlers->on_ring || + (application_event_handlers->on_ring && + application_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + switch_core_standard_on_ring(session); + } + } + break; +case CS_EXECUTE: /* Execute an Operation*/ + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State EXECUTE\n"); + if (!driver_event_handlers->on_execute || + (driver_event_handlers->on_execute && + driver_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + if (!application_event_handlers || !application_event_handlers->on_execute || + (application_event_handlers->on_execute && + application_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + switch_core_standard_on_execute(session); + } + } + break; +case CS_LOOPBACK: /* loop all data back to source */ + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State LOOPBACK\n"); + if (!driver_event_handlers->on_loopback || + (driver_event_handlers->on_loopback && + driver_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + if (!application_event_handlers || !application_event_handlers->on_loopback || + (application_event_handlers->on_loopback && + application_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + switch_core_standard_on_loopback(session); + } + } + break; +case CS_TRANSMIT: /* send/recieve data to/from another channel */ + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State TRANSMIT\n"); + if (!driver_event_handlers->on_transmit || + (driver_event_handlers->on_transmit && + driver_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + if (!application_event_handlers || !application_event_handlers->on_transmit || + (application_event_handlers->on_transmit && + application_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS && + midstate == switch_channel_get_state(session->channel))) { + switch_core_standard_on_transmit(session); + } + } + break; } 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 - 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 - neither the core nor the calling module know anything about each other. +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 +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 - to make sure that is the case. +This thread is expected to never exit until the application exits so the func is responsible +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 - 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 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 +the core to have any clue and keeping switch_loadable_module.c from needing any thread code. */ @@ -1605,10 +1605,10 @@ SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void switch_threadattr_detach_set(thd_attr, 1); if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n"); - return; - } - + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n"); + return; + } + if (!(ts = switch_core_alloc(pool, sizeof(*ts)))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory\n"); } else { @@ -1616,11 +1616,11 @@ SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void ts->objs[0] = obj; switch_thread_create(&thread, - thd_attr, - func, - ts, - ts->pool - ); + thd_attr, + func, + ts, + 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); if (switch_thread_create(&thread, - thd_attr, - switch_core_session_thread, - session, - session->pool - ) != APR_SUCCESS) { - switch_core_session_destroy(&session); + thd_attr, + switch_core_session_thread, + session, + session->pool + ) != APR_SUCCESS) { + 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_thread_create(&thread, - thd_attr, - func, - obj, - session->pool - ); + thd_attr, + func, + obj, + 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); /* 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_format(session->uuid_str, &uuid); @@ -1735,7 +1735,7 @@ SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_e session->raw_write_frame.buflen = sizeof(session->raw_write_buf); session->raw_read_frame.data = session->raw_read_buf; session->raw_read_frame.buflen = sizeof(session->raw_read_buf); - + session->enc_write_frame.data = session->enc_write_buf; session->enc_write_frame.buflen = sizeof(session->enc_write_buf); @@ -1744,7 +1744,7 @@ SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_e switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED ,session->pool); switch_thread_cond_create(&session->cond, session->pool); - + return session; } @@ -1766,13 +1766,13 @@ static void core_event_handler (switch_event *event) char buf[1024]; switch(event->event_id) { - case SWITCH_EVENT_LOG: - return; - break; - default: - switch_event_serialize(event, buf, sizeof(buf), NULL); - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nCORE EVENT\n--------------------------------\n%s\n", buf); - break; +case SWITCH_EVENT_LOG: + return; + break; +default: + switch_event_serialize(event, buf, sizeof(buf), NULL); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nCORE EVENT\n--------------------------------\n%s\n", buf); + break; } } diff --git a/src/switch_event.c b/src/switch_event.c index b581eae419..a0aa802617 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -76,7 +76,7 @@ static void *locked_dup(char *str) dup = switch_core_strdup(THRUNTIME_POOL, str); switch_mutex_unlock(POOL_LOCK); /* ----------------------------------------------*/ - + return dup; } #define ALLOC(size) locked_alloc(size) @@ -84,7 +84,7 @@ static void *locked_dup(char *str) #endif /* 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[] = { "CUSTOM", @@ -106,7 +106,7 @@ static int switch_events_match(switch_event *event, switch_event_node *node) { int match = 0; - + if (node->event_id == SWITCH_EVENT_ALL) { match++; @@ -178,7 +178,7 @@ static void * SWITCH_THREAD_FUNC switch_event_thread(switch_thread *thread, void node->callback(out_event); } } - + if (e == SWITCH_EVENT_ALL) { break; } @@ -224,9 +224,9 @@ SWITCH_DECLARE(switch_status) switch_event_reserve_subclass_detailed(char *owner subclass->owner = switch_core_strdup(RUNTIME_POOL, owner); subclass->name = switch_core_strdup(RUNTIME_POOL, subclass_name); - + switch_core_hash_insert(CUSTOM_HASH, subclass->name, subclass); - + return SWITCH_STATUS_SUCCESS; } @@ -243,23 +243,23 @@ SWITCH_DECLARE(switch_status) switch_event_shutdown(void) SWITCH_DECLARE(switch_status) switch_event_init(switch_memory_pool *pool) { - switch_thread *thread; - switch_threadattr_t *thd_attr;; - switch_threadattr_create(&thd_attr, pool); - switch_threadattr_detach_set(thd_attr, 1); + switch_thread *thread; + switch_threadattr_t *thd_attr;; + switch_threadattr_create(&thd_attr, pool); + switch_threadattr_detach_set(thd_attr, 1); assert(pool != NULL); RUNTIME_POOL = pool; if (switch_core_new_memory_pool(&APOOL) != SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n"); - return SWITCH_STATUS_MEMERR; - } + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n"); + return SWITCH_STATUS_MEMERR; + } if (switch_core_new_memory_pool(&BPOOL) != SWITCH_STATUS_SUCCESS) { - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n"); - return SWITCH_STATUS_MEMERR; - } + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n"); + return SWITCH_STATUS_MEMERR; + } THRUNTIME_POOL = APOOL; 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(&POOL_LOCK, SWITCH_MUTEX_NESTED, RUNTIME_POOL); switch_core_hash_init(&CUSTOM_HASH, RUNTIME_POOL); - switch_thread_create(&thread, - thd_attr, - switch_event_thread, - NULL, - RUNTIME_POOL - ); + switch_thread_create(&thread, + thd_attr, + switch_event_thread, + NULL, + RUNTIME_POOL + ); while(!THREAD_RUNNING) { 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, ...) { - int ret = 0; + int ret = 0; char data[2048]; - va_list ap; + va_list ap; va_start(ap, fmt); vsnprintf(data, sizeof(data), fmt, ap); va_end(ap); @@ -333,7 +333,7 @@ SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switc return SWITCH_STATUS_MEMERR; } else { switch_event_header *header, *hp; - + if (!(header = ALLOC(sizeof(*header)))) { return SWITCH_STATUS_MEMERR; } @@ -348,7 +348,7 @@ SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switc event->headers = header; } else { for (hp = event->headers; hp && hp->next; hp = hp->next); - + if (hp) { hp->next = header; } else { @@ -358,18 +358,18 @@ SWITCH_DECLARE(switch_status) switch_event_add_header(switch_event *event, switc return SWITCH_STATUS_SUCCESS; } - + return (ret >= 0) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR; - + } SWITCH_DECLARE(switch_status) switch_event_add_body(switch_event *event, char *fmt, ...) { - int ret = 0; + int ret = 0; char data[2048]; - va_list ap; + va_list ap; va_start(ap, fmt); vsnprintf(data, sizeof(data), fmt, ap); va_end(ap); @@ -380,9 +380,9 @@ SWITCH_DECLARE(switch_status) switch_event_add_body(switch_event *event, char *f event->body = DUP(data); return SWITCH_STATUS_SUCCESS; } - + return (ret >= 0) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR; - + } SWITCH_DECLARE(void) switch_event_destroy(switch_event **event) @@ -410,11 +410,11 @@ SWITCH_DECLARE(switch_status) switch_event_dup(switch_event **event, switch_even if (switch_event_create_subclass(event, todup->event_id, todup->subclass->name) != SWITCH_STATUS_SUCCESS) { return SWITCH_STATUS_GENERR; } - + (*event)->subclass = todup->subclass; (*event)->event_user_data = todup->event_user_data; (*event)->bind_user_data = todup->bind_user_data; - + for (hp = todup->headers; hp && hp->next;) { if (!(header = ALLOC(sizeof(*header)))) { return SWITCH_STATUS_MEMERR; @@ -441,9 +441,9 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char * { size_t len = 0; switch_event_header *hp; - char *data = NULL, *body = NULL; - int ret = 0; - va_list ap; + char *data = NULL, *body = NULL; + int ret = 0; + va_list ap; if (fmt) { va_start(ap, fmt); @@ -462,7 +462,7 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char * for (hp = event->headers; hp; hp = hp->next) { snprintf(buf+len, buflen-len, "%s: %s\n", hp->name, hp->value); len = strlen(buf); - + } if (data) { @@ -485,7 +485,7 @@ SWITCH_DECLARE(switch_status) switch_event_serialize(switch_event *event, char * if (data) { free(data); } - + return SWITCH_STATUS_SUCCESS; } @@ -499,7 +499,7 @@ SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func, assert(BLOCK != NULL); assert(RUNTIME_POOL != NULL); - + if (THREAD_RUNNING <= 0) { /* sorry we're closed */ switch_event_destroy(event); @@ -525,7 +525,7 @@ SWITCH_DECLARE(switch_status) switch_event_fire_detailed(char *file, char *func, if (user_data) { (*event)->event_user_data = user_data; } - + switch_queue_push(EVENT_QUEUE, *event); *event = NULL; diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index f074f06ec2..7586592eb1 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -232,7 +232,7 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init() if (!(ptr = (char *) fname)) { continue; } - + if (!strstr(fname, ext) && !strstr(fname, EXT)) { continue; } @@ -250,11 +250,11 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init() 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_core_hash_insert(loadable_modules.endpoint_hash, - (char *) ptr->interface_name, - (void *) ptr); + (char *) ptr->interface_name, + (void *) ptr); } } - + if (new_module->interface->codec_interface) { const switch_codec_implementation *impl; const switch_codec_interface *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(impl = ptr->implementations; impl ; impl = impl->next) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, - "Adding Codec '%s' (%s) %dkhz %dms\n", - ptr->iananame, - ptr->interface_name, - impl->samples_per_second, - impl->microseconds_per_frame / 1000); + "Adding Codec '%s' (%s) %dkhz %dms\n", + ptr->iananame, + ptr->interface_name, + impl->samples_per_second, + impl->microseconds_per_frame / 1000); } switch_core_hash_insert(loadable_modules.codec_hash, - (char *) ptr->iananame, - (void *) ptr); + (char *) ptr->iananame, + (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) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Dialplan '%s'\n", ptr->interface_name); switch_core_hash_insert(loadable_modules.dialplan_hash, - (char *) ptr->interface_name, - (void *) ptr); + (char *) ptr->interface_name, + (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) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Timer '%s'\n", ptr->interface_name); switch_core_hash_insert(loadable_modules.timer_hash, - (char *) ptr->interface_name, - (void *) ptr); + (char *) ptr->interface_name, + (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) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding Application '%s'\n", ptr->interface_name); switch_core_hash_insert(loadable_modules.application_hash, - (char *) ptr->interface_name, - (void *) ptr); + (char *) ptr->interface_name, + (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) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding API Function '%s'\n", ptr->interface_name); switch_core_hash_insert(loadable_modules.api_hash, - (char *) ptr->interface_name, - (void *) ptr); + (char *) ptr->interface_name, + (void *) ptr); } } @@ -327,8 +327,8 @@ SWITCH_DECLARE(switch_status) switch_loadable_module_init() for (i = 0 ; ptr->extens[i]; i++) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Adding File Format '%s'\n", ptr->extens[i]); switch_core_hash_insert(loadable_modules.file_hash, - (char *) ptr->extens[i], - (void *) ptr); + (char *) ptr->extens[i], + (void *) ptr); } } } diff --git a/src/switch_mutex.c b/src/switch_mutex.c index 4310840462..00a69150c7 100644 --- a/src/switch_mutex.c +++ b/src/switch_mutex.c @@ -32,8 +32,8 @@ #include SWITCH_DECLARE(switch_status) switch_mutex_init(switch_mutex_t **lock, - switch_lock_flag flags, - switch_memory_pool *pool) + switch_lock_flag flags, + switch_memory_pool *pool) { return (apr_thread_mutex_create(lock, flags, pool) == APR_SUCCESS) ? SWITCH_STATUS_SUCCESS : SWITCH_STATUS_GENERR; diff --git a/src/switch_resample.c b/src/switch_resample.c index ace26a4f47..5f978676b9 100644 --- a/src/switch_resample.c +++ b/src/switch_resample.c @@ -54,7 +54,7 @@ SWITCH_DECLARE(switch_status) switch_resample_create(switch_audio_resampler **ne switch_memory_pool *pool) { switch_audio_resampler *resampler; - + if (!(resampler = switch_core_alloc(pool, sizeof(*resampler)))) { return SWITCH_STATUS_MEMERR; } @@ -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) { - int o=0, srcused=0, srcpos=0, out=0; + int o=0, srcused=0, srcpos=0, out=0; - for(;;) { - int srcBlock = MIN(srclen-srcpos, srclen); - int lastFlag = (last && (srcBlock == srclen-srcpos)); - 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); + for(;;) { + int srcBlock = MIN(srclen-srcpos, srclen); + int lastFlag = (last && (srcBlock == srclen-srcpos)); + 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); srcpos += srcused; if (o >= 0) { - out += o; + out += o; } if (o < 0 || (o == 0 && srcpos == srclen)) { - break; + break; } - } - return out; + } + return out; } SWITCH_DECLARE(void) switch_resample_destroy(switch_audio_resampler *resampler) diff --git a/src/switch_utils.c b/src/switch_utils.c index 5e485b8427..557f498e40 100644 --- a/src/switch_utils.c +++ b/src/switch_utils.c @@ -72,21 +72,16 @@ SWITCH_DECLARE(switch_status) switch_socket_create_pollfd(switch_pollfd_t *poll, switch_pollset_t *pollset; switch_status status; - if ((status = switch_pollset_create(&pollset, 1, pool, flags)) != SWITCH_STATUS_SUCCESS) { return status; } - poll->desc_type = SWITCH_POLL_SOCKET; poll->reqevents = flags; poll->desc.s = sock; poll->client_data = sock; return switch_pollset_add(pollset, poll); - - - } @@ -94,62 +89,14 @@ SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms) { switch_status status; int nsds = 0; - + if ((status = switch_poll(poll, 1, &nsds, ms)) != SWITCH_STATUS_SUCCESS) { return -1; } - + 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 //this forces certain symbols to not be optimized out of the dll void include_me(void)