From patchwork Fri Jul 7 14:05:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 42505 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp7318214pzh; Fri, 7 Jul 2023 07:06:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlFXeLnW5I9SbV5FXrxDVeAPUr+8XEzJ03hLOHa9zw3HuGrks3yMmqgJJq1Njcuo5YMfwZa8 X-Received: by 2002:a05:6512:3ba6:b0:4f8:7772:3dfd with SMTP id g38-20020a0565123ba600b004f877723dfdmr5033224lfv.11.1688738789021; Fri, 07 Jul 2023 07:06:29 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ca9-20020a170906a3c900b0099364d9f0e3si648893ejb.562.2023.07.07.07.06.28; Fri, 07 Jul 2023 07:06:28 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=EcSI3QUP; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5BE5768C7C3; Fri, 7 Jul 2023 17:06:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01olkn2093.outbound.protection.outlook.com [40.92.53.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D1F6B68C7C3 for ; Fri, 7 Jul 2023 17:06:03 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oMcyeeoqBrhpdjYn5CEmFr4o6JrxT5bDVplnPPANS5ZghOSiH7Z0gLNdIxyt+6cC+vuaHr10gUEoPrK/RIWEJf86Ibg8+adWki2dVbl+n7+nWKdGKaOckfgLRmTGFIBO2Aktc73vEcQ8GIEdQD9nQbVeg6p7QSDZ7h8IeAsVEHjQe1OjnM9XGGc7u9EZuWUBCVg40zhwoacTpkwFdCOTDNsiTQeXYX7OmwM9sM8M8hcCa1FzNrdZ3CFpR2KfSx5yprd8500KBwgRBIDfPbaQff2qTV+7M6QQAHySDRPOEGYQYX1zWwiPWUoaE/DP14i+g6yRrXT9f0gWA5YvTSwePg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NiypXsGkwRlQK+LHsbKvvLSbfIKeVlToU7CLhDNM1zM=; b=fU+5PR61WUBJBd+hhdpPE2MRAmb5JUHEcsaOl1TDPI59TaDdxc1b8nkg+F/S4rS5EnCDBHxmdrwvhV3cW17ywMXLQDObG18zLdSdxjx4ExOQmTAa6tRwM9k7pHh+kOisNzUCbVEvIskCSQ0JymfwzGT6i0Gd4L8j6P8O9bAsyYNkqGVZPlfY4SvyGl2MbQaqzBF1qRye0iYvkDFv7qqVyF1pNSv+Iq6SmwA4qfrN9kcsSng9EN1R6uR5qR1QbetTk+mkwHcyKidIJpVeXYU1pG2FALIUuRf4d66WzyepG4oW2fxDOBJmKr9BES1BGTBKJBUiSHpzYm9MH273heuAVw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NiypXsGkwRlQK+LHsbKvvLSbfIKeVlToU7CLhDNM1zM=; b=EcSI3QUPeLLOMPcQVJ2ssQRlr4zWXEuhuYwzzZL/ozYbYBWhOLg+6NpL6n+aG9uu7svc9UjAMhQnYhmdIxYJqmAe8lyEwadmFl0kN+8yccw+jhIb1HuAyIO9eykmX5Pw9U8+noHNZXYO6f1Vh1+sYV2RCOXW/2lW4bTq1eDnFFcYJafzaFHPSM5tdr64OrO9B0R1XaKkDOTE9NRvlcKxf/eGEnqCj47brh7KUPOKUzCoEvemc10Ojpk+8lFGamp0sfzTOKjqGrKy1SjA+Sy0zI7hw/WdWB5rYyWL8E1cCc83htXfe5H+971TXJzrrPk3rz2HdDyJT39dNFwRQejsNw== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by KL1PR0601MB5445.apcprd06.prod.outlook.com (2603:1096:820:c0::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.25; Fri, 7 Jul 2023 14:05:51 +0000 Received: from TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::7d80:1294:fd54:a7f]) by TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::7d80:1294:fd54:a7f%7]) with mapi id 15.20.6565.016; Fri, 7 Jul 2023 14:05:51 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Fri, 7 Jul 2023 22:05:28 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230707140540.10279-1-nuomi2021@gmail.com> References: <20230707140540.10279-1-nuomi2021@gmail.com> X-TMN: [tRxMTo/MURRdvqmpB6VLYFNXvJdOoUkw] X-ClientProxiedBy: TYCP286CA0251.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:456::20) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20230707140540.10279-3-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|KL1PR0601MB5445:EE_ X-MS-Office365-Filtering-Correlation-Id: f8ee6f8c-70c3-460f-d29e-08db7ef345a9 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OickQ17I3vR3gzJg8Q2TxaV2Y6IYCjOgeBaATZPVceSWlikQ6hmVdByeasZsz/jEHSa97xKbSaaRu3TBs3Bhosdn95AIMcvQDVnEMUhoB91hIb9jKUP7ViHvfy3Pw4A2ojYkP1tHxBNCQpOP/9ZT7KNHYY9JtSD/69jEzQofdojrCvsPxbxB3wbmdROTVqDh/Pu66ddzi6/9ATvpib8Xik2E+RaGAVa/4rL3jrH3/FMXzLFcKYH9YV2TaaPSLDXdjc0NaLIpQ1G0mE85LZLmpvPpUVPPvQihPsQVTwgQ3wdniirL8EH0aRh6ZKTra8/i0hB7XBhON/rE69XNL68IEtCAjOA3SN/ZteuXfLydzQxdsCN4wmCaZdBTOLuS0WDf8z2QMF7w3xkcqXr6qbQkKBhbmeHLCk3tr+r0MUyYO5Pb1Ayis8IzE2lqwznSQZgJlhb4BoxrC95WAv75NZoEo72Kv+3LOXWEf9Zy5vaTGLAqmUUePAI6ReWQATDtrMMfdUVUtDluI4TnLP2DzRJES9b0EWTC+/JPkJ88Q2QoEOeBsdG1MrcrHM7dgrvsMCj0P6vSTEdMJnKquCblYLT7L6o4Wcnd6BgZb7Y8Qp1syPhL/Nycl0KNGtEx3vDyJvTe X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: diRrS7+EqQWncrY/LLm27fSdyHUAoBe2RzT4AlJWwACLJrQlk87/c7OJ1QmkPWFFEwh87O9xbi5TFkbDuchV0Zv8k6sD7HAywvK0mmBha+b1BCITnBLweFAZnUXdu0ARoHxxn7LalEfLsiNIrVnvhPRdwrm9iwSlmHNMYamSB0tr500QZ1qRRfTF3km6z7VNrNQOKmfgDAFfIrElBsDizZIncH1hCYTZtVHWCTBnT5ayYqP7JqFeh/czFcbfP6JqSO0S1Lrw/L4Dg8u2uTCIM0csoOMD3mHfIQf106GPLYvZXyW7WlfmwBvxW37TVyICToCY8arvNe33t3TYFx7+lnz42Tik2esK9QzGMFRNDmlfQvz1RzsqZDsy00oWY0Tmj778VqwabtsCQ2v6evYEtyflt4sipVJJJ+a6g6NC49jWKEEDdlE+u/HYLvqnSWBHAKtdKTx51ZwIvNWxV/RbnUXi+WppvTEfzk3kgDgVw6vNZ7l4OZ1llfwyn52qJnG+wpquzHdtpVxh8sHgM0pGTCdK7fgDM0RAKoe+E0woibVoHPEOMDUcJMlDaX3qK1V0BlHHtz2TKV4jEQokrOee6fmNx2Ohl77JJ2AZT9GU7KZTGs0+U3mG9HhdQVDZc9oBw7bgjbMxBJfl71wEbGXpqs64ODiy8w+AWOTdOdT/yr/UMWk9FuD+bhcmine0oiNO767MNfRUYAEdZsaziadCC1f/coxjQm/UuSVq3KqoBNUSy/AiwK4x66nURHlcpvjVyiby+CYvi3ivI9WWZX/FL69zaQ4HyDo3lWajswysCFx+HHSMW6s3vSPpz0pcQCD2cAQBm/Dm24o8Le+aa0pAxcYgH3FKzZNFBgsmLw0QSfjRQZbkqZiOJdTSpATjLN84nDP/MjCNV/m7VEO8j6qPD79gInLF9977lxjsjnGGwfH8UgYqcYISOw+ppmTf8dnRzXM23WuEhA9ug6JCEI0nRXvkjFAhxgQYjuqzc3KGg13oNV7bXyltvcQkIO3DjEX+CVXMAfJlfjUfaW25QzyhcnxuIDMMeXh9HQ+GDQGWj/6gYcZ9TQxf4kytxsaCMI5DKlzkZBHMKSdXqX9qp4+FUhOfPWc+K4N1MMg/RIKLB6+guM1daXE6+YLleZft1lCnPOpC3moMyFw7T17z27MQm78CbxU/KSoT2dH00DFLnyRsfQaIeCugpqcBdYPhSZaNWqPG3k3YtNBkWr+jraeXA6/ku54iFM5pOnDNeOTZZ16dH1ocGZS8EHY2p3c095s9 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f8ee6f8c-70c3-460f-d29e-08db7ef345a9 X-MS-Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jul 2023 14:05:51.6395 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR0601MB5445 Subject: [FFmpeg-devel] [PATCH v2 02/14] vvcdec: add vvc decoder stub X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Nuo Mi Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: kvQs/tzVKt0D --- configure | 1 + libavcodec/allcodecs.c | 1 + libavcodec/vvc/Makefile | 3 +- libavcodec/vvc/vvcdec.c | 84 +++++++++++ libavcodec/vvc/vvcdec.h | 306 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 libavcodec/vvc/vvcdec.c create mode 100644 libavcodec/vvc/vvcdec.h diff --git a/configure b/configure index d6e78297fe..3d65b4305a 100755 --- a/configure +++ b/configure @@ -3025,6 +3025,7 @@ vp6f_decoder_select="vp6_decoder" vp7_decoder_select="h264pred videodsp vp8dsp" vp8_decoder_select="h264pred videodsp vp8dsp" vp9_decoder_select="videodsp vp9_parser vp9_superframe_split_bsf" +vvc_decoder_select="cabac golomb videodsp" wcmv_decoder_select="inflate_wrapper" webp_decoder_select="vp8_decoder exif" wmalossless_decoder_select="llauddsp" diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c index 8775d15a4f..f5ac324cd9 100644 --- a/libavcodec/allcodecs.c +++ b/libavcodec/allcodecs.c @@ -388,6 +388,7 @@ extern const FFCodec ff_vp9_rkmpp_decoder; extern const FFCodec ff_vp9_v4l2m2m_decoder; extern const FFCodec ff_vqa_decoder; extern const FFCodec ff_vqc_decoder; +extern const FFCodec ff_vvc_decoder; extern const FFCodec ff_wbmp_decoder; extern const FFCodec ff_wbmp_encoder; extern const FFCodec ff_webp_decoder; diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile index 16cdd04307..0e110206fa 100644 --- a/libavcodec/vvc/Makefile +++ b/libavcodec/vvc/Makefile @@ -1,4 +1,5 @@ clean:: $(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%) -OBJS-$(CONFIG_VVC_DECODER) += executor.o +OBJS-$(CONFIG_VVC_DECODER) += vvc/vvcdec.o \ + executor.o diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c new file mode 100644 index 0000000000..8d027af0b9 --- /dev/null +++ b/libavcodec/vvc/vvcdec.c @@ -0,0 +1,84 @@ +/* + * VVC video decoder + * + * Copyright (C) 2021 Nuo Mi + * Copyright (C) 2022 Xu Mu + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "config_components.h" + +#include "libavcodec/codec_internal.h" +#include "libavcodec/decode.h" +#include "libavcodec/golomb.h" +#include "libavcodec/profiles.h" +#include "libavcodec/vvc.h" + +#include "libavutil/cpu.h" + +#include "vvcdec.h" + +static int vvc_decode_frame(AVCodecContext *avctx, AVFrame *output, + int *got_output, AVPacket *avpkt) +{ + return avpkt->size; +} + +static void vvc_decode_flush(AVCodecContext *avctx) +{ +} + +static av_cold int vvc_decode_free(AVCodecContext *avctx) +{ + return 0; +} + +static av_cold int vvc_decode_init(AVCodecContext *avctx) +{ + return 0; +} + +#define OFFSET(x) offsetof(VVCContext, x) +#define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) + +static const AVOption options[] = { + { NULL }, +}; + +static const AVClass vvc_decoder_class = { + .class_name = "vvc decoder", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +const FFCodec ff_vvc_decoder = { + .p.name = "vvc", + .p.long_name = NULL_IF_CONFIG_SMALL("VVC (Versatile Video Coding)"), + .p.type = AVMEDIA_TYPE_VIDEO, + .p.id = AV_CODEC_ID_VVC, + .priv_data_size = sizeof(VVCContext), + .p.priv_class = &vvc_decoder_class, + .init = vvc_decode_init, + .close = vvc_decode_free, + FF_CODEC_DECODE_CB(vvc_decode_frame), + .flush = vvc_decode_flush, + .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS, + .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_INIT_CLEANUP | + FF_CODEC_CAP_AUTO_THREADS, + .p.profiles = NULL_IF_CONFIG_SMALL(ff_vvc_profiles), +}; diff --git a/libavcodec/vvc/vvcdec.h b/libavcodec/vvc/vvcdec.h new file mode 100644 index 0000000000..babc908f02 --- /dev/null +++ b/libavcodec/vvc/vvcdec.h @@ -0,0 +1,306 @@ +/* + * VVC video decoder + * + * Copyright (C) 2021 Nuo Mi + * Copyright (C) 2022 Xu Mu + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_VVCDEC_H +#define AVCODEC_VVCDEC_H + +#include "libavcodec/executor.h" +#include "libavcodec/h2645_parse.h" +#include "libavcodec/threadframe.h" +#include "libavcodec/videodsp.h" +#include "libavcodec/vvc.h" + + +#define LUMA 0 +#define CHROMA 1 +#define CB 1 +#define CR 2 +#define JCBCR 3 + +#define MAX_CTU_SIZE 128 + +#define MAX_CU_SIZE MAX_CTU_SIZE +#define MIN_CU_SIZE 4 +#define MIN_CU_LOG2 2 +#define MAX_CU_DEPTH 7 + +#define MIN_PU_SIZE 4 +#define MIN_PU_LOG2 2 + +#define MAX_TB_SIZE 64 +#define MIN_TU_LOG2 2 ///< MinTbLog2SizeY +#define MIN_TU_SIZE 4 +#define MAX_TUS_IN_CU 64 + +#define MAX_PARTS_IN_CTU ((MAX_CTU_SIZE >> MIN_CU_LOG2) * (MAX_CTU_SIZE >> MIN_CU_LOG2)) + +#define MAX_CONTROL_POINTS 3 + +#define MRG_MAX_NUM_CANDS 6 +#define MAX_NUM_HMVP_CANDS 5 + +#define L0 0 +#define L1 1 + +#define CHROMA_EXTRA_BEFORE 1 +#define CHROMA_EXTRA_AFTER 2 +#define CHROMA_EXTRA 3 +#define LUMA_EXTRA_BEFORE 3 +#define LUMA_EXTRA_AFTER 4 +#define LUMA_EXTRA 7 +#define BILINEAR_EXTRA_BEFORE 0 +#define BILINEAR_EXTRA_AFTER 1 +#define BILINEAR_EXTRA 1 + +#define MAX_QP 63 +#define DEFAULT_INTRA_TC_OFFSET 2 + +#define SAO_PADDING_SIZE 1 + +#define ALF_PADDING_SIZE 8 +#define ALF_BLOCK_SIZE 4 + +#define ALF_BORDER_LUMA 3 +#define ALF_BORDER_CHROMA 2 + +#define ALF_VB_POS_ABOVE_LUMA 4 +#define ALF_VB_POS_ABOVE_CHROMA 2 + +#define ALF_GRADIENT_STEP 2 +#define ALF_GRADIENT_BORDER 2 +#define ALF_GRADIENT_SIZE ((MAX_CU_SIZE + ALF_GRADIENT_BORDER * 2) / ALF_GRADIENT_STEP) +#define ALF_NUM_DIR 4 + +#define MAX_PB_SIZE 128 +#define EDGE_EMU_BUFFER_STRIDE (MAX_PB_SIZE + 32) + +#define AFFINE_MIN_BLOCK_SIZE 4 +#define PROF_BORDER_EXT 1 +#define PROF_BLOCK_SIZE (AFFINE_MIN_BLOCK_SIZE + PROF_BORDER_EXT * 2) +#define BDOF_BORDER_EXT 1 + +#define BDOF_PADDED_SIZE (16 + BDOF_BORDER_EXT * 2) +#define BDOF_BLOCK_SIZE 4 +#define BDOF_GRADIENT_SIZE (BDOF_BLOCK_SIZE + BDOF_BORDER_EXT * 2) + +/** + * Value of the luma sample at position (x, y) in the 2D array tab. + */ +#define SAMPLE(tab, x, y) ((tab)[(y) * s->sps->width + (x)]) +#define SAMPLE_CTB(tab, x, y) ((tab)[(y) * min_cb_width + (x)]) +#define CTB(tab, x, y) ((tab)[(y) * fc->ps.pps->ctb_width + (x)]) + +typedef struct VVCLocalContext VVCLocalContext; +typedef struct SliceContext SliceContext; +typedef struct VVCFrameContext VVCFrameContext; +typedef struct VVCFrameThread VVCFrameThread; +typedef struct EntryPoint EntryPoint; +typedef struct VVCTask VVCTask; +typedef struct Mv Mv; +typedef struct MvField MvField; +typedef struct DMVRInfo DMVRInfo; +typedef struct CTU CTU; +typedef struct SAOParams SAOParams; +typedef struct ALFParams ALFParams; + +typedef struct RefPicList { + struct VVCFrame *ref[VVC_MAX_REF_ENTRIES]; + int list[VVC_MAX_REF_ENTRIES]; + int isLongTerm[VVC_MAX_REF_ENTRIES]; + int nb_refs; +} RefPicList; + +typedef struct RefPicListTab { + RefPicList refPicList[2]; +} RefPicListTab; + +typedef struct VVCFrame { + AVFrame *frame; + ThreadFrame tf; + + MvField *tab_dmvr_mvf; + RefPicListTab **rpl_tab; + + int ctb_count; + + int poc; + + struct VVCFrame *collocated_ref; + + AVBufferRef *tab_dmvr_mvf_buf; + AVBufferRef *rpl_tab_buf; + AVBufferRef *rpl_buf; + AVBufferRef *progress_buf; + + /** + * A sequence counter, so that old frames are output first + * after a POC reset + */ + uint16_t sequence; + /** + * A combination of VVC_FRAME_FLAG_* + */ + uint8_t flags; +} VVCFrame; + +struct SliceContext { + int slice_idx; + EntryPoint *eps; + int nb_eps; + RefPicList *rpl; +}; + +struct VVCFrameContext { + AVCodecContext *avctx; + + // +1 for the current frame + VVCFrame DPB[VVC_MAX_DPB_SIZE + 1]; + + AVFrame *frame; + AVFrame *output_frame; + + SliceContext **slices; + int nb_slices; + int nb_slices_allocated; + + VVCFrame *ref; + + VideoDSPContext vdsp; + + VVCFrameThread *frame_thread; + + uint64_t decode_order; + + AVPacket *avpkt; + H2645Packet pkt; + + AVBufferPool *tab_dmvr_mvf_pool; + AVBufferPool *rpl_tab_pool; + + AVBufferPool *cu_pool; + AVBufferPool *tu_pool; + + struct { + int16_t *slice_idx; + + DMVRInfo *dmvr; + + int *cb_pos_x[2]; ///< CbPosX[][][] + int *cb_pos_y[2]; ///< CbPosY[][][] + uint8_t *cb_width[2]; ///< CbWidth[][][] + uint8_t *cb_height[2]; ///< CbHeight[][][] + uint8_t *cqt_depth[2]; ///< CqtDepth[][][] + int8_t *qp[VVC_MAX_SAMPLE_ARRAYS]; + + uint8_t *skip; ///< CuSkipFlag[][] + uint8_t *ispmf; ///< intra_sub_partitions_mode_flag + uint8_t *msm[2]; ///< MttSplitMode[][][] in 32 pixels + uint8_t *imf; ///< IntraMipFlag[][] + uint8_t *imtf; ///< intra_mip_transposed_flag[][] + uint8_t *imm; ///< intra_mip_mode[][] + uint8_t *ipm; ///< IntraPredModeY[][] + uint8_t *cpm[2]; ///< CuPredMode[][][] + uint8_t *msf; ///< MergeSubblockFlag[][] + uint8_t *iaf; ///< InterAffineFlag[][] + uint8_t *mmi; ///< MotionModelIdc[][] + Mv *cp_mv[2]; ///< CpMvLX[][][][MAX_CONTROL_POINTS]; + MvField *mvf; ///< MvDmvrL0, MvDmvrL1 + + uint8_t *tu_coded_flag[VVC_MAX_SAMPLE_ARRAYS]; ///< tu_y_coded_flag[][], tu_cb_coded_flag[][], tu_cr_coded_flag[][] + uint8_t *tu_joint_cbcr_residual_flag; ///< tu_joint_cbcr_residual_flag[][] + int *tb_pos_x0[2]; + int *tb_pos_y0[2]; + uint8_t *tb_width[2]; + uint8_t *tb_height[2]; + uint8_t *pcmf[2]; + + uint8_t *horizontal_bs[VVC_MAX_SAMPLE_ARRAYS]; + uint8_t *vertical_bs[VVC_MAX_SAMPLE_ARRAYS]; + uint8_t *horizontal_p; ///< horizontal maxFilterLengthPs for luma + uint8_t *horizontal_q; ///< horizontal maxFilterLengthPs for luma + uint8_t *vertical_p; ///< vertical maxFilterLengthQs for luma + uint8_t *vertical_q; ///< vertical maxFilterLengthQs for luma + + uint8_t *sao_pixel_buffer_h[VVC_MAX_SAMPLE_ARRAYS]; + uint8_t *sao_pixel_buffer_v[VVC_MAX_SAMPLE_ARRAYS]; + uint8_t *alf_pixel_buffer_h[VVC_MAX_SAMPLE_ARRAYS][2]; + uint8_t *alf_pixel_buffer_v[VVC_MAX_SAMPLE_ARRAYS][2]; + + int *coeffs; + CTU *ctus; + + //used in arrays_init only + int ctu_count; + int ctu_size; + int pic_size_in_min_cb; + int pic_size_in_min_pu; + int pic_size_in_min_tu; + int ctu_width; + int ctu_height; + int width; + int height; + int chroma_format_idc; + int pixel_shift; + int bs_width; + int bs_height; + } tab; +} ; + +typedef struct VVCContext { + const AVClass *c; // needed by private avoptions + AVCodecContext *avctx; + + int temporal_id; ///< temporal_id_plus1 - 1 + int pocTid0; + + int eos; ///< current packet contains an EOS/EOB NAL + int last_eos; ///< last packet contains an EOS/EOB NAL + + + enum VVCNALUnitType vcl_unit_type; + int no_output_before_recovery_flag; ///< NoOutputBeforeRecoveryFlag + int gdr_recovery_point_poc; ///< recoveryPointPocVal + + /** + * Sequence counters for decoded and output frames, so that old + * frames are output first after a POC reset + */ + uint16_t seq_decode; + uint16_t seq_output; + + int is_nalff; ///< this flag is != 0 if bitstream is encapsulated + ///< as a format defined in 14496-15 + + int apply_defdispwin; + int nal_length_size; ///< Number of bytes used for nal length (1, 2 or 4) + + Executor *executor; + + VVCFrameContext *fcs; + int nb_fcs; + + uint64_t nb_frames; ///< processed frames + int nb_delayed; ///< delayed frames +} VVCContext ; + +#endif /* AVCODEC_VVCDEC_H */