flac: convert to new channel layout API

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
Anton Khirnov 2013-05-07 07:20:32 +02:00 committed by James Almer
parent 06431f1997
commit 5e257c1f7b
5 changed files with 40 additions and 42 deletions

View file

@ -29,15 +29,15 @@
static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 }; static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 };
static const uint64_t flac_channel_layouts[8] = { static const AVChannelLayout flac_channel_layouts[8] = {
AV_CH_LAYOUT_MONO, AV_CHANNEL_LAYOUT_MONO,
AV_CH_LAYOUT_STEREO, AV_CHANNEL_LAYOUT_STEREO,
AV_CH_LAYOUT_SURROUND, AV_CHANNEL_LAYOUT_SURROUND,
AV_CH_LAYOUT_QUAD, AV_CHANNEL_LAYOUT_QUAD,
AV_CH_LAYOUT_5POINT0, AV_CHANNEL_LAYOUT_5POINT0,
AV_CH_LAYOUT_5POINT1, AV_CHANNEL_LAYOUT_5POINT1,
AV_CH_LAYOUT_6POINT1, AV_CHANNEL_LAYOUT_6POINT1,
AV_CH_LAYOUT_7POINT1 AV_CHANNEL_LAYOUT_7POINT1
}; };
static int64_t get_utf8(GetBitContext *gb) static int64_t get_utf8(GetBitContext *gb)
@ -193,12 +193,18 @@ int ff_flac_is_extradata_valid(AVCodecContext *avctx,
return 1; return 1;
} }
void ff_flac_set_channel_layout(AVCodecContext *avctx) void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels)
{ {
if (avctx->channels <= FF_ARRAY_ELEMS(flac_channel_layouts)) if (channels == avctx->ch_layout.nb_channels &&
avctx->channel_layout = flac_channel_layouts[avctx->channels - 1]; avctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC)
return;
av_channel_layout_uninit(&avctx->ch_layout);
if (channels <= FF_ARRAY_ELEMS(flac_channel_layouts))
avctx->ch_layout = flac_channel_layouts[channels - 1];
else else
avctx->channel_layout = 0; avctx->ch_layout = (AVChannelLayout){ .order = AV_CHANNEL_ORDER_UNSPEC,
.nb_channels = channels };
} }
int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
@ -229,13 +235,9 @@ int ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s,
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
avctx->channels = s->channels;
avctx->sample_rate = s->samplerate; avctx->sample_rate = s->samplerate;
avctx->bits_per_raw_sample = s->bps; avctx->bits_per_raw_sample = s->bps;
ff_flac_set_channel_layout(avctx, s->channels);
if (!avctx->channel_layout ||
av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels)
ff_flac_set_channel_layout(avctx);
s->samples = get_bits64(&gb, 36); s->samples = get_bits64(&gb, 36);

View file

@ -131,7 +131,7 @@ int ff_flac_get_max_frame_size(int blocksize, int ch, int bps);
int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, int ff_flac_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,
FLACFrameInfo *fi, int log_level_offset); FLACFrameInfo *fi, int log_level_offset);
void ff_flac_set_channel_layout(AVCodecContext *avctx); void ff_flac_set_channel_layout(AVCodecContext *avctx, int channels);
/** /**
* Parse the metadata block parameters from the header. * Parse the metadata block parameters from the header.

View file

@ -628,11 +628,8 @@ static int get_best_header(FLACParseContext *fpc, const uint8_t **poutbuf,
check_header_mismatch(fpc, header, child, 0); check_header_mismatch(fpc, header, child, 0);
} }
if (header->fi.channels != fpc->avctx->channels || ff_flac_set_channel_layout(fpc->avctx, header->fi.channels);
!fpc->avctx->channel_layout) {
fpc->avctx->channels = header->fi.channels;
ff_flac_set_channel_layout(fpc->avctx);
}
fpc->avctx->sample_rate = header->fi.samplerate; fpc->avctx->sample_rate = header->fi.samplerate;
fpc->pc->duration = header->fi.blocksize; fpc->pc->duration = header->fi.blocksize;
*poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size, *poutbuf = flac_fifo_read_wrap(fpc, header->offset, *poutbuf_size,

View file

@ -483,15 +483,14 @@ static int decode_frame(FLACContext *s)
if ( s->flac_stream_info.channels if ( s->flac_stream_info.channels
&& fi.channels != s->flac_stream_info.channels && fi.channels != s->flac_stream_info.channels
&& s->got_streaminfo) { && s->got_streaminfo) {
s->flac_stream_info.channels = s->avctx->channels = fi.channels; s->flac_stream_info.channels = fi.channels;
ff_flac_set_channel_layout(s->avctx); ff_flac_set_channel_layout(s->avctx, fi.channels);
ret = allocate_buffers(s); ret = allocate_buffers(s);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
s->flac_stream_info.channels = s->avctx->channels = fi.channels; s->flac_stream_info.channels = fi.channels;
if (!s->avctx->channel_layout) ff_flac_set_channel_layout(s->avctx, fi.channels);
ff_flac_set_channel_layout(s->avctx);
s->ch_mode = fi.ch_mode; s->ch_mode = fi.ch_mode;
if (!s->flac_stream_info.bps && !fi.bps) { if (!s->flac_stream_info.bps && !fi.bps) {

View file

@ -241,7 +241,7 @@ static av_cold void dprint_compression_options(FlacEncodeContext *s)
static av_cold int flac_encode_init(AVCodecContext *avctx) static av_cold int flac_encode_init(AVCodecContext *avctx)
{ {
int freq = avctx->sample_rate; int freq = avctx->sample_rate;
int channels = avctx->channels; int channels = avctx->ch_layout.nb_channels;
FlacEncodeContext *s = avctx->priv_data; FlacEncodeContext *s = avctx->priv_data;
int i, level, ret; int i, level, ret;
uint8_t *streaminfo; uint8_t *streaminfo;
@ -398,18 +398,18 @@ static av_cold int flac_encode_init(AVCodecContext *avctx)
s->frame_count = 0; s->frame_count = 0;
s->min_framesize = s->max_framesize; s->min_framesize = s->max_framesize;
if (channels == 3 && if ((channels == 3 &&
avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) || av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_SURROUND)) ||
channels == 4 && (channels == 4 &&
avctx->channel_layout != AV_CH_LAYOUT_2_2 && av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2) &&
avctx->channel_layout != AV_CH_LAYOUT_QUAD || av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD)) ||
channels == 5 && (channels == 5 &&
avctx->channel_layout != AV_CH_LAYOUT_5POINT0 && av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0) &&
avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK || av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0_BACK)) ||
channels == 6 && (channels == 6 &&
avctx->channel_layout != AV_CH_LAYOUT_5POINT1 && av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1) &&
avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK) { av_channel_layout_compare(&avctx->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK))) {
if (avctx->channel_layout) { if (avctx->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC) {
av_log(avctx, AV_LOG_ERROR, "Channel layout not supported by Flac, " av_log(avctx, AV_LOG_ERROR, "Channel layout not supported by Flac, "
"output stream will have incorrect " "output stream will have incorrect "
"channel layout.\n"); "channel layout.\n");