From patchwork Wed Jul 5 14:01:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nuo Mi X-Patchwork-Id: 42451 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1e:b0:12b:9ae3:586d with SMTP id c30csp5809325pzh; Wed, 5 Jul 2023 07:01:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlHDFb4cyw0r5dHhr2y19tUxxS8xnh9W/4mIdDI8p0D3g6ognRAkt7OCqg0Ap3xCmeVSJ8sW X-Received: by 2002:a50:fc12:0:b0:51d:95f2:ee76 with SMTP id i18-20020a50fc12000000b0051d95f2ee76mr11524633edr.27.1688565712114; Wed, 05 Jul 2023 07:01:52 -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 e26-20020a056402105a00b0051debcd957esi8119269edu.351.2023.07.05.07.01.46; Wed, 05 Jul 2023 07:01:52 -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=gKARVrSQ; 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 05D7768C654; Wed, 5 Jul 2023 17:01:43 +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-tyzapc01olkn2051.outbound.protection.outlook.com [40.92.107.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8E6AC68C585 for ; Wed, 5 Jul 2023 17:01:35 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H98/q+tWiTGTWfsqrndKI5uBfhl3mcf5cXUkFmZjxsEnoJYqyqqBrTR8zcrABL9cM8NmKaZvBfpO8/q0bztB58AJwPndT2kmuykMKZ+qeYbOSHsQqR6sKCf52f05hpPz0axPYrBwgH6FxTdAhx80bEjL10W0xvxJjnmO6OCPt1j7b39NVs3G7/MkbcAHGY11352YGR+WC1VnYQjSxZZqs0YZyAM5TtdEhV6fnPZegDgeTl3hs1c8l+uYFDl5m/r/VdXfcSEkfZYb1N61A4y+Zh8FJH75z3sOc3RlETpe5KD3uBjgTScGWHsp5M0G7+ElZXUbw4/9Mt25n5hBvhhAbA== 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=8am3Shojwv9iNDWbetXBmBMjJzkgZSlPgzxL6wY0noU=; b=n77z9yWLj0QDHy6Fj4hYCArJbtgEwAer2D05iX3zMRuWk/8MpCxbs0vep0Mpye/QsG87Jymwfz8Qav3wXACOyvL4hc9fM6Uezpc1RQRnDS1BMNBHk/DAzuLtMVcoRUApOUU5k+CPjEBNlyx64tdw5rCOACFakZmddYNmdBsPWPZXhO4AfmbtpCrIrsYmRBivQlOx2WIbgHx8XxULF56dnPz/219t18RmX4pvNAtS+9Ag0g3kB5CsiDWy2AKWeAvB6HemDBdDqw+MGhQlNha9vdkBGznNVojZooiByAiLdDeR+Aru4+iIwRyv1YwkWdkl6xD2xwwBGDGgYrGsVczCXQ== 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=8am3Shojwv9iNDWbetXBmBMjJzkgZSlPgzxL6wY0noU=; b=gKARVrSQzZ4Vf1XhJ2ZzXxwjIWzZnUqOzWafDyyO6/sxPkNwBBvSRL022XoeScxjyAh35tkHk+YHwSPwKtgXYn76ZFiP7Zu90FdIR/seDyeAjamm9gR4Lbm6I747/+P6nhwL+UIKST4k02y9edc6tl7W5TuQpQN5b9GoxHOZbvPUJAkgf2QLhWA6FXzAlL4gKuyfBcNUroKq0fJAEeX4XTwo9lgWBbFfNdEe28Fvm8eWAyK71aQ+FVcE4eu78AsH211+Dax7jGmIYYwWc53rG/DQIVxOKocqTo4C/8lkFTxfaYf1ijxMbEQ2lQCaZw+1BBT9WbV6K19imDyRCKglNQ== Received: from TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) by TYZPR06MB4542.apcprd06.prod.outlook.com (2603:1096:400:66::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Wed, 5 Jul 2023 14:01:30 +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 14:01:30 +0000 From: Nuo Mi To: ffmpeg-devel@ffmpeg.org Date: Wed, 5 Jul 2023 22:01:13 +0800 Message-ID: X-Mailer: git-send-email 2.25.1 X-TMN: [HquOWhDKLIZcbOXXAXC/vbveDn49KXw9] X-ClientProxiedBy: TYXPR01CA0043.jpnprd01.prod.outlook.com (2603:1096:403:a::13) To TYSPR06MB6433.apcprd06.prod.outlook.com (2603:1096:400:47a::6) X-Microsoft-Original-Message-ID: <20230705140113.27294-1-nuomi2021@gmail.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 2 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TYSPR06MB6433:EE_|TYZPR06MB4542:EE_ X-MS-Office365-Filtering-Correlation-Id: ce303dcf-6652-4407-80d5-08db7d6054ec X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gPpBRwCMFrZmupQ2LOZcxTPFhMJxO+FABsoETLYr4fgzGCtULExfjOCBqXiAHQZlQAGieJeXJ1EgpSphcFc6VY4aGcxEhGdKTXNBYVfRkN0C85U8kxNw6HBlEt/rCCOua/WKYsnqUO73ZVBSOUROUTtW2ylHfOnmL73nB5W6U1J8oe1VGhqzIgGba5ZO5gPvqEFqSuwMKmAEqxl3YdNq0Wz2vKcE6TY60KclF0/FhOMG6KXYGzEB9J9sg7SO+s1D6Ya3khyWkO88M1xpCQ3CVs/AefMF5j1nRFCiiJMtD7oc7XuyCLFpELhnRdL4GELaMfFVlu5Bn5CmZzzJL0aRdwlAqpzVb9j9wwjOO+CgshGWtxBXkKEnWS0yC6ZtUPpOTOjlHdD97t8LduAqXb7247ceZryaGojwGXBnAbLlI5ZGBF9qBpBiCXUn20/gzUmMPQPC0z+bOPbqApNAnRpOpCP4dp9zAfCreNko5k3+pMAAp3RpNytKVq+GIMx4DoPJt8vf03LFGVA+B67vi9eD4mZmGU06ktS7ApGmj5E1wIDA7Nb9qNHcVwJDPFIjCvEi11R7F+7SaIB7WnaMDdVJ6drXoYKVYind7SPT10+XcTRn/IbDJfZIJ/nqgOFi6LSMy5yYvXQIslxlc5Qhl5XKfg1vek06qlgSUX/W5S7L4BKpLp8kD9tGOobPZOsUhA0u X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: A7Qgq0O00UupTTHVzSl0eHRuGULn1vduc5GC4SPZqhJsIL+0k0Pix9T5LcuXN1deMAJJw4r5Z33zuDSPFeqfOVqXSX6KWQ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QCT/bcbgRyVLACVQ4tYF6GAuUDPx5QwfX2Xqi5o+fTHnK+6GjJX/4LC6kHAzpzGeQqfxR7gU2rPiawO6BNTzFmTswuBopQnEtEC0m2kHe5/da+Vm1t5z5Gf X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce303dcf-6652-4407-80d5-08db7d6054ec X-MS-Exchange-CrossTenant-AuthSource: TYSPR06MB6433.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2023 14:01:30.1327 (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: TYZPR06MB4542 Subject: [FFmpeg-devel] [PATCH v2] 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 , Nuo Mi Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: nh+bDa4uDFt2 From: frankplow example clips: * 12b444vvc1_E_Sony_2 * 12b444Ietsrc_A_Kwai_2 * 10b444P16_D_Sony_2 * 12b444Iepp_A_Sharp_2 * 12b444SPetsrc_B_Kwai_2 Co-authored-by: Nuo Mi --- libavcodec/cbs_h266.h | 23 +++++++- libavcodec/cbs_h266_syntax_template.c | 81 +++++++++++++++++++++++++-- 2 files changed, 96 insertions(+), 8 deletions(-) diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h index e33d08a0f5..15d3466d8f 100644 --- a/libavcodec/cbs_h266.h +++ b/libavcodec/cbs_h266.h @@ -118,8 +118,16 @@ typedef struct H266GeneralConstraintsInfo { uint8_t gci_no_lmcs_constraint_flag; uint8_t gci_no_ladf_constraint_flag; uint8_t gci_no_virtual_boundaries_constraint_flag; - uint8_t gci_num_reserved_bits; - uint8_t gci_reserved_zero_bit[255]; + + uint8_t gci_num_additional_bits; + uint8_t gci_reserved_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 +459,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 +751,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..6d78bbc8db 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) { @@ -148,10 +148,27 @@ static int FUNC(general_constraints_info) (CodedBitstreamContext *ctx, flag(gci_no_lmcs_constraint_flag); 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++) { - flags(gci_reserved_zero_bit[i], 1, i); + ub(8, gci_num_additional_bits); + if (current->gci_num_additional_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_additional_bits - num_additional_bits_used; i++) + flags(gci_reserved_bit[i], 1, i); } while (byte_alignment(rw) != 0) fixed(1, gci_alignment_zero_bit, 0); @@ -963,6 +980,22 @@ 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 +1551,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 +3062,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++)