From 90fcac0e95b7d266c148a86506f301a2072d9de3 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 21 Oct 2012 17:02:28 -0400 Subject: flacdec: allow mid-stream channel layout change Although the libFLAC decoder cannot handle such a change, it is allowed by the spec and could potentially occur with live streams. --- libavcodec/flacdec.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'libavcodec/flacdec.c') diff --git a/libavcodec/flacdec.c b/libavcodec/flacdec.c index 4ecf5f27aa..20af820a9d 100644 --- a/libavcodec/flacdec.c +++ b/libavcodec/flacdec.c @@ -66,15 +66,6 @@ typedef struct FLACContext { FLACDSPContext dsp; } FLACContext; -static const int64_t flac_channel_layouts[6] = { - AV_CH_LAYOUT_MONO, - AV_CH_LAYOUT_STEREO, - AV_CH_LAYOUT_SURROUND, - AV_CH_LAYOUT_QUAD, - AV_CH_LAYOUT_5POINT0, - AV_CH_LAYOUT_5POINT1 -}; - static int allocate_buffers(FLACContext *s); static void flac_set_bps(FLACContext *s) @@ -127,9 +118,6 @@ static av_cold int flac_decode_init(AVCodecContext *avctx) avcodec_get_frame_defaults(&s->frame); avctx->coded_frame = &s->frame; - if (avctx->channels <= FF_ARRAY_ELEMS(flac_channel_layouts)) - avctx->channel_layout = flac_channel_layouts[avctx->channels - 1]; - return 0; } @@ -421,7 +409,7 @@ static inline int decode_subframe(FLACContext *s, int channel) static int decode_frame(FLACContext *s) { - int i; + int i, ret; GetBitContext *gb = &s->gb; FLACFrameInfo fi; @@ -430,12 +418,15 @@ static int decode_frame(FLACContext *s) return -1; } - if (s->channels && fi.channels != s->channels) { - av_log(s->avctx, AV_LOG_ERROR, "switching channel layout mid-stream " - "is not supported\n"); - return -1; + if (s->channels && fi.channels != s->channels && s->got_streaminfo) { + s->channels = s->avctx->channels = fi.channels; + ff_flac_set_channel_layout(s->avctx); + ret = allocate_buffers(s); + if (ret < 0) + return ret; } s->channels = s->avctx->channels = fi.channels; + ff_flac_set_channel_layout(s->avctx); s->ch_mode = fi.ch_mode; if (!s->bps && !fi.bps) { @@ -478,7 +469,7 @@ static int decode_frame(FLACContext *s) s->samplerate = s->avctx->sample_rate = fi.samplerate; if (!s->got_streaminfo) { - int ret = allocate_buffers(s); + ret = allocate_buffers(s); if (ret < 0) return ret; ff_flacdsp_init(&s->dsp, s->avctx->sample_fmt, s->bps); -- cgit v1.2.3