diff options
author | Paul B Mahol <onemda@gmail.com> | 2023-10-19 22:11:33 +0200 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2023-10-20 17:07:22 +0200 |
commit | 94abb4df325f2a903aca62020e00dd9e79205517 (patch) | |
tree | c27272b998d0700353847fdd8d92efed0e2def2d | |
parent | 2d1aeba8f26869dff6857087f48066f76dba8dc5 (diff) | |
download | ffmpeg-94abb4df325f2a903aca62020e00dd9e79205517.tar.gz |
avcodec/mlpenc: add helper function to derive TrueHD ch map from ch_layout
-rw-r--r-- | libavcodec/mlp_parse.h | 12 | ||||
-rw-r--r-- | 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++) |