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

Freeswitch SVN anthm at freeswitch.org
Sun Jan 28 12:37:52 EST 2007


Author: anthm
Date: Sun Jan 28 12:37:51 2007
New Revision: 4073

Modified:
   freeswitch/trunk/conf/sofia.conf.xml
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/include/switch_utils.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/switch_core.c

Log:
CODEC TWEAK

mod_sofia will now examine a variable in the channel to
see what the channel's originator was using for a codec and 
try to put that to the top of the list in the sdp.

if this new sofia profile param is set:
<param name="disable-transcoding" value="true"/>

All outbound calls will use *only* the codec that thier originator 
is using to ensure no transcoding.
(of course that could lead to a failed call where there is no way to do this, so use sparingly)



Modified: freeswitch/trunk/conf/sofia.conf.xml
==============================================================================
--- freeswitch/trunk/conf/sofia.conf.xml	(original)
+++ freeswitch/trunk/conf/sofia.conf.xml	Sun Jan 28 12:37:51 2007
@@ -38,7 +38,9 @@
 
 	<!--TTL for nonce in sip auth-->
 	<param name="nonce-ttl" value="60"/>
-
+	<!--Uncomment if you want to force the outbound leg of a bridge to only offer the codec 
+	    that the originator is using-->
+	<!--<param name="disable-transcoding" value="true"/>-->
 	<!--<param name="auth-calls" value="true"/>-->
 	<!-- on authed calls, authenticate *all* the packets not just invite -->
 	<!--<param name="auth-all-packets" value="true"/>-->

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Sun Jan 28 12:37:51 2007
@@ -82,6 +82,7 @@
 #define SWITCH_BRIDGE_VARIABLE "_bridge_to_"
 #define SWITCH_SIGNAL_BRIDGE_VARIABLE "_signal_bridge_to_"
 #define SWITCH_ORIGINATOR_VARIABLE "_originator_"
+#define SWITCH_ORIGINATOR_CODEC_VARIABLE "_originator_codec_"
 #define SWITCH_LOCAL_MEDIA_IP_VARIABLE "_local_media_ip_"
 #define SWITCH_LOCAL_MEDIA_PORT_VARIABLE "_local_media_port_"
 #define SWITCH_REMOTE_MEDIA_IP_VARIABLE "_remote_media_ip_"

Modified: freeswitch/trunk/src/include/switch_utils.h
==============================================================================
--- freeswitch/trunk/src/include/switch_utils.h	(original)
+++ freeswitch/trunk/src/include/switch_utils.h	Sun Jan 28 12:37:51 2007
@@ -62,6 +62,11 @@
 									apr_size_t *len);
 
 
+#define switch_codec2str(codec,buf,len) snprintf(buf, len, "%s@%uk@%ui", \
+                                                 codec->implementation->iananame, \
+                                                 codec->implementation->samples_per_second, \
+                                                 codec->implementation->microseconds_per_frame / 1000)
+
 #ifdef WIN32
 #define switch_is_file_path(file) (*(file +1) == ':' || *file == '/')
 #else

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Sun Jan 28 12:37:51 2007
@@ -142,7 +142,8 @@
 	PFLAG_AUTH_ALL = (1 << 2),
 	PFLAG_FULL_ID = (1 << 3),
 	PFLAG_PRESENCE = (1 << 4),
-	PFLAG_PASS_RFC2833 = (1 << 5)
+	PFLAG_PASS_RFC2833 = (1 << 5),
+    PFLAG_DISABLE_TRANSCODING = (1 << 6)
 } PFLAGS;
 
 typedef enum {
@@ -772,6 +773,8 @@
 {
     switch_channel_t *channel;
     char *codec_string = NULL;
+    char *csdyn = NULL;
+    char *ocodec = NULL;
 
 	if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
 		return;
@@ -786,11 +789,25 @@
     channel = switch_core_session_get_channel(tech_pvt->session);
     assert (channel != NULL);
 
+
     if (!(codec_string = switch_channel_get_variable(channel, "codec_string"))) {
         codec_string = tech_pvt->profile->codec_string;
     }
 
+    if ((ocodec = switch_channel_get_variable(channel, SWITCH_ORIGINATOR_CODEC_VARIABLE))) {
+        if (!codec_string || (tech_pvt->profile->pflags & PFLAG_DISABLE_TRANSCODING)) {
+            codec_string = ocodec;
+        } else {
+            if ((csdyn = switch_mprintf("%s,%s", ocodec, codec_string))) {
+                codec_string = csdyn;
+            } else {
+                codec_string = ocodec;
+            }
+        }
+    }
+
 	if (codec_string) {
+        tech_pvt->profile->codec_order_last = switch_separate_string(codec_string, ',', tech_pvt->profile->codec_order, SWITCH_MAX_CODECS);
 		tech_pvt->num_codecs = switch_loadable_module_get_codecs_sorted(tech_pvt->codecs,
 																		SWITCH_MAX_CODECS,
 																		tech_pvt->profile->codec_order,
@@ -800,6 +817,8 @@
 		tech_pvt->num_codecs = switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), tech_pvt->codecs,
 																 sizeof(tech_pvt->codecs) / sizeof(tech_pvt->codecs[0]));
 	}
+
+    switch_safe_free(csdyn);
 }
 
 
