[FFmpeg-devel] [PATCH 196/281] binkaudio: convert to new channel layout API

James Almer jamrial at gmail.com
Thu Jan 13 04:02:29 EET 2022


From: Anton Khirnov <anton at khirnov.net>

Signed-off-by: Vittorio Giovara <vittorio.giovara at gmail.com>
Signed-off-by: Anton Khirnov <anton at khirnov.net>
Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/binkaudio.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c
index f808141ba5..be321233c8 100644
--- a/libavcodec/binkaudio.c
+++ b/libavcodec/binkaudio.c
@@ -72,6 +72,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
     int sample_rate_half;
     int i, ret;
     int frame_len_bits;
+    int channels = avctx->ch_layout.nb_channels;
 
     /* determine frame length */
     if (avctx->sample_rate < 22050) {
@@ -82,26 +83,26 @@ static av_cold int decode_init(AVCodecContext *avctx)
         frame_len_bits = 11;
     }
 
-    if (avctx->channels < 1 || avctx->channels > MAX_CHANNELS) {
-        av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", avctx->channels);
+    if (channels < 1 || channels > MAX_CHANNELS) {
+        av_log(avctx, AV_LOG_ERROR, "invalid number of channels: %d\n", channels);
         return AVERROR_INVALIDDATA;
     }
-    avctx->channel_layout = avctx->channels == 1 ? AV_CH_LAYOUT_MONO :
-                                                   AV_CH_LAYOUT_STEREO;
+    av_channel_layout_uninit(&avctx->ch_layout);
+    av_channel_layout_default(&avctx->ch_layout, channels);
 
     s->version_b = avctx->extradata_size >= 4 && avctx->extradata[3] == 'b';
 
     if (avctx->codec->id == AV_CODEC_ID_BINKAUDIO_RDFT) {
         // audio is already interleaved for the RDFT format variant
         avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
-        if (sample_rate > INT_MAX / avctx->channels)
+        if (sample_rate > INT_MAX / channels)
             return AVERROR_INVALIDDATA;
-        sample_rate  *= avctx->channels;
+        sample_rate  *= channels;
         s->channels = 1;
         if (!s->version_b)
-            frame_len_bits += av_log2(avctx->channels);
+            frame_len_bits += av_log2(channels);
     } else {
-        s->channels = avctx->channels;
+        s->channels = channels;
         avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
     }
 
@@ -325,7 +326,7 @@ static int binkaudio_receive_frame(AVCodecContext *avctx, AVFrame *frame)
         av_packet_unref(s->pkt);
     }
 
-    frame->nb_samples = s->block_size / avctx->channels;
+    frame->nb_samples = s->block_size / avctx->ch_layout.nb_channels;
 
     return 0;
 fail:
-- 
2.34.1



More information about the ffmpeg-devel mailing list