From patchwork Thu Jan 13 02:02:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 33475 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp39300iog; Wed, 12 Jan 2022 18:37:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzV/1BAGgTUzK9aNORZzZvq9fq88s1T3LqBCNtMxQHPoN3yb5/j72sghPcPtefSMJFDSYeU X-Received: by 2002:a17:906:d184:: with SMTP id c4mr1925867ejz.20.1642041428679; Wed, 12 Jan 2022 18:37:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642041428; cv=none; d=google.com; s=arc-20160816; b=p/A7MA3/Q0+EtSxvowwGGR7azrwyBCD9Asxsogjn7JdMEnB7spf8PhbslrIesfPuls NpVaZdxFkzHei/dkadZ5ZWqHvs8nvHqqr+tJe93P6D21lyiGT7whA7ZHzLRcsSb7sCT0 BkVCelAC1yGr3OnZFPDr5tpDHTKe8XU+DZkNxEVrTbtOZrzCgGDrL8uE6tdiCVrjaSZs PM6ZSLRb1+kCwxGpHAxd9SQ/WM0E5ZedcgNG7ScMVNPjRo0tb/3v6oYVj8KkNgZEcCAF 9Q/sIe1/fSM/TSBGgLaZhsyKtF/UhghLyatQMllTYvr4Bv/WPxmT3mCPC1V6QL3C4ax9 7/Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=9ginFy9Yv7cdwZPBMmh+42O87+HrRYKHpZZ//yg4gFQ=; b=FAgi58o2JyT2wBo3FSSkFhzFf5ZkHGW8kXKy8QGxR1p/lpydMKhD1lVwnTb7toJh0U MxI2GsxUvEEaJDNdU/e59CVc5MA/bcalIoy3Z/V/d9LUG3CPHEDwMn2MDFLFcBHkEnXC lL/cE1lu/mBCiNOL3XmACmrWg4jC8Is60SiV0C17Zoczkk50ErBHdExyjiOUZrHSvcTF I4xhtwPlLtwaHz3dAhJUUcla/ytw6Q4U5cesTl9gbZEJEqBkyULHaAkyCNAH/Z/wWO80 YchGZT78b38QraMWTTIexLyDf7eHa7xekAzd8FlgE0MGM/sJicKVLKotMtZIHoKY2W40 4Qpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=a8rlA5Xx; 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=QUARANTINE 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 e3si799560ejs.167.2022.01.12.18.37.08; Wed, 12 Jan 2022 18:37:08 -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=20210112 header.b=a8rlA5Xx; 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=QUARANTINE 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 8855668B771; Thu, 13 Jan 2022 04:03:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5878968B744 for ; Thu, 13 Jan 2022 04:03:24 +0200 (EET) Received: by mail-qv1-f53.google.com with SMTP id q4so5105242qvh.9 for ; Wed, 12 Jan 2022 18:03:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=JykrKsdHw3+XiRCHJcrYpdteHXVW8sP6mOttuwthLWA=; b=a8rlA5Xxk3FBDhFRfPsCGBImc4gVKVCkJa3tcv49l5CtznGzGLfJsYJ0JF7yFoIOU9 8KZFa2iGUPyIdeyfwGtww+j0lqCRCQEJhzqq7gRiYtXxYEcsfPPZRopVPO7k4yigse9S i7o7hJhBb7RNsu7R04OjaOWnJyQSX1qyu+ILhdja1xX4y2pW4DKM8Y4UgLQ/EdUeoT5y 7XkTLaQ+9S6J2ke9JbOXSHxwbSWj2I23i+aGYP3JUfG3i7N61TxIpncm5QN7krucMeUQ ho+tgrmPw+7Mox08QoFaLS9V6waNaUTZDTsjfeE/I6x3YAqL/eLKIWn2+G6Iby2+LgSS qLLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JykrKsdHw3+XiRCHJcrYpdteHXVW8sP6mOttuwthLWA=; b=Eh6EyB5W2xtrSc9osaD83myFXlfDJPRVNfwv2yzvo/Y5fShXvEYd3O41a1AbOc+Yil WzZmjVaqLiY4/UYDGetcQAlzOtTSbrLOPjlmdqMbu1759IzDTHNpnZza+ASLlrilPEqZ KzHK5uwqJMDAIkU/Mmsije8WQrcnwicpEEMIq9F/Hq08reRW3tYHU35P6F3iAYcA9Fpg HRCSUIFZuY0IgUY47325jI5wtqLmmEBKuGMnrkN37U+bcTJo7bOL0l8tL9xb8Lvz1/Br VYT4o6KWhKJJEySaajwEVfzrPeb0v16CxPTyh675s2fqn0Di9OHE1dSC5kegk5mZ6GvP ii4A== X-Gm-Message-State: AOAM531lfZo/jxS57iG8N7vaTHGREPEnID2pCwGQrgY4BKMP3R3Vos+o U+OCe0UXstRIa9KTyhWm8oUZrehVL6Q= X-Received: by 2002:a05:6214:5287:: with SMTP id kj7mr2273935qvb.38.1642039402813; Wed, 12 Jan 2022 18:03:22 -0800 (PST) Received: from localhost.localdomain ([186.136.131.95]) by smtp.gmail.com with ESMTPSA id v1sm1045961qtc.95.2022.01.12.18.03.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 18:03:22 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Wed, 12 Jan 2022 23:02:34 -0300 Message-Id: <20220113020242.661-22-jamrial@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220113015101.4-1-jamrial@gmail.com> References: <20220113015101.4-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 201/281] dolby_e: convert to new channel layout API X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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" X-TUID: cY6KzxJzGlyC From: Anton Khirnov Signed-off-by: James Almer --- libavcodec/dolby_e.c | 52 ++++++++++++++++++++++++++++++++----- libavcodec/dolby_e.h | 2 ++ libavcodec/dolby_e_parser.c | 11 +++++--- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c index 6c0d54be4c..a9106a7632 100644 --- a/libavcodec/dolby_e.c +++ b/libavcodec/dolby_e.c @@ -23,6 +23,7 @@ #include "libavutil/thread.h" #include "libavutil/mem.h" #include "libavutil/mem_internal.h" +#include "libavutil/opt.h" #include "internal.h" #include "get_bits.h" @@ -39,6 +40,11 @@ #define MAX_MSTR_EXP 2 #define MAX_BIAS_EXP 50 +enum DBEOutputChannelOrder { + CHANNEL_ORDER_DEFAULT, + CHANNEL_ORDER_CODED, +}; + typedef struct DBEGroup { uint8_t nb_exponent; uint8_t nb_bias_exp[MAX_MSTR_EXP]; @@ -70,6 +76,7 @@ typedef struct DBEChannel { } DBEChannel; typedef struct DBEDecodeContext { + const AVClass *class; AVCodecContext *avctx; DBEContext dectx; @@ -1057,7 +1064,7 @@ static int filter_frame(DBEDecodeContext *s, AVFrame *frame) reorder = ch_reorder_4; else if (metadata->nb_channels == 6) reorder = ch_reorder_6; - else if (metadata->nb_programs == 1 && !(s->avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE)) + else if (metadata->nb_programs == 1 && metadata->output_channel_order == CHANNEL_ORDER_DEFAULT) reorder = ch_reorder_8; else reorder = ch_reorder_n; @@ -1093,19 +1100,23 @@ static int dolby_e_decode_frame(AVCodecContext *avctx, void *data, s->metadata.multi_prog_warned = 1; } + av_channel_layout_uninit(&avctx->ch_layout); switch (s->metadata.nb_channels) { case 4: - avctx->channel_layout = AV_CH_LAYOUT_4POINT0; + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0; break; case 6: - avctx->channel_layout = AV_CH_LAYOUT_5POINT1; + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1; break; case 8: - avctx->channel_layout = AV_CH_LAYOUT_7POINT1; + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1; + break; + default: + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = s->metadata.nb_channels; break; } - avctx->channels = s->metadata.nb_channels; avctx->sample_rate = s->metadata.sample_rate; avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; @@ -1252,17 +1263,46 @@ static av_cold int dolby_e_init(AVCodecContext *avctx) if (!(s->fdsp = avpriv_float_dsp_alloc(0))) return AVERROR(ENOMEM); - s->dectx.metadata.multi_prog_warned = !!(avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) + s->dectx.metadata.output_channel_order = CHANNEL_ORDER_CODED; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + + s->dectx.metadata.multi_prog_warned = s->dectx.metadata.output_channel_order == CHANNEL_ORDER_CODED; s->dectx.avctx = s->avctx = avctx; return 0; } +#define OFFSET(x) offsetof(DBEDecodeContext, x) +#define FLAGS (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM) +static const AVOption options[] = { + { "channel_order", "Order in which the channels are to be exported", + OFFSET(dectx.metadata.output_channel_order), AV_OPT_TYPE_INT, + { .i64 = CHANNEL_ORDER_DEFAULT }, 0, 1, FLAGS, "channel_order" }, + { "default", "normal libavcodec channel order", 0, AV_OPT_TYPE_CONST, + { .i64 = CHANNEL_ORDER_DEFAULT }, .flags = FLAGS, "channel_order" }, + { "coded", "order in which the channels are coded in the bitstream", + 0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = FLAGS, "channel_order" }, + + { NULL }, +}; + +static const AVClass dolby_e_decoder_class = { + .class_name = "Dolby E decoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + const AVCodec ff_dolby_e_decoder = { .name = "dolby_e", .long_name = NULL_IF_CONFIG_SMALL("Dolby E"), .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_DOLBY_E, .priv_data_size = sizeof(DBEDecodeContext), + .priv_class = &dolby_e_decoder_class, .init = dolby_e_init, .decode = dolby_e_decode_frame, .close = dolby_e_close, diff --git a/libavcodec/dolby_e.h b/libavcodec/dolby_e.h index 9f0c065729..b2eadfea4a 100644 --- a/libavcodec/dolby_e.h +++ b/libavcodec/dolby_e.h @@ -59,6 +59,8 @@ typedef struct DolbyEHeaderInfo { */ int multi_prog_warned; + int output_channel_order; + int sample_rate; /** @} */ } DolbyEHeaderInfo; diff --git a/libavcodec/dolby_e_parser.c b/libavcodec/dolby_e_parser.c index 23bddd14f3..9f54627356 100644 --- a/libavcodec/dolby_e_parser.c +++ b/libavcodec/dolby_e_parser.c @@ -42,17 +42,20 @@ static int dolby_e_parse(AVCodecParserContext *s2, AVCodecContext *avctx, s2->duration = FRAME_SAMPLES; switch (s->metadata.nb_channels) { case 4: - avctx->channel_layout = AV_CH_LAYOUT_4POINT0; + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0; break; case 6: - avctx->channel_layout = AV_CH_LAYOUT_5POINT1; + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1; break; case 8: - avctx->channel_layout = AV_CH_LAYOUT_7POINT1; + avctx->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_7POINT1; + break; + default: + avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; + avctx->ch_layout.nb_channels = s->metadata.nb_channels; break; } - avctx->channels = s->metadata.nb_channels; avctx->sample_rate = s->metadata.sample_rate; avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;