From 892974f01002d3be5650d9cb4b5a539e2fe81c45 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 13 Sep 2012 10:32:00 -0500 Subject: [PATCH 1/2] update opus to use the standardized release --- src/mod/codecs/mod_opus/Makefile | 10 +++--- src/mod/codecs/mod_opus/mod_opus.c | 56 ++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/src/mod/codecs/mod_opus/Makefile b/src/mod/codecs/mod_opus/Makefile index 21a526a671..cf1e8d034b 100644 --- a/src/mod/codecs/mod_opus/Makefile +++ b/src/mod/codecs/mod_opus/Makefile @@ -1,16 +1,14 @@ BASE=../../../.. -OPUS=opus-0.9.0 +OPUS=opus-1.0.1 OPUS_DIR=$(switch_srcdir)/libs/$(OPUS) OPUS_BUILDDIR=$(switch_builddir)/libs/$(OPUS) -LOCAL_CFLAGS=-I$(OPUS_DIR)/src -g -O2 +LOCAL_CFLAGS=-I$(OPUS_DIR)/include -g -O2 -IETF_LA=$(OPUS_BUILDDIR)/src/libietfcodec.la -CELT_LA=$(OPUS_BUILDDIR)/celt/libcelt/libcelt0.la -SILK_LA=$(OPUS_BUILDDIR)/silk/libSKP_SILK_SDK.la +OPUS_LA=$(OPUS_BUILDDIR)/.libs/libopus.la -LOCAL_LIBADD=$(IETF_LA) $(CELT_LA) $(SILK_LA) -lm -lz +LOCAL_LIBADD=$(OPUS_LA) -lm -lz include $(BASE)/build/modmake.rules diff --git a/src/mod/codecs/mod_opus/mod_opus.c b/src/mod/codecs/mod_opus/mod_opus.c index 285557fd96..d88e88fe43 100644 --- a/src/mod/codecs/mod_opus/mod_opus.c +++ b/src/mod/codecs/mod_opus/mod_opus.c @@ -57,27 +57,48 @@ 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 = codec->implementation->bits_per_second; - int mode = MODE_HYBRID; int use_vbr = 1; int complexity = 10; int use_inbandfec = 1; int use_dtx = 1; - int bandwidth = BANDWIDTH_FULLBAND; + int bandwidth = OPUS_BANDWIDTH_FULLBAND; + int err; - context->encoder_object = opus_encoder_create(codec->implementation->actual_samples_per_second, codec->implementation->number_of_channels); + context->encoder_object = opus_encoder_create(codec->implementation->actual_samples_per_second, + 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; + } - opus_encoder_ctl(context->encoder_object, OPUS_SET_MODE(mode)); opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(bitrate_bps)); opus_encoder_ctl(context->encoder_object, OPUS_SET_BANDWIDTH(bandwidth)); - opus_encoder_ctl(context->encoder_object, OPUS_SET_VBR_FLAG(use_vbr)); + opus_encoder_ctl(context->encoder_object, OPUS_SET_VBR(use_vbr)); opus_encoder_ctl(context->encoder_object, OPUS_SET_COMPLEXITY(complexity)); - opus_encoder_ctl(context->encoder_object, OPUS_SET_INBAND_FEC_FLAG(use_inbandfec)); - opus_encoder_ctl(context->encoder_object, OPUS_SET_DTX_FLAG(use_dtx)); + opus_encoder_ctl(context->encoder_object, OPUS_SET_INBAND_FEC(use_inbandfec)); + opus_encoder_ctl(context->encoder_object, OPUS_SET_DTX(use_dtx)); } if (decoding) { - context->decoder_object = opus_decoder_create(codec->implementation->actual_samples_per_second, codec->implementation->number_of_channels); + int err; + + context->decoder_object = opus_decoder_create(codec->implementation->actual_samples_per_second, + codec->implementation->number_of_channels, &err); + + + if (err != OPUS_OK) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot create decoder: %s\n", opus_strerror(err)); + + if (context->encoder_object) { + opus_encoder_destroy(context->encoder_object); + context->encoder_object = NULL; + } + + return SWITCH_STATUS_GENERR; + } + } codec->private_info = context; @@ -87,6 +108,19 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag static switch_status_t switch_opus_destroy(switch_codec_t *codec) { + struct opus_context *context = codec->private_info; + + if (context) { + if (context->decoder_object) { + opus_decoder_destroy(context->decoder_object); + context->decoder_object = NULL; + } + if (context->encoder_object) { + opus_encoder_destroy(context->encoder_object); + context->encoder_object = NULL; + } + } + codec->private_info = NULL; return SWITCH_STATUS_SUCCESS; } @@ -133,7 +167,7 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec, return SWITCH_STATUS_FALSE; } - samples = opus_decode(context->decoder_object, encoded_data, encoded_data_len, decoded_data, *decoded_data_len); + samples = opus_decode(context->decoder_object, (*flag & SFF_PLC) ? NULL : encoded_data, encoded_data_len, decoded_data, *decoded_data_len, 0); if (samples < 0) { return SWITCH_STATUS_GENERR; @@ -157,12 +191,12 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load) /* connect my internal structure to the blank pointer passed to me */ *module_interface = switch_loadable_module_create_module_interface(pool, modname); - SWITCH_ADD_CODEC(codec_interface, "OPUS (BETA 0.9.0)"); + SWITCH_ADD_CODEC(codec_interface, "OPUS (STANDARD)"); for (x = 0; x < 2; x++) { switch_core_codec_add_implementation(pool, codec_interface, SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */ 115, /* the IANA code number */ - "Opus-0.9.0",/* the IANA code name */ + "opus",/* the IANA code name */ NULL, /* default fmtp to send (can be overridden by the init function) */ rate, /* samples transferred per second */ rate, /* actual samples transferred per second */ From 0424a81494e2569cc64eeba71a189332d68d7211 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 13 Sep 2012 11:27:50 -0500 Subject: [PATCH 2/2] build fix on opus --- src/mod/codecs/mod_opus/Makefile | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/mod/codecs/mod_opus/Makefile b/src/mod/codecs/mod_opus/Makefile index cf1e8d034b..c57e047461 100644 --- a/src/mod/codecs/mod_opus/Makefile +++ b/src/mod/codecs/mod_opus/Makefile @@ -15,16 +15,14 @@ include $(BASE)/build/modmake.rules $(OPUS_DIR): $(GETLIB) $(OPUS).tar.gz -$(OPUS_BUILDDIR)/Makefile: $(OPUS_DIR) - mkdir -p $(OPUS_BUILDDIR) +$(OPUS_DIR)/Makefile: $(OPUS_DIR) cd $(OPUS_BUILDDIR) && $(DEFAULT_VARS) $(OPUS_DIR)/configure --disable-shared --with-pic --srcdir=$(OPUS_DIR) $(TOUCH_TARGET) -$(IETF_LA): $(OPUS_BUILDDIR)/Makefile +$(OPUS_LA): $(OPUS_DIR)/Makefile cd $(OPUS_BUILDDIR) && $(MAKE) - $(TOUCH_TARGET) -$(CELT_LA): $(IETF_LA) -$(SILK_LA): $(IETF_LA) -$(MODNAME).lo: $(IETF_LA) $(CELT_LA) $(SILK_LA) + +$(MODNAME).lo: $(OPUS_LA) +