mbox series

[FFmpeg-devel,0/5,v2] 22.2 channel layout support for AAC decoding

Message ID 20200729113952.14574-1-jeebjp@gmail.com
Headers show
Series 22.2 channel layout support for AAC decoding | expand

Message

Jan Ekström July 29, 2020, 11:39 a.m. UTC
Now that we actually have sample(s) for channel_config 13, it was possible
to see at which various points the AAC decoder fails attempting to parse
the bit stream.

As the feature `-request_channel_layout 9223372036854775808` (AV_CH_LAYOUT_NATIVE)
seems to work, the channel order has been validated both visually with
Audacity, as well as by logging the post-reorder element ordering:

(what specific CPE/SCE/LFE elements mean is documented in the
`avcodec/aacdectab: add mapping for 22.2` commit):

Setting layout map list after reorder...
tag 0 = { pos: (null) (3), syn_elem: CPE, elem_id: 1 }
tag 1 = { pos: FC (4), syn_elem: SCE, elem_id: 0 }
tag 2 = { pos: LFE (8), syn_elem: LFE, elem_id: 0 }
tag 3 = { pos: (null) (30), syn_elem: CPE, elem_id: 3 }
tag 4 = { pos: (null) (c0), syn_elem: CPE, elem_id: 0 }
tag 5 = { pos: BC (100), syn_elem: SCE, elem_id: 1 }
tag 6 = { pos: LFE2 (800000000), syn_elem: LFE, elem_id: 1 }
tag 7 = { pos: (null) (600), syn_elem: CPE, elem_id: 2 }
tag 8 = { pos: (null) (5000), syn_elem: CPE, elem_id: 4 }
tag 9 = { pos: TFC (2000), syn_elem: SCE, elem_id: 2 }
tag 10 = { pos: TC (800), syn_elem: SCE, elem_id: 3 }
tag 11 = { pos: (null) (28000), syn_elem: CPE, elem_id: 6 }
tag 12 = { pos: (null) (3000000000), syn_elem: CPE, elem_id: 5 }
tag 13 = { pos: TBC (10000), syn_elem: SCE, elem_id: 4 }
tag 14 = { pos: BFC (8000000000), syn_elem: SCE, elem_id: 5 }
tag 15 = { pos: (null) (14000000000), syn_elem: CPE, elem_id: 7 }

swresample seems to give out the correct channels for 5.1 and stereo
downmix (checked with ffmpeg.c by utilizing `-channel_layout` 5.1 and stereo),
although the default downmix logic seems to lower the volume somewhat.

Fixes #8714

Jan Ekström (5):
  avutil/channel_layout: add 22.2 layout
  avcodec/mpeg4audio: add newer channel_coding mappings
  avcodec/aacdectab: add mapping for 22.2
  avcodec/aacdec_template: mark second LFE element as LFE2
  avcodec/aacdec_template: add support for 22.2 / channel_config 13

 doc/APIchanges               |  5 ++
 libavcodec/aacdec_template.c | 98 ++++++++++++++++++++++++++++++++----
 libavcodec/aacdectab.h       | 23 ++++++++-
 libavcodec/mpeg4audio.c      | 17 ++++++-
 libavcodec/mpeg4audio.h      |  2 +-
 libavutil/channel_layout.c   |  6 +++
 libavutil/channel_layout.h   |  6 +++
 libavutil/version.h          |  2 +-
 8 files changed, 142 insertions(+), 17 deletions(-)

Comments

Jan Ekström July 30, 2020, 9:25 p.m. UTC | #1
On Wed, Jul 29, 2020 at 2:39 PM Jan Ekström <jeebjp@gmail.com> wrote:
>
> swresample seems to give out the correct channels for 5.1 and stereo
> downmix (checked with ffmpeg.c by utilizing `-channel_layout` 5.1 and stereo),
> although the default downmix logic seems to lower the volume somewhat.
>

I attempted to take this into mention, and apparently seem to have
succeeded. Not pretty but since we don't yet have a full matrix for it
and as the rest of the channel layout doesn't follow the bit mask's
rising order I guess for now this is the least bad way of handling it.
Added a warning since anyone interested in actually implementing this
in a more complete manner might get interested.

Note: I have no idea if this is the correct location or way to put
this override, but since the stereo overrides seemed to be here as
well, I followed similar logic.

format-patch follows:

From 16e9eda23862daaaf2a43824b75ddf7e8054f23e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Ekstr=C3=B6m?= <jeebjp@gmail.com>
Date: Thu, 30 Jul 2020 23:52:57 +0300
Subject: [PATCH] swresample/rematrix: treat 22.2 as 5.1 (back) when mixing

Only this sub-set of channels actually follows the bit mask order
in the official 22.2 channel mapping.
---
 libswresample/rematrix.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index 6b5feaa07b..43845a429f 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -141,6 +141,16 @@ av_cold int swr_build_matrix(uint64_t
in_ch_layout_param, uint64_t out_ch_layout
     )
         in_ch_layout = AV_CH_LAYOUT_STEREO;

+    if (in_ch_layout_param == AV_CH_LAYOUT_22POINT2 &&
+        out_ch_layout_param != AV_CH_LAYOUT_22POINT2) {
+        in_ch_layout = AV_CH_LAYOUT_5POINT1_BACK;
+        av_get_channel_layout_string(buf, sizeof(buf), -1, in_ch_layout);
+        av_log(log_context, AV_LOG_WARNING,
+               "Full-on remixing from 22.2 has not yet been implemented! "
+               "Processing the input as '%s'\n",
+               buf);
+    }
+
     if(!sane_layout(in_ch_layout)){
         av_get_channel_layout_string(buf, sizeof(buf), -1, in_ch_layout_param);
         av_log(log_context, AV_LOG_ERROR, "Input channel layout '%s'
is not supported\n", buf);