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 */