diff --git a/src/opus_decoder.c b/src/opus_decoder.c index 88e87d5e657693d3862ca7037c8e4f9944537294..75fb9325a1c0951718bd8c10bb794654771af23f 100644 --- a/src/opus_decoder.c +++ b/src/opus_decoder.c @@ -67,6 +67,8 @@ OpusDecoder *opus_decoder_init(OpusDecoder *st, int Fs, int channels) CELTDecoder *celt_dec; int ret, silkDecSizeBytes; + if (channels<1 || channels > 2) + return NULL; memset(st, 0, opus_decoder_get_size(channels)); /* Initialize SILK encoder */ ret = silk_Get_Decoder_Size( &silkDecSizeBytes ); diff --git a/src/opus_encoder.c b/src/opus_encoder.c index 3faee96fc9b0cd315c03013c2f122b77f7ec5ba3..3013c84eda7dba08e924cc581166a26a9aa5d1e5 100644 --- a/src/opus_encoder.c +++ b/src/opus_encoder.c @@ -82,17 +82,18 @@ OpusEncoder *opus_encoder_init(OpusEncoder* st, int Fs, int channels, int applic int err; int ret, silkEncSizeBytes; - memset(st, 0, opus_encoder_get_size(channels)); - /* Create SILK encoder */ - ret = silk_Get_Encoder_Size( &silkEncSizeBytes ); - if( ret ) - return NULL; if (channels > 2 || channels<1) return NULL; if (application < OPUS_APPLICATION_VOIP || application > OPUS_APPLICATION_AUDIO) return NULL; if (Fs != 8000 && Fs != 12000 && Fs != 16000 && Fs != 24000 && Fs != 48000) return NULL; + + memset(st, 0, opus_encoder_get_size(channels)); + /* Create SILK encoder */ + ret = silk_Get_Encoder_Size( &silkEncSizeBytes ); + if( ret ) + return NULL; silkEncSizeBytes = align(silkEncSizeBytes); st->silk_enc_offset = align(sizeof(OpusEncoder)); st->celt_enc_offset = st->silk_enc_offset+silkEncSizeBytes; @@ -301,11 +302,18 @@ int opus_encode(OpusEncoder *st, const short *pcm, int frame_size, if (st->user_bandwidth != OPUS_BANDWIDTH_AUTO) st->bandwidth = st->user_bandwidth; - /* Prevents nonsensical configurations, i.e. modes that don't exist */ + /* Preventing nonsensical configurations, i.e. modes that don't exist */ + + /* Frame size < 10 ms */ if (frame_size < st->Fs/100 && st->mode != MODE_CELT_ONLY) st->mode = MODE_CELT_ONLY; - if (frame_size > st->Fs/50 && st->mode != MODE_SILK_ONLY) + /* Frame size > 20 ms */ + if (50*frame_size > st->Fs) + { st->mode = MODE_SILK_ONLY; + if (st->bandwidth > OPUS_BANDWIDTH_WIDEBAND) + st->bandwidth = OPUS_BANDWIDTH_WIDEBAND; + } if (st->mode == MODE_CELT_ONLY && st->bandwidth == OPUS_BANDWIDTH_MEDIUMBAND) st->bandwidth = OPUS_BANDWIDTH_WIDEBAND; if (st->mode == MODE_SILK_ONLY && st->bandwidth > OPUS_BANDWIDTH_WIDEBAND)