diff mbox series

[FFmpeg-devel] avcodec/mlpdec: relax channel checking

Message ID CAPYw7P7uOBbkFszyG52z+QUWxQ_FZEe3kOWevhvhJuAFQ64T7Q@mail.gmail.com
State New
Headers show
Series [FFmpeg-devel] avcodec/mlpdec: relax channel checking | expand

Checks

Context Check Description
yinshiyou/configure_loongarch64 warning Failed to apply patch
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Paul B Mahol Sept. 17, 2022, 12:10 p.m. UTC
Patch attached.
diff mbox series

Patch

From 5be1fbb848b50e02d302873653e94ed77dea861c Mon Sep 17 00:00:00 2001
From: Paul B Mahol <onemda@gmail.com>
Date: Sat, 17 Sep 2022 14:08:58 +0200
Subject: [PATCH] avcodec/mlpdec: relax channels checking

Internal TrueHD decoder channel rematrix can mix 2 stereo substreams
into single mono stream.

Fixes #1726

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavcodec/mlpdec.c | 23 +----------------------
 1 file changed, 1 insertion(+), 22 deletions(-)

diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index bb72134b09..092344b69a 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -425,6 +425,7 @@  static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb)
                         mh.stream_type);
             return AVERROR_PATCHWELCOME;
         }
+        m->substream[1].mask = mh.channel_layout_thd_stream1;
         if (mh.channels_thd_stream1 == 2 &&
             mh.channels_thd_stream2 == 2 &&
             m->avctx->ch_layout.nb_channels == 2)
@@ -438,16 +439,6 @@  static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb)
                 m->substream[2].mask = mh.channel_layout_thd_stream1;
         if (m->avctx->ch_layout.nb_channels > 2)
             m->substream[mh.num_substreams > 1].mask = mh.channel_layout_thd_stream1;
-
-        if (m->avctx->ch_layout.nb_channels <= 2 &&
-            m->substream[substr].mask == AV_CH_LAYOUT_MONO && m->max_decoded_substream == 1) {
-            av_log(m->avctx, AV_LOG_DEBUG, "Mono stream with 2 substreams, ignoring 2nd\n");
-            m->max_decoded_substream = 0;
-            if (m->avctx->ch_layout.nb_channels == 2) {
-                av_channel_layout_uninit(&m->avctx->ch_layout);
-                m->avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
-            }
-        }
     }
 
     m->needs_reordering = mh.channel_arrangement >= 18 && mh.channel_arrangement <= 20;
@@ -541,12 +532,6 @@  static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
         return AVERROR_INVALIDDATA;
     }
 
-    if (max_channel != max_matrix_channel) {
-        av_log(m->avctx, AV_LOG_ERROR,
-               "Max channel must be equal max matrix channel.\n");
-        return AVERROR_INVALIDDATA;
-    }
-
     /* This should happen for TrueHD streams with >6 channels and MLP's noise
      * type. It is not yet known if this is allowed. */
     if (max_channel > MAX_MATRIX_CHANNEL_MLP && !noise_type) {
@@ -557,12 +542,6 @@  static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp,
         return AVERROR_PATCHWELCOME;
     }
 
-    if (min_channel > max_channel) {
-        av_log(m->avctx, AV_LOG_ERROR,
-               "Substream min channel cannot be greater than max channel.\n");
-        return AVERROR_INVALIDDATA;
-    }
-
     s->min_channel        = min_channel;
     s->max_channel        = max_channel;
     s->coded_channels     = ((1LL << (max_channel - min_channel + 1)) - 1) << min_channel;
-- 
2.37.2