OSDN Git Service

mlp_parser: account for AVCodecContext.request_channels when setting the channel...
authorTim Walker <tdskywalker@gmail.com>
Mon, 31 Dec 2012 14:33:26 +0000 (15:33 +0100)
committerJustin Ruggles <justin.ruggles@gmail.com>
Tue, 22 Jan 2013 21:10:02 +0000 (16:10 -0500)
Allows users to configure the output based on what's actually decoded, rather than the full native layout.

Signed-off-by: Justin Ruggles <justin.ruggles@gmail.com>
libavcodec/mlp_parser.c

index 31c79c9..8c57840 100644 (file)
@@ -322,11 +322,23 @@ static int mlp_parse(AVCodecParserContext *s,
 
         if (mh.stream_type == 0xbb) {
             /* MLP stream */
-            avctx->channels       = mh.channels_mlp;
-            avctx->channel_layout = mh.channel_layout_mlp;
+            if (avctx->request_channels > 0 && avctx->request_channels <= 2 &&
+                mh.num_substreams > 1) {
+                avctx->channels       = 2;
+                avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+            } else {
+                avctx->channels       = mh.channels_mlp;
+                avctx->channel_layout = mh.channel_layout_mlp;
+            }
         } else { /* mh.stream_type == 0xba */
             /* TrueHD stream */
-            if (mh.channels_thd_stream2) {
+            if (avctx->request_channels > 0 && avctx->request_channels <= 2 &&
+                mh.num_substreams > 1) {
+                avctx->channels       = 2;
+                avctx->channel_layout = AV_CH_LAYOUT_STEREO;
+            } else if (mh.channels_thd_stream2 &&
+                       (avctx->request_channels <= 0 ||
+                        avctx->request_channels > mh.channels_thd_stream1)) {
                 avctx->channels       = mh.channels_thd_stream2;
                 avctx->channel_layout = mh.channel_layout_thd_stream2;
             } else {