]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-4135 --resolve
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 20 Apr 2012 13:56:14 +0000 (08:56 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 20 Apr 2012 13:56:14 +0000 (08:56 -0500)
src/switch_loadable_module.c

index 104c4b4073ff656d0f5094d2406f8fc97b5e40a8..c0755c6b55ae255bd5b96b1c337e23325d153ced 100644 (file)
@@ -2075,6 +2075,37 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs(const switch_codec_impleme
 
 }
 
+char *parse_codec_buf(char *buf, uint32_t *interval, uint32_t *rate, uint32_t *bit)
+{
+       char *cur, *next = NULL, *name, *p;
+
+       name = next = cur = buf;
+
+       for (;;) {
+               if (!next) {
+                       break;
+               }
+
+               if ((p = strchr(next, '@'))) {
+                       *p++ = '\0';
+               }
+               next = p;
+
+               if (cur != name) {
+                       if (strchr(cur, 'i')) {
+                               *interval = atoi(cur);
+                       } else if ((strchr(cur, 'k') || strchr(cur, 'h'))) {
+                               *rate = atoi(cur);
+                       } else if (strchr(cur, 'b')) {
+                               *bit = atoi(cur);
+                       }
+               }
+               cur = next;
+       }
+       
+       return name;
+}
+
 SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_implementation_t **array, int arraylen, char **prefs, int preflen)
 {
        int x, i = 0, j = 0;
@@ -2084,38 +2115,39 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_
        switch_mutex_lock(loadable_modules.mutex);
 
        for (x = 0; x < preflen; x++) {
-               char *cur, *next = NULL, *name, *p, buf[256];
+               char *name, buf[256], jbuf[256];
                uint32_t interval = 0, rate = 0, bit = 0;
 
+               switch_copy_string(buf, prefs[x], sizeof(buf));
+               name = parse_codec_buf(buf, &interval, &rate, &bit);
+
                for(j = 0; j < x; j++) {
-                       if (!strcasecmp(prefs[j], prefs[x])) {
-                               goto next_x;
+                       char *jname;
+                       uint32_t jinterval = 0, jrate = 0, jbit = 0;
+                       uint32_t ointerval = interval, orate = rate, obit = bit;
+
+                       if (ointerval == 0) {
+                               ointerval = switch_default_ptime(name, 0);
+                       }
+                       
+                       if (orate == 0) {
+                               orate = 8000;
                        }
-               }
 
-               switch_copy_string(buf, prefs[x], sizeof(buf));
-               name = next = cur = buf;
+                       switch_copy_string(jbuf, prefs[j], sizeof(jbuf));
+                       jname = parse_codec_buf(jbuf, &jinterval, &jrate, &jbit);
 
-               for (;;) {
-                       if (!next) {
-                               break;
+                       if (jinterval == 0) {
+                               jinterval = switch_default_ptime(jname, 0);
                        }
 
-                       if ((p = strchr(next, '@'))) {
-                               *p++ = '\0';
+                       if (jrate == 0) {
+                               jrate = 8000;
                        }
-                       next = p;
-
-                       if (cur != name) {
-                               if (strchr(cur, 'i')) {
-                                       interval = atoi(cur);
-                               } else if ((strchr(cur, 'k') || strchr(cur, 'h'))) {
-                                       rate = atoi(cur);
-                               } else if (strchr(cur, 'b')) {
-                                       bit = atoi(cur);
-                               }
+
+                       if (!strcasecmp(name, jname) && ointerval == jinterval && orate == jrate) {
+                               goto next_x;
                        }
-                       cur = next;
                }
 
                if ((codec_interface = switch_loadable_module_get_codec_interface(name)) != 0) {