[FFmpeg-devel] [PATCH] ac3dec: fix center_mix_level handling.
Michael Niedermayer
michaelni at gmx.at
Thu Jan 19 00:39:54 CET 2012
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.
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
---
libavcodec/ac3_parser.c | 12 +++++++++---
libavcodec/ac3dec.c | 10 ++--------
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 17f205b..d2ec6a0 100644
--- a/libavcodec/ac3_parser.c
+++ b/libavcodec/ac3_parser.c
@@ -53,7 +53,7 @@ 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->center_mix_level = 5; // -4.5dB
hdr->surround_mix_level = 1; // -6.0dB
if(hdr->bitstream_id <= 10) {
@@ -75,8 +75,14 @@ int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
if(hdr->channel_mode == AC3_CHMODE_STEREO) {
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);
+ if ((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO) {
+ hdr->center_mix_level = get_bits(gbc, 2) + 4;
+ if (hdr->center_mix_level == 3 + 4) {
+ hdr->center_mix_level = 5;
+ av_log(NULL, AV_LOG_DEBUG,
+ "Reserved center_mix_level, using -4.5dB as mandated by spec\n");
+ }
+ }
if(hdr->channel_mode & 4)
hdr->surround_mix_level = get_bits(gbc, 2);
}
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 325d23b..ac1ae90 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -77,12 +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
*/
@@ -320,7 +314,7 @@ 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 cmix = gain_levels[ s-> center_mix_level ];
float smix = gain_levels[surround_levels[s->surround_mix_level]];
float norm0, norm1;
@@ -1400,7 +1394,7 @@ 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_center_mix_level = gain_levels[ s-> center_mix_level ];
s->loro_surround_mix_level = gain_levels[surround_levels[s->surround_mix_level]];
s->ltrt_center_mix_level = LEVEL_MINUS_3DB;
s->ltrt_surround_mix_level = LEVEL_MINUS_3DB;
--
1.7.5.4
More information about the ffmpeg-devel
mailing list