[Freeswitch-svn] [commit] r11881 - freeswitch/trunk/src/mod/endpoints/mod_sofia

FreeSWITCH SVN anthm at freeswitch.org
Wed Feb 11 09:43:00 PST 2009


Author: anthm
Date: Wed Feb 11 11:43:00 2009
New Revision: 11881

Log:
add some stuff to tolerate more buggy switches

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	Wed Feb 11 11:43:00 2009
@@ -173,7 +173,7 @@
 	PFLAG_3PCC_PROXY,
 	PFLAG_CALLID_AS_UUID,
 	PFLAG_UUID_AS_CALLID,
-
+	PFLAG_SCROOGE,
 	PFLAG_MAX
 } PFLAGS;
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Wed Feb 11 11:43:00 2009
@@ -1561,7 +1561,11 @@
 					} else if (!strcasecmp(var, "inbound-codec-negotiation")) {
 						if (!strcasecmp(val, "greedy")) {
 							sofia_set_pflag(profile, PFLAG_GREEDY);
+						} else if (!strcasecmp(val, "scrooge")) {
+							sofia_set_pflag(profile, PFLAG_GREEDY);
+							sofia_set_pflag(profile, PFLAG_SCROOGE);
 						} else {
+							sofia_clear_pflag(profile, PFLAG_SCROOGE);
 							sofia_clear_pflag(profile, PFLAG_GREEDY);
 						}
 					} else if (!strcasecmp(var, "disable-transcoding")) {
@@ -2072,6 +2076,12 @@
 					} else if (!strcasecmp(var, "inbound-codec-negotiation")) {
 						if (!strcasecmp(val, "greedy")) {
 							sofia_set_pflag(profile, PFLAG_GREEDY);
+						} else if (!strcasecmp(val, "scrooge")) {
+							sofia_set_pflag(profile, PFLAG_GREEDY);
+							sofia_set_pflag(profile, PFLAG_SCROOGE);
+						} else {
+							sofia_clear_pflag(profile, PFLAG_SCROOGE);
+							sofia_clear_pflag(profile, PFLAG_GREEDY);
 						}
 					} else if (!strcasecmp(var, "disable-transcoding")) {
 						if (switch_true(val)) {

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	Wed Feb 11 11:43:00 2009
@@ -2271,14 +2271,21 @@
 	const char *val;
 	const char *crypto = NULL;
 	int got_crypto = 0, got_audio = 0, got_avp = 0, got_savp = 0, got_udptl = 0;
+	int scrooge = 0;
 
 	switch_assert(tech_pvt != NULL);
 
 	greedy = !!sofia_test_pflag(tech_pvt->profile, PFLAG_GREEDY);
-
-	if (!greedy) {
-		if ((val = switch_channel_get_variable(channel, "sip_codec_negotiation")) && !strcasecmp(val, "greedy")) {
-			greedy = 1;
+	scrooge = !!sofia_test_pflag(tech_pvt->profile, PFLAG_SCROOGE);
+	
+	if (!greedy || !scrooge) {
+		if ((val = switch_channel_get_variable(channel, "sip_codec_negotiation"))) {
+			if (!strcasecmp(val, "greedy")) {
+				greedy = 1;
+			} else if (!strcasecmp(val, "scrooge")) {
+				scrooge = 1;
+				greedy = 1;
+			}
 		}
 	}
 
@@ -2330,6 +2337,10 @@
 		sofia_glue_toggle_hold(tech_pvt, sendonly);
 	}
 
+	if (!dptime) {
+		dptime = 20;
+	}
+
 	for (m = sdp->sdp_media; m; m = m->m_next) {
 		sdp_connection_t *connection;
 
@@ -2533,8 +2544,9 @@
 						continue;
 					}
 
-					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Audio Codec Compare [%s:%d:%u]/[%s:%d:%u]\n",
-									  rm_encoding, map->rm_pt, (int) map->rm_rate, imp->iananame, imp->ianacode, codec_rate);
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Audio Codec Compare [%s:%d:%u:%d]/[%s:%d:%u:%d]\n",
+									  rm_encoding, map->rm_pt, (int) map->rm_rate, ptime,
+									  imp->iananame, imp->ianacode, codec_rate, imp->microseconds_per_packet / 1000);
 					if (map->rm_pt < 96) {
 						match = (map->rm_pt == imp->ianacode) ? 1 : 0;
 					} else {
@@ -2542,12 +2554,18 @@
 					}
 
 					if (match) {
-						if ((ptime && ptime * 1000 != imp->microseconds_per_packet) || 
-							map->rm_rate != codec_rate) {
-							near_rate = map->rm_rate;
-							near_match = imp;
-							match = 0;
-							continue;
+						if (scrooge) {
+							switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, 
+											  "Bah HUMBUG! Sticking with %s@%uh@%ui\n", 
+											  imp->iananame, imp->samples_per_second, imp->microseconds_per_packet / 1000);
+						} else {
+							if ((ptime && ptime * 1000 != imp->microseconds_per_packet) || 
+								map->rm_rate != codec_rate) {
+								near_rate = map->rm_rate;
+								near_match = imp;
+								match = 0;
+								continue;
+							}
 						}
 						mimp = imp;
 						break;
@@ -2561,18 +2579,18 @@
 					char *prefs[1];
 					char tmp[80];
 					int num;
-
-					switch_snprintf(tmp, sizeof(tmp), "%s@%uk@%ui", near_match->iananame, near_rate ? near_rate : near_match->samples_per_second, ptime);
-
+					
+					switch_snprintf(tmp, sizeof(tmp), "%s@%uh@%ui", near_match->iananame, near_rate ? near_rate : near_match->samples_per_second, ptime);
+					
 					prefs[0] = tmp;
 					num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1);
-
+					
 					if (num) {
 						mimp = search[0];
 					} else {
 						mimp = near_match;
 					}
-
+					
 					if (!maxptime || mimp->microseconds_per_packet / 1000 <= maxptime) {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Substituting codec %s@%ui@%uh\n",
 										  mimp->iananame, mimp->microseconds_per_packet / 1000, mimp->samples_per_second);
@@ -2581,6 +2599,7 @@
 						mimp = NULL;
 						match = 0;
 					}
+					
 				}
 
 				if (!match && greedy) {



More information about the Freeswitch-svn mailing list