]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9584 Separate initial bitrate negotiation from sample rates
authorGiacomo Vacca <giacomo.vacca@gmail.com>
Wed, 28 Sep 2016 15:22:40 +0000 (11:22 -0400)
committerGiacomo Vacca <giacomo.vacca@gmail.com>
Wed, 28 Sep 2016 15:22:40 +0000 (11:22 -0400)
conf/vanilla/autoload_configs/opus.conf.xml
src/mod/codecs/mod_opus/mod_opus.c

index 98a6b7fd1d3557764f3f8058642174deb2248428..2e05ff6f841dcfe9b841ffcd80d0d89670c6373a 100644 (file)
@@ -7,6 +7,10 @@
         <!--<param name="packet-loss-percent" value="10"/>-->
        <!-- Support asymmetric sample rates -->
         <!--<param name="asymmetric-sample-rates" value="1"/>-->
+
+       <!-- Enable bitrate negotiation -->
+        <!--<param name="bitrate-negotiation" value="1"/>-->
+
        <!-- Keep FEC Enabled -->
         <param name="keep-fec-enabled" value="1"/>
        <!--<param name="use-jb-lookahead" value="true"/> -->
index 4a46c3f1e31cc0f36315c7e9d428b876bf42d957..d4b5b81ac34fedcaa3cb27f9da2d77bb9829b55b 100644 (file)
@@ -129,6 +129,7 @@ struct {
        int sprop_maxcapturerate;
        int plpct;
        int asymmetric_samplerates;
+       int bitrate_negotiation;
        int keep_fec;
        int fec_decode;
        int adjust_bitrate;
@@ -490,30 +491,32 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag
        memset(&codec_fmtp, '\0', sizeof(struct switch_codec_fmtp));
        codec_fmtp.private_info = &opus_codec_settings;
        switch_opus_fmtp_parse(codec->fmtp_in, &codec_fmtp);
-       if (opus_prefs.asymmetric_samplerates) {
+       if (opus_prefs.asymmetric_samplerates || opus_prefs.bitrate_negotiation) {
                /* save the remote fmtp values, before processing */
                codec_fmtp_only_remote.private_info = &opus_codec_settings_remote;
                switch_opus_fmtp_parse(codec->fmtp_in, &codec_fmtp_only_remote);
        }
        context->codec_settings = opus_codec_settings;
 
-       /* Verify if the local or remote configuration are lowering maxaveragebitrate and/or maxplaybackrate */
+       /* If bitrate negotiation is allowed, verify whether remote is asking for a smaller maxaveragebitrate */
        if (opus_prefs.maxaveragebitrate &&
-                (opus_prefs.maxaveragebitrate < opus_codec_settings_remote.maxaveragebitrate || !opus_codec_settings_remote.maxaveragebitrate)) {
+                (!opus_prefs.bitrate_negotiation || (opus_prefs.maxaveragebitrate < opus_codec_settings_remote.maxaveragebitrate) || !opus_codec_settings_remote.maxaveragebitrate)) {
                opus_codec_settings.maxaveragebitrate = opus_prefs.maxaveragebitrate;
        } else {
                opus_codec_settings.maxaveragebitrate = opus_codec_settings_remote.maxaveragebitrate;
        }
 
+       /* If asymmetric sample rates are allowed, verify whether remote is asking for a smaller maxplaybackrate */
        if (opus_prefs.maxplaybackrate &&
-                (opus_prefs.maxplaybackrate < opus_codec_settings_remote.maxplaybackrate || !opus_codec_settings_remote.maxplaybackrate)) {
+                (!opus_prefs.asymmetric_samplerates || (opus_prefs.maxplaybackrate < opus_codec_settings_remote.maxplaybackrate) || !opus_codec_settings_remote.maxplaybackrate)) {
                opus_codec_settings.maxplaybackrate = opus_prefs.maxplaybackrate;
        } else {
                opus_codec_settings.maxplaybackrate=opus_codec_settings_remote.maxplaybackrate;
        }
 
+       /* If asymmetric sample rates are allowed, verify whether remote is asking for a smaller sprop_maxcapturerate */
        if (opus_prefs.sprop_maxcapturerate &&
-                (opus_prefs.sprop_maxcapturerate < opus_codec_settings_remote.sprop_maxcapturerate || !opus_codec_settings_remote.sprop_maxcapturerate)) {
+                (!opus_prefs.asymmetric_samplerates || (opus_prefs.sprop_maxcapturerate < opus_codec_settings_remote.sprop_maxcapturerate) || !opus_codec_settings_remote.sprop_maxcapturerate)) {
                opus_codec_settings.sprop_maxcapturerate = opus_prefs.sprop_maxcapturerate;
        } else {
                opus_codec_settings.sprop_maxcapturerate = opus_codec_settings_remote.sprop_maxcapturerate;
@@ -987,6 +990,8 @@ static switch_status_t opus_load_config(switch_bool_t reload)
                                opus_prefs.plpct = atoi(val);
                        } else if (!strcasecmp(key, "asymmetric-sample-rates")) {
                                opus_prefs.asymmetric_samplerates = atoi(val);
+                       } else if (!strcasecmp(key, "bitrate-negotiation")) {
+                               opus_prefs.bitrate_negotiation = atoi(val);
                        } else if (!strcasecmp(key, "use-jb-lookahead")) {
                                opus_prefs.use_jb_lookahead = switch_true(val);
                        } else if (!strcasecmp(key, "keep-fec-enabled")) { /* encoder */