No speed difference, and this will allow for more flexible bit counting.
---
 libavcodec/ac3enc.c |   47 +++++++++++++++++++++++++++++++----------------
 1 files changed, 31 insertions(+), 16 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index 95bdc58..bb3490a 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -1008,6 +1008,34 @@ static void reset_block_bap(AC3EncodeContext *s)
 
 
 /**
+ * Count the number of mantissa bits in the frame based on the bap values.
+ */
+static int count_mantissa_bits(AC3EncodeContext *s)
+{
+    int blk, ch;
+    int mantissa_bits;
+    int mant_cnt[5];
+
+    mantissa_bits = 0;
+    for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
+        // initialize grouped mantissa counts. these are set so that they are
+        // padded to the next whole group size when bits are counted in
+        // compute_mantissa_size_final
+        mant_cnt[0] = mant_cnt[3] = 0;
+        mant_cnt[1] = mant_cnt[2] = 2;
+        mant_cnt[4] = 1;
+        for (ch = 0; ch < s->channels; ch++) {
+            mantissa_bits += s->ac3dsp.compute_mantissa_size(mant_cnt,
+                                                             s->blocks[blk].exp_ref_block[ch]->bap[ch],
+                                                             s->nb_coefs[ch]);
+        }
+        mantissa_bits += compute_mantissa_size_final(mant_cnt);
+    }
+    return mantissa_bits;
+}
+
+
+/**
  * Run the bit allocation with a given SNR offset.
  * This calculates the bit allocation pointers that will be used to determine
  * the quantization of each mantissa.
@@ -1017,42 +1045,29 @@ static void reset_block_bap(AC3EncodeContext *s)
 static int bit_alloc(AC3EncodeContext *s, int snr_offset)
 {
     int blk, ch;
-    int mantissa_bits;
-    int mant_cnt[5];
 
     snr_offset = (snr_offset - 240) << 2;
 
     reset_block_bap(s);
-    mantissa_bits = 0;
     for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) {
         AC3Block *block = &s->blocks[blk];
-        AC3Block *ref_block;
-        // initialize grouped mantissa counts. these are set so that they are
-        // padded to the next whole group size when bits are counted in
-        // compute_mantissa_size_final
-        mant_cnt[0] = mant_cnt[3] = 0;
-        mant_cnt[1] = mant_cnt[2] = 2;
-        mant_cnt[4] = 1;
         for (ch = 0; ch < s->channels; ch++) {
             /* Currently the only bit allocation parameters which vary across
                blocks within a frame are the exponent values.  We can take
                advantage of that by reusing the bit allocation pointers
                whenever we reuse exponents. */
-            ref_block = block->exp_ref_block[ch];
             if (s->exp_strategy[ch][blk] != EXP_REUSE) {
+                AC3Block *ref_block = block->exp_ref_block[ch];
                 s->ac3dsp.bit_alloc_calc_bap(ref_block->mask[ch],
                                              ref_block->psd[ch], 0,
                                              s->nb_coefs[ch], snr_offset,
                                              s->bit_alloc.floor, ff_ac3_bap_tab,
                                              ref_block->bap[ch]);
             }
-            mantissa_bits += s->ac3dsp.compute_mantissa_size(mant_cnt,
-                                                             ref_block->bap[ch],
-                                                             s->nb_coefs[ch]);
         }
-        mantissa_bits += compute_mantissa_size_final(mant_cnt);
     }
-    return mantissa_bits;
+
+    return count_mantissa_bits(s);
 }
 
 
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to