diff mbox series

[FFmpeg-devel,17/17] avcodec/dcaenc: Simplify channel layout check

Message ID GV1P250MB073763739995E2C6DADD5B688F4A9@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit ce16d18307559213b20b24c4c824c7014a564590
Headers show
Series [FFmpeg-devel,01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it | 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

Commit Message

Andreas Rheinhardt Sept. 18, 2022, 8:27 p.m. UTC
ff_encode_preinit() ensures that the channel layout is equivalent
to one of the channel layouts in AVCodec.ch_layout; given that
all of these channel layouts have distinct numbers of channels,
one can therefore uniquely determine the channel layout by
the number of channels.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/dcaenc.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/dcaenc.c b/libavcodec/dcaenc.c
index 0996296d8c..46618c13f9 100644
--- a/libavcodec/dcaenc.c
+++ b/libavcodec/dcaenc.c
@@ -222,16 +222,25 @@  static int encode_init(AVCodecContext *avctx)
     if (ff_dcaadpcm_init(&c->adpcm_ctx))
         return AVERROR(ENOMEM);
 
-    if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO))
+    switch (layout.nb_channels) {
+    case 1: /* mono */
         c->channel_config = 0;
-    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO))
+        break;
+    case 2: /* stereo */
         c->channel_config = 2;
-    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2))
+        break;
+    case 4: /* 2.2 */
         c->channel_config = 8;
-    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0))
+        break;
+    case 5: /* 5.0 */
         c->channel_config = 9;
-    else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1))
+        break;
+    case 6: /* 5.1 */
         c->channel_config = 9;
+        break;
+    default:
+        av_assert1(!"impossible channel layout");
+    }
 
     if (c->lfe_channel) {
         c->fullband_channels--;