Browse code

Ignore subsequent channel configurations after the first in an AAC file. The current code doesn't handle them properly, and they are a dubious construction at best.

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

Alex Converse authored on 2009/07/11 06:53:04
Showing 2 changed files
... ...
@@ -199,6 +199,8 @@ static int output_configure(AACContext *ac, enum ChannelPosition che_pos[4][MAX_
199 199
 
200 200
     avctx->channels = channels;
201 201
 
202
+    ac->output_configured = 1;
203
+
202 204
     return 0;
203 205
 }
204 206
 
... ...
@@ -445,12 +447,6 @@ static av_cold int aac_decode_init(AVCodecContext * avccontext) {
445 445
             return -1;
446 446
         avccontext->sample_rate = ac->m4ac.sample_rate;
447 447
     } else if (avccontext->channels > 0) {
448
-        enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
449
-        memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
450
-        if(set_default_channel_config(ac, new_che_pos, avccontext->channels - (avccontext->channels == 8)))
451
-            return -1;
452
-        if(output_configure(ac, ac->che_pos, new_che_pos, 1))
453
-            return -1;
454 448
         ac->m4ac.sample_rate = avccontext->sample_rate;
455 449
     }
456 450
 
... ...
@@ -1579,8 +1575,15 @@ static int parse_adts_frame_header(AACContext * ac, GetBitContext * gb) {
1579 1579
 
1580 1580
     size = ff_aac_parse_header(gb, &hdr_info);
1581 1581
     if (size > 0) {
1582
-        if (hdr_info.chan_config)
1582
+        if (!ac->output_configured && hdr_info.chan_config) {
1583
+            enum ChannelPosition new_che_pos[4][MAX_ELEM_ID];
1584
+            memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
1583 1585
             ac->m4ac.chan_config = hdr_info.chan_config;
1586
+            if (set_default_channel_config(ac, new_che_pos, hdr_info.chan_config))
1587
+                return -7;
1588
+            if (output_configure(ac, ac->che_pos, new_che_pos, 1))
1589
+                return -7;
1590
+        }
1584 1591
         ac->m4ac.sample_rate     = hdr_info.sample_rate;
1585 1592
         ac->m4ac.sampling_index  = hdr_info.sampling_index;
1586 1593
         ac->m4ac.object_type     = hdr_info.object_type;
... ...
@@ -1655,6 +1658,10 @@ static int aac_decode_frame(AVCodecContext * avccontext, void * data, int * data
1655 1655
             memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0]));
1656 1656
             if((err = decode_pce(ac, new_che_pos, &gb)))
1657 1657
                 break;
1658
+            if (ac->output_configured)
1659
+                av_log(avccontext, AV_LOG_ERROR,
1660
+                       "Not evaluating a further program_config_element as this construct is dubious at best.\n");
1661
+            else
1658 1662
             err = output_configure(ac, ac->che_pos, new_che_pos, 0);
1659 1663
             break;
1660 1664
         }
... ...
@@ -274,6 +274,8 @@ typedef struct {
274 274
     /** @} */
275 275
 
276 276
     DECLARE_ALIGNED(16, float, temp[128]);
277
+
278
+    int output_configured;
277 279
 } AACContext;
278 280
 
279 281
 #endif /* AVCODEC_AAC_H */