From patchwork Fri Oct 2 18:26:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 22694 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 1F33344B263 for ; Fri, 2 Oct 2020 21:26:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E8806689CFF; Fri, 2 Oct 2020 21:26:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0F089680812 for ; Fri, 2 Oct 2020 21:26:27 +0300 (EEST) Received: by mail-qt1-f176.google.com with SMTP id d1so2156096qtr.6 for ; Fri, 02 Oct 2020 11:26:26 -0700 (PDT) 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=rDKjC8911iIWxq22wRE/EidKyoiV7/12Dd/eGMskQ/E=; b=A7zZpQ1XY+HqZhkMeDk37KdOCVtL2Nn713ig4ZMFMC83WDIe9cQuHXTCI0HViaXWaQ 0HQ/D8kys/SxPJJefXNp63+WcJ6lOWhFTfAzaqlxrNhf4gibEtX+NaDV37KXKSnJJcb0 CaPtOFECygeFX5/oyptsQ342m5ufgA8fg5oKcu1CUX/yWkCkf/CCTp4KsA3ZJQ46pC6J Zvj6KHaGhU2+M9OlWAdfFLLlKezJgZDe8h83b6KG79aHx5LkrSfBnwj52jmEirmhGxKT RrFE1hzQk8DsGFfXON9F9aJ6zude5QIsgs8ErsC243cFuHI9ZilfVshQUCHbLEc56i9K KKzQ== 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=rDKjC8911iIWxq22wRE/EidKyoiV7/12Dd/eGMskQ/E=; b=G7egH1YhZD0UJnaRz/S/HgO1zDXsr+UGXd7hvnrs21fhtu0JN5Nyhy4OcCSgcF46kO FeQ+3Qr81+r1undUkhDoBtZNmuK63h9xSx0Knp2PKpOgEXGU9k1aOnNrDhIckkoZwQmu 7XfX/jtZ5cSNIlHM+XMu4W9LBMCLjKCDaxT0uJiHLFY+abZ3Z/TimybjyA0AKM4nbJdp b6xu9iu7fZza6BlQWWwrQKB4wurRQxBbn2L2l835ZVe3w5uvoV+v3JDbgnkEt61ixYYc 82DuPBpUliAmLaq1YuculPvInbjJos9zO5YnvJZsJxoMJvUEb0uWy5LbL6Semwia6td1 eSfw== X-Gm-Message-State: AOAM533TR7hBfItWnIuZC1CdqmKK8OHJJ9By1NZOfqHu722cSzaywdAj 0g29aTDDhXWmRFKnV7sOc2NJ+PCgxpY= X-Google-Smtp-Source: ABdhPJwowEbW6u6iTJcwjzbNvoe3zujEVw29LxM4quVdPldPw10SFnLLK679T0YBHnRvnMrZYsiPeA== X-Received: by 2002:ac8:5d4d:: with SMTP id g13mr3665350qtx.348.1601663184970; Fri, 02 Oct 2020 11:26:24 -0700 (PDT) Received: from localhost.localdomain ([181.23.78.153]) by smtp.gmail.com with ESMTPSA id h26sm1653222qtm.9.2020.10.02.11.26.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 11:26:24 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Oct 2020 15:26:10 -0300 Message-Id: <20201002182610.61516-1-jamrial@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4 v2] 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 65cf45fcfa..753e089e8f 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -18,6 +18,7 @@ #include "libavutil/avassert.h" #include "libavutil/pixfmt.h" +#include "libavutil/opt.h" #include "cbs.h" #include "cbs_internal.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; @@ -1251,9 +1264,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 7a0c08c596..27b44d68ff 100644 --- a/libavcodec/cbs_av1.h +++ b/libavcodec/cbs_av1.h @@ -416,6 +416,8 @@ typedef struct AV1ReferenceFrameState { } AV1ReferenceFrameState; typedef struct CodedBitstreamAV1Context { + const AVClass *class; + AV1RawSequenceHeader *sequence_header; AVBufferRef *sequence_header_ref; @@ -443,6 +445,9 @@ typedef struct CodedBitstreamAV1Context { int tile_rows; AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES]; + + // AVOptions + int operating_point; } CodedBitstreamAV1Context;