diff mbox series

[FFmpeg-devel,4/4] avcodec/ac3enc: Simplify AC-3 bit counting

Message ID HE1PR0301MB21548A0CEB404FFDAD57B1758F7B9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit 18bb323da437642616bfefcc1d6bc781ca0658b4
Headers show
Series [FFmpeg-devel,1/2] avcodec/ac3enc: Use actual size of buffer in init_put_bits() | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt April 1, 2021, 3:53 p.m. UTC
When encoding E-AC-3, whether coupling is on or not determines whether
an additional frame based coupling exponent strategy element frmcplexpstr
(of size five bits) is present in the bitstream. So just add five to the
number of bits when counting them instead of adding 5*s->cpl_on (the
latter field is currently only 0 or 1, so it doesn't make a difference).

Furthermore, move some parts of the bit allocation that doesn't change
per-frame to count_frame_bits_fixed() (which is only run once during
init).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/ac3enc.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index e27858e1b0..8d9de8e108 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -784,6 +784,10 @@  static void count_frame_bits_fixed(AC3EncodeContext *s)
         if (s->eac3)
             frame_bits++;
 
+        /* coupling strategy exists: cplstre */
+        if (!s->eac3)
+            frame_bits++;
+
         if (!s->eac3) {
             /* exponent strategy */
             frame_bits += 2 * s->fbw_channels;
@@ -796,9 +800,8 @@  static void count_frame_bits_fixed(AC3EncodeContext *s)
                 frame_bits += 2 + 2 + 2 + 2 + 3;
         }
 
-        /* converter snr offset */
-        if (s->eac3)
-            frame_bits++;
+        /* snroffste for AC-3, convsnroffste for E-AC-3 */
+        frame_bits++;
 
         if (!s->eac3) {
             /* delta bit allocation */
@@ -904,7 +907,7 @@  static void count_frame_bits(AC3EncodeContext *s)
         /* coupling exponent strategy */
         if (s->cpl_on) {
             if (s->use_frame_exp_strategy) {
-                frame_bits += 5 * s->cpl_on;
+                frame_bits += 5;
             } else {
                 for (blk = 0; blk < s->num_blocks; blk++)
                     frame_bits += 2 * s->blocks[blk].cpl_in_use;
@@ -926,8 +929,6 @@  static void count_frame_bits(AC3EncodeContext *s)
         AC3Block *block = &s->blocks[blk];
 
         /* coupling strategy */
-        if (!s->eac3)
-            frame_bits++;
         if (block->new_cpl_strategy) {
             if (!s->eac3)
                 frame_bits++;
@@ -983,7 +984,6 @@  static void count_frame_bits(AC3EncodeContext *s)
 
         /* snr offsets and fast gain codes */
         if (!s->eac3) {
-            frame_bits++;
             if (block->new_snr_offsets)
                 frame_bits += 6 + (s->channels + block->cpl_in_use) * (4 + 3);
         }