Commit fa36270c authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '99ccd2ba'

* commit '99ccd2ba':
  mlp: store the channel layout for each substream.

Conflicts:
	libavcodec/mlp_parser.c
	libavcodec/mlpdec.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 8102f27b 99ccd2ba
...@@ -126,7 +126,7 @@ uint64_t ff_truehd_layout(int chanmap) ...@@ -126,7 +126,7 @@ uint64_t ff_truehd_layout(int chanmap)
int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb) int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb)
{ {
int ratebits; int ratebits, channel_arrangement;
uint16_t checksum; uint16_t checksum;
av_assert1(get_bits_count(gb) == 0); av_assert1(get_bits_count(gb) == 0);
...@@ -157,7 +157,9 @@ int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb) ...@@ -157,7 +157,9 @@ int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb)
skip_bits(gb, 11); 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 = ff_mlp_layout[channel_arrangement];
} else if (mh->stream_type == 0xba) { } else if (mh->stream_type == 0xba) {
mh->group1_bits = 24; // TODO: Is this information actually conveyed anywhere? mh->group1_bits = 24; // TODO: Is this information actually conveyed anywhere?
mh->group2_bits = 0; mh->group2_bits = 0;
...@@ -168,11 +170,15 @@ int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb) ...@@ -168,11 +170,15 @@ int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb)
skip_bits(gb, 8); skip_bits(gb, 8);
mh->channels_thd_stream1 = get_bits(gb, 5); channel_arrangement = get_bits(gb, 5);
mh->channels_thd_stream1 = truehd_channels(channel_arrangement);
mh->channel_layout_thd_stream1 = ff_truehd_layout(channel_arrangement);
skip_bits(gb, 2); skip_bits(gb, 2);
mh->channels_thd_stream2 = get_bits(gb, 13); channel_arrangement = get_bits(gb, 13);
mh->channels_thd_stream2 = truehd_channels(channel_arrangement);
mh->channel_layout_thd_stream2 = ff_truehd_layout(channel_arrangement);
} else } else
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
...@@ -322,16 +328,16 @@ static int mlp_parse(AVCodecParserContext *s, ...@@ -322,16 +328,16 @@ static int mlp_parse(AVCodecParserContext *s,
if(!avctx->channels || !avctx->channel_layout) { if(!avctx->channels || !avctx->channel_layout) {
if (mh.stream_type == 0xbb) { if (mh.stream_type == 0xbb) {
/* MLP stream */ /* MLP stream */
avctx->channels = mlp_channels[mh.channels_mlp]; avctx->channels = mh.channels_mlp;
avctx->channel_layout = ff_mlp_layout[mh.channels_mlp]; avctx->channel_layout = mh.channel_layout_mlp;
} else { /* mh.stream_type == 0xba */ } else { /* mh.stream_type == 0xba */
/* TrueHD stream */ /* TrueHD stream */
if (mh.channels_thd_stream2) { if (mh.channels_thd_stream2) {
avctx->channels = truehd_channels(mh.channels_thd_stream2); avctx->channels = mh.channels_thd_stream2;
avctx->channel_layout = ff_truehd_layout(mh.channels_thd_stream2); avctx->channel_layout = mh.channel_layout_thd_stream2;
} else { } else {
avctx->channels = truehd_channels(mh.channels_thd_stream1); avctx->channels = mh.channels_thd_stream1;
avctx->channel_layout = ff_truehd_layout(mh.channels_thd_stream1); avctx->channel_layout = mh.channel_layout_thd_stream1;
} }
} }
} }
......
...@@ -39,9 +39,12 @@ typedef struct MLPHeaderInfo ...@@ -39,9 +39,12 @@ typedef struct MLPHeaderInfo
int group1_samplerate; ///< Sample rate of first substream int group1_samplerate; ///< Sample rate of first substream
int group2_samplerate; ///< Sample rate of second substream (MLP only) int group2_samplerate; ///< Sample rate of second substream (MLP only)
int channels_mlp; ///< Channel arrangement for MLP streams int channels_mlp; ///< Channel count for MLP streams
int channels_thd_stream1; ///< Channel arrangement for substream 1 of TrueHD streams (5.1) int channels_thd_stream1; ///< Channel count for substream 1 of TrueHD streams ("6-channel presentation")
int channels_thd_stream2; ///< Channel arrangement for substream 2 of TrueHD streams (7.1) int channels_thd_stream2; ///< Channel count for substream 2 of TrueHD streams ("8-channel presentation")
uint64_t channel_layout_mlp; ///< Channel layout for MLP streams
uint64_t channel_layout_thd_stream1; ///< Channel layout for substream 1 of TrueHD streams ("6-channel presentation")
uint64_t channel_layout_thd_stream2; ///< Channel layout for substream 2 of TrueHD streams ("8-channel presentation")
int access_unit_size; ///< Number of samples per coded frame int access_unit_size; ///< Number of samples per coded frame
int access_unit_size_pow2; ///< Next power of two above number of samples per frame int access_unit_size_pow2; ///< Next power of two above number of samples per frame
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "avcodec.h" #include "avcodec.h"
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/channel_layout.h"
#include "get_bits.h" #include "get_bits.h"
#include "internal.h" #include "internal.h"
#include "libavutil/crc.h" #include "libavutil/crc.h"
...@@ -56,6 +57,8 @@ typedef struct SubStream { ...@@ -56,6 +57,8 @@ typedef struct SubStream {
uint8_t max_matrix_channel; uint8_t max_matrix_channel;
/// For each channel output by the matrix, the output channel to map it to /// For each channel output by the matrix, the output channel to map it to
uint8_t ch_assign[MAX_CHANNELS]; uint8_t ch_assign[MAX_CHANNELS];
/// The channel layout for this substream
uint64_t ch_layout;
/// Channel coding parameters for channels in the substream /// Channel coding parameters for channels in the substream
ChannelParams channel_params[MAX_CHANNELS]; ChannelParams channel_params[MAX_CHANNELS];
...@@ -328,6 +331,7 @@ static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb) ...@@ -328,6 +331,7 @@ static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb)
for (substr = 0; substr < MAX_SUBSTREAMS; substr++) for (substr = 0; substr < MAX_SUBSTREAMS; substr++)
m->substream[substr].restart_seen = 0; m->substream[substr].restart_seen = 0;
#if 0
if (mh.stream_type == 0xbb) { if (mh.stream_type == 0xbb) {
/* MLP stream */ /* MLP stream */
m->avctx->channel_layout = ff_mlp_layout[mh.channels_mlp]; m->avctx->channel_layout = ff_mlp_layout[mh.channels_mlp];
...@@ -352,6 +356,34 @@ static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb) ...@@ -352,6 +356,34 @@ static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb)
} }
} }
#else
/* Set the layout for each substream. When there's more than one, the first
* substream is Stereo. Subsequent substreams' layouts are indicated in the
* major sync. */
if (m->avctx->codec_id == AV_CODEC_ID_MLP) {
if ((substr = (mh.num_substreams > 1)))
m->substream[0].ch_layout = AV_CH_LAYOUT_STEREO;
m->substream[substr].ch_layout = mh.channel_layout_mlp;
} else {
if ((substr = (mh.num_substreams > 1)))
m->substream[0].ch_layout = AV_CH_LAYOUT_STEREO;
if (mh.num_substreams > 2)
if (mh.channel_layout_thd_stream2)
m->substream[2].ch_layout = mh.channel_layout_thd_stream2;
else
m->substream[2].ch_layout = mh.channel_layout_thd_stream1;
m->substream[substr].ch_layout = mh.channel_layout_thd_stream1;
if (m->avctx->channels<=2 && m->substream[substr].ch_layout == AV_CH_LAYOUT_MONO && m->max_decoded_substream == 1) {
av_log(m->avctx, AV_LOG_DEBUG, "Mono stream with 2 substreams, ignoring 2nd\n");
m->max_decoded_substream = 0;
if (m->avctx->channels==2)
m->avctx->channel_layout = AV_CH_LAYOUT_STEREO;
}
}
#endif
m->needs_reordering = mh.channels_mlp >= 18 && mh.channels_mlp <= 20; m->needs_reordering = mh.channels_mlp >= 18 && mh.channels_mlp <= 20;
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment