mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-06-01 03:05:50 +00:00
FS-6209 --resolve
This commit is contained in:
parent
9511fd780c
commit
cf1329df63
6
conf/vanilla/autoload_configs/opus.conf.xml
Normal file
6
conf/vanilla/autoload_configs/opus.conf.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<configuration name="opus.conf">
|
||||
<settings>
|
||||
<param name="use_vbr" value="1"/>
|
||||
<param name="complexity" value="10"/>
|
||||
</settings>
|
||||
</configuration>
|
@ -24,6 +24,7 @@
|
||||
* Contributor(s):
|
||||
*
|
||||
* Brian K. West <brian@freeswitch.org>
|
||||
* Noel Morgan <noel@vwci.com>
|
||||
*
|
||||
* mod_opus.c -- The OPUS ultra-low delay audio codec (http://www.opus-codec.org/)
|
||||
*
|
||||
@ -72,6 +73,13 @@ struct opus_context {
|
||||
int frame_size;
|
||||
};
|
||||
|
||||
struct {
|
||||
int use_vbr;
|
||||
int complexity;
|
||||
switch_mutex_t *mutex;
|
||||
} opus_prefs;
|
||||
|
||||
|
||||
static switch_status_t switch_opus_fmtp_parse(const char *fmtp, switch_codec_fmtp_t *codec_fmtp)
|
||||
{
|
||||
if (codec_fmtp) {
|
||||
@ -140,33 +148,33 @@ static switch_status_t switch_opus_fmtp_parse(const char *fmtp, switch_codec_fmt
|
||||
codec_settings->maxaveragebitrate = atoi(arg);
|
||||
switch(codec_fmtp->actual_samples_per_second) {
|
||||
case 8000:
|
||||
{
|
||||
if(codec_settings->maxaveragebitrate < 6000 || codec_settings->maxaveragebitrate > 20000) {
|
||||
codec_settings->maxaveragebitrate = 20000;
|
||||
}
|
||||
break;
|
||||
}
|
||||
{
|
||||
if(codec_settings->maxaveragebitrate < 6000 || codec_settings->maxaveragebitrate > 20000) {
|
||||
codec_settings->maxaveragebitrate = 20000;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 12000:
|
||||
{
|
||||
if(codec_settings->maxaveragebitrate < 7000 || codec_settings->maxaveragebitrate > 25000) {
|
||||
codec_settings->maxaveragebitrate = 25000;
|
||||
}
|
||||
break;
|
||||
}
|
||||
{
|
||||
if(codec_settings->maxaveragebitrate < 7000 || codec_settings->maxaveragebitrate > 25000) {
|
||||
codec_settings->maxaveragebitrate = 25000;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 16000:
|
||||
{
|
||||
if(codec_settings->maxaveragebitrate < 8000 || codec_settings->maxaveragebitrate > 30000) {
|
||||
codec_settings->maxaveragebitrate = 30000;
|
||||
}
|
||||
break;
|
||||
}
|
||||
{
|
||||
if(codec_settings->maxaveragebitrate < 8000 || codec_settings->maxaveragebitrate > 30000) {
|
||||
codec_settings->maxaveragebitrate = 30000;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 24000:
|
||||
{
|
||||
if(codec_settings->maxaveragebitrate < 12000 || codec_settings->maxaveragebitrate > 40000) {
|
||||
codec_settings->maxaveragebitrate = 40000;
|
||||
}
|
||||
break;
|
||||
}
|
||||
{
|
||||
if(codec_settings->maxaveragebitrate < 12000 || codec_settings->maxaveragebitrate > 40000) {
|
||||
codec_settings->maxaveragebitrate = 40000;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
/* this should never happen but 20000 is common among all rates */
|
||||
@ -253,8 +261,8 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag
|
||||
if (encoding) {
|
||||
/* come up with a way to specify these */
|
||||
int bitrate_bps = OPUS_AUTO;
|
||||
int use_vbr = 1;
|
||||
int complexity = 10;
|
||||
int use_vbr = opus_prefs.use_vbr;
|
||||
int complexity = opus_prefs.complexity;
|
||||
int err;
|
||||
int samplerate = opus_codec_settings.samplerate ? opus_codec_settings.samplerate : codec->implementation->actual_samples_per_second;
|
||||
|
||||
@ -262,10 +270,10 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag
|
||||
codec->implementation->number_of_channels,
|
||||
OPUS_APPLICATION_VOIP, &err);
|
||||
|
||||
if (err != OPUS_OK) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create encoder: %s\n", opus_strerror(err));
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
if (err != OPUS_OK) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create encoder: %s\n", opus_strerror(err));
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(bitrate_bps));
|
||||
|
||||
@ -385,6 +393,37 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec,
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t opus_load_config(switch_bool_t reload)
|
||||
{
|
||||
char *cf = "opus.conf";
|
||||
switch_xml_t cfg, xml = NULL, param, settings;
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
|
||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Opening of %s failed\n", cf);
|
||||
status = SWITCH_STATUS_TERM;
|
||||
}
|
||||
|
||||
if ((settings = switch_xml_child(cfg, "settings"))) {
|
||||
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
|
||||
char *key = (char *) switch_xml_attr_soft(param, "name");
|
||||
char *val = (char *) switch_xml_attr_soft(param, "value");
|
||||
|
||||
if (!strcasecmp(key, "use_vbr") && !zstr(val)) {
|
||||
opus_prefs.use_vbr = atoi(val);
|
||||
} else if (!strcasecmp(key, "complexity")) {
|
||||
opus_prefs.complexity = atoi(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (xml) {
|
||||
switch_xml_free(xml);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load)
|
||||
{
|
||||
switch_codec_interface_t *codec_interface;
|
||||
@ -396,6 +435,11 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load)
|
||||
int bits = 0;
|
||||
char *dft_fmtp = NULL;
|
||||
opus_codec_settings_t settings = { 0 };
|
||||
switch_status_t status = SWITCH_FALSE;
|
||||
|
||||
if ((status = opus_load_config(SWITCH_FALSE)) != SWITCH_STATUS_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
/* connect my internal structure to the blank pointer passed to me */
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
|
Loading…
x
Reference in New Issue
Block a user