Skip to content
Snippets Groups Projects
Commit d3358b1d authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Better error checking, getting 60 ms to work again

parent 23a900ce
No related branches found
No related tags found
No related merge requests found
......@@ -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 );
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment