xref: /rockchip-linux_mpp/mpp/codec/dec/av1/av1d_cbs.h (revision 437bfbeb9567cca9cd9080e3f6954aa9d6a94f18)
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_U8 ref_frame_valued;
198     RK_S8  ref_frame_idx[AV1_REFS_PER_FRAME];
199     RK_U32 delta_frame_id_minus1[AV1_REFS_PER_FRAME];
200 
201     RK_U8 allow_high_precision_mv;
202     RK_U8 is_filter_switchable;
203     RK_U8 interpolation_filter;
204     RK_U8 is_motion_mode_switchable;
205     RK_U8 use_ref_frame_mvs;
206 
207     RK_U8 disable_frame_end_update_cdf;
208 
209     RK_U8 uniform_tile_spacing_flag;
210     RK_U8 tile_cols_log2;
211     RK_U8 tile_rows_log2;
212     RK_U8 width_in_sbs_minus_1[AV1_MAX_TILE_COLS];
213     RK_U8 height_in_sbs_minus_1[AV1_MAX_TILE_ROWS];
214     RK_U16 context_update_tile_id;
215     RK_U8 tile_size_bytes_minus1;
216 
217     // These are derived values, but it's very unhelpful to have to
218     // recalculate them all the time so we store them here.
219     RK_U16 tile_cols;
220     RK_U16 tile_rows;
221 
222     RK_U8 base_q_idx;
223     RK_S8  delta_q_y_dc;
224     RK_U8 diff_uv_delta;
225     RK_S8  delta_q_u_dc;
226     RK_S8  delta_q_u_ac;
227     RK_S8  delta_q_v_dc;
228     RK_S8  delta_q_v_ac;
229     RK_U8 using_qmatrix;
230     RK_U8 qm_y;
231     RK_U8 qm_u;
232     RK_U8 qm_v;
233 
234     RK_U8 segmentation_enabled;
235     RK_U8 segmentation_update_map;
236     RK_U8 segmentation_temporal_update;
237     RK_U8 segmentation_update_data;
238     RK_U8 feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
239     RK_S16 feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
240     RK_U8 segmentation_id_last_active;
241     RK_U8 segmentation_id_preskip;
242 
243     RK_U8 delta_q_present;
244     RK_U8 delta_q_res;
245     RK_U8 delta_lf_present;
246     RK_U8 delta_lf_res;
247     RK_U8 delta_lf_multi;
248 
249     RK_U8 loop_filter_level[4];
250     RK_U8 loop_filter_sharpness;
251     RK_U8 loop_filter_delta_enabled;
252     RK_U8 loop_filter_delta_update;
253     RK_U8 update_ref_delta[AV1_TOTAL_REFS_PER_FRAME];
254     RK_S8  loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME];
255     RK_U8 update_mode_delta[2];
256     RK_S8  loop_filter_mode_deltas[2];
257 
258     RK_U8 cdef_damping_minus_3;
259     RK_U8 cdef_bits;
260     RK_U8 cdef_y_pri_strength[8];
261     RK_U8 cdef_y_sec_strength[8];
262     RK_U8 cdef_uv_pri_strength[8];
263     RK_U8 cdef_uv_sec_strength[8];
264 
265     RK_U8 lr_type[3];
266     RK_U8 lr_unit_shift;
267     RK_U8 lr_uv_shift;
268 
269     RK_U8 tx_mode;
270     RK_U8 reference_select;
271     RK_U8 skip_mode_present;
272 
273     RK_U8 allow_warped_motion;
274     RK_U8 reduced_tx_set;
275 
276     RK_U8 is_global[AV1_TOTAL_REFS_PER_FRAME];
277     RK_U8 is_rot_zoom[AV1_TOTAL_REFS_PER_FRAME];
278     RK_U8 is_translation[AV1_TOTAL_REFS_PER_FRAME];
279     //AV1RawSubexp gm_params[AV1_TOTAL_REFS_PER_FRAME][6];
280     RK_U32 gm_params[AV1_TOTAL_REFS_PER_FRAME][6];
281 
282     AV1RawFilmGrainParams film_grain;
283 } AV1RawFrameHeader;
284 
285 typedef struct AV1RawTileData {
286     RK_U8   *data;
287     size_t  offset;
288     size_t  data_size;
289 } AV1RawTileData;
290 
291 typedef struct AV1RawTileGroup {
292     RK_U8  tile_start_and_end_present_flag;
293     RK_U8 tg_start;
294     RK_U8 tg_end;
295 
296     AV1RawTileData tile_data;
297 } AV1RawTileGroup;
298 
299 typedef struct AV1RawFrame {
300     AV1RawFrameHeader header;
301     AV1RawTileGroup   tile_group;
302 } AV1RawFrame;
303 
304 typedef struct AV1RawTileList {
305     RK_U8 output_frame_width_in_tiles_minus_1;
306     RK_U8 output_frame_height_in_tiles_minus_1;
307     RK_U8 tile_count_minus_1;
308 
309     AV1RawTileData tile_data;
310 } AV1RawTileList;
311 
312 typedef struct AV1RawMetadataHDRCLL {
313     RK_U16 max_cll;
314     RK_U16 max_fall;
315 } AV1RawMetadataHDRCLL;
316 
317 typedef struct AV1RawMetadataHDRMDCV {
318     RK_U16 primary_chromaticity_x[3];
319     RK_U16 primary_chromaticity_y[3];
320     RK_U16 white_point_chromaticity_x;
321     RK_U16 white_point_chromaticity_y;
322     RK_U32 luminance_max;
323     RK_U32 luminance_min;
324 } AV1RawMetadataHDRMDCV;
325 
326 typedef struct AV1RawMetadataScalability {
327     RK_U8 scalability_mode_idc;
328     RK_U8 spatial_layers_cnt_minus_1;
329     RK_U8 spatial_layer_dimensions_present_flag;
330     RK_U8 spatial_layer_description_present_flag;
331     RK_U8 temporal_group_description_present_flag;
332     RK_U8 scalability_structure_reserved_3bits;
333     RK_U8 spatial_layer_max_width[4];
334     RK_U8 spatial_layer_max_height[4];
335     RK_U8 spatial_layer_ref_id[4];
336     RK_U8 temporal_group_size;
337     RK_U8 temporal_group_temporal_id[255];
338     RK_U8 temporal_group_temporal_switching_up_point_flag[255];
339     RK_U8 temporal_group_spatial_switching_up_point_flag[255];
340     RK_U8 temporal_group_ref_cnt[255];
341     RK_U8 temporal_group_ref_pic_diff[255][7];
342 } AV1RawMetadataScalability;
343 
344 typedef struct AV1RawMetadataITUTT35 {
345     RK_U8 itu_t_t35_country_code;
346     RK_U8 itu_t_t35_country_code_extension_byte;
347     RK_U32 itu_t_t35_terminal_provider_code;
348     RK_U32 itu_t_t35_terminal_provider_oriented_code;
349 
350     RK_U8     *payload;
351     size_t     payload_size;
352 } AV1RawMetadataITUTT35;
353 
354 typedef struct AV1RawMetadataTimecode {
355     RK_U8  counting_type;
356     RK_U8  full_timestamp_flag;
357     RK_U8  discontinuity_flag;
358     RK_U8  cnt_dropped_flag;
359     RK_U8  n_frames;
360     RK_U8  seconds_value;
361     RK_U8  minutes_value;
362     RK_U8  hours_value;
363     RK_U8  seconds_flag;
364     RK_U8  minutes_flag;
365     RK_U8  hours_flag;
366     RK_U8  time_offset_length;
367     RK_U32 time_offset_value;
368 } AV1RawMetadataTimecode;
369 
370 typedef struct AV1RawMetadata {
371     RK_U64 metadata_type;
372     union {
373         AV1RawMetadataHDRCLL      hdr_cll;
374         AV1RawMetadataHDRMDCV     hdr_mdcv;
375         AV1RawMetadataScalability scalability;
376         AV1RawMetadataITUTT35     itut_t35;
377         AV1RawMetadataTimecode    timecode;
378     } metadata;
379 } AV1RawMetadata;
380 
381 typedef struct AV1RawPadding {
382     RK_U8     *payload;
383     size_t       payload_size;
384 } AV1RawPadding;
385 
386 
387 typedef struct AV1RawOBU {
388     AV1RawOBUHeader header;
389 
390     size_t obu_size;
391 
392     union {
393         AV1RawSequenceHeader sequence_header;
394         AV1RawFrameHeader    frame_header;
395         AV1RawFrame          frame;
396         AV1RawTileGroup      tile_group;
397         AV1RawTileList       tile_list;
398         AV1RawMetadata       metadata;
399         AV1RawPadding        padding;
400     } obu;
401 } AV1RawOBU;
402 
403 typedef struct AV1ReferenceFrameState {
404     RK_S32 valid;          // RefValid
405     RK_S32 frame_id;       // RefFrameId
406     RK_S32 upscaled_width; // RefUpscaledWidth
407     RK_S32 frame_width;    // RefFrameWidth
408     RK_S32 frame_height;   // RefFrameHeight
409     RK_S32 render_width;   // RefRenderWidth
410     RK_S32 render_height;  // RefRenderHeight
411     RK_S32 frame_type;     // RefFrameType
412     RK_S32 subsampling_x;  // RefSubsamplingX
413     RK_S32 subsampling_y;  // RefSubsamplingY
414     RK_S32 bit_depth;      // RefBitDepth
415     RK_S32 order_hint;     // RefOrderHint
416 
417     RK_S8  loop_filter_ref_deltas[AV1_TOTAL_REFS_PER_FRAME];
418     RK_S8  loop_filter_mode_deltas[2];
419     RK_U8 feature_enabled[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
420     RK_S16 feature_value[AV1_MAX_SEGMENTS][AV1_SEG_LVL_MAX];
421 } AV1ReferenceFrameState;
422 
423 
424 typedef RK_U32 Av1UnitType;
425 
426 typedef struct Av1ObuUnit_t {
427     /**
428      * Codec-specific type of this unit.
429      */
430     Av1UnitType type;
431 
432     /**
433      * Pointer to the directly-parsable bitstream form of this unit.
434      *
435      * May be NULL if the unit currently only exists in decomposed form.
436      */
437     RK_U8 *data;
438 
439     size_t   data_size;
440 
441     void     *content;
442 } Av1ObuUnit;
443 
444 typedef struct Av1UnitFragment_t {
445     RK_U8    *data;
446     size_t     data_size;
447     int        nb_units;
448     int        nb_units_allocated;
449     Av1ObuUnit *units;
450 } Av1UnitFragment;
451 
452 #endif //__AV1D_CBS_H__
453