shithub: opus

Download patch

ref: 9fdc489c359b8723902a8e440d6efa89ba929862
parent: 1736ae3f5e3a2772190f72f8ad29778b20235304
author: Jean-Marc Valin <jmvalin@amazon.com>
date: Tue Jul 11 13:48:11 EDT 2023

Fix a CELT encoder CBR corner case

If configuring CELT for CBR but controlling the bitrate with
OPUS_SET_BITRATE rather than nbCompressedBytes, then the range
coder buffer would never get resized. AFAICT this could never
be triggered in Opus because CBR was also controlled by
nbCompressedBytes.

--- a/celt/celt_encoder.c
+++ b/celt/celt_encoder.c
@@ -1567,8 +1567,11 @@
       if (tell>1)
          tmp += tell*mode->Fs;
       if (st->bitrate!=OPUS_BITRATE_MAX)
+      {
          nbCompressedBytes = IMAX(2, IMIN(nbCompressedBytes,
                (tmp+4*mode->Fs)/(8*mode->Fs)-!!st->signalling));
+         ec_enc_shrink(enc, nbCompressedBytes);
+      }
       effectiveBytes = nbCompressedBytes - nbFilledBytes;
    }
    equiv_rate = ((opus_int32)nbCompressedBytes*8*50 << (3-LM)) - (40*C+20)*((400>>LM) - 50);
--- a/src/opus_encoder.c
+++ b/src/opus_encoder.c
@@ -2129,7 +2129,7 @@
            if (redundancy && celt_to_silk && st->mode==MODE_HYBRID && st->use_vbr)
            {
               OPUS_MOVE(data+ret, data+nb_compr_bytes, redundancy_bytes);
-              nb_compr_bytes = nb_compr_bytes+redundancy_bytes;
+              nb_compr_bytes = ret+redundancy_bytes;
            }
         }
     }
--