[FFmpeg-devel] [PATCH] aacenc: WIP support for PCEs

pkv.stream pkv.stream at gmail.com
Sun Sep 24 17:27:35 EEST 2017


Hi atomnuker and others

I am interested in working on this patch by atomnuker who did a great job.

This could allow encoding to more channels with aac (e.g. ambisonics 
order three = 16 audio channels).

Here's a report about additions I made to the PCE table for all the 
basic ffmpeg channel layouts (except mixed stereo).

I have followed atomnuker assumptions for the guess work, notably 
regarding indexes (which seems right, I saw on spec an example with 
indexes running like 0 1 0 so ithe indexing seems to reset , quite 
probably for each group of either, front, side, back or LFE channels in 
the PCE).

I have done some testing:

encoding goes without fuss up to 16 channels. No warning, no error.

But, ffmpeg aac decoder is throwing errors in aacdec_template.c :

lines 3119-3124:

         if (elem_type < TYPE_DSE) {
             if (!(che=get_che(ac, elem_type, elem_id))) {
                 av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d 
is not allocated\n",
                        elem_type, elem_id);
                 err = AVERROR_INVALIDDATA;
                 goto fail;

error message is:

channel element 0.0 is not allocated

So the get_che function is failing.

Can't tell yet if this is an issue with the encoder or with the decoder.

*atomnuker: *do you remember if could you decode with ffmpeg the files 
you produced with the layouts in your original patch ? I haven't tried 
with other decoders. Libfdk_aac decoder provides for channel =0 
directing to a pce. Didn't find that in the ffmpeg aac decoder (haven't 
searched too much though)

Best

pkv




-------------- next part --------------
From dba1cef5d1aee3d26c35a6fa429a11a6039d4844 Mon Sep 17 00:00:00 2001
From: pkviet <pkv.stream at gmail.com>
Date: Sun, 24 Sep 2017 16:11:17 +0200
Subject: [PATCH] avcodec/aacenc: more multichannels layouts added to pce

Add most ffmpeg channel layouts to the pce table by atomnuker. WIP. Encodes without errors up to 16 channels in aac but the files throw errors with ffmpeg aac decoder. Don't know yet if issue is with encoder or with decoder.
---
 libavcodec/aacenc.c |   2 +-
 libavcodec/aacenc.h | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 185 insertions(+), 1 deletion(-)

diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
index 2996996..faa0684 100644
--- a/libavcodec/aacenc.c
+++ b/libavcodec/aacenc.c
@@ -565,7 +565,7 @@ static int aac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
             return 0;
     }
 
-    copy_input_samples(s, frame);
+	copy_input_samples(s, frame);
     if (s->psypp)
         ff_psy_preprocess(s->psypp, s->planar_samples, s->channels);
 
diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h
index 346d989..ce2202d 100644
--- a/libavcodec/aacenc.h
+++ b/libavcodec/aacenc.h
@@ -116,6 +116,22 @@ static const AACPCEInfo aac_pce_configs[] = {
         .config_map = { 1, TYPE_CPE, },
         .reorder_map = { 0, 1 },
     },
+	{
+		.layout = AV_CH_LAYOUT_2POINT1,
+		.num_ele = { 1, 0, 0, 1 },
+		.pairing = { { 1 }, },
+		.index = { { 0 }, { 0 }, { 0 }, { 0 } },
+		.config_map = { 2, TYPE_CPE, TYPE_LFE},
+		.reorder_map = { 0, 1, 2 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_2_1,
+		.num_ele = { 1, 0, 1, 0 },
+		.pairing = { { 1 }, { 0 }, { 0 } },
+		.index = { { 0 }, { 0 }, { 0 }, },
+		.config_map = { 2, TYPE_CPE, TYPE_SCE },
+		.reorder_map = { 0, 1, 2 },
+	},
     {
         .layout = AV_CH_LAYOUT_SURROUND,
         .num_ele = { 2, 0, 0, 0 },
@@ -124,6 +140,14 @@ static const AACPCEInfo aac_pce_configs[] = {
         .config_map = { 2, TYPE_SCE, TYPE_CPE },
         .reorder_map = { 2, 0, 1 },
     },
+	{
+		.layout = AV_CH_LAYOUT_3POINT1,
+		.num_ele = { 2, 0, 0, 1 },
+		.pairing = { { 1, 0 }, },
+		.index = { { 0, 1 }, { 0 }, { 0 }, { 0 }, },
+		.config_map = { 3, TYPE_SCE, TYPE_CPE, TYPE_LFE },
+		.reorder_map = { 2, 0, 1, 3 },
+	},
     {
         .layout = AV_CH_LAYOUT_4POINT0,
         .num_ele = { 2, 0, 1, 0 },
@@ -132,6 +156,166 @@ static const AACPCEInfo aac_pce_configs[] = {
         .config_map = { 3, TYPE_SCE, TYPE_CPE, TYPE_SCE },
         .reorder_map = { 2, 0, 1, 3 },
     },
+	{
+		.layout = AV_CH_LAYOUT_4POINT1,
+		.num_ele = { 2, 0, 1, 1 },
+		.pairing = { { 1, 0 }, { 0 }, { 0 }, },
+		.index = { { 0, 1 }, { 0 }, { 0 }, { 0 } },
+		.config_map = { 4, TYPE_SCE, TYPE_CPE, TYPE_SCE, TYPE_LFE },
+		.reorder_map = { 2, 0, 1, 4, 3 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_2_2,
+		.num_ele = { 1, 1, 0, 0 },
+		.pairing = { { 1 }, { 1 }, },
+		.index = { { 0 }, { 0 }, },
+		.config_map = { 2, TYPE_CPE, TYPE_CPE },
+		.reorder_map = { 0, 1, 2, 3 },
+	},
+    {
+	    .layout = AV_CH_LAYOUT_QUAD,
+	    .num_ele = { 1, 0, 1, 0 },
+	    .pairing = { { 1 }, { 0 }, { 1 }, },
+	    .index = { { 0 }, { 0 }, { 0 } },
+	    .config_map = { 2, TYPE_CPE, TYPE_CPE },
+	    .reorder_map = { 0, 1, 2, 3 },
+    },
+	{
+		.layout = AV_CH_LAYOUT_5POINT0,
+		.num_ele = { 2, 1, 0, 0 },
+		.pairing = { { 1, 0 }, { 1 }, },
+		.index = { { 0, 1 }, { 0 } },
+		.config_map = { 3, TYPE_SCE, TYPE_CPE, TYPE_CPE },
+		.reorder_map = { 2, 0, 1, 3, 4 },
+	},
+    {
+		.layout = AV_CH_LAYOUT_5POINT1,
+		.num_ele = { 2, 1, 0, 1 },
+		.pairing = { { 1, 0 }, { 1 }, },
+		.index = { { 0, 1 }, { 0 }, { 0 }, { 0 } },
+		.config_map = { 4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_LFE },
+		.reorder_map = { 2, 0, 1, 4, 5, 3 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_5POINT0_BACK,
+		.num_ele = { 2, 0, 1, 0 },
+		.pairing = { { 1, 0 }, { 0 }, { 1 } },
+		.index = { { 0, 1 }, { 0 }, { 0 } },
+		.config_map = { 3, TYPE_SCE, TYPE_CPE, TYPE_CPE },
+		.reorder_map = { 2, 0, 1, 3, 4 },
+	},
+    {
+		.layout = AV_CH_LAYOUT_5POINT1_BACK,
+		.num_ele = { 2, 0, 1, 1 },
+		.pairing = { { 1, 0 }, { 0 }, { 1 }, },
+		.index = { { 0, 1 }, { 0 }, { 0 }, { 0 } },
+		.config_map = { 4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_LFE },
+		.reorder_map = { 2, 0, 1, 4, 5, 3 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_6POINT0,
+		.num_ele = { 2, 1, 1, 0 },
+		.pairing = { { 1, 0 }, { 1 }, { 0 }, },
+		.index = { { 0, 1 }, { 0 }, { 0 } },
+		.config_map = { 4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_SCE },
+		.reorder_map = { 2, 0, 1, 3, 4, 5 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_6POINT0_FRONT,
+		.num_ele = { 2, 1, 0, 0 },
+		.pairing = { { 1, 1 }, { 1 } },
+		.index = { { 0, 1 }, { 0 }, },
+		.config_map = { 3, TYPE_CPE, TYPE_CPE, TYPE_CPE, },
+		.reorder_map = { 0, 1, 4, 5, 2, 3 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_HEXAGONAL,
+		.num_ele = { 2, 0, 2, 0 },
+		.pairing = { { 1, 0 }, { 0 }, { 1, 0 }, },
+		.index = { { 0, 1 }, { 0 }, { 0, 1 } },
+		.config_map = { 4, TYPE_SCE, TYPE_CPE, TYPE_SCE, TYPE_CPE },
+		.reorder_map = { 2, 0, 1, 5, 3, 4 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_6POINT1,
+		.num_ele = { 2, 1, 1, 1 },
+		.pairing = { { 1, 0 }, { 1 }, { 0 }, },
+		.index = { { 0, 1 }, { 0 }, { 0 }, { 0 } },
+		.config_map = { 5, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_SCE, TYPE_LFE },
+		.reorder_map = { 2, 0, 1, 4, 5, 6, 3 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_6POINT1_BACK,
+		.num_ele = { 2, 0, 2, 1 },
+		.pairing = { { 1, 0 }, { 0 }, { 1, 0 } },
+		.index = { { 0, 1 }, { 0 }, { 0, 1 }, { 0 } },
+		.config_map = { 5, TYPE_SCE, TYPE_CPE, TYPE_SCE, TYPE_CPE, TYPE_LFE },
+		.reorder_map = { 2, 0, 1, 6, 4, 5, 3 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_6POINT1_FRONT,
+		.num_ele = { 2, 1, 0, 1 },
+		.pairing = { { 1, 1 }, { 1 }, },
+		.index = { { 0, 1 }, { 0 }, { 0 }, { 0 } },
+		.config_map = { 4, TYPE_CPE, TYPE_CPE, TYPE_CPE, TYPE_LFE },
+		.reorder_map = {  0, 1, 3, 4, 5, 6, 2 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_7POINT0,
+		.num_ele = { 2, 1, 1, 0 },
+		.pairing = { { 1, 0 }, { 1 }, { 1 }, },
+		.index = { { 0, 1 }, { 0 }, { 0 }, },
+		.config_map = { 4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_CPE },
+		.reorder_map = { 2, 0, 1, 5, 6, 3, 4 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_7POINT0_FRONT,
+		.num_ele = { 3, 1, 0, 0 },
+		.pairing = { { 1, 0, 1 }, { 1 }, },
+		.index = { { 0, 1, 2 }, { 0 }, },
+		.config_map = { 4, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_CPE },
+		.reorder_map = { 2, 0, 1, 3, 4, 5, 6 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_7POINT1,
+		.num_ele = { 2, 1, 1, 1 },
+		.pairing = { { 1, 0 }, { 1 }, { 1 }, },
+		.index = { { 0, 1 }, { 0 }, { 0 }, { 0 } },
+		.config_map = { 5, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_CPE, TYPE_LFE },
+		.reorder_map = { 2, 0, 1, 6, 7, 4, 5, 3 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_7POINT1_WIDE,
+		.num_ele = { 3, 1, 0, 1 },
+		.pairing = { { 1, 0, 1 }, { 1 }, },
+		.index = { { 0, 1, 2 }, { 0 }, { 0 }, { 0 } },
+		.config_map = { 5, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_CPE, TYPE_LFE },
+		.reorder_map = { 2, 6, 7, 0, 1, 4, 5, 3 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_7POINT1_WIDE_BACK,
+		.num_ele = { 3, 0, 1, 1 },
+		.pairing = { { 1, 0, 1 }, { 0 }, { 1 }, },
+		.index = { { 0, 1, 2 }, { 0 }, { 0 }, { 0 } },
+		.config_map = { 5, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_CPE, TYPE_LFE },
+		.reorder_map = { 2, 6, 7, 0, 1, 4, 5, 3 },
+	},
+    {
+		.layout = AV_CH_LAYOUT_OCTAGONAL,
+		.num_ele = { 2, 1, 2, 0 },
+		.pairing = { { 1, 0 }, { 1 }, { 1, 0 }, },
+		.index = { { 0, 1 }, { 0 }, { 0, 1 } },
+		.config_map = { 5, TYPE_CPE, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_SCE },
+		.reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7 },
+	},
+	{
+		.layout = AV_CH_LAYOUT_HEXADECAGONAL,
+		.num_ele = { 4, 2, 4, 0 },
+		.pairing = { { 1, 0, 1, 0 }, { 1, 1 }, { 1, 0, 1, 0 }, },
+		.index = { { 0, 1, 2, 3 }, { 0, 1 }, { 0, 1, 2, 3 } },
+		.config_map = { 10, TYPE_CPE, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_SCE, TYPE_CPE, TYPE_SCE, TYPE_CPE, TYPE_CPE, TYPE_SCE },
+		.reorder_map = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
+	},
 };
 
 /**
-- 
2.10.1.windows.1



More information about the ffmpeg-devel mailing list