diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-01-23 18:59:45 +0400 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-01-23 19:05:56 +0400 |
commit | cd6a8618b1f57a37e6bc639651fe5a657663409b (patch) | |
tree | 6638da040ab17e5deafb6dd3109a7fcb9447d742 /libavcodec/mlpdec.c | |
parent | fa36270c4c68589882cfeae68a037f1d191231c2 (diff) | |
parent | 3ffcccb4fbaae4d5ad775506f1f2761f2029affa (diff) |
Merge commit '3ffcccb4fbaae4d5ad775506f1f2761f2029affa'
* commit '3ffcccb4fbaae4d5ad775506f1f2761f2029affa':
mlpdec: TrueHD: use Libav channel order.
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec/mlpdec.c')
-rw-r--r-- | libavcodec/mlpdec.c | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c index 8edca1761c..8e6f1fc5f3 100644 --- a/libavcodec/mlpdec.c +++ b/libavcodec/mlpdec.c @@ -152,6 +152,36 @@ typedef struct MLPDecodeContext { MLPDSPContext dsp; } MLPDecodeContext; +static const uint64_t thd_channel_order[] = { + AV_CH_FRONT_LEFT, AV_CH_FRONT_RIGHT, // LR + AV_CH_FRONT_CENTER, // C + 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_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_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 uint64_t thd_channel_layout_extract_channel(uint64_t channel_layout, + int index) +{ + int i; + + if (av_get_channel_layout_nb_channels(channel_layout) <= index) + return 0; + + for (i = 0; i < FF_ARRAY_ELEMS(thd_channel_order); i++) + if (channel_layout & thd_channel_order[i] && !index--) + return thd_channel_order[i]; + return 0; +} + static VLC huff_vlc[3]; /** Initialize static data, constant between all invocations of the codec. */ @@ -492,6 +522,12 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, for (ch = 0; ch <= s->max_matrix_channel; ch++) { int ch_assign = get_bits(gbp, 6); + if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD) { + uint64_t channel = thd_channel_layout_extract_channel(s->ch_layout, + ch_assign); + ch_assign = av_get_channel_layout_channel_index(s->ch_layout, + channel); + } if (ch_assign > s->max_matrix_channel) { av_log_ask_for_sample(m->avctx, "Assignment of matrix channel %d to invalid output channel %d.\n", @@ -513,20 +549,6 @@ static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, FFSWAP(int, s->ch_assign[3], s->ch_assign[5]); } } - if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD && - (m->avctx->channel_layout == AV_CH_LAYOUT_7POINT1 || - m->avctx->channel_layout == AV_CH_LAYOUT_7POINT1_WIDE)) { - FFSWAP(int, s->ch_assign[4], s->ch_assign[6]); - FFSWAP(int, s->ch_assign[5], s->ch_assign[7]); - } else if (m->avctx->codec_id == AV_CODEC_ID_TRUEHD && - (m->avctx->channel_layout == AV_CH_LAYOUT_6POINT1 || - m->avctx->channel_layout == (AV_CH_LAYOUT_6POINT1 | AV_CH_TOP_CENTER) || - m->avctx->channel_layout == (AV_CH_LAYOUT_6POINT1 | AV_CH_TOP_FRONT_CENTER))) { - int i = s->ch_assign[6]; - s->ch_assign[6] = s->ch_assign[5]; - s->ch_assign[5] = s->ch_assign[4]; - s->ch_assign[4] = i; - } checksum = ff_mlp_restart_checksum(buf, get_bits_count(gbp) - start_count); |