diff mbox

[FFmpeg-devel] aacenc: WIP support for PCEs

Message ID ee3d888e-cbfe-954c-31b4-04e3ebddf938@gmail.com
State Superseded
Headers show

Commit Message

pkv.stream Sept. 24, 2017, 2:27 p.m. UTC
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
From dba1cef5d1aee3d26c35a6fa429a11a6039d4844 Mon Sep 17 00:00:00 2001
From: pkviet <pkv.stream@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(-)

Comments

Rostislav Pehlivanov Sept. 24, 2017, 3:06 p.m. UTC | #1
On 24 September 2017 at 15:27, pkv.stream <pkv.stream@gmail.com> wrote:

> 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.
>
>
Of course it isn't going to work, I explicitly told you 1.) its a wip patch
so no real error reporting and 2.) you need to add a new entry for whatever
messed up channel layout ambisonics use and make sure the signalling
indices are correct. And the latter isn't easy since nothing tells you
what's correct - the spec, a decoder or anything like that.
pkv.stream Sept. 24, 2017, 3:54 p.m. UTC | #2
Le 24/09/2017 à 5:06 PM, Rostislav Pehlivanov a écrit :
> On 24 September 2017 at 15:27, pkv.stream <pkv.stream@gmail.com> wrote:
>
>> 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.
>>
>>
> Of course it isn't going to work, I explicitly told you 1.) its a wip patch
> so no real error reporting and 2.) you need to add a new entry for whatever
> messed up channel layout ambisonics use and make sure the signalling
> indices are correct. And the latter isn't easy since nothing tells you
> what's correct - the spec, a decoder or anything like that.
I understand.
I did get though a decode of pce 4.0  or quad with vlc (downmixed to 
stereo by my sound card). In contrast ffmpeg aac decoder throws the 
error I mentioned (in ffmpeg and ffplay).
So already your pce code is not doing a bad job.
My point is maybe faad2 is perhaps implementing pce decode better than 
ffmpeg own aac decoder.
Or your pce implementation might miss something that faad2 works around. 
I'll inquire and post if I find something useful for getting functional 
pce.

> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
diff mbox

Patch

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 },
+	},
 };
 
 /**