[FFmpeg-devel] [PATCH]MLP/TrueHD channel_layout for applications not using the mlp_parser

Carl Eugen Hoyos cehoyos at ag.or.at
Thu Apr 14 22:40:31 CEST 2011


Hi!

Attached patch fixes the channel layout (and channel order) for MLP and TrueHD 
in MPlayer. The ff_ renaming and removal of one of the 
av_log_ask_for_sample()'s are left out for brevity.

Please comment, Carl Eugen
-------------- next part --------------
diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c
index 5f0b49a..c7da8a0 100644
--- a/libavcodec/mlp_parser.c
+++ b/libavcodec/mlp_parser.c
@@ -43,7 +43,7 @@ static const uint8_t mlp_channels[32] = {
     5, 6, 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
 };
 
-static const uint64_t mlp_layout[32] = {
+const uint64_t mlp_layout[32] = {
     AV_CH_LAYOUT_MONO,
     AV_CH_LAYOUT_STEREO,
     AV_CH_LAYOUT_2_1,
@@ -107,7 +107,7 @@ static int truehd_channels(int chanmap)
     return channels;
 }
 
-static int64_t truehd_layout(int chanmap)
+int64_t truehd_layout(int chanmap)
 {
     int layout = 0, i;
 
diff --git a/libavcodec/mlp_parser.h b/libavcodec/mlp_parser.h
index d7ce2b8..2313be2 100644
--- a/libavcodec/mlp_parser.h
+++ b/libavcodec/mlp_parser.h
@@ -54,6 +54,9 @@ typedef struct MLPHeaderInfo
 
 
 int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb);
+int64_t truehd_layout(int chanmap);
+
+extern const uint64_t mlp_layout[32];
 
 #endif /* AVCODEC_MLP_PARSER_H */
 
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index 044df5b..30ee4b6 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -329,6 +329,23 @@ static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb)
     for (substr = 0; substr < MAX_SUBSTREAMS; substr++)
         m->substream[substr].restart_seen = 0;
 
+    if (mh.stream_type == 0xbb) {
+        /* MLP stream */
+        m->avctx->channel_layout = mlp_layout[mh.channels_mlp];
+    } else { /* mh.stream_type == 0xba */
+        /* TrueHD stream */
+        if (mh.channels_thd_stream2) {
+            m->avctx->channel_layout = truehd_layout(mh.channels_thd_stream2);
+        } else {
+            m->avctx->channel_layout = truehd_layout(mh.channels_thd_stream1);
+        }
+        if (m->avctx->channels &&
+            av_get_channel_layout_nb_channels(m->avctx->channel_layout) != m->avctx->channels) {
+            m->avctx->channel_layout = 0;
+            av_log_ask_for_sample(m->avctx, "Unknown channel layout.");
+        }
+    }
+
     m->needs_reordering = mh.channels_mlp >= 18 && mh.channels_mlp <= 20;
 
     return 0;


More information about the ffmpeg-devel mailing list