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/flac.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libavcodec/flac.c') diff --git a/libavcodec/flac.c b/libavcodec/flac.c index d624beb61f..07da702e94 100644 --- a/libavcodec/flac.c +++ b/libavcodec/flac.c @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/audioconvert.h" #include "libavutil/crc.h" #include "libavutil/log.h" #include "bytestream.h" @@ -28,6 +29,15 @@ static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 }; +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 int64_t get_utf8(GetBitContext *gb) { int64_t val; @@ -181,6 +191,14 @@ int avpriv_flac_is_extradata_valid(AVCodecContext *avctx, return 1; } +void ff_flac_set_channel_layout(AVCodecContext *avctx) +{ + if (avctx->channels <= FF_ARRAY_ELEMS(flac_channel_layouts)) + avctx->channel_layout = flac_channel_layouts[avctx->channels - 1]; + else + avctx->channel_layout = 0; +} + void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, const uint8_t *buffer) { @@ -205,6 +223,7 @@ void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo * avctx->channels = s->channels; avctx->sample_rate = s->samplerate; avctx->bits_per_raw_sample = s->bps; + ff_flac_set_channel_layout(avctx); s->samples = get_bits_long(&gb, 32) << 4; s->samples |= get_bits(&gb, 4); -- cgit v1.2.3