summaryrefslogtreecommitdiff
path: root/libavcodec/ac3_parser.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2012-01-19 00:06:03 +0100
committerMichael Niedermayer <michaelni@gmx.at>2012-01-21 05:29:47 +0100
commit99a42f3fa95aa68f6c945e98e043d69e541d93cc (patch)
tree438cc910521b3d5484763a4a3dbfbc5ce83debc1 /libavcodec/ac3_parser.c
parent9ec39937f9c7f28a2279a19f71f290d8161eb52f (diff)
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 <justin.ruggles@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/ac3_parser.c')
-rw-r--r--libavcodec/ac3_parser.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/libavcodec/ac3_parser.c b/libavcodec/ac3_parser.c
index 17f205bfd2..14ca196aaf 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);