From patchwork Sun Nov 15 21:55:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23654 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id A41C844ACB9 for ; Sun, 15 Nov 2020 23:56:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 820E268A0FA; Sun, 15 Nov 2020 23:56:15 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f68.google.com (mail-qv1-f68.google.com [209.85.219.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 999D9688057 for ; Sun, 15 Nov 2020 23:56:08 +0200 (EET) Received: by mail-qv1-f68.google.com with SMTP id ek7so7756986qvb.6 for ; Sun, 15 Nov 2020 13:56:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=8b9DWyEbPsOpb2+e0WYDQpXoxEywAc9VeurzkSLUcY4=; b=ENBbf8dDExEDm8XFzW8q8y1jE3uacPxCZn5ce48Z76wb2X9LuY3WHYuyY6dSTq0tcX QfGERnmQWmEks/Lskp3fEtGyJkO/DKWPmD01JgYM7bZH1j6pV5uHiCypGPIJ6URVIU0J sI67uDRLSab1RTLVD+obvhrluDDnPuNRH+lpAgtE2aZwf2ircCeHofw41acagNbt90if xkWK1WQkDTJxaZ06peAfWZjzjMQMPphIj81BPRORuXc6rEJAbjqVra1YgOnVs5bwFLGN gfM5O28sEarvnmr3Ij3joBY0+iKtsYG/XT6dAa2E3OT9yUz0+y2WNQaN+08ubsllCtJJ OwPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=8b9DWyEbPsOpb2+e0WYDQpXoxEywAc9VeurzkSLUcY4=; b=mXEYHGiTJV4kuW4a8jNk5cSj/jllPhoScp6Vtj+uHc3u2iV0/HxqWsf6z555U7vcHv TfRNyYYKjPQ8MaiNep+xgrjB72uRn7mtz/hOvrIrLG6KcEKfDssxX9Zw1zpygqtAzwKu hyjIChyLlNlzYOrvypGykhXwG49D221YyDi0D9WXDaudbY3X56b9EuIxHUxAaPOV1l8R pIlVo4WNiLkC931EdEKh6WHVzkCYYw1DH7O80UBt5PBsOk0WRXz/eeyBt45iE7/Rb3Uv zkNopTsQGgmBvpfiLs4RVhUpmjBM+fl0OJ65JXmmmFGrW55cZcDZrleLZZv5MWUcX992 qb5w== X-Gm-Message-State: AOAM530/ZpAIwPTn6tfoYlBmuy6CLVfbpcZzloH4sa5MzKBvJy++2uFt apyXxIZ7yLMXL3b1Dd/ylC1XHCg1zBk= X-Google-Smtp-Source: ABdhPJxg0X2MtiDTQF7xObIDoW8hfub9tHjMAbSV0yMwdwoNiiORLbmJB6GUIhthvL5wNTHOE8NW2A== X-Received: by 2002:a05:6214:c8e:: with SMTP id r14mr6523188qvr.21.1605477366728; Sun, 15 Nov 2020 13:56:06 -0800 (PST) Received: from localhost.localdomain ([181.23.74.184]) by smtp.gmail.com with ESMTPSA id z133sm6833136qka.20.2020.11.15.13.56.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Nov 2020 13:56:05 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 15 Nov 2020 18:55:38 -0300 Message-Id: <20201115215541.4526-1-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4 v2] avcodec/cbs: add an AVClass to CodedBitstreamType for option handling 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" So unit parsing may be configured with caller set options. Signed-off-by: James Almer --- libavcodec/cbs.c | 9 +++++++++ libavcodec/cbs_internal.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index c8c526ab12..c7afccd6f5 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -23,6 +23,7 @@ #include "libavutil/avassert.h" #include "libavutil/buffer.h" #include "libavutil/common.h" +#include "libavutil/opt.h" #include "cbs.h" #include "cbs_internal.h" @@ -101,6 +102,10 @@ int ff_cbs_init(CodedBitstreamContext **ctx_ptr, av_freep(&ctx); return AVERROR(ENOMEM); } + if (type->priv_class) { + *(const AVClass **)ctx->priv_data = type->priv_class; + av_opt_set_defaults(ctx->priv_data); + } } ctx->decompose_unit_types = NULL; @@ -129,6 +134,10 @@ void ff_cbs_close(CodedBitstreamContext **ctx_ptr) ctx->codec->close(ctx); av_freep(&ctx->write_buffer); + + if (ctx->codec->priv_class && ctx->priv_data) + av_opt_free(ctx->priv_data); + av_freep(&ctx->priv_data); av_freep(ctx_ptr); } diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index faa847aad3..a392880036 100644 --- a/libavcodec/cbs_internal.h +++ b/libavcodec/cbs_internal.h @@ -86,6 +86,12 @@ typedef const struct CodedBitstreamUnitTypeDescriptor { typedef struct CodedBitstreamType { enum AVCodecID codec_id; + // A class for the private data, used to declare private AVOptions. + // This field is NULL for types that do not declare any options. + // If this field is non-NULL, the first member of the filter private data + // must be a pointer to AVClass. + const AVClass *priv_class; + size_t priv_data_size; // List of unit type descriptors for this codec. From patchwork Sun Nov 15 21:55:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23655 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id BACAD44ACB9 for ; Sun, 15 Nov 2020 23:56:18 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A17A36881EE; Sun, 15 Nov 2020 23:56:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f196.google.com (mail-qk1-f196.google.com [209.85.222.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C7754688057 for ; Sun, 15 Nov 2020 23:56:09 +0200 (EET) Received: by mail-qk1-f196.google.com with SMTP id 11so14908338qkd.5 for ; Sun, 15 Nov 2020 13:56:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LFHrS1ZFz8afTyvMCnluukBvA2Etvhp0cPUhyilItLo=; b=NHXjL5Px7+YSqtisHBy06wXs9Mq2Qbt8WwOQ1vR9RnOtuZN2Wm0S/x413Dk2OwZVCE oD8qBETKog05eu7VJbU319d9+Q+GI4o51jyv+8x9cswvZmRhqMrLK9cU2e6PgcRN8l+r IWFNIlaI1wOBBscx73JgammJklLZd372t4unMJQG/+OCwjQXKG6jwqVQEG8/mi0zA0/T T0/u8CdwjAllthSmzYCfhpdVMEO2YwUlqjsqx5iiyUkv6ouVQ97FcQJrUCIvEnEWdgW9 4atfswx4i46/Gpy4eGpZ+8R1qufKNQlyn6QHiT3ILGGQ1LMrkU5ZCGel8qu0WX4+5Qv1 pBzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LFHrS1ZFz8afTyvMCnluukBvA2Etvhp0cPUhyilItLo=; b=HEBplfBhkVb6c/xwqxUxZx6VbVfmV62dgfKXx9EH0raZxziv1v+PM6cHWyKCWEL8Zp F7EPs807LNKt2W6WXctygFUI2opSDfxZT7zAOaX6HpI57pOm67Q5AmkorCDiGmeELj2S pn47apfEOOK4khHwKHkplkDgnIFO/VCYaEY+OOvobDP7JeYwj8zckjRaX0XhHaPCE+53 /dKAD53goA6gQfJUAJstF4b0+klZPo7aRN45VvkvczPLCn2O7wxY9dxWJG4Sx9NGel5u /1otFE1N9AZjY4p4rwn65CWIrp9NT5A2jttNgi3FdmjRaTWJwkDzJ5RMw7/6jHbwUgHg 6sRw== X-Gm-Message-State: AOAM533P4djU60cLc5YQxxj7fCMucYdLvwloP6qEV9fa0xPznatoSbpv ZpzGh4kzopltKneNMuNbDlFIok7qXqc= X-Google-Smtp-Source: ABdhPJwEcIkz/ZFUqQDdcnygG7MeFMBAEqyLvwvriSKNNzI1wwkuzepmICJFSsUjMrM9dWPXw6FqMA== X-Received: by 2002:a37:5447:: with SMTP id i68mr12098492qkb.31.1605477368214; Sun, 15 Nov 2020 13:56:08 -0800 (PST) Received: from localhost.localdomain ([181.23.74.184]) by smtp.gmail.com with ESMTPSA id z133sm6833136qka.20.2020.11.15.13.56.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Nov 2020 13:56:07 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 15 Nov 2020 18:55:39 -0300 Message-Id: <20201115215541.4526-2-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201115215541.4526-1-jamrial@gmail.com> References: <20201115215541.4526-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4 v2] avcodec/cbs: allow cbs_read_fragment_content() to discard units 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" The caller may not need all units in a fragment in reading only scenarios. They could in fact alter global state stored in the private CodedBitstreamType fields in an undesirable way. And unlike preventing decomposition of units, discarding can be done based on parsed values within the unit. Signed-off-by: James Almer --- libavcodec/cbs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index c7afccd6f5..f4312d199b 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -202,6 +202,12 @@ static int cbs_read_fragment_content(CodedBitstreamContext *ctx, av_log(ctx->log_ctx, AV_LOG_VERBOSE, "Decomposition unimplemented for unit %d " "(type %"PRIu32").\n", i, unit->type); + } else if (err == AVERROR(EAGAIN)) { + av_log(ctx->log_ctx, AV_LOG_VERBOSE, + "Discarding unit %d " + "(type %"PRIu32").\n", i, unit->type); + av_buffer_unref(&unit->content_ref); + unit->content = NULL; } else if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d " "(type %"PRIu32").\n", i, unit->type); From patchwork Sun Nov 15 21:55:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23656 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9F34344ACB9 for ; Sun, 15 Nov 2020 23:56:19 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8506E68B814; Sun, 15 Nov 2020 23:56:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5129A6881F5 for ; Sun, 15 Nov 2020 23:56:11 +0200 (EET) Received: by mail-qk1-f179.google.com with SMTP id d28so14882462qka.11 for ; Sun, 15 Nov 2020 13:56:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=PzlXMTDP909tEPkUouClTAlijTkcYg7+lNgW/pMSS80=; b=V2vOsLdm+Z2mdCo31YLKuX+u4bdhOBVqPQ8VNv6xy7tylUmKa4xVOdvFR2TNYym6JZ S2UzUbIahL8pqa6UMo2n2QqsCAdjjCAEqOrY7SHlYpeveh5Mb96mSJlHZF8yC2vNAd/e GchrLzsiP65g7P4WyKRq8c06hxoA9Kgx6YjLBzJJN7nYz2H5WhQjr6NZ2VYwNMyES7NE Ww2BYs2z0YxJ/4umJdvMBWkgT1XhgSKIEpo439Z1eMCVLsusQwoBdjxp04GgddgYUvzA q46mDiQDS949LqWmn4zKSvxmm34VVA0exgRQGAz5UTk4purrOwp92AHNUA7ibp+6pG9P vG3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PzlXMTDP909tEPkUouClTAlijTkcYg7+lNgW/pMSS80=; b=H5e8tEQbmSMIKRg5gLGtbb5d4pQMoicrEax9KaUr08xfO16MrGt+kwiqtT3657MCh7 SAyFqP79aXq94UNWIy6sGWNPoQkD57hzy7UesVSmMwLwKJ+a57xrNHVMscRmDGkr/HcR frTbyMjzj3qHa8aLfTUpAg4pUDe7q5m1OyHSEKjQeeWhjYjJqq3Tw1d3ZeUWY8WX4hC3 yKAd74iVTXImEYdEN4jKw+3ub5eeTRCPkyAAcJ2BtAGBhnp9rrSKz89zs99QKTSdMz2x kr3TqDRbg486tgbdI3o729s7SYQnsDXzgbI3uJmptG08viRJVe9XjC+60aoJau5wggrK 140w== X-Gm-Message-State: AOAM532axfXyHUA298z0UMEzGdoWyBFgNeHpuWG64BEawy9azNncUpn/ czqxFJ9PTxcoiKn+31y2e0i2SGv8kmk= X-Google-Smtp-Source: ABdhPJw/g/5mcz4hl3cM74XVjaicUd0TKNhhmpjak9ANw4DkrRch7G2NzpolyBBIViwu+uVFEyyZjw== X-Received: by 2002:a37:a88f:: with SMTP id r137mr12668907qke.437.1605477369688; Sun, 15 Nov 2020 13:56:09 -0800 (PST) Received: from localhost.localdomain ([181.23.74.184]) by smtp.gmail.com with ESMTPSA id z133sm6833136qka.20.2020.11.15.13.56.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Nov 2020 13:56:09 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 15 Nov 2020 18:55:40 -0300 Message-Id: <20201115215541.4526-3-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201115215541.4526-1-jamrial@gmail.com> References: <20201115215541.4526-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4 v3] avcodec/cbs_av1: add an option to select an operating point 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" This implements the function drop_obu() as defined in Setion 6.2.1 from the spec. In a reading only scenario, units that belong to an operating point the caller doesn't want should not be parsed. Signed-off-by: James Almer --- libavcodec/cbs_av1.c | 30 +++++++++++++++++++++++++++++- libavcodec/cbs_av1.h | 5 +++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index 9badfe31e4..81662114a1 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -17,6 +17,7 @@ */ #include "libavutil/avassert.h" +#include "libavutil/opt.h" #include "libavutil/pixfmt.h" #include "cbs.h" @@ -883,7 +884,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, int in_spatial_layer = (priv->operating_point_idc >> (priv->spatial_id + 8)) & 1; if (!in_temporal_layer || !in_spatial_layer) { - // Decoding will drop this OBU at this operating point. + return AVERROR(EAGAIN); // drop_obu() } } } @@ -896,6 +897,18 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, if (err < 0) return err; + if (priv->operating_point >= 0) { + AV1RawSequenceHeader *sequence_header = &obu->obu.sequence_header; + + if (priv->operating_point > sequence_header->operating_points_cnt_minus_1) { + av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid Operating Point %d requested. " + "Must not be higher than %u.\n", + priv->operating_point, sequence_header->operating_points_cnt_minus_1); + return AVERROR(EINVAL); + } + priv->operating_point_idc = sequence_header->operating_point_idc[priv->operating_point]; + } + av_buffer_unref(&priv->sequence_header_ref); priv->sequence_header = NULL; @@ -1253,9 +1266,24 @@ static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = { CBS_UNIT_TYPE_END_OF_LIST }; +#define OFFSET(x) offsetof(CodedBitstreamAV1Context, x) +static const AVOption cbs_av1_options[] = { + { "operating_point", "Set operating point to select layers to parse from a scalable bitstream", + OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, AV1_MAX_OPERATING_POINTS - 1, 0 }, + { NULL } +}; + +static const AVClass cbs_av1_class = { + .class_name = "cbs_av1", + .item_name = av_default_item_name, + .option = cbs_av1_options, + .version = LIBAVUTIL_VERSION_INT, +}; + const CodedBitstreamType ff_cbs_type_av1 = { .codec_id = AV_CODEC_ID_AV1, + .priv_class = &cbs_av1_class, .priv_data_size = sizeof(CodedBitstreamAV1Context), .unit_types = cbs_av1_unit_types, diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h index 386774750a..e4e0a8ba40 100644 --- a/libavcodec/cbs_av1.h +++ b/libavcodec/cbs_av1.h @@ -421,6 +421,8 @@ typedef struct AV1ReferenceFrameState { } AV1ReferenceFrameState; typedef struct CodedBitstreamAV1Context { + const AVClass *class; + AV1RawSequenceHeader *sequence_header; AVBufferRef *sequence_header_ref; @@ -449,6 +451,9 @@ typedef struct CodedBitstreamAV1Context { int tile_num; AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES]; + + // AVOptions + int operating_point; } CodedBitstreamAV1Context; From patchwork Sun Nov 15 21:55:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 23657 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 85CAF44ACB9 for ; Sun, 15 Nov 2020 23:56:21 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6C1C368B83F; Sun, 15 Nov 2020 23:56:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f193.google.com (mail-qt1-f193.google.com [209.85.160.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 069416881EE for ; Sun, 15 Nov 2020 23:56:13 +0200 (EET) Received: by mail-qt1-f193.google.com with SMTP id i12so11402123qtj.0 for ; Sun, 15 Nov 2020 13:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=VbrXaaEeyek8Ab8f/pNJFa6bHt1Y4d14WNXGX10FyK8=; b=Xn/KM9VKViE/ebPdBkXhb0VPUfxmZRuMPcpj2nYTxqnmJqvRMoG+bNMboGR8M0FTqe YzS/MAzuV6KvQkWiYL1uDZdXKvrssVAhwNNdsG55urXfB1vQxPYxlkD+196uVedLemzB gfye9LPXsd5B7xNQU4/o/qdyZ1DLlmCMnEvbi2PLUMaqbSd2bdChkDsTse9yByzbbM7G 9+EKDSsjtEf+jh1BT9kD6ZBScZKbATRTWUwhz/wHP8o6+c1J3fx19MIFal6gFRg8yOyx wh7yADytNkzQOL6w/C98NbPBAd36sy9gBAEs8WYa7ykXcvh2FzsTi2+oj33ArvAgdBC5 Lttw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VbrXaaEeyek8Ab8f/pNJFa6bHt1Y4d14WNXGX10FyK8=; b=OuMny+VVMgCaNMDHSTQZDQ9LtZXtGOxTeLIAodTFktTFag5U5V74WDBBZzSa4DJKNg 42Qc9d66fDEq1ta02g4cC3YlXREypsRTWR1f0hb/Zsnd+yA3i39odS4R26WncKn6nq9D lrJq9maTkQk2NqOqoOcqLFBej8BVXFluWtKG7qjfzjckzI3nf5uMe94scEtxpPuo4mfl N8b0uekmsGTdU9XnrgVazX+Skn/0ChqdJYNNUp9+5hQX6FBB+IdqQPCAM0eyOaVU4INz wbfNCcchD/4HoS7LeUotDYae2vKXtrJcSVTzpmVa0WsDwTEm0JwCoKPuT02YFxxFT5kU SHyA== X-Gm-Message-State: AOAM533o9TNK0smMoQQCwDKJf/QO7pagVfx0b3S2tZC4u+egzvqjy7sR sxviFvLPgTf3pg2DbSyEDKyEyZjPcOg= X-Google-Smtp-Source: ABdhPJw4x7y7HamS4qYcO7SqKvL2bWgrmRYRLQjTa6fYtUzlT2PJNLThUKQaIhd0Q3MbolNKU+NLqQ== X-Received: by 2002:a05:622a:2c7:: with SMTP id a7mr11387709qtx.174.1605477371167; Sun, 15 Nov 2020 13:56:11 -0800 (PST) Received: from localhost.localdomain ([181.23.74.184]) by smtp.gmail.com with ESMTPSA id z133sm6833136qka.20.2020.11.15.13.56.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Nov 2020 13:56:10 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 15 Nov 2020 18:55:41 -0300 Message-Id: <20201115215541.4526-4-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201115215541.4526-1-jamrial@gmail.com> References: <20201115215541.4526-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4 v3] avcodec/av1dec: add an option to select an operating point 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" Signed-off-by: James Almer --- doc/decoders.texi | 13 +++++++++++++ libavcodec/av1dec.c | 30 ++++++++++++++++++++++++++++++ libavcodec/av1dec.h | 4 ++++ 3 files changed, 47 insertions(+) diff --git a/doc/decoders.texi b/doc/decoders.texi index bfab562fb2..27c6ba4a5d 100644 --- a/doc/decoders.texi +++ b/doc/decoders.texi @@ -25,6 +25,19 @@ enabled decoders. A description of some of the currently available video decoders follows. +@section av1 + +AOMedia Video 1 (AV1) decoder. + +@subsection Options + +@table @option + +@item operating_point +Select an operating point of a scalable AV1 bitstream (0 - 31). Default is 0. + +@end table + @section rawvideo Raw video decoder. diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index c1967f03bd..b7ee307159 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -19,6 +19,7 @@ */ #include "libavutil/pixdesc.h" +#include "libavutil/opt.h" #include "avcodec.h" #include "av1dec.h" #include "bytestream.h" @@ -615,6 +616,8 @@ static av_cold int av1_decode_init(AVCodecContext *avctx) if (ret < 0) return ret; + av_opt_set_int(s->cbc->priv_data, "operating_point", s->operating_point, 0); + if (avctx->extradata && avctx->extradata_size) { ret = ff_cbs_read(s->cbc, &s->current_obu, avctx->extradata, avctx->extradata_size); @@ -704,6 +707,11 @@ static int set_output_frame(AVCodecContext *avctx, AVFrame *frame, const AVFrame *srcframe = s->cur_frame.tf.f; int ret; + // TODO: all layers + if (s->operating_point_idc && + av_log2(s->operating_point_idc >> 8) > s->cur_frame.spatial_id) + return 0; + ret = av_frame_ref(frame, srcframe); if (ret < 0) return ret; @@ -809,6 +817,8 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame, goto end; } + s->operating_point_idc = s->raw_seq->operating_point_idc[s->operating_point]; + if (s->pix_fmt == AV_PIX_FMT_NONE) { ret = get_pixel_format(avctx); if (ret < 0) { @@ -888,6 +898,9 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame, s->cur_frame.spatial_id = header->spatial_id; s->cur_frame.temporal_id = header->temporal_id; + s->cur_frame.spatial_id = header->spatial_id; + s->cur_frame.temporal_id = header->temporal_id; + if (avctx->hwaccel) { ret = avctx->hwaccel->start_frame(avctx, unit->data, unit->data_size); @@ -979,12 +992,28 @@ static void av1_decode_flush(AVCodecContext *avctx) av1_frame_unref(avctx, &s->ref[i]); av1_frame_unref(avctx, &s->cur_frame); + s->operating_point_idc = 0; s->raw_frame_header = NULL; s->raw_seq = NULL; ff_cbs_flush(s->cbc); } +#define OFFSET(x) offsetof(AV1DecContext, x) +#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM +static const AVOption av1_options[] = { + { "operating_point", "Select an operating point of the scalable bitstream", + OFFSET(operating_point), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, AV1_MAX_OPERATING_POINTS - 1, VD }, + { NULL } +}; + +static const AVClass av1_class = { + .class_name = "AV1 decoder", + .item_name = av_default_item_name, + .option = av1_options, + .version = LIBAVUTIL_VERSION_INT, +}; + AVCodec ff_av1_decoder = { .name = "av1", .long_name = NULL_IF_CONFIG_SMALL("Alliance for Open Media AV1"), @@ -1000,6 +1029,7 @@ AVCodec ff_av1_decoder = { FF_CODEC_CAP_SETS_PKT_DTS, .flush = av1_decode_flush, .profiles = NULL_IF_CONFIG_SMALL(ff_av1_profiles), + .priv_class = &av1_class, .hw_configs = (const AVCodecHWConfigInternal * []) { #if CONFIG_AV1_DXVA2_HWACCEL HWACCEL_DXVA2(av1), diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h index 4b218f64bb..70414c9ca3 100644 --- a/libavcodec/av1dec.h +++ b/libavcodec/av1dec.h @@ -74,9 +74,13 @@ typedef struct AV1DecContext { uint16_t tg_start; uint16_t tg_end; + int operating_point_idc; + AV1Frame ref[AV1_NUM_REF_FRAMES]; AV1Frame cur_frame; + // AVOptions + int operating_point; } AV1DecContext; #endif /* AVCODEC_AV1DEC_H */