[FFmpeg-devel] [PATCH] ac3dec: Move center&surround mix level tables to parser.

Michael Niedermayer michaelni at gmx.at
Thu Jan 19 06:50:56 CET 2012


That way all mix levels as exported by the parser
will have the same meaning.

Previously the 3bit center mix level for eac3 was
used to index in a 4 entry table leading to out of array reads.
this change removes the table and offsets the ac3 variable by 4
so it matches the meanings for eac3 except the reserved case.
The reserved case is then explicitly handled.

Idea-by: Justin Ruggles <justin.ruggles at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
 libavcodec/ac3_parser.c |   20 ++++++++++++++++----
 libavcodec/ac3dec.c     |   20 ++++----------------
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 17f205b..14ca196 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -34,6 +34,18 @@ static const uint8_t eac3_blocks[4] = {
     1, 2, 3, 6
 };
 
+/**
+ * Table for center mix levels
+ * reference: Section 5.4.2.4 cmixlev
+ */
+static const uint8_t center_levels[4] = { 4, 5, 6, 5 };
+
+/**
+ * Table for surround mix levels
+ * reference: Section 5.4.2.5 surmixlev
+ */
+static const uint8_t surround_levels[4] = { 4, 6, 7, 6 };
+
 
 int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
 {
@@ -53,8 +65,8 @@ int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
     hdr->num_blocks = 6;
 
     /* set default mix levels */
-    hdr->center_mix_level   = 1;  // -4.5dB
-    hdr->surround_mix_level = 1;  // -6.0dB
+    hdr->center_mix_level   = 5;  // -4.5dB
+    hdr->surround_mix_level = 6;  // -6.0dB
 
     if(hdr->bitstream_id <= 10) {
         /* Normal AC-3 */
@@ -76,9 +88,9 @@ int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
             skip_bits(gbc, 2); // skip dsurmod
         } else {
             if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO)
-                hdr->center_mix_level = get_bits(gbc, 2);
+                hdr->  center_mix_level =   center_levels[get_bits(gbc, 2)];
             if(hdr->channel_mode & 4)
-                hdr->surround_mix_level = get_bits(gbc, 2);
+                hdr->surround_mix_level = surround_levels[get_bits(gbc, 2)];
         }
         hdr->lfe_on = get_bits1(gbc);
 
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 325d23b..5982558 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -77,18 +77,6 @@ static const float gain_levels[9] = {
 };
 
 /**
- * Table for center mix levels
- * reference: Section 5.4.2.4 cmixlev
- */
-static const uint8_t center_levels[4] = { 4, 5, 6, 5 };
-
-/**
- * Table for surround mix levels
- * reference: Section 5.4.2.5 surmixlev
- */
-static const uint8_t surround_levels[4] = { 4, 6, 7, 6 };
-
-/**
  * Table for default stereo downmixing coefficients
  * reference: Section 7.8.2 Downmixing Into Two Channels
  */
@@ -320,8 +308,8 @@ static int parse_frame_header(AC3DecodeContext *s)
 static void set_downmix_coeffs(AC3DecodeContext *s)
 {
     int i;
-    float cmix = gain_levels[center_levels[s->center_mix_level]];
-    float smix = gain_levels[surround_levels[s->surround_mix_level]];
+    float cmix = gain_levels[s->  center_mix_level];
+    float smix = gain_levels[s->surround_mix_level];
     float norm0, norm1;
 
     for (i = 0; i < s->fbw_channels; i++) {
@@ -1400,8 +1388,8 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
         avctx->channels       = s->out_channels;
         avctx->channel_layout = s->channel_layout;
 
-        s->loro_center_mix_level   = gain_levels[  center_levels[s->  center_mix_level]];
-        s->loro_surround_mix_level = gain_levels[surround_levels[s->surround_mix_level]];
+        s->loro_center_mix_level   = gain_levels[s->  center_mix_level];
+        s->loro_surround_mix_level = gain_levels[s->surround_mix_level];
         s->ltrt_center_mix_level   = LEVEL_MINUS_3DB;
         s->ltrt_surround_mix_level = LEVEL_MINUS_3DB;
         /* set downmixing coefficients if needed */
-- 
1.7.5.4



More information about the ffmpeg-devel mailing list