cbs_av1.h (14635B)
1 /* 2 * This file is part of FFmpeg. 3 * 4 * FFmpeg is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * FFmpeg is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with FFmpeg; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 19 #ifndef AVCODEC_CBS_AV1_H 20 #define AVCODEC_CBS_AV1_H 21 22 #include <stddef.h> 23 #include <stdint.h> 24 25 #include "av1.h" 26 #include "cbs.h" 27 28 29 typedef struct AV1RawOBUHeader { 30 uint8_t obu_forbidden_bit; 31 uint8_t obu_type; 32 uint8_t obu_extension_flag; 33 uint8_t obu_has_size_field; 34 uint8_t obu_reserved_1bit; 35 36 uint8_t temporal_id; 37 uint8_t spatial_id; 38 uint8_t extension_header_reserved_3bits; 39 } AV1RawOBUHeader; 40 41 typedef struct AV1RawColorConfig { 42 uint8_t high_bitdepth; 43 uint8_t twelve_bit; 44 uint8_t mono_chrome; 45 46 uint8_t color_description_present_flag; 47 uint8_t color_primaries; 48 uint8_t transfer_characteristics; 49 uint8_t matrix_coefficients; 50 51 uint8_t color_range; 52 uint8_t subsampling_x; 53 uint8_t subsampling_y; 54 uint8_t chroma_sample_position; 55 uint8_t separate_uv_delta_q; 56 } AV1RawColorConfig; 57 58 typedef struct AV1RawTimingInfo { 59 uint32_t num_units_in_display_tick; 60 uint32_t time_scale; 61 62 uint8_t equal_picture_interval; 63 uint32_t num_ticks_per_picture_minus_1; 64 } AV1RawTimingInfo; 65 66 typedef struct AV1RawDecoderModelInfo { 67 uint8_t buffer_delay_length_minus_1; 68 uint32_t num_units_in_decoding_tick; 69 uint8_t buffer_removal_time_length_minus_1; 70 uint8_t frame_presentation_time_length_minus_1; 71 } AV1RawDecoderModelInfo; 72 73 typedef struct AV1RawSequenceHeader { 74 uint8_t seq_profile; 75 uint8_t still_picture; 76 uint8_t reduced_still_picture_header; 77 78 uint8_t timing_info_present_flag; 79 uint8_t decoder_model_info_present_flag; 80 uint8_t initial_display_delay_present_flag; 81 uint8_t operating_points_cnt_minus_1; 82 83 AV1RawTimingInfo timing_info; 84 AV1RawDecoderModelInfo decoder_model_info; 85 86 uint16_t operating_point_idc[AV1_MAX_OPERATING_POINTS]; 87 uint8_t seq_level_idx[AV1_MAX_OPERATING_POINTS]; 88 uint8_t seq_tier[AV1_MAX_OPERATING_POINTS]; 89 uint8_t decoder_model_present_for_this_op[AV1_MAX_OPERATING_POINTS]; 90 uint32_t decoder_buffer_delay[AV1_MAX_OPERATING_POINTS]; 91 uint32_t encoder_buffer_delay[AV1_MAX_OPERATING_POINTS]; 92 uint8_t low_delay_mode_flag[AV1_MAX_OPERATING_POINTS]; 93 uint8_t initial_display_delay_present_for_this_op[AV1_MAX_OPERATING_POINTS]; 94 uint8_t initial_display_delay_minus_1[AV1_MAX_OPERATING_POINTS]; 95 96 uint8_t frame_width_bits_minus_1; 97 uint8_t frame_height_bits_minus_1; 98 uint16_t max_frame_width_minus_1; 99 uint16_t max_frame_height_minus_1; 100 101 uint8_t frame_id_numbers_present_flag; 102 uint8_t delta_frame_id_length_minus_2; 103 uint8_t additional_frame_id_length_minus_1; 104 105 uint8_t use_128x128_superblock; 106 uint8_t enable_filter_intra; 107 uint8_t enable_intra_edge_filter; 108 uint8_t enable_interintra_compound; 109 uint8_t enable_masked_compound; 110 uint8_t enable_warped_motion; 111 uint8_t enable_dual_filter; 112 113 uint8_t enable_order_hint; 114 uint8_t enable_jnt_comp; 115 uint8_t enable_ref_frame_mvs; 116 117 uint8_t seq_choose_screen_content_tools; 118 uint8_t seq_force_screen_content_tools; 119 uint8_t seq_choose_integer_mv; 120 uint8_t seq_force_integer_mv; 121 122 uint8_t order_hint_bits_minus_1; 123 124 uint8_t enable_superres; 125 uint8_t enable_cdef; 126 uint8_t enable_restoration; 127 128 AV1RawColorConfig color_config; 129 130 uint8_t film_grain_params_present; 131 } AV1RawSequenceHeader; 132 133 typedef struct AV1RawFilmGrainParams { 134 uint8_t apply_grain; 135 uint16_t grain_seed; 136 uint8_t update_grain; 137 uint8_t film_grain_params_ref_idx; 138 uint8_t num_y_points; 139 uint8_t point_y_value[14]; 140 uint8_t point_y_scaling[14]; 141 uint8_t chroma_scaling_from_luma; 142 uint8_t num_cb_points; 143 uint8_t point_cb_value[10]; 144 uint8_t point_cb_scaling[10]; 145 uint8_t num_cr_points; 146 uint8_t point_cr_value[10]; 147 uint8_t point_cr_scaling[10]; 148 uint8_t grain_scaling_minus_8; 149 uint8_t ar_coeff_lag; 150 uint8_t ar_coeffs_y_plus_128[24]; 151 uint8_t ar_coeffs_cb_plus_128[25]; 152 uint8_t ar_coeffs_cr_plus_128[25]; 153 uint8_t ar_coeff_shift_minus_6; 154 uint8_t grain_scale_shift; 155 uint8_t cb_mult; 156 uint8_t cb_luma_mult; 157 uint16_t cb_offset; 158 uint8_t cr_mult; 159 uint8_t cr_luma_mult; 160 uint16_t cr_offset; 161 uint8_t overlap_flag; 162 uint8_t clip_to_restricted_range; 163 } AV1RawFilmGrainParams; 164 165 typedef struct AV1RawFrameHeader { 166 uint8_t show_existing_frame; 167 uint8_t frame_to_show_map_idx; 168 uint32_t frame_presentation_time; 169 uint32_t display_frame_id; 170 171 uint8_t frame_type; 172 uint8_t show_frame; 173 uint8_t showable_frame; 174 175 uint8_t error_resilient_mode; 176 uint8_t disable_cdf_update; 177 uint8_t allow_screen_content_tools; 178 uint8_t force_integer_mv; 179 180 uint32_t current_frame_id; 181 uint8_t frame_size_override_flag; 182 uint8_t order_hint; 183 184 uint8_t buffer_removal_time_present_flag; 185 uint32_t buffer_removal_time[AV1_MAX_OPERATING_POINTS]; 186 187 uint8_t primary_ref_frame; 188 uint16_t frame_width_minus_1; 189 uint16_t frame_height_minus_1; 190 uint8_t use_superres; 191 uint8_t coded_denom; 192 uint8_t render_and_frame_size_different; 193 uint16_t render_width_minus_1; 194 uint16_t render_height_minus_1; 195 196 uint8_t found_ref[AV1_REFS_PER_FRAME]; 197 198 uint8_t refresh_frame_flags; 199 uint8_t allow_intrabc; 200 uint8_t ref_order_hint[AV1_NUM_REF_FRAMES]; 201 uint8_t frame_refs_short_signaling; 202 uint8_t last_frame_idx; 203 uint8_t golden_frame_idx; 204 int8_t ref_frame_idx[AV1_REFS_PER_FRAME]; 205 uint32_t delta_frame_id_minus1[AV1_REFS_PER_FRAME]; 206 207 uint8_t allow_high_precision_mv; 208 uint8_t is_filter_switchable; 209 uint8_t interpolation_filter; 210 uint8_t is_motion_mode_switchable; 211 uint8_t use_ref_frame_mvs; 212 213 uint8_t disable_frame_end_update_cdf; 214 215 uint8_t uniform_tile_spacing_flag; 216 uint8_t tile_cols_log2; 217 uint8_t tile_rows_log2; 218 uint8_t tile_start_col_sb[AV1_MAX_TILE_COLS]; 219 uint8_t tile_start_row_sb[AV1_MAX_TILE_COLS]; 220 uint8_t width_in_sbs_minus_1[AV1_MAX_TILE_COLS]; 221 uint8_t height_in_sbs_minus_1[AV1_MAX_TILE_ROWS]; 222 uint16_t context_update_tile_id; 223 uint8_t tile_size_bytes_minus1; 224 225 // These are derived values, but it's very unhelpful to have to 226 // recalculate them all the time so we store them here. 227 uint16_t tile_cols; 228 uint16_t tile_rows; 229 230 uint8_t base_q_idx; 231 int8_t delta_q_y_dc; 232 uint8_t diff_uv_delta; 233 int8_t delta_q_u_dc; 234 int8_t delta_q_u_ac; 235 int8_t delta_q_v_dc; 236 int8_t delta_q_v_ac; 237 uint8_t using_qmatrix; 238 uint8_t qm_y; 239 uint8_t qm_u; 240 uint8_t qm_v; 241 242 uint8_t segmentation_enabled; 243 uint8_t segmentation_update_map; 244 uint8_t segmentation_temporal_update; 245 uint8_t segmentation_update_data; 246 uint8_t feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; 247 int16_t feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; 248 249 uint8_t delta_q_present; 250 uint8_t delta_q_res; 251 uint8_t delta_lf_present; 252 uint8_t delta_lf_res; 253 uint8_t delta_lf_multi; 254 255 uint8_t loop_filter_level[4]; 256 uint8_t loop_filter_sharpness; 257 uint8_t loop_filter_delta_enabled; 258 uint8_t loop_filter_delta_update; 259 uint8_t update_ref_delta[AV1_TOTAL_REFS_PER_FRAME]; 260 int8_t loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME]; 261 uint8_t update_mode_delta[2]; 262 int8_t loop_filter_mode_deltas[2]; 263 264 uint8_t cdef_damping_minus_3; 265 uint8_t cdef_bits; 266 uint8_t cdef_y_pri_strength[8]; 267 uint8_t cdef_y_sec_strength[8]; 268 uint8_t cdef_uv_pri_strength[8]; 269 uint8_t cdef_uv_sec_strength[8]; 270 271 uint8_t lr_type[3]; 272 uint8_t lr_unit_shift; 273 uint8_t lr_uv_shift; 274 275 uint8_t tx_mode; 276 uint8_t reference_select; 277 uint8_t skip_mode_present; 278 279 uint8_t allow_warped_motion; 280 uint8_t reduced_tx_set; 281 282 uint8_t is_global[AV1_TOTAL_REFS_PER_FRAME]; 283 uint8_t is_rot_zoom[AV1_TOTAL_REFS_PER_FRAME]; 284 uint8_t is_translation[AV1_TOTAL_REFS_PER_FRAME]; 285 //AV1RawSubexp gm_params[AV1_TOTAL_REFS_PER_FRAME][6]; 286 uint32_t gm_params[AV1_TOTAL_REFS_PER_FRAME][6]; 287 288 AV1RawFilmGrainParams film_grain; 289 } AV1RawFrameHeader; 290 291 typedef struct AV1RawTileData { 292 uint8_t *data; 293 AVBufferRef *data_ref; 294 size_t data_size; 295 } AV1RawTileData; 296 297 typedef struct AV1RawTileGroup { 298 uint8_t tile_start_and_end_present_flag; 299 uint16_t tg_start; 300 uint16_t tg_end; 301 302 AV1RawTileData tile_data; 303 } AV1RawTileGroup; 304 305 typedef struct AV1RawFrame { 306 AV1RawFrameHeader header; 307 AV1RawTileGroup tile_group; 308 } AV1RawFrame; 309 310 typedef struct AV1RawTileList { 311 uint8_t output_frame_width_in_tiles_minus_1; 312 uint8_t output_frame_height_in_tiles_minus_1; 313 uint16_t tile_count_minus_1; 314 315 AV1RawTileData tile_data; 316 } AV1RawTileList; 317 318 typedef struct AV1RawMetadataHDRCLL { 319 uint16_t max_cll; 320 uint16_t max_fall; 321 } AV1RawMetadataHDRCLL; 322 323 typedef struct AV1RawMetadataHDRMDCV { 324 uint16_t primary_chromaticity_x[3]; 325 uint16_t primary_chromaticity_y[3]; 326 uint16_t white_point_chromaticity_x; 327 uint16_t white_point_chromaticity_y; 328 uint32_t luminance_max; 329 uint32_t luminance_min; 330 } AV1RawMetadataHDRMDCV; 331 332 typedef struct AV1RawMetadataScalability { 333 uint8_t scalability_mode_idc; 334 uint8_t spatial_layers_cnt_minus_1; 335 uint8_t spatial_layer_dimensions_present_flag; 336 uint8_t spatial_layer_description_present_flag; 337 uint8_t temporal_group_description_present_flag; 338 uint8_t scalability_structure_reserved_3bits; 339 uint16_t spatial_layer_max_width[4]; 340 uint16_t spatial_layer_max_height[4]; 341 uint8_t spatial_layer_ref_id[4]; 342 uint8_t temporal_group_size; 343 uint8_t temporal_group_temporal_id[255]; 344 uint8_t temporal_group_temporal_switching_up_point_flag[255]; 345 uint8_t temporal_group_spatial_switching_up_point_flag[255]; 346 uint8_t temporal_group_ref_cnt[255]; 347 uint8_t temporal_group_ref_pic_diff[255][7]; 348 } AV1RawMetadataScalability; 349 350 typedef struct AV1RawMetadataITUTT35 { 351 uint8_t itu_t_t35_country_code; 352 uint8_t itu_t_t35_country_code_extension_byte; 353 354 uint8_t *payload; 355 AVBufferRef *payload_ref; 356 size_t payload_size; 357 } AV1RawMetadataITUTT35; 358 359 typedef struct AV1RawMetadataTimecode { 360 uint8_t counting_type; 361 uint8_t full_timestamp_flag; 362 uint8_t discontinuity_flag; 363 uint8_t cnt_dropped_flag; 364 uint16_t n_frames; 365 uint8_t seconds_value; 366 uint8_t minutes_value; 367 uint8_t hours_value; 368 uint8_t seconds_flag; 369 uint8_t minutes_flag; 370 uint8_t hours_flag; 371 uint8_t time_offset_length; 372 uint32_t time_offset_value; 373 } AV1RawMetadataTimecode; 374 375 typedef struct AV1RawMetadataUnknown { 376 uint8_t *payload; 377 AVBufferRef *payload_ref; 378 size_t payload_size; 379 } AV1RawMetadataUnknown; 380 381 typedef struct AV1RawMetadata { 382 uint64_t metadata_type; 383 union { 384 AV1RawMetadataHDRCLL hdr_cll; 385 AV1RawMetadataHDRMDCV hdr_mdcv; 386 AV1RawMetadataScalability scalability; 387 AV1RawMetadataITUTT35 itut_t35; 388 AV1RawMetadataTimecode timecode; 389 AV1RawMetadataUnknown unknown; 390 } metadata; 391 } AV1RawMetadata; 392 393 typedef struct AV1RawPadding { 394 uint8_t *payload; 395 AVBufferRef *payload_ref; 396 size_t payload_size; 397 } AV1RawPadding; 398 399 400 typedef struct AV1RawOBU { 401 AV1RawOBUHeader header; 402 403 size_t obu_size; 404 405 union { 406 AV1RawSequenceHeader sequence_header; 407 AV1RawFrameHeader frame_header; 408 AV1RawFrame frame; 409 AV1RawTileGroup tile_group; 410 AV1RawTileList tile_list; 411 AV1RawMetadata metadata; 412 AV1RawPadding padding; 413 } obu; 414 } AV1RawOBU; 415 416 typedef struct AV1ReferenceFrameState { 417 int valid; // RefValid 418 int frame_id; // RefFrameId 419 int upscaled_width; // RefUpscaledWidth 420 int frame_width; // RefFrameWidth 421 int frame_height; // RefFrameHeight 422 int render_width; // RefRenderWidth 423 int render_height; // RefRenderHeight 424 int frame_type; // RefFrameType 425 int subsampling_x; // RefSubsamplingX 426 int subsampling_y; // RefSubsamplingY 427 int bit_depth; // RefBitDepth 428 int order_hint; // RefOrderHint 429 430 int saved_order_hints[AV1_TOTAL_REFS_PER_FRAME]; // SavedOrderHints[ref] 431 432 int8_t loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME]; 433 int8_t loop_filter_mode_deltas[2]; 434 uint8_t feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; 435 int16_t feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; 436 } AV1ReferenceFrameState; 437 438 typedef struct CodedBitstreamAV1Context { 439 const AVClass *class; 440 441 AV1RawSequenceHeader *sequence_header; 442 /** A RefStruct reference backing sequence_header. */ 443 AV1RawOBU *sequence_header_ref; 444 445 int seen_frame_header; 446 AVBufferRef *frame_header_ref; 447 uint8_t *frame_header; 448 size_t frame_header_size; 449 450 int temporal_id; 451 int spatial_id; 452 int operating_point_idc; 453 454 int bit_depth; 455 int order_hint; 456 int frame_width; 457 int frame_height; 458 int upscaled_width; 459 int render_width; 460 int render_height; 461 462 int num_planes; 463 int coded_lossless; 464 int all_lossless; 465 int tile_cols; 466 int tile_rows; 467 int tile_num; 468 469 int order_hints[AV1_TOTAL_REFS_PER_FRAME]; // OrderHints 470 int ref_frame_sign_bias[AV1_TOTAL_REFS_PER_FRAME]; // RefFrameSignBias 471 472 AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES]; 473 474 // AVOptions 475 int operating_point; 476 // When writing, fix the length in bytes of the obu_size field. 477 // Writing will fail with an error if an OBU larger than can be 478 // represented by the fixed size is encountered. 479 int fixed_obu_size_length; 480 481 int8_t loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME]; 482 int8_t loop_filter_mode_deltas[2]; 483 uint8_t feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; 484 int16_t feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX]; 485 } CodedBitstreamAV1Context; 486 487 488 #endif /* AVCODEC_CBS_AV1_H */