summaryrefslogtreecommitdiff
path: root/libavcodec/flacdec.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2012-10-21 17:02:28 -0400
committerJustin Ruggles <justin.ruggles@gmail.com>2012-11-01 11:29:16 -0400
commit90fcac0e95b7d266c148a86506f301a2072d9de3 (patch)
tree3a98aa2c6d0bf7e22f78894dc5f308a7db0732d3 /libavcodec/flacdec.c
parent268f8ba112570956f1d7be8f4f2f0bea86c61461 (diff)
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.
Diffstat (limited to 'libavcodec/flacdec.c')
-rw-r--r--libavcodec/flacdec.c27
1 files changed, 9 insertions, 18 deletions
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);