diff mbox series

[FFmpeg-devel,04/17] avcodec/avcodec: Always use old channel count/layout if set

Message ID GV1P250MB073727E4A2BF5FEA399BC1FB8F4A9@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM
State Accepted
Commit 90edbd3185e6fac04aed739e2bdef9c69d574b17
Headers show
Series [FFmpeg-devel,01/17] avcodec/avcodec: Uninitialize AVChannelLayout before overwriting it | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 18, 2022, 8:27 p.m. UTC
This ensures that if AVCodecContext.channels or
AVCodecContext.channel_layout are set, AVCodecContext.ch_layout
has the equivalent values after this block.

(In case these values are set inconsistently, the consistency check
for ch_layout below will error out.)

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

Patch

diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index 96b69e0a17..754c21c97a 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -232,7 +232,7 @@  FF_DISABLE_DEPRECATION_WARNINGS
     if (avctx->channel_layout && !avctx->channels)
         avctx->channels = av_popcount64(avctx->channel_layout);
 
-    if ((avctx->channels > 0 && avctx->ch_layout.nb_channels != avctx->channels) ||
+    if ((avctx->channels && avctx->ch_layout.nb_channels != avctx->channels) ||
         (avctx->channel_layout && (avctx->ch_layout.order != AV_CHANNEL_ORDER_NATIVE ||
                                    avctx->ch_layout.u.mask != avctx->channel_layout))) {
         av_channel_layout_uninit(&avctx->ch_layout);
@@ -240,8 +240,8 @@  FF_DISABLE_DEPRECATION_WARNINGS
             av_channel_layout_from_mask(&avctx->ch_layout, avctx->channel_layout);
         } else {
             avctx->ch_layout.order       = AV_CHANNEL_ORDER_UNSPEC;
-            avctx->ch_layout.nb_channels = avctx->channels;
         }
+        avctx->ch_layout.nb_channels = avctx->channels;
     }
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif