X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fmlp_parser.c;h=075227f302dbbdb1ec9e0294006617bc2109f7fc;hb=f86f39cb9b1fcd063d5e4812132a75c06cc7acd2;hp=e0fedeb7e9503deed154724fd99f1d864d4d56da;hpb=cc276c85d15272df6e44fb3252657a43cbd49555;p=ffmpeg diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c index e0fedeb7e95..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" @@ -79,14 +80,14 @@ static const uint64_t thd_layout[13] = { AV_CH_LOW_FREQUENCY, // LFE AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, // LRs AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT, // LRvh - AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, // LRc + AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER, // LRc AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, // LRrs AV_CH_BACK_CENTER, // Cs - AV_CH_TOP_BACK_CENTER, // Ts - AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, // LRsd - AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER, // LRw - AV_CH_TOP_BACK_CENTER, // Cvh - AV_CH_LOW_FREQUENCY // LFE2 + AV_CH_TOP_CENTER, // Ts + 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_2, // LFE2 }; static int mlp_samplerate(int in) @@ -109,7 +110,8 @@ static int truehd_channels(int chanmap) static uint64_t truehd_layout(int chanmap) { - int layout = 0, i; + int i; + uint64_t layout = 0; for (i = 0; i < 13; i++) layout |= thd_layout[i] * ((chanmap >> i) & 1); @@ -125,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); @@ -156,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; @@ -165,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; @@ -311,20 +322,59 @@ static int mlp_parse(AVCodecParserContext *s, else avctx->sample_fmt = AV_SAMPLE_FMT_S16; avctx->sample_rate = mh.group1_samplerate; - avctx->frame_size = mh.access_unit_size; + s->duration = mh.access_unit_size; 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; } } @@ -345,7 +395,7 @@ lost_sync: } AVCodecParser ff_mlp_parser = { - .codec_ids = { CODEC_ID_MLP, CODEC_ID_TRUEHD }, + .codec_ids = { AV_CODEC_ID_MLP, AV_CODEC_ID_TRUEHD }, .priv_data_size = sizeof(MLPParseContext), .parser_init = mlp_init, .parser_parse = mlp_parse,