mpegaudio: convert to new channel layout API

Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
Anton Khirnov 2019-05-29 09:36:27 +02:00 committed by James Almer
parent a96c94bbd8
commit 53d25983bf
6 changed files with 26 additions and 13 deletions

View File

@ -98,7 +98,7 @@ static int mp3_header_decompress(AVBSFContext *ctx, AVPacket *out)
}
memcpy(out->data + frame_size - buf_size, buf, buf_size + AV_INPUT_BUFFER_PADDING_SIZE);
if(ctx->par_in->channels==2){
if (ctx->par_in->ch_layout.nb_channels == 2){
uint8_t *p= out->data + frame_size - buf_size;
if(lsf){
FFSWAP(int, p[1], p[2]);

View File

@ -84,7 +84,8 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
if (s->header_count > header_threshold) {
avctx->sample_rate= sr;
avctx->channels = channels;
av_channel_layout_uninit(&avctx->ch_layout);
av_channel_layout_default(&avctx->ch_layout, channels);
s1->duration = frame_size;
avctx->codec_id = codec_id;
if (s->no_bitrate || !avctx->bit_rate) {

View File

@ -1580,8 +1580,9 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr,
return AVERROR_INVALIDDATA;
}
/* update codec info */
avctx->channels = s->nb_channels;
avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
av_channel_layout_uninit(&avctx->ch_layout);
avctx->ch_layout = s->nb_channels == 1 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
if (!avctx->bit_rate)
avctx->bit_rate = s->bit_rate;
@ -1661,8 +1662,9 @@ static int decode_frame_adu(AVCodecContext *avctx, void *data,
}
/* update codec info */
avctx->sample_rate = s->sample_rate;
avctx->channels = s->nb_channels;
avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO;
av_channel_layout_uninit(&avctx->ch_layout);
avctx->ch_layout = s->nb_channels == 1 ? (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO :
(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
if (!avctx->bit_rate)
avctx->bit_rate = s->bit_rate;
@ -1756,8 +1758,8 @@ static av_cold int decode_init_mp3on4(AVCodecContext * avctx)
}
s->frames = mp3Frames[cfg.chan_config];
s->coff = chan_offset[cfg.chan_config];
avctx->channels = ff_mpeg4audio_channels[cfg.chan_config];
avctx->channel_layout = chan_layout[cfg.chan_config];
av_channel_layout_uninit(&avctx->ch_layout);
av_channel_layout_from_mask(&avctx->ch_layout, chan_layout[cfg.chan_config]);
if (cfg.sample_rate < 16000)
s->syncword = 0xffe00000;
@ -1854,8 +1856,8 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
return AVERROR_INVALIDDATA;
}
if (ch + m->nb_channels > avctx->channels ||
s->coff[fr] + m->nb_channels > avctx->channels) {
if (ch + m->nb_channels > avctx->ch_layout.nb_channels ||
s->coff[fr] + m->nb_channels > avctx->ch_layout.nb_channels) {
av_log(avctx, AV_LOG_ERROR, "frame channel count exceeds codec "
"channel count\n");
return AVERROR_INVALIDDATA;
@ -1880,7 +1882,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
avctx->bit_rate += m->bit_rate;
}
if (ch != avctx->channels) {
if (ch != avctx->ch_layout.nb_channels) {
av_log(avctx, AV_LOG_ERROR, "failed to decode all channels\n");
return AVERROR_INVALIDDATA;
}
@ -1888,7 +1890,7 @@ static int decode_frame_mp3on4(AVCodecContext *avctx, void *data,
/* update codec info */
avctx->sample_rate = s->mp3decctx[0]->sample_rate;
frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT));
frame->nb_samples = out_size / (avctx->ch_layout.nb_channels * sizeof(OUT_INT));
*got_frame_ptr = 1;
return buf_size;

View File

@ -35,9 +35,14 @@ const AVCodec ff_mp2fixed_encoder = {
.supported_samplerates = (const int[]){
44100, 48000, 32000, 22050, 24000, 16000, 0
},
#if FF_API_OLD_CHANNEL_LAYOUT
.channel_layouts = (const uint64_t[]){ AV_CH_LAYOUT_MONO,
AV_CH_LAYOUT_STEREO,
0 },
#endif
.ch_layouts = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO,
AV_CHANNEL_LAYOUT_STEREO,
{ 0 } },
.defaults = mp2_defaults,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
};

View File

@ -36,9 +36,14 @@ const AVCodec ff_mp2_encoder = {
.supported_samplerates = (const int[]){
44100, 48000, 32000, 22050, 24000, 16000, 0
},
#if FF_API_OLD_CHANNEL_LAYOUT
.channel_layouts = (const uint64_t[]){ AV_CH_LAYOUT_MONO,
AV_CH_LAYOUT_STEREO,
0 },
#endif
.ch_layouts = (const AVChannelLayout[]){ AV_CHANNEL_LAYOUT_MONO,
AV_CHANNEL_LAYOUT_STEREO,
{ 0 } },
.defaults = mp2_defaults,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
};

View File

@ -79,7 +79,7 @@ static av_cold int MPA_encode_init(AVCodecContext *avctx)
MpegAudioContext *s = avctx->priv_data;
int freq = avctx->sample_rate;
int bitrate = avctx->bit_rate;
int channels = avctx->channels;
int channels = avctx->ch_layout.nb_channels;
int i, v, table;
float a;