1 /* 2 * Copyright 2021 Rockchip Electronics Co. LTD 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __AV1D_CBS_H__ 18 #define __AV1D_CBS_H__ 19 20 #include "av1.h" 21 22 typedef struct AV1RawOBUHeader { 23 RK_U8 obu_forbidden_bit; 24 RK_U8 obu_type; 25 RK_U8 obu_extension_flag; 26 RK_U8 obu_has_size_field; 27 RK_U8 obu_reserved_1bit; 28 29 RK_U8 temporal_id; 30 RK_U8 spatial_id; 31 RK_U8 extension_header_reserved_3bits; 32 } AV1RawOBUHeader; 33 34 typedef struct AV1RawColorConfig { 35 RK_U8 high_bitdepth; 36 RK_U8 twelve_bit; 37 RK_U8 mono_chrome; 38 39 RK_U8 color_description_present_flag; 40 RK_U8 color_primaries; 41 RK_U8 transfer_characteristics; 42 RK_U8 matrix_coefficients; 43 44 RK_U8 color_range; 45 RK_U8 subsampling_x; 46 RK_U8 subsampling_y; 47 RK_U8 chroma_sample_position; 48 RK_U8 separate_uv_delta_q; 49 } AV1RawColorConfig; 50 51 typedef struct AV1RawTimingInfo { 52 RK_U32 num_units_in_display_tick; 53 RK_U32 time_scale; 54 55 RK_U8 equal_picture_interval; 56 RK_U32 num_ticks_per_picture_minus_1; 57 } AV1RawTimingInfo; 58 59 typedef struct AV1RawDecoderModelInfo { 60 RK_U8 buffer_delay_length_minus_1; 61 RK_U32 num_units_in_decoding_tick; 62 RK_U8 buffer_removal_time_length_minus_1; 63 RK_U8 frame_presentation_time_length_minus_1; 64 } AV1RawDecoderModelInfo; 65 66 typedef struct AV1RawSequenceHeader { 67 RK_U8 seq_profile; 68 RK_U8 still_picture; 69 RK_U8 reduced_still_picture_header; 70 71 RK_U8 timing_info_present_flag; 72 RK_U8 decoder_model_info_present_flag; 73 RK_U8 initial_display_delay_present_flag; 74 RK_U8 operating_points_cnt_minus_1; 75 76 AV1RawTimingInfo timing_info; 77 AV1RawDecoderModelInfo decoder_model_info; 78 79 RK_U16 operating_point_idc[AV1_MAX_OPERATING_POINTS]; 80 RK_U8 seq_level_idx[AV1_MAX_OPERATING_POINTS]; 81 RK_U8 seq_tier[AV1_MAX_OPERATING_POINTS]; 82 RK_U8 decoder_model_present_for_this_op[AV1_MAX_OPERATING_POINTS]; 83 RK_U32 decoder_buffer_delay[AV1_MAX_OPERATING_POINTS]; 84 RK_U32 encoder_buffer_delay[AV1_MAX_OPERATING_POINTS]; 85 RK_U8 low_delay_mode_flag[AV1_MAX_OPERATING_POINTS]; 86 RK_U8 initial_display_delay_present_for_this_op[AV1_MAX_OPERATING_POINTS]; 87 RK_U8 initial_display_delay_minus_1[AV1_MAX_OPERATING_POINTS]; 88 89 RK_U8 frame_width_bits_minus_1; 90 RK_U8 frame_height_bits_minus_1; 91 RK_U16 max_frame_width_minus_1; 92 RK_U16 max_frame_height_minus_1; 93 94 RK_U8 frame_id_numbers_present_flag; 95 RK_U8 delta_frame_id_length_minus_2; 96 RK_U8 additional_frame_id_length_minus_1; 97 98 RK_U8 use_128x128_superblock; 99 RK_U8 enable_filter_intra; 100 RK_U8 enable_intra_edge_filter; 101 RK_U8 enable_interintra_compound; 102 RK_U8 enable_masked_compound; 103 RK_U8 enable_warped_motion; 104 RK_U8 enable_dual_filter; 105 106 RK_U8 enable_order_hint; 107 RK_U8 enable_jnt_comp; 108 RK_U8 enable_ref_frame_mvs; 109 110 RK_U8 seq_choose_screen_content_tools; 111 RK_U8 seq_force_screen_content_tools; 112 RK_U8 seq_choose_integer_mv; 113 RK_U8 seq_force_integer_mv; 114 115 RK_U8 order_hint_bits_minus_1; 116 117 RK_U8 enable_superres; 118 RK_U8 enable_cdef; 119 RK_U8 enable_restoration; 120 121 AV1RawColorConfig color_config; 122 123 RK_U8 film_grain_params_present; 124 } AV1RawSequenceHeader; 125 126 typedef struct AV1RawFilmGrainParams { 127 RK_U8 apply_grain; 128 RK_U16 grain_seed; 129 RK_U8 update_grain; 130 RK_U8 film_grain_params_ref_idx; 131 RK_U8 num_y_points; 132 RK_U8 point_y_value[14]; 133 RK_U8 point_y_scaling[14]; 134 RK_U8 chroma_scaling_from_luma; 135 RK_U8 num_cb_points; 136 RK_U8 point_cb_value[10]; 137 RK_U8 point_cb_scaling[10]; 138 RK_U8 num_cr_points; 139 RK_U8 point_cr_value[10]; 140 RK_U8 point_cr_scaling[10]; 141 RK_U8 grain_scaling_minus_8; 142 RK_U8 ar_coeff_lag; 143 RK_U8 ar_coeffs_y_plus_128[24]; 144 RK_U8 ar_coeffs_cb_plus_128[25]; 145 RK_U8 ar_coeffs_cr_plus_128[25]; 146 RK_U8 ar_coeff_shift_minus_6; 147 RK_U8 grain_scale_shift; 148 RK_U8 cb_mult; 149 RK_U8 cb_luma_mult; 150 RK_U16 cb_offset; 151 RK_U8 cr_mult; 152 RK_U8 cr_luma_mult; 153 RK_U16 cr_offset; 154 RK_U8 overlap_flag; 155 RK_U8 clip_to_restricted_range; 156 } AV1RawFilmGrainParams; 157 158 typedef struct AV1RawFrameHeader { 159 RK_U8 show_existing_frame; 160 RK_U8 frame_to_show_map_idx; 161 RK_U32 frame_presentation_time; 162 RK_U32 display_frame_id; 163 164 RK_U8 frame_type; 165 RK_U8 show_frame; 166 RK_U8 showable_frame; 167 168 RK_U8 error_resilient_mode; 169 RK_U8 disable_cdf_update; 170 RK_U8 allow_screen_content_tools; 171 RK_U8 force_integer_mv; 172 173 RK_S32 current_frame_id; 174 RK_U8 frame_size_override_flag; 175 RK_U8 order_hint; 176 177 RK_U8 buffer_removal_time_present_flag; 178 RK_U32 buffer_removal_time[AV1_MAX_OPERATING_POINTS]; 179 180 RK_U8 primary_ref_frame; 181 RK_U16 frame_width_minus_1; 182 RK_U16 frame_height_minus_1; 183 RK_U8 use_superres; 184 RK_U8 coded_denom; 185 RK_U8 render_and_frame_size_different; 186 RK_U16 render_width_minus_1; 187 RK_U16 render_height_minus_1; 188 189 RK_U8 found_ref[AV1_REFS_PER_FRAME]; 190 191 RK_U8 refresh_frame_flags; 192 RK_U8 allow_intrabc; 193 RK_U8 ref_order_hint[AV1_NUM_REF_FRAMES]; 194 RK_U8 frame_refs_short_signaling; 195 RK_U8 last_frame_idx; 196 RK_U8 golden_frame_idx; 197 RK_S8 ref_frame_idx[AV1_REFS_PER_FRAME]; 198 RK_U32 delta_frame_id_minus1[AV1_REFS_PER_FRAME]; 199 200 RK_U8 allow_high_precision_mv; 201 RK_U8 is_filter_switchable; 202 RK_U8 interpolation_filter; 203 RK_U8 is_motion_mode_switchable; 204 RK_U8 use_ref_frame_mvs; 205 206 RK_U8 disable_frame_end_update_cdf; 207 208 RK_U8 uniform_tile_spacing_flag; 209 RK_U8 tile_cols_log2; 210 RK_U8 tile_rows_log2; 211 RK_U8 width_in_sbs_minus_1[AV1_MAX_TILE_COLS]; 212 RK_U8 height_in_sbs_minus_1[AV1_MAX_TILE_ROWS]; 213 RK_U16 context_update_tile_id; 214 RK_U8 tile_size_bytes_minus1; 215 216 // These are derived values, but it's very unhelpful to have to 217 // recalculate them all the time so we store them here. 218 RK_U16 tile_cols; 219 RK_U16 tile_rows; 220 221 RK_U8 base_q_idx; 222 RK_S8 delta_q_y_dc; 223 RK_U8 diff_uv_delta; 224 RK_S8 delta_q_u_dc; 225 RK_S8 delta_q_u_ac; 226 RK_S8 delta_q_v_dc; 227 RK_S8 delta_q_v_ac; 228 RK_U8 using_qmatrix; 229 RK_U8 qm_y; 230 RK_U8 qm_u; 231 RK_U8 qm_v; 232 233 RK_U8 segmentation_enabled; 234 RK_U8 segmentation_update_map; 235 RK_U8 segmentation_temporal_update; 236 RK_U8 segmentation_update_data; 237 RK_U8 feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; 238 RK_S16 feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; 239 240 RK_U8 delta_q_present; 241 RK_U8 delta_q_res; 242 RK_U8 delta_lf_present; 243 RK_U8 delta_lf_res; 244 RK_U8 delta_lf_multi; 245 246 RK_U8 loop_filter_level[4]; 247 RK_U8 loop_filter_sharpness; 248 RK_U8 loop_filter_delta_enabled; 249 RK_U8 loop_filter_delta_update; 250 RK_U8 update_ref_delta[AV1_TOTAL_REFS_PER_FRAME]; 251 RK_S8 loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME]; 252 RK_U8 update_mode_delta[2]; 253 RK_S8 loop_filter_mode_deltas[2]; 254 255 RK_U8 cdef_damping_minus_3; 256 RK_U8 cdef_bits; 257 RK_U8 cdef_y_pri_strength[8]; 258 RK_U8 cdef_y_sec_strength[8]; 259 RK_U8 cdef_uv_pri_strength[8]; 260 RK_U8 cdef_uv_sec_strength[8]; 261 262 RK_U8 lr_type[3]; 263 RK_U8 lr_unit_shift; 264 RK_U8 lr_uv_shift; 265 266 RK_U8 tx_mode; 267 RK_U8 reference_select; 268 RK_U8 skip_mode_present; 269 270 RK_U8 allow_warped_motion; 271 RK_U8 reduced_tx_set; 272 273 RK_U8 is_global[AV1_TOTAL_REFS_PER_FRAME]; 274 RK_U8 is_rot_zoom[AV1_TOTAL_REFS_PER_FRAME]; 275 RK_U8 is_translation[AV1_TOTAL_REFS_PER_FRAME]; 276 //AV1RawSubexp gm_params[AV1_TOTAL_REFS_PER_FRAME][6]; 277 RK_U32 gm_params[AV1_TOTAL_REFS_PER_FRAME][6]; 278 279 AV1RawFilmGrainParams film_grain; 280 } AV1RawFrameHeader; 281 282 typedef struct AV1RawTileData { 283 RK_U8 *data; 284 size_t offset; 285 size_t data_size; 286 } AV1RawTileData; 287 288 typedef struct AV1RawTileGroup { 289 RK_U8 tile_start_and_end_present_flag; 290 RK_U8 tg_start; 291 RK_U8 tg_end; 292 293 AV1RawTileData tile_data; 294 } AV1RawTileGroup; 295 296 typedef struct AV1RawFrame { 297 AV1RawFrameHeader header; 298 AV1RawTileGroup tile_group; 299 } AV1RawFrame; 300 301 typedef struct AV1RawTileList { 302 RK_U8 output_frame_width_in_tiles_minus_1; 303 RK_U8 output_frame_height_in_tiles_minus_1; 304 RK_U8 tile_count_minus_1; 305 306 AV1RawTileData tile_data; 307 } AV1RawTileList; 308 309 typedef struct AV1RawMetadataHDRCLL { 310 RK_U8 max_cll; 311 RK_U8 max_fall; 312 } AV1RawMetadataHDRCLL; 313 314 typedef struct AV1RawMetadataHDRMDCV { 315 RK_U8 primary_chromaticity_x[3]; 316 RK_U8 primary_chromaticity_y[3]; 317 RK_U8 white_point_chromaticity_x; 318 RK_U8 white_point_chromaticity_y; 319 RK_U32 luminance_max; 320 RK_U32 luminance_min; 321 } AV1RawMetadataHDRMDCV; 322 323 typedef struct AV1RawMetadataScalability { 324 RK_U8 scalability_mode_idc; 325 RK_U8 spatial_layers_cnt_minus_1; 326 RK_U8 spatial_layer_dimensions_present_flag; 327 RK_U8 spatial_layer_description_present_flag; 328 RK_U8 temporal_group_description_present_flag; 329 RK_U8 scalability_structure_reserved_3bits; 330 RK_U8 spatial_layer_max_width[4]; 331 RK_U8 spatial_layer_max_height[4]; 332 RK_U8 spatial_layer_ref_id[4]; 333 RK_U8 temporal_group_size; 334 RK_U8 temporal_group_temporal_id[255]; 335 RK_U8 temporal_group_temporal_switching_up_point_flag[255]; 336 RK_U8 temporal_group_spatial_switching_up_point_flag[255]; 337 RK_U8 temporal_group_ref_cnt[255]; 338 RK_U8 temporal_group_ref_pic_diff[255][7]; 339 } AV1RawMetadataScalability; 340 341 typedef struct AV1RawMetadataITUTT35 { 342 RK_U8 itu_t_t35_country_code; 343 RK_U8 itu_t_t35_country_code_extension_byte; 344 RK_U32 itu_t_t35_terminal_provider_code; 345 RK_U32 itu_t_t35_terminal_provider_oriented_code; 346 347 RK_U8 *payload; 348 size_t payload_size; 349 } AV1RawMetadataITUTT35; 350 351 typedef struct AV1RawMetadataTimecode { 352 RK_U8 counting_type; 353 RK_U8 full_timestamp_flag; 354 RK_U8 discontinuity_flag; 355 RK_U8 cnt_dropped_flag; 356 RK_U8 n_frames; 357 RK_U8 seconds_value; 358 RK_U8 minutes_value; 359 RK_U8 hours_value; 360 RK_U8 seconds_flag; 361 RK_U8 minutes_flag; 362 RK_U8 hours_flag; 363 RK_U8 time_offset_length; 364 RK_U32 time_offset_value; 365 } AV1RawMetadataTimecode; 366 367 typedef struct AV1RawMetadata { 368 RK_U64 metadata_type; 369 union { 370 AV1RawMetadataHDRCLL hdr_cll; 371 AV1RawMetadataHDRMDCV hdr_mdcv; 372 AV1RawMetadataScalability scalability; 373 AV1RawMetadataITUTT35 itut_t35; 374 AV1RawMetadataTimecode timecode; 375 } metadata; 376 } AV1RawMetadata; 377 378 typedef struct AV1RawPadding { 379 RK_U8 *payload; 380 size_t payload_size; 381 } AV1RawPadding; 382 383 384 typedef struct AV1RawOBU { 385 AV1RawOBUHeader header; 386 387 size_t obu_size; 388 389 union { 390 AV1RawSequenceHeader sequence_header; 391 AV1RawFrameHeader frame_header; 392 AV1RawFrame frame; 393 AV1RawTileGroup tile_group; 394 AV1RawTileList tile_list; 395 AV1RawMetadata metadata; 396 AV1RawPadding padding; 397 } obu; 398 } AV1RawOBU; 399 400 typedef struct AV1ReferenceFrameState { 401 RK_S32 valid; // RefValid 402 RK_S32 frame_id; // RefFrameId 403 RK_S32 upscaled_width; // RefUpscaledWidth 404 RK_S32 frame_width; // RefFrameWidth 405 RK_S32 frame_height; // RefFrameHeight 406 RK_S32 render_width; // RefRenderWidth 407 RK_S32 render_height; // RefRenderHeight 408 RK_S32 frame_type; // RefFrameType 409 RK_S32 subsampling_x; // RefSubsamplingX 410 RK_S32 subsampling_y; // RefSubsamplingY 411 RK_S32 bit_depth; // RefBitDepth 412 RK_S32 order_hint; // RefOrderHint 413 414 RK_S8 loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME]; 415 RK_S8 loop_filter_mode_deltas[2]; 416 RK_U8 feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; 417 RK_S16 feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; 418 } AV1ReferenceFrameState; 419 420 421 typedef RK_U32 Av1UnitType; 422 423 typedef struct Av1ObuUnit_t { 424 /** 425 * Codec-specific type of this unit. 426 */ 427 Av1UnitType type; 428 429 /** 430 * Pointer to the directly-parsable bitstream form of this unit. 431 * 432 * May be NULL if the unit currently only exists in decomposed form. 433 */ 434 RK_U8 *data; 435 436 size_t data_size; 437 438 void *content; 439 } Av1ObuUnit; 440 441 typedef struct Av1UnitFragment_t { 442 RK_U8 *data; 443 size_t data_size; 444 int nb_units; 445 int nb_units_allocated; 446 Av1ObuUnit *units; 447 } Av1UnitFragment; 448 449 #endif //__AV1D_CBS_H__ 450