From patchwork Fri Jan 26 10:30:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mrdegier@gmail.com X-Patchwork-Id: 7420 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.156.27 with SMTP id q27csp514071jak; Fri, 26 Jan 2018 02:36:45 -0800 (PST) X-Google-Smtp-Source: AH8x225RHCdoUI1YV4In4y1+LuQdg67hzZljK8yTk7XiNkNpPswYO1POOiRQ1JhPnZ4r/bqoybDY X-Received: by 10.223.184.200 with SMTP id c8mr5118337wrg.105.1516963005570; Fri, 26 Jan 2018 02:36:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516963005; cv=none; d=google.com; s=arc-20160816; b=wjds9hi0dPVI0lHCjgLmEX93GFdUYKr337Mwij+dhc1LvSvzfbe5zRh5lIK7uwCnIM 0hbWpd5a1jeeaPEKzb1KzhpDIFIrl+UGxR4K4HKpCS8CehdtWyOMXBA7Hc4St7kV7qvR Mde58AwEDfI/KNyn9yMHwk3/SCoV84e0ZT2IjWve32DvnX5lls1U9zOqgBtrdAGsF1L2 z/7vPGXEfO6LD7uvp7M54+dkWs6WIEXe0pRl8NxvEDTSa3/anaF2Knr5w4vykBi7fXfU OOWa6qUYnjRI85ASp8PrM2ukZeAb70wclbMz6uV7+oj5HEBT75NHbPo5C/3IdV82TMcp JXsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=riQ4txT196ia4vQSxssLFVGzt+pcjfTQD02h3dI/u2M=; b=KQiGpIDqz0HcPNG/7m4JiX59YPNgmn4HgjqoXnMfZPn1AAehEnx6H6bU2uj2DXaF2X GT6uvd/5TJp69opLTXU4iYtWEurL2Lb6LInbkKcaDT+zvLRFrGTNQZZe5SNmIUK+n/qO LRdV/BW8fmUv0oOcAqku/I+ckyh82V9acG4PvxPNUiknNzKSaWxrdJPlwnoUmFZUCUwN VQoCZIw3qPW3l8f7NhiebUVUY/ap3OJc+Qg7XF1tVaXyhYBifltrbWQN1lch5EgfV7De 0YhIBF/0OdDBCOjq1hzQk8Jhr/Kdi+hZaiIvR3j+QnFWKIkRDwpxUVHGsEVtNfq4n7VY kxcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=iQrJZmkY; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id m4si5311430wrm.210.2018.01.26.02.36.44; Fri, 26 Jan 2018 02:36:45 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=iQrJZmkY; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 07B7E6897AC; Fri, 26 Jan 2018 12:36:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 46EFC68920E for ; Fri, 26 Jan 2018 12:36:33 +0200 (EET) Received: by mail-wm0-f66.google.com with SMTP id x4so34664214wmc.0 for ; Fri, 26 Jan 2018 02:36:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FJgTP0NFiIPZngJ+/aA6hGXgPWan0s+hPzK0gKRPdWs=; b=iQrJZmkYHpvwXdjoNF70N42Qz6X0HD5Nswb8vvR3buyBCX7T2BcRHU7CppgT4qOZ3/ dJ5narsnbrdEVHMfLGD6EmGJoi9kAZ8lEbl7VQ4QG24QtE3Cm7Yf1Azo56lHaovgz9LX 4VUmG6BGecIHRP55ZSIzaDv3jtQX+tkayEXkXdDO5Sx94/GpsPK55MzYza9Uj5VtL78+ iklWPkPZ3uAkBjVeq46Bb8HcD4vWEct3MYW9ZXvsC7ugU8Ott3EgQXmpVi3n6rwGvKFo jU2d2Wd/ez5gFchjlo3agoNvVnBK8YKjAJCg5Rg+DCEG6zaEk/TR80j5/gvISezPtAQf 3Ixg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FJgTP0NFiIPZngJ+/aA6hGXgPWan0s+hPzK0gKRPdWs=; b=KsET/88BnAnMMPg/PpGWCBipfrIhFD8lhdC2IXm6FIYWoggFOuTJd8JC5b6MwsWNIk KrMxX08MOXIw+YCPanqHD+BW2WZ3ix/w7Yje9XTMi9i8IQZk+QkRtDEwkiwzFAcQ/Bew 09/EMIyHAM2HKaev38gIM601c5N5L+fPaDptN+SkaFCeEu0vg9Pu7ER9U9Z1MRA+PwOb cPhYOBmG6ARJIElTpEvh1Y5nxRPH3iRdTKuxvB2UWq07Ex1BDSyMtEEKK5Izfpv26i2u puX3hp8ctmxHFt/PIgxlmtqdtyGlFUv0im3kF0oQTNDLXCKLMQ215DAdeA5G85qkfcv4 VABA== X-Gm-Message-State: AKwxytcnoTTTRzvXeon/F9Tbxcj1B2222uj9kGG9gX86EAnfbXKG4Mzq 6wFjWcRJ6EDihvIktuOV5InWEw7Z X-Received: by 10.80.206.88 with SMTP id k24mr34270004edj.153.1516962677410; Fri, 26 Jan 2018 02:31:17 -0800 (PST) Received: from yoyodyne.local.net ([80.82.202.196]) by smtp.gmail.com with ESMTPSA id g21sm2293799edg.88.2018.01.26.02.31.16 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 26 Jan 2018 02:31:16 -0800 (PST) From: Menno de Gier To: ffmpeg-devel@ffmpeg.org Date: Fri, 26 Jan 2018 11:30:57 +0100 Message-Id: <20180126103057.13172-1-mrdegier@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180122113826.26172-1-mrdegier@gmail.com> References: <20180122113826.26172-1-mrdegier@gmail.com> Subject: [FFmpeg-devel] [PATCH v3] avcodec/libopus: support disabling phase inversion. 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 Cc: Menno MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Menno This supports disabling phase inversion in both the libopus encoder and the decoder. Signed-off-by: Menno --- doc/encoders.texi | 5 +++++ libavcodec/libopusdec.c | 33 +++++++++++++++++++++++++++++++++ libavcodec/libopusenc.c | 14 ++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/doc/encoders.texi b/doc/encoders.texi index 6a410a8cb6..c5dfc646d9 100644 --- a/doc/encoders.texi +++ b/doc/encoders.texi @@ -981,6 +981,11 @@ Other values include 0 for mono and stereo, 1 for surround sound with masking and LFE bandwidth optimizations, and 255 for independent streams with an unspecified channel layout. +@item apply_phase_inv (N.A.) (requires libopus >= 1.2) +If set to 0, disables the use of phase inversion for intensity stereo, +improving the quality of mono downmixes, but slightly reducing normal stereo +quality. The default is 1 (phase inversion enabled). + @end table @anchor{libshine} diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c index 4f7f4755c2..f82ae57e54 100644 --- a/libavcodec/libopusdec.c +++ b/libavcodec/libopusdec.c @@ -25,6 +25,7 @@ #include "libavutil/internal.h" #include "libavutil/intreadwrite.h" #include "libavutil/ffmath.h" +#include "libavutil/opt.h" #include "avcodec.h" #include "internal.h" @@ -33,11 +34,15 @@ #include "libopus.h" struct libopus_context { + AVClass *class; OpusMSDecoder *dec; int pre_skip; #ifndef OPUS_SET_GAIN union { int i; double d; } gain; #endif +#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST + int apply_phase_inv; +#endif }; #define OPUS_HEAD_SIZE 19 @@ -136,6 +141,15 @@ static av_cold int libopus_decode_init(AVCodecContext *avc) } #endif +#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST + ret = opus_multistream_decoder_ctl(opus->dec, + OPUS_SET_PHASE_INVERSION_DISABLED(!opus->apply_phase_inv)); + if (ret != OPUS_OK) + av_log(avc, AV_LOG_WARNING, + "Unable to set phase inversion: %s\n", + opus_strerror(ret)); +#endif + /* Decoder delay (in samples) at 48kHz */ avc->delay = avc->internal->skip_samples = opus->pre_skip; @@ -209,6 +223,24 @@ static void libopus_flush(AVCodecContext *avc) avc->internal->skip_samples = opus->pre_skip; } + +#define OFFSET(x) offsetof(struct libopus_context, x) +#define FLAGS AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM +static const AVOption libopusdec_options[] = { +#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST + { "apply_phase_inv", "Apply intensity stereo phase inversion", OFFSET(apply_phase_inv), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS }, + { NULL }, +#endif +}; + +static const AVClass libopusdec_class = { + .class_name = "libopusdec", + .item_name = av_default_item_name, + .option = libopusdec_options, + .version = LIBAVUTIL_VERSION_INT, +}; + + AVCodec ff_libopus_decoder = { .name = "libopus", .long_name = NULL_IF_CONFIG_SMALL("libopus Opus"), @@ -223,5 +255,6 @@ AVCodec ff_libopus_decoder = { .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, + .priv_class = &libopusdec_class, .wrapper_name = "libopus", }; diff --git a/libavcodec/libopusenc.c b/libavcodec/libopusenc.c index b449497d15..4ae81b0bb2 100644 --- a/libavcodec/libopusenc.c +++ b/libavcodec/libopusenc.c @@ -39,6 +39,9 @@ typedef struct LibopusEncOpts { int packet_size; int max_bandwidth; int mapping_family; +#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST + int apply_phase_inv; +#endif } LibopusEncOpts; typedef struct LibopusEncContext { @@ -154,6 +157,14 @@ static int libopus_configure_encoder(AVCodecContext *avctx, OpusMSEncoder *enc, "Unable to set maximum bandwidth: %s\n", opus_strerror(ret)); } +#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST + ret = opus_multistream_encoder_ctl(enc, + OPUS_SET_PHASE_INVERSION_DISABLED(!opts->apply_phase_inv)); + if (ret != OPUS_OK) + av_log(avctx, AV_LOG_WARNING, + "Unable to set phase inversion: %s\n", + opus_strerror(ret)); +#endif return OPUS_OK; } @@ -530,6 +541,9 @@ static const AVOption libopus_options[] = { { "on", "Use variable bit rate", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, FLAGS, "vbr" }, { "constrained", "Use constrained VBR", 0, AV_OPT_TYPE_CONST, { .i64 = 2 }, 0, 0, FLAGS, "vbr" }, { "mapping_family", "Channel Mapping Family", OFFSET(mapping_family), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 255, FLAGS, "mapping_family" }, +#ifdef OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST + { "apply_phase_inv", "Apply intensity stereo phase inversion", OFFSET(apply_phase_inv), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, FLAGS }, +#endif { NULL }, };