diff mbox series

[FFmpeg-devel] libavcodec/mlpdec: add missing correction to ch_layout when downmixing

Message ID 20231126050100.1686194-1-geoff@hostfission.com
State Accepted
Commit 93b5d9030b1f22feb3d8ff242f638d5e0009ce3a
Headers show
Series [FFmpeg-devel] libavcodec/mlpdec: add missing correction to ch_layout when downmixing | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Geoffrey McRae Nov. 26, 2023, 5:01 a.m. UTC
This fixes corrupted audio for applications relying on ch_layout when
codec downmixing is active.

Signed-off-by: Geoffrey McRae <geoff@hostfission.com>
---
 libavcodec/mlpdec.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

James Almer Nov. 26, 2023, 1:19 p.m. UTC | #1
On 11/26/2023 2:01 AM, Geoffrey McRae via ffmpeg-devel wrote:
> This fixes corrupted audio for applications relying on ch_layout when
> codec downmixing is active.
> 
> Signed-off-by: Geoffrey McRae <geoff@hostfission.com>
> ---
>   libavcodec/mlpdec.c | 17 +++++++++++++++++
>   1 file changed, 17 insertions(+)
> 
> diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
> index f1524b95a6..18e0f47864 100644
> --- a/libavcodec/mlpdec.c
> +++ b/libavcodec/mlpdec.c
> @@ -306,6 +306,23 @@ FF_DISABLE_DEPRECATION_WARNINGS
>       }
>   FF_ENABLE_DEPRECATION_WARNINGS
>   #endif
> +
> +    if (m->downmix_layout.nb_channels) {
> +        if (!av_channel_layout_compare(&m->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO) ||
> +            !av_channel_layout_compare(&m->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)) {
> +            av_channel_layout_uninit(&avctx->ch_layout);
> +            avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
> +        } else if (!av_channel_layout_compare(&m->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0)) {
> +            av_channel_layout_uninit(&avctx->ch_layout);
> +            avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0;
> +        } else if (!av_channel_layout_compare(&m->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1)) {
> +            av_channel_layout_uninit(&avctx->ch_layout);
> +            avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1;
> +        }
> +        else
> +          av_log(avctx, AV_LOG_WARNING, "Invalid downmix layout\n");
> +    }
> +
>       ff_thread_once(&init_static_once, init_static);
>   
>       return 0;

Applied, thanks.
diff mbox series

Patch

diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index f1524b95a6..18e0f47864 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -306,6 +306,23 @@  FF_DISABLE_DEPRECATION_WARNINGS
     }
 FF_ENABLE_DEPRECATION_WARNINGS
 #endif
+
+    if (m->downmix_layout.nb_channels) {
+        if (!av_channel_layout_compare(&m->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO) ||
+            !av_channel_layout_compare(&m->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX)) {
+            av_channel_layout_uninit(&avctx->ch_layout);
+            avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
+        } else if (!av_channel_layout_compare(&m->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0)) {
+            av_channel_layout_uninit(&avctx->ch_layout);
+            avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0;
+        } else if (!av_channel_layout_compare(&m->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1)) {
+            av_channel_layout_uninit(&avctx->ch_layout);
+            avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1;
+        }
+        else
+          av_log(avctx, AV_LOG_WARNING, "Invalid downmix layout\n");
+    }
+
     ff_thread_once(&init_static_once, init_static);
 
     return 0;