[FFmpeg-cvslog] avcodec/mlpenc: add helper function to derive TrueHD ch map from ch_layout

Paul B Mahol git at videolan.org
Fri Oct 20 18:09:38 EEST 2023


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Thu Oct 19 22:11:33 2023 +0200| [94abb4df325f2a903aca62020e00dd9e79205517] | committer: Paul B Mahol

avcodec/mlpenc: add helper function to derive TrueHD ch map from ch_layout

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=94abb4df325f2a903aca62020e00dd9e79205517
---

 libavcodec/mlp_parse.h | 12 ++++++++++++
 libavcodec/mlpenc.c    | 11 +++--------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/libavcodec/mlp_parse.h b/libavcodec/mlp_parse.h
index fa6e3d52dc..5f1f953cfe 100644
--- a/libavcodec/mlp_parse.h
+++ b/libavcodec/mlp_parse.h
@@ -113,6 +113,18 @@ static inline uint64_t truehd_layout(int chanmap)
     return layout;
 }
 
+static inline int layout_truehd(uint64_t layout)
+{
+    int chanmap = 0;
+
+    for (int i = 0; i < 13; i++) {
+        if ((layout & thd_layout[i]) == thd_layout[i])
+            chanmap |= 1 << i;
+    }
+
+    return chanmap;
+}
+
 int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb);
 
 #endif /* AVCODEC_MLP_PARSE_H */
diff --git a/libavcodec/mlpenc.c b/libavcodec/mlpenc.c
index 70f9120e8b..4a3d466ba7 100644
--- a/libavcodec/mlpenc.c
+++ b/libavcodec/mlpenc.c
@@ -35,6 +35,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/thread.h"
+#include "mlp_parse.h"
 #include "mlp.h"
 #include "lpc.h"
 
@@ -577,29 +578,21 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
             ctx->ch2_presentation_mod= 3;
             ctx->ch6_presentation_mod= 3;
             ctx->ch8_presentation_mod= 3;
-            ctx->channel_arrangement = 2;
-            ctx->channel_arrangement8= 2;
             ctx->thd_substream_info  = 0x14;
         } else if (channels_present == AV_CH_LAYOUT_STEREO) {
             ctx->ch2_presentation_mod= 1;
             ctx->ch6_presentation_mod= 1;
             ctx->ch8_presentation_mod= 1;
-            ctx->channel_arrangement = 1;
-            ctx->channel_arrangement8= 1;
             ctx->thd_substream_info  = 0x14;
         } else if (channels_present == AV_CH_LAYOUT_5POINT0) {
             ctx->ch2_presentation_mod= 1;
             ctx->ch6_presentation_mod= 1;
             ctx->ch8_presentation_mod= 1;
-            ctx->channel_arrangement = 11;
-            ctx->channel_arrangement8= 11;
             ctx->thd_substream_info  = 0x104;
         } else if (channels_present == AV_CH_LAYOUT_5POINT1) {
             ctx->ch2_presentation_mod= 2;
             ctx->ch6_presentation_mod= 1;
             ctx->ch8_presentation_mod= 2;
-            ctx->channel_arrangement = 15;
-            ctx->channel_arrangement8= 15;
             ctx->thd_substream_info  = 0x104;
         } else {
             av_assert1(!"AVCodec.ch_layouts needs to be updated");
@@ -607,6 +600,8 @@ static av_cold int mlp_encode_init(AVCodecContext *avctx)
         ctx->flags = 0;
         ctx->channel_occupancy = 0;
         ctx->summary_info = 0;
+        ctx->channel_arrangement =
+        ctx->channel_arrangement8 = layout_truehd(channels_present);
     }
 
     for (unsigned int index = 0; index < ctx->restart_intervals; index++)



More information about the ffmpeg-cvslog mailing list