From 88053d974040b2b404fada7dd141404c46d007d0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 2 Jul 2007 20:17:10 +0000 Subject: [PATCH] fix for everyone git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5489 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/codecs/mod_l16/mod_l16.c | 5 +-- src/mod/endpoints/mod_sofia/sofia_presence.c | 3 +- src/switch_core_io.c | 34 +++++++++++++++++--- src/switch_ivr_bridge.c | 2 +- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/mod/codecs/mod_l16/mod_l16.c b/src/mod/codecs/mod_l16/mod_l16.c index 134521c2a2..8ae98a7929 100644 --- a/src/mod/codecs/mod_l16/mod_l16.c +++ b/src/mod/codecs/mod_l16/mod_l16.c @@ -55,8 +55,9 @@ static switch_status_t switch_raw_encode(switch_codec_t *codec, uint32_t decoded_rate, void *encoded_data, uint32_t * encoded_data_len, uint32_t * encoded_rate, unsigned int *flag) { + printf("WTF %d %d\n", codec->implementation->samples_per_second , other_codec->implementation->samples_per_second ); /* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary. */ - if (codec && other_codec && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) { + if (codec && other_codec && codec->implementation && other_codec->implementation && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) { memcpy(encoded_data, decoded_data, decoded_data_len); *encoded_data_len = decoded_data_len; return SWITCH_STATUS_RESAMPLE; @@ -71,7 +72,7 @@ static switch_status_t switch_raw_decode(switch_codec_t *codec, uint32_t encoded_rate, void *decoded_data, uint32_t * decoded_data_len, uint32_t * decoded_rate, unsigned int *flag) { - if (codec && other_codec && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) { + if (codec && other_codec && codec->implementation && other_codec->implementation && codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) { memcpy(decoded_data, encoded_data, encoded_data_len); *decoded_data_len = encoded_data_len; return SWITCH_STATUS_RESAMPLE; diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index f3b5883c3b..f5353e2583 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -756,7 +756,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, free(sql); sql = switch_mprintf("insert into sip_subscriptions values ('%q','%q','%q','%q','%q','%q','%q','%q','%q','%q',%ld)", proto, from_user, from_host, to_user, to_host, event, contact_str, call_id, full_from, full_via, exp); - + assert(sql != NULL); sofia_glue_execute_sql(profile, SWITCH_FALSE, sql, NULL); free(sql); @@ -775,6 +775,7 @@ void sofia_presence_handle_sip_i_subscribe(int status, + switch_safe_free(sstr); if ((sql = switch_mprintf("select * from sip_subscriptions where user='%q' and host='%q'", to_user, to_host, to_user, to_host))) { diff --git a/src/switch_core_io.c b/src/switch_core_io.c index fefe4588a6..912d6be480 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -94,7 +94,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi { switch_io_event_hook_read_frame_t *ptr; switch_status_t status; - int need_codec, perfect, do_bugs = 0; + int need_codec, perfect, do_bugs = 0, do_resample = 0; unsigned int flag = 0; top: @@ -149,6 +149,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi goto done; } + if ((*frame)->codec->implementation->samples_per_second != session->write_codec->implementation->samples_per_second) { + do_resample = 1; + } + if (session->bugs && !need_codec) { do_bugs = 1; need_codec = 1; @@ -166,6 +170,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi session->read_codec->implementation->samples_per_second, session->raw_read_frame.data, &session->raw_read_frame.datalen, &session->raw_read_frame.rate, &flag); + if (do_resample && status == SWITCH_STATUS_SUCCESS) { + status = SWITCH_STATUS_RESAMPLE; + } + switch (status) { case SWITCH_STATUS_RESAMPLE: if (!session->read_resampler) { @@ -384,7 +392,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess switch_status_t status = SWITCH_STATUS_FALSE; switch_frame_t *enc_frame = NULL, *write_frame = frame; - unsigned int flag = 0, need_codec = 0, perfect = 0, do_bugs = 0, do_write = 0; + unsigned int flag = 0, need_codec = 0, perfect = 0, do_bugs = 0, do_write = 0, do_resample = 0; switch_io_flag_t io_flag = SWITCH_IO_FLAG_NOOP; assert(session != NULL); @@ -423,6 +431,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess need_codec = 1; } + if (frame->codec->implementation->samples_per_second != session->read_codec->implementation->samples_per_second) { + need_codec = 1; + do_resample = 1; + } + if (need_codec) { if (frame->codec) { session->raw_write_frame.datalen = session->raw_write_frame.buflen; @@ -434,6 +447,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess session->raw_write_frame.data, &session->raw_write_frame.datalen, &session->raw_write_frame.rate, &flag); + + + if (do_resample && status == SWITCH_STATUS_SUCCESS) { + status = SWITCH_STATUS_RESAMPLE; + } + switch (status) { case SWITCH_STATUS_RESAMPLE: write_frame = &session->raw_write_frame; @@ -570,7 +589,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess } } - if (perfect) { enc_frame = write_frame; session->enc_write_frame.datalen = session->enc_write_frame.buflen; @@ -630,16 +648,24 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess for (x = 0; x < frames; x++) { if ((session->raw_write_frame.datalen = (uint32_t) switch_buffer_read(session->raw_write_buffer, session->raw_write_frame.data, bytes)) != 0) { + int rate; 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; + if (frame->codec && frame->codec->implementation) { + rate = frame->codec->implementation->samples_per_second; + } else { + rate = session->write_codec->implementation->samples_per_second; + } + printf("WTF %d %d %d\n", rate, enc_frame->datalen, session->enc_write_frame.datalen); + status = switch_core_codec_encode(session->write_codec, frame->codec, enc_frame->data, enc_frame->datalen, - frame->codec->implementation->samples_per_second, + rate, session->enc_write_frame.data, &session->enc_write_frame.datalen, &session->enc_write_frame.rate, &flag); diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index 9b1a001036..710d0483de 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -187,7 +187,7 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj) switch_core_session_receive_message(session_a, &msg); switch_core_session_kill_channel(session_b, SWITCH_SIG_BREAK); - + switch_core_session_reset(session_a); switch_channel_set_variable(chan_a, SWITCH_BRIDGE_VARIABLE, NULL); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "BRIDGE THREAD DONE [%s]\n", switch_channel_get_name(chan_a)); switch_channel_clear_flag(chan_a, CF_BRIDGED);