Revision bb2d8e9f

View differences:

libavcodec/aac.h
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

  
libavcodec/aacdec.c
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 225
        }
243 226

  
244 227
        memset(ac->tag_che_map, 0,       4 * MAX_ELEM_ID * sizeof(ac->che[0][0]));
245
        ac->tags_mapped = 0;
246 228

  
247 229
        avctx->channel_layout = aac_channel_layout[channel_config - 1];
248 230
    } else {
......
263 245
        }
264 246

  
265 247
        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 248

  
268 249
        avctx->channel_layout = 0;
269 250
    }
......
1964 1945
        }
1965 1946
    }
1966 1947

  
1967
    memset(ac->tags_seen_this_frame, 0, sizeof(ac->tags_seen_this_frame));
1948
    ac->tags_mapped = 0;
1968 1949
    // parse
1969 1950
    while ((elem_type = get_bits(&gb, 3)) != TYPE_END) {
1970 1951
        elem_id = get_bits(&gb, 4);

Also available in: Unified diff