]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-12008: special case G722 - fix rate passed to switch_core_codec_init()
authorDragos Oancea <dragos@signalwire.com>
Mon, 19 Aug 2019 18:31:10 +0000 (18:31 +0000)
committerDragos Oancea <dragos@signalwire.com>
Mon, 19 Aug 2019 18:31:10 +0000 (18:31 +0000)
src/switch_core_codec.c
tests/unit/conf/freeswitch.xml
tests/unit/switch_core_codec.c

index ac21fa4567dcb483db4fb418092fd0727538900d..69883f8122b03e1b99685493158b5001c945d6bc 100644 (file)
@@ -614,14 +614,18 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_reset(switch_codec_t *codec)
 SWITCH_DECLARE(switch_status_t) switch_core_codec_copy(switch_codec_t *codec, switch_codec_t *new_codec,
                                                                                                           const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool)
 {
+       uint32_t codec_rate;
        switch_assert(codec != NULL);
        switch_assert(new_codec != NULL);
 
+       codec_rate = !strcasecmp(codec->implementation->iananame, "g722")
+                               ? codec->implementation->samples_per_second : codec->implementation->actual_samples_per_second;
+
        return switch_core_codec_init(new_codec,
                                                                  codec->implementation->iananame,
                                                                  codec->implementation->modname,
                                                                  codec->fmtp_in,
-                                                                 codec->implementation->actual_samples_per_second,
+                                                                 codec_rate,
                                                                  codec->implementation->microseconds_per_packet / 1000,
                                                                  codec->implementation->number_of_channels,
                                                                  codec->flags,
index fe2fe1b17ca859279cabf985f3fa66fa7846a56f..abdbcd4ae55971bd06a85bf726d66566043ae570 100644 (file)
@@ -8,6 +8,9 @@
         <load module="mod_console"/>
                <load module="mod_loopback"/>
                <load module="mod_opus"/>
+               <load module="mod_spandsp"/>
+               <load module="mod_amr"/>
+               <load module="mod_amrwb"/>
       </modules>
     </configuration>
 
index 4926de6b849e85d0d4a5db6ef766a16f4dd63ba1..b01d5220c5a91aa9fbbb0d05ebf8b9f95485eeae 100644 (file)
@@ -51,6 +51,7 @@ FST_CORE_BEGIN("./conf")
                FST_SETUP_BEGIN()
                {
                        fst_requires_module("mod_opus");
+                       fst_requires_module("mod_spandsp");
                }
                FST_SETUP_END()
 
@@ -101,6 +102,20 @@ FST_CORE_BEGIN("./conf")
                        switch_core_codec_copy(&orig_codec, &new_codec, NULL, NULL);
                        fst_check(orig_codec.implementation->samples_per_second == new_codec.implementation->samples_per_second);
                        fst_check(orig_codec.implementation->actual_samples_per_second == new_codec.implementation->actual_samples_per_second);
+                       status = switch_core_codec_init(&orig_codec,
+                       "G722",
+                       "mod_spandsp",
+                       NULL,
+                       8000,
+                       20,
+                       1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+                       &codec_settings, fst_pool);
+                       fst_check(status == SWITCH_STATUS_SUCCESS);
+
+                       switch_core_codec_copy(&orig_codec, &new_codec, NULL, NULL);
+                       fst_check(orig_codec.implementation->samples_per_second == new_codec.implementation->samples_per_second);
+                       fst_check(orig_codec.implementation->actual_samples_per_second == new_codec.implementation->actual_samples_per_second);
 
                }
                FST_TEST_END()