shithub: opus

Download patch

ref: d3358b1d42f5092c42f45a68f1e53a16b5a6926f
parent: 23a900cebf5a5824850ead88bbed95f1607aadea
author: Jean-Marc Valin <[email protected]>
date: Tue Jun 14 10:48:53 EDT 2011

Better error checking, getting 60 ms to work again

--- a/src/opus_decoder.c
+++ b/src/opus_decoder.c
@@ -67,6 +67,8 @@
 	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 );
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -82,11 +82,6 @@
     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)
@@ -93,6 +88,12 @@
         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 @@
     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)