From 932cee5d6730c1358cb564ee0c84423ddd9ab21c Mon Sep 17 00:00:00 2001
From: Ramiro Polla <ramiro.polla@gmail.com>
Date: Fri, 20 Mar 2009 13:02:15 +0000
Subject: [PATCH] truehd: support up to 3 substreams.

Originally committed as revision 18072 to svn://svn.ffmpeg.org/ffmpeg/trunk
---
 libavcodec/mlp.h    | 6 +++---
 libavcodec/mlpdec.c | 4 ++++
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/libavcodec/mlp.h b/libavcodec/mlp.h
index 032a8f6bdff..c19b69915e9 100644
--- a/libavcodec/mlp.h
+++ b/libavcodec/mlp.h
@@ -34,10 +34,10 @@
  */
 #define MAX_MATRICES        15
 
-/** Maximum number of substreams that can be decoded. This could also be set
- *  higher, but I haven't seen any examples with more than two.
+/** Maximum number of substreams that can be decoded.
+ *  MLP's limit is 2. TrueHD supports at least up to 3.
  */
-#define MAX_SUBSTREAMS      2
+#define MAX_SUBSTREAMS      3
 
 /** maximum sample frequency seen in files */
 #define MAX_SAMPLERATE      192000
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index 6b825cdea11..c71450062a0 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -280,6 +280,10 @@ static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb)
 
     if (mh.num_substreams == 0)
         return -1;
+    if (m->avctx->codec_id == CODEC_ID_MLP && mh.num_substreams > 2) {
+        av_log(m->avctx, AV_LOG_ERROR, "MLP only supports up to 2 substreams.\n");
+        return -1;
+    }
     if (mh.num_substreams > MAX_SUBSTREAMS) {
         av_log(m->avctx, AV_LOG_ERROR,
                "Number of substreams %d is larger than the maximum supported "
-- 
GitLab