From: Carl Eugen Hoyos <[email protected]>
This is a squash of the following commits from FFmpeg:
939a12e25d956850613f9c6c416e12de305f444b Fix channel order for some MLP
samples.
0aac0403c54eb7f47d5d707e1368e52763043a69 Map mlp surround channels to
FFmpeg rear channels.
6daf513cf24a99ddddb7e748fc150f37bcd323f3 Fix channel order for 7.1 TrueHD
samples.
b9d8af03270223202c9a991655d3f75b5a8b56b5 mlpdec: fix channel order for wide
7.1 truehd layouts
1af0ace3a4b8aa8c6240a99de3c40f495ab279e9 Fix channel order for some less
common TrueHD layouts.
One fix by Hendrik Leppkes.
Signed-off-by: Derek Buitenhuis <[email protected]>
---
libavcodec/mlp_parser.c | 18 +++++++++---------
libavcodec/mlpdec.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/libavcodec/mlp_parser.c b/libavcodec/mlp_parser.c
index 1879e00..351908f 100644
--- a/libavcodec/mlp_parser.c
+++ b/libavcodec/mlp_parser.c
@@ -47,24 +47,24 @@ static const uint64_t mlp_layout[32] = {
AV_CH_LAYOUT_MONO,
AV_CH_LAYOUT_STEREO,
AV_CH_LAYOUT_2_1,
- AV_CH_LAYOUT_2_2,
+ AV_CH_LAYOUT_QUAD,
AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY,
AV_CH_LAYOUT_2_1|AV_CH_LOW_FREQUENCY,
- AV_CH_LAYOUT_2_2|AV_CH_LOW_FREQUENCY,
+ AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY,
AV_CH_LAYOUT_SURROUND,
AV_CH_LAYOUT_4POINT0,
- AV_CH_LAYOUT_5POINT0,
+ AV_CH_LAYOUT_5POINT0_BACK,
AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY,
AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY,
- AV_CH_LAYOUT_5POINT1,
+ AV_CH_LAYOUT_5POINT1_BACK,
AV_CH_LAYOUT_4POINT0,
- AV_CH_LAYOUT_5POINT0,
+ AV_CH_LAYOUT_5POINT0_BACK,
AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY,
AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY,
- AV_CH_LAYOUT_5POINT1,
- AV_CH_LAYOUT_2_2|AV_CH_LOW_FREQUENCY,
- AV_CH_LAYOUT_5POINT0,
- AV_CH_LAYOUT_5POINT1,
+ AV_CH_LAYOUT_5POINT1_BACK,
+ AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY,
+ AV_CH_LAYOUT_5POINT0_BACK,
+ AV_CH_LAYOUT_5POINT1_BACK,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c
index 30310db..89ce0a3 100644
--- a/libavcodec/mlpdec.c
+++ b/libavcodec/mlpdec.c
@@ -29,6 +29,7 @@
#include "avcodec.h"
#include "dsputil.h"
#include "libavutil/intreadwrite.h"
+#include "libavutil/audioconvert.h"
#include "get_bits.h"
#include "libavutil/crc.h"
#include "parser.h"
@@ -128,6 +129,9 @@ typedef struct MLPDecodeContext {
/// Index of the last substream to decode - further substreams are skipped.
uint8_t max_decoded_substream;
+ /// Stream needs channel reordering to comply with Libav's channel order
+ uint8_t needs_reordering;
+
/// number of PCM samples contained in each frame
int access_unit_size;
/// next power of two above the number of samples in each frame
@@ -324,6 +328,8 @@ static int read_major_sync(MLPDecodeContext *m,
GetBitContext *gb)
for (substr = 0; substr < MAX_SUBSTREAMS; substr++)
m->substream[substr].restart_seen = 0;
+ m->needs_reordering = mh.channels_mlp >= 18 && mh.channels_mlp <= 20;
+
return 0;
}
@@ -434,6 +440,33 @@ static int read_restart_header(MLPDecodeContext *m,
GetBitContext *gbp,
s->ch_assign[ch_assign] = ch;
}
+ if (m->avctx->codec_id == CODEC_ID_MLP && m->needs_reordering) {
+ if (m->avctx->channel_layout ==
(AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY) ||
+ m->avctx->channel_layout == AV_CH_LAYOUT_5POINT0_BACK) {
+ int i = s->ch_assign[4];
+ s->ch_assign[4] = s->ch_assign[3];
+ s->ch_assign[3] = s->ch_assign[2];
+ s->ch_assign[2] = i;
+ } else if (m->avctx->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) {
+ FFSWAP(int, s->ch_assign[2], s->ch_assign[4]);
+ FFSWAP(int, s->ch_assign[3], s->ch_assign[5]);
+ }
+ }
+ if (m->avctx->codec_id == CODEC_ID_TRUEHD) {
+ if (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->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);
if (checksum != get_bits(gbp, 8))
--
1.7.10
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel