From patchwork Tue Mar 28 00:35:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felicia Lim X-Patchwork-Id: 3140 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.44.195 with SMTP id s186csp405137vss; Mon, 27 Mar 2017 17:44:01 -0700 (PDT) X-Received: by 10.28.187.213 with SMTP id l204mr11273623wmf.104.1490661841730; Mon, 27 Mar 2017 17:44:01 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m6si2600004wrm.247.2017.03.27.17.44.01; Mon, 27 Mar 2017 17:44:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AA57A6891E7; Tue, 28 Mar 2017 03:43:35 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yw0-f170.google.com (mail-yw0-f170.google.com [209.85.161.170]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 27D59688249 for ; Tue, 28 Mar 2017 03:43:29 +0300 (EEST) Received: by mail-yw0-f170.google.com with SMTP id v76so43521373ywg.0 for ; Mon, 27 Mar 2017 17:43:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=u8O09EdyIOY+Fp+bLRXdd1aZWGuPuz80+v99kQhnByw=; b=bETGJfRXc9kELKEVzZ5Vxwy7WyZcoTANtHj+6JnK+dpKzOa6Dso80jZ0SvL1RvoHiq 6IYUV+pxsWhdCwve01reaQU8c5PuZRv5rLmXqq8+TLLeTXdwqDl53MDB6NQCOpMVni33 bnIW2XsEyPrlZnGjw9GI0U/Ovp4Quxtht+1EKOpVOZ9SqodIzYnB4guXCms5Ud8T6sax kAyNlcIklUmwgnY+Hti9ApZaXnDZTKN2Q1Xba1rjqTl+MhqZ1SUUSECFiE3LiwMXfPfm FfKcpHjEhWse8nEcYQTiRDerR87JlClXVpfq6o7+GDT5tuJ/EsdBAdin9KvER9o0xCoO H5uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=u8O09EdyIOY+Fp+bLRXdd1aZWGuPuz80+v99kQhnByw=; b=Xz//V8Cv+7d9tCDFtzv4gtYRj0MGadTXLkqiQ03AMgAKARDf+BuhcMDlLFbRarLJAH bHVzjce3ADJRqZaCIeYnBnPKlO+RajxagEO6WlJ6fvMWLdZx92OuxhmONlHuUMCUcKeT 47tqGk04M5aRG/aREOlwqfHmZxHZVhKbfXz2Tc2ohJdW/AyMwG6XdpkTGlTWZkyczqm3 SjbYMUSWvK263W3zqXyiU6cIuDkon4DReV60S20qLOA+UJZvLLUiaH3uGsM+MIbKMmGA zZvx0mLDTrMSFgBkCKsDAXTfnJxlZ/7VNTFGTFn+Q9/OT0i3fzhEYTBoHVLvQZlc4yz7 QrTw== X-Gm-Message-State: AFeK/H3BwZTbPNxVixH595qdPm99OROC7fmoC4ZnIbHrSE+iq2OMsoEsv38GudtURphvh5aE1my7Mt5iv4d1LAQN X-Received: by 10.129.98.2 with SMTP id w2mr15708274ywb.336.1490661340500; Mon, 27 Mar 2017 17:35:40 -0700 (PDT) MIME-Version: 1.0 From: Felicia Lim Date: Tue, 28 Mar 2017 00:35:29 +0000 Message-ID: To: "ffmpeg-devel@ffmpeg.org" X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] [PATCH] libopus: Add channel mapping 2 support in libopusdec X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" 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 * From 6607c6f8cff64771cdf34faa6e318271f5a48ac2 Mon Sep 17 00:00:00 2001 From: Felicia Lim 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