Browse code

aacdec: Rework channel mapping compatibility hacks.

For a PCE based configuration map the channels solely based on tags.
For an indexed configuration map the channels solely based on position.

This works with all known exotic samples including al17, elem_id0, bad_concat,
and lfe_is_sce.

Originally committed as revision 25098 to svn://svn.ffmpeg.org/ffmpeg/trunk

Alex Converse authored on 2010/09/11 03:01:48
Showing 2 changed files
... ...
@@ -251,7 +251,6 @@ typedef struct {
251 251
                                                    */
252 252
     ChannelElement          *che[4][MAX_ELEM_ID];
253 253
     ChannelElement  *tag_che_map[4][MAX_ELEM_ID];
254
-    uint8_t tags_seen_this_frame[4][MAX_ELEM_ID];
255 254
     int tags_mapped;
256 255
     /** @} */
257 256
 
... ...
@@ -113,28 +113,11 @@ static const char overread_err[] = "Input buffer exhausted before END element fo
113 113
 
114 114
 static ChannelElement *get_che(AACContext *ac, int type, int elem_id)
115 115
 {
116
-    /* Some buggy encoders appear to set all elem_ids to zero and rely on
117
-    channels always occurring in the same order. This is expressly forbidden
118
-    by the spec but we will try to work around it.
119
-    */
120
-    int err_printed = 0;
121
-    while (ac->tags_seen_this_frame[type][elem_id] && elem_id < MAX_ELEM_ID) {
122
-        if (ac->output_configured < OC_LOCKED && !err_printed) {
123
-            av_log(ac->avctx, AV_LOG_WARNING, "Duplicate channel tag found, attempting to remap.\n");
124
-            err_printed = 1;
125
-        }
126
-        elem_id++;
127
-    }
128
-    if (elem_id == MAX_ELEM_ID)
129
-        return NULL;
130
-    ac->tags_seen_this_frame[type][elem_id] = 1;
131
-
132
-    if (ac->tag_che_map[type][elem_id]) {
116
+    // For PCE based channel configurations map the channels solely based on tags.
117
+    if (!ac->m4ac.chan_config) {
133 118
         return ac->tag_che_map[type][elem_id];
134 119
     }
135
-    if (ac->tags_mapped >= tags_per_config[ac->m4ac.chan_config]) {
136
-        return NULL;
137
-    }
120
+    // For indexed channel configurations map the channels solely based on position.
138 121
     switch (ac->m4ac.chan_config) {
139 122
     case 7:
140 123
         if (ac->tags_mapped == 3 && type == TYPE_CPE) {
... ...
@@ -242,7 +225,6 @@ static av_cold int output_configure(AACContext *ac,
242 242
         }
243 243
 
244 244
         memset(ac->tag_che_map, 0,       4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
245
-        ac->tags_mapped = 0;
246 245
 
247 246
         avctx->channel_layout = aac_channel_layout[channel_config - 1];
248 247
     } else {
... ...
@@ -263,7 +245,6 @@ static av_cold int output_configure(AACContext *ac,
263 263
         }
264 264
 
265 265
         memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
266
-        ac->tags_mapped = 4 * MAX_ELEM_ID;
267 266
 
268 267
         avctx->channel_layout = 0;
269 268
     }
... ...
@@ -1964,7 +1945,7 @@ static int aac_decode_frame(AVCodecContext *avctx, void *data,
1964 1964
         }
1965 1965
     }
1966 1966
 
1967
-    memset(ac->tags_seen_this_frame, 0, sizeof(ac->tags_seen_this_frame));
1967
+    ac->tags_mapped = 0;
1968 1968
     // parse
1969 1969
     while ((elem_type = get_bits(&gb, 3)) != TYPE_END) {
1970 1970
         elem_id = get_bits(&gb, 4);