From 826d42874139c59636de234d7021d485f03b81ee Mon Sep 17 00:00:00 2001 From: Julien Chavanton Date: Thu, 13 Nov 2014 13:48:04 +0100 Subject: [PATCH] FS-6992 [mod_opus] global configuration or maxplaybackrate and maxaveragebitrate from opus.conf.xml --- conf/vanilla/autoload_configs/opus.conf.xml | 13 +++++++++++ src/mod/codecs/mod_opus/mod_opus.c | 24 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/conf/vanilla/autoload_configs/opus.conf.xml b/conf/vanilla/autoload_configs/opus.conf.xml index 747a8f762f..2ac3f66f86 100644 --- a/conf/vanilla/autoload_configs/opus.conf.xml +++ b/conf/vanilla/autoload_configs/opus.conf.xml @@ -2,5 +2,18 @@ + + + + + diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index 7fa8526219..dc51a653f1 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -78,6 +78,8 @@ struct opus_context { struct { int use_vbr; int complexity; + int maxaveragebitrate; + int maxplaybackrate; switch_mutex_t *mutex; } opus_prefs; @@ -240,6 +242,15 @@ 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); + + /* Verify if the local or remote configuration are lowering maxaveragebitrate and/or maxplaybackrate */ + if ( opus_prefs.maxaveragebitrate && (opus_prefs.maxaveragebitrate < opus_codec_settings.maxaveragebitrate || !opus_codec_settings.maxaveragebitrate) ) { + opus_codec_settings.maxaveragebitrate = opus_prefs.maxaveragebitrate; + } + if ( opus_prefs.maxplaybackrate && (opus_prefs.maxplaybackrate < opus_codec_settings.maxplaybackrate || !opus_codec_settings.maxplaybackrate) ) { + opus_codec_settings.maxplaybackrate = opus_prefs.maxplaybackrate; + } + codec->fmtp_out = gen_fmtp(&opus_codec_settings, codec->memory_pool); if (encoding) { @@ -260,8 +271,6 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag } - - /* Setting documented in "RTP Payload Format for Opus Speech and Audio Codec" draft-spittka-payload-rtp-opus-03 */ if( opus_codec_settings.maxaveragebitrate ) { /* Remote codec settings found in SDP "fmtp", we accept to tune the Encoder */ opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(opus_codec_settings.maxaveragebitrate)); @@ -430,6 +439,17 @@ static switch_status_t opus_load_config(switch_bool_t reload) opus_prefs.use_vbr = atoi(val); } else if (!strcasecmp(key, "complexity")) { opus_prefs.complexity = atoi(val); + } else if (!strcasecmp(key, "maxaveragebitrate")) { + opus_prefs.maxaveragebitrate = atoi(val); + if ( opus_prefs.maxaveragebitrate < 6000 || opus_prefs.maxaveragebitrate > 510000 ) { + opus_prefs.maxaveragebitrate = 0; /* values outside the range between 6000 and 510000 SHOULD be ignored */ + } + } else if (!strcasecmp(key, "maxplaybackrate")) { + opus_prefs.maxplaybackrate = atoi(val); + if ( opus_prefs.maxplaybackrate != 8000 && opus_prefs.maxplaybackrate != 12000 && opus_prefs.maxplaybackrate != 16000 + && opus_prefs.maxplaybackrate != 24000 && opus_prefs.maxplaybackrate != 48000) { + opus_prefs.maxplaybackrate = 0; /* value not supported */ + } } } }