shithub: opus

Download patch

ref: b63e22cff9601ab2249ce5b6371a5ca9e663ce09
parent: 7b73c9bc7ff8e54bb6b72aad500bdab5d031aee0
author: Jean-Marc Valin <jmvalin@amazon.com>
date: Mon Dec 18 20:55:28 EST 2023

Fix desync for CBR DRED

The encoder wouldn't reserve enough bits for CELT, causing it
to not have enough bits to code the switching redundancy flag
when it should have.

--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -2143,8 +2143,9 @@
             opus_int32 dred_bytes = dred_bitrate_bps/(frame_rate*8);
             /* Allow CELT to steal up to 25% of the remaining bits. */
             max_celt_bytes = nb_compr_bytes - dred_bytes*3/4;
-            /* But try to give CELT at least 4 bytes */
-            max_celt_bytes = IMAX(ec_tell(&enc)/8 + 4, max_celt_bytes);
+            /* But try to give CELT at least 5 bytes to prevent a mismatch with
+               the redundancy signaling. */
+            max_celt_bytes = IMAX((ec_tell(&enc)+7)/8 + 5, max_celt_bytes);
             /* Subject to the original max. */
             nb_compr_bytes = IMIN(nb_compr_bytes, max_celt_bytes);
         }
--