From patchwork Sun Sep 20 17:24:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 22543 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 4055844B700 for ; Sun, 20 Sep 2020 20:25:19 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 25A1C68BA18; Sun, 20 Sep 2020 20:25:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E701768B9F2 for ; Sun, 20 Sep 2020 20:25:10 +0300 (EEST) Received: by mail-qk1-f173.google.com with SMTP id d20so12601396qka.5 for ; Sun, 20 Sep 2020 10:25:10 -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=vhNvevZwtbam0999cIAy6EhAjaWeFJQv3TX6jw4vDRA=; b=tyXgfE5o0tIJfWwfNlnPYjbDJ6IcFCrUeRE0Ai+8cW3y6fuxnQpUYHmaTRRYciIyut BV+mpRq6sb34PK5hZjPCbzA4zTFRShxonqIxq3XHAMK7xN81AQDIg592tAII9JzVMHck UeVoHtwEZFSyBfiYjSz1r9pMedJTiauDn675z7mwigM/ffgUMklw1R0IlVWK5/uXHwRU pXtl7XB+OoEei64Vo49VsZ5C80cZ70Ae87sMktek2Z6Q0Pgmj3wf18Jl3kX0cBs4yT0v RoI9jVhK2RlR8IF0DP83LMqUGHCe+f3hIYUeyNxYDAL11rXZ6JNmQQbbX+3ssLC7yrqG 7hlw== 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=vhNvevZwtbam0999cIAy6EhAjaWeFJQv3TX6jw4vDRA=; b=JS+D8VBohG7KytbACT/hVKGR6Qe8jcQUerPE/xdp817uFGVhGTuU5h9SwTuVk2wTSR nlB4dYi1Y19vZNi05mJdG4E9UxFHq1B4QzuyONhGja51Eb2fIMi097OYqp7x4VFv3O/B Y313+qVMH3kf1qD7tpfXfSWWiE5VEzwm4poVgCReSrULwojWXOZrY2cLsyEzTUUpuxXX a6TjLKsqY9FOlXxWh8VY0hwDppj6LlX6H1czOTumwHadomu/gRUYvPoxhOpHK9zOUxpF nCdN02d8Vpsosayu5bbTO87Z77hwHgBbo+OQS1k+gGkwlS37MrBu37FXX/OZEuxebIgY sttA== X-Gm-Message-State: AOAM532SutHDtBZu2S9njP3R6x5U161mtbSjUBPQr4zJo5lekIN4tTFu fiYdss4VyCl5cwZ1JXrH6sbM6rGUomLWNw== X-Google-Smtp-Source: ABdhPJyXu+LMWzdxuXyy7FeBoc1ZHlqi1wNV76EfUozo5FR149hlDamYje7IjGBk78TYKipcR0LoBg== X-Received: by 2002:a05:620a:21d1:: with SMTP id h17mr41442889qka.466.1600622709330; Sun, 20 Sep 2020 10:25:09 -0700 (PDT) Received: from localhost.localdomain ([191.83.208.67]) by smtp.gmail.com with ESMTPSA id g19sm6970762qka.84.2020.09.20.10.25.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 10:25:08 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Sep 2020 14:24:42 -0300 Message-Id: <20200920172443.4763-3-jamrial@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200920172443.4763-1-jamrial@gmail.com> References: <20200920172443.4763-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 3/4] 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 | 18 +++++++++++++++++- libavcodec/cbs_av1.h | 5 +++++ libavcodec/cbs_av1_syntax_template.c | 7 +++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index dcf6c140ae..edacc29ca8 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() } } } @@ -1238,10 +1239,25 @@ 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[] = { + { "oppoint", "Select an operating point of the 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_data_size = sizeof(CodedBitstreamAV1Context), + .priv_class = &cbs_av1_class, .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; diff --git a/libavcodec/cbs_av1_syntax_template.c b/libavcodec/cbs_av1_syntax_template.c index bcaa334134..34d09fab68 100644 --- a/libavcodec/cbs_av1_syntax_template.c +++ b/libavcodec/cbs_av1_syntax_template.c @@ -186,6 +186,7 @@ static int FUNC(decoder_model_info)(CodedBitstreamContext *ctx, RWContext *rw, static int FUNC(sequence_header_obu)(CodedBitstreamContext *ctx, RWContext *rw, AV1RawSequenceHeader *current) { + CodedBitstreamAV1Context *priv = ctx->priv_data; int i, err; HEADER("Sequence Header"); @@ -253,6 +254,12 @@ static int FUNC(sequence_header_obu)(CodedBitstreamContext *ctx, RWContext *rw, } } } + if (priv->operating_point >= 0) { + int op_pt = 0; + if (priv->operating_point <= current->operating_points_cnt_minus_1) + op_pt = priv->operating_point; + priv->operating_point_idc = current->operating_point_idc[op_pt]; + } fb(4, frame_width_bits_minus_1); fb(4, frame_height_bits_minus_1);