From a4da5e5833ae360aaf145099bfab2e6cdcbec5fc Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthony.minessale@gmail.com>
Date: Fri, 11 Dec 2009 04:18:10 +0000
Subject: [PATCH] FSCORE-510

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15902 d0543943-73ff-0310-b7d9-9358b9ac24b2
---
 src/mod/endpoints/mod_sofia/sofia_glue.c |  4 +++-
 src/switch_ivr_async.c                   | 10 +++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c
index 2c5fd2a88b..5c6ec817f1 100644
--- a/src/mod/endpoints/mod_sofia/sofia_glue.c
+++ b/src/mod/endpoints/mod_sofia/sofia_glue.c
@@ -2069,7 +2069,7 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
 		}
 		if (strcasecmp(tech_pvt->read_impl.iananame, tech_pvt->iananame) ||
 			tech_pvt->read_impl.samples_per_second != tech_pvt->rm_rate ||
-			tech_pvt->codec_ms != tech_pvt->read_impl.microseconds_per_packet) {
+			tech_pvt->codec_ms != tech_pvt->read_impl.microseconds_per_packet / 1000) {
 			
 			switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_DEBUG, "Changing Codec from %s@%dms to %s@%dms\n",
 							  tech_pvt->read_impl.iananame, tech_pvt->read_impl.microseconds_per_packet / 1000, 
@@ -2161,6 +2161,8 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
 
  end:
 	if (resetting) {
+		switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
+		switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
 		switch_core_session_unlock_codec_write(tech_pvt->session);
 		switch_core_session_unlock_codec_read(tech_pvt->session);
 	}
diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c
index 5b5e49fc43..955cd1193e 100644
--- a/src/switch_ivr_async.c
+++ b/src/switch_ivr_async.c
@@ -1554,7 +1554,7 @@ static switch_bool_t inband_dtmf_generate_callback(switch_media_bug_t *bug, void
 			}
 
 			if (!switch_buffer_inuse(pvt->audio_buffer)) {
-				while (switch_queue_trypop(pvt->digit_queue, &pop) == SWITCH_STATUS_SUCCESS) {
+				if (switch_queue_trypop(pvt->digit_queue, &pop) == SWITCH_STATUS_SUCCESS) {
 					switch_dtmf_t *dtmf = (switch_dtmf_t *) pop;
 					char buf[2] = "";
 					int duration = dtmf->duration;
@@ -1562,14 +1562,17 @@ static switch_bool_t inband_dtmf_generate_callback(switch_media_bug_t *bug, void
 					buf[0] = dtmf->digit;
 					if (duration > 8000) {
 						duration = 4000;
-						switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), SWITCH_LOG_WARNING, "%s Truncating ridiculous DTMF duration %d ms to 1/2 second.\n",
+						switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(switch_core_media_bug_get_session(bug)), 
+										  SWITCH_LOG_WARNING, "%s Truncating ridiculous DTMF duration %d ms to 1/2 second.\n",
 										  switch_channel_get_name(switch_core_session_get_channel(pvt->session)), dtmf->duration / 8);
 					}
 					pvt->ts.duration = duration;
 					teletone_run(&pvt->ts, buf);
 					free(pop);
 				}
-			} else if (switch_buffer_inuse(pvt->audio_buffer) && (bytes = switch_buffer_read(pvt->audio_buffer, frame->data, frame->datalen))) {
+			}
+
+			if (switch_buffer_inuse(pvt->audio_buffer) && (bytes = switch_buffer_read(pvt->audio_buffer, frame->data, frame->datalen))) {
 				if (bytes < frame->datalen) {
 					switch_byte_t *dp = frame->data;
 					memset(dp + bytes, 0, frame->datalen - bytes);
@@ -1581,6 +1584,7 @@ static switch_bool_t inband_dtmf_generate_callback(switch_media_bug_t *bug, void
 			} else {
 				switch_core_media_bug_set_write_replace_frame(bug, frame);
 			}
+
 			switch_mutex_unlock(pvt->mutex);
 		}
 		break;