From patchwork Mon Mar 18 14:16:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 47166 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:958e:b0:1a3:31a3:7958 with SMTP id iu14csp1041856pzb; Mon, 18 Mar 2024 07:17:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXYzaDiJ2nCM1tq8HsUsCWoC4jRBucczKh5Bz14pgFzUPcBtEHFmgiH+vDuUHpod22GkvTuU6uW5D3SMNus/hOI2Xigr162m/R1mA== X-Google-Smtp-Source: AGHT+IEGbRDk8jHOWZUwSuQDM96WJsTLzJXgoqXi7jCH/yo35tH7Yugpd9PVhzzTNtFNQP8pC4lR X-Received: by 2002:a17:907:7294:b0:a46:b64e:58a1 with SMTP id dt20-20020a170907729400b00a46b64e58a1mr3777257ejc.25.1710771460799; Mon, 18 Mar 2024 07:17:40 -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 fi9-20020a170906da0900b00a467df32d76si3587836ejb.446.2024.03.18.07.17.40; Mon, 18 Mar 2024 07:17:40 -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=ClgYEF0o; 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 A261F68D291; Mon, 18 Mar 2024 16:17:14 +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-tyzapc01olkn2037.outbound.protection.outlook.com [40.92.107.37]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7262B68D28A for ; Mon, 18 Mar 2024 16:17:07 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ReihKpxuNa2hucb1OhG8AOdEvjwUL8zd7Chja4EXpVfNl4xbpqbYsWnCKWxIpTYRIMAKIK7WQuTvJK9uRGASgQKOq5whQFFBM3nMRal91DnvG+9fi2+VzRo9csjLv5RHD7gWqG1VRSYXGhcplXl8nUnpcKAZxnNOnDb0FPojKFoB9iqJYxKNqYyn1oduSH05ZviWvopKqC3FSmTvYBx3J2/f4HFjonMhRKj/HwnX2ztjYTSDYOTBBS5p3aouxB+i6/y755+mSDGuB7gYKiwijJFVOZpRuiq7lhzBUngs4EibWIm/fdLmXetPPo4S8H0f7S86bzB8LR1bDcHMu9VC8A== 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=NccN9OGv5/Vjb22YjTIMkzPjvBpaDy7Fi2jZcE9hx30=; b=GIgjRLEVUIb0g1eEhTe20SwCqP98cs9aNZ89qjMbP1yAmRYpZ5Jxf+vw0yGcm5yxEtY5qh2dLWI3WGUOyZToRMxZAYPTvg/2DzVk+axBhv/dHhzFC0xZNsc/naB6mSwOIHnlGkyaiF9WYK7yBhRdyHE1vrR2A0C58k5BrQ/KFyyYB564W7vp77sF0KSAC7JEC0qQd38CjK68IHVV/2XJeRhczp3UjSodsQ8GWs36WR3+FUOyV8Ol/gjpz4H/Op3e+1Q0NafgmFxi9wTrhEkINQ5dmtGRJOgNp2i+Ot6kskysskc2/3ERxM2F/jcoj33ZmzkeHpQbTTHrzWrXsg1dhg== 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=NccN9OGv5/Vjb22YjTIMkzPjvBpaDy7Fi2jZcE9hx30=; b=ClgYEF0owsqBpF2nA7JWkFCFmDhL23VHBrY4qUWWhPgs4Y0CXWeJXarHMlGCCBGNa6its1aw+CTMRvTyT0LB8Bno4/Ss/yvAW1Nq7bPfE0tuM4Mn90IofXTdkVvgqVB15/HH9Ws6GQs11jBj+iQG4Ga481NP8raMGCkbl/I9Q3XM63riJfY6/mQqZRsEqz6+HNc5JtPIpC5gnKJxgXCV7RGWGUkMi8CAlT3/yVXIdn+DAlfeYoY00Sa+NnoCYWXtpxLYPAMZR3wR2a3ZOMHGfrR3AF8Gw1X38QHJElV7C/HrZML43wVlkyCaMLe6blnRHxXRflvcR3SkGKB49di8rA== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by JH0PR06MB6604.apcprd06.prod.outlook.com (2603:1096:990:3f::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26; Mon, 18 Mar 2024 14:17:00 +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.7386.025; Mon, 18 Mar 2024 14:17:00 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Mon, 18 Mar 2024 22:16:15 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240318141626.3375-1-nuomi2021@gmail.com> References: <20240318141626.3375-1-nuomi2021@gmail.com> X-TMN: [5AP5fgpVJQmG4gp7d7zCn5hSUuY1iBgt] X-ClientProxiedBy: TYAPR01CA0085.jpnprd01.prod.outlook.com (2603:1096:404:2c::25) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20240318141626.3375-4-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|JH0PR06MB6604:EE_ X-MS-Office365-Filtering-Correlation-Id: 1856dc95-c446-4e63-07f4-08dc47561367 X-MS-Exchange-SLBlob-MailProps: Vs63Iqe4sQndKyqL8642oOb5kiEsziF14ZtWVIA1je5Ld0sXpFS5t1BNpJsdLjQu8KisQUtpI3QdXOZpxZZwWqocTM40/poVsSNAmUOgpleIEHg5ExgFD2VNMvOxqz/IW7eaSaXz+gf3yHtyz1WEZc2vQkkTRUKhJQq08bkVpFy6rlswagMpBafvZwd7nB0mmizlibyTXUslZrDELlvqTSIFUWCUl8pzKaaTXe2r6C6YeZtccHSruvwqmeivxsnnCrYd7VPB1dbW3ZlvQzQ31xrHoE1/+mWZ3QrEovlqhtqaWDbsexR5LOFYSOSnDVPLu4cp3Tqv797d3l42UGuB9nux1pEaw2jJCzaxLXAF8Y6QfpGyLvitTjjIvqdcH1OSo/DMMWeZWzaMNhcpskHuPC6kbkO8/Kif9S9BpbNsIx4vbXy+tY9gS887iM+gl8xzYubVjxUNrHgFd38lmzLX6eqI+NSiE21J8jmk+yQjnr02kp0mhCt2fiLPV36sMAvTvZ2AEbXi5/bNafJjfLZCt/XMSjqE779zqcO0wcVf5AbP7/URzVqwcB+CxkIj3ZgLtqIini++TfUR5JE21VD+pLyNcCvNJRw4UaEM045bwpiC6rHCej/acToFghhjFEzvDxBdG78azuoCmk8nuHXzGqy0qdJAb2ldmhysCiB6Em9H8oKGKJYW/FoJZke+QRKy9+s0VyiY0/Qa39fucr7tIiyZ4tbkd6Z+mDalo18mh6I= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qimgy+rcU8KAYxMYjt/QNvOOA/djVqw7cw6sciGf+T5KzevtMum38iB36UKpFavE0e5fgU2ARwzE6mHWF3Ysjz+HevuLJEwUcGc3V0vbMcxTYXPlryHvvalDNiqXN9iItGGI8Eh7IHikxIJ6a0SMOg5BmsoDddDIlHiVs1iQHAP3GaePekLCzSE4Z7mybvSmju88whGepAuK6NnpT9Kh0d8rod4Vnlj95J77KDvWAvTUeG9j9Gb3zT4QTik66zS3VFpHuH86/WZrFmGPtDCG7CCYQDMu3ZtvWhasv6PdB6UaC8aj8/RNI4PrfxglK65h2NFsrW9NQ9P55O24gChVQ9LnF8J2a0R3S0e81Aw5kFYUwDe+iH2Z1T7/2VcF/PDCaTi3HOBgcVrS9sNm3gxqzqpyhyn8cp9eLcBhzQrM0F6zvFoGxlHRp0Bz7rTWz4efUApkUhruN04n4+Xwtd9LbdSWs2XA14ihN0tj+dkX6RZZ2Q9VzjlSZEjDJUJz1J4ND3W3Y3C3KZVKA3QF2fXMlS+cnbiWXjxXObySVVAQd9lgnoEXxfzrq0dSRoSlD6fy9WzN/LRDA4tJPAGLhZodgQ6SYPryAPPMSoxFFXLkKYk= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hp1cFX8UneyanJMTTv2OlUY5oXUekN20nk76jwtUiKnUx4OrFhUVp7KHgZZd3OpBCtSdhquV868FJuaXqbkqx/1CeBN6il4VbvNsxO+5Aefluki9kaCx9s4T8LNwhBbFZLCwoTkRwSsXMnKXrmtBYTOguhhyrPoHEwE5ePM1Rs5i9xNjigID4VObhvPJCIzq3fgmyyeIAmDGai0QADym/VOM9eS7OynPiRUF1ndnC8tJ2MTAcdDMdLtjTk2xhqBAS0FzBc2j6xZjz5rh26sqg/hkmO2jh6hfkYr7rQKR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Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Mar 2024 14:17:00.0276 (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: JH0PR06MB6604 Subject: [FFmpeg-devel] [PATCH 03/14] 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: YXIbhfJvM4ap 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 15368502d7..9fa7e0eec8 100644 --- a/libavcodec/cbs_h266_syntax_template.c +++ b/libavcodec/cbs_h266_syntax_template.c @@ -2118,9 +2118,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 7972803da6..bb13b04a5d 100644 --- a/libavcodec/vvc/vvc_ps.c +++ b/libavcodec/vvc/vvc_ps.c @@ -343,6 +343,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_multi_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_multi_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; @@ -378,18 +455,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); } @@ -408,14 +489,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); @@ -441,7 +522,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;