[FFmpeg-cvslog] ac3enc: separate exponent bit counting from exponent grouping.

Justin Ruggles git at videolan.org
Wed Aug 10 16:53:22 CEST 2011


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Fri Aug  5 16:00:18 2011 -0400| [d55ad59a8a67b73f3370ee01efd0051fbffe3577] | committer: Justin Ruggles

ac3enc: separate exponent bit counting from exponent grouping.

Move bit counting to the bit allocation function. Move exponent grouping to
after bit allocation. This will allow for adjustment of bandwidth parameters
during bit allocation without having to do exponent grouping multiple times.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d55ad59a8a67b73f3370ee01efd0051fbffe3577
---

 libavcodec/ac3enc.c          |   40 ++++++++++++++++++++++++++++++++--------
 libavcodec/ac3enc.h          |    2 ++
 libavcodec/ac3enc_template.c |    2 ++
 3 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c
index c138f99..d454654 100644
--- a/libavcodec/ac3enc.c
+++ b/libavcodec/ac3enc.c
@@ -527,19 +527,46 @@ static void encode_exponents(AC3EncodeContext *s)
 
 
 /**
+ * Count exponent bits based on bandwidth, coupling, and exponent strategies.
+ */
+static int count_exponent_bits(AC3EncodeContext *s)
+{
+    int blk, ch;
+    int nb_groups, bit_count;
+
+    bit_count = 0;
+    for (blk = 0; blk < s->num_blocks; blk++) {
+        AC3Block *block = &s->blocks[blk];
+        for (ch = !block->cpl_in_use; ch <= s->channels; ch++) {
+            int exp_strategy = s->exp_strategy[ch][blk];
+            int cpl          = (ch == CPL_CH);
+            int nb_coefs     = block->end_freq[ch] - s->start_freq[ch];
+
+            if (exp_strategy == EXP_REUSE)
+                continue;
+
+            nb_groups = exponent_group_tab[cpl][exp_strategy-1][nb_coefs];
+            bit_count += 4 + (nb_groups * 7);
+        }
+    }
+
+    return bit_count;
+}
+
+
+/**
  * Group exponents.
  * 3 delta-encoded exponents are in each 7-bit group. The number of groups
  * varies depending on exponent strategy and bandwidth.
  */
-static void group_exponents(AC3EncodeContext *s)
+void ff_ac3_group_exponents(AC3EncodeContext *s)
 {
     int blk, ch, i, cpl;
-    int group_size, nb_groups, bit_count;
+    int group_size, nb_groups;
     uint8_t *p;
     int delta0, delta1, delta2;
     int exp0, exp1;
 
-    bit_count = 0;
     for (blk = 0; blk < s->num_blocks; blk++) {
         AC3Block *block = &s->blocks[blk];
         for (ch = !block->cpl_in_use; ch <= s->channels; ch++) {
@@ -549,7 +576,6 @@ static void group_exponents(AC3EncodeContext *s)
             cpl = (ch == CPL_CH);
             group_size = exp_strategy + (exp_strategy == EXP_D45);
             nb_groups = exponent_group_tab[cpl][exp_strategy-1][block->end_freq[ch]-s->start_freq[ch]];
-            bit_count += 4 + (nb_groups * 7);
             p = block->exp[ch] + s->start_freq[ch] - cpl;
 
             /* DC exponent */
@@ -581,8 +607,6 @@ static void group_exponents(AC3EncodeContext *s)
             }
         }
     }
-
-    s->exponent_bits = bit_count;
 }
 
 
@@ -599,8 +623,6 @@ void ff_ac3_process_exponents(AC3EncodeContext *s)
 
     encode_exponents(s);
 
-    group_exponents(s);
-
     emms_c();
 }
 
@@ -1095,6 +1117,8 @@ int ff_ac3_compute_bit_allocation(AC3EncodeContext *s)
 {
     count_frame_bits(s);
 
+    s->exponent_bits = count_exponent_bits(s);
+
     bit_alloc_masking(s);
 
     return cbr_bit_allocation(s);
diff --git a/libavcodec/ac3enc.h b/libavcodec/ac3enc.h
index 6d57143..c1e69b1 100644
--- a/libavcodec/ac3enc.h
+++ b/libavcodec/ac3enc.h
@@ -257,6 +257,8 @@ void ff_ac3_process_exponents(AC3EncodeContext *s);
 
 int ff_ac3_compute_bit_allocation(AC3EncodeContext *s);
 
+void ff_ac3_group_exponents(AC3EncodeContext *s);
+
 void ff_ac3_quantize_mantissas(AC3EncodeContext *s);
 
 void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame);
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 103e7b1..dd1e48d 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -463,6 +463,8 @@ int AC3_NAME(encode_frame)(AVCodecContext *avctx, unsigned char *frame,
         return ret;
     }
 
+    ff_ac3_group_exponents(s);
+
     ff_ac3_quantize_mantissas(s);
 
     ff_ac3_output_frame(s, frame);



More information about the ffmpeg-cvslog mailing list