X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=libavcodec%2Fmlp_parser.c;h=075227f302dbbdb1ec9e0294006617bc2109f7fc;hb=d961a79eb07a8911540a0bd356d68ae0cf93c6a1;hp=016252cfb6423e5751a9d762b5a03a8cfb431715;hpb=36ef5369ee9b336febc2c270f8718cec4476cb85;p=ffmpeg diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c index 016252cfb64..075227f302d 100644 --- a/libavcodec/mlp_parser.c +++ b/libavcodec/mlp_parser.c @@ -26,8 +26,9 @@ #include +#include "libavutil/channel_layout.h" #include "libavutil/crc.h" -#include "libavutil/audioconvert.h" +#include "libavutil/internal.h" #include "get_bits.h" #include "parser.h" #include "mlp_parser.h" @@ -83,10 +84,10 @@ static const uint64_t thd_layout[13] = { AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, // LRrs AV_CH_BACK_CENTER, // Cs AV_CH_TOP_CENTER, // Ts - AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, // LRsd + AV_CH_SURROUND_DIRECT_LEFT|AV_CH_SURROUND_DIRECT_RIGHT, // LRsd AV_CH_WIDE_LEFT|AV_CH_WIDE_RIGHT, // LRw AV_CH_TOP_FRONT_CENTER, // Cvh - AV_CH_LOW_FREQUENCY // LFE2 + AV_CH_LOW_FREQUENCY_2, // LFE2 }; static int mlp_samplerate(int in) @@ -126,7 +127,7 @@ static uint64_t truehd_layout(int chanmap) int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb) { - int ratebits; + int ratebits, channel_arrangement; uint16_t checksum; assert(get_bits_count(gb) == 0); @@ -157,7 +158,9 @@ int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb) skip_bits(gb, 11); - mh->channels_mlp = get_bits(gb, 5); + channel_arrangement = get_bits(gb, 5); + mh->channels_mlp = mlp_channels[channel_arrangement]; + mh->channel_layout_mlp = mlp_layout[channel_arrangement]; } else if (mh->stream_type == 0xba) { mh->group1_bits = 24; // TODO: Is this information actually conveyed anywhere? mh->group2_bits = 0; @@ -166,13 +169,20 @@ int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb) mh->group1_samplerate = mlp_samplerate(ratebits); mh->group2_samplerate = 0; - skip_bits(gb, 8); + skip_bits(gb, 4); - mh->channels_thd_stream1 = get_bits(gb, 5); + mh->channel_modifier_thd_stream0 = get_bits(gb, 2); + mh->channel_modifier_thd_stream1 = get_bits(gb, 2); - skip_bits(gb, 2); + channel_arrangement = get_bits(gb, 5); + mh->channels_thd_stream1 = truehd_channels(channel_arrangement); + mh->channel_layout_thd_stream1 = truehd_layout(channel_arrangement); - mh->channels_thd_stream2 = get_bits(gb, 13); + mh->channel_modifier_thd_stream2 = get_bits(gb, 2); + + channel_arrangement = get_bits(gb, 13); + mh->channels_thd_stream2 = truehd_channels(channel_arrangement); + mh->channel_layout_thd_stream2 = truehd_layout(channel_arrangement); } else return AVERROR_INVALIDDATA; @@ -316,16 +326,55 @@ static int mlp_parse(AVCodecParserContext *s, if (mh.stream_type == 0xbb) { /* MLP stream */ - avctx->channels = mlp_channels[mh.channels_mlp]; - avctx->channel_layout = mlp_layout[mh.channels_mlp]; +#if FF_API_REQUEST_CHANNELS +FF_DISABLE_DEPRECATION_WARNINGS + if (avctx->request_channels > 0 && avctx->request_channels <= 2 && + mh.num_substreams > 1) { + avctx->channels = 2; + avctx->channel_layout = AV_CH_LAYOUT_STEREO; + } else +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (avctx->request_channel_layout && + (avctx->request_channel_layout & AV_CH_LAYOUT_STEREO) == + avctx->request_channel_layout && + 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) { - avctx->channels = truehd_channels(mh.channels_thd_stream2); - avctx->channel_layout = truehd_layout(mh.channels_thd_stream2); +#if FF_API_REQUEST_CHANNELS +FF_DISABLE_DEPRECATION_WARNINGS + 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 (avctx->request_channels > 0 && + avctx->request_channels <= mh.channels_thd_stream1) { + avctx->channels = mh.channels_thd_stream1; + avctx->channel_layout = mh.channel_layout_thd_stream1; + } else +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if (avctx->request_channel_layout && + (avctx->request_channel_layout & AV_CH_LAYOUT_STEREO) == + avctx->request_channel_layout && + mh.num_substreams > 1) { + avctx->channels = 2; + avctx->channel_layout = AV_CH_LAYOUT_STEREO; + } else if (!mh.channels_thd_stream2 || + (avctx->request_channel_layout && + (avctx->request_channel_layout & mh.channel_layout_thd_stream1) == + avctx->request_channel_layout)) { + avctx->channels = mh.channels_thd_stream1; + avctx->channel_layout = mh.channel_layout_thd_stream1; } else { - avctx->channels = truehd_channels(mh.channels_thd_stream1); - avctx->channel_layout = truehd_layout(mh.channels_thd_stream1); + avctx->channels = mh.channels_thd_stream2; + avctx->channel_layout = mh.channel_layout_thd_stream2; } }