2 * This file is part of FFmpeg.
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.
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.
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
19 #ifndef AVCODEC_CBS_AV1_H
20 #define AVCODEC_CBS_AV1_H
29 typedef struct AV1RawOBUHeader {
30 uint8_t obu_forbidden_bit;
32 uint8_t obu_extension_flag;
33 uint8_t obu_has_size_field;
34 uint8_t obu_reserved_1bit;
38 uint8_t extension_header_reserved_3bits;
41 typedef struct AV1RawColorConfig {
42 uint8_t high_bitdepth;
46 uint8_t color_description_present_flag;
47 uint8_t color_primaries;
48 uint8_t transfer_characteristics;
49 uint8_t matrix_coefficients;
52 uint8_t subsampling_x;
53 uint8_t subsampling_y;
54 uint8_t chroma_sample_position;
55 uint8_t separate_uv_delta_q;
58 typedef struct AV1RawTimingInfo {
59 uint32_t num_units_in_display_tick;
62 uint8_t equal_picture_interval;
63 uint32_t num_ticks_per_picture_minus_1;
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;
73 typedef struct AV1RawSequenceHeader {
75 uint8_t still_picture;
76 uint8_t reduced_still_picture_header;
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;
83 AV1RawTimingInfo timing_info;
84 AV1RawDecoderModelInfo decoder_model_info;
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];
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;
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;
105 uint8_t use_128x128_superblock;
106 uint8_t enable_filter_intra;
107 uint8_t enable_intra_edge_filter;
108 uint8_t enable_intraintra_compound;
109 uint8_t enable_masked_compound;
110 uint8_t enable_warped_motion;
111 uint8_t enable_dual_filter;
113 uint8_t enable_order_hint;
114 uint8_t enable_jnt_comp;
115 uint8_t enable_ref_frame_mvs;
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;
122 uint8_t order_hint_bits_minus_1;
124 uint8_t enable_superres;
126 uint8_t enable_restoration;
128 AV1RawColorConfig color_config;
130 uint8_t film_grain_params_present;
131 } AV1RawSequenceHeader;
133 typedef struct AV1RawFrameHeader {
134 uint8_t show_existing_frame;
135 uint8_t frame_to_show_map_idx;
136 uint32_t frame_presentation_time;
137 uint32_t display_frame_id;
141 uint8_t showable_frame;
143 uint8_t error_resilient_mode;
144 uint8_t disable_cdf_update;
145 uint8_t allow_screen_content_tools;
146 uint8_t force_integer_mv;
148 uint32_t current_frame_id;
149 uint8_t frame_size_override_flag;
152 uint8_t buffer_removal_time_present_flag;
153 uint32_t buffer_removal_time[AV1_MAX_OPERATING_POINTS];
155 uint8_t primary_ref_frame;
156 uint16_t frame_width_minus_1;
157 uint16_t frame_height_minus_1;
158 uint8_t use_superres;
160 uint8_t render_and_frame_size_different;
161 uint8_t render_width_minus_1;
162 uint8_t render_height_minus_1;
164 uint8_t found_ref[AV1_REFS_PER_FRAME];
166 uint8_t refresh_frame_flags;
167 uint8_t allow_intrabc;
168 uint8_t ref_order_hint[AV1_NUM_REF_FRAMES];
169 uint8_t frame_refs_short_signaling;
170 uint8_t last_frame_idx;
171 uint8_t golden_frame_idx;
172 int8_t ref_frame_idx[AV1_REFS_PER_FRAME];
173 uint32_t delta_frame_id_minus1[AV1_REFS_PER_FRAME];
175 uint8_t allow_high_precision_mv;
176 uint8_t is_filter_switchable;
177 uint8_t interpolation_filter;
178 uint8_t is_motion_mode_switchable;
179 uint8_t use_ref_frame_mvs;
181 uint8_t disable_frame_end_update_cdf;
183 uint8_t uniform_tile_spacing_flag;
184 uint8_t tile_cols_log2;
185 uint8_t tile_rows_log2;
186 uint8_t width_in_sbs_minus_1[AV1_MAX_TILE_COLS];
187 uint8_t height_in_sbs_minus_1[AV1_MAX_TILE_ROWS];
188 uint16_t context_update_tile_id;
189 uint8_t tile_size_bytes_minus1;
191 // These are derived values, but it's very unhelpful to have to
192 // recalculate them all the time so we store them here.
198 uint8_t diff_uv_delta;
203 uint8_t using_qmatrix;
208 uint8_t segmentation_enabled;
209 uint8_t segmentation_update_map;
210 uint8_t segmentation_temporal_update;
211 uint8_t segmentation_update_data;
212 uint8_t feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
213 int16_t feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
215 uint8_t delta_q_present;
217 uint8_t delta_lf_present;
218 uint8_t delta_lf_res;
219 uint8_t delta_lf_multi;
221 uint8_t loop_filter_level[4];
222 uint8_t loop_filter_sharpness;
223 uint8_t loop_filter_delta_enabled;
224 uint8_t loop_filter_delta_update;
225 uint8_t update_ref_delta[AV1_TOTAL_REFS_PER_FRAME];
226 int8_t loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME];
227 uint8_t update_mode_delta[2];
228 int8_t loop_filter_mode_deltas[2];
230 uint8_t cdef_damping_minus_3;
232 uint8_t cdef_y_pri_strength[8];
233 uint8_t cdef_y_sec_strength[8];
234 uint8_t cdef_uv_pri_strength[8];
235 uint8_t cdef_uv_sec_strength[8];
238 uint8_t lr_unit_shift;
242 uint8_t reference_select;
243 uint8_t skip_mode_present;
245 uint8_t allow_warped_motion;
246 uint8_t reduced_tx_set;
248 uint8_t is_global[AV1_TOTAL_REFS_PER_FRAME];
249 uint8_t is_rot_zoom[AV1_TOTAL_REFS_PER_FRAME];
250 uint8_t is_translation[AV1_TOTAL_REFS_PER_FRAME];
251 //AV1RawSubexp gm_params[AV1_TOTAL_REFS_PER_FRAME][6];
252 uint32_t gm_params[AV1_TOTAL_REFS_PER_FRAME][6];
256 uint8_t update_grain;
257 uint8_t film_grain_params_ref_idx;
258 uint8_t num_y_points;
259 uint8_t point_y_value[16];
260 uint8_t point_y_scaling[16];
261 uint8_t chroma_scaling_from_luma;
262 uint8_t num_cb_points;
263 uint8_t point_cb_value[16];
264 uint8_t point_cb_scaling[16];
265 uint8_t num_cr_points;
266 uint8_t point_cr_value[16];
267 uint8_t point_cr_scaling[16];
268 uint8_t grain_scaling_minus_8;
269 uint8_t ar_coeff_lag;
270 uint8_t ar_coeffs_y_plus_128[24];
271 uint8_t ar_coeffs_cb_plus_128[24];
272 uint8_t ar_coeffs_cr_plus_128[24];
273 uint8_t ar_coeff_shift_minus_6;
274 uint8_t grain_scale_shift;
276 uint8_t cb_luma_mult;
279 uint8_t cr_luma_mult;
281 uint8_t overlap_flag;
282 uint8_t clip_to_restricted_range;
285 typedef struct AV1RawTileData {
288 AVBufferRef *data_ref;
291 typedef struct AV1RawTileGroup {
292 uint8_t tile_start_and_end_present_flag;
296 AV1RawTileData tile_data;
299 typedef struct AV1RawFrame {
300 AV1RawFrameHeader header;
301 AV1RawTileGroup tile_group;
304 typedef struct AV1RawTileList {
305 uint8_t output_frame_width_in_tiles_minus_1;
306 uint8_t output_frame_height_in_tiles_minus_1;
307 uint16_t tile_count_minus_1;
309 AV1RawTileData tile_data;
312 typedef struct AV1RawMetadataHDRCLL {
315 } AV1RawMetadataHDRCLL;
317 typedef struct AV1RawMetadataHDRMDCV {
318 uint16_t primary_chromaticity_x[3];
319 uint16_t primary_chromaticity_y[3];
320 uint16_t white_point_chromaticity_x;
321 uint16_t white_point_chromaticity_y;
322 uint32_t luminance_max;
323 uint32_t luminance_min;
324 } AV1RawMetadataHDRMDCV;
326 typedef struct AV1RawMetadataScalability {
327 uint8_t scalability_mode_idc;
329 } AV1RawMetadataScalability;
331 typedef struct AV1RawMetadataITUTT35 {
332 uint8_t itu_t_t35_country_code;
333 uint8_t itu_t_t35_country_code_extension_byte;
337 AVBufferRef *payload_ref;
338 } AV1RawMetadataITUTT35;
340 typedef struct AV1RawMetadataTimecode {
341 uint8_t counting_type;
342 uint8_t full_timestamp_flag;
343 uint8_t discontinuity_flag;
344 uint8_t cnt_dropped_flag;
346 uint8_t seconds_value;
347 uint8_t minutes_value;
349 uint8_t seconds_flag;
350 uint8_t minutes_flag;
352 uint8_t time_offset_length;
353 uint32_t time_offset_value;
354 } AV1RawMetadataTimecode;
356 typedef struct AV1RawMetadata {
357 uint64_t metadata_type;
359 AV1RawMetadataHDRCLL hdr_cll;
360 AV1RawMetadataHDRMDCV hdr_mdcv;
361 AV1RawMetadataScalability scalability;
362 AV1RawMetadataITUTT35 itut_t35;
363 AV1RawMetadataTimecode timecode;
368 typedef struct AV1RawOBU {
369 AV1RawOBUHeader header;
374 AV1RawSequenceHeader sequence_header;
375 AV1RawFrameHeader frame_header;
377 AV1RawTileGroup tile_group;
378 AV1RawTileList tile_list;
379 AV1RawMetadata metadata;
383 typedef struct AV1ReferenceFrameState {
384 int valid; // RefValid
385 int frame_id; // RefFrameId
386 int upscaled_width; // RefUpscaledWidth
387 int frame_width; // RefFrameWidth
388 int frame_height; // RefFrameHeight
389 int render_width; // RefRenderWidth
390 int render_height; // RefRenderHeight
391 int frame_type; // RefFrameType
392 int subsampling_x; // RefSubsamplingX
393 int subsampling_y; // RefSubsamplingY
394 int bit_depth; // RefBitDepth
395 int order_hint; // RefOrderHint
396 } AV1ReferenceFrameState;
398 typedef struct CodedBitstreamAV1Context {
399 AV1RawSequenceHeader *sequence_header;
400 AVBufferRef *sequence_header_ref;
402 int seen_frame_header;
403 AVBufferRef *frame_header_ref;
404 uint8_t *frame_header;
405 size_t frame_header_size;
409 int operating_point_idc;
424 AV1ReferenceFrameState ref[AV1_NUM_REF_FRAMES];
427 uint8_t *write_buffer;
428 size_t write_buffer_size;
429 } CodedBitstreamAV1Context;
432 #endif /* AVCODEC_CBS_AV1_H */