From 641761ac6e05f1cdafbd1a52b76a90b124daccd0 Mon Sep 17 00:00:00 2001 From: James Almer Date: Mon, 23 Aug 2021 23:01:06 -0300 Subject: [PATCH] alp: convert to new channel layout API Signed-off-by: James Almer --- libavformat/alp.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/libavformat/alp.c b/libavformat/alp.c index f46bdb4511..444b55dd77 100644 --- a/libavformat/alp.c +++ b/libavformat/alp.c @@ -119,18 +119,14 @@ static int alp_read_header(AVFormatContext *s) par->codec_id = AV_CODEC_ID_ADPCM_IMA_ALP; par->format = AV_SAMPLE_FMT_S16; par->sample_rate = hdr->sample_rate; - par->channels = hdr->num_channels; - if (hdr->num_channels == 1) - par->channel_layout = AV_CH_LAYOUT_MONO; - else if (hdr->num_channels == 2) - par->channel_layout = AV_CH_LAYOUT_STEREO; - else + if (hdr->num_channels > 2) return AVERROR_INVALIDDATA; + av_channel_layout_default(&par->ch_layout, hdr->num_channels); par->bits_per_coded_sample = 4; par->block_align = 1; - par->bit_rate = par->channels * + par->bit_rate = par->ch_layout.nb_channels * par->sample_rate * par->bits_per_coded_sample; @@ -148,7 +144,7 @@ static int alp_read_packet(AVFormatContext *s, AVPacket *pkt) pkt->flags &= ~AV_PKT_FLAG_CORRUPT; pkt->stream_index = 0; - pkt->duration = ret * 2 / par->channels; + pkt->duration = ret * 2 / par->ch_layout.nb_channels; return 0; } @@ -202,7 +198,7 @@ static int alp_write_init(AVFormatContext *s) return AVERROR(EINVAL); } - if (par->channels > 2) { + if (par->ch_layout.nb_channels > 2) { av_log(s, AV_LOG_ERROR, "A maximum of 2 channels are supported\n"); return AVERROR(EINVAL); } @@ -228,7 +224,7 @@ static int alp_write_header(AVFormatContext *s) avio_wl32(s->pb, alp->type == ALP_TYPE_PCM ? 12 : 8); avio_write(s->pb, "ADPCM", 6); avio_w8(s->pb, 0); - avio_w8(s->pb, par->channels); + avio_w8(s->pb, par->ch_layout.nb_channels); if (alp->type == ALP_TYPE_PCM) avio_wl32(s->pb, par->sample_rate);