diff mbox

[FFmpeg-devel] libavcodec/opus: Add channel mapping 2 to extradata parser

Message ID 1472753850-14834-2-git-send-email-mgraczyk@google.com
State Accepted
Commit be07c25896bb608ee84a902e6a470b87c741115b
Headers show

Commit Message

Michael Graczyk Sept. 1, 2016, 6:17 p.m. UTC
From: Michael Graczyk <mgraczyk@google.com>

This allows libavcodec/opus to demux ambisonics in an ogg/opus container.
Channel mapping family 2 is being added in this standards track IETF draft:
tools.ietf.org/html/draft-ietf-codec-ambisonics-00
---
 libavcodec/opus.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Michael Niedermayer Sept. 1, 2016, 9:56 p.m. UTC | #1
On Thu, Sep 01, 2016 at 11:17:30AM -0700, mgraczyk-at-google.com@ffmpeg.org wrote:
> From: Michael Graczyk <mgraczyk@google.com>
> 
> This allows libavcodec/opus to demux ambisonics in an ogg/opus container.
> Channel mapping family 2 is being added in this standards track IETF draft:
> tools.ietf.org/html/draft-ietf-codec-ambisonics-00
> ---
>  libavcodec/opus.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)

applied

thx

[...]
diff mbox

Patch

diff --git a/libavcodec/opus.c b/libavcodec/opus.c
index 703d2e8..da015ec 100644
--- a/libavcodec/opus.c
+++ b/libavcodec/opus.c
@@ -347,7 +347,7 @@  av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
         streams        = 1;
         stereo_streams = channels - 1;
         channel_map    = default_channel_map;
-    } else if (map_type == 1 || map_type == 255) {
+    } else if (map_type == 1 || map_type == 2 || map_type == 255) {
         if (extradata_size < 21 + channels) {
             av_log(avctx, AV_LOG_ERROR, "Invalid extradata size: %d\n",
                    extradata_size);
@@ -371,6 +371,15 @@  av_cold int ff_opus_parse_extradata(AVCodecContext *avctx,
             }
             layout = ff_vorbis_channel_layouts[channels - 1];
             channel_reorder = channel_reorder_vorbis;
+        } else if (map_type == 2) {
+            int ambisonic_order = ff_sqrt(channels) - 1;
+            if (channels != (ambisonic_order + 1) * (ambisonic_order + 1)) {
+                av_log(avctx, AV_LOG_ERROR,
+                       "Channel mapping 2 is only specified for channel counts"
+                       " which can be written as (n + 1)^2 for nonnegative integer n\n");
+                return AVERROR_INVALIDDATA;
+            }
+            layout = 0;
         } else
             layout = 0;