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;