[FFmpeg-devel] libopus: Add channel mapping 2 support in libopusdec

Submitted by Felicia Lim on March 28, 2017, 12:35 a.m.

Details

Message ID CAJ0LFHUMA9P8xt+vao0qDwXN5eb2prMoSNUWNBA+jiuezjCAZQ@mail.gmail.com
State New
Headers show

Commit Message

Felicia Lim March 28, 2017, 12:35 a.m.
Hi all,

Here is another patch to decode Opus ambisonics files using channel mapping
2 [1], this time in libopusdec.c.

Please let me know if there are any concerns.

Thanks,
Felicia

[1] *https://trac.tools.ietf.org/html/draft-ietf-codec-ambisonics-02#section-3.1
<https://trac.tools.ietf.org/html/draft-ietf-codec-ambisonics-02#section-3.1>*

Comments

Felicia Lim April 7, 2017, 6:14 p.m.
Hi,

Just wanted to follow up and check if there any changes I should add to
this patch?

Thanks for taking a look.

Felicia

On Mon, Mar 27, 2017 at 5:35 PM Felicia Lim <flim@google.com> wrote:

> Hi all,
>
> Here is another patch to decode Opus ambisonics files using channel
> mapping 2 [1], this time in libopusdec.c.
>
> Please let me know if there are any concerns.
>
> Thanks,
> Felicia
>
> [1] *https://trac.tools.ietf.org/html/draft-ietf-codec-ambisonics-02#section-3.1
> <https://trac.tools.ietf.org/html/draft-ietf-codec-ambisonics-02#section-3.1>*
>
Dale Curtis Oct. 23, 2017, 10:04 p.m.
Any update on this patch? We've been carrying it in Chrome for a while.

- dale

On Fri, Apr 7, 2017 at 11:14 AM, Felicia Lim <flim-at-google.com@ffmpeg.org>
wrote:

> Hi,
>
> Just wanted to follow up and check if there any changes I should add to
> this patch?
>
> Thanks for taking a look.
>
> Felicia
>
> On Mon, Mar 27, 2017 at 5:35 PM Felicia Lim <flim@google.com> wrote:
>
> > Hi all,
> >
> > Here is another patch to decode Opus ambisonics files using channel
> > mapping 2 [1], this time in libopusdec.c.
> >
> > Please let me know if there are any concerns.
> >
> > Thanks,
> > Felicia
> >
> > [1] *https://trac.tools.ietf.org/html/draft-ietf-codec-
> ambisonics-02#section-3.1
> > <https://trac.tools.ietf.org/html/draft-ietf-codec-
> ambisonics-02#section-3.1>*
> >
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Michael Niedermayer Oct. 24, 2017, 9:20 p.m.
On Tue, Mar 28, 2017 at 12:35:29AM +0000, Felicia Lim wrote:
> Hi all,
> 
> Here is another patch to decode Opus ambisonics files using channel mapping
> 2 [1], this time in libopusdec.c.
> 
> Please let me know if there are any concerns.
> 
> Thanks,
> Felicia
> 
> [1] *https://trac.tools.ietf.org/html/draft-ietf-codec-ambisonics-02#section-3.1
> <https://trac.tools.ietf.org/html/draft-ietf-codec-ambisonics-02#section-3.1>*

>  libopusdec.c |   39 +++++++++++++++++++++++++++++----------
>  1 file changed, 29 insertions(+), 10 deletions(-)
> b84e04c55997e5edfceff91fa7e57f85dd0f1141  0001-libopus-Add-channel-mapping-2-support-in-libopusdec.patch
> From 6607c6f8cff64771cdf34faa6e318271f5a48ac2 Mon Sep 17 00:00:00 2001
> From: Felicia Lim <flim@google.com>
> Date: Mon, 27 Mar 2017 16:21:20 -0700
> Subject: [PATCH] libopus: Add channel mapping 2 support in libopusdec
> 
> Enables demuxing of Ambisonics content coded with channel mapping 2
> ---
>  libavcodec/libopusdec.c | 39 +++++++++++++++++++++++++++++----------
>  1 file changed, 29 insertions(+), 10 deletions(-)

will apply

thanks

[...]

Patch hide | download patch | download mbox

From 6607c6f8cff64771cdf34faa6e318271f5a48ac2 Mon Sep 17 00:00:00 2001
From: Felicia Lim <flim@google.com>
Date: Mon, 27 Mar 2017 16:21:20 -0700
Subject: [PATCH] libopus: Add channel mapping 2 support in libopusdec

Enables demuxing of Ambisonics content coded with channel mapping 2
---
 libavcodec/libopusdec.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)

diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c
index e6ca61a78f..9dab0fdf65 100644
--- a/libavcodec/libopusdec.c
+++ b/libavcodec/libopusdec.c
@@ -57,8 +57,6 @@  static av_cold int libopus_decode_init(AVCodecContext *avc)
     avc->sample_rate    = 48000;
     avc->sample_fmt     = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
                           AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;
-    avc->channel_layout = avc->channels > 8 ? 0 :
-                          ff_vorbis_channel_layouts[avc->channels - 1];
 
     if (avc->extradata_size >= OPUS_HEAD_SIZE) {
         opus->pre_skip = AV_RL16(avc->extradata + 10);
@@ -82,14 +80,35 @@  static av_cold int libopus_decode_init(AVCodecContext *avc)
         mapping    = mapping_arr;
     }
 
-    if (avc->channels > 2 && avc->channels <= 8) {
-        const uint8_t *vorbis_offset = ff_vorbis_channel_layout_offsets[avc->channels - 1];
-        int ch;
-
-        /* Remap channels from Vorbis order to ffmpeg order */
-        for (ch = 0; ch < avc->channels; ch++)
-            mapping_arr[ch] = mapping[vorbis_offset[ch]];
-        mapping = mapping_arr;
+    if (channel_map == 1) {
+        avc->channel_layout = avc->channels > 8 ? 0 :
+                              ff_vorbis_channel_layouts[avc->channels - 1];
+        if (avc->channels > 2 && avc->channels <= 8) {
+            const uint8_t *vorbis_offset = ff_vorbis_channel_layout_offsets[avc->channels - 1];
+            int ch;
+
+            /* Remap channels from Vorbis order to ffmpeg order */
+            for (ch = 0; ch < avc->channels; ch++)
+                mapping_arr[ch] = mapping[vorbis_offset[ch]];
+            mapping = mapping_arr;
+        }
+    } else if (channel_map == 2) {
+        int ambisonic_order = ff_sqrt(avc->channels) - 1;
+        if (avc->channels != (ambisonic_order + 1) * (ambisonic_order + 1) &&
+            avc->channels != (ambisonic_order + 1) * (ambisonic_order + 1) + 2) {
+            av_log(avc, AV_LOG_ERROR,
+                   "Channel mapping 2 is only specified for channel counts"
+                   " which can be written as (n + 1)^2 or (n + 2)^2 + 2"
+                   " for nonnegative integer n\n");
+            return AVERROR_INVALIDDATA;
+        }
+        if (avc->channels > 227) {
+            av_log(avc, AV_LOG_ERROR, "Too many channels\n");
+            return AVERROR_INVALIDDATA;
+        }
+        avc->channel_layout = 0;
+    } else {
+        avc->channel_layout = 0;
     }
 
     opus->dec = opus_multistream_decoder_create(avc->sample_rate, avc->channels,
-- 
2.12.2.564.g063fe858b8-goog