From patchwork Wed Mar 27 13:01:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 47527 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp604341pzb; Wed, 27 Mar 2024 06:02:37 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWHUzh10ziMIVKHb4Xa0Gk005wLwm3rDyuMqOHdwFRfZH4xi1/y+rAzx0wsYrFvTkxp7m4dBPHxkBRdUDHyjXmbCG52uKQvdvSG9A== X-Google-Smtp-Source: AGHT+IHX2SF0oBHaz56ngh0PrSx4tM7MmS1wyEgdVAvyQ9wDI0bFahwic94+4faLXkkC0cfb6Slz X-Received: by 2002:a17:906:52d7:b0:a46:47d5:2851 with SMTP id w23-20020a17090652d700b00a4647d52851mr2607446ejn.29.1711544556818; Wed, 27 Mar 2024 06:02:36 -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 rv21-20020a17090710d500b00a4725e6b8aesi4535189ejb.18.2024.03.27.06.02.28; Wed, 27 Mar 2024 06:02:36 -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=HN52dJJ+; 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 7D40E68D6AC; Wed, 27 Mar 2024 15:01:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01olkn2014.outbound.protection.outlook.com [40.92.53.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5CC8468D6A6 for ; Wed, 27 Mar 2024 15:01:35 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NZf8yroaBgKNr/GBf8GTOnHudG+LCzS3hMInedh4QO4aX+s2MTGPXqkrdwhQ9cph9CQS9sxgmiqn7hKO9b8R8d2ixjNdfIJLsZsv6XeJkIn0+YRNReB6twUj4nzvamz9pQCf/CBxVpWL8uGhuF7TP+qYG2yZWFh88QNV1HaxhjbnDpsflyLilyNYrV4jjatmJfAlBIWhkl+W+ja105B3dCdhrbKcJHsa5rSwXUllEG/IGXZJ2zuuFJG2qWVKOopZ+ON4hlTWX5ykOWh5l1xyg2+fHNYvDDVRVY3Bcm04UQsiau8Ei10iAPkgEjalcK5wIraKktFfCnUd5OQwzqHljw== 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=G1So1XD7KkXhfzhLVXANHwNyN4AcJez6cXox0lc+guw=; b=UuG8cHM5F9fJ+Udmw8Zx1Bls70stetZDWSFdc0ox2JuzgOoK6FFhLSxOKmu7fr7idnAd4XApekOWzkJA8IadP5CnLXLYawIIn6M3hoHIzhi4W6vpe0zqd0KbwBIoUBNZrgH77TxWWxi0tr+8Om4Y/8gcnXcNxtB001lr/FOMkBDoe+14yCGSFuBr+3mZfFwCUxyvigLI4pIHLXFfxLhc1CVh9cV1wvyo67sA9K2KZq7BmOyfeTqMNPBuhbOKNu0a4W7l4PE4quqcyOizgjJpJ7QmLTs4uzgBM3XXeIJajuRCkry4EkVY05HmGVX2gbs/xS07/l92IbJK+8rM4UNqZA== 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=G1So1XD7KkXhfzhLVXANHwNyN4AcJez6cXox0lc+guw=; b=HN52dJJ+gbrPdQhCAzGEztLpMlLudU1pLGM9t0w9DbaZbYvFv6T+Pob9ndgUIXVhA9cr8lZM4M5/QiT2ERn508TGi3b314x7v4cmAgogKuhnjiGu8KfobXl+5sQpix5g29ANLKtA2ifWHsegrPMV8Ar5xhSkziw0PZY5C8ZDDSVA6NLyj/d9kL2U9sDv808M/0QLsKhSdL9lB+GRE1ChjQB4SukBF15KFB2zETgjRoMVGQ/bWsUcTb7w1PoyIxPec2yDm8ceuragRsM9UzgBUsmrqtb2oKyuzc3HgMYH1Nl+Nz9ib4E1l9pnzDMBc/0uwfKxXUkwQCA2eBwWDxdotQ== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by JH0PR06MB7107.apcprd06.prod.outlook.com (2603:1096:990:9b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.33; Wed, 27 Mar 2024 13:01:24 +0000 Received: from TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::d001:da90:518b:ec1c]) by TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::d001:da90:518b:ec1c%3]) with mapi id 15.20.7409.031; Wed, 27 Mar 2024 13:01:24 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Wed, 27 Mar 2024 21:01:01 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240327130112.6111-1-nuomi2021@gmail.com> References: <20240327130112.6111-1-nuomi2021@gmail.com> X-TMN: [LsR2QxRRU8Vnj2oJgR3Hjf2TfSRUO4X2] X-ClientProxiedBy: SG2PR01CA0117.apcprd01.prod.exchangelabs.com (2603:1096:4:40::21) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20240327130112.6111-6-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|JH0PR06MB7107:EE_ X-MS-Office365-Filtering-Correlation-Id: 87a85fed-1714-4349-39ee-08dc4e5e010e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gZ+MDy57zfsbMyfjL91uvmhm1gMvYyZx37/cYG5ANjsNAz5y5KAyxIC1e0YQ5NdtcIA+r9LiYDtemhNEufPD/AzQts66pEKz4iRtXcjM11+6K+ykO7pumvhmzukCZXjXfLpAzsRcKtiELtyqi66FBdkZNK2OFMo6/H6QQqeLc/FAHKR6kf16NWG1qQ66poUmNrXFwSnqcGdA7hBbAGxHi0ZIoQrid6TASEepgPUTy1uF0Fqnjz86agXx8sr1QiuomYmCBJt/DvldMdpGJ//pX8ki93v11EbSv1jP5qB3Z5q+Sw9MC6mkeRBGQFYA7SeZiR12yS13ymEFfropKsO407LCuw3nd5riDKtiEYKZxPXciBB8IVJK4PHuT+O0RXaIfCc5/rot0r2p1akQdYsKQMDfU055Ai2mN5x2CKNlQgr8coaVvxPVKm/CcevmyBDve0XM+kSbGbj1Xt6ZjwUPp+UNpA6AEa22IWZg+gRKVdzTF/jNFtS9csXfokQ3CyG5vpIFcy5w+ln990rnURmbnUdJdo/+6qOY8velMPKKUnN0D/KMDSWj0RgofWC2MmO3yTtWyQ06vYdA3iERHo30eYUAdKPzH/gS2/+EWFgwSIEGGqxw2qUqd7JoOX9W/tlA X-MS-Exchange-AntiSpam-MessageData-Ch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LbQ+PPYg8+Jbgqw80kbUr1lCMl4fR3vIVC6/bFPIujNoC4laZ6f9DnjOJkwJz0YfVU3HFj6YMkVBNtWSrhxXRqzc90A6VPj9Y8/Lc3nsXYt6ImoMUI7kEuaKDFiHaPp7q1ItawGSAPFBYnf/0oRwGiDpk4Ir94rGHuzZLg8EMIa7gIpYnVXt5OQckSxgQu3ULf86TXiwDmQTCVebJ9/8vMYRq+mDFgwG3UrNibMnNkTJ/td5LurxeVKGtrNVaAwzkRyZA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 87a85fed-1714-4349-39ee-08dc4e5e010e X-MS-Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2024 13:01:23.3089 (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: JH0PR06MB7107 Subject: [FFmpeg-devel] [PATCH v2 05/16] avcodec/vvcdec: support rectangular single-slice subpics 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: Frank Plowman , Nuo Mi Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 6ckWJIDpENEJ From: Frank Plowman Co-authored-by: Nuo Mi --- libavcodec/cbs_h266_syntax_template.c | 5 +- libavcodec/vvc/vvc_ps.c | 93 +++++++++++++++++++++++++-- 2 files changed, 91 insertions(+), 7 deletions(-) diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c index f56066d470..725cee5b03 100644 --- a/libavcodec/cbs_h266_syntax_template.c +++ b/libavcodec/cbs_h266_syntax_template.c @@ -2120,9 +2120,12 @@ static int FUNC(pps) (CodedBitstreamContext *ctx, RWContext *rw, } else { if (current->pps_no_pic_partition_flag) infer(pps_num_slices_in_pic_minus1, 0); - else if (current->pps_single_slice_per_subpic_flag) + else if (current->pps_single_slice_per_subpic_flag) { + for (i = 0; i <= sps->sps_num_subpics_minus1; i++) + current->num_slices_in_subpic[i] = 1; infer(pps_num_slices_in_pic_minus1, sps->sps_num_subpics_minus1); + } // else? } if (!current->pps_rect_slice_flag || diff --git a/libavcodec/vvc/vvc_ps.c b/libavcodec/vvc/vvc_ps.c index 3e7c0b4f5b..6b5aa31ccd 100644 --- a/libavcodec/vvc/vvc_ps.c +++ b/libavcodec/vvc/vvc_ps.c @@ -346,6 +346,83 @@ static int pps_add_ctus(VVCPPS *pps, int *off, const int ctu_x, const int ctu_y, return *off - start; } +static void pps_single_slice_picture(VVCPPS *pps, int *off) +{ + for (int j = 0; j < pps->r->num_tile_rows; j++) { + for (int i = 0; i < pps->r->num_tile_columns; i++) { + pps->num_ctus_in_slice[0] = pps_add_ctus(pps, off, + pps->col_bd[i], pps->row_bd[j], + pps->r->col_width_val[i], pps->r->row_height_val[j]); + } + } +} + +static void subpic_tiles(int *tile_x, int *tile_y, int *tile_x_end, int *tile_y_end, + const VVCSPS *sps, const VVCPPS *pps, const int i) +{ + const int rx = sps->r->sps_subpic_ctu_top_left_x[i]; + const int ry = sps->r->sps_subpic_ctu_top_left_y[i]; + + *tile_x = *tile_y = 0; + + while (pps->col_bd[*tile_x] != rx) + (*tile_x)++; + + while (pps->row_bd[*tile_y] != ry) + (*tile_y)++; + + *tile_x_end = (*tile_x); + *tile_y_end = (*tile_y); + + while (pps->col_bd[*tile_x_end] < rx + sps->r->sps_subpic_width_minus1[i] + 1) + (*tile_x_end)++; + + while (pps->row_bd[*tile_y_end] < ry + sps->r->sps_subpic_height_minus1[i] + 1) + (*tile_y_end)++; +} + +static void pps_subpic_less_than_one_tile_slice(VVCPPS *pps, const VVCSPS *sps, const int i, const int tx, const int ty, int *off) +{ + pps->num_ctus_in_slice[i] = pps_add_ctus(pps, off, + pps->col_bd[tx], pps->row_bd[ty], + pps->r->col_width_val[tx], sps->r->sps_subpic_height_minus1[i] + 1); +} + +static void pps_subpic_one_or_more_tiles_slice(VVCPPS *pps, const int tile_x, const int tile_y, const int x_end, const int y_end, const int i, int *off) +{ + for (int ty = tile_y; ty < y_end; ty++) { + for (int tx = tile_x; tx < x_end; tx++) { + pps->num_ctus_in_slice[i] += pps_add_ctus(pps, off, + pps->col_bd[tx], pps->row_bd[ty], + pps->r->col_width_val[tx], pps->r->row_height_val[ty]); + } + } +} + +static void pps_subpic_slice(VVCPPS *pps, const VVCSPS *sps, const int i, int *off) +{ + int tx, ty, x_end, y_end; + + pps->slice_start_offset[i] = *off; + pps->num_ctus_in_slice[i] = 0; + + subpic_tiles(&tx, &ty, &x_end, &y_end, sps, pps, i); + if (ty + 1 == y_end && sps->r->sps_subpic_height_minus1[i] + 1 < pps->r->row_height_val[ty]) + pps_subpic_less_than_one_tile_slice(pps, sps, i, tx, ty, off); + else + pps_subpic_one_or_more_tiles_slice(pps, tx, ty, x_end, y_end, i, off); +} + +static void pps_single_slice_per_subpic(VVCPPS *pps, const VVCSPS *sps, int *off) +{ + if (!sps->r->sps_subpic_info_present_flag) { + pps_single_slice_picture(pps, off); + } else { + for (int i = 0; i < pps->r->pps_num_slices_in_pic_minus1 + 1; i++) + pps_subpic_slice(pps, sps, i, off); + } +} + static int pps_one_tile_slices(VVCPPS *pps, const int tile_idx, int i, int *off) { const H266RawPPS *r = pps->r; @@ -381,18 +458,22 @@ static void pps_multi_tiles_slice(VVCPPS *pps, const int tile_idx, const int i, } } -static void pps_rect_slice(VVCPPS* pps) +static void pps_rect_slice(VVCPPS *pps, const VVCSPS *sps) { - const H266RawPPS* r = pps->r; + const H266RawPPS *r = pps->r; int tile_idx = 0, off = 0; + if (r->pps_single_slice_per_subpic_flag) { + pps_single_slice_per_subpic(pps, sps, &off); + return; + } + for (int i = 0; i < r->pps_num_slices_in_pic_minus1 + 1; i++) { if (!r->pps_slice_width_in_tiles_minus1[i] && !r->pps_slice_height_in_tiles_minus1[i]) { i = pps_one_tile_slices(pps, tile_idx, i, &off); } else { pps_multi_tiles_slice(pps, tile_idx, i, &off); - } tile_idx = next_tile_idx(tile_idx, i, r); } @@ -411,14 +492,14 @@ static void pps_no_rect_slice(VVCPPS* pps) } } -static int pps_slice_map(VVCPPS *pps) +static int pps_slice_map(VVCPPS *pps, const VVCSPS *sps) { pps->ctb_addr_in_slice = av_calloc(pps->ctb_count, sizeof(*pps->ctb_addr_in_slice)); if (!pps->ctb_addr_in_slice) return AVERROR(ENOMEM); if (pps->r->pps_rect_slice_flag) - pps_rect_slice(pps); + pps_rect_slice(pps, sps); else pps_no_rect_slice(pps); @@ -444,7 +525,7 @@ static int pps_derive(VVCPPS *pps, const VVCSPS *sps) if (ret < 0) return ret; - ret = pps_slice_map(pps); + ret = pps_slice_map(pps, sps); if (ret < 0) return ret;