]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add some stuff to tolerate more buggy switches
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 11 Feb 2009 17:43:00 +0000 (17:43 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 11 Feb 2009 17:43:00 +0000 (17:43 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11881 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c

index 246eabbd0ed69e2f94ccc6d1f4f6573eaa0f0659..e286d29b17b6b6bfe996ac9654258bfb70252f17 100644 (file)
@@ -173,7 +173,7 @@ typedef enum {
        PFLAG_3PCC_PROXY,
        PFLAG_CALLID_AS_UUID,
        PFLAG_UUID_AS_CALLID,
-
+       PFLAG_SCROOGE,
        PFLAG_MAX
 } PFLAGS;
 
index 02d9688b1f86c3f046909ca936c7dd8fa444fcef..4926e7932fe9bab7b102bb2e7788b9c60f09cce5 100644 (file)
@@ -1561,7 +1561,11 @@ switch_status_t reconfig_sofia(sofia_profile_t *profile)
                                        } 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 @@ switch_status_t config_sofia(int reload, char *profile_name)
                                        } 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)) {
index 0c9908ab1119bd87177472b6db72d610b5e1d87e..bb9855b6f95947d9ceb9b49fbb920b3259d72f7b 100644 (file)
@@ -2271,14 +2271,21 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *
        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 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *
                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 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *
                                                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 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *
                                        }
 
                                        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 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *
                                        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 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, sdp_session_t *
                                                mimp = NULL;
                                                match = 0;
                                        }
+                                       
                                }
 
                                if (!match && greedy) {