From patchwork Wed Jul 5 11:38:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 42447 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp5717329pzh; Wed, 5 Jul 2023 04:38:42 -0700 (PDT) X-Google-Smtp-Source: APBJJlEtvCheUw4NDebUM93krp+muoe/eL3vH+TCTiG4r+P4+KxWhIVicWidytG0yl0RO6JgXRVT X-Received: by 2002:a05:6402:60a:b0:51e:1927:6ade with SMTP id n10-20020a056402060a00b0051e19276ademr5121203edv.11.1688557122039; Wed, 05 Jul 2023 04:38:42 -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 f5-20020a50ee85000000b0051e29791767si145247edr.124.2023.07.05.04.38.41; Wed, 05 Jul 2023 04:38:42 -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=IiVbJMq0; 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 9127068C5F3; Wed, 5 Jul 2023 14:38:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01olkn2028.outbound.protection.outlook.com [40.92.107.28]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0336B68C5D7 for ; Wed, 5 Jul 2023 14:38:30 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fr4mv9k++E0yo9SH8mzww5JgUUsEA48bIIuzZpJ8RRYsql+jow/QnE6/B/OvQqhvpI3xk+QSdSImJdjeBWpx3lz024ePw0qHPkE0b22+en4qCkAIwQ9UfHo2MBgSwPDs/M/oL8Hmo6elBKaaX47hGz3Es3+XS02UmIaUlnplVqNakdIhlVLNh2fBHx5ogXbq5sUrVc2sS+INqcQee1eU4U+hxvcqKPkB7TuUmiDTz5kgJhEg3UNamRIkVRz8ZvkRdC0kCZRCBBouO7qvvfqqDlbStMV7G/G2tnKwRMgtke3m7IR93s64qoPwvIrc7LTSf4389MMkHqG8vmN5OWX2gA== 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=lOiHCjas1OnwZmNTK2s8fGFQXsjbjREizcBLCYzyVeM=; b=lUkvkHpNL1A1KfK5T5itfx9chTCt2hkKy2u+RayikMeHOIE3gZ4Ki+c7TfVCJKOib1Go+WSIrpsxex5czUNlxPpA5nCFXA+EVKTGtcV5SNGeTIQmAvFMidkk85mZhGCbG/iVR0G+wIdx/0slT6QWdcAEMZIouSA/KMLLyDUr8Br+oiduNj1TsQ+A2JUMTWIJYJSc++81/c8i0O1Xr0nFTw4ifH9Xbk7pStWtbH9mfl+aA4gZQZs0jVtu2j/MqRrpirHPc7Iv+jJkn6J6HpanmvsjscqVUzwXVUoJpqtUzxqGb8pmRyXybZKMxR0VeZ80Qk44Kt3i2jaiHV2hX1Xaow== 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=lOiHCjas1OnwZmNTK2s8fGFQXsjbjREizcBLCYzyVeM=; b=IiVbJMq0oJ1rp0jdjGilWGsyRB/1k0v1rcVTi9qOH60gbaupR8+K5bnXRk7x/Flvc1JJE8qY1c+PNeMUG+3Y1sfSDgS9c40JY4Wnkr4BWbyQ/pgsXB4O7zfTALjehxBKBkcNYa4kxqFNDGC/BY9V7LCkFfm8WNDvpax8kxv/XfoJOfMxqF9zzK4FQjo/07xDX7lF6mkpJrJRkoZyA3UDvr8jFzGCF7GvcMljZuuOw/6fJND3adJ1tKelMXM32M1bCbqcGxVPM8lyR8SNFjf+5uZUerpJJ2rX9cIhx6+PDlcZJFxKpAMmpuz7VDlzE01wTnn2mXONgS93U9xSmsUCEQ== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by SEYPR06MB5816.apcprd06.prod.outlook.com (2603:1096:101:b0::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Wed, 5 Jul 2023 11:38:26 +0000 Received: from TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::7d80:1294:fd54:a7f]) by TYSPR06MB6433.apcprd06.prod.outlook.com ([fe80::7d80:1294:fd54:a7f%7]) with mapi id 15.20.6544.024; Wed, 5 Jul 2023 11:38:26 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Wed, 5 Jul 2023 19:38:07 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 X-TMN: [ZDQ54/zLWZZpHKHO6GCocZIWzDQm+rLk] X-ClientProxiedBy: TYCP286CA0263.JPNP286.PROD.OUTLOOK.COM (2603:1096:400:455::11) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20230705113807.3999-1-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|SEYPR06MB5816:EE_ X-MS-Office365-Filtering-Correlation-Id: 863c8aa0-0002-466f-44cd-08db7d4c564d X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UuI5si5J5jdEtbpCgIYoZStEs1D9DNdJYcJVUCXl0eEOzUqbne4gOQNaAxxYuokY74GAsiDv1JTkSJMWU0UknSa+Wr41LQBQ0sbr/uqL6cg6zh2E5JWwZlS3I1aXUjxVCNJpDJMSHUwrmrTCyP5PuYclzF20FwD6pSHSC4gZQ1rFzGVp3QXbEmGvW1jdf1dC+VCzqa5lg+vjKPBfDKuJW2xP0mfhJvowvcgaVpvwonQi01SDQaPNE4LHYlTNOJ/7uo+a4wsVDhC7F48EjwggR7SfPYTvXH6V6XXMQoznWltGdLB4YbLWp2lwa9xWeM0UGZXNkN4LoUNTB/2bYQS0WhrzIg68VSv4EUMI2ZUF9hmc7FBi7ky+/VRhtDWqmLNYR10uQkGTNcmZJJ8dMdaKg0d1NobfmmcvdtkmvW1z3L0R9AAu2ikKkBsRsHIjAYDjLPzjBsBfPj2B67lYm5A2fNZfk9TBRWbqNiOgjCHvecZGWChbrDn/1OzclpLRyfmaTV9NXs6zB8MPOIi581MOemXrxXVPQnH80LZR/0iJN37+TXqJ0bWsNAqMZPbcsTZazPG/xCDVyY/sbzRT27ZqCmWTSQ3Fdf51HiFubrsXKQOePRe5CmV8mpvD/padz697eMX/+thV9atbeclwBtOrcQ== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xwxLe0rwijb1tC5ZMeaNMGxgFtkS64e4jS0zOeHk3zIbGPRgojpH3geWYRUqjVPAUtodFm/XoQ0+2Dcd3x3iqLM8pQrIYiPl6MA0YeilqlQmPF+QnZhXoJEceh11511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HGeMNoQefywNBSfn7GIPPuh2LuYaKDrnMCGAdn1k1XARxyzOT8E1upFaB1tm X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 863c8aa0-0002-466f-44cd-08db7d4c564d X-MS-Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2023 11:38:26.0269 (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: SEYPR06MB5816 Subject: [FFmpeg-devel] [PATCH] cbs_h266: add range extension support 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: frankplow Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 2UKTsg73kZuz From: frankplow --- libavcodec/cbs_h266.h | 18 ++++++ libavcodec/cbs_h266_syntax_template.c | 79 +++++++++++++++++++++++++-- 2 files changed, 93 insertions(+), 4 deletions(-) diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h index e33d08a0f5..40aba9eb13 100644 --- a/libavcodec/cbs_h266.h +++ b/libavcodec/cbs_h266.h @@ -120,6 +120,13 @@ typedef struct H266GeneralConstraintsInfo { uint8_t gci_no_virtual_boundaries_constraint_flag; uint8_t gci_num_reserved_bits; uint8_t gci_reserved_zero_bit[255]; + + uint8_t gci_all_rap_pictures_constraint_flag; + uint8_t gci_no_extended_precision_processing_constraint_flag; + uint8_t gci_no_ts_residual_coding_rice_constraint_flag; + uint8_t gci_no_rrc_rice_extension_constraint_flag; + uint8_t gci_no_persistent_rice_adaptation_constraint_flag; + uint8_t gci_no_reverse_last_sig_coeff_constraint_flag; } H266GeneralConstraintsInfo; typedef struct H266RawProfileTierLevel { @@ -451,6 +458,15 @@ typedef struct H266RawSPS { uint8_t sps_extension_flag; + uint8_t sps_range_extension_flag; + uint8_t sps_extension_7bits; + + uint8_t sps_extended_precision_flag; + uint8_t sps_ts_residual_coding_rice_present_in_sh_flag; + uint8_t sps_rrc_rice_extension_flag; + uint8_t sps_persistent_rice_adaptation_enabled_flag; + uint8_t sps_reverse_last_sig_coeff_enabled_flag; + H266RawExtensionData extension_data; } H266RawSPS; @@ -734,6 +750,8 @@ typedef struct H266RawSliceHeader { uint8_t sh_sign_data_hiding_used_flag; uint8_t sh_ts_residual_coding_disabled_flag; + uint8_t sh_ts_residual_coding_rice_idx_minus1; + uint8_t sh_reverse_last_sig_coeff_flag; uint16_t sh_slice_header_extension_length; uint8_t sh_slice_header_extension_data_byte[256]; diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c index 485c02f590..893fa55369 100644 --- a/libavcodec/cbs_h266_syntax_template.c +++ b/libavcodec/cbs_h266_syntax_template.c @@ -61,7 +61,7 @@ static int FUNC(general_constraints_info) (CodedBitstreamContext *ctx, RWContext *rw, H266GeneralConstraintsInfo *current) { - int err, i; + int err, i, num_additional_bits_used; flag(gci_present_flag); if (current->gci_present_flag) { @@ -149,7 +149,25 @@ static int FUNC(general_constraints_info) (CodedBitstreamContext *ctx, flag(gci_no_ladf_constraint_flag); flag(gci_no_virtual_boundaries_constraint_flag); ub(8, gci_num_reserved_bits); - for (i = 0; i < current->gci_num_reserved_bits; i++) { + if (current->gci_num_reserved_bits > 5) { + flag(gci_all_rap_pictures_constraint_flag); + flag(gci_no_extended_precision_processing_constraint_flag); + flag(gci_no_ts_residual_coding_rice_constraint_flag); + flag(gci_no_rrc_rice_extension_constraint_flag); + flag(gci_no_persistent_rice_adaptation_constraint_flag); + flag(gci_no_reverse_last_sig_coeff_constraint_flag); + num_additional_bits_used = 6; + } else { + infer(gci_all_rap_pictures_constraint_flag, 0); + infer(gci_no_extended_precision_processing_constraint_flag, 0); + infer(gci_no_ts_residual_coding_rice_constraint_flag, 0); + infer(gci_no_rrc_rice_extension_constraint_flag, 0); + infer(gci_no_persistent_rice_adaptation_constraint_flag, 0); + infer(gci_no_reverse_last_sig_coeff_constraint_flag, 0); + num_additional_bits_used = 0; + } + + for (i = 0; i < current->gci_num_reserved_bits - num_additional_bits_used; i++) { flags(gci_reserved_zero_bit[i], 1, i); } } @@ -963,6 +981,23 @@ static int FUNC(vps) (CodedBitstreamContext *ctx, RWContext *rw, return 0; } +static int FUNC(sps_range_extension)(CodedBitstreamContext *ctx, RWContext *rw, + H266RawSPS *current) +{ + int err; + + flag(sps_extended_precision_flag); + if (current->sps_transform_skip_enabled_flag) { + flag(sps_ts_residual_coding_rice_present_in_sh_flag); + } else { + infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0); + } + flag(sps_rrc_rice_extension_flag); + flag(sps_persistent_rice_adaptation_enabled_flag); + flag(sps_reverse_last_sig_coeff_enabled_flag); + + return 0; +} static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, H266RawSPS *current) @@ -1518,9 +1553,33 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, } else { CHECK(FUNC(vui_parameters_default) (ctx, rw, ¤t->vui)); } + flag(sps_extension_flag); - if (current->sps_extension_flag) - CHECK(FUNC(extension_data) (ctx, rw, ¤t->extension_data)); + if (current->sps_extension_flag) { + flag(sps_range_extension_flag); + ub(7, sps_extension_7bits); + + if (current->sps_range_extension_flag) { + CHECK(FUNC(sps_range_extension)(ctx, rw, current)); + } else { + infer(sps_extended_precision_flag, 0); + infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0); + infer(sps_rrc_rice_extension_flag, 0); + infer(sps_persistent_rice_adaptation_enabled_flag, 0); + infer(sps_reverse_last_sig_coeff_enabled_flag, 0); + } + } else { + infer(sps_range_extension_flag, 0); + infer(sps_extension_7bits, 0); + infer(sps_extended_precision_flag, 0); + infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0); + infer(sps_rrc_rice_extension_flag, 0); + infer(sps_persistent_rice_adaptation_enabled_flag, 0); + infer(sps_reverse_last_sig_coeff_enabled_flag, 0); + } + + if (current->sps_extension_7bits) + CHECK(FUNC(extension_data)(ctx, rw, ¤t->extension_data)); CHECK(FUNC(rbsp_trailing_bits) (ctx, rw)); @@ -3005,6 +3064,18 @@ static int FUNC(slice_header) (CodedBitstreamContext *ctx, RWContext *rw, flag(sh_ts_residual_coding_disabled_flag); else infer(sh_ts_residual_coding_disabled_flag, 0); + + if (!current->sh_ts_residual_coding_disabled_flag && + sps->sps_ts_residual_coding_rice_present_in_sh_flag) + ub(3, sh_ts_residual_coding_rice_idx_minus1); + else + infer(sh_ts_residual_coding_rice_idx_minus1, 0); + + if (sps->sps_reverse_last_sig_coeff_enabled_flag) + flag(sh_reverse_last_sig_coeff_flag); + else + infer(sh_reverse_last_sig_coeff_flag, 0); + if (pps->pps_slice_header_extension_present_flag) { ue(sh_slice_header_extension_length, 0, 256); for (i = 0; i < current->sh_slice_header_extension_length; i++)