flac: only set channel layout if not previously set or on channel count change
authorJustin Ruggles <justin.ruggles@gmail.com>
Sun, 16 Dec 2012 16:02:39 +0000 (11:02 -0500)
committerJustin Ruggles <justin.ruggles@gmail.com>
Sat, 22 Dec 2012 06:35:28 +0000 (01:35 -0500)
Fixes Bug 402

libavcodec/flac_parser.c
libavcodec/flacdec.c

index f0a37f310e6429666e71e59c31f99c9c73d3c253..3d8e17f9953760b8247ea891b61983be67518d54 100644 (file)
@@ -457,9 +457,12 @@ static int get_best_header(FLACParseContext* fpc, const uint8_t **poutbuf,
         check_header_mismatch(fpc, header, child, 0);
     }
 
+    if (header->fi.channels != fpc->avctx->channels ||
+        (!fpc->avctx->channel_layout && header->fi.channels <= 6)) {
+        fpc->avctx->channels = header->fi.channels;
+        ff_flac_set_channel_layout(fpc->avctx);
+    }
     fpc->avctx->sample_rate = header->fi.samplerate;
-    fpc->avctx->channels    = header->fi.channels;
-    ff_flac_set_channel_layout(fpc->avctx);
     fpc->pc->duration       = header->fi.blocksize;
     *poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size,
                                         &fpc->wrap_buf,
index fd47929c50c89734e6e60907a47bf2fbf1d30c7b..51fd19628cf89ebb99c34ff6228e5164044ab757 100644 (file)
@@ -426,7 +426,8 @@ static int decode_frame(FLACContext *s)
             return ret;
     }
     s->channels = s->avctx->channels = fi.channels;
-    ff_flac_set_channel_layout(s->avctx);
+    if (!s->avctx->channel_layout && s->channels <= 6)
+        ff_flac_set_channel_layout(s->avctx);
     s->ch_mode = fi.ch_mode;
 
     if (!s->bps && !fi.bps) {