shithub: opus

Download patch

ref: 51ac8e68e660e22b444e85d345e73e4d8c844c8f
parent: 5c3d155188366f02a1dd7ecdcb055ef7df4f20c0
author: Jean-Marc Valin <[email protected]>
date: Mon Aug 15 18:06:02 EDT 2011

Fixes a high bit-rate redundant frame bug

We now ensure that the total payload *including* the redundant frame
is no more than 1275 bytes. Also, the redundant frame itself must
be no more than 257 (the max that can be signalled).

--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -515,8 +515,6 @@
             }
         }
 
-        nb_compr_bytes = IMIN(1275, nb_compr_bytes);
-        ec_enc_shrink(&enc, nb_compr_bytes);
     } else {
         nb_compr_bytes = 0;
     }
@@ -556,7 +554,9 @@
         ec_enc_bit_logp(&enc, redundancy, 12);
         if (redundancy)
         {
-            redundancy_bytes = st->stream_channels*st->bitrate_bps/1600;
+            /* Target the same bit-rate for redundancy as for the rest,
+               up to a max of 257 bytes */
+            redundancy_bytes = IMIN(257, st->bitrate_bps/1600);
             ec_enc_bit_logp(&enc, celt_to_silk, 1);
             if (st->mode == MODE_HYBRID)
             	ec_enc_uint(&enc, redundancy_bytes-2, 256);
@@ -577,7 +577,11 @@
         if(!redundancy)
             while(ret>2&&data[ret-1]==0)ret--;
         nb_compr_bytes = ret;
+    } else {
+       nb_compr_bytes = IMIN(1275-redundancy_bytes, nb_compr_bytes);
+       ec_enc_shrink(&enc, nb_compr_bytes);
     }
+
 
     /* 5 ms redundant frame for CELT->SILK */
     if (redundancy && celt_to_silk)