diff mbox series

[FFmpeg-devel,024/281] alp: convert to new channel layout API

Message ID 20220113015101.4-25-jamrial@gmail.com
State Accepted
Commit 641761ac6e05f1cdafbd1a52b76a90b124daccd0
Headers show
Series New channel layout API | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished
andriy/make_aarch64_jetson success Make finished
andriy/make_fate_aarch64_jetson success Make fate finished
andriy/make_armv7_RPi4 success Make finished
andriy/make_fate_armv7_RPi4 success Make fate finished

Commit Message

James Almer Jan. 13, 2022, 1:49 a.m. UTC
Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/alp.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
diff mbox series

Patch

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);