From be6e6ea5fb7b25001ea371ef2c537a5bf2fa7dd1 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Wed, 8 Jul 2015 19:54:28 -0400 Subject: [PATCH] FS-7801: mod_opus: added support to set CBR mode --- src/mod/codecs/mod_opus/mod_opus.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index 02287e4995..e28616e5f1 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -145,7 +145,11 @@ static switch_status_t switch_opus_fmtp_parse(const char *fmtp, switch_codec_fmt if (!strcasecmp(data, "usedtx")) { codec_settings->usedtx = switch_true(arg); } - + + if (!strcasecmp(data, "cbr")) { + codec_settings->cbr = switch_true(arg); + } + if (!strcasecmp(data, "sprop-maxcapturerate")) { codec_settings->sprop_maxcapturerate = atoi(arg); } @@ -213,7 +217,11 @@ static char *gen_fmtp(opus_codec_settings_t *settings, switch_memory_pool_t *poo if (settings->usedtx) { snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "usedtx=1; "); } - + + if (settings->cbr) { + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "cbr=1; "); + } + if (settings->maxaveragebitrate) { snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "maxaveragebitrate=%d; ", settings->maxaveragebitrate); } @@ -337,12 +345,14 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag opus_codec_settings.sprop_maxcapturerate = opus_codec_settings_remote.sprop_maxcapturerate; } + opus_codec_settings.cbr = !opus_prefs.use_vbr; + codec->fmtp_out = gen_fmtp(&opus_codec_settings, codec->memory_pool); if (encoding) { /* come up with a way to specify these */ int bitrate_bps = OPUS_AUTO; - int use_vbr = opus_prefs.use_vbr; + int use_vbr = opus_codec_settings.cbr ? !opus_codec_settings.cbr : opus_prefs.use_vbr ; int complexity = opus_prefs.complexity; int plpct = opus_prefs.plpct; int err; @@ -410,7 +420,11 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag } if (use_vbr) { + /* VBR is default*/ opus_encoder_ctl(context->encoder_object, OPUS_SET_VBR(use_vbr)); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: CBR mode enabled\n"); + opus_encoder_ctl(context->encoder_object, OPUS_SET_VBR(0)); } if (complexity) { opus_encoder_ctl(context->encoder_object, OPUS_SET_COMPLEXITY(complexity));