From patchwork Sun Dec 10 16:03:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 45018 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp2452837pzf; Sun, 10 Dec 2023 08:03:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6/7BwO4F/nhmOKft6Xj+aDl3wVscuJQT4DqrLXvLqHvXjDuWcjO73Npk9zXGBjM4Lncx6 X-Received: by 2002:a17:907:1c2a:b0:9fc:3aeb:d2b9 with SMTP id nc42-20020a1709071c2a00b009fc3aebd2b9mr2250600ejc.71.1702224227414; Sun, 10 Dec 2023 08:03:47 -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 jo19-20020a170906f6d300b00a1c9ac097fesi2895842ejb.393.2023.12.10.08.03.43; Sun, 10 Dec 2023 08:03:47 -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=bfhINPZV; 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 5206568D071; Sun, 10 Dec 2023 18:03:40 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2086.outbound.protection.outlook.com [40.92.107.86]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B817068D071 for ; Sun, 10 Dec 2023 18:03:32 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YfocCFkHx1kLT8u+NsjabwSCRvWO6LjuMAdZDSGVIKNFaR8NhfTMjrjLND6+3C3Ne0UnuJ6BHDwDhB/1M4wHTaB28zq5rLAxmqcEIAmeggzV1I8wiS+g/gNIM5lWAxVe/28s5eVODaNLd/JltpcbRnR1yiWwDmihrw7atsafkBhDneDNvVMyGTjXlWfDvw292sfUHCRp99+D5mHN6Hlr+1YtIvI3RwI9MQo9bZ+tii/V3QwBYA1/to3xMcOr2u6zrxCvAJFEe+O5EfuIBxkwR/8bc+37ClkfiJ1WtJdznBTkFTMLzyTgUarMR9l4/jS0QCrMTOpSTJcrIW69cz1aLA== 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=hM804TUO0sj9VTucBrxr5DV8r5LtXDjP1yiC1jQanEI=; b=BemoRqdJ/FOmPYO/qVwAyUIDYqlb/1r+BsC3zk55suxLKJ7PpRM7n6TOkPRzVQq251z/CqRCHKwUrgGxP7YEcQdmRuffIyoKY1TSCz2YVkv30dMAx2vPwRocVaufY4Hvp8joO6m+vxNq2dKuGbSH+9FF9KiuSinljUuM6+8gflwmikLUkxrOfd+4uKOJ+FtIvHBvVDZjwkypqAC8hgys6eENaBfSAYDQ5H6cVXD1+Le1+V6Bd9ydAIlEu13vpPMudU+PlFW73h7RioN90kI/tKI6aEmKJ+KHyHdkIh64CjjniEsvClXV38VFRcb4MtCAgagloCHLp32weNCoHS0ddA== 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=hM804TUO0sj9VTucBrxr5DV8r5LtXDjP1yiC1jQanEI=; b=bfhINPZV80qk+ZAzpaM9G2yYKXLkiTc9kA7LhxOtcZ1IlFAnhxKbAdgGmUhhLIYukoPxceBY+S5Ii3C7hOZuDP2oDac/INMX4lDnmc3dJhB+ifLP7MY0m8RcIZjZsn4auSkOnx8fnG9it2wQLwKrw8R4mHm04iH1CreejrjqU11mpuVm9Y45mPwAdXKrXqvFG48Q2u/t61o3RAAcUoraLf68GKRT8yw2gXqJrPGCpYRIP6VogT+4hCQg/zst4+Gn+hZBInFEUQnaXGPBPvqPscsPcMPAkJXM11aybNpz3UeSwE9mrJf6ecgktw65BsjknHLZO9jryg7ht10T6Du8Rw== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by JH0PR06MB7295.apcprd06.prod.outlook.com (2603:1096:990:a9::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7068.30; Sun, 10 Dec 2023 16:03:29 +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.7068.030; Sun, 10 Dec 2023 16:03:28 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Mon, 11 Dec 2023 00:03:19 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 X-TMN: [tc3RvKYlsEewnerp3IqyNKCjYL0vMrW2] X-ClientProxiedBy: SI2PR02CA0027.apcprd02.prod.outlook.com (2603:1096:4:195::14) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20231210160319.4847-1-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|JH0PR06MB7295:EE_ X-MS-Office365-Filtering-Correlation-Id: 622457c6-0191-453c-42cc-08dbf9998c4d X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: H6hFx04SoVHX5pMbXpf37lEPIbQm8rHOSezZvxagEADSaHMmkqtKxaXSHxkgYgK9qwFZfLUztk5I6ldXYOnWw2RpIxaWxx5qKlBAXN94387OnPlGI0514t3Fo6P9/SR1MczWj2md844RXgMnpM0JPmq7yKeReOhio2JaLOHHzABBCWWpluM7+JGlAFlTlP2HuwjNTSResj3gkD0POEjlV9igwO1CS+AOfG8DpDrgRnfbO20NPwIYROtQ8+CqgHL1DLV2fR8dRFf0VaLaB0G7dgr8nvEcVJrN/XIADa5+yZOe3Xpe9BP7nreHQCtQ9KJ2tM9mKnmQQZpd72hrFbUYY2Sbm9eAHR+jCjXsGGPtnDqoOyoLFMKf4PnUK0W8spoMrTZ4S8wdVoSYal17Lwxl1+q+wFqgnC0i+6vL0B36m4/LDawuJODZkkLyd2bFNgvdY87tArBD2TRkft42om0DZDfF+8+Q91YH6FLGC4w9tpmXBZEunLYiVQL/LhKS4zx50Am8AOmaBYs0hjaJ4SCAJAGZQiE2wU0GMpkyL4+Qh6cPG3cit/2f3tRbwTRW8PZUiJMTRaoytugOIUcV1S5ke9sz4zLNoG6ea00ustjpFHipKqidNv8jagC85+Q8U7/f X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: jisxarKBrrhTxwF8Q3Fzyz1/sUVoaAtkjUYTq6Y/DbAMVTpcyopBX8pKXSVq7KHTP7Kev/pnPa1/L+Dfy4iQQri0oqVu5THd/f/xjSEDBR1Ye33xZ4SgDIp3kUIL+ugs8HcEnPzFxn7//KIT9HqB5HPsI3lUxVNyzK30wcCdq70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1wwCsi8NsY5WawxjyxbbGp6Ozh X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 622457c6-0191-453c-42cc-08dbf9998c4d X-MS-Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2023 16:03:28.5431 (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: JH0PR06MB7295 Subject: [FFmpeg-devel] [PATCH v7 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: 8WqUsPlacP0Z --- 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..c82ea7be30 --- /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 *coeffs, ptrdiff_t step, size_t nz) \ +{ \ + ff_vvc_inv_##type##_##s(coeffs, step, nz); \ +} + +#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 +}