Skip to content

Commit 99a42f3

Browse files
committed
ac3dec: Move center&surround mix level tables to parser.
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 <[email protected]> Signed-off-by: Michael Niedermayer <[email protected]>
1 parent 9ec3993 commit 99a42f3

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

libavcodec/ac3_parser.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ static const uint8_t eac3_blocks[4] = {
3434
1, 2, 3, 6
3535
};
3636

37+
/**
38+
* Table for center mix levels
39+
* reference: Section 5.4.2.4 cmixlev
40+
*/
41+
static const uint8_t center_levels[4] = { 4, 5, 6, 5 };
42+
43+
/**
44+
* Table for surround mix levels
45+
* reference: Section 5.4.2.5 surmixlev
46+
*/
47+
static const uint8_t surround_levels[4] = { 4, 6, 7, 6 };
48+
3749

3850
int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
3951
{
@@ -53,8 +65,8 @@ int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
5365
hdr->num_blocks = 6;
5466

5567
/* set default mix levels */
56-
hdr->center_mix_level = 1; // -4.5dB
57-
hdr->surround_mix_level = 1; // -6.0dB
68+
hdr->center_mix_level = 5; // -4.5dB
69+
hdr->surround_mix_level = 6; // -6.0dB
5870

5971
if(hdr->bitstream_id <= 10) {
6072
/* Normal AC-3 */
@@ -76,9 +88,9 @@ int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr)
7688
skip_bits(gbc, 2); // skip dsurmod
7789
} else {
7890
if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO)
79-
hdr->center_mix_level = get_bits(gbc, 2);
91+
hdr-> center_mix_level = center_levels[get_bits(gbc, 2)];
8092
if(hdr->channel_mode & 4)
81-
hdr->surround_mix_level = get_bits(gbc, 2);
93+
hdr->surround_mix_level = surround_levels[get_bits(gbc, 2)];
8294
}
8395
hdr->lfe_on = get_bits1(gbc);
8496

libavcodec/ac3dec.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,6 @@ static const float gain_levels[9] = {
7676
LEVEL_MINUS_9DB
7777
};
7878

79-
/**
80-
* Table for center mix levels
81-
* reference: Section 5.4.2.4 cmixlev
82-
*/
83-
static const uint8_t center_levels[4] = { 4, 5, 6, 5 };
84-
85-
/**
86-
* Table for surround mix levels
87-
* reference: Section 5.4.2.5 surmixlev
88-
*/
89-
static const uint8_t surround_levels[4] = { 4, 6, 7, 6 };
90-
9179
/**
9280
* Table for default stereo downmixing coefficients
9381
* reference: Section 7.8.2 Downmixing Into Two Channels
@@ -320,8 +308,8 @@ static int parse_frame_header(AC3DecodeContext *s)
320308
static void set_downmix_coeffs(AC3DecodeContext *s)
321309
{
322310
int i;
323-
float cmix = gain_levels[center_levels[s->center_mix_level]];
324-
float smix = gain_levels[surround_levels[s->surround_mix_level]];
311+
float cmix = gain_levels[s-> center_mix_level];
312+
float smix = gain_levels[s->surround_mix_level];
325313
float norm0, norm1;
326314

327315
for (i = 0; i < s->fbw_channels; i++) {
@@ -1400,8 +1388,8 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
14001388
avctx->channels = s->out_channels;
14011389
avctx->channel_layout = s->channel_layout;
14021390

1403-
s->loro_center_mix_level = gain_levels[ center_levels[s-> center_mix_level]];
1404-
s->loro_surround_mix_level = gain_levels[surround_levels[s->surround_mix_level]];
1391+
s->loro_center_mix_level = gain_levels[s-> center_mix_level];
1392+
s->loro_surround_mix_level = gain_levels[s->surround_mix_level];
14051393
s->ltrt_center_mix_level = LEVEL_MINUS_3DB;
14061394
s->ltrt_surround_mix_level = LEVEL_MINUS_3DB;
14071395
/* set downmixing coefficients if needed */

0 commit comments

Comments
 (0)