Browse code

aacdec: Work around illegal files with all elem_id tags set to the same value.

Fixes issue 1882.

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

Alex Converse authored on 2010/06/03 11:17:49
Showing 2 changed files
... ...
@@ -113,6 +113,22 @@ 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->avccontext, 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
+
116 132
     if (ac->tag_che_map[type][elem_id]) {
117 133
         return ac->tag_che_map[type][elem_id];
118 134
     }
... ...
@@ -1969,6 +1985,7 @@ static int aac_decode_frame(AVCodecContext *avccontext, void *data,
1969 1969
         }
1970 1970
     }
1971 1971
 
1972
+    memset(ac->tags_seen_this_frame, 0, sizeof(ac->tags_seen_this_frame));
1972 1973
     // parse
1973 1974
     while ((elem_type = get_bits(&gb, 3)) != TYPE_END) {
1974 1975
         elem_id = get_bits(&gb, 4);
... ...
@@ -257,6 +257,7 @@ typedef struct {
257 257
                                                    */
258 258
     ChannelElement * che[4][MAX_ELEM_ID];
259 259
     ChannelElement * tag_che_map[4][MAX_ELEM_ID];
260
+    uint8_t tags_seen_this_frame[4][MAX_ELEM_ID];
260 261
     int tags_mapped;
261 262
     /** @} */
262 263