From patchwork Sun Sep 20 17:24: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: 22541 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 099BA44B700 for ; Sun, 20 Sep 2020 20:25:15 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D4DF468B9D8; Sun, 20 Sep 2020 20:25:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B229568B779 for ; Sun, 20 Sep 2020 20:25:07 +0300 (EEST) Received: by mail-qk1-f177.google.com with SMTP id 16so12589768qkf.4 for ; Sun, 20 Sep 2020 10:25:07 -0700 (PDT) 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=DLMc7e+Pue1iF3IGap0iPSMZD5YzqAOWMY/yDUnAYno=; b=nzxiuDCcRdcNUogm4bvQvZDI0v6/sYmOTROaGW8gLBtP3UmT3atT4GbFGKLiQqWtEm noylnq8zB7N0sMU6sf/4UfcQU+zksAoelUcWVaaN0H2LsGT5ZwJzFB5Mnhk8kMqhxtzl 6h7djtSLMEmimZVHvAeokFP7E9mt+zJBRDwsOVu2TVAryclR8txsNep6QxIQth0fHzym CnPm3L/3a17kWQv4B2zbERw9Of7U6bKOJajVGOrC+e9PC/1y8t2QF3HU7qmWZp+oCV5Y ZmDuOSF7yFiQq0NcEcQbu9WhRt0m2pmcLk44J2p4wD1Im9N9ED2hUGdoFwQ/Yxuc5UyA bqAg== 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=DLMc7e+Pue1iF3IGap0iPSMZD5YzqAOWMY/yDUnAYno=; b=TwDnmp6Ik9IwA3EYYs4NNFl2Vvmy3+I1PTkBfBjQNkulvuGV+v7b1L7AYhZRbedSh+ I+OktlhqUmDCmNq5Du/KnMrkkh+mBBBsiKpFrPRcstNID9TGrWSyB4yhFqI9s05Rek1j rcmukZYLHlGZt8iWO4hCAIFOm2PIOCyKrtdYOVrO7svPPLNdLhnrIhSxYWOrFzzPqn5T X6kMtdpvT2w9J/zEYnad3tOGNz4S6KQLzNtD6sDvj7YwLSoQpvKG+RJ4TibfeMFfvl7P d7k660J2z2lvkS1du9iYGg1jM50r6ONSVDRLVb+44SI7biGdCeYEsNPTf6faTm3B8Aja hzVA== X-Gm-Message-State: AOAM532l5HvpdB4acW+PHUO2xwGktRp7tRxvCQ8tGRBM2Bwp/QjMRoHd nTOAgVdZmNP6mfU9o8e+JVbce2jSbqh8EQ== X-Google-Smtp-Source: ABdhPJw4HrT3aI1r5V5H7qFgqTF/1w6b9Us5NTxBgyTg71ISg0DL+Jwdga3uI0gWoF6Wo599QCyjgQ== X-Received: by 2002:a05:620a:5f4:: with SMTP id z20mr43045815qkg.260.1600622705741; Sun, 20 Sep 2020 10:25:05 -0700 (PDT) Received: from localhost.localdomain ([191.83.208.67]) by smtp.gmail.com with ESMTPSA id g19sm6970762qka.84.2020.09.20.10.25.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 10:25:05 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Sep 2020 14:24:40 -0300 Message-Id: <20200920172443.4763-1-jamrial@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] 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 7c1aa005c2..e73e18f398 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; @@ -123,6 +128,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 d991e1eedf..10530af69f 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 Sep 20 17:24: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: 22542 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 0B18344B700 for ; Sun, 20 Sep 2020 20:25:16 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E41DA68B9D9; Sun, 20 Sep 2020 20:25:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D68C968B779 for ; Sun, 20 Sep 2020 20:25:08 +0300 (EEST) Received: by mail-qk1-f195.google.com with SMTP id g72so12562167qke.8 for ; Sun, 20 Sep 2020 10:25:08 -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=HcNMiR5KuuulGocJC/YTQpLGAYJQ03V/zcZKyusOopw=; b=Y6J1deHNzgbISLpI+BkpdUEAX8140SaY+aqMDZRTHpj8vg9gEF7/vRD0uBAhWGruXZ knc5xO7NJUXvYovinX7BDhSqdWL3s+KN4tZXnUtjabUxuFkaZEzORXstFJpcQqxACPYI F6G5/Z1l06cFeYYEDtThIelWPc1tb4uRwxJAfVIrNtHKq+thC9QvtZrzC5D3UUje6sel YBxViGgerg77JLGraJH9aeY8tl3AP6OOq9K6OCoxxF/3XdQGbvHb0655IogMDIM4viLs +O8ZwylXc19UMkgPVHugdAqWZr1d2sDtgRkte2DQ7kY0BJVggwxNrlCqUp4AQHDeVoYj hpQw== 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=HcNMiR5KuuulGocJC/YTQpLGAYJQ03V/zcZKyusOopw=; b=ikqh/zD4P+XQgUNkYFix7hV4Bp7b9qn9/ZHeQdwbjUQzCLH9MbmdvPXlt5qPq9Ni0+ H5rEvWzLlms8zKS4RQz16fOkJMDkuXPYGlW3MOZjGz3f+F51MjncnebnM4KXnRsOnMLg 1Gw97b7biA8JV2c0wpFn9nKTOImdj/k+Ycx3GN9qil96bICeLR4zTcT5XJ/V7X74z8TY nXxu7ty3LY/znYf0v4bH8fa6i6tpHZJF5TA2wKd45q02DmcjuC/47kxje+ZOVaYA3GDX r3R1x0uZeFHnEJmH0IcX11W5CWbxl4AAglBSECvrpEfPigVNmAPQaYQUeoreYl0JXtbs PvSA== X-Gm-Message-State: AOAM5325v1ItAnp5fLGmnFCyCXdjrclf4g744+Diu54IEFCU+Mprshea RkIu+sUfUtry9tx5EmK3/SQC0DXoXuwI8Q== X-Google-Smtp-Source: ABdhPJxPWh6qQuqoi9KxQof6mQU4vN6vywPd8wdOqQFTvCulB22L96sceeLGQzdP9vVTPASK+4DrGw== X-Received: by 2002:a37:4c15:: with SMTP id z21mr41600251qka.194.1600622707300; Sun, 20 Sep 2020 10:25:07 -0700 (PDT) Received: from localhost.localdomain ([191.83.208.67]) by smtp.gmail.com with ESMTPSA id g19sm6970762qka.84.2020.09.20.10.25.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 10:25:06 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Sep 2020 14:24:41 -0300 Message-Id: <20200920172443.4763-2-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 2/4] 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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index e73e18f398..363385b6f3 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -196,6 +196,11 @@ 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); + ff_cbs_delete_unit(frag, i--); } 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 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); From patchwork Sun Sep 20 17:24:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 22544 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 19E5244B700 for ; Sun, 20 Sep 2020 20:25:20 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 096BA68B9DB; Sun, 20 Sep 2020 20:25:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A5CB468B779 for ; Sun, 20 Sep 2020 20:25:12 +0300 (EEST) Received: by mail-qk1-f175.google.com with SMTP id t138so12618959qka.0 for ; Sun, 20 Sep 2020 10:25:12 -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=40qHjJta7T7E/Y6XrQyFVT0nzYYvMy2k6oCPVt56NbU=; b=GgY8VKYjUiN9F+ZA4tnkBYc+xcHzrWdjmVIhRbNe1MAg9lES3kc03e2RBY17Srt8JA F/sjTNZ8sgvdfYozyKRpp4a10ghbezLa85hseuXaTDAK5JBjHrnc1GNKTznavNlEes55 4hNhS/iL5EtolG7jLuhw0WTkYTjq/5fDNULKp1NqZQ8DfRIKEQ6LuD3UPNIyS+3gg8va 6OmzHp+lXoAVLneAnz0XMeCKiIcPZibAu1jmdiCzWp8BW9HpnzIWQJDWlwa9QxeDj717 8WidMbXtt32JY1beCe59zsStR15S5U63n5pSOB5SidJmdWdhmc0ih9RokGi31EyHtwus TqgA== 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=40qHjJta7T7E/Y6XrQyFVT0nzYYvMy2k6oCPVt56NbU=; b=B8Cjw2BVx2bjjWVE1R6JpQoqSZiFthKTfgiPSyfhVkhUW8IbP/NHKjY23L9jodkkyl G0OOn6ebuE+Mz717bxPAA7UABugwzCXP4PsUjUY0Dr12IgeUYl4C5bkMS8hr5w/FuBC0 W6/5CHUn+e9ylJHGRSFMqnTk9C2QYEwMLqMgUV8pCcYjg0JJ5GI7R4jalJBcmJbxoUfo 5zp2YKhlwWwCcehSqQ638gXYPNbtQg/zMUXOiNSgS9S37cLkBvxGjgtTAnRYCvNgZeLp vDKG03ogkFWlqG2WRTEdt3N0keTTe9Mz0pCuzunby5zC5+9OsaHV7p+QK7Jl4BNzKtys uvLQ== X-Gm-Message-State: AOAM5305kGdViB/Ti6YNeTKARGs03tnOrhC6Rb7Wag9lDh4SANA3q4n7 GI5tEcu5iyTzIRY0hq8jyqy+30yqT0DrtA== X-Google-Smtp-Source: ABdhPJzaxhESW3rbGxLNd+YqrEGM4zI869+cixGEIIb+GdRMr9a3XewhJGfe5nTymnMtxjYoFzS90A== X-Received: by 2002:a37:a712:: with SMTP id q18mr39575041qke.428.1600622710762; Sun, 20 Sep 2020 10:25:10 -0700 (PDT) Received: from localhost.localdomain ([191.83.208.67]) by smtp.gmail.com with ESMTPSA id g19sm6970762qka.84.2020.09.20.10.25.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Sep 2020 10:25:10 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Sun, 20 Sep 2020 14:24:43 -0300 Message-Id: <20200920172443.4763-4-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 4/4] 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 --- libavcodec/av1dec.c | 36 ++++++++++++++++++++++++++++++++++++ libavcodec/av1dec.h | 7 +++++++ 2 files changed, 43 insertions(+) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 0bb04a3e44..178fbdc2f0 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" @@ -343,6 +344,7 @@ static void av1_frame_unref(AVCodecContext *avctx, AV1Frame *f) ff_thread_release_buffer(avctx, &f->tf); av_buffer_unref(&f->hwaccel_priv_buf); f->hwaccel_picture_private = NULL; + f->spatial_id = f->temporal_id = 0; } static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *src) @@ -360,6 +362,8 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; } + dst->spatial_id = src->spatial_id; + dst->temporal_id = src->temporal_id; dst->loop_filter_delta_enabled = src->loop_filter_delta_enabled; memcpy(dst->loop_filter_ref_deltas, src->loop_filter_ref_deltas, @@ -495,6 +499,8 @@ static av_cold int av1_decode_init(AVCodecContext *avctx) if (ret < 0) return ret; + av_opt_set_int(s->cbc->priv_data, "oppoint", s->operating_point, 0); + if (avctx->extradata && avctx->extradata_size) { ret = ff_cbs_read(s->cbc, &s->current_obu, avctx->extradata, avctx->extradata_size); @@ -578,6 +584,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; @@ -660,6 +671,8 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame, for (int i = 0; i < s->current_obu.nb_units; i++) { CodedBitstreamUnit *unit = &s->current_obu.units[i]; AV1RawOBU *obu = unit->content; + const AV1RawOBUHeader *header = &obu->header; + int op = 0; av_log(avctx, AV_LOG_DEBUG, "Obu idx:%d, obu type:%d.\n", i, unit->type); switch (unit->type) { @@ -679,6 +692,10 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame, goto end; } + if (s->operating_point <= s->raw_seq->operating_points_cnt_minus_1) + op = s->operating_point; + s->operating_point_idc = s->raw_seq->operating_point_idc[op]; + if (s->pix_fmt == AV_PIX_FMT_NONE) { ret = get_pixel_format(avctx); if (ret < 0) { @@ -753,6 +770,9 @@ static int av1_decode_frame(AVCodecContext *avctx, void *frame, goto end; } + 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); @@ -846,6 +866,21 @@ static void av1_decode_flush(AVCodecContext *avctx) s->raw_seq = NULL; } +#define OFFSET(x) offsetof(AV1DecContext, x) +#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM +static const AVOption av1_options[] = { + { "oppoint", "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"), @@ -861,6 +896,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 * []) { NULL }, diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h index 3604870299..67ae4c2c9f 100644 --- a/libavcodec/av1dec.h +++ b/libavcodec/av1dec.h @@ -36,6 +36,9 @@ typedef struct AV1Frame { AVBufferRef *hwaccel_priv_buf; void *hwaccel_picture_private; + int temporal_id; + int spatial_id; + uint8_t loop_filter_delta_enabled; int8_t loop_filter_ref_deltas[AV1_NUM_REF_FRAMES]; int8_t loop_filter_mode_deltas[2]; @@ -67,9 +70,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 */