shithub: opus

Download patch

ref: 1fad3048af514f3abc6e70f844af3861ebf4ffca
parent: 99ca4b3cffc9166380e77962f506f08ba909db2a
author: Jean-Marc Valin <[email protected]>
date: Thu Oct 20 17:10:25 EDT 2011

Make the encoder output a "PLC packet" when SILK can't reach the target

--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -1115,9 +1115,16 @@
     st->first = 0;
     if (!redundancy && st->mode==MODE_SILK_ONLY && !st->use_vbr && ret >= 2)
     {
-       nb_compr_bytes = st->bitrate_bps * frame_size / (st->Fs * 8);
-       pad_frame(data, ret+1, nb_compr_bytes);
-       return nb_compr_bytes;
+       /* In the unlikely case that the SILK encoder busted its target, tell
+          the decoder to call the PLC */
+       if (ec_tell(&enc) > (max_data_bytes-1)*8)
+       {
+          data[1] = 0;
+          ret = 1;
+          st->rangeFinal = 0;
+       }
+       pad_frame(data, ret+1, max_data_bytes);
+       return max_data_bytes;
     }
     RESTORE_STACK;
     return ret+1+redundancy_bytes;