@@ -829,9 +848,10 @@
 
 	switch_core_session_set_private(session, tech_pvt);
 
-	tech_set_codecs(tech_pvt);
+
 	snprintf(name, sizeof(name), "sofia/%s/%s", profile->name, channame);
     switch_channel_set_name(channel, name);
+	//tech_set_codecs(tech_pvt);
 
 }
 
@@ -939,7 +959,8 @@
 
 	cid_name = (char *) caller_profile->caller_id_name;
 	cid_num = (char *) caller_profile->caller_id_number;
-	
+    tech_set_codecs(tech_pvt);
+
 	if ((tech_pvt->from_str = switch_mprintf("\"%s\" <sip:%s@%s>", 
 													 cid_name,
 													 cid_num,
@@ -1433,7 +1454,7 @@
 		flags |= SWITCH_RTP_FLAG_BUGGY_2833;
 	}
 
-    if (tech_pvt->profile->flags & PFLAG_PASS_RFC2833 || ((val = switch_channel_get_variable(channel, "pass_rfc2833")) && switch_true(val))) {
+    if ((tech_pvt->profile->pflags & PFLAG_PASS_RFC2833) || ((val = switch_channel_get_variable(channel, "pass_rfc2833")) && switch_true(val))) {
         flags |= SWITCH_RTP_FLAG_PASS_RFC2833;
     }
 
@@ -2205,6 +2226,7 @@
 
 	attach_private(nsession, profile, tech_pvt, dest);
 
+
 	nchannel = switch_core_session_get_channel(nsession);
 	caller_profile = switch_caller_profile_clone(nsession, outbound_profile);
 	switch_channel_set_caller_profile(nchannel, caller_profile);
@@ -4164,7 +4186,7 @@
     }
 
     attach_private(session, profile, tech_pvt, username);
-
+    tech_set_codecs(tech_pvt);
 
     channel = switch_core_session_get_channel(session);
     switch_channel_set_variable(channel, "endpoint_disposition", "INBOUND CALL");
@@ -4993,6 +5015,10 @@
 						if (switch_true(val)) {
 							profile->pflags |= PFLAG_PASS_RFC2833;
 						}
+					} else if (!strcasecmp(var, "disable-transcoding")) {
+						if (switch_true(val)) {
+							profile->pflags |= PFLAG_DISABLE_TRANSCODING;
+						}
 					} else if (!strcasecmp(var, "auth-calls")) {
 						if (switch_true(val)) {
 							profile->pflags |= PFLAG_AUTH_CALLS;
@@ -5035,7 +5061,6 @@
 						profile->max_calls = atoi(val);
 					} else if (!strcasecmp(var, "codec-prefs")) {
 						profile->codec_string = switch_core_strdup(profile->pool, val);
-						profile->codec_order_last = switch_separate_string(profile->codec_string, ',', profile->codec_order, SWITCH_MAX_CODECS);
 					} else if (!strcasecmp(var, "codec-ms")) {
 						profile->codec_ms = atoi(val);
 					} else if (!strcasecmp(var, "dtmf-duration")) {

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Sun Jan 28 12:37:51 2007
@@ -1577,10 +1577,17 @@
 
 		if (channel && peer_channel) {
 			char *export_vars, *val;
+            switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
 
-			switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VARIABLE, switch_core_session_get_uuid(session));
-			
-			/* A comma (,) separated list of variable names that should ne propagated from originator to originatee */
+            if (read_codec) {
+                char tmp[80];
+                switch_codec2str(read_codec, tmp, sizeof(tmp));
+                switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_CODEC_VARIABLE, tmp);
+            }
+
+			switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VARIABLE, switch_core_session_get_uuid(session));            
+
+            /* A comma (,) separated list of variable names that should ne propagated from originator to originatee */
 			if ((export_vars = switch_channel_get_variable(channel, "export_vars"))) {
 				char *cptmp = switch_core_session_strdup(session, export_vars);
 				int argc;



More information about the Freeswitch-svn mailing list