From 726464555cf605347b1c78b66647c2bb3914adc6 Mon Sep 17 00:00:00 2001 From: Brian West Date: Fri, 18 Dec 2009 23:19:53 +0000 Subject: [PATCH] FSCORE-517 git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16003 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_module_interfaces.h | 1 + src/switch_core_codec.c | 17 +++++++++++++++-- src/switch_ivr_play_say.c | 12 ++++++------ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index 5b2d2baab4..aa3cde37e6 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -583,6 +583,7 @@ struct switch_codec { void *private_info; switch_payload_t agreed_pt; switch_mutex_t *mutex; + struct switch_codec *next; }; /*! \brief A table of settings and callbacks that define a paticular implementation of a codec */ diff --git a/src/switch_core_codec.c b/src/switch_core_codec.c index 5efac5b817..b17dcd28fa 100644 --- a/src/switch_core_codec.c +++ b/src/switch_core_codec.c @@ -97,7 +97,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s switch_channel_t *channel = switch_core_session_get_channel(session); char tmp[30]; switch_status_t status = SWITCH_STATUS_SUCCESS; - + switch_mutex_lock(session->codec_read_mutex); if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) { @@ -109,6 +109,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s session->read_codec = session->real_read_codec = codec; session->read_impl = *codec->implementation; } else { + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Push codec %s:%d\n", + switch_channel_get_name(session->channel), codec->implementation->iananame, codec->implementation->ianacode); + codec->next = session->read_codec; session->read_codec = codec; session->read_impl = *codec->implementation; } @@ -116,7 +119,17 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s if (session->read_codec == session->real_read_codec) { goto end; } - if (session->real_read_codec) { + + if (session->read_codec->next) { + switch_codec_t *old = session->read_codec; + session->read_codec = session->read_codec->next; + session->read_impl = *session->read_codec->implementation; + old->next = NULL; + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Restore previous codec %s:%d.\n", + switch_channel_get_name(session->channel), + session->read_codec->implementation->iananame, session->read_codec->implementation->ianacode); + + } else if (session->real_read_codec) { session->read_codec = session->real_read_codec; session->read_impl = *session->real_read_codec->implementation; switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Restore original codec.\n"); diff --git a/src/switch_ivr_play_say.c b/src/switch_ivr_play_say.c index c08fe92a32..a22821a95a 100644 --- a/src/switch_ivr_play_say.c +++ b/src/switch_ivr_play_say.c @@ -1081,7 +1081,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess read_impl.number_of_channels, read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) { - switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE); + switch_core_session_reset(session, SWITCH_TRUE, SWITCH_FALSE); status = SWITCH_STATUS_NOTFOUND; continue; } @@ -1159,7 +1159,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Raw Codec Activation Failed %s@%uhz %u channels %dms\n", codec_name, fh->samplerate, fh->channels, interval); switch_core_file_close(fh); - switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE); + switch_core_session_reset(session, SWITCH_TRUE, SWITCH_FALSE); status = SWITCH_STATUS_GENERR; continue; } @@ -1179,7 +1179,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Setup timer failed!\n"); switch_core_codec_destroy(&codec); switch_core_file_close(fh); - switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE); + switch_core_session_reset(session, SWITCH_TRUE, SWITCH_FALSE); status = SWITCH_STATUS_GENERR; continue; } @@ -1476,7 +1476,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess switch_safe_free(abuf); - switch_core_session_reset(session, SWITCH_FALSE, SWITCH_TRUE); + switch_core_session_reset(session, SWITCH_FALSE, SWITCH_FALSE); return status; } @@ -1513,7 +1513,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_silence(switch_core_session_ read_impl.number_of_channels, read_impl.actual_samples_per_second, SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT, NULL) != SWITCH_STATUS_SUCCESS) { - switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE); + switch_core_session_reset(session, SWITCH_TRUE, SWITCH_FALSE); return SWITCH_STATUS_NOTFOUND; } switch_zmalloc(abuf, SWITCH_RECOMMENDED_BUFFER_SIZE); @@ -2100,7 +2100,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_speak_text(switch_core_session_t *ses timer_name = switch_channel_get_variable(channel, "timer_name"); - switch_core_session_reset(session, SWITCH_FALSE, SWITCH_TRUE); + switch_core_session_reset(session, SWITCH_FALSE, SWITCH_FALSE); read_codec = switch_core_session_get_read_codec(session); rate = read_impl.actual_samples_per_second;