1
fix aac playback regression
3
patch taken from upstream svn:
5
------------------------------------------------------------------------
6
r17856 | alexc | 2009-03-06 20:47:01 +0100 (Fr, 06. Mär 2009) | 3 lines
8
Fix the channel allocation bug/assumption (issue 800).
9
Approved by Rob on IRC.
11
------------------------------------------------------------------------
12
r17860 | alexc | 2009-03-06 23:36:24 +0100 (Fr, 06. Mär 2009) | 2 lines
14
If we get an error from ff_aac_parse_header() we should not trust the
15
header info that it provides.
17
------------------------------------------------------------------------
18
r17861 | alexc | 2009-03-06 23:37:21 +0100 (Fr, 06. Mär 2009) | 2 lines
20
Re-indent after last commit.
22
------------------------------------------------------------------------
24
diff --git a/libavcodec/aac.c b/libavcodec/aac.c
25
index 80195c0..b6759dd 100644
26
--- a/libavcodec/aac.c
27
+++ b/libavcodec/aac.c
28
@@ -97,6 +97,56 @@ static VLC vlc_scalefactors;
29
static VLC vlc_spectral[11];
32
+static ChannelElement* get_che(AACContext *ac, int type, int elem_id) {
33
+ static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 };
34
+ if (ac->tag_che_map[type][elem_id]) {
35
+ return ac->tag_che_map[type][elem_id];
37
+ if (ac->tags_mapped >= tags_per_config[ac->m4ac.chan_config]) {
40
+ switch (ac->m4ac.chan_config) {
42
+ if (ac->tags_mapped == 3 && type == TYPE_CPE) {
44
+ return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][2];
47
+ /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
48
+ instead of SCE[0] CPE[0] CPE[0] LFE[0]. If we seem to have
49
+ encountered such a stream, transfer the LFE[0] element to SCE[1] */
50
+ if (ac->tags_mapped == tags_per_config[ac->m4ac.chan_config] - 1 && (type == TYPE_LFE || type == TYPE_SCE)) {
52
+ return ac->tag_che_map[type][elem_id] = ac->che[TYPE_LFE][0];
55
+ if (ac->tags_mapped == 2 && type == TYPE_CPE) {
57
+ return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][1];
60
+ if (ac->tags_mapped == 2 && ac->m4ac.chan_config == 4 && type == TYPE_SCE) {
62
+ return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][1];
66
+ if (ac->tags_mapped == (ac->m4ac.chan_config != 2) && type == TYPE_CPE) {
68
+ return ac->tag_che_map[TYPE_CPE][elem_id] = ac->che[TYPE_CPE][0];
69
+ } else if (ac->m4ac.chan_config == 2) {
73
+ if (!ac->tags_mapped && type == TYPE_SCE) {
75
+ return ac->tag_che_map[TYPE_SCE][elem_id] = ac->che[TYPE_SCE][0];
83
* Configure output channel order based on the current program configuration element.
85
@@ -106,7 +156,7 @@ static VLC vlc_spectral[11];
86
* @return Returns error status. 0 - OK, !0 - error
88
static int output_configure(AACContext *ac, enum ChannelPosition che_pos[4][MAX_ELEM_ID],
89
- enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]) {
90
+ enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], int channel_config) {
91
AVCodecContext *avctx = ac->avccontext;
92
int i, type, channels = 0;
94
@@ -140,7 +190,16 @@ static int output_configure(AACContext *ac, enum ChannelPosition che_pos[4][MAX_
98
+ if (channel_config) {
99
+ memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
100
+ ac->tags_mapped = 0;
102
+ memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
103
+ ac->tags_mapped = 4*MAX_ELEM_ID;
106
avctx->channels = channels;
111
@@ -286,7 +345,7 @@ static int decode_ga_specific_config(AACContext * ac, GetBitContext * gb, int ch
112
if((ret = set_default_channel_config(ac, new_che_pos, channel_config)))
115
- if((ret = output_configure(ac, ac->che_pos, new_che_pos)))
116
+ if((ret = output_configure(ac, ac->che_pos, new_che_pos, channel_config)))
119
if (extension_flag) {
120
@@ -394,7 +453,7 @@ static av_cold int aac_decode_init(AVCodecContext * avccontext) {
121
memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
122
if(set_default_channel_config(ac, new_che_pos, avccontext->channels - (avccontext->channels == 8)))
124
- if(output_configure(ac, ac->che_pos, new_che_pos))
125
+ if(output_configure(ac, ac->che_pos, new_che_pos, 1))
127
ac->m4ac.sample_rate = avccontext->sample_rate;
129
@@ -1538,19 +1597,20 @@ static int parse_adts_frame_header(AACContext * ac, GetBitContext * gb) {
130
ac->m4ac.sample_rate = hdr_info.sample_rate;
131
ac->m4ac.sampling_index = hdr_info.sampling_index;
132
ac->m4ac.object_type = hdr_info.object_type;
134
- if (hdr_info.num_aac_frames == 1) {
135
- if (!hdr_info.crc_absent)
138
- ff_log_missing_feature(ac->avccontext, "More than one AAC RDB per ADTS frame is", 0);
140
+ if (hdr_info.num_aac_frames == 1) {
141
+ if (!hdr_info.crc_absent)
144
+ ff_log_missing_feature(ac->avccontext, "More than one AAC RDB per ADTS frame is", 0);
151
static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data_size, const uint8_t * buf, int buf_size) {
152
AACContext * ac = avccontext->priv_data;
153
+ ChannelElement * che = NULL;
155
enum RawDataBlockType elem_type;
156
int err, elem_id, data_size_tmp;
157
@@ -1573,15 +1633,7 @@ static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data
158
elem_id = get_bits(&gb, 4);
161
- if(elem_type == TYPE_SCE && elem_id == 1 &&
162
- !ac->che[TYPE_SCE][elem_id] && ac->che[TYPE_LFE][0]) {
163
- /* Some streams incorrectly code 5.1 audio as SCE[0] CPE[0] CPE[1] SCE[1]
164
- instead of SCE[0] CPE[0] CPE[0] LFE[0]. If we seem to have
165
- encountered such a stream, transfer the LFE[0] element to SCE[1] */
166
- ac->che[TYPE_SCE][elem_id] = ac->che[TYPE_LFE][0];
167
- ac->che[TYPE_LFE][0] = NULL;
169
- if(elem_type < TYPE_DSE && !ac->che[elem_type][elem_id]) {
170
+ if(elem_type < TYPE_DSE && !(che=get_che(ac, elem_type, elem_id))) {
171
av_log(ac->avccontext, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", elem_type, elem_id);
174
@@ -1589,19 +1641,19 @@ static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data
178
- err = decode_ics(ac, &ac->che[TYPE_SCE][elem_id]->ch[0], &gb, 0, 0);
179
+ err = decode_ics(ac, &che->ch[0], &gb, 0, 0);
183
- err = decode_cpe(ac, &gb, ac->che[TYPE_CPE][elem_id]);
184
+ err = decode_cpe(ac, &gb, che);
188
- err = decode_cce(ac, &gb, ac->che[TYPE_CCE][elem_id]);
189
+ err = decode_cce(ac, &gb, che);
193
- err = decode_ics(ac, &ac->che[TYPE_LFE][elem_id]->ch[0], &gb, 0, 0);
194
+ err = decode_ics(ac, &che->ch[0], &gb, 0, 0);
198
@@ -1615,7 +1667,7 @@ static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data
199
memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
200
if((err = decode_pce(ac, new_che_pos, &gb)))
202
- err = output_configure(ac, ac->che_pos, new_che_pos);
203
+ err = output_configure(ac, ac->che_pos, new_che_pos, 0);
207
Modified libavcodec/aac.h
208
diff --git a/libavcodec/aac.h b/libavcodec/aac.h
209
index 66b2e22..32e7224 100644
210
--- a/libavcodec/aac.h
211
+++ b/libavcodec/aac.h
212
@@ -260,6 +260,8 @@ typedef struct {
213
* first index as the first 4 raw data block types
215
ChannelElement * che[4][MAX_ELEM_ID];
216
+ ChannelElement * tag_che_map[4][MAX_ELEM_ID];