From patchwork Sun Nov 12 10:35:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 44631 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:92a5:b0:181:818d:5e7f with SMTP id q37csp728679pzg; Sun, 12 Nov 2023 02:38:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEL0c53LbXIFixBOR0t7WLrn0A0xGdALb/5BLZ4KRwljKsHCKs41ClWKK2cKt9Afty2WcNG X-Received: by 2002:a05:6402:412:b0:547:2547:d973 with SMTP id q18-20020a056402041200b005472547d973mr2087013edv.6.1699785498550; Sun, 12 Nov 2023 02:38:18 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i1-20020a50d741000000b0053deaf10390si1573327edj.339.2023.11.12.02.38.18; Sun, 12 Nov 2023 02:38:18 -0800 (PST) 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=kpxBMrGL; 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 269E868CCB8; Sun, 12 Nov 2023 12:36:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01olkn2037.outbound.protection.outlook.com [40.92.52.37]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 43DDA68CC70 for ; Sun, 12 Nov 2023 12:36:20 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ncgtqjQStK1UmO0jyoiOYUvOYqqDZVwG956PyLFb0ZupyVQEnIEq6N528j2S5s6dVAeVHq5MoHMb7Lgn31eKyucpS97+bChaG2sIEpvIXcF9jSnIH4QMdp7MfXjal3QuboIU41o3D5DnNpGPk5yqj0Xmj+vx1PbomstQIuK+9I4319FSI+OzOHRdcKi3lauRqyB/X3jDK74F+sEPh2/zxLCYsOMtPT6gNj8FmSHGDSnjz9evUIIWsXwMQjCJ8hmII+97bHjCVcrIhkmaLoPk2gnQJeToF2Dbvq+ubcU1RxzS7s+JrIQ+m6r1OZzXfxQ/iPqvzD7GEIp/0FUuUzPxEg== 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=VMcL0jtMx/VN4yEWr5RvYa01yy3SYVyzgWvoReByyaU=; b=FK6HZvP10m6fuD0jrHVzP43rwxZcRtkjm5+dwnpCO8NzPKF4oJi1puFIQaxG8b/xfEglPyJ5Og83NEQKnNJvs2D9YTuq4hyuvPQzj6a/8gzREnEXj2NSLaQix0cexDetgvOSvD+7i6+4Iif33Q0fExZlTiDURO2opSoKGEb5geo5xxSPIAWIaLMxxlY3O+iiOF6kE+ffatJjx2/tycmGJxWk6DDQUQb/eJNlfHLD5Hr3tU+nPUyVOFZfu/2AdKHLzgEB3755NEEC3Ctc6nFGGNxemNHCVn9Xx7qmn0ICuu9VxDucg9kp1YJUMWH4c4U8ONmN8qiG3AbHCZ/1z/EAdA== 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=VMcL0jtMx/VN4yEWr5RvYa01yy3SYVyzgWvoReByyaU=; b=kpxBMrGLWkPeDaDiadLkuTbCThaxa2TGe+ll6Uhj98THjcqOaZXpmPuaeru8kgPxiyR5KZkxw8QVb85J6L4ZCRLTpvR0fWGZnteZ4dmvxKsBNyRXgl4CCzi2ySYCvX0usA7VIbFUEaxBQsRYboeSs+7cd0eeKLkeUt978otJMABeFvU0cqY5ZKDWndMvxBsvH9/DnIYTbkm46yVuWWXNZA7WQZnZz0H0ctsk2xf2+heUzADWxcZRHE6McwpcIliZRUbe3EFuthRnu7hXYleHxF0NIiCvIIHbtYXuMi5vsQc0m/7ZlnTOe16LQson6Xg7ntpFFV5RiuJ0GJOf7sn7IQ== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by TYSPR06MB6768.apcprd06.prod.outlook.com (2603:1096:400:475::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.29; Sun, 12 Nov 2023 10:36:02 +0000 Received: from TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::80b3:be24:949c:e49f]) by TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::80b3:be24:949c:e49f%4]) with mapi id 15.20.6954.028; Sun, 12 Nov 2023 10:36:02 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Sun, 12 Nov 2023 18:35:23 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231112103526.11245-1-nuomi2021@gmail.com> References: <20231112103526.11245-1-nuomi2021@gmail.com> X-TMN: [yrt63qO4QfheDHOljgfksh7sWtv9REm4] X-ClientProxiedBy: TYWP286CA0030.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:262::20) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20231112103526.11245-11-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|TYSPR06MB6768:EE_ X-MS-Office365-Filtering-Correlation-Id: e3a1503c-959c-4d2a-4a22-08dbe36b2a82 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: p85UDLdsOaG9qoWHZj0jwQHk7928uVBJETJJCNmY7e4Im/6siP9W5aspiJCCUqmocJnQqBi1XuC7I+6vw+ZfpBDjOtZ/E9LOTV/2dwHub2fR/TDIABHteZR6XujFxNCJJVCIjeXC3EzLuglhpFDTUeLnPo3nV5s6/LCIlifXiHs/xyz6yNXHS9tCiaCV/Ta1irBWNMb1ysH6p6VW6Og2Ym2eVuxsyrScNF5kl3VD8kvHWiMuPX7NomA9m4nHw9HMdFpvG/BSfPDIzFT9iqI/n6y7uIhpHoOTf587yskrmr1VbcocR7MhifAOQEkDP3bxRCwC9ithqqUbsBCErGO67XMN0RDfOYSsEu/sS7ggp7/PHJ1DlwwELb3Z31YeLLjIphlKuDw4swQk/5XRSWIeDl/EVsuNF7huK4fUEeyhyq5ERmMltTJlgx/gKNrxzcdhmd9cp0hFh1eGrdSIazyYUNG2EDsdQjlxcLNMU8B83OFGBusQGGcGZbTj1Hcxe/RLObheGfhJ4LGFP9wmQW7uJGptk7qilT7EwTO+FXbsZzsjXMhfNgNCI+zvj2qxZaSbi/XfNsQXi/R52kf+SOpMgToZ7o3YKMGT+3T8C9BIah++oYPrKG80GTS3BQbdnA4O X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: u9NUIjHyeOJeCaMKX2sVG3q9lH6iLP45Qj6PojOqcI2ShugzCe6Wfv0RPXhY4wL9qHKHq1dAU9pksmUrzwez1uMnCTS3m9NY0jnDAdyeCBz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J4XWM1VlIxn8P/rGaZ/g4OpI4GUXdeb/+GTzUO+QU298Q64Eji3EZZ0eZWGgAnkPXU6PQIYVK8htSU8Gp0OiN76e X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3a1503c-959c-4d2a-4a22-08dbe36b2a82 X-MS-Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2023 10:36:02.0103 (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: TYSPR06MB6768 Subject: [FFmpeg-devel] [PATCH v5 11/14] vvcdec: add dsp init and inv transform 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: p4Mul9WNWvpO --- libavcodec/vvc/Makefile | 1 + libavcodec/vvc/vvcdsp.c | 141 +++++++++++++++++++++++++++++++ libavcodec/vvc/vvcdsp_template.c | 120 ++++++++++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 libavcodec/vvc/vvcdsp.c create mode 100644 libavcodec/vvc/vvcdsp_template.c diff --git a/libavcodec/vvc/Makefile b/libavcodec/vvc/Makefile index 9e7fef7d38..bc663a5b50 100644 --- a/libavcodec/vvc/Makefile +++ b/libavcodec/vvc/Makefile @@ -2,6 +2,7 @@ clean:: $(RM) $(CLEANSUFFIXES:%=libavcodec/vvc/%) OBJS-$(CONFIG_VVC_DECODER) += vvc/vvcdec.o \ + vvc/vvcdsp.o \ vvc/vvc_cabac.o \ vvc/vvc_ctu.o \ vvc/vvc_data.o \ diff --git a/libavcodec/vvc/vvcdsp.c b/libavcodec/vvc/vvcdsp.c new file mode 100644 index 0000000000..fa14614397 --- /dev/null +++ b/libavcodec/vvc/vvcdsp.c @@ -0,0 +1,141 @@ +/* + * VVC DSP + * + * Copyright (C) 2021 Nuo Mi + * + * 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 "vvcdsp.h" +#include "vvc_ctu.h" +#include "vvc_itx_1d.h" + +#define VVC_SIGN(v) (v < 0 ? -1 : !!v) + +static void av_always_inline pad_int16(int16_t *_dst, const ptrdiff_t dst_stride, const int width, const int height) +{ + const int padded_width = width + 2; + int16_t *dst; + for (int y = 0; y < height; y++) { + dst = _dst + y * dst_stride; + for (int x = 0; x < width; x++) { + dst[-1] = dst[0]; + dst[width] = dst[width - 1]; + } + } + + _dst--; + //top + memcpy(_dst - dst_stride, _dst, padded_width * sizeof(int16_t)); + //bottom + _dst += dst_stride * height; + memcpy(_dst, _dst - dst_stride, padded_width * sizeof(int16_t)); +} + +static int vvc_sad(const int16_t *src0, const int16_t *src1, int dx, int dy, + const int block_w, const int block_h) +{ + int sad = 0; + dx -= 2; + dy -= 2; + src0 += (2 + dy) * MAX_PB_SIZE + 2 + dx; + src1 += (2 - dy) * MAX_PB_SIZE + 2 - dx; + for (int y = 0; y < block_h; y += 2) { + for (int x = 0; x < block_w; x++) { + sad += FFABS(src0[x] - src1[x]); + } + src0 += 2 * MAX_PB_SIZE; + src1 += 2 * MAX_PB_SIZE; + } + return sad; +} + +#define itx_fn(type, s) \ +static void itx_##type##_##s(int *out, ptrdiff_t out_step, const int *in, ptrdiff_t in_step) \ +{ \ + ff_vvc_inv_##type##_##s(out, out_step, in, in_step); \ +} + +#define itx_fn_common(type) \ + itx_fn(type, 4); \ + itx_fn(type, 8); \ + itx_fn(type, 16); \ + itx_fn(type, 32); \ + +itx_fn_common(dct2); +itx_fn_common(dst7); +itx_fn_common(dct8); +itx_fn(dct2, 2); +itx_fn(dct2, 64); + +typedef struct IntraEdgeParams { + uint8_t* top; + uint8_t* left; + int filter_flag; + + uint16_t left_array[3 * MAX_TB_SIZE + 3]; + uint16_t filtered_left_array[3 * MAX_TB_SIZE + 3]; + uint16_t top_array[3 * MAX_TB_SIZE + 3]; + uint16_t filtered_top_array[3 * MAX_TB_SIZE + 3]; +} IntraEdgeParams; + +#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) + +#define BIT_DEPTH 8 +#include "vvcdsp_template.c" +#undef BIT_DEPTH + +#define BIT_DEPTH 10 +#include "vvcdsp_template.c" +#undef BIT_DEPTH + +#define BIT_DEPTH 12 +#include "vvcdsp_template.c" +#undef BIT_DEPTH + +void ff_vvc_dsp_init(VVCDSPContext *vvcdsp, int bit_depth) +{ +#undef FUNC +#define FUNC(a, depth) a ## _ ## depth + +#define VVC_DSP(depth) \ + FUNC(ff_vvc_inter_dsp_init, depth)(&vvcdsp->inter); \ + FUNC(ff_vvc_intra_dsp_init, depth)(&vvcdsp->intra); \ + FUNC(ff_vvc_itx_dsp_init, depth)(&vvcdsp->itx); \ + FUNC(ff_vvc_lmcs_dsp_init, depth)(&vvcdsp->lmcs); \ + FUNC(ff_vvc_lf_dsp_init, depth)(&vvcdsp->lf); \ + FUNC(ff_vvc_sao_dsp_init, depth)(&vvcdsp->sao); \ + FUNC(ff_vvc_alf_dsp_init, depth)(&vvcdsp->alf); \ + + switch (bit_depth) { + case 12: + VVC_DSP(12); + break; + case 10: + VVC_DSP(10); + break; + default: + VVC_DSP(8); + break; + } +} diff --git a/libavcodec/vvc/vvcdsp_template.c b/libavcodec/vvc/vvcdsp_template.c new file mode 100644 index 0000000000..f92c266478 --- /dev/null +++ b/libavcodec/vvc/vvcdsp_template.c @@ -0,0 +1,120 @@ +/* + * VVC transform and residual DSP + * + * Copyright (C) 2021 Nuo Mi + * + * 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 "libavutil/frame.h" +#include "libavcodec/bit_depth_template.c" + +#include "vvcdec.h" +#include "vvc_data.h" + +#include "vvc_inter_template.c" +#include "vvc_intra_template.c" +#include "vvc_filter_template.c" + +static void FUNC(add_residual)(uint8_t *_dst, const int *res, + const int w, const int h, const ptrdiff_t _stride) +{ + pixel *dst = (pixel *)_dst; + + const int stride = _stride / sizeof(pixel); + + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + dst[x] = av_clip_pixel(dst[x] + *res); + res++; + } + dst += stride; + } +} + +static void FUNC(add_residual_joint)(uint8_t *_dst, const int *res, + const int w, const int h, const ptrdiff_t _stride, const int c_sign, const int shift) +{ + pixel *dst = (pixel *)_dst; + + const int stride = _stride / sizeof(pixel); + + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + const int r = ((*res) * c_sign) >> shift; + dst[x] = av_clip_pixel(dst[x] + r); + res++; + } + dst += stride; + } +} + +static void FUNC(pred_residual_joint)(int *buf, const int w, const int h, + const int c_sign, const int shift) +{ + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + *buf = ((*buf) * c_sign) >> shift; + buf++; + } + } +} + +static void FUNC(transform_bdpcm)(int *coeffs, const int width, const int height, + const int vertical, const int log2_transform_range) +{ + int x, y; + + if (vertical) { + coeffs += width; + for (y = 0; y < height - 1; y++) { + for (x = 0; x < width; x++) + coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - width], log2_transform_range); + coeffs += width; + } + } else { + for (y = 0; y < height; y++) { + for (x = 1; x < width; x++) + coeffs[x] = av_clip_intp2(coeffs[x] + coeffs[x - 1], log2_transform_range); + coeffs += width; + } + } +} + +static void FUNC(ff_vvc_itx_dsp_init)(VVCItxDSPContext *const itx) +{ +#define VVC_ITX(TYPE, type, s) \ + itx->itx[TYPE][TX_SIZE_##s] = itx_##type##_##s; \ + +#define VVC_ITX_COMMON(TYPE, type) \ + VVC_ITX(TYPE, type, 4); \ + VVC_ITX(TYPE, type, 8); \ + VVC_ITX(TYPE, type, 16); \ + VVC_ITX(TYPE, type, 32); + + itx->add_residual = FUNC(add_residual); + itx->add_residual_joint = FUNC(add_residual_joint); + itx->pred_residual_joint = FUNC(pred_residual_joint); + itx->transform_bdpcm = FUNC(transform_bdpcm); + VVC_ITX(DCT2, dct2, 2) + VVC_ITX(DCT2, dct2, 64) + VVC_ITX_COMMON(DCT2, dct2) + VVC_ITX_COMMON(DCT8, dct8) + VVC_ITX_COMMON(DST7, dst7) + +#undef VVC_ITX +#undef VVC_ITX_COMMON +}