From 303e89bef5410f068832b6a34c37035fa7aad36b Mon Sep 17 00:00:00 2001
From: Nuo Mi <nuomi2021@gmail.com>
Date: Sun, 22 Nov 2020 10:05:42 +0800
Subject: [PATCH] WIP: h266 cbs

---
 libavcodec/cbs_h2645.c |  66 ++++++
 libavcodec/cbs_h266.h  | 442 +++++++++++++++++++++++++++++++++++++++++
 libavcodec/vvc.h       |  20 ++
 3 files changed, 528 insertions(+)
 create mode 100644 libavcodec/cbs_h266.h

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index b6d77dd17f..60e41d50e3 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -24,11 +24,13 @@
 #include "cbs_internal.h"
 #include "cbs_h264.h"
 #include "cbs_h265.h"
+#include "cbs_h266.h"
 #include "h264.h"
 #include "h264_sei.h"
 #include "h2645_parse.h"
 #include "hevc.h"
 #include "hevc_sei.h"
+#include "vvc.h"
 
 
 static int cbs_read_ue_golomb(CodedBitstreamContext *ctx, GetBitContext *gbc,
@@ -681,6 +683,9 @@ cbs_h2645_replace_ps(4, PPS, pps, pic_parameter_set_id)
 cbs_h2645_replace_ps(5, VPS, vps, vps_video_parameter_set_id)
 cbs_h2645_replace_ps(5, SPS, sps, sps_seq_parameter_set_id)
 cbs_h2645_replace_ps(5, PPS, pps, pps_pic_parameter_set_id)
+cbs_h2645_replace_ps(6, VPS, vps, vps_video_parameter_set_id)
+cbs_h2645_replace_ps(6, SPS, sps, sps_seq_parameter_set_id)
+cbs_h2645_replace_ps(6, PPS, pps, pps_pic_parameter_set_id)
 
 static int cbs_h264_read_nal_unit(CodedBitstreamContext *ctx,
                                   CodedBitstreamUnit *unit)
@@ -1508,6 +1513,51 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[] = {
     CBS_UNIT_TYPE_END_OF_LIST
 };
 
+static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = {
+    CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_VPS, H266RawVPS, extension_data.data),
+    CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_SPS, H266RawSPS, extension_data.data),
+    CBS_UNIT_TYPE_INTERNAL_REF(HEVC_NAL_PPS, H266RawPPS, extension_data.data),
+
+    CBS_UNIT_TYPE_POD(HEVC_NAL_AUD, H266RawAUD),
+
+    {
+        // Slices of non-IRAP pictures.
+        .nb_unit_types         = CBS_UNIT_TYPE_RANGE,
+        .unit_type_range_start = HEVC_NAL_TRAIL_N,
+        .unit_type_range_end   = HEVC_NAL_RASL_R,
+
+        .content_type   = CBS_CONTENT_TYPE_INTERNAL_REFS,
+        .content_size   = sizeof(H266RawSlice),
+        .nb_ref_offsets = 1,
+        .ref_offsets    = { offsetof(H266RawSlice, data) },
+    },
+
+    {
+        // Slices of IRAP pictures.
+        .nb_unit_types         = CBS_UNIT_TYPE_RANGE,
+        .unit_type_range_start = HEVC_NAL_BLA_W_LP,
+        .unit_type_range_end   = HEVC_NAL_CRA_NUT,
+
+        .content_type   = CBS_CONTENT_TYPE_INTERNAL_REFS,
+        .content_size   = sizeof(H266RawSlice),
+        .nb_ref_offsets = 1,
+        .ref_offsets    = { offsetof(H266RawSlice, data) },
+    },
+
+    {
+        .nb_unit_types  = 2,
+        .unit_types     = {
+            HEVC_NAL_SEI_PREFIX,
+            HEVC_NAL_SEI_SUFFIX
+        },
+        .content_type   = CBS_CONTENT_TYPE_COMPLEX,
+        .content_size   = sizeof(H266RawSEI),
+        .content_free   = &cbs_h266_free_sei,
+    },
+
+    CBS_UNIT_TYPE_END_OF_LIST
+};
+
 const CodedBitstreamType ff_cbs_type_h264 = {
     .codec_id          = AV_CODEC_ID_H264,
 
@@ -1540,6 +1590,22 @@ const CodedBitstreamType ff_cbs_type_h265 = {
     .close             = &cbs_h265_close,
 };
 
+const CodedBitstreamType ff_cbs_type_h266 = {
+    .codec_id          = AV_CODEC_ID_VVC,
+
+    .priv_data_size    = sizeof(CodedBitstreamH266Context),
+
+    .unit_types        = cbs_h266_unit_types,
+
+    .split_fragment    = &cbs_h2645_split_fragment,
+    .read_unit         = &cbs_h266_read_nal_unit,
+    .write_unit        = &cbs_h266_write_nal_unit,
+    .assemble_fragment = &cbs_h2645_assemble_fragment,
+
+    .flush             = &cbs_h266_flush,
+    .close             = &cbs_h266_close,
+};
+
 int ff_cbs_h264_add_sei_message(CodedBitstreamFragment *au,
                                 H264RawSEIPayload *payload)
 {
diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h
new file mode 100644
index 0000000000..9ffc6aa0df
--- /dev/null
+++ b/libavcodec/cbs_h266.h
@@ -0,0 +1,442 @@
+/*
+ * 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
+ */
+
+#ifndef AVCODEC_CBS_H266_H
+#define AVCODEC_CBS_H266_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "cbs_h2645.h"
+#include "vvc.h"
+
+enum {
+    // This limit is arbitrary - it is sufficient for one message of each
+    // type plus some repeats, and will therefore easily cover all sane
+    // streams.  However, it is possible to make technically-valid streams
+    // for which it will fail (for example, by including a large number of
+    // user-data-unregistered messages).
+    H266_MAX_SEI_PAYLOADS = 64,
+};
+
+typedef struct H266RawNALUnitHeader {
+    uint8_t nuh_layer_id;
+    uint8_t nal_unit_type;
+    uint8_t nuh_temporal_id_plus1;
+} H266RawNALUnitHeader;
+
+typedef struct H266RawProfileTierLevel {
+    uint8_t general_profile_idc;
+    uint8_t general_tier_flag;
+    uint8_t general_level_idc;
+    uint8_t ptl_frame_only_constraint_flag;
+    uint8_t ptl_multilayer_enabled_flag;
+    uint8_t gci_present_flag;
+    /*TODO: add gci_xxx */
+    uint8_t ptl_sublayer_level_present_flag[VVC_MAX_SUB_LAYERS - 1];
+    uint8_t sublayer_level_idc[VVC_MAX_SUB_LAYERS - 1];
+    uint8_t ptl_num_sub_profiles;
+    uint32_t general_sub_profile_idc[256];
+} H266RawProfileTierLevel;
+
+typedef struct H266RawExtensionData {
+    uint8_t     *data;
+    AVBufferRef *data_ref;
+    size_t       bit_length;
+} H266RawExtensionData;
+
+typedef struct H266RawVPS {
+    H266RawNALUnitHeader nal_unit_header;
+
+    uint8_t vps_video_parameter_set_id;
+
+    uint8_t vps_max_layers_minus1;
+    uint8_t vps_max_sublayers_minus1;
+    /*TODO add more*/
+    H266RawExtensionData extension_data;
+} H266RawVPS;
+
+typedef struct H266RawSPS {
+    H266RawNALUnitHeader nal_unit_header;
+
+    uint8_t sps_video_parameter_set_id;
+    uint8_t sps_max_sublayers_minus1;
+    uint8_t sps_chroma_format_idc;
+    uint8_t sps_log2_ctu_size_minus5;
+    uint8_t sps_ptl_dpb_hrd_params_present_flag;
+    H266RawProfileTierLevel profile_tier_level;
+    uint8_t sps_gdr_enabled_flag;
+    uint8_t sps_ref_pic_resampling_enabled_flag;
+    uint8_t sps_res_change_in_clvs_allowed_flag;
+
+    uint16_t sps_pic_width_max_in_luma_samples;
+    uint16_t sps_pic_height_max_in_luma_samples;
+
+    uint8_t sps_conformance_window_flag;
+    uint16_t sps_conf_win_left_offset;
+    uint16_t sps_conf_win_right_offset;
+    uint16_t sps_conf_win_top_offset;
+    uint16_t sps_conf_win_bottom_offset;
+
+    uint8_t sps_subpic_info_present_flag;
+    uint8_t sps_num_subpics_minus1;
+
+    // TODO: add subpics related
+    // uint8_t sps_independent_subpics_flag;
+
+	uint8_t sps_bitdepth_minus8;
+	uint8_t sps_entropy_coding_sync_enabled_flag;
+    uint8_t sps_entry_point_offsets_present_flag;
+
+    uint8_t sps_log2_max_pic_order_cnt_lsb_minus4;
+    uint8_t sps_poc_msb_cycle_len_minus1;
+
+    // TODO: add dpb information here
+    uint8_t sps_log2_min_luma_coding_block_size_minus2;
+    uint8_t sps_partition_constraints_override_enabled_flag;
+	uint8_t sps_log2_diff_min_qt_min_cb_intra_slice_luma;
+	uint8_t sps_max_mtt_hierarchy_depth_intra_slice_luma;
+
+    uint8_t sps_qtbtt_dual_tree_intra_flag;
+	uint8_t sps_log2_diff_min_qt_min_cb_intra_slice_chroma;
+	uint8_t sps_max_mtt_hierarchy_depth_intra_slice_chroma;
+    uint8_t sps_log2_diff_max_bt_min_qt_intra_slice_chroma;
+	uint8_t sps_log2_diff_max_tt_min_qt_intra_slice_chroma;
+
+    uint8_t sps_log2_diff_min_qt_min_cb_inter_slice;
+	uint8_t sps_max_mtt_hierarchy_depth_inter_slice;
+	uint8_t sps_log2_diff_max_bt_min_qt_inter_slice;
+	uint8_t sps_log2_diff_max_tt_min_qt_inter_slice;
+
+    uint8_t sps_max_luma_transform_size_64_flag;
+
+    uint8_t sps_transform_skip_enabled_flag;
+    uint8_t sps_log2_transform_skip_max_size_minus2;
+	uint8_t sps_bdpcm_enabled_flag;
+
+    uint8_t sps_mts_enabled_flag;
+    uint8_t sps_explicit_mts_intra_enabled_flag;
+	uint8_t sps_explicit_mts_inter_enabled_flag;
+
+    uint8_t sps_lfnst_enabled_flag;
+
+	uint8_t sps_joint_cbcr_enabled_flag;
+	uint8_t sps_same_qp_table_for_chroma_flag;
+
+    int16_t sps_qp_table_start_minus26[VVC_MAX_PLANES];
+    uint8_t sps_num_points_in_qp_table_minus1[VVC_MAX_PLANES];
+    uint8_t sps_delta_qp_in_val_minus1[VVC_MAX_PLANES][VVC_MAX_POINTS_IN_QP_TABLE];
+	uint8_t sps_delta_qp_diff_val[VVC_MAX_PLANES][VVC_MAX_POINTS_IN_QP_TABLE];
+
+    uint8_t sps_sao_enabled_flag;
+	uint8_t sps_alf_enabled_flag;
+	uint8_t sps_ccalf_enabled_flag;
+	uint8_t sps_lmcs_enabled_flag;
+	uint8_t sps_weighted_pred_flag;
+	uint8_t sps_weighted_bipred_flag;
+	uint8_t sps_long_term_ref_pics_flag;
+	uint8_t sps_inter_layer_prediction_enabled_flag;
+	uint8_t sps_idr_rpl_present_flag;
+	uint8_t sps_rpl1_same_as_rpl0_flag;
+
+    // TODO: add reference strcuture
+    uint8_t sps_ref_wraparound_enabled_flag;
+	uint8_t sps_temporal_mvp_enabled_flag;
+	uint8_t sps_sbtmvp_enabled_flag;
+	uint8_t sps_amvr_enabled_flag;
+	uint8_t sps_bdof_enabled_flag;
+	uint8_t sps_bdof_control_present_in_ph_flag;
+	uint8_t sps_smvd_enabled_flag;
+	uint8_t sps_dmvr_enabled_flag;
+    uint8_t	sps_dmvr_control_present_in_ph_flag;
+	uint8_t sps_mmvd_enabled_flag;
+	uint8_t sps_mmvd_fullpel_only_enabled_flag;
+	uint8_t sps_six_minus_max_num_merge_cand;
+	uint8_t sps_sbt_enabled_flag;
+	uint8_t sps_affine_enabled_flag;
+	uint8_t sps_five_minus_max_num_subblock_merge_cand;
+    uint8_t sps_6param_affine_enabled_flag;
+    uint8_t sps_affine_amvr_enabled_flag;
+	uint8_t sps_affine_prof_enabled_flag;
+    uint8_t sps_prof_control_present_in_ph_flag;
+    uint8_t sps_bcw_enabled_flag;
+	uint8_t sps_ciip_enabled_flag;
+	uint8_t sps_gpm_enabled_flag;
+    uint8_t sps_max_num_merge_cand_minus_max_num_gpm_cand;
+    uint8_t sps_log2_parallel_merge_level_minus2;
+	uint8_t sps_isp_enabled_flag;
+	uint8_t sps_mrl_enabled_flag;
+	uint8_t sps_mip_enabled_flag;
+	uint8_t sps_cclm_enabled_flag;
+    uint8_t sps_chroma_horizontal_collocated_flag;
+    uint8_t sps_chroma_vertical_collocated_flag;
+    uint8_t sps_palette_enabled_flag;
+	uint8_t sps_act_enabled_flag;
+	uint8_t sps_min_qp_prime_ts;
+    uint8_t sps_ibc_enabled_flag;
+    uint8_t sps_six_minus_max_num_ibc_merge_cand;
+	uint8_t sps_ladf_enabled_flag;
+    uint8_t sps_num_ladf_intervals_minus2;
+    uint8_t sps_ladf_lowest_interval_qp_offset;
+    /*
+		for( i = 0; i < sps_num_ladf_intervals_minus2 + 1; i++ ) {
+			sps_ladf_qp_offset[ i ]
+			sps_ladf_delta_threshold_minus1[ i ]
+		}
+	}*/
+	uint8_t sps_explicit_scaling_list_enabled_flag;
+	uint8_t sps_scaling_matrix_for_lfnst_disabled_flag;
+	uint8_t sps_scaling_matrix_for_alternative_colour_space_disabled_flag;
+	uint8_t sps_scaling_matrix_designated_colour_space_flag;
+    uint8_t sps_dep_quant_enabled_flag;
+	uint8_t sps_sign_data_hiding_enabled_flag;
+
+    uint8_t sps_virtual_boundaries_enabled_flag;
+	uint8_t sps_virtual_boundaries_present_flag;
+    uint8_t sps_num_ver_virtual_boundaries;
+    uint16_t sps_virtual_boundary_pos_x_minus1[4];
+	uint8_t sps_num_hor_virtual_boundaries;
+	uint16_t sps_virtual_boundary_pos_y_minus1[4];
+	uint8_t sps_timing_hrd_params_present_flag;
+
+    /* TODO: general_timing_hrd_parameters( ) */
+
+	uint8_t sps_field_seq_flag;
+	uint8_t sps_vui_parameters_present_flag;
+	/* TODO: vui_payload */
+
+    H266RawExtensionData extension_data;
+} H266RawSPS;
+
+typedef struct H266RawPPS {
+    H266RawNALUnitHeader nal_unit_header;
+
+    uint8_t pps_pic_parameter_set_id;
+	uint8_t pps_seq_parameter_set_id;
+	uint8_t pps_mixed_nalu_types_in_pic_flag;
+	uint16_t pps_pic_width_in_luma_samples;
+	uint16_t pps_pic_height_in_luma_samples;
+
+    uint8_t pps_conformance_window_flag;
+	uint16_t pps_conf_win_left_offset;
+	uint16_t pps_conf_win_right_offset;
+	uint16_t pps_conf_win_top_offset;
+	uint16_t pps_conf_win_bottom_offset;
+
+	uint8_t pps_scaling_window_explicit_signalling_flag;
+	uint16_t pps_scaling_win_left_offset;
+	uint16_t pps_scaling_win_right_offset;
+	uint16_t pps_scaling_win_top_offset;
+	uint16_t pps_scaling_win_bottom_offset;
+
+    uint8_t pps_output_flag_present_flag;
+	uint8_t pps_no_pic_partition_flag;
+	uint8_t pps_subpic_id_mapping_present_flag;
+	/* TODO: pps_subpic_id[ i ] */
+	uint8_t pps_log2_ctu_size_minus5;
+	uint16_t pps_num_exp_tile_columns_minus1;
+	uint16_t pps_num_exp_tile_rows_minus1;
+    uint16_t pps_tile_column_width_minus1[VVC_MAX_TILE_COLUMNS];
+	uint16_t pps_tile_row_height_minus1[VVC_MAX_TILE_ROWS];
+
+    uint8_t pps_loop_filter_across_tiles_enabled_flag;
+    uint8_t pps_rect_slice_flag;
+    uint8_t pps_single_slice_per_subpic_flag;
+    uint16_t pps_num_slices_in_pic_minus1;
+    uint8_t pps_tile_idx_delta_present_flag;
+
+    /* TODO:
+    uint16_t pps_slice_width_in_tiles_minus1[VVC_MAX_TILE_COLUMNS];
+    uint16_t pps_slice_height_in_tiles_minus1[VVC_MAX_TILE_ROWS];
+    */
+    uint8_t pps_loop_filter_across_slices_enabled_flag;
+    uint8_t pps_cabac_init_present_flag;
+	uint8_t pps_num_ref_idx_default_active_minus1[2];
+	uint8_t pps_rpl1_idx_present_flag;
+	uint8_t pps_weighted_pred_flag;
+	uint8_t pps_weighted_bipred_flag;
+	uint8_t pps_ref_wraparound_enabled_flag;
+	uint8_t pps_pic_width_minus_wraparound_offset;
+	uint8_t pps_init_qp_minus26;
+	uint8_t pps_cu_qp_delta_enabled_flag;
+	uint8_t pps_chroma_tool_offsets_present_flag;
+	uint8_t pps_cb_qp_offset;
+	uint8_t pps_cr_qp_offse;
+	uint8_t pps_joint_cbcr_qp_offset_present_flag;
+    uint8_t pps_joint_cbcr_qp_offset_value;
+    uint8_t pps_slice_chroma_qp_offsets_present_flag;
+    uint8_t pps_cu_chroma_qp_offset_list_enabled_flag;
+    uint8_t pps_chroma_qp_offset_list_len_minus1;
+    uint8_t pps_cb_qp_offset_list[6];
+    uint8_t pps_cr_qp_offset_list[6];
+    uint8_t	pps_joint_cbcr_qp_offset_list[6];
+    uint8_t pps_deblocking_filter_control_present_flag;
+    uint8_t pps_deblocking_filter_override_enabled_flag;
+    uint8_t pps_deblocking_filter_disabled_flag;
+	uint8_t pps_dbf_info_in_ph_flag;
+
+    uint8_t pps_luma_beta_offset_div2;
+	uint8_t	pps_luma_tc_offset_div2;
+    uint8_t pps_cb_beta_offset_div2;
+	uint8_t pps_cb_tc_offset_div2;
+	uint8_t pps_cr_beta_offset_div2;
+	uint8_t pps_cr_tc_offset_div2;
+
+    uint8_t pps_rpl_info_in_ph_flag;
+    uint8_t pps_sao_info_in_ph_flag;
+    uint8_t pps_alf_info_in_ph_flag;
+    uint8_t pps_wp_info_in_ph_flag;
+	uint8_t pps_qp_delta_info_in_ph_flag;
+    H266RawExtensionData extension_data;
+
+} H266RawPPS;
+
+typedef struct H266RawAUD {
+    H266RawNALUnitHeader nal_unit_header;
+
+    uint8_t pic_type;
+} H266RawAUD;
+
+typedef struct  H266RawSliceHeader {
+    H266RawNALUnitHeader nal_unit_header;
+} H266RawSliceHeader;
+
+
+typedef struct H266RawSlice {
+    H266RawSliceHeader header;
+
+    uint8_t     *data;
+    AVBufferRef *data_ref;
+    size_t       data_size;
+    int          data_bit_start;
+} H266RawSlice;
+
+
+typedef struct H266RawSEIBufferingPeriod {
+    uint8_t  bp_seq_parameter_set_id;
+} H266RawSEIBufferingPeriod;
+
+typedef struct H266RawSEIPicTiming {
+} H266RawSEIPicTiming;
+
+typedef struct H266RawSEIPanScanRect {
+} H266RawSEIPanScanRect;
+
+typedef struct H266RawSEIUserDataRegistered {
+
+} H266RawSEIUserDataRegistered;
+
+typedef struct H266RawSEIUserDataUnregistered {
+} H266RawSEIUserDataUnregistered;
+
+typedef struct H266RawSEIRecoveryPoint {
+} H266RawSEIRecoveryPoint;
+
+typedef struct H266RawSEIDisplayOrientation {
+} H266RawSEIDisplayOrientation;
+
+typedef struct H266RawSEIActiveParameterSets {
+} H266RawSEIActiveParameterSets;
+
+typedef struct H266RawSEIDecodedPictureHash {
+} H266RawSEIDecodedPictureHash;
+
+typedef struct H266RawSEITimeCode {
+} H266RawSEITimeCode;
+
+typedef struct H266RawSEIMasteringDisplayColourVolume {
+} H266RawSEIMasteringDisplayColourVolume;
+
+typedef struct H266RawSEIContentLightLevelInfo {
+    uint16_t max_content_light_level;
+    uint16_t max_pic_average_light_level;
+} H266RawSEIContentLightLevelInfo;
+
+typedef struct H266RawSEIAlternativeTransferCharacteristics {
+    uint8_t preferred_transfer_characteristics;
+} H266RawSEIAlternativeTransferCharacteristics;
+
+typedef struct H266RawSEIAlphaChannelInfo {
+    uint8_t  alpha_channel_cancel_flag;
+    uint8_t  alpha_channel_use_idc;
+    uint8_t  alpha_channel_bit_depth_minus8;
+    uint16_t alpha_transparent_value;
+    uint16_t alpha_opaque_value;
+    uint8_t  alpha_channel_incr_flag;
+    uint8_t  alpha_channel_clip_flag;
+    uint8_t  alpha_channel_clip_type_flag;
+} H266RawSEIAlphaChannelInfo;
+
+typedef struct H266RawSEIPayload {
+    uint32_t payload_type;
+    uint32_t payload_size;
+    union {
+        H266RawSEIBufferingPeriod buffering_period;
+        H266RawSEIPicTiming pic_timing;
+        H266RawSEIPanScanRect pan_scan_rect;
+        H266RawSEIUserDataRegistered user_data_registered;
+        H266RawSEIUserDataUnregistered user_data_unregistered;
+        H266RawSEIRecoveryPoint recovery_point;
+        H266RawSEIDisplayOrientation display_orientation;
+        H266RawSEIActiveParameterSets active_parameter_sets;
+        H266RawSEIDecodedPictureHash decoded_picture_hash;
+        H266RawSEITimeCode time_code;
+        H266RawSEIMasteringDisplayColourVolume mastering_display;
+        H266RawSEIContentLightLevelInfo content_light_level;
+        H266RawSEIAlternativeTransferCharacteristics
+            alternative_transfer_characteristics;
+        H266RawSEIAlphaChannelInfo alpha_channel_info;
+        struct {
+            uint8_t     *data;
+            AVBufferRef *data_ref;
+            size_t       data_length;
+        } other;
+    } payload;
+    H266RawExtensionData extension_data;
+} H266RawSEIPayload;
+
+typedef struct H266RawSEI {
+    H266RawNALUnitHeader nal_unit_header;
+
+    H266RawSEIPayload payload[H266_MAX_SEI_PAYLOADS];
+    uint8_t payload_count;
+} H266RawSEI;
+
+typedef struct CodedBitstreamH266Context {
+    // Reader/writer context in common with the H.264 implementation.
+    CodedBitstreamH2645Context common;
+
+    // All currently available parameter sets.  These are updated when
+    // any parameter set NAL unit is read/written with this context.
+    AVBufferRef *vps_ref[VVC_MAX_VPS_COUNT];
+    AVBufferRef *sps_ref[VVC_MAX_SPS_COUNT];
+    AVBufferRef *pps_ref[VVC_MAX_PPS_COUNT];
+    H266RawVPS *vps[VVC_MAX_VPS_COUNT];
+    H266RawSPS *sps[VVC_MAX_SPS_COUNT];
+    H266RawPPS *pps[VVC_MAX_PPS_COUNT];
+
+    // The currently active parameter sets.  These are updated when any
+    // NAL unit refers to the relevant parameter set.  These pointers
+    // must also be present in the arrays above.
+    const H266RawVPS *active_vps;
+    const H266RawSPS *active_sps;
+    const H266RawPPS *active_pps;
+} CodedBitstreamH266Context;
+
+
+#endif /* AVCODEC_CBS_H266_H */
diff --git a/libavcodec/vvc.h b/libavcodec/vvc.h
index 02d532730f..93996feb82 100644
--- a/libavcodec/vvc.h
+++ b/libavcodec/vvc.h
@@ -66,4 +66,24 @@ enum VVCSliceType {
     VCC_SLICE_I = 2,
 };
 
+enum {
+    VVC_MAX_PLANES = 3,
+    //7.4.3.3 The value of vps_max_sublayers_minus1 shall be in the range of 0 to 6, inclusive
+    VVC_MAX_SUB_LAYERS = 7,
+
+    // 7.3.2.3: vps_video_parameter_set_id is u(4).
+    VVC_MAX_VPS_COUNT = 16,
+    // 7.3.2.4: sps_seq_parameter_set_id is in [0, 15].
+    VVC_MAX_SPS_COUNT = 16,
+    // 7.3.2.5: pps_pic_parameter_set_id is in [0, 63].
+    VVC_MAX_PPS_COUNT = 64,
+    //
+    VVC_MAX_POINTS_IN_QP_TABLE = 76,
+    // A.4.1: table 135 allows at most 20 tile rows for any level.
+    VVC_MAX_TILE_ROWS    = 20,
+    // A.4.1: table 135 allows at most 20 tile columns for any level.
+    VVC_MAX_TILE_COLUMNS = 20,
+
+};
+
 #endif /* AVCODEC_VVC_H */
-- 
2.25.1

