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++)