From 018a3800b4cec46e0cebb6707497bac8045d654b Mon Sep 17 00:00:00 2001
From: Michael Jerris <mike@jerris.com>
Date: Mon, 17 Jan 2011 13:10:53 -0600
Subject: [PATCH] fix session timer failure when freeswitch is generating the
 sdp and there are enough dynamic codecs enabled to conflict with the 2833 pt
 (4 by default)

---
 src/mod/endpoints/mod_sofia/sofia_glue.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c
index 8a8af67ae6..dfd6a76974 100644
--- a/src/mod/endpoints/mod_sofia/sofia_glue.c
+++ b/src/mod/endpoints/mod_sofia/sofia_glue.c
@@ -377,6 +377,13 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, uint32
 
 	sofia_glue_check_dtmf_type(tech_pvt);
 
+	if (sofia_test_pflag(tech_pvt->profile, PFLAG_SUPPRESS_CNG) ||
+		((val = switch_channel_get_variable(tech_pvt->channel, "supress_cng")) && switch_true(val)) ||
+		((val = switch_channel_get_variable(tech_pvt->channel, "suppress_cng")) && switch_true(val))) {
+		use_cng = 0;
+		tech_pvt->cng_pt = 0;
+	}
+
 	if (!tech_pvt->payload_space) {
 		int i;
 
@@ -388,6 +395,13 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, uint32
 			tech_pvt->ianacodes[i] = imp->ianacode;
 			
 			if (tech_pvt->ianacodes[i] > 64) {
+				if (tech_pvt->dtmf_type == DTMF_2833 && tech_pvt->te > 95 && tech_pvt->te == tech_pvt->payload_space) {
+					tech_pvt->payload_space++;
+				}
+				if (!sofia_test_pflag(tech_pvt->profile, PFLAG_SUPPRESS_CNG) &&
+					tech_pvt->cng_pt && use_cng  && tech_pvt->cng_pt == tech_pvt->payload_space) {
+					tech_pvt->payload_space++;
+				}
 				tech_pvt->ianacodes[i] = tech_pvt->payload_space++;
 			}
 		}
@@ -401,13 +415,6 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, uint32
 		verbose_sdp = 1;
 	}
 
-	if (sofia_test_pflag(tech_pvt->profile, PFLAG_SUPPRESS_CNG) ||
-		((val = switch_channel_get_variable(tech_pvt->channel, "supress_cng")) && switch_true(val)) ||
-		((val = switch_channel_get_variable(tech_pvt->channel, "suppress_cng")) && switch_true(val))) {
-		use_cng = 0;
-		tech_pvt->cng_pt = 0;
-	}
-
 	if (!force && !ip && !sr
 		&& (switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MODE) || switch_channel_test_flag(tech_pvt->channel, CF_PROXY_MEDIA))) {
 		return;