From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 8D1524805E for ; Sun, 10 Dec 2023 12:54:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7441668D10A; Sun, 10 Dec 2023 14:53:49 +0200 (EET) Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01olkn2071.outbound.protection.outlook.com [40.92.53.71]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CC64068D0E8 for ; Sun, 10 Dec 2023 14:53:46 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LABeZYbq4X6iOIswc59wc3Dy3K2a9H5WODojAF4px5MwvIpvQUdvpamDlFKwQ1kC1SUSlAxgPnMLI6Rk1zg8IhhtvKoz+n2bGTf1EiPp+xxwFa64gHiwnAENsoTS8/90M2Uch+RLmISpDjJESyYbmrEfxLGw2LVaGbLom0+AJXB8iqsMX32WT/e3+TtLNnN0CpirsI5AkF+fTedUonUdTTmaxCt18Mt1Ko0mVRIGNw/ULlZU+gi87OSjMlObBGZVbaWp9RxQHyv6b0x+8Y3VrknuIf3xhF021UYvZDpqwxDLUhgjFg6MtzSWaSSWzcQU/iK06UdkALlJYeHV+y34nQ== 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=aWbK4g6YaetdHxztFmBAQjYU12fjaaXspXvJ3LrAWRaW+6NtelfOMh/sj4YRKonFX3ph84OUQw/qvrVKYUkUYgkNKrch+JfUoo0QyEcZN/tqMJjO9GthN6od2mcBLTEU/oVVUVqESQqv0DV108a2e2TSTKY2n8bBdYQ1+MqHdNm60CcYUG77NhbtnnXdn137LKLyAqvTbvbrNJeri4IrI8n8ruHMQKPhHiUY8ffTSJKfD29XXvKXLqdYLMUi6w9Wh5SiV0n3Y1oXwmAQ1s+8g/iONn3/eayuA8mvXMr5vgc1htFy7znoMYPh7EiOlAY7K75/1yJ8HVQR85ut6G/crw== 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=D73VP1bVm5/PS56LrmxfiVUpli3mxiJ5BJPFgNHAB20WttwGPb3+G/r54LlUeIj00cOsNE4xemvQeDAbiyH8s0ToRBLEw/3Y4LV6KrR3INBGXnuECNAWTgn2m9Uw7vnxF2KgUeqq7QZNCIJT67a1pafxoa4ohsuDRuTq+coOxbj4uahxLDBKcvml/60G27NxWQ8G4ZfitPgh0/yNM8b76YcQIoKI2j2QNMzjzwKG4r5P+CH1l48aGSgP/z0RtCVVOl0oeJ+ILObytBJFSw9WJI8ePlvWBFhIW/JxNUqjdZpfvaQIOw79H3qRkBKBOnH162CncMP5iQtkmvU1/SuFDw== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by SEZPR06MB7644.apcprd06.prod.outlook.com (2603:1096:101:249::9) 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 12:53: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 12:53:29 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Sun, 10 Dec 2023 20:53:05 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231210125308.1838-1-nuomi2021@gmail.com> References: <20231210125308.1838-1-nuomi2021@gmail.com> X-TMN: [/OkmkvyjB+HChgDQoh23goPyZrmiQajV] X-ClientProxiedBy: TY2PR02CA0031.apcprd02.prod.outlook.com (2603:1096:404:a6::19) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20231210125308.1838-11-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|SEZPR06MB7644:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f80b2bd-425e-4875-cb74-08dbf97f01e7 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: c0ZGIl80HnLARUT4q/hu0rTqGUVxUWUwn2MSr07pa8ztRSarAPloBWUzRId1SMt7vRpXzMEq1mM2CSz5cc3a5wRFX5JhBqeZUlC8TuMk6KoOiP0wT/lVjov17km/XbBhndtWGYn9sYm935fMV7Wj7luwRSWP4wwSS3NzdfF65SOdFxl69MwnA2yWS3dLYMm5BBt9IP5ilQgipRCx4gQVDCCyhkl3dgsN/s0rlZPscssHjR1AnHfwlV1XoPqBjkYzH5q0cud5Y3EceUr3HlAbRU6rDkftu2TokfyLqD6Fk4VsyT5a94JGx0cYDiC8KfYWf1gkdykGPHUO868j4eNvYPC02He6q+O/osDvpQRrbL6b8OKmy3Mk/AxD+aWYIn0gOdAFesi++lmQlIndoWr6QlCOVxL07WNQ7pCgBmkNFkhJpLnpUAvBYI6o7vRfEWecV3JDXCc0gwLdQeNZ7kiysqlKBfza01knPKLL+4aCE+OCb1/2II8ToYSCaBQcV27Fh1RZ/eP7FeygJ4b0NJsKH+nr4BgxlM4EOMDhhneZb9cUjh5pU4mAtvQWFSaUUEeandBL1brm+J5mFfN5cj7/LLLfnBEa8NHJVBjUo4+HDh2gpFklozV2uJkAG/BZzylj X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?kugYdhizYWPK9ymIrK/YUy9R+kU9yLiH6Ifa3dPnx4BDrsjyJcmIiMCvVenF?= =?us-ascii?Q?Q+hSI1l8/ipgf9E36Y+iSxcDZVrVr2TBGRk7r7tUHJMZe3ZOWILifDhgIDtW?= =?us-ascii?Q?3aG0E47QPyLXeDe3XpI7p0nGsDHk7F9Zg77rBksu0XyDZkSt0yk1cm1AcBSF?= =?us-ascii?Q?T+lbTmT3BbmRinrBuW+cODrdAhwbJtPUpy/WEs8yNfxdLaJm/rcYnxxbtOmu?= =?us-ascii?Q?XRa/iNd6ET4yKb6Q3RPVDClL6PfcdwR9s/INe9Jlc571pBM5y08IvOz90n1R?= =?us-ascii?Q?vZ0BG0eB5dQCrtRQTwy6w19UoJboJ+E3Fpu0OsFN2nCTBRrRAGUXiw0ZyxAp?= =?us-ascii?Q?GDw3L5yOI+pDMeypZqt8F9RNiHqEvCpst/FNpL4An1KSzApkgIV+24UpnFN9?= =?us-ascii?Q?XvP7WgyElzj113J05mu7uf/+/Qio3wYtpRwRQY4oc5zvwgdn/3MqTnd1e/4F?= =?us-ascii?Q?frTMFyDNG2vsTdqRu+TEXJYqo5OO8aE+987PezfmmmtqwPjbv2Pa7PoEh0KS?= =?us-ascii?Q?5xtmYOmWHpjOwfSoINT7fMwWuOwGfnxcn6mBxohB6QOGBE6e8iPMGviCdSXP?= =?us-ascii?Q?7BFTc8hPv0XsTgtri8E0FdDuCguEyFKRYrkBw938Q80KG0F/z3xIvkp37Inj?= =?us-ascii?Q?X0eiFMfAbLAapfqOBoq4aOd0RD63iw5mTksjWaJJWmIWLFXprnkKMBZ/6n7e?= =?us-ascii?Q?aJgWl0pP66kGUmqo47UFVj4JrThcTpnhenbsCiwfWaUFJ4GAnL/tQq4NhAqM?= =?us-ascii?Q?0zUrQz09rr82IN+AEU414DylZsn6QhdCUWOULHYoGjNt/DMyQX8Oqd45ZPVK?= =?us-ascii?Q?a/UA71jVpfuKsCejszIO8kcTxrPseKYam2mkUDtmrP3gI1lfNSAMYQmMp7Ed?= =?us-ascii?Q?Gknj9144MAkEdiiczHtzaTciZS9nQRORCeEYU4Pa1ROOE2FU6VJRcRSkipTP?= =?us-ascii?Q?aWSAAoz2m3Js9sPirLNqjBv7B+4BUbdXmCalkwWVEzXwiEpDc6rNbWs8so0N?= =?us-ascii?Q?rQA5uwuCQAk4/aYVNphNT+oOPq2aQ80xDrAIoi/cShyUQv7Xp862ptguKumw?= =?us-ascii?Q?+vW3H7Uz85QH+V1Pmj9MG+eS25xylzVwp/2tFzKzChzksYN8O49rNq/9iL+m?= =?us-ascii?Q?NCaa8jdmY23+jsng1B/Wt8cJxKB8gemplk9eb+9qcFyvF7keste0YTc0FAOX?= =?us-ascii?Q?iBduRZwQt9T+sjeQBvrIt5IMdBoZpxm2gnAWe/yvxKP2h52QWivalQuCBfdu?= =?us-ascii?Q?YHUD03oZvikPctR4FQzz?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9f80b2bd-425e-4875-cb74-08dbf97f01e7 X-MS-Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2023 12:53:29.3406 (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: SEZPR06MB7644 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: --- 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 +} -- 2.25.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".