1 // Copyright (c) 2018 Intel Corporation
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in all
11 // copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 // SOFTWARE.
20 
21 #pragma once
22 
23 #include "bs_def.h"
24 
25 namespace BS_HEVC2
26 {
27 
28 typedef class Parser* HDL;
29 
30 enum INIT_MODE
31 {
32     INIT_MODE_DEFAULT   = 0x00,
33     PARSE_SSD           = 0x01,
34     PARALLEL_AU         = 0x02,
35     PARALLEL_SD         = 0x04,
36     PARALLEL_TILES      = 0x08,
37     PARSE_SSD_TC        = 0x10 | PARSE_SSD,
38 
39     ASYNC               = (PARALLEL_AU | PARALLEL_SD | PARALLEL_TILES)
40 };
41 
42 enum TRACE_LEVEL
43 {
44     TRACE_NUH       = 0x00000001,
45     TRACE_AUD       = 0x00000002,
46     TRACE_VPS       = 0x00000004,
47     TRACE_SPS       = 0x00000008,
48     TRACE_PPS       = 0x00000010,
49     TRACE_SEI       = 0x00000020,
50     TRACE_SSH       = 0x00000040,
51     TRACE_REF       = 0x00000080,
52     TRACE_CTU       = 0x00000100,
53     TRACE_SAO       = 0x00000200,
54     TRACE_CQT       = 0x00000400,
55     TRACE_CU        = 0x00000800,
56     TRACE_PU        = 0x00001000,
57     TRACE_TT        = 0x00002000,
58     TRACE_TU        = 0x00004000,
59     TRACE_RESIDUAL  = 0x00008000,
60     TRACE_PRED      = 0x04000000,
61     TRACE_QP        = 0x08000000,
62     TRACE_COEF      = 0x10000000,
63     TRACE_SIZE      = 0x40000000,
64     TRACE_OFFSET    = 0x80000000,
65     TRACE_DEFAULT =
66           TRACE_NUH
67         | TRACE_AUD
68         | TRACE_VPS
69         | TRACE_SPS
70         | TRACE_PPS
71         | TRACE_SEI
72         | TRACE_SSH
73         | TRACE_REF
74         | TRACE_SIZE
75         //| TRACE_OFFSET
76 };
77 
78 enum NALU_TYPE
79 {
80     TRAIL_N = 0,
81     TRAIL_R,
82     TSA_N,
83     TSA_R,
84     STSA_N,
85     STSA_R,
86     RADL_N,
87     RADL_R,
88     RASL_N,
89     RASL_R,
90     RSV_VCL_N10, RSV_VCL_R11, RSV_VCL_N12,
91     RSV_VCL_R13, RSV_VCL_N14, RSV_VCL_R15,
92     BLA_W_LP,
93     BLA_W_RADL,
94     BLA_N_LP,
95     IDR_W_RADL,
96     IDR_N_LP,
97     CRA_NUT,
98     RSV_IRAP_VCL22, RSV_IRAP_VCL23,
99     RSV_VCL24, RSV_VCL25, RSV_VCL26, RSV_VCL27,
100     RSV_VCL28, RSV_VCL29, RSV_VCL30, RSV_VCL31,
101     VPS_NUT,
102     SPS_NUT,
103     PPS_NUT,
104     AUD_NUT,
105     EOS_NUT,
106     EOB_NUT,
107     FD_NUT,
108     PREFIX_SEI_NUT,
109     SUFFIX_SEI_NUT,
110     RSV_NVCL41, RSV_NVCL42, RSV_NVCL43, RSV_NVCL44,
111     RSV_NVCL45, RSV_NVCL46, RSV_NVCL47,
112     UNSPEC48, UNSPEC49, UNSPEC50, UNSPEC51,
113     UNSPEC52, UNSPEC53, UNSPEC54, UNSPEC55,
114     UNSPEC56, UNSPEC57, UNSPEC58, UNSPEC59,
115     UNSPEC60, UNSPEC61, UNSPEC62, UNSPEC63,
116     num_NALU_TYPE
117 };
118 
119 enum PROFILE
120 {
121     MAIN     = 1,
122     MAIN_10  = 2,
123     MAIN_SP  = 3,
124     REXT     = 4,
125     REXT_HT  = 5,
126     MAIN_MV  = 6,
127     MAIN_SC  = 7,
128     MAIN_3D  = 8,
129     SCC      = 9,
130     REXT_SC  = 10
131 };
132 
133 enum PIC_TYPE
134 {
135     PIC_I = 0,
136     PIC_PI,
137     PIC_BPI
138 };
139 
140 enum CHROMA_FORMAT
141 {
142     CHROMA_400 = 0,
143     CHROMA_420 = 1,
144     CHROMA_422 = 2,
145     CHROMA_444 = 3
146 };
147 
148 enum AR_IDC
149 {
150     AR_IDC_1_1    =   1,
151     AR_IDC_square =   1,
152     AR_IDC_12_11  =   2,
153     AR_IDC_10_11  =   3,
154     AR_IDC_16_11  =   4,
155     AR_IDC_40_33  =   5,
156     AR_IDC_24_11  =   6,
157     AR_IDC_20_11  =   7,
158     AR_IDC_32_11  =   8,
159     AR_IDC_80_33  =   9,
160     AR_IDC_18_11  =  10,
161     AR_IDC_15_11  =  11,
162     AR_IDC_64_33  =  12,
163     AR_IDC_160_99 =  13,
164     AR_IDC_4_3    =  14,
165     AR_IDC_3_2    =  15,
166     AR_IDC_2_1    =  16,
167     Extended_SAR  = 255,
168 };
169 
170 enum VIDEO_FORMAT
171 {
172     Component = 0,
173     PAL       = 1,
174     NTSC      = 2,
175     SECAM     = 3,
176     MAC       = 4
177 };
178 
179 enum SEI_TYPE
180 {
181     SEI_BUFFERING_PERIOD                     = 0,
182     SEI_PICTURE_TIMING                       = 1,
183     SEI_PAN_SCAN_RECT                        = 2,
184     SEI_FILLER_PAYLOAD                       = 3,
185     SEI_USER_DATA_REGISTERED_ITU_T_T35       = 4,
186     SEI_USER_DATA_UNREGISTERED               = 5,
187     SEI_RECOVERY_POINT                       = 6,
188     SEI_SCENE_INFO                           = 9,
189     SEI_FULL_FRAME_SNAPSHOT                  = 15,
190     SEI_PROGRESSIVE_REFINEMENT_SEGMENT_START = 16,
191     SEI_PROGRESSIVE_REFINEMENT_SEGMENT_END   = 17,
192     SEI_FILM_GRAIN_CHARACTERISTICS           = 19,
193     SEI_POST_FILTER_HINT                     = 22,
194     SEI_TONE_MAPPING_INFO                    = 23,
195     SEI_FRAME_PACKING                        = 45,
196     SEI_DISPLAY_ORIENTATION                  = 47,
197     SEI_SOP_DESCRIPTION                      = 128,
198     SEI_ACTIVE_PARAMETER_SETS                = 129,
199     SEI_DECODING_UNIT_INFO                   = 130,
200     SEI_TEMPORAL_LEVEL0_INDEX                = 131,
201     SEI_DECODED_PICTURE_HASH                 = 132,
202     SEI_SCALABLE_NESTING                     = 133,
203     SEI_REGION_REFRESH_INFO                  = 134,
204     SEI_NO_DISPLAY                           = 135,
205     SEI_TIME_CODE                            = 136,
206     SEI_MASTERING_DISPLAY_COLOUR_VOLUME      = 137,
207     SEI_SEGM_RECT_FRAME_PACKING              = 138,
208     SEI_TEMP_MOTION_CONSTRAINED_TILE_SETS    = 139,
209     SEI_CHROMA_RESAMPLING_FILTER_HINT        = 140,
210     SEI_KNEE_FUNCTION_INFO                   = 141,
211     SEI_COLOUR_REMAPPING_INFO                = 142,
212 };
213 
214 enum PIC_STRUCT
215 {
216     FRAME = 0,
217     TOP,
218     BOT,
219     TOP_BOT,
220     BOT_TOP,
221     TOP_BOT_TOP,
222     BOT_TOP_BOT,
223     FRAME_x2,
224     FRAME_x3,
225     TOP_PREVBOT,
226     BOT_PREVTOP,
227     TOP_NEXTBOT,
228     BOT_NEXTTOP
229 };
230 
231 enum SOURCE_SCAN_TYPE
232 {
233     SCAN_INTERLACED = 0,
234     SCAN_PROGRESSIVE,
235     SCAN_UNKNOWN,
236     SCAN_RESERVED
237 };
238 
239 enum SLICE_TYPE
240 {
241     B = 0,
242     P,
243     I
244 };
245 
246 enum PRED_MODE
247 {
248       MODE_INTER = 0
249     , MODE_INTRA
250     , MODE_SKIP
251 };
252 
253 enum PART_MODE
254 {
255       PART_2Nx2N = 0
256     , PART_2NxN
257     , PART_Nx2N
258     , PART_NxN
259     , PART_2NxnU
260     , PART_2NxnD
261     , PART_nLx2N
262     , PART_nRx2N
263 };
264 
265 enum INTER_PRED
266 {
267       PRED_L0 = 0
268     , PRED_L1
269     , PRED_BI
270 };
271 
272 enum SAO_TYPE
273 {
274       NOT_APPLIED = 0
275     , BAND_OFFSET
276     , EDGE_OFFSET
277 };
278 
279 enum SAO_EO_CLASS
280 {
281       EO_0  = 0
282     , EO_90
283     , EO_135
284     , EO_45
285 };
286 
287 struct AUD
288 {
289     Bs8u pic_type;
290 };
291 
292 struct PTL
293 {
294     union
295     {
296         struct
297         {
298             Bs32u profile_space                    : 2;
299             Bs32u tier_flag                        : 1;
300             Bs32u profile_idc                      : 5;
301             Bs32u progressive_source_flag          : 1;
302             Bs32u interlaced_source_flag           : 1;
303             Bs32u non_packed_constraint_flag       : 1;
304             Bs32u frame_only_constraint_flag       : 1;
305             Bs32u max_12bit_constraint_flag        : 1;
306             Bs32u max_10bit_constraint_flag        : 1;
307             Bs32u max_8bit_constraint_flag         : 1;
308             Bs32u max_422chroma_constraint_flag    : 1;
309             Bs32u max_420chroma_constraint_flag    : 1;
310             Bs32u max_monochrome_constraint_flag   : 1;
311             Bs32u intra_constraint_flag            : 1;
312             Bs32u one_picture_only_constraint_flag : 1;
313             Bs32u lower_bit_rate_constraint_flag   : 1;
314             Bs32u reserved_zero_34bits_0_10        : 11;
315 
316             Bs32u reserved_zero_34bits_11_33       : 23;
317             Bs32u inbld_flag                       : 1;
318             Bs32u level_idc                        : 8;
319         };
320         struct
321         {
322             Bs32u                            : 21;
323             Bs32u max_14bit_constraint_flag  : 1;
324             Bs32u reserved_zero_33bits_0_9   : 10;
325 
326             Bs32u reserved_zero_33bits_10_32 : 23;
327             Bs32u                            : 9;
328         };
329         struct
330         {
331             Bs32u                            : 12;
332             Bs32u reserved_zero_43bits_0_19  : 20;
333 
334             Bs32u reserved_zero_43bits_20_42 : 23;
335             Bs32u reserved_zero_bit          : 1;
336             Bs32u                            : 8;
337         };
338     };
339 
340     Bs32u profile_compatibility_flags;
341 
342     Bs32u profile_present_flag             : 1;
343     Bs32u level_present_flag               : 1;
344     Bs32u                                  : 30;
345 };
346 
347 struct SubLayerOrderingInfo
348 {
349     Bs32u max_dec_pic_buffering_minus1 : 4;
350     Bs32u max_num_reorder_pics         : 4;
351     Bs32u                              : 24;
352     Bs32u max_latency_increase_plus1;
353 };
354 
355 struct HRD
356 {
357     Bs32u nal_hrd_parameters_present_flag                : 1;
358     Bs32u vcl_hrd_parameters_present_flag                : 1;
359     Bs32u sub_pic_hrd_params_present_flag                : 1;
360     Bs32u du_cpb_removal_delay_increment_length_minus1   : 5;
361     Bs32u dpb_output_delay_du_length_minus1              : 5;
362     Bs32u bit_rate_scale                                 : 4;
363     Bs32u initial_cpb_removal_delay_length_minus1        : 5;
364     Bs32u au_cpb_removal_delay_length_minus1             : 5;
365     Bs32u dpb_output_delay_length_minus1                 : 5;
366 
367     Bs32u tick_divisor_minus2                            : 8;
368     Bs32u cpb_size_scale                                 : 4;
369     Bs32u cpb_size_du_scale                              : 4;
370     Bs32u sub_pic_cpb_params_in_pic_timing_sei_flag      : 1;
371     Bs32u                                                : 15;
372 
373     struct SubLayer
374     {
375         Bs32u fixed_pic_rate_general_flag       : 1;
376         Bs32u fixed_pic_rate_within_cvs_flag    : 1;
377         Bs32u elemental_duration_in_tc_minus1   : 11;
378         Bs32u low_delay_hrd_flag                : 1;
379         Bs32u cpb_cnt_minus1                    : 5;
380         Bs32u                                   : 14;
381 
382         struct CPB
383         {
384             Bs32u bit_rate_value_minus1;
385             Bs32u cpb_size_value_minus1;
386             Bs32u cpb_size_du_value_minus1;
387             Bs32u bit_rate_du_value_minus1;
388             Bs32u cbr_flag : 1;
389             Bs32u          : 31;
390         } *nal, *vcl;
391     } sl[8];
392 };
393 
394 struct SubLayers
395 {
396     SubLayerOrderingInfo slo[8];
397 
398     union
399     {
400         struct
401         {
402             PTL general;
403             PTL sub_layer[7];
404         };
405         PTL ptl[8];
406     };
407 };
408 
409 struct VPS : SubLayers
410 {
411     Bs32u video_parameter_set_id    : 4;
412     Bs32u base_layer_internal_flag  : 1;
413     Bs32u base_layer_available_flag : 1;
414     Bs32u max_layers_minus1         : 6;
415     Bs32u max_sub_layers_minus1     : 3;
416     Bs32u temporal_id_nesting_flag  : 1;
417     Bs32u reserved_0xffff_16bits    : 16;
418 
419     Bs32u num_units_in_tick;
420     Bs32u time_scale;
421 
422     Bs32u timing_info_present_flag             : 1;
423     Bs32u poc_proportional_to_timing_flag      : 1;
424     Bs32u sub_layer_ordering_info_present_flag : 1;
425     Bs32u extension_flag                       : 1;
426     Bs32u num_ticks_poc_diff_one_minus1        : 10;
427     Bs32u num_hrd_parameters                   : 10;
428     Bs32u                                      : 8;
429 
430     Bs32u max_layer_id                         : 6;
431     Bs32u num_layer_sets_minus1                : 10;
432     Bs32u                                      : 16;
433 
434     Bs32u ExtBits;
435 
436     Bs8u* layer_id_included_flags;
437 
438     struct VPSHRD : HRD
439     {
440         Bs16u hrd_layer_set_idx  : 10;
441         Bs16u cprms_present_flag : 1;
442         Bs16u                    : 5;
443     } *hrd;
444 
445     Bs8u* ExtData;
446 };
447 
448 
449 struct VUI
450 {
451     Bs32u sar_width                               : 16;
452     Bs32u sar_height                              : 16;
453 
454     Bs32u aspect_ratio_info_present_flag          : 1;
455     Bs32u timing_info_present_flag                : 1;
456     Bs32u hrd_parameters_present_flag             : 1;
457     Bs32u poc_proportional_to_timing_flag         : 1;
458     Bs32u bitstream_restriction_flag              : 1;
459     Bs32u tiles_fixed_structure_flag              : 1;
460     Bs32u motion_vectors_over_pic_boundaries_flag : 1;
461     Bs32u restricted_ref_pic_lists_flag           : 1;
462     Bs32u aspect_ratio_idc                        : 8;
463     Bs32u overscan_info_present_flag              : 1;
464     Bs32u overscan_appropriate_flag               : 1;
465     Bs32u video_signal_type_present_flag          : 1;
466     Bs32u video_full_range_flag                   : 1;
467     Bs32u colour_description_present_flag         : 1;
468     Bs32u video_format                            : 3;
469     Bs32u chroma_loc_info_present_flag            : 1;
470     Bs32u neutral_chroma_indication_flag          : 1;
471     Bs32u chroma_sample_loc_type_top_field        : 3;
472     Bs32u chroma_sample_loc_type_bottom_field     : 3;
473 
474     Bs32u field_seq_flag                          : 1;
475     Bs32u frame_field_info_present_flag           : 1;
476     Bs32u default_display_window_flag             : 1;
477     Bs32u max_bytes_per_pic_denom                 : 5;
478     Bs32u colour_primaries                        : 8;
479     Bs32u transfer_characteristics                : 8;
480     Bs32u matrix_coeffs                           : 8;
481 
482     Bs32u log2_max_mv_length_horizontal           : 4;
483     Bs32u log2_max_mv_length_vertical             : 4;
484     Bs32u max_bits_per_min_cu_denom               : 5;
485     Bs32u                                         : 7;
486     Bs32u min_spatial_segmentation_idc            : 12;
487 
488     Bs32u def_disp_win_left_offset;
489     Bs32u def_disp_win_right_offset;
490     Bs32u def_disp_win_top_offset;
491     Bs32u def_disp_win_bottom_offset;
492 
493     Bs32u num_units_in_tick;
494     Bs32u time_scale;
495     Bs32u num_ticks_poc_diff_one_minus1;
496 
497     HRD* hrd;
498 };
499 
500 enum QM_IDX
501 {
502     QM_IntraY = 0,
503     QM_IntraCb,
504     QM_IntraCr,
505     QM_InterY,
506     QM_InterCb,
507     QM_InterCr,
508 };
509 
510 struct QM
511 {
512     Bs8u ScalingFactor0[6][4][4];
513     Bs8u ScalingFactor1[6][8][8];
514     Bs8u ScalingFactor2[6][16][16];
515     Bs8u ScalingFactor3[6][32][32];
516 };
517 
518 struct STRPS
519 {
520     Bs16u NumDeltaPocs;
521     Bs16u UsedByCurrPicFlags;
522     Bs16s DeltaPoc[16];
523 };
524 
525 struct SPS : SubLayers
526 {
527     Bs32u seq_parameter_set_id                      : 4;
528     Bs32u video_parameter_set_id                    : 4;
529     Bs32u temporal_id_nesting_flag                  : 1;
530     Bs32u num_short_term_ref_pic_sets               : 7;
531     Bs32u separate_colour_plane_flag                : 1;
532     Bs32u conformance_window_flag                   : 1;
533     Bs32u sub_layer_ordering_info_present_flag      : 1;
534     Bs32u chroma_format_idc                         : 2;
535     Bs32u max_sub_layers_minus1                     : 3;
536     Bs32u scaling_list_enabled_flag                 : 1;
537     Bs32u scaling_list_data_present_flag            : 1;
538     Bs32u amp_enabled_flag                          : 1;
539     Bs32u sample_adaptive_offset_enabled_flag       : 1;
540     Bs32u pcm_sample_bit_depth_luma_minus1          : 4;
541 
542     Bs32u pcm_enabled_flag                          : 1;
543     Bs32u pcm_loop_filter_disabled_flag             : 1;
544     Bs32u long_term_ref_pics_present_flag           : 1;
545     Bs32u temporal_mvp_enabled_flag                 : 1;
546     Bs32u pcm_sample_bit_depth_chroma_minus1        : 4;
547     Bs32u strong_intra_smoothing_enabled_flag       : 1;
548     Bs32u bit_depth_chroma_minus8                   : 4;
549     Bs32u log2_max_pic_order_cnt_lsb_minus4         : 4;
550     Bs32u vui_parameters_present_flag               : 1;
551     Bs32u bit_depth_luma_minus8                     : 4;
552     Bs32u num_long_term_ref_pics                    : 7;
553     Bs32u motion_vector_resolution_control_idc      : 2;
554     Bs32u intra_boundary_filtering_disabled_flag    : 1;
555 
556     Bs32u extension_present_flag                    : 1;
557     Bs32u range_extension_flag                      : 1;
558     Bs32u multilayer_extension_flag                 : 1;
559     Bs32u extension_3d_flag                         : 1;
560     Bs32u scc_extension_flag                        : 1;
561     Bs32u extension_xbits                           : 4;
562     Bs32u transform_skip_rotation_enabled_flag      : 1;
563     Bs32u transform_skip_context_enabled_flag       : 1;
564     Bs32u implicit_rdpcm_enabled_flag               : 1;
565     Bs32u explicit_rdpcm_enabled_flag               : 1;
566     Bs32u extended_precision_processing_flag        : 1;
567     Bs32u intra_smoothing_disabled_flag             : 1;
568     Bs32u high_precision_offsets_enabled_flag       : 1;
569     Bs32u persistent_rice_adaptation_enabled_flag   : 1;
570     Bs32u cabac_bypass_alignment_enabled_flag       : 1;
571     Bs32u inter_view_mv_vert_constraint_flag        : 1;
572     Bs32u log2_min_luma_transform_block_size_minus2     : 5;
573     Bs32u log2_diff_max_min_luma_transform_block_size   : 5;
574     Bs32u curr_pic_ref_enabled_flag                  : 1;
575     Bs32u palette_mode_enabled_flag                  : 1;
576     Bs32u palette_predictor_initializer_present_flag : 1;
577 
578     Bs32u log2_min_luma_coding_block_size_minus3        : 5;
579     Bs32u log2_diff_max_min_luma_coding_block_size      : 5;
580     Bs32u log2_min_pcm_luma_coding_block_size_minus3    : 5;
581     Bs32u log2_diff_max_min_pcm_luma_coding_block_size  : 5;
582     Bs32u max_transform_hierarchy_depth_inter           : 6;
583     Bs32u max_transform_hierarchy_depth_intra           : 6;
584 
585     Bs16u pic_width_in_luma_samples;
586     Bs16u pic_height_in_luma_samples;
587 
588     Bs16u conf_win_left_offset;
589     Bs16u conf_win_right_offset;
590 
591     Bs16u conf_win_top_offset;
592     Bs16u conf_win_bottom_offset;
593 
594     Bs32u used_by_curr_pic_lt_flags;
595 
596     Bs8u palette_max_size;
597     Bs8s delta_palette_max_predictor_size;
598     Bs16u num_palette_predictor_initializer;
599 
600     Bs32u ExtBits;
601 
602     Bs8u    *ExtData;
603     STRPS   *strps;
604     Bs16u   *lt_ref_pic_poc_lsb;
605     QM      *qm;
606     VUI     *vui;
607     Bs16u   *palette_predictor_initializers[3];
608 };
609 
610 struct PPS
611 {
612     Bs32u pic_parameter_set_id                        : 6;
613     Bs32u seq_parameter_set_id                        : 4;
614     Bs32u dependent_slice_segments_enabled_flag       : 1;
615     Bs32u output_flag_present_flag                    : 1;
616     Bs32u sign_data_hiding_enabled_flag               : 1;
617     Bs32u cabac_init_present_flag                     : 1;
618     Bs32u constrained_intra_pred_flag                 : 1;
619     Bs32u transform_skip_enabled_flag                 : 1;
620     Bs32u cu_qp_delta_enabled_flag                    : 1;
621     Bs32u slice_chroma_qp_offsets_present_flag        : 1;
622     Bs32u weighted_pred_flag                          : 1;
623     Bs32u weighted_bipred_flag                        : 1;
624     Bs32u transquant_bypass_enabled_flag              : 1;
625     Bs32u tiles_enabled_flag                          : 1;
626     Bs32u entropy_coding_sync_enabled_flag            : 1;
627     Bs32u uniform_spacing_flag                        : 1;
628     Bs32u loop_filter_across_tiles_enabled_flag       : 1;
629     Bs32u loop_filter_across_slices_enabled_flag      : 1;
630     Bs32u deblocking_filter_control_present_flag      : 1;
631     Bs32u deblocking_filter_override_enabled_flag     : 1;
632     Bs32u deblocking_filter_disabled_flag             : 1;
633     Bs32u scaling_list_data_present_flag              : 1;
634     Bs32u lists_modification_present_flag             : 1;
635     Bs32u slice_segment_header_extension_present_flag : 1;
636 
637     Bs32u num_extra_slice_header_bits                 : 3;
638     Bs32u num_ref_idx_l0_default_active_minus1        : 4;
639     Bs32u num_ref_idx_l1_default_active_minus1        : 4;
640     Bs32u extension_present_flag                      : 1;
641     Bs32u range_extension_flag                        : 1;
642     Bs32u multilayer_extension_flag                   : 1;
643     Bs32u extension_3d_flag                           : 1;
644     Bs32u scc_extension_flag                          : 1;
645     Bs32u extension_xbits                             : 4;
646     Bs32u                                             : 12;
647 
648     Bs32u curr_pic_ref_enabled_flag                         : 1;
649     Bs32u residual_adaptive_colour_transform_enabled_flag   : 1;
650     Bs32u slice_act_qp_offsets_present_flag                 : 1;
651     Bs32u palette_predictor_initializer_present_flag        : 1;
652     Bs32u monochrome_palette_flag                           : 1;
653     Bs32u luma_bit_depth_entry_minus8                       : 4;
654     Bs32u chroma_bit_depth_entry_minus8                     : 4;
655     Bs32u num_palette_predictor_initializer                 : 16;
656     Bs32u                                                   : 3;
657     Bs32s ActQpOffsetY  : 5; //-12 to +12,
658     Bs32s ActQpOffsetCb : 5; //-12 to +12,
659     Bs32s ActQpOffsetCr : 5; //-12 to +12,
660     Bs32s               : 17;
661 
662     Bs8s init_qp_minus26;
663     Bs8s cb_qp_offset;
664     Bs8s cr_qp_offset;
665     Bs8s beta_offset_div2 : 4;
666     Bs8s tc_offset_div2   : 4;
667 
668     Bs32u cross_component_prediction_enabled_flag   : 1;
669     Bs32u chroma_qp_offset_list_enabled_flag        : 1;
670     Bs32u log2_sao_offset_scale_luma                : 3;
671     Bs32u log2_sao_offset_scale_chroma              : 3;
672     Bs32u chroma_qp_offset_list_len_minus1          : 3;
673     Bs32u diff_cu_chroma_qp_offset_depth            : 5;
674     Bs32u log2_max_transform_skip_block_size_minus2 : 5;
675     Bs32u                                           : 11;
676 
677     Bs8s cb_qp_offset_list[6];
678     Bs8s cr_qp_offset_list[6];
679 
680     Bs16u diff_cu_qp_delta_depth;
681     Bs16u num_tile_columns_minus1;
682     Bs16u num_tile_rows_minus1;
683     Bs16u log2_parallel_merge_level_minus2;
684 
685     Bs32u ExtBits;
686 
687     Bs8u  *ExtData;
688     Bs16u *column_width_minus1;
689     Bs16u *row_height_minus1;
690     Bs16u *CtbAddrRsToTs;
691     QM    *qm;
692     Bs16u *palette_predictor_initializers[3];
693 };
694 
695 struct APS_SEI
696 {
697     Bs32u active_video_parameter_set_id : 4;
698     Bs32u self_contained_cvs_flag       : 1;
699     Bs32u no_parameter_set_update_flag  : 1;
700     Bs32u num_sps_ids_minus1            : 4;
701     Bs32u                               : 22;
702     Bs8u* active_seq_parameter_set_id;
703     Bs8u* layer_sps_idx;
704 };
705 
706 struct BP_SEI
707 {
708     Bs32u seq_parameter_set_id               : 4;
709     Bs32u irap_cpb_params_present_flag       : 1;
710     Bs32u concatenation_flag                 : 1;
711     Bs32u use_alt_cpb_params_flag            : 1;
712     Bs32u au_cpb_removal_delay_delta_minus1;
713     Bs32u cpb_delay_offset;
714     Bs32u dpb_delay_offset;
715 
716     struct CPB
717     {
718         Bs32u initial_cpb_removal_delay;
719         Bs32u initial_cpb_removal_offset;
720         Bs32u initial_alt_cpb_removal_delay;
721         Bs32u initial_alt_cpb_removal_offset;
722     } *nal, *vcl;
723 };
724 
725 struct PT_SEI
726 {
727     Bs32u pic_struct                       : 4;
728     Bs32u source_scan_type                 : 2;
729     Bs32u duplicate_flag                   : 1;
730     Bs32u du_common_cpb_removal_delay_flag : 1;
731 
732     Bs32u au_cpb_removal_delay_minus1;
733     Bs32u pic_dpb_output_delay;
734     Bs32u pic_dpb_output_du_delay;
735     Bs32u num_decoding_units_minus1;
736     Bs32u du_common_cpb_removal_delay_increment_minus1;
737 
738     Bs32u *num_nalus_in_du_minus1;
739     Bs32u *du_cpb_removal_delay_increment_minus1;
740 
741     VUI* vui;
742 };
743 
744 struct RP_SEI
745 {
746     Bs16s recovery_poc_cnt;
747     Bs16u exact_match_flag : 1;
748     Bs16u broken_link_flag : 1;
749 };
750 
751 struct SEI
752 {
753     Bs32u payloadType;
754     Bs32u payloadSize;
755 
756     Bs8u* rawData;
757 
758     union
759     {
760         APS_SEI *aps;
761         BP_SEI  *bp;
762         PT_SEI  *pt;
763         RP_SEI  *rp;
764     };
765 
766     SEI* next;
767 };
768 
769 typedef Bs16s PWT[16][3][2];
770 
771 struct RefPic
772 {
773     Bs32u long_term :  1;
774     Bs32u lost      :  1;
775     Bs32u used      :  1;
776     Bs32u           : 29;
777     Bs32s POC;
778 };
779 
780 struct PU
781 {
782     Bs16u x;
783     Bs16u y;
784     Bs16u w : 8;
785     Bs16u h : 8;
786 
787     Bs16u merge_idx      : 3;
788     Bs16u merge_flag     : 1;
789     Bs16u inter_pred_idc : 2;
790     Bs16u mvp_l0_flag    : 1;
791     Bs16u mvp_l1_flag    : 1;
792     Bs16u ref_idx_l0     : 4;
793     Bs16u ref_idx_l1     : 4;
794 
795     Bs16s MvLX[2][2];
796 
797     PU* Next;
798 };
799 
800 struct TU
801 {
802     Bs16u x;
803     Bs16u y;
804 
805     Bs32u log2TrafoSize       : 8;
806     Bs32u transform_skip_flag : 3;
807     Bs32u cbf_cb              : 1;
808     Bs32u cbf_cb1             : 1;
809     Bs32u cbf_cr              : 1;
810     Bs32u cbf_cr1             : 1;
811     Bs32u cbf_luma            : 1;
812 
813     Bs32u log2_res_scale_abs_plus1_0 : 3;
814     Bs32u res_scale_sign_flag_0      : 1;
815     Bs32u log2_res_scale_abs_plus1_1 : 3;
816     Bs32u res_scale_sign_flag_1      : 1;
817     Bs32u tu_residual_act_flag       : 1;
818     Bs32u                            : 7;
819 
820     Bs16s QP[3];
821 
822     Bs32s* tc_levels_luma;
823 
824     TU* Next;
825 };
826 
827 struct CU
828 {
829     Bs16u x;
830     Bs16u y;
831 
832     Bs32u log2CbSize             : 8;
833     Bs32u transquant_bypass_flag : 1;
834     Bs32u PredMode               : 2;
835     Bs32u PartMode               : 4;
836     Bs32u pcm_flag               : 1;
837     Bs32u palette_mode_flag      : 1;
838     Bs32u chroma_qp_offset_flag  : 1;
839     Bs32u chroma_qp_offset_idx   : 3;
840     Bs32u                        : 11;
841 
842     Bs8u IntraPredModeY[2][2];
843     Bs8u IntraPredModeC[2][2];
844 
845     Bs16s QpY;
846     Bs16s QpCb;
847     Bs16s QpCr;
848 
849     PU* Pu;
850     TU* Tu;
851     CU* Next;
852 };
853 
854 struct SAO
855 {
856     Bs16u type_idx      : 2;
857     Bs16u band_position : 5;
858     Bs16u eo_class      : 2;
859     Bs16u               : 7;
860     Bs8s  offset[4];
861 };
862 
863 struct CTU
864 {
865     Bs16u CtbAddrInRs;
866     Bs16u CtbAddrInTs;
867 
868     Bs16u end_of_slice_segment_flag :  1;
869     Bs16u sao_merge_left_flag       :  1;
870     Bs16u sao_merge_up_flag         :  1;
871     Bs16u                           : 13;
872 
873     SAO  sao[3];
874     CU*  Cu;
875     CTU* Next;
876 };
877 
878 struct Slice
879 {
880     Bs32u first_slice_segment_in_pic_flag           : 1;
881     Bs32u no_output_of_prior_pics_flag              : 1;
882     Bs32u dependent_slice_segment_flag              : 1;
883     Bs32u sao_luma_flag                             : 1;
884     Bs32u sao_chroma_flag                           : 1;
885     Bs32u colour_plane_id                           : 2;
886     Bs32u num_ref_idx_l0_active                     : 4;
887     Bs32u num_ref_idx_l1_active                     : 4;
888     Bs32u num_long_term_pics                        : 4;
889     Bs32u collocated_ref_idx                        : 4;
890     Bs32u short_term_ref_pic_set_idx                : 6;
891     Bs32u ref_pic_list_modification_flag_l0         : 1;
892     Bs32u ref_pic_list_modification_flag_l1         : 1;
893     Bs32u Split                                     : 1;
894 
895     Bs32u temporal_mvp_enabled_flag                 : 1;
896     Bs32u num_ref_idx_active_override_flag          : 1;
897     Bs32u mvd_l1_zero_flag                          : 1;
898     Bs32u cabac_init_flag                           : 1;
899     Bs32u collocated_from_l0_flag                   : 1;
900     Bs32u cu_chroma_qp_offset_enabled_flag          : 1;
901     Bs32u deblocking_filter_override_flag           : 1;
902     Bs32u deblocking_filter_disabled_flag           : 1;
903     Bs32u loop_filter_across_slices_enabled_flag    : 1;
904     Bs32u pic_output_flag                           : 1;
905     Bs32u short_term_ref_pic_set_sps_flag           : 1;
906     Bs32u type                                      : 2;
907     Bs32u MaxNumMergeCand                           : 3;
908     Bs32u num_long_term_sps                         : 5;
909     Bs32u offset_len_minus1                         : 5;
910     Bs32u pic_parameter_set_id                      : 6;
911 
912     Bs32u pic_order_cnt_lsb         : 16;
913     Bs32u reserved_flags            : 8;
914     Bs32u luma_log2_weight_denom    : 3;
915     Bs32u chroma_log2_weight_denom  : 3;
916     Bs32u use_integer_mv_flag       : 1;
917     Bs32u                           : 1;
918 
919     Bs32u slice_segment_address;
920 
921     Bs32u num_entry_point_offsets;
922     Bs32u ExtBits;
923 
924     Bs32s qp_delta         : 8;
925     Bs32s cb_qp_offset     : 8;
926     Bs32s cr_qp_offset     : 8;
927     Bs32s beta_offset_div2 : 4;
928     Bs32s tc_offset_div2   : 4;
929 
930     Bs32u used_by_curr_pic_lt_flags;
931 
932     Bs32s POC;
933     Bs32u NumCTU;
934 
935     Bs32s act_y_qp_offset  : 6;
936     Bs32s act_cb_qp_offset : 6;
937     Bs32s act_cr_qp_offset : 6;
938     Bs32s                  : 14;
939 
940     STRPS strps;
941     Bs8u  list_entry_lx[2][16];
942 
943     Bs8u   *ExtData;
944     Bs16u  *poc_lsb_lt;
945     Bs16u  *DeltaPocMsbCycleLt;
946     PWT    *pwt; //[list][entry][Y, Cb, Cr][Weight, Offset]
947     Bs32u  *entry_point_offset_minus1;
948 
949     RefPic *DPB;
950     RefPic *L0;
951     RefPic *L1;
952 
953     PPS    *pps;
954     SPS    *sps;
955     CTU    *ctu;
956 };
957 
958 struct NALU
959 {
960     Bs64u StartOffset;
961     Bs32u NumBytesInNalUnit;
962     Bs32u NumBytesInRbsp;
963 
964     Bs16u forbidden_zero_bit    : 1;
965     Bs16u nal_unit_type         : 6;
966     Bs16u nuh_layer_id          : 6;
967     Bs16u nuh_temporal_id_plus1 : 3;
968 
969     union
970     {
971         void  *unit;
972         AUD   *aud;
973         VPS   *vps;
974         SPS   *sps;
975         PPS   *pps;
976         SEI   *sei;
977         Slice *slice;
978     };
979 
980     NALU* next;
981 };
982 
983 };
984