[Freeswitch-svn] [commit] r5304 - in freeswitch/trunk: conf src/mod/endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Sat Jun 9 22:52:25 EDT 2007


Author: anthm
Date: Sat Jun  9 22:52:23 2007
New Revision: 5304

Modified:
   freeswitch/trunk/conf/sofia.conf.xml
   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

Log:
add inbound-codec-negotiation and  channel variable to enable greedy codec negotiation

Modified: freeswitch/trunk/conf/sofia.conf.xml
==============================================================================
--- freeswitch/trunk/conf/sofia.conf.xml	(original)
+++ freeswitch/trunk/conf/sofia.conf.xml	Sat Jun  9 22:52:23 2007
@@ -50,6 +50,8 @@
 	<param name="rtp-timer-name" value="soft"/>
 	<param name="rtp-ip" value="$${bind_server_ip}"/>
 	<param name="sip-ip" value="$${bind_server_ip}"/>
+	<!--set to 'greedy' if you want your codec list to take precedence -->
+	<param name="inbound-codec-negotiation" value="generous"/>
 	<!-- if you want to send any special bind params of your own -->
 	<!--<param name="bind-params" value="transport=udp"/>-->
 

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	Sat Jun  9 22:52:23 2007
@@ -111,7 +111,8 @@
 	PFLAG_DISABLE_TRANSCODING = (1 << 6),
 	PFLAG_REWRITE_TIMESTAMPS = (1 << 7),
 	PFLAG_RUNNING = (1 << 8),
-	PFLAG_RESPAWN = (1 << 9)
+	PFLAG_RESPAWN = (1 << 9),
+	PFLAG_GREEDY = (1 << 10)
 } 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	Sat Jun  9 22:52:23 2007
@@ -797,6 +797,10 @@
 						if (switch_true(val)) {
 							profile->pflags |= PFLAG_PASS_RFC2833;
 						}
+					} else if (!strcasecmp(var, "inbound-codec-negotiation")) {
+						if (!strcasecmp(val, "greedy")) {
+							profile->pflags |= PFLAG_GREEDY;
+						}
 					} else if (!strcasecmp(var, "disable-transcoding")) {
 						if (switch_true(val)) {
 							profile->pflags |= PFLAG_DISABLE_TRANSCODING;

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	Sat Jun  9 22:52:23 2007
@@ -1042,12 +1042,25 @@
 	private_object_t *tech_pvt;
 	sdp_media_t *m;
 	sdp_attribute_t *a;
-
+	int first = 0, last = 0;
 	int ptime = 0, dptime = 0;
+	int greedy = 0, x = 0, skip = 0, mine = 0;
+	switch_channel_t *channel = NULL;
+	char *val;
 
 	tech_pvt = switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
+	channel = switch_core_session_get_channel(session);
+	assert(channel != NULL);
+	
+	greedy = !!(tech_pvt->profile->pflags & PFLAG_GREEDY);
+	
+	if (!greedy) {
+		if ((val = switch_channel_get_variable(channel, "sip_codec_negotiation")) && !strcasecmp(val, "greedy")) {
+			greedy = 1;
+		}
+	}
 
 	if ((tech_pvt->origin = switch_core_session_strdup(session, (char *) sdp->sdp_origin->o_username))) {
 		if (strstr(tech_pvt->origin, "CiscoSystemsSIP-GW-UserAgent")) {
@@ -1108,12 +1121,18 @@
 				match = 0;
 				break;
 			}
-
+			
+		greed:
+			x = 0;
 			for (map = m->m_rtpmaps; map; map = map->rm_next) {
 				int32_t i;
 				const switch_codec_implementation_t *mimp = NULL, *near_match = NULL;
 				const char *rm_encoding;
-
+				
+				if (x++ < skip) {
+					printf("skip %s\n", map->rm_encoding);
+					continue;
+				}
 
 				if (!(rm_encoding = map->rm_encoding)) {
 					rm_encoding = "";
@@ -1135,15 +1154,22 @@
 						switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_AUTO_CNG);
 					}
 				}
-
+				
 				if (match) {
 					if (te && cng_pt) {
 						break;
 					}
 					continue;
 				}
+				
+				if (greedy) {
+					first = mine;
+					last = first + 1;
+				} else {
+					first = 0; last = tech_pvt->num_codecs;
+				}
 
-				for (i = 0; i < tech_pvt->num_codecs; i++) {
+				for (i = first; i < last && i < tech_pvt->num_codecs; i++) {
 					const switch_codec_implementation_t *imp = tech_pvt->codecs[i];
 					uint32_t codec_rate = imp->samples_per_second;
 					if (imp->codec_type != SWITCH_CODEC_TYPE_AUDIO) {
@@ -1174,6 +1200,11 @@
 						match = 0;
 					}
 				}
+				
+				if (!match && greedy) {
+					skip++;
+					continue;
+				}
 
 				if (!match && near_match) {
 					const switch_codec_implementation_t *search[1];
@@ -1182,7 +1213,7 @@
 					int num;
 
 					snprintf(tmp, sizeof(tmp), "%s@%uk@%ui", near_match->iananame, near_match->samples_per_second, ptime);
-
+					
 					prefs[0] = tmp;
 					num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1);
 
@@ -1221,6 +1252,13 @@
 					}
 				}
 			}
+
+			if (!match && greedy && mine < tech_pvt->num_codecs) {
+				mine++;
+				skip = 0;
+				goto greed;
+			}
+
 		} else if (m->m_type == sdp_media_video) { 
 			sdp_rtpmap_t *map;
 			const char *rm_encoding;



More information about the Freeswitch-svn mailing list