]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_opus] add cfg setting to overwrite the fmtp stereo param coming from remote...
authorDragos Oancea <dragos@signalwire.com>
Fri, 14 May 2021 15:36:30 +0000 (18:36 +0300)
committerGitHub <noreply@github.com>
Fri, 14 May 2021 15:36:30 +0000 (18:36 +0300)
* [mod_opus] add cfg setting to overwrite the fmtp stereo param coming from remote. Eg: incoming SDP has stereo=1 but we want a mono call so we answer with stereo=0.
sprop-stereo will be set to 0 too.

* [core] opus: use switch_core_max_audio_channels() with remote fmtp stereo=1 to allow disabling of stereo.

conf/testing/autoload_configs/opus.conf.xml
conf/vanilla/autoload_configs/opus.conf.xml
src/mod/codecs/mod_opus/mod_opus.c
src/switch_core_media.c

index e187a0a6c5545b0f3acbc17846c5c35174d838a8..1154797dce7f7354fd855335cab4673d90d4ec13 100644 (file)
@@ -6,6 +6,7 @@
     <param name="complexity" value="10"/>
     <param name="use-jb-lookahead" value="true"/>
        <param name="keep-fec-enabled" value="true"/>
-    <param name="adjust-bitrate" value="true"/>
+       <param name="adjust-bitrate" value="true"/>
+    <param name="mono" value="0"/>
   </settings>
 </configuration>
index 94aaede4718bf71468f77993233e6fd6a82e2234..8494c2d3c728a4747993dfb51c8c3ce9e4175e43 100644 (file)
@@ -28,6 +28,8 @@
        <!-- Max capture rate, 8000, 12000, 16000, 24000 and 48000 are valid options -->
         <!--<param name="sprop-maxcapturerate" value="0"/>-->
        <!-- Enable automatic bitrate variation during the call based on RTCP feedback -->
-        <!--<param name="adjust-bitrate" value="1"/>-->
+       <!--<param name="adjust-bitrate" value="1"/>-->
+       <!-- will enforce mono even if the remote party wants stereo. must be used in conjunction with param "max-audio-channels" set to 1 in switch.conf.xml. -->
+               <param name="mono" value="0"/>
     </settings>
 </configuration>
index 2081ef1b88bbdf1c85bc7de0c41d14dfc098f551..a90aba346a2353fa1ad274b93c428e37f616774c 100644 (file)
@@ -160,6 +160,7 @@ struct {
        int debuginfo;
        uint32_t use_jb_lookahead;
        switch_mutex_t *mutex;
+       int mono;
 } opus_prefs;
 
 static struct {
@@ -283,7 +284,7 @@ static switch_status_t switch_opus_fmtp_parse(const char *fmtp, switch_codec_fmt
                                        }
 
                                        if (!strcasecmp(data, "stereo")) {
-                                               codec_settings->stereo = atoi(arg);
+                                               codec_settings->stereo = opus_prefs.mono ? 0 : atoi(arg);
                                                codec_fmtp->stereo = codec_settings->stereo;
                                        }
 
@@ -563,6 +564,11 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag
 
        opus_codec_settings.usedtx = opus_prefs.use_dtx;
 
+       if (opus_prefs.mono) {
+               opus_codec_settings.stereo = 0;
+               opus_codec_settings.sprop_stereo = 0;
+       }
+
        codec->fmtp_out = gen_fmtp(&opus_codec_settings, codec->memory_pool);
 
        if (encoding) {
@@ -1080,6 +1086,8 @@ static switch_status_t opus_load_config(switch_bool_t reload)
                                if (!switch_opus_acceptable_rate(opus_prefs.sprop_maxcapturerate)) {
                                        opus_prefs.sprop_maxcapturerate = 0; /* value not supported */
                                }
+                       } else if (!strcasecmp(key, "mono")) {
+                               opus_prefs.mono = atoi(val);
                        }
                }
        }
index ac8b9b9f71b3a3d232403987401c47e52dc0d1f5..686bc344f7e0c2ddae0cac764d59c62f01a81a62 100644 (file)
@@ -5774,7 +5774,13 @@ SWITCH_DECLARE(uint8_t) switch_core_media_negotiate_sdp(switch_core_session_t *s
                                                        pmap->adv_channels = 2; /* IKR ???*/
                                                }
                                                if (!zstr((char *) mmap->rm_fmtp) && switch_stristr("stereo=1", (char *) mmap->rm_fmtp)) {
-                                                       pmap->channels = 2;
+                                                       uint32_t allow_channels = switch_core_max_audio_channels(0);
+                                                       if (!allow_channels || allow_channels >= 2) { /*default*/
+                                                               pmap->channels = 2;
+                                                       } else { /* allow_channels == 1 */
+                                                               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Opus: setting 1 audio channel via config.\n");
+                                                               pmap->channels = 1;
+                                                       }
                                                } else {
                                                        pmap->channels = 1;
                                                }