24 fixed(1, rbsp_stop_one_bit, 1);
26 fixed(1, rbsp_alignment_zero_bit, 0);
32 int expected_nal_unit_type)
36 fixed(1, forbidden_zero_bit, 0);
37 flag(nuh_reserved_zero_bit);
39 u(6, nuh_layer_id, 0, 55);
41 if (expected_nal_unit_type >= 0)
42 u(5, nal_unit_type, expected_nal_unit_type, expected_nal_unit_type);
46 u(3, nuh_temporal_id_plus1, 1, 7);
54 fixed(1, byte_alignment_bit_equal_to_one, 1);
56 fixed(1, byte_alignment_bit_equal_to_zero, 0);
64 int err,
i, num_additional_bits_used;
66 flag(gci_present_flag);
67 if (current->gci_present_flag) {
69 flag(gci_intra_only_constraint_flag);
70 flag(gci_all_layers_independent_constraint_flag);
71 flag(gci_one_au_only_constraint_flag);
74 u(4, gci_sixteen_minus_max_bitdepth_constraint_idc, 0, 8);
75 ub(2, gci_three_minus_max_chroma_format_constraint_idc);
78 flag(gci_no_mixed_nalu_types_in_pic_constraint_flag);
79 flag(gci_no_trail_constraint_flag);
80 flag(gci_no_stsa_constraint_flag);
81 flag(gci_no_rasl_constraint_flag);
82 flag(gci_no_radl_constraint_flag);
83 flag(gci_no_idr_constraint_flag);
84 flag(gci_no_cra_constraint_flag);
85 flag(gci_no_gdr_constraint_flag);
86 flag(gci_no_aps_constraint_flag);
87 flag(gci_no_idr_rpl_constraint_flag);
90 flag(gci_one_tile_per_pic_constraint_flag);
91 flag(gci_pic_header_in_slice_header_constraint_flag);
92 flag(gci_one_slice_per_pic_constraint_flag);
93 flag(gci_no_rectangular_slice_constraint_flag);
94 flag(gci_one_slice_per_subpic_constraint_flag);
95 flag(gci_no_subpic_info_constraint_flag);
98 ub(2, gci_three_minus_max_log2_ctu_size_constraint_idc);
99 flag(gci_no_partition_constraints_override_constraint_flag);
100 flag(gci_no_mtt_constraint_flag);
101 flag(gci_no_qtbtt_dual_tree_intra_constraint_flag);
104 flag(gci_no_palette_constraint_flag);
105 flag(gci_no_ibc_constraint_flag);
106 flag(gci_no_isp_constraint_flag);
107 flag(gci_no_mrl_constraint_flag);
108 flag(gci_no_mip_constraint_flag);
109 flag(gci_no_cclm_constraint_flag);
112 flag(gci_no_ref_pic_resampling_constraint_flag);
113 flag(gci_no_res_change_in_clvs_constraint_flag);
114 flag(gci_no_weighted_prediction_constraint_flag);
115 flag(gci_no_ref_wraparound_constraint_flag);
116 flag(gci_no_temporal_mvp_constraint_flag);
117 flag(gci_no_sbtmvp_constraint_flag);
118 flag(gci_no_amvr_constraint_flag);
119 flag(gci_no_bdof_constraint_flag);
120 flag(gci_no_smvd_constraint_flag);
121 flag(gci_no_dmvr_constraint_flag);
122 flag(gci_no_mmvd_constraint_flag);
123 flag(gci_no_affine_motion_constraint_flag);
124 flag(gci_no_prof_constraint_flag);
125 flag(gci_no_bcw_constraint_flag);
126 flag(gci_no_ciip_constraint_flag);
127 flag(gci_no_gpm_constraint_flag);
130 flag(gci_no_luma_transform_size_64_constraint_flag);
131 flag(gci_no_transform_skip_constraint_flag);
132 flag(gci_no_bdpcm_constraint_flag);
133 flag(gci_no_mts_constraint_flag);
134 flag(gci_no_lfnst_constraint_flag);
135 flag(gci_no_joint_cbcr_constraint_flag);
136 flag(gci_no_sbt_constraint_flag);
137 flag(gci_no_act_constraint_flag);
138 flag(gci_no_explicit_scaling_list_constraint_flag);
139 flag(gci_no_dep_quant_constraint_flag);
140 flag(gci_no_sign_data_hiding_constraint_flag);
141 flag(gci_no_cu_qp_delta_constraint_flag);
142 flag(gci_no_chroma_qp_offset_constraint_flag);
145 flag(gci_no_sao_constraint_flag);
146 flag(gci_no_alf_constraint_flag);
147 flag(gci_no_ccalf_constraint_flag);
148 flag(gci_no_lmcs_constraint_flag);
149 flag(gci_no_ladf_constraint_flag);
150 flag(gci_no_virtual_boundaries_constraint_flag);
151 ub(8, gci_num_additional_bits);
152 if (current->gci_num_additional_bits > 5) {
153 flag(gci_all_rap_pictures_constraint_flag);
154 flag(gci_no_extended_precision_processing_constraint_flag);
155 flag(gci_no_ts_residual_coding_rice_constraint_flag);
156 flag(gci_no_rrc_rice_extension_constraint_flag);
157 flag(gci_no_persistent_rice_adaptation_constraint_flag);
158 flag(gci_no_reverse_last_sig_coeff_constraint_flag);
159 num_additional_bits_used = 6;
161 infer(gci_all_rap_pictures_constraint_flag, 0);
162 infer(gci_no_extended_precision_processing_constraint_flag, 0);
163 infer(gci_no_ts_residual_coding_rice_constraint_flag, 0);
164 infer(gci_no_rrc_rice_extension_constraint_flag, 0);
165 infer(gci_no_persistent_rice_adaptation_constraint_flag, 0);
166 infer(gci_no_reverse_last_sig_coeff_constraint_flag, 0);
167 num_additional_bits_used = 0;
170 for (
i = 0;
i < current->gci_num_additional_bits - num_additional_bits_used;
i++)
171 flags(gci_reserved_bit[
i], 1,
i);
174 fixed(1, gci_alignment_zero_bit, 0);
181 int profile_tier_present_flag,
182 int max_num_sub_layers_minus1)
186 if (profile_tier_present_flag) {
187 ub(7, general_profile_idc);
188 flag(general_tier_flag);
190 ub(8, general_level_idc);
191 flag(ptl_frame_only_constraint_flag);
192 flag(ptl_multilayer_enabled_flag);
193 if (profile_tier_present_flag) {
198 for (
i = max_num_sub_layers_minus1 - 1;
i >= 0;
i--)
199 flags(ptl_sublayer_level_present_flag[
i], 1,
i);
201 flag(ptl_reserved_zero_bit);
202 for (
i = max_num_sub_layers_minus1 - 1;
i >= 0;
i--)
203 if (current->ptl_sublayer_level_present_flag[
i])
204 ubs(8, sublayer_level_idc[
i], 1,
i);
205 if (profile_tier_present_flag) {
206 ub(8, ptl_num_sub_profiles);
207 for (
i = 0;
i < current->ptl_num_sub_profiles;
i++)
208 ubs(32, general_sub_profile_idc[
i], 1,
i);
217 infer(vui_progressive_source_flag, 0);
218 infer(vui_interlaced_source_flag, 0);
220 infer(vui_non_packed_constraint_flag, 0);
221 infer(vui_non_projected_constraint_flag, 0);
223 infer(vui_aspect_ratio_constant_flag, 0);
224 infer(vui_aspect_ratio_idc, 0);
226 infer(vui_overscan_info_present_flag, 0);
228 infer(vui_colour_primaries, 2);
229 infer(vui_transfer_characteristics, 2);
230 infer(vui_matrix_coeffs, 2);
231 infer(vui_full_range_flag, 0);
233 infer(vui_chroma_sample_loc_type_frame, 6);
234 infer(vui_chroma_sample_loc_type_top_field, 6);
235 infer(vui_chroma_sample_loc_type_bottom_field, 6);
241 uint8_t chroma_format_idc)
245 flag(vui_progressive_source_flag);
246 flag(vui_interlaced_source_flag);
247 flag(vui_non_packed_constraint_flag);
248 flag(vui_non_projected_constraint_flag);
249 flag(vui_aspect_ratio_info_present_flag);
250 if (current->vui_aspect_ratio_info_present_flag) {
251 flag(vui_aspect_ratio_constant_flag);
252 ub(8, vui_aspect_ratio_idc);
253 if (current->vui_aspect_ratio_idc == 255) {
254 ub(16, vui_sar_width);
255 ub(16, vui_sar_height);
258 infer(vui_aspect_ratio_constant_flag, 0);
259 infer(vui_aspect_ratio_idc, 0);
261 flag(vui_overscan_info_present_flag);
262 if (current->vui_overscan_info_present_flag)
263 flag(vui_overscan_appropriate_flag);
264 flag(vui_colour_description_present_flag);
265 if (current->vui_colour_description_present_flag) {
266 ub(8, vui_colour_primaries);
268 current->vui_colour_primaries);
269 ub(8, vui_transfer_characteristics);
271 "vui_transfer_characteristics == %d \n",
272 current->vui_transfer_characteristics);
273 ub(8, vui_matrix_coeffs);
275 current->vui_matrix_coeffs);
276 flag(vui_full_range_flag);
278 infer(vui_colour_primaries, 2);
279 infer(vui_transfer_characteristics, 2);
280 infer(vui_matrix_coeffs, 2);
281 infer(vui_full_range_flag, 0);
283 flag(vui_chroma_loc_info_present_flag);
284 if (chroma_format_idc != 1 && current->vui_chroma_loc_info_present_flag) {
286 "vui_chroma_loc_info_present_flag can't not be true",
290 if (current->vui_chroma_loc_info_present_flag) {
291 if (current->vui_progressive_source_flag &&
292 !current->vui_interlaced_source_flag) {
293 ue(vui_chroma_sample_loc_type_frame, 0, 6);
295 ue(vui_chroma_sample_loc_type_top_field, 0, 6);
296 ue(vui_chroma_sample_loc_type_bottom_field, 0, 6);
299 if (chroma_format_idc == 1) {
300 infer(vui_chroma_sample_loc_type_frame, 6);
301 infer(vui_chroma_sample_loc_type_top_field,
302 current->vui_chroma_sample_loc_type_frame);
303 infer(vui_chroma_sample_loc_type_bottom_field,
304 current->vui_chroma_sample_loc_type_frame);
312 uint32_t payload_size,
int cur_pos)
315 size_t byte_length, k;
329 if (!payload_zero_bits)
331 payload_zero_bits =
ff_ctz(payload_zero_bits);
332 current->bit_length =
bits_left - payload_zero_bits - 1;
333 allocate(current->data, (current->bit_length + 7) / 8);
336 byte_length = (current->bit_length + 7) / 8;
337 for (k = 0; k < byte_length; k++) {
338 int length =
FFMIN(current->bit_length - k * 8, 8);
339 xu(length, reserved_payload_extension_data, current->data[k],
347 H266RawVUI *current, uint16_t vui_payload_size,
348 uint8_t chroma_format_idc)
351 int start_position, current_position;
357 if (current_position < 8 * vui_payload_size) {
359 vui_payload_size, current_position));
360 fixed(1, vui_payload_bit_equal_to_one, 1);
362 fixed(1, vui_payload_bit_equal_to_zero, 0);
378 current->bit_length = k;
381 allocate(current->data, (current->bit_length + 7) / 8);
382 for (k = 0; k < current->bit_length; k++) {
384 current->data[k / 8] |=
bit << (7 - k % 8);
388 for (k = 0; k < current->bit_length; k++)
396 uint8_t max_sublayers_minus1,
397 uint8_t sublayer_info_flag)
400 for (
i = (sublayer_info_flag ? 0 : max_sublayers_minus1);
401 i <= max_sublayers_minus1;
i++) {
403 ues(dpb_max_num_reorder_pics[
i],
404 0, current->dpb_max_dec_pic_buffering_minus1[
i], 1,
i);
405 ues(dpb_max_latency_increase_plus1[
i], 0, UINT32_MAX - 1, 1,
i);
413 uint8_t list_idx, uint8_t rpls_idx,
417 int err,
i, j, general_layer_idx = -1, num_direct_ref_layers = 0;
422 "VPS id %d not available.\n",
sps->sps_video_parameter_set_id);
426 for (
i = 0;
i <=
vps->vps_max_layers_minus1;
i++) {
427 if (
sps->nal_unit_header.nuh_layer_id ==
vps->vps_layer_id[
i]) {
428 general_layer_idx =
i;
432 if (general_layer_idx < 0) {
434 sps->nal_unit_header.nuh_layer_id);
438 for (j = 0; j <=
vps->vps_max_layers_minus1; j++) {
439 if (
vps->vps_direct_ref_layer_flag[general_layer_idx][j])
440 num_direct_ref_layers++;
444 if (
sps->sps_long_term_ref_pics_flag &&
445 rpls_idx < sps->sps_num_ref_pic_lists[list_idx] &&
446 current->num_ref_entries > 0)
447 flag(ltrp_in_header_flag);
448 if (
sps->sps_long_term_ref_pics_flag &&
449 rpls_idx ==
sps->sps_num_ref_pic_lists[list_idx])
450 infer(ltrp_in_header_flag, 1);
451 for (
i = 0, j = 0;
i < current->num_ref_entries;
i++) {
452 if (
sps->sps_inter_layer_prediction_enabled_flag)
453 flags(inter_layer_ref_pic_flag[
i], 1,
i);
455 infer(inter_layer_ref_pic_flag[
i], 0);
457 if (!current->inter_layer_ref_pic_flag[
i]) {
458 if (
sps->sps_long_term_ref_pics_flag)
459 flags(st_ref_pic_flag[
i], 1,
i);
461 infer(st_ref_pic_flag[
i], 1);
462 if (current->st_ref_pic_flag[
i]) {
463 int abs_delta_poc_st;
465 if ((
sps->sps_weighted_pred_flag ||
466 sps->sps_weighted_bipred_flag) &&
i != 0)
467 abs_delta_poc_st = current->abs_delta_poc_st[
i];
469 abs_delta_poc_st = current->abs_delta_poc_st[
i] + 1;
470 if (abs_delta_poc_st > 0)
471 flags(strp_entry_sign_flag[
i], 1,
i);
473 if (!current->ltrp_in_header_flag) {
474 uint8_t
bits =
sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4;
475 ubs(
bits, rpls_poc_lsb_lt[j], 1, j);
480 if (num_direct_ref_layers == 0) {
482 "num_direct_ref_layers needs > 0.\n");
485 ues(ilrp_idx[
i], 0, num_direct_ref_layers - 1, 1,
i);
495 int err,
i, j, num_ltrp_entries;
496 for (
i = 0;
i < 2;
i++) {
497 if (
sps->sps_num_ref_pic_lists[
i] > 0 &&
498 (
i == 0 || (
i == 1 &&
pps->pps_rpl1_idx_present_flag))) {
501 if (
sps->sps_num_ref_pic_lists[
i] == 0) {
502 infer(rpl_sps_flag[
i], 0);
504 if (!
pps->pps_rpl1_idx_present_flag &&
i == 1)
505 infer(rpl_sps_flag[1], current->rpl_sps_flag[0]);
508 if (current->rpl_sps_flag[
i]) {
509 if (
sps->sps_num_ref_pic_lists[
i] > 1 &&
510 (
i == 0 || (
i == 1 &&
pps->pps_rpl1_idx_present_flag))) {
512 us(
bits, rpl_idx[
i], 0,
sps->sps_num_ref_pic_lists[
i] - 1, 1,
i);
513 }
else if (
sps->sps_num_ref_pic_lists[
i] == 1) {
515 }
else if (
i == 1 && !
pps->pps_rpl1_idx_present_flag) {
516 infer(rpl_idx[1], current->rpl_idx[0]);
520 "can't infer the rpl_idx[i]\n");
523 memcpy(¤t->rpl_ref_list[
i],
524 &
sps->sps_ref_pic_list_struct[
i][current->rpl_idx[
i]],
525 sizeof(current->rpl_ref_list[
i]));
528 i,
sps->sps_num_ref_pic_lists[
i],
531 ref_list = ¤t->rpl_ref_list[
i];
533 num_ltrp_entries = 0;
542 for (j = 0; j < num_ltrp_entries; j++) {
544 ubs(
sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4,
545 poc_lsb_lt[
i][j], 2,
i, j);
547 flags(delta_poc_msb_cycle_present_flag[
i][j], 2,
i, j);
548 if (current->delta_poc_msb_cycle_present_flag[
i][j]) {
550 1 << (32 -
sps->sps_log2_max_pic_order_cnt_lsb_minus4 - 4);
551 ues(delta_poc_msb_cycle_lt[
i][j], 0,
max, 2,
i, j);
563 ub(32, num_units_in_tick);
565 flag(general_nal_hrd_params_present_flag);
566 flag(general_vcl_hrd_params_present_flag);
568 if (current->general_nal_hrd_params_present_flag ||
569 current->general_vcl_hrd_params_present_flag) {
570 flag(general_same_pic_timing_in_all_ols_flag);
571 flag(general_du_hrd_params_present_flag);
572 if (current->general_du_hrd_params_present_flag)
573 ub(8, tick_divisor_minus2);
574 ub(4, bit_rate_scale);
575 ub(4, cpb_size_scale);
576 if (current->general_du_hrd_params_present_flag)
577 ub(4, cpb_size_du_scale);
578 ue(hrd_cpb_cnt_minus1, 0, 31);
581 infer(general_du_hrd_params_present_flag, 0);
593 for (
i = 0;
i <= general->hrd_cpb_cnt_minus1;
i++) {
594 ues(bit_rate_value_minus1[sublayer_id][
i], 0, UINT32_MAX - 1, 2,
596 ues(cpb_size_value_minus1[sublayer_id][
i], 0, UINT32_MAX - 1, 2,
598 if (general->general_du_hrd_params_present_flag) {
599 ues(cpb_size_du_value_minus1[sublayer_id][
i],
600 0, UINT32_MAX - 1, 2, sublayer_id,
i);
601 ues(bit_rate_du_value_minus1[sublayer_id][
i],
602 0, UINT32_MAX - 1, 2, sublayer_id,
i);
604 flags(cbr_flag[sublayer_id][
i], 2, sublayer_id,
i);
611 uint8_t first_sublayer, uint8_t max_sublayers_minus1,
615 for (
i = first_sublayer;
i <= max_sublayers_minus1;
i++) {
616 flags(fixed_pic_rate_general_flag[
i], 1,
i);
617 if (!current->fixed_pic_rate_general_flag[
i])
618 flags(fixed_pic_rate_within_cvs_flag[
i], 1,
i);
620 infer(fixed_pic_rate_within_cvs_flag[
i], 1);
621 if (current->fixed_pic_rate_within_cvs_flag[
i]) {
622 ues(elemental_duration_in_tc_minus1[
i], 0, 2047, 1,
i);
623 infer(low_delay_hrd_flag[
i], 0);
624 }
else if ((general->general_nal_hrd_params_present_flag ||
625 general->general_vcl_hrd_params_present_flag) &&
626 general->hrd_cpb_cnt_minus1 == 0) {
627 flags(low_delay_hrd_flag[
i], 1,
i);
629 infer(low_delay_hrd_flag[
i], 0);
631 if (general->general_nal_hrd_params_present_flag)
633 ¤t->nal_sub_layer_hrd_parameters,
635 if (general->general_vcl_hrd_params_present_flag)
637 ¤t->nal_sub_layer_hrd_parameters,
648 HEADER(
"Operating point information");
653 flag(opi_ols_info_present_flag);
654 flag(opi_htid_info_present_flag);
656 if(current->opi_ols_info_present_flag)
659 if(current->opi_htid_info_present_flag)
660 ub(3, opi_htid_plus1);
662 flag(opi_extension_flag);
663 if (current->opi_extension_flag)
675 HEADER(
"Decoding capability information");
680 ub(4, dci_reserved_zero_4bits);
681 ub(4, dci_num_ptls_minus1);
682 for (
i = 0;
i <= current->dci_num_ptls_minus1;
i++)
684 current->dci_profile_tier_level +
i, 1, 0));
686 flag(dci_extension_flag);
687 if (current->dci_extension_flag)
698 uint16_t total_num_olss = 0;
699 uint8_t ols_mode_idc = 0;
700 uint16_t num_multi_layer_olss = 0;
705 HEADER(
"Video Parameter Set");
711 ub(6, vps_max_layers_minus1);
712 u(3, vps_max_sublayers_minus1, 0, 6);
713 if (current->vps_max_layers_minus1 > 0
714 && current->vps_max_sublayers_minus1 > 0)
715 flag(vps_default_ptl_dpb_hrd_max_tid_flag);
717 infer(vps_default_ptl_dpb_hrd_max_tid_flag, 1);
719 if (current->vps_max_layers_minus1 > 0)
720 flag(vps_all_independent_layers_flag);
722 infer(vps_all_independent_layers_flag, 1);
724 for (
i = 0;
i <= current->vps_max_layers_minus1;
i++) {
725 ubs(6, vps_layer_id[
i], 1,
i);
726 if (
i > 0 && current->vps_layer_id[
i] <= current->vps_layer_id[
i - 1]) {
728 "vps_layer_id[%d](%d) should > vps_layer_id[%d](%d).\n",
729 i, current->vps_layer_id[
i],
i - 1,
730 current->vps_layer_id[
i - 1]);
733 if (
i > 0 && !current->vps_all_independent_layers_flag) {
734 flags(vps_independent_layer_flag[
i], 1,
i);
735 if (!current->vps_independent_layer_flag[
i]) {
736 flags(vps_max_tid_ref_present_flag[
i], 1,
i);
737 for (j = 0; j <
i; j++) {
738 flags(vps_direct_ref_layer_flag[
i][j], 2,
i, j);
739 if (current->vps_max_tid_ref_present_flag[
i] &&
740 current->vps_direct_ref_layer_flag[
i][j]) {
741 ubs(3, vps_max_tid_il_ref_pics_plus1[
i][j], 2,
i, j);
743 infer(vps_max_tid_il_ref_pics_plus1[
i][j],
744 current->vps_max_sublayers_minus1 + 1);
748 for (j = 0; j <
i; j++) {
749 infer(vps_direct_ref_layer_flag[
i][j], 0);
753 infer(vps_independent_layer_flag[
i], 1);
754 for (j = 0; j <
i; j++) {
755 infer(vps_direct_ref_layer_flag[
i][j], 0);
760 if (current->vps_max_layers_minus1 > 0) {
761 if (current->vps_all_independent_layers_flag)
762 flag(vps_each_layer_is_an_ols_flag);
764 infer(vps_each_layer_is_an_ols_flag, 0);
765 if (!current->vps_each_layer_is_an_ols_flag) {
766 if (!current->vps_all_independent_layers_flag)
767 ub(2, vps_ols_mode_idc);
769 infer(vps_ols_mode_idc, 2);
770 if (current->vps_ols_mode_idc == 2) {
771 ub(8, vps_num_output_layer_sets_minus2);
772 for (
i = 1;
i <= current->vps_num_output_layer_sets_minus2 + 1;
774 for (j = 0; j <= current->vps_max_layers_minus1; j++)
775 flags(vps_ols_output_layer_flag[
i][j], 2,
i, j);
777 ols_mode_idc = current->vps_ols_mode_idc;
781 if (ols_mode_idc == 4 || ols_mode_idc == 0 || ols_mode_idc == 1)
782 total_num_olss = current->vps_max_layers_minus1 + 1;
783 else if (ols_mode_idc == 2)
784 total_num_olss = current->vps_num_output_layer_sets_minus2 + 2;
787 "ols_mode_idc == 3, patch welcome");
788 u(8, vps_num_ptls_minus1, 0, total_num_olss - 1);
790 infer(vps_each_layer_is_an_ols_flag, 1);
791 infer(vps_num_ptls_minus1, 0);
794 for (
i = 0;
i <= current->vps_num_ptls_minus1;
i++) {
796 flags(vps_pt_present_flag[
i], 1,
i);
798 infer(vps_pt_present_flag[
i], 1);
800 if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
801 us(3, vps_ptl_max_tid[
i], 0, current->vps_max_sublayers_minus1, 1,
i);
803 infer(vps_ptl_max_tid[
i], current->vps_max_sublayers_minus1);
806 fixed(1, vps_ptl_alignment_zero_bit, 0);
817 for (
i = 0;
i <= current->vps_max_layers_minus1;
i++) {
818 for (j = 0; j <= current->vps_max_layers_minus1; j++) {
819 dependency_flag[
i][j] = current->vps_direct_ref_layer_flag[
i][j];
820 for (k = 0; k <
i; k++) {
821 if (current->vps_direct_ref_layer_flag[
i][k] &&
822 dependency_flag[k][j])
823 dependency_flag[
i][j] = 1;
827 for (
i = 0;
i <= current->vps_max_layers_minus1;
i++) {
829 for (j = 0,
r = 0; j <= current->vps_max_layers_minus1; j++) {
830 if (dependency_flag[
i][j])
831 reference_layer_idx[
i][
r++] = j;
833 num_ref_layers[
i] =
r;
837 num_output_layers_in_ols[0] = 1;
838 num_sub_layers_in_layer_in_ols[0][0] =
839 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[0]] + 1;
840 for (
i = 1;
i < total_num_olss;
i++) {
841 if (ols_mode_idc == 4 || ols_mode_idc == 0) {
842 num_output_layers_in_ols[
i] = 1;
843 if (current->vps_each_layer_is_an_ols_flag) {
844 num_sub_layers_in_layer_in_ols[
i][0] =
845 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[
i]] + 1;
847 num_sub_layers_in_layer_in_ols[
i][
i] =
848 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[
i]] + 1;
849 for (k =
i - 1; k >= 0; k--) {
850 num_sub_layers_in_layer_in_ols[
i][k] = 0;
851 for (m = k + 1; m <=
i; m++) {
852 uint8_t max_sublayer_needed =
853 FFMIN(num_sub_layers_in_layer_in_ols[
i][m],
854 current->vps_max_tid_il_ref_pics_plus1[m][k]);
855 if (current->vps_direct_ref_layer_flag[m][k] &&
856 num_sub_layers_in_layer_in_ols[
i][k] < max_sublayer_needed)
857 num_sub_layers_in_layer_in_ols[
i][k] = max_sublayer_needed;
861 }
else if (current->vps_ols_mode_idc == 1) {
862 num_output_layers_in_ols[
i] =
i + 1;
863 for (j = 0; j < num_output_layers_in_ols[
i]; j++) {
864 num_sub_layers_in_layer_in_ols[
i][j] =
865 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[
i]] + 1;
867 }
else if (current->vps_ols_mode_idc == 2) {
868 uint8_t highest_included_layer = 0;
869 for (j = 0; j <= current->vps_max_layers_minus1; j++) {
870 layer_included_in_ols_flag[
i][j] = 0;
871 num_sub_layers_in_layer_in_ols[
i][j] = 0;
873 for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++) {
874 if (current->vps_ols_output_layer_flag[
i][k]) {
875 layer_included_in_ols_flag[
i][k] = 1;
876 highest_included_layer = k;
877 output_layer_idx[
i][j] = k;
878 num_sub_layers_in_layer_in_ols[
i][k] =
879 current->vps_ptl_max_tid[current->
880 vps_ols_ptl_idx[
i]] + 1;
884 num_output_layers_in_ols[
i] = j;
885 for (j = 0; j < num_output_layers_in_ols[
i]; j++) {
886 int idx = output_layer_idx[
i][j];
887 for (k = 0; k < num_ref_layers[idx]; k++) {
888 if (!layer_included_in_ols_flag[
i][reference_layer_idx[idx][k]])
889 layer_included_in_ols_flag[
i][reference_layer_idx[idx][k]] = 1;
892 for (k = highest_included_layer - 1; k >= 0; k--) {
893 if (layer_included_in_ols_flag[
i][k] &&
894 !current->vps_ols_output_layer_flag[
i][k]) {
895 for (m = k + 1; m <= highest_included_layer; m++) {
896 uint8_t max_sublayer_needed =
897 FFMIN(num_sub_layers_in_layer_in_ols[
i][m],
898 current->vps_max_tid_il_ref_pics_plus1[m][k]);
899 if (current->vps_direct_ref_layer_flag[m][k] &&
900 layer_included_in_ols_flag[
i][m] &&
901 num_sub_layers_in_layer_in_ols[
i][k] <
903 num_sub_layers_in_layer_in_ols[
i][k] =
909 if (!num_output_layers_in_ols[
i])
912 for (
i = 1;
i < total_num_olss;
i++) {
913 int num_layers_in_ols = 0;
914 if (current->vps_each_layer_is_an_ols_flag) {
915 num_layers_in_ols = 1;
916 }
else if (current->vps_ols_mode_idc == 0 ||
917 current->vps_ols_mode_idc == 1) {
918 num_layers_in_ols =
i + 1;
919 }
else if (current->vps_ols_mode_idc == 2) {
920 for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++)
921 if (layer_included_in_ols_flag[
i][k])
923 num_layers_in_ols = j;
925 if (num_layers_in_ols > 1) {
926 num_multi_layer_olss++;
929 if (!current->vps_each_layer_is_an_ols_flag && num_multi_layer_olss == 0)
933 for (
i = 0;
i <= current->vps_num_ptls_minus1;
i++) {
935 current->vps_profile_tier_level +
i,
936 current->vps_pt_present_flag[
i],
937 current->vps_ptl_max_tid[
i]));
939 for (
i = 0;
i < total_num_olss;
i++) {
940 if (current->vps_num_ptls_minus1 > 0 &&
941 current->vps_num_ptls_minus1 + 1 != total_num_olss) {
942 us(8, vps_ols_ptl_idx[
i], 0, current->vps_num_ptls_minus1, 1,
i);
943 }
else if (current->vps_num_ptls_minus1 == 0) {
944 infer(vps_ols_ptl_idx[
i], 0);
950 if (!current->vps_each_layer_is_an_ols_flag) {
951 uint16_t vps_num_dpb_params;
952 ue(vps_num_dpb_params_minus1, 0, num_multi_layer_olss - 1);
953 if (current->vps_each_layer_is_an_ols_flag)
954 vps_num_dpb_params = 0;
956 vps_num_dpb_params = current->vps_num_dpb_params_minus1 + 1;
958 if (current->vps_max_sublayers_minus1 > 0)
959 flag(vps_sublayer_dpb_params_present_flag);
961 infer(vps_sublayer_dpb_params_present_flag, 0);
963 for (
i = 0;
i < vps_num_dpb_params;
i++) {
964 if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
965 us(3, vps_dpb_max_tid[
i], 0, current->vps_max_sublayers_minus1,
968 infer(vps_dpb_max_tid[
i], current->vps_max_sublayers_minus1);
970 current->vps_dpb_max_tid[
i],
972 vps_sublayer_dpb_params_present_flag));
974 for (
i = 0;
i < num_multi_layer_olss;
i++) {
975 ues(vps_ols_dpb_pic_width[
i], 0, UINT16_MAX, 1,
i);
976 ues(vps_ols_dpb_pic_height[
i], 0, UINT16_MAX, 1,
i);
977 ubs(2, vps_ols_dpb_chroma_format[
i], 1,
i);
978 ues(vps_ols_dpb_bitdepth_minus8[
i], 0, 8, 1,
i);
979 if (vps_num_dpb_params > 1
980 && vps_num_dpb_params != num_multi_layer_olss)
981 ues(vps_ols_dpb_params_idx[
i], 0, vps_num_dpb_params - 1, 1,
i);
982 else if (vps_num_dpb_params == 1)
983 infer(vps_ols_dpb_params_idx[
i], 0);
985 infer(vps_ols_dpb_params_idx[
i],
i);
987 flag(vps_timing_hrd_params_present_flag);
988 if (current->vps_timing_hrd_params_present_flag) {
991 vps_general_timing_hrd_parameters));
992 if (current->vps_max_sublayers_minus1 > 0)
993 flag(vps_sublayer_cpb_params_present_flag);
995 infer(vps_sublayer_cpb_params_present_flag, 0);
996 ue(vps_num_ols_timing_hrd_params_minus1, 0,
997 num_multi_layer_olss - 1);
998 for (
i = 0;
i <= current->vps_num_ols_timing_hrd_params_minus1;
i++) {
999 uint8_t first_sublayer;
1000 if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
1001 us(3, vps_hrd_max_tid[
i], 0,
1002 current->vps_max_sublayers_minus1, 1,
i);
1004 infer(vps_hrd_max_tid[
i],
1005 current->vps_max_sublayers_minus1);
1006 first_sublayer = current->vps_sublayer_cpb_params_present_flag ?
1007 0 : current->vps_hrd_max_tid[
i];
1009 (
ctx, rw, ¤t->vps_ols_timing_hrd_parameters,
1010 first_sublayer, current->vps_max_sublayers_minus1,
1011 ¤t->vps_general_timing_hrd_parameters));
1014 if (current->vps_num_ols_timing_hrd_params_minus1 > 0 &&
1015 current->vps_num_ols_timing_hrd_params_minus1 + 1 !=
1016 num_multi_layer_olss) {
1017 for (
i = 0;
i < num_multi_layer_olss;
i++) {
1018 ues(vps_ols_timing_hrd_idx[
i], 0,
1019 current->vps_num_ols_timing_hrd_params_minus1, 1,
i);
1021 }
else if (current->vps_num_ols_timing_hrd_params_minus1 == 0) {
1022 for (
i = 0;
i < num_multi_layer_olss;
i++)
1023 infer(vps_ols_timing_hrd_idx[
i], 0);
1025 for (
i = 0;
i < num_multi_layer_olss;
i++)
1026 infer(vps_ols_timing_hrd_idx[
i],
i);
1031 flag(vps_extension_flag);
1032 if (current->vps_extension_flag)
1044 flag(sps_extended_precision_flag);
1045 if (current->sps_transform_skip_enabled_flag)
1046 flag(sps_ts_residual_coding_rice_present_in_sh_flag);
1048 infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1049 flag(sps_rrc_rice_extension_flag);
1050 flag(sps_persistent_rice_adaptation_enabled_flag);
1051 flag(sps_reverse_last_sig_coeff_enabled_flag);
1061 unsigned int ctb_log2_size_y, min_cb_log2_size_y,
1062 min_qt_log2_size_intra_y, min_qt_log2_size_inter_y,
1063 ctb_size_y, max_num_merge_cand, tmp_width_val, tmp_height_val;
1064 uint8_t qp_bd_offset, sub_width_c, sub_height_c;
1066 static const uint8_t h266_sub_width_c[] = {
1069 static const uint8_t h266_sub_height_c[] = {
1073 HEADER(
"Sequence Parameter Set");
1078 ub(4, sps_seq_parameter_set_id);
1079 ub(4, sps_video_parameter_set_id);
1080 if (current->sps_video_parameter_set_id == 0 && !h266->
vps[0]) {
1084 vps->vps_max_layers_minus1 = 0;
1085 vps->vps_independent_layer_flag[0] = 1;
1086 vps->vps_layer_id[0] = current->nal_unit_header.nuh_layer_id;
1091 u(2, sps_chroma_format_idc, 0, 3);
1092 sub_width_c = h266_sub_width_c[current->sps_chroma_format_idc];
1093 sub_height_c = h266_sub_height_c[current->sps_chroma_format_idc];
1095 u(2, sps_log2_ctu_size_minus5, 0, 3);
1096 ctb_log2_size_y = current->sps_log2_ctu_size_minus5 + 5;
1097 ctb_size_y = 1 << ctb_log2_size_y;
1099 flag(sps_ptl_dpb_hrd_params_present_flag);
1100 if (current->sps_ptl_dpb_hrd_params_present_flag) {
1102 1, current->sps_max_sublayers_minus1));
1104 flag(sps_gdr_enabled_flag);
1105 flag(sps_ref_pic_resampling_enabled_flag);
1106 if (current->sps_ref_pic_resampling_enabled_flag)
1107 flag(sps_res_change_in_clvs_allowed_flag);
1109 infer(sps_res_change_in_clvs_allowed_flag, 0);
1114 flag(sps_conformance_window_flag);
1115 if (current->sps_conformance_window_flag) {
1116 uint16_t
width = current->sps_pic_width_max_in_luma_samples / sub_width_c;
1117 uint16_t
height = current->sps_pic_height_max_in_luma_samples / sub_height_c;
1118 ue(sps_conf_win_left_offset, 0,
width);
1119 ue(sps_conf_win_right_offset, 0,
width - current->sps_conf_win_left_offset);
1120 ue(sps_conf_win_top_offset, 0,
height);
1121 ue(sps_conf_win_bottom_offset, 0,
height - current->sps_conf_win_top_offset);
1123 infer(sps_conf_win_left_offset, 0);
1124 infer(sps_conf_win_right_offset, 0);
1125 infer(sps_conf_win_top_offset, 0);
1126 infer(sps_conf_win_bottom_offset, 0);
1129 tmp_width_val =
AV_CEIL_RSHIFT(current->sps_pic_width_max_in_luma_samples,
1131 tmp_height_val =
AV_CEIL_RSHIFT(current->sps_pic_height_max_in_luma_samples,
1134 flag(sps_subpic_info_present_flag);
1135 if (current->sps_subpic_info_present_flag) {
1137 if (current->sps_num_subpics_minus1 > 0) {
1138 flag(sps_independent_subpics_flag);
1139 flag(sps_subpic_same_size_flag);
1142 if (current->sps_num_subpics_minus1 > 0) {
1145 infer(sps_subpic_ctu_top_left_x[0], 0);
1146 infer(sps_subpic_ctu_top_left_y[0], 0);
1147 if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1148 ubs(wlen, sps_subpic_width_minus1[0], 1, 0);
1150 infer(sps_subpic_width_minus1[0], tmp_width_val - 1);
1151 if (current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1152 ubs(hlen, sps_subpic_height_minus1[0], 1, 0);
1154 infer(sps_subpic_height_minus1[0], tmp_height_val - 1);
1155 if (!current->sps_independent_subpics_flag) {
1156 flags(sps_subpic_treated_as_pic_flag[0], 1, 0);
1157 flags(sps_loop_filter_across_subpic_enabled_flag[0], 1, 0);
1159 infer(sps_subpic_treated_as_pic_flag[0], 1);
1160 infer(sps_loop_filter_across_subpic_enabled_flag[0], 1);
1162 for (
i = 1;
i <= current->sps_num_subpics_minus1;
i++) {
1163 if (!current->sps_subpic_same_size_flag) {
1164 if (current->sps_pic_width_max_in_luma_samples > ctb_size_y) {
1165 const unsigned int win_right_edge =
1166 current->sps_pic_width_max_in_luma_samples
1167 - current->sps_conf_win_right_offset * sub_width_c;
1168 us(wlen, sps_subpic_ctu_top_left_x[
i], 0,
1172 infer(sps_subpic_ctu_top_left_x[
i], 0);
1173 if (current->sps_pic_height_max_in_luma_samples >
1175 const unsigned int win_bottom_edge =
1176 current->sps_pic_height_max_in_luma_samples
1177 - current->sps_conf_win_bottom_offset * sub_height_c;
1178 us(hlen, sps_subpic_ctu_top_left_y[
i], 0,
1182 infer(sps_subpic_ctu_top_left_y[
i], 0);
1183 if (i < current->sps_num_subpics_minus1 &&
1184 current->sps_pic_width_max_in_luma_samples >
1186 const unsigned int win_left_edge =
1187 current->sps_conf_win_left_offset * sub_width_c;
1188 const unsigned int win_left_edge_ctus =
1190 us(wlen, sps_subpic_width_minus1[
i],
1191 win_left_edge_ctus > current->sps_subpic_ctu_top_left_x[
i]
1192 ? win_left_edge_ctus - current->sps_subpic_ctu_top_left_x[
i]
1196 infer(sps_subpic_width_minus1[
i],
1198 current->sps_subpic_ctu_top_left_x[
i] - 1);
1200 if (i < current->sps_num_subpics_minus1 &&
1201 current->sps_pic_height_max_in_luma_samples >
1203 const unsigned int win_top_edge =
1204 current->sps_conf_win_top_offset * sub_height_c;
1205 const unsigned int win_top_edge_ctus =
1207 us(hlen, sps_subpic_height_minus1[
i],
1208 win_top_edge_ctus > current->sps_subpic_ctu_top_left_y[
i]
1209 ? win_top_edge_ctus - current->sps_subpic_ctu_top_left_y[
i]
1213 infer(sps_subpic_height_minus1[
i],
1215 current->sps_subpic_ctu_top_left_y[
i] - 1);
1218 int num_subpic_cols = tmp_width_val /
1219 (current->sps_subpic_width_minus1[0] + 1);
1220 if (tmp_width_val % (current->sps_subpic_width_minus1[0] + 1) ||
1221 tmp_height_val % (current->sps_subpic_width_minus1[0] + 1) ||
1222 current->sps_num_subpics_minus1 !=
1223 (num_subpic_cols * tmp_height_val /
1224 (current->sps_subpic_height_minus1[0] + 1) - 1))
1226 infer(sps_subpic_ctu_top_left_x[
i],
1227 (
i % num_subpic_cols) *
1228 (current->sps_subpic_width_minus1[0] + 1));
1229 infer(sps_subpic_ctu_top_left_y[
i],
1230 (
i / num_subpic_cols) *
1231 (current->sps_subpic_height_minus1[0] + 1));
1232 infer(sps_subpic_width_minus1[
i],
1233 current->sps_subpic_width_minus1[0]);
1234 infer(sps_subpic_height_minus1[
i],
1235 current->sps_subpic_height_minus1[0]);
1237 if (!current->sps_independent_subpics_flag) {
1238 flags(sps_subpic_treated_as_pic_flag[
i], 1,
i);
1239 flags(sps_loop_filter_across_subpic_enabled_flag[
i], 1,
i);
1241 infer(sps_subpic_treated_as_pic_flag[
i], 1);
1242 infer(sps_loop_filter_across_subpic_enabled_flag[
i], 0);
1246 infer(sps_subpic_ctu_top_left_x[0], 0);
1247 infer(sps_subpic_ctu_top_left_y[0], 0);
1248 infer(sps_subpic_width_minus1[0], tmp_width_val - 1);
1249 infer(sps_subpic_height_minus1[0], tmp_height_val - 1);
1251 ue(sps_subpic_id_len_minus1, 0, 15);
1252 if ((1 << (current->sps_subpic_id_len_minus1 + 1)) <
1253 current->sps_num_subpics_minus1 + 1) {
1255 "sps_subpic_id_len_minus1(%d) is too small\n",
1256 current->sps_subpic_id_len_minus1);
1259 flag(sps_subpic_id_mapping_explicitly_signalled_flag);
1260 if (current->sps_subpic_id_mapping_explicitly_signalled_flag) {
1261 flag(sps_subpic_id_mapping_present_flag);
1262 if (current->sps_subpic_id_mapping_present_flag) {
1263 for (
i = 0;
i <= current->sps_num_subpics_minus1;
i++) {
1264 ubs(current->sps_subpic_id_len_minus1 + 1,
1265 sps_subpic_id[
i], 1,
i);
1270 infer(sps_num_subpics_minus1, 0);
1271 infer(sps_independent_subpics_flag, 1);
1272 infer(sps_subpic_same_size_flag, 0);
1273 infer(sps_subpic_id_mapping_explicitly_signalled_flag, 0);
1274 infer(sps_subpic_ctu_top_left_x[0], 0);
1275 infer(sps_subpic_ctu_top_left_y[0], 0);
1276 infer(sps_subpic_width_minus1[0], tmp_width_val - 1);
1277 infer(sps_subpic_height_minus1[0], tmp_height_val - 1);
1281 ue(sps_bitdepth_minus8, 0, 8);
1282 qp_bd_offset = 6 * current->sps_bitdepth_minus8;
1284 flag(sps_entropy_coding_sync_enabled_flag);
1285 flag(sps_entry_point_offsets_present_flag);
1287 u(4, sps_log2_max_pic_order_cnt_lsb_minus4, 0, 12);
1288 flag(sps_poc_msb_cycle_flag);
1289 if (current->sps_poc_msb_cycle_flag)
1290 ue(sps_poc_msb_cycle_len_minus1,
1291 0, 32 - current->sps_log2_max_pic_order_cnt_lsb_minus4 - 5);
1293 u(2, sps_num_extra_ph_bytes, 0, 2);
1294 for (
i = 0;
i < (current->sps_num_extra_ph_bytes * 8);
i++) {
1295 flags(sps_extra_ph_bit_present_flag[
i], 1,
i);
1298 u(2, sps_num_extra_sh_bytes, 0, 2);
1299 for (
i = 0;
i < (current->sps_num_extra_sh_bytes * 8);
i++) {
1300 flags(sps_extra_sh_bit_present_flag[
i], 1,
i);
1303 if (current->sps_ptl_dpb_hrd_params_present_flag) {
1304 if (current->sps_max_sublayers_minus1 > 0)
1305 flag(sps_sublayer_dpb_params_flag);
1307 infer(sps_sublayer_dpb_params_flag, 0);
1309 current->sps_max_sublayers_minus1,
1310 current->sps_sublayer_dpb_params_flag));
1313 ue(sps_log2_min_luma_coding_block_size_minus2,
1314 0,
FFMIN(4, current->sps_log2_ctu_size_minus5 + 3));
1315 min_cb_log2_size_y =
1316 current->sps_log2_min_luma_coding_block_size_minus2 + 2;
1318 flag(sps_partition_constraints_override_enabled_flag);
1320 ue(sps_log2_diff_min_qt_min_cb_intra_slice_luma,
1321 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1322 min_qt_log2_size_intra_y =
1323 current->sps_log2_diff_min_qt_min_cb_intra_slice_luma +
1326 ue(sps_max_mtt_hierarchy_depth_intra_slice_luma,
1327 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1329 if (current->sps_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
1330 ue(sps_log2_diff_max_bt_min_qt_intra_slice_luma,
1331 0, ctb_log2_size_y - min_qt_log2_size_intra_y);
1332 ue(sps_log2_diff_max_tt_min_qt_intra_slice_luma,
1333 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
1335 infer(sps_log2_diff_max_bt_min_qt_intra_slice_luma, 0);
1336 infer(sps_log2_diff_max_tt_min_qt_intra_slice_luma, 0);
1339 if (current->sps_chroma_format_idc != 0) {
1340 flag(sps_qtbtt_dual_tree_intra_flag);
1342 infer(sps_qtbtt_dual_tree_intra_flag, 0);
1345 if (current->sps_qtbtt_dual_tree_intra_flag) {
1346 ue(sps_log2_diff_min_qt_min_cb_intra_slice_chroma,
1347 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1348 ue(sps_max_mtt_hierarchy_depth_intra_slice_chroma,
1349 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1350 if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
1351 unsigned int min_qt_log2_size_intra_c =
1352 current->sps_log2_diff_min_qt_min_cb_intra_slice_chroma +
1354 ue(sps_log2_diff_max_bt_min_qt_intra_slice_chroma,
1355 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1356 ue(sps_log2_diff_max_tt_min_qt_intra_slice_chroma,
1357 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1360 infer(sps_log2_diff_min_qt_min_cb_intra_slice_chroma, 0);
1361 infer(sps_max_mtt_hierarchy_depth_intra_slice_chroma, 0);
1363 if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma == 0) {
1364 infer(sps_log2_diff_max_bt_min_qt_intra_slice_chroma, 0);
1365 infer(sps_log2_diff_max_tt_min_qt_intra_slice_chroma, 0);
1368 ue(sps_log2_diff_min_qt_min_cb_inter_slice,
1369 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1370 min_qt_log2_size_inter_y =
1371 current->sps_log2_diff_min_qt_min_cb_inter_slice + min_cb_log2_size_y;
1373 ue(sps_max_mtt_hierarchy_depth_inter_slice,
1374 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1375 if (current->sps_max_mtt_hierarchy_depth_inter_slice != 0) {
1376 ue(sps_log2_diff_max_bt_min_qt_inter_slice,
1377 0, ctb_log2_size_y - min_qt_log2_size_inter_y);
1378 ue(sps_log2_diff_max_tt_min_qt_inter_slice,
1379 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
1381 infer(sps_log2_diff_max_bt_min_qt_inter_slice, 0);
1382 infer(sps_log2_diff_max_tt_min_qt_inter_slice, 0);
1385 if (ctb_size_y > 32)
1386 flag(sps_max_luma_transform_size_64_flag);
1388 infer(sps_max_luma_transform_size_64_flag, 0);
1390 flag(sps_transform_skip_enabled_flag);
1391 if (current->sps_transform_skip_enabled_flag) {
1392 ue(sps_log2_transform_skip_max_size_minus2, 0, 3);
1393 flag(sps_bdpcm_enabled_flag);
1396 flag(sps_mts_enabled_flag);
1397 if (current->sps_mts_enabled_flag) {
1398 flag(sps_explicit_mts_intra_enabled_flag);
1399 flag(sps_explicit_mts_inter_enabled_flag);
1401 infer(sps_explicit_mts_intra_enabled_flag, 0);
1402 infer(sps_explicit_mts_inter_enabled_flag, 0);
1405 flag(sps_lfnst_enabled_flag);
1407 if (current->sps_chroma_format_idc != 0) {
1408 uint8_t num_qp_tables;
1409 flag(sps_joint_cbcr_enabled_flag);
1410 flag(sps_same_qp_table_for_chroma_flag);
1411 num_qp_tables = current->sps_same_qp_table_for_chroma_flag ?
1412 1 : (current->sps_joint_cbcr_enabled_flag ? 3 : 2);
1413 for (
i = 0;
i < num_qp_tables;
i++) {
1414 ses(sps_qp_table_start_minus26[
i], -26 - qp_bd_offset, 36, 1,
i);
1415 ues(sps_num_points_in_qp_table_minus1[
i],
1416 0, 36 - current->sps_qp_table_start_minus26[
i], 1,
i);
1417 for (j = 0; j <= current->sps_num_points_in_qp_table_minus1[
i]; j++) {
1419 ues(sps_delta_qp_in_val_minus1[
i][j], 0,
max, 2,
i, j);
1420 ues(sps_delta_qp_diff_val[
i][j], 0,
max, 2,
i, j);
1424 infer(sps_joint_cbcr_enabled_flag, 0);
1425 infer(sps_same_qp_table_for_chroma_flag, 0);
1428 flag(sps_sao_enabled_flag);
1429 flag(sps_alf_enabled_flag);
1430 if (current->sps_alf_enabled_flag && current->sps_chroma_format_idc)
1431 flag(sps_ccalf_enabled_flag);
1433 infer(sps_ccalf_enabled_flag, 0);
1434 flag(sps_lmcs_enabled_flag);
1435 flag(sps_weighted_pred_flag);
1436 flag(sps_weighted_bipred_flag);
1437 flag(sps_long_term_ref_pics_flag);
1438 if (current->sps_video_parameter_set_id > 0)
1439 flag(sps_inter_layer_prediction_enabled_flag);
1441 infer(sps_inter_layer_prediction_enabled_flag, 0);
1442 flag(sps_idr_rpl_present_flag);
1443 flag(sps_rpl1_same_as_rpl0_flag);
1445 for (
i = 0;
i < (current->sps_rpl1_same_as_rpl0_flag ? 1 : 2);
i++) {
1447 for (j = 0; j < current->sps_num_ref_pic_lists[
i]; j++)
1450 sps_ref_pic_list_struct[
i][j],
i,
1454 if (current->sps_rpl1_same_as_rpl0_flag) {
1455 current->sps_num_ref_pic_lists[1] = current->sps_num_ref_pic_lists[0];
1456 for (j = 0; j < current->sps_num_ref_pic_lists[0]; j++)
1457 memcpy(¤t->sps_ref_pic_list_struct[1][j],
1458 ¤t->sps_ref_pic_list_struct[0][j],
1459 sizeof(current->sps_ref_pic_list_struct[0][j]));
1462 flag(sps_ref_wraparound_enabled_flag);
1464 flag(sps_temporal_mvp_enabled_flag);
1465 if (current->sps_temporal_mvp_enabled_flag)
1466 flag(sps_sbtmvp_enabled_flag);
1468 infer(sps_sbtmvp_enabled_flag, 0);
1470 flag(sps_amvr_enabled_flag);
1471 flag(sps_bdof_enabled_flag);
1472 if (current->sps_bdof_enabled_flag)
1473 flag(sps_bdof_control_present_in_ph_flag);
1475 infer(sps_bdof_control_present_in_ph_flag, 0);
1477 flag(sps_smvd_enabled_flag);
1478 flag(sps_dmvr_enabled_flag);
1479 if (current->sps_dmvr_enabled_flag)
1480 flag(sps_dmvr_control_present_in_ph_flag);
1482 infer(sps_dmvr_control_present_in_ph_flag, 0);
1484 flag(sps_mmvd_enabled_flag);
1485 if (current->sps_mmvd_enabled_flag)
1486 flag(sps_mmvd_fullpel_only_enabled_flag);
1488 infer(sps_mmvd_fullpel_only_enabled_flag, 0);
1490 ue(sps_six_minus_max_num_merge_cand, 0, 5);
1491 max_num_merge_cand = 6 - current->sps_six_minus_max_num_merge_cand;
1493 flag(sps_sbt_enabled_flag);
1495 flag(sps_affine_enabled_flag);
1496 if (current->sps_affine_enabled_flag) {
1497 ue(sps_five_minus_max_num_subblock_merge_cand,
1498 0, 5 - current->sps_sbtmvp_enabled_flag);
1499 flag(sps_6param_affine_enabled_flag);
1500 if (current->sps_amvr_enabled_flag)
1501 flag(sps_affine_amvr_enabled_flag);
1503 infer(sps_affine_amvr_enabled_flag, 0);
1504 flag(sps_affine_prof_enabled_flag);
1505 if (current->sps_affine_prof_enabled_flag)
1506 flag(sps_prof_control_present_in_ph_flag);
1508 infer(sps_prof_control_present_in_ph_flag, 0);
1510 infer(sps_6param_affine_enabled_flag, 0);
1511 infer(sps_affine_amvr_enabled_flag, 0);
1512 infer(sps_affine_prof_enabled_flag, 0);
1513 infer(sps_prof_control_present_in_ph_flag, 0);
1516 flag(sps_bcw_enabled_flag);
1517 flag(sps_ciip_enabled_flag);
1519 if (max_num_merge_cand >= 2) {
1520 flag(sps_gpm_enabled_flag);
1521 if (current->sps_gpm_enabled_flag && max_num_merge_cand >= 3)
1522 ue(sps_max_num_merge_cand_minus_max_num_gpm_cand,
1523 0, max_num_merge_cand - 2);
1525 infer(sps_gpm_enabled_flag, 0);
1528 ue(sps_log2_parallel_merge_level_minus2, 0, ctb_log2_size_y - 2);
1530 flag(sps_isp_enabled_flag);
1531 flag(sps_mrl_enabled_flag);
1532 flag(sps_mip_enabled_flag);
1534 if (current->sps_chroma_format_idc != 0)
1535 flag(sps_cclm_enabled_flag);
1537 infer(sps_cclm_enabled_flag, 0);
1538 if (current->sps_chroma_format_idc == 1) {
1539 flag(sps_chroma_horizontal_collocated_flag);
1540 flag(sps_chroma_vertical_collocated_flag);
1542 infer(sps_chroma_horizontal_collocated_flag, 1);
1543 infer(sps_chroma_vertical_collocated_flag, 1);
1546 flag(sps_palette_enabled_flag);
1547 if (current->sps_chroma_format_idc == 3 &&
1548 !current->sps_max_luma_transform_size_64_flag)
1549 flag(sps_act_enabled_flag);
1551 infer(sps_act_enabled_flag, 0);
1552 if (current->sps_transform_skip_enabled_flag ||
1553 current->sps_palette_enabled_flag)
1554 ue(sps_min_qp_prime_ts, 0, 8);
1556 flag(sps_ibc_enabled_flag);
1557 if (current->sps_ibc_enabled_flag)
1558 ue(sps_six_minus_max_num_ibc_merge_cand, 0, 5);
1560 flag(sps_ladf_enabled_flag);
1561 if (current->sps_ladf_enabled_flag) {
1562 ub(2, sps_num_ladf_intervals_minus2);
1563 se(sps_ladf_lowest_interval_qp_offset, -63, 63);
1564 for (
i = 0;
i < current->sps_num_ladf_intervals_minus2 + 1;
i++) {
1565 ses(sps_ladf_qp_offset[
i], -63, 63, 1,
i);
1566 ues(sps_ladf_delta_threshold_minus1[
i],
1567 0, (2 << (8 + current->sps_bitdepth_minus8)) - 3, 1,
i);
1571 flag(sps_explicit_scaling_list_enabled_flag);
1572 if (current->sps_lfnst_enabled_flag &&
1573 current->sps_explicit_scaling_list_enabled_flag)
1574 flag(sps_scaling_matrix_for_lfnst_disabled_flag);
1576 if (current->sps_act_enabled_flag &&
1577 current->sps_explicit_scaling_list_enabled_flag)
1578 flag(sps_scaling_matrix_for_alternative_colour_space_disabled_flag);
1580 infer(sps_scaling_matrix_for_alternative_colour_space_disabled_flag, 0);
1581 if (current->sps_scaling_matrix_for_alternative_colour_space_disabled_flag)
1582 flag(sps_scaling_matrix_designated_colour_space_flag);
1584 flag(sps_dep_quant_enabled_flag);
1585 flag(sps_sign_data_hiding_enabled_flag);
1587 flag(sps_virtual_boundaries_enabled_flag);
1588 if (current->sps_virtual_boundaries_enabled_flag) {
1589 flag(sps_virtual_boundaries_present_flag);
1590 if (current->sps_virtual_boundaries_present_flag) {
1591 ue(sps_num_ver_virtual_boundaries,
1592 0, current->sps_pic_width_max_in_luma_samples <= 8 ? 0 :
VVC_MAX_VBS);
1593 for (
i = 0;
i < current->sps_num_ver_virtual_boundaries;
i++)
1594 ues(sps_virtual_boundary_pos_x_minus1[
i],
1595 0, (current->sps_pic_width_max_in_luma_samples + 7) / 8 - 2,
1597 ue(sps_num_hor_virtual_boundaries,
1598 0, current->sps_pic_height_max_in_luma_samples <= 8 ? 0 :
VVC_MAX_VBS);
1599 for (
i = 0;
i < current->sps_num_hor_virtual_boundaries;
i++)
1600 ues(sps_virtual_boundary_pos_y_minus1[
i],
1601 0, (current->sps_pic_height_max_in_luma_samples + 7) /
1605 infer(sps_virtual_boundaries_present_flag, 0);
1606 infer(sps_num_ver_virtual_boundaries, 0);
1607 infer(sps_num_hor_virtual_boundaries, 0);
1610 if (current->sps_ptl_dpb_hrd_params_present_flag) {
1611 flag(sps_timing_hrd_params_present_flag);
1612 if (current->sps_timing_hrd_params_present_flag) {
1613 uint8_t first_sublayer;
1615 ¤t->sps_general_timing_hrd_parameters));
1616 if (current->sps_max_sublayers_minus1 > 0)
1617 flag(sps_sublayer_cpb_params_present_flag);
1619 infer(sps_sublayer_cpb_params_present_flag, 0);
1620 first_sublayer = current->sps_sublayer_cpb_params_present_flag ?
1621 0 : current->sps_max_sublayers_minus1;
1623 ¤t->sps_ols_timing_hrd_parameters, first_sublayer,
1624 current->sps_max_sublayers_minus1,
1625 ¤t->sps_general_timing_hrd_parameters));
1629 flag(sps_field_seq_flag);
1630 flag(sps_vui_parameters_present_flag);
1631 if (current->sps_vui_parameters_present_flag) {
1632 ue(sps_vui_payload_size_minus1, 0, 1023);
1634 fixed(1, sps_vui_alignment_zero_bit, 0);
1636 current->sps_vui_payload_size_minus1 + 1,
1637 current->sps_chroma_format_idc));
1642 flag(sps_extension_flag);
1643 if (current->sps_extension_flag) {
1644 flag(sps_range_extension_flag);
1645 ub(7, sps_extension_7bits);
1647 if (current->sps_range_extension_flag) {
1648 if (current->sps_bitdepth_minus8 <= 10 - 8)
1652 infer(sps_extended_precision_flag, 0);
1653 infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1654 infer(sps_rrc_rice_extension_flag, 0);
1655 infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1656 infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1659 infer(sps_range_extension_flag, 0);
1660 infer(sps_extension_7bits, 0);
1661 infer(sps_extended_precision_flag, 0);
1662 infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1663 infer(sps_rrc_rice_extension_flag, 0);
1664 infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1665 infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1668 if (current->sps_extension_7bits)
1682 unsigned int min_cb_size_y, divisor, ctb_size_y,
1683 pic_width_in_ctbs_y, pic_height_in_ctbs_y;
1684 uint8_t sub_width_c, sub_height_c, qp_bd_offset;
1686 static const uint8_t h266_sub_width_c[] = {
1689 static const uint8_t h266_sub_height_c[] = {
1693 HEADER(
"Picture Parameter Set");
1698 ub(6, pps_pic_parameter_set_id);
1699 ub(4, pps_seq_parameter_set_id);
1700 sps = h266->
sps[current->pps_seq_parameter_set_id];
1703 current->pps_seq_parameter_set_id);
1707 flag(pps_mixed_nalu_types_in_pic_flag);
1708 ue(pps_pic_width_in_luma_samples,
1709 1,
sps->sps_pic_width_max_in_luma_samples);
1710 ue(pps_pic_height_in_luma_samples,
1711 1,
sps->sps_pic_height_max_in_luma_samples);
1713 min_cb_size_y = 1 << (
sps->sps_log2_min_luma_coding_block_size_minus2 + 2);
1714 divisor =
FFMAX(min_cb_size_y, 8);
1715 if (current->pps_pic_width_in_luma_samples % divisor ||
1716 current->pps_pic_height_in_luma_samples % divisor) {
1718 "Invalid dimensions: %ux%u not divisible "
1719 "by %u, MinCbSizeY = %u.\n",
1720 current->pps_pic_width_in_luma_samples,
1721 current->pps_pic_height_in_luma_samples, divisor, min_cb_size_y);
1724 if (!
sps->sps_res_change_in_clvs_allowed_flag &&
1725 (current->pps_pic_width_in_luma_samples !=
1726 sps->sps_pic_width_max_in_luma_samples ||
1727 current->pps_pic_height_in_luma_samples !=
1728 sps->sps_pic_height_max_in_luma_samples)) {
1730 "Resoltuion change is not allowed, "
1731 "in max resolution (%ux%u) mismatched with pps(%ux%u).\n",
1732 sps->sps_pic_width_max_in_luma_samples,
1733 sps->sps_pic_height_max_in_luma_samples,
1734 current->pps_pic_width_in_luma_samples,
1735 current->pps_pic_height_in_luma_samples);
1739 ctb_size_y = 1 << (
sps->sps_log2_ctu_size_minus5 + 5);
1740 if (
sps->sps_ref_wraparound_enabled_flag) {
1741 if ((ctb_size_y / min_cb_size_y + 1) >
1742 (current->pps_pic_width_in_luma_samples / min_cb_size_y - 1)) {
1744 "Invalid width(%u), ctb_size_y = %u, min_cb_size_y = %u.\n",
1745 current->pps_pic_width_in_luma_samples,
1746 ctb_size_y, min_cb_size_y);
1751 flag(pps_conformance_window_flag);
1752 if (current->pps_pic_width_in_luma_samples ==
1753 sps->sps_pic_width_max_in_luma_samples &&
1754 current->pps_pic_height_in_luma_samples ==
1755 sps->sps_pic_height_max_in_luma_samples &&
1756 current->pps_conformance_window_flag) {
1758 "Conformance window flag should not true.\n");
1762 sub_width_c = h266_sub_width_c[
sps->sps_chroma_format_idc];
1763 sub_height_c = h266_sub_height_c[
sps->sps_chroma_format_idc];
1764 if (current->pps_conformance_window_flag) {
1765 ue(pps_conf_win_left_offset, 0, current->pps_pic_width_in_luma_samples);
1766 ue(pps_conf_win_right_offset,
1767 0, current->pps_pic_width_in_luma_samples);
1768 ue(pps_conf_win_top_offset, 0, current->pps_pic_height_in_luma_samples);
1769 ue(pps_conf_win_bottom_offset,
1770 0, current->pps_pic_height_in_luma_samples);
1772 (current->pps_conf_win_left_offset +
1773 current->pps_conf_win_right_offset) >=
1774 current->pps_pic_width_in_luma_samples ||
1776 (current->pps_conf_win_top_offset +
1777 current->pps_conf_win_bottom_offset) >=
1778 current->pps_pic_height_in_luma_samples) {
1780 "Invalid pps conformance window: (%u, %u, %u, %u), "
1781 "resolution is %ux%u, sub wxh is %ux%u.\n",
1782 current->pps_conf_win_left_offset,
1783 current->pps_conf_win_right_offset,
1784 current->pps_conf_win_top_offset,
1785 current->pps_conf_win_bottom_offset,
1786 current->pps_pic_width_in_luma_samples,
1787 current->pps_pic_height_in_luma_samples,
1788 sub_width_c, sub_height_c);
1792 if (current->pps_pic_width_in_luma_samples ==
1793 sps->sps_pic_width_max_in_luma_samples &&
1794 current->pps_pic_height_in_luma_samples ==
1795 sps->sps_pic_height_max_in_luma_samples) {
1796 infer(pps_conf_win_left_offset,
sps->sps_conf_win_left_offset);
1797 infer(pps_conf_win_right_offset,
sps->sps_conf_win_right_offset);
1798 infer(pps_conf_win_top_offset,
sps->sps_conf_win_top_offset);
1799 infer(pps_conf_win_bottom_offset,
sps->sps_conf_win_bottom_offset);
1801 infer(pps_conf_win_left_offset, 0);
1802 infer(pps_conf_win_right_offset, 0);
1803 infer(pps_conf_win_top_offset, 0);
1804 infer(pps_conf_win_bottom_offset, 0);
1809 flag(pps_scaling_window_explicit_signalling_flag);
1810 if (!
sps->sps_ref_pic_resampling_enabled_flag &&
1811 current->pps_scaling_window_explicit_signalling_flag) {
1813 "Invalid data: sps_ref_pic_resampling_enabled_flag is false, "
1814 "but pps_scaling_window_explicit_signalling_flag is true.\n");
1817 if (current->pps_scaling_window_explicit_signalling_flag) {
1818 se(pps_scaling_win_left_offset,
1819 -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1820 current->pps_pic_width_in_luma_samples / sub_width_c);
1821 se(pps_scaling_win_right_offset,
1822 -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1823 current->pps_pic_width_in_luma_samples / sub_width_c);
1824 se(pps_scaling_win_top_offset,
1825 -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1826 current->pps_pic_height_in_luma_samples / sub_height_c);
1827 se(pps_scaling_win_bottom_offset,
1828 -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1829 current->pps_pic_height_in_luma_samples / sub_height_c);
1831 infer(pps_scaling_win_left_offset, current->pps_conf_win_left_offset);
1832 infer(pps_scaling_win_right_offset, current->pps_conf_win_right_offset);
1833 infer(pps_scaling_win_top_offset, current->pps_conf_win_top_offset);
1834 infer(pps_scaling_win_bottom_offset, current->pps_conf_win_bottom_offset);
1837 flag(pps_output_flag_present_flag);
1838 flag(pps_no_pic_partition_flag);
1839 flag(pps_subpic_id_mapping_present_flag);
1841 if (current->pps_subpic_id_mapping_present_flag) {
1842 if (!current->pps_no_pic_partition_flag) {
1843 ue(pps_num_subpics_minus1,
1844 sps->sps_num_subpics_minus1,
sps->sps_num_subpics_minus1);
1846 infer(pps_num_subpics_minus1, 0);
1848 ue(pps_subpic_id_len_minus1,
sps->sps_subpic_id_len_minus1,
1849 sps->sps_subpic_id_len_minus1);
1850 for (
i = 0;
i <= current->pps_num_subpics_minus1;
i++) {
1851 ubs(
sps->sps_subpic_id_len_minus1 + 1, pps_subpic_id[
i], 1,
i);
1855 for (
i = 0;
i <=
sps->sps_num_subpics_minus1;
i++) {
1856 if (
sps->sps_subpic_id_mapping_explicitly_signalled_flag)
1857 current->sub_pic_id_val[
i] = current->pps_subpic_id_mapping_present_flag
1858 ? current->pps_subpic_id[
i]
1859 :
sps->sps_subpic_id[
i];
1861 current->sub_pic_id_val[
i] =
i;
1865 (current->pps_pic_width_in_luma_samples, (
sps->sps_log2_ctu_size_minus5 + 5));
1867 current->pps_pic_height_in_luma_samples,(
sps->sps_log2_ctu_size_minus5 + 5));
1868 if (!current->pps_no_pic_partition_flag) {
1869 unsigned int exp_tile_width = 0, exp_tile_height = 0;
1870 unsigned int unified_size, remaining_size;
1872 u(2, pps_log2_ctu_size_minus5,
1873 sps->sps_log2_ctu_size_minus5,
sps->sps_log2_ctu_size_minus5);
1874 ue(pps_num_exp_tile_columns_minus1,
1876 ue(pps_num_exp_tile_rows_minus1,
1879 for (
i = 0;
i <= current->pps_num_exp_tile_columns_minus1;
i++) {
1880 ues(pps_tile_column_width_minus1[
i],
1881 0, pic_width_in_ctbs_y - exp_tile_width - 1, 1,
i);
1882 exp_tile_width += current->pps_tile_column_width_minus1[
i] + 1;
1884 for (
i = 0;
i <= current->pps_num_exp_tile_rows_minus1;
i++) {
1885 ues(pps_tile_row_height_minus1[
i],
1886 0, pic_height_in_ctbs_y - exp_tile_height - 1, 1,
i);
1887 exp_tile_height += current->pps_tile_row_height_minus1[
i] + 1;
1890 remaining_size = pic_width_in_ctbs_y;
1891 for (
i = 0;
i <= current->pps_num_exp_tile_columns_minus1;
i++) {
1892 if (current->pps_tile_column_width_minus1[
i] >= remaining_size) {
1894 "Tile column width(%d) exceeds picture width\n",
i);
1897 current->col_width_val[
i] = current->pps_tile_column_width_minus1[
i] + 1;
1898 remaining_size -= (current->pps_tile_column_width_minus1[
i] + 1);
1900 unified_size = current->pps_tile_column_width_minus1[
i - 1] + 1;
1901 while (remaining_size > 0) {
1904 "NumTileColumns(%d) > than VVC_MAX_TILE_COLUMNS(%d)\n",
1908 unified_size =
FFMIN(remaining_size, unified_size);
1909 current->col_width_val[
i] = unified_size;
1910 remaining_size -= unified_size;
1913 current->num_tile_columns =
i;
1916 "NumTileColumns(%d) > than VVC_MAX_TILE_COLUMNS(%d)\n",
1921 remaining_size = pic_height_in_ctbs_y;
1922 for (
i = 0;
i <= current->pps_num_exp_tile_rows_minus1;
i++) {
1923 if (current->pps_tile_row_height_minus1[
i] >= remaining_size) {
1925 "Tile row height(%d) exceeds picture height\n",
i);
1928 current->row_height_val[
i] = current->pps_tile_row_height_minus1[
i] + 1;
1929 remaining_size -= (current->pps_tile_row_height_minus1[
i] + 1);
1931 unified_size = current->pps_tile_row_height_minus1[
i - 1] + 1;
1933 while (remaining_size > 0) {
1934 unified_size =
FFMIN(remaining_size, unified_size);
1935 current->row_height_val[
i] = unified_size;
1936 remaining_size -= unified_size;
1939 current->num_tile_rows=
i;
1942 "NumTileRows(%d) > than VVC_MAX_TILE_ROWS(%d)\n",
1947 current->num_tiles_in_pic = current->num_tile_columns *
1948 current->num_tile_rows;
1951 "NumTilesInPic(%d) > than VVC_MAX_TILES_PER_AU(%d)\n",
1956 if (current->num_tiles_in_pic > 1) {
1957 flag(pps_loop_filter_across_tiles_enabled_flag);
1958 flag(pps_rect_slice_flag);
1960 infer(pps_loop_filter_across_tiles_enabled_flag, 0);
1961 infer(pps_rect_slice_flag, 1);
1963 if (current->pps_rect_slice_flag)
1964 flag(pps_single_slice_per_subpic_flag);
1966 infer(pps_single_slice_per_subpic_flag, 1);
1967 if (current->pps_rect_slice_flag &&
1968 !current->pps_single_slice_per_subpic_flag) {
1970 uint16_t tile_idx = 0, tile_x, tile_y, ctu_x, ctu_y;
1974 if (current->pps_num_slices_in_pic_minus1 > 1)
1975 flag(pps_tile_idx_delta_present_flag);
1977 infer(pps_tile_idx_delta_present_flag, 0);
1978 for (
i = 0;
i < current->pps_num_slices_in_pic_minus1;
i++) {
1979 tile_x = tile_idx % current->num_tile_columns;
1980 tile_y = tile_idx / current->num_tile_columns;
1981 if (tile_x != current->num_tile_columns - 1) {
1982 ues(pps_slice_width_in_tiles_minus1[
i],
1983 0, current->num_tile_columns - 1, 1,
i);
1985 infer(pps_slice_width_in_tiles_minus1[
i], 0);
1987 if (tile_y != current->num_tile_rows - 1 &&
1988 (current->pps_tile_idx_delta_present_flag || tile_x == 0)) {
1989 ues(pps_slice_height_in_tiles_minus1[
i],
1990 0, current->num_tile_rows - 1, 1,
i);
1992 if (tile_y == current->num_tile_rows - 1)
1993 infer(pps_slice_height_in_tiles_minus1[
i], 0);
1995 infer(pps_slice_height_in_tiles_minus1[
i],
1996 current->pps_slice_height_in_tiles_minus1[
i - 1]);
2000 for (j = 0; j < tile_x; j++) {
2001 ctu_x += current->col_width_val[j];
2003 for (j = 0; j < tile_y; j++) {
2004 ctu_y += current->row_height_val[j];
2006 if (current->pps_slice_width_in_tiles_minus1[
i] == 0 &&
2007 current->pps_slice_height_in_tiles_minus1[
i] == 0 &&
2008 current->row_height_val[tile_y] > 1) {
2009 int num_slices_in_tile,
2010 uniform_slice_height, remaining_height_in_ctbs_y;
2011 remaining_height_in_ctbs_y =
2012 current->row_height_val[tile_y];
2013 ues(pps_num_exp_slices_in_tile[
i],
2014 0, current->row_height_val[tile_y] - 1, 1,
i);
2015 if (current->pps_num_exp_slices_in_tile[
i] == 0) {
2016 num_slices_in_tile = 1;
2017 current->slice_height_in_ctus[
i] = current->row_height_val[tile_y];
2018 slice_top_left_ctu_x[
i] = ctu_x;
2019 slice_top_left_ctu_y[
i] = ctu_y;
2021 uint16_t slice_height_in_ctus;
2022 for (j = 0; j < current->pps_num_exp_slices_in_tile[
i];
2024 ues(pps_exp_slice_height_in_ctus_minus1[
i][j], 0,
2025 current->row_height_val[tile_y] - 1, 2,
2027 slice_height_in_ctus =
2029 pps_exp_slice_height_in_ctus_minus1[
i][j] + 1;
2031 current->slice_height_in_ctus[
i + j] =
2032 slice_height_in_ctus;
2033 slice_top_left_ctu_x[
i + j] = ctu_x;
2034 slice_top_left_ctu_y[
i + j] = ctu_y;
2035 ctu_y += slice_height_in_ctus;
2037 remaining_height_in_ctbs_y -= slice_height_in_ctus;
2039 uniform_slice_height = 1 +
2040 (j == 0 ? current->row_height_val[tile_y] - 1:
2041 current->pps_exp_slice_height_in_ctus_minus1[
i][j-1]);
2042 while (remaining_height_in_ctbs_y > uniform_slice_height) {
2043 current->slice_height_in_ctus[
i + j] =
2044 uniform_slice_height;
2045 slice_top_left_ctu_x[
i + j] = ctu_x;
2046 slice_top_left_ctu_y[
i + j] = ctu_y;
2047 ctu_y += uniform_slice_height;
2049 remaining_height_in_ctbs_y -= uniform_slice_height;
2052 if (remaining_height_in_ctbs_y > 0) {
2053 current->slice_height_in_ctus[
i + j] =
2054 remaining_height_in_ctbs_y;
2055 slice_top_left_ctu_x[
i + j] = ctu_x;
2056 slice_top_left_ctu_y[
i + j] = ctu_y;
2059 num_slices_in_tile = j;
2061 i += num_slices_in_tile - 1;
2064 infer(pps_num_exp_slices_in_tile[
i], 0);
2066 j <= current->pps_slice_height_in_tiles_minus1[
i];
2069 current->row_height_val[tile_y + j];
2071 current->slice_height_in_ctus[
i] =
height;
2073 slice_top_left_ctu_x[
i] = ctu_x;
2074 slice_top_left_ctu_y[
i] = ctu_y;
2076 if (i < current->pps_num_slices_in_pic_minus1) {
2077 if (current->pps_tile_idx_delta_present_flag) {
2082 ses(pps_tile_idx_delta_val[
i],
2083 -tile_idx, current->num_tiles_in_pic - 1 - tile_idx, 1,
i);
2084 if (current->pps_tile_idx_delta_val[
i] == 0) {
2086 "pps_tile_idx_delta_val[i] shall not be equal to 0.\n");
2088 tile_idx += current->pps_tile_idx_delta_val[
i];
2090 infer(pps_tile_idx_delta_val[
i], 0);
2092 current->pps_slice_width_in_tiles_minus1[
i] + 1;
2093 if (tile_idx % current->num_tile_columns == 0) {
2095 current->pps_slice_height_in_tiles_minus1[
i] *
2096 current->num_tile_columns;
2101 if (
i == current->pps_num_slices_in_pic_minus1) {
2104 tile_x = tile_idx % current->num_tile_columns;
2105 tile_y = tile_idx / current->num_tile_columns;
2106 if (tile_y >= current->num_tile_rows)
2109 ctu_x = 0, ctu_y = 0;
2110 for (j = 0; j < tile_x; j++) {
2111 ctu_x += current->col_width_val[j];
2113 for (j = 0; j < tile_y; j++) {
2114 ctu_y += current->row_height_val[j];
2116 slice_top_left_ctu_x[
i] = ctu_x;
2117 slice_top_left_ctu_y[
i] = ctu_y;
2119 current->pps_slice_width_in_tiles_minus1[
i] =
2120 current->num_tile_columns - tile_x - 1;
2121 current->pps_slice_height_in_tiles_minus1[
i] =
2122 current->num_tile_rows - tile_y - 1;
2124 for (j = 0; j <= current->pps_slice_height_in_tiles_minus1[
i];
2127 current->row_height_val[tile_y + j];
2129 current->slice_height_in_ctus[
i] =
height;
2131 infer(pps_num_exp_slices_in_tile[
i], 0);
2134 for (
i = 0;
i <=
sps->sps_num_subpics_minus1;
i++) {
2135 current->num_slices_in_subpic[
i] = 0;
2136 for (j = 0; j <= current->pps_num_slices_in_pic_minus1; j++) {
2137 uint16_t pos_x = 0, pos_y = 0;
2138 pos_x = slice_top_left_ctu_x[j];
2139 pos_y = slice_top_left_ctu_y[j];
2140 if ((pos_x >=
sps->sps_subpic_ctu_top_left_x[
i]) &&
2142 sps->sps_subpic_ctu_top_left_x[
i] +
2143 sps->sps_subpic_width_minus1[
i] + 1) &&
2144 (pos_y >=
sps->sps_subpic_ctu_top_left_y[
i]) &&
2145 (pos_y < sps->sps_subpic_ctu_top_left_y[
i] +
2146 sps->sps_subpic_height_minus1[
i] + 1)) {
2147 current->num_slices_in_subpic[
i]++;
2152 if (current->pps_no_pic_partition_flag)
2153 infer(pps_num_slices_in_pic_minus1, 0);
2154 else if (current->pps_single_slice_per_subpic_flag) {
2155 for (
i = 0;
i <=
sps->sps_num_subpics_minus1;
i++)
2156 current->num_slices_in_subpic[
i] = 1;
2157 infer(pps_num_slices_in_pic_minus1,
2158 sps->sps_num_subpics_minus1);
2162 if (!current->pps_rect_slice_flag ||
2163 current->pps_single_slice_per_subpic_flag ||
2164 current->pps_num_slices_in_pic_minus1 > 0)
2165 flag(pps_loop_filter_across_slices_enabled_flag);
2167 infer(pps_loop_filter_across_slices_enabled_flag, 0);
2169 infer(pps_num_exp_tile_columns_minus1, 0);
2170 infer(pps_tile_column_width_minus1[0], pic_width_in_ctbs_y - 1);
2171 infer(pps_num_exp_tile_rows_minus1, 0);
2172 infer(pps_tile_row_height_minus1[0], pic_height_in_ctbs_y - 1);
2173 current->col_width_val[0] = pic_width_in_ctbs_y;
2174 current->row_height_val[0] = pic_height_in_ctbs_y;
2175 current->num_tile_columns = 1;
2176 current->num_tile_rows = 1;
2177 current->num_tiles_in_pic = 1;
2180 flag(pps_cabac_init_present_flag);
2181 for (
i = 0;
i < 2;
i++)
2182 ues(pps_num_ref_idx_default_active_minus1[
i], 0, 14, 1,
i);
2183 flag(pps_rpl1_idx_present_flag);
2184 flag(pps_weighted_pred_flag);
2185 flag(pps_weighted_bipred_flag);
2186 flag(pps_ref_wraparound_enabled_flag);
2187 if (current->pps_ref_wraparound_enabled_flag) {
2188 ue(pps_pic_width_minus_wraparound_offset,
2189 0, (current->pps_pic_width_in_luma_samples / min_cb_size_y)
2190 - (ctb_size_y / min_cb_size_y) - 2);
2193 qp_bd_offset = 6 *
sps->sps_bitdepth_minus8;
2194 se(pps_init_qp_minus26, -(26 + qp_bd_offset), 37);
2195 flag(pps_cu_qp_delta_enabled_flag);
2196 flag(pps_chroma_tool_offsets_present_flag);
2197 if (current->pps_chroma_tool_offsets_present_flag) {
2198 se(pps_cb_qp_offset, -12, 12);
2199 se(pps_cr_qp_offset, -12, 12);
2200 flag(pps_joint_cbcr_qp_offset_present_flag);
2201 if (current->pps_joint_cbcr_qp_offset_present_flag)
2202 se(pps_joint_cbcr_qp_offset_value, -12, 12);
2204 infer(pps_joint_cbcr_qp_offset_value, 0);
2205 flag(pps_slice_chroma_qp_offsets_present_flag);
2206 flag(pps_cu_chroma_qp_offset_list_enabled_flag);
2207 if (current->pps_cu_chroma_qp_offset_list_enabled_flag) {
2208 ue(pps_chroma_qp_offset_list_len_minus1, 0, 5);
2209 for (
i = 0;
i <= current->pps_chroma_qp_offset_list_len_minus1;
i++) {
2210 ses(pps_cb_qp_offset_list[
i], -12, 12, 1,
i);
2211 ses(pps_cr_qp_offset_list[
i], -12, 12, 1,
i);
2212 if (current->pps_joint_cbcr_qp_offset_present_flag)
2213 ses(pps_joint_cbcr_qp_offset_list[
i], -12, 12, 1,
i);
2215 infer(pps_joint_cbcr_qp_offset_list[
i], 0);
2219 infer(pps_cb_qp_offset, 0);
2220 infer(pps_cr_qp_offset, 0);
2221 infer(pps_joint_cbcr_qp_offset_present_flag, 0);
2222 infer(pps_joint_cbcr_qp_offset_value, 0);
2223 infer(pps_slice_chroma_qp_offsets_present_flag, 0);
2224 infer(pps_cu_chroma_qp_offset_list_enabled_flag, 0);
2226 flag(pps_deblocking_filter_control_present_flag);
2227 if (current->pps_deblocking_filter_control_present_flag) {
2228 flag(pps_deblocking_filter_override_enabled_flag);
2229 flag(pps_deblocking_filter_disabled_flag);
2230 if (!current->pps_no_pic_partition_flag &&
2231 current->pps_deblocking_filter_override_enabled_flag)
2232 flag(pps_dbf_info_in_ph_flag);
2234 infer(pps_dbf_info_in_ph_flag, 0);
2235 if (!current->pps_deblocking_filter_disabled_flag) {
2236 se(pps_luma_beta_offset_div2, -12, 12);
2237 se(pps_luma_tc_offset_div2, -12, 12);
2238 if (current->pps_chroma_tool_offsets_present_flag) {
2239 se(pps_cb_beta_offset_div2, -12, 12);
2240 se(pps_cb_tc_offset_div2, -12, 12);
2241 se(pps_cr_beta_offset_div2, -12, 12);
2242 se(pps_cr_tc_offset_div2, -12, 12);
2244 infer(pps_cb_beta_offset_div2,
2245 current->pps_luma_beta_offset_div2);
2246 infer(pps_cb_tc_offset_div2, current->pps_luma_tc_offset_div2);
2247 infer(pps_cr_beta_offset_div2,
2248 current->pps_luma_beta_offset_div2);
2249 infer(pps_cr_tc_offset_div2, current->pps_luma_tc_offset_div2);
2252 infer(pps_luma_beta_offset_div2, 0);
2253 infer(pps_luma_tc_offset_div2, 0);
2254 infer(pps_cb_beta_offset_div2, 0);
2255 infer(pps_cb_tc_offset_div2, 0);
2256 infer(pps_cr_beta_offset_div2, 0);
2257 infer(pps_cr_tc_offset_div2, 0);
2260 infer(pps_deblocking_filter_override_enabled_flag, 0);
2261 infer(pps_deblocking_filter_disabled_flag, 0);
2262 infer(pps_dbf_info_in_ph_flag, 0);
2263 infer(pps_luma_beta_offset_div2, 0);
2264 infer(pps_luma_tc_offset_div2, 0);
2265 infer(pps_cb_beta_offset_div2, 0);
2266 infer(pps_cb_tc_offset_div2, 0);
2267 infer(pps_cr_beta_offset_div2, 0);
2268 infer(pps_cr_tc_offset_div2, 0);
2271 if (!current->pps_no_pic_partition_flag) {
2272 flag(pps_rpl_info_in_ph_flag);
2273 flag(pps_sao_info_in_ph_flag);
2274 flag(pps_alf_info_in_ph_flag);
2275 if ((current->pps_weighted_pred_flag ||
2276 current->pps_weighted_bipred_flag) &&
2277 current->pps_rpl_info_in_ph_flag)
2278 flag(pps_wp_info_in_ph_flag);
2279 flag(pps_qp_delta_info_in_ph_flag);
2281 flag(pps_picture_header_extension_present_flag);
2282 flag(pps_slice_header_extension_present_flag);
2284 flag(pps_extension_flag);
2285 if (current->pps_extension_flag)
2297 flag(alf_luma_filter_signal_flag);
2299 if (current->aps_chroma_present_flag) {
2300 flag(alf_chroma_filter_signal_flag);
2301 flag(alf_cc_cb_filter_signal_flag);
2302 flag(alf_cc_cr_filter_signal_flag);
2304 infer(alf_chroma_filter_signal_flag, 0);
2305 infer(alf_cc_cb_filter_signal_flag, 0);
2306 infer(alf_cc_cr_filter_signal_flag, 0);
2309 if (current->alf_luma_filter_signal_flag) {
2310 flag(alf_luma_clip_flag);
2312 if (current->alf_luma_num_filters_signalled_minus1 > 0) {
2313 unsigned int bits =
av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
2315 us(
bits, alf_luma_coeff_delta_idx[filt_idx],
2316 0, current->alf_luma_num_filters_signalled_minus1,
2319 for (
int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
2320 for (j = 0; j < 12; j++) {
2321 ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
2322 if (current->alf_luma_coeff_abs[sf_idx][j])
2323 ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
2325 infer(alf_luma_coeff_sign[sf_idx][j], 0);
2328 infer(alf_luma_clip_flag, 0);
2329 infer(alf_luma_num_filters_signalled_minus1, 0);
2331 for (
int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++) {
2332 for (j = 0; j < 12; j++) {
2333 if (current->alf_luma_clip_flag)
2334 ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
2336 infer(alf_luma_clip_idx[sf_idx][j], 0);
2340 if (current->alf_chroma_filter_signal_flag) {
2341 flag(alf_chroma_clip_flag);
2342 ue(alf_chroma_num_alt_filters_minus1, 0, 7);
2344 infer(alf_chroma_clip_flag, 0);
2345 infer(alf_chroma_num_alt_filters_minus1, 0);
2347 for (
int alt_idx = 0; alt_idx <= current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
2348 for (j = 0; j < 6; j++) {
2349 if (current->alf_chroma_filter_signal_flag)
2350 ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx, j);
2352 infer(alf_chroma_coeff_abs[alt_idx][j], 0);
2353 if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
2354 ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
2356 infer(alf_chroma_coeff_sign[alt_idx][j], 0);
2358 for (j = 0; j < 6; j++) {
2359 if (current->alf_chroma_clip_flag)
2360 ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
2362 infer(alf_chroma_clip_idx[alt_idx][j], 0);
2366 if (current->alf_cc_cb_filter_signal_flag)
2367 ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
2369 infer(alf_cc_cb_filters_signalled_minus1, 0);
2370 for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
2371 for (j = 0; j < 7; j++) {
2372 if (current->alf_cc_cb_filter_signal_flag)
2373 ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
2375 infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
2376 if (current->alf_cc_cb_mapped_coeff_abs[k][j])
2377 ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
2379 infer(alf_cc_cb_coeff_sign[k][j], 0);
2383 if (current->alf_cc_cr_filter_signal_flag)
2384 ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
2386 infer(alf_cc_cr_filters_signalled_minus1, 0);
2387 for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++) {
2388 for (j = 0; j < 7; j++) {
2389 if (current->alf_cc_cr_filter_signal_flag)
2390 ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
2392 infer(alf_cc_cr_mapped_coeff_abs[k][j], 0);
2393 if (current->alf_cc_cr_mapped_coeff_abs[k][j])
2394 ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
2396 infer(alf_cc_cr_coeff_sign[k][j], 0);
2406 int err,
i, lmcs_max_bin_idx;
2408 ue(lmcs_min_bin_idx, 0, 15);
2409 ue(lmcs_delta_max_bin_idx, 0, 15);
2410 ue(lmcs_delta_cw_prec_minus1, 0, 14);
2412 lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
2414 if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
2417 for (
i = current->lmcs_min_bin_idx;
i <= lmcs_max_bin_idx;
i++) {
2418 ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[
i], 1,
i);
2419 if (current->lmcs_delta_abs_cw[
i] > 0)
2420 flags(lmcs_delta_sign_cw_flag[
i], 1,
i);
2422 infer(lmcs_delta_sign_cw_flag[
i], 0);
2425 if (current->aps_chroma_present_flag) {
2426 ub(3, lmcs_delta_abs_crs);
2427 if (current->lmcs_delta_abs_crs > 0)
2428 flag(lmcs_delta_sign_crs_flag);
2430 infer(lmcs_delta_sign_crs_flag, 0);
2432 infer(lmcs_delta_abs_crs, 0);
2433 infer(lmcs_delta_sign_crs_flag, 0);
2443 static const uint8_t diag_scan_order[64][2] = {
2444 { 0, 0, }, { 0, 1, }, { 1, 0, }, { 0, 2, }, { 1, 1, }, { 2, 0, }, { 0, 3, }, { 1, 2, },
2445 { 2, 1, }, { 3, 0, }, { 0, 4, }, { 1, 3, }, { 2, 2, }, { 3, 1, }, { 4, 0, }, { 0, 5, },
2446 { 1, 4, }, { 2, 3, }, { 3, 2, }, { 4, 1, }, { 5, 0, }, { 0, 6, }, { 1, 5, }, { 2, 4, },
2447 { 3, 3, }, { 4, 2, }, { 5, 1, }, { 6, 0, }, { 0, 7, }, { 1, 6, }, { 2, 5, }, { 3, 4, },
2448 { 4, 3, }, { 5, 2, }, { 6, 1, }, { 7, 0, }, { 1, 7, }, { 2, 6, }, { 3, 5, }, { 4, 4, },
2449 { 5, 3, }, { 6, 2, }, { 7, 1, }, { 2, 7, }, { 3, 6, }, { 4, 5, }, { 5, 4, }, { 6, 3, },
2450 { 7, 2, }, { 3, 7, }, { 4, 6, }, { 5, 5, }, { 6, 4, }, { 7, 3, }, { 4, 7, }, { 5, 6, },
2451 { 6, 5, }, { 7, 4, }, { 5, 7, }, { 6, 6, }, { 7, 5, }, { 6, 7, }, { 7, 6, }, { 7, 7, }, };
2454 for (
int id = 0;
id < 28;
id ++) {
2455 if (current->aps_chroma_present_flag ||
id % 3 == 2 ||
id == 27) {
2456 flags(scaling_list_copy_mode_flag[
id], 1,
id);
2457 if (!current->scaling_list_copy_mode_flag[
id])
2458 flags(scaling_list_pred_mode_flag[
id], 1,
id);
2460 infer(scaling_list_pred_mode_flag[
id], 0);
2461 if ((current->scaling_list_copy_mode_flag[
id] ||
2462 current->scaling_list_pred_mode_flag[
id]) &&
2463 id != 0 &&
id != 2 &&
id != 8) {
2464 int max_id_delta = (
id < 2) ?
id : ((
id < 8) ? (
id - 2) : (
id - 8));
2465 ues(scaling_list_pred_id_delta[
id], 0, max_id_delta, 1,
id);
2467 if (!current->scaling_list_copy_mode_flag[
id]) {
2468 int matrix_size =
id < 2 ? 2 : (
id < 8 ? 4 : 8);
2471 ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
2473 for (
int i = 0;
i < matrix_size * matrix_size;
i++) {
2474 int x = diag_scan_order[
i][0];
2475 int y = diag_scan_order[
i][1];
2476 if (!(
id > 25 && x >= 4 && y >= 4))
2477 ses(scaling_list_delta_coef[
id][
i], -128, 127, 2,
id,
i);
2479 }
else if (
id > 13) {
2481 infer(scaling_list_dc_coef[idx], 0);
2484 infer(scaling_list_copy_mode_flag[
id], 1);
2485 infer(scaling_list_pred_mode_flag[
id], 0);
2499 HEADER(
"Prefix Adaptation parameter set");
2501 HEADER(
"Suffix Adaptation parameter set");
2507 ub(3, aps_params_type);
2513 u(5, aps_adaptation_parameter_set_id, 0, aps_id_max);
2514 flag(aps_chroma_present_flag);
2521 flag(aps_extension_flag);
2522 if (current->aps_extension_flag)
2534 HEADER(
"Access Unit Delimiter");
2539 flag(aud_irap_or_gdr_flag);
2540 u(3, aud_pic_type, 0, 2);
2550 uint8_t num_ref_idx_active[2],
2554 ue(luma_log2_weight_denom, 0, 7);
2555 if (
sps->sps_chroma_format_idc != 0) {
2556 se(delta_chroma_log2_weight_denom,
2557 -current->luma_log2_weight_denom,
2558 7 - current->luma_log2_weight_denom);
2560 infer(delta_chroma_log2_weight_denom, 0);
2562 if (
pps->pps_wp_info_in_ph_flag) {
2563 ue(num_l0_weights, 0,
2564 FFMIN(15, ref_lists->rpl_ref_list[0].num_ref_entries));
2565 infer(num_weights_l0, current->num_l0_weights);
2567 infer(num_weights_l0, num_ref_idx_active[0]);
2569 for (
i = 0;
i < current->num_weights_l0;
i++) {
2570 flags(luma_weight_l0_flag[
i], 1,
i);
2572 if (
sps->sps_chroma_format_idc != 0) {
2573 for (
i = 0;
i < current->num_weights_l0;
i++)
2574 flags(chroma_weight_l0_flag[
i], 1,
i);
2576 for (
i = 0;
i < current->num_weights_l0;
i++) {
2577 if (current->luma_weight_l0_flag[
i]) {
2578 ses(delta_luma_weight_l0[
i], -128, 127, 1,
i);
2579 ses(luma_offset_l0[
i], -128, 127, 1,
i);
2581 infer(delta_luma_weight_l0[
i], 0);
2582 infer(luma_offset_l0[
i], 0);
2584 if (current->chroma_weight_l0_flag[
i]) {
2585 for (j = 0; j < 2; j++) {
2586 ses(delta_chroma_weight_l0[
i][j], -128, 127, 2,
i, j);
2587 ses(delta_chroma_offset_l0[
i][j], -4 * 128, 4 * 127, 2,
i, j);
2592 if (
pps->pps_weighted_bipred_flag &&
2593 ref_lists->rpl_ref_list[1].num_ref_entries > 0) {
2594 if (
pps->pps_wp_info_in_ph_flag) {
2595 ue(num_l1_weights, 0,
2596 FFMIN(15, ref_lists->rpl_ref_list[1].num_ref_entries));
2597 infer(num_weights_l1, current->num_l1_weights);
2599 infer(num_weights_l1, num_ref_idx_active[1]);
2602 infer(num_weights_l1, 0);
2605 for (
i = 0;
i < current->num_weights_l1;
i++)
2606 flags(luma_weight_l1_flag[
i], 1,
i);
2607 if (
sps->sps_chroma_format_idc != 0) {
2608 for (
i = 0;
i < current->num_weights_l1;
i++)
2609 flags(chroma_weight_l1_flag[
i], 1,
i);
2611 for (
i = 0;
i < current->num_weights_l1;
i++) {
2612 if (current->luma_weight_l1_flag[
i]) {
2613 ses(delta_luma_weight_l1[
i], -128, 127, 1,
i);
2614 ses(luma_offset_l1[
i], -128, 127, 1,
i);
2616 infer(delta_luma_weight_l1[
i], 0);
2617 infer(luma_offset_l1[
i], 0);
2619 if (current->chroma_weight_l1_flag[
i]) {
2620 for (j = 0; j < 2; j++) {
2621 ses(delta_chroma_weight_l1[
i][j], -128, 127, 2,
i, j);
2622 ses(delta_chroma_offset_l1[
i][j], -4 * 128, 4 * 127, 2,
i, j);
2636 unsigned int ctb_log2_size_y, min_cb_log2_size_y,
2637 min_qt_log2_size_intra_y, min_qt_log2_size_inter_y;
2638 uint8_t qp_bd_offset;
2640 flag(ph_gdr_or_irap_pic_flag);
2641 flag(ph_non_ref_pic_flag);
2642 if (current->ph_gdr_or_irap_pic_flag)
2643 flag(ph_gdr_pic_flag);
2645 infer(ph_gdr_pic_flag, 0);
2646 flag(ph_inter_slice_allowed_flag);
2647 if (current->ph_inter_slice_allowed_flag)
2648 flag(ph_intra_slice_allowed_flag);
2650 infer(ph_intra_slice_allowed_flag, 1);
2652 pps = h266->
pps[current->ph_pic_parameter_set_id];
2655 current->ph_pic_parameter_set_id);
2658 sps = h266->
sps[
pps->pps_seq_parameter_set_id];
2661 pps->pps_seq_parameter_set_id);
2664 vps = h266->
vps[
sps->sps_video_parameter_set_id];
2667 sps->sps_video_parameter_set_id);
2671 ub(
sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4, ph_pic_order_cnt_lsb);
2672 if (current->ph_gdr_pic_flag)
2673 ue(ph_recovery_poc_cnt, 0,
2674 1 << (
sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4));
2676 for (
i = 0;
i <
sps->sps_num_extra_ph_bytes * 8;
i++) {
2677 if (
sps->sps_extra_ph_bit_present_flag[
i])
2680 if (
sps->sps_poc_msb_cycle_flag) {
2681 flag(ph_poc_msb_cycle_present_flag);
2682 if (current->ph_poc_msb_cycle_present_flag)
2683 ub(
sps->sps_poc_msb_cycle_len_minus1 + 1, ph_poc_msb_cycle_val);
2685 if (
sps->sps_alf_enabled_flag &&
pps->pps_alf_info_in_ph_flag) {
2686 flag(ph_alf_enabled_flag);
2687 if (current->ph_alf_enabled_flag) {
2689 ub(3, ph_num_alf_aps_ids_luma);
2690 for (
i = 0;
i < current->ph_num_alf_aps_ids_luma;
i++)
2691 ubs(3, ph_alf_aps_id_luma[
i], 1,
i);
2693 if (
sps->sps_chroma_format_idc != 0) {
2694 flag(ph_alf_cb_enabled_flag);
2695 flag(ph_alf_cr_enabled_flag);
2697 infer(ph_alf_cb_enabled_flag, 0);
2698 infer(ph_alf_cr_enabled_flag, 0);
2701 if (current->ph_alf_cb_enabled_flag
2702 || current->ph_alf_cr_enabled_flag) {
2703 ub(3, ph_alf_aps_id_chroma);
2706 if (
sps->sps_ccalf_enabled_flag) {
2707 flag(ph_alf_cc_cb_enabled_flag);
2708 if (current->ph_alf_cc_cb_enabled_flag)
2709 ub(3, ph_alf_cc_cb_aps_id);
2710 flag(ph_alf_cc_cr_enabled_flag);
2711 if (current->ph_alf_cc_cr_enabled_flag)
2712 ub(3, ph_alf_cc_cr_aps_id);
2716 infer(ph_alf_enabled_flag, 0);
2718 if (
sps->sps_lmcs_enabled_flag) {
2719 flag(ph_lmcs_enabled_flag);
2720 if (current->ph_lmcs_enabled_flag) {
2721 ub(2, ph_lmcs_aps_id);
2722 if (
sps->sps_chroma_format_idc != 0)
2723 flag(ph_chroma_residual_scale_flag);
2725 infer(ph_chroma_residual_scale_flag, 0);
2728 infer(ph_lmcs_enabled_flag, 0);
2729 infer(ph_chroma_residual_scale_flag, 0);
2732 if (
sps->sps_explicit_scaling_list_enabled_flag) {
2733 flag(ph_explicit_scaling_list_enabled_flag);
2734 if (current->ph_explicit_scaling_list_enabled_flag) {
2736 ub(3, ph_scaling_list_aps_id);
2739 infer(ph_explicit_scaling_list_enabled_flag, 0);
2741 if (
sps->sps_virtual_boundaries_enabled_flag &&
2742 !
sps->sps_virtual_boundaries_present_flag) {
2743 flag(ph_virtual_boundaries_present_flag);
2744 if (current->ph_virtual_boundaries_present_flag) {
2745 ue(ph_num_ver_virtual_boundaries,
2747 for (
i = 0;
i < current->ph_num_ver_virtual_boundaries;
i++) {
2748 ues(ph_virtual_boundary_pos_x_minus1[
i],
2749 0, (
pps->pps_pic_width_in_luma_samples + 7) / 8 - 2, 1,
i);
2751 ue(ph_num_hor_virtual_boundaries,
2753 for (
i = 0;
i < current->ph_num_hor_virtual_boundaries;
i++) {
2754 ues(ph_virtual_boundary_pos_y_minus1[
i],
2755 0, (
pps->pps_pic_height_in_luma_samples + 7) / 8 - 2, 1,
i);
2758 infer(ph_num_ver_virtual_boundaries, 0);
2759 infer(ph_num_hor_virtual_boundaries, 0);
2762 if (
pps->pps_output_flag_present_flag && !current->ph_non_ref_pic_flag)
2763 flag(ph_pic_output_flag);
2765 infer(ph_pic_output_flag, 1);
2766 if (
pps->pps_rpl_info_in_ph_flag) {
2768 (
ctx, rw,
sps,
pps, ¤t->ph_ref_pic_lists));
2770 if (
sps->sps_partition_constraints_override_enabled_flag)
2771 flag(ph_partition_constraints_override_flag);
2773 infer(ph_partition_constraints_override_flag, 0);
2775 ctb_log2_size_y =
sps->sps_log2_ctu_size_minus5 + 5;
2776 min_cb_log2_size_y =
sps->sps_log2_min_luma_coding_block_size_minus2 + 2;
2777 if (current->ph_intra_slice_allowed_flag) {
2778 if (current->ph_partition_constraints_override_flag) {
2779 ue(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2780 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2781 ue(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2782 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2783 if (current->ph_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
2784 min_qt_log2_size_intra_y =
2785 current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2787 ue(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2788 0, (
sps->sps_qtbtt_dual_tree_intra_flag ?
2789 FFMIN(6, ctb_log2_size_y) :
2790 ctb_log2_size_y) - min_qt_log2_size_intra_y);
2791 ue(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2792 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
2794 infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2795 sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2796 infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2797 sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2799 if (
sps->sps_qtbtt_dual_tree_intra_flag) {
2800 ue(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2801 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2802 ue(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2803 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2804 if (
sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
2805 unsigned int min_qt_log2_size_intra_c =
2806 sps->sps_log2_diff_min_qt_min_cb_intra_slice_chroma +
2808 ue(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2809 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2810 ue(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2811 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2813 infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2814 sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2815 infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2816 sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2820 infer(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2821 sps->sps_log2_diff_min_qt_min_cb_intra_slice_luma);
2822 infer(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2823 sps->sps_max_mtt_hierarchy_depth_intra_slice_luma);
2824 infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2825 sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2826 infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2827 sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2828 infer(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2829 sps->sps_log2_diff_min_qt_min_cb_intra_slice_chroma);
2830 infer(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2831 sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma);
2832 infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2833 sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2834 infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2835 sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2838 min_qt_log2_size_intra_y =
2839 current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2841 if (
pps->pps_cu_qp_delta_enabled_flag)
2842 ue(ph_cu_qp_delta_subdiv_intra_slice, 0,
2843 2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2844 current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2846 infer(ph_cu_qp_delta_subdiv_intra_slice, 0);
2848 if (
pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2849 ue(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0,
2850 2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2851 current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2853 infer(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0);
2855 if (current->ph_inter_slice_allowed_flag) {
2856 if (current->ph_partition_constraints_override_flag) {
2857 ue(ph_log2_diff_min_qt_min_cb_inter_slice,
2858 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2859 min_qt_log2_size_inter_y =
2860 current->ph_log2_diff_min_qt_min_cb_inter_slice +
2862 ue(ph_max_mtt_hierarchy_depth_inter_slice, 0,
2863 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2864 if (current->ph_max_mtt_hierarchy_depth_inter_slice != 0) {
2865 ue(ph_log2_diff_max_bt_min_qt_inter_slice,
2866 0, ctb_log2_size_y - min_qt_log2_size_inter_y);
2867 ue(ph_log2_diff_max_tt_min_qt_inter_slice,
2868 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
2871 infer(ph_log2_diff_min_qt_min_cb_inter_slice,
2872 sps->sps_log2_diff_min_qt_min_cb_inter_slice);
2873 min_qt_log2_size_inter_y =
2874 current->ph_log2_diff_min_qt_min_cb_inter_slice +
2876 infer(ph_max_mtt_hierarchy_depth_inter_slice,
2877 sps->sps_max_mtt_hierarchy_depth_inter_slice);
2878 infer(ph_log2_diff_max_bt_min_qt_inter_slice,
2879 sps->sps_log2_diff_max_bt_min_qt_inter_slice);
2880 infer(ph_log2_diff_max_tt_min_qt_inter_slice,
2881 sps->sps_log2_diff_max_tt_min_qt_inter_slice);
2884 if (
pps->pps_cu_qp_delta_enabled_flag)
2885 ue(ph_cu_qp_delta_subdiv_inter_slice, 0,
2886 2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2887 current->ph_max_mtt_hierarchy_depth_inter_slice));
2889 infer(ph_cu_qp_delta_subdiv_inter_slice, 0);
2891 if (
pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2892 ue(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0,
2893 2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2894 current->ph_max_mtt_hierarchy_depth_inter_slice));
2896 infer(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0);
2897 if (
sps->sps_temporal_mvp_enabled_flag) {
2898 flag(ph_temporal_mvp_enabled_flag);
2899 if (current->ph_temporal_mvp_enabled_flag &&
2900 pps->pps_rpl_info_in_ph_flag) {
2901 if (current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0)
2902 flag(ph_collocated_from_l0_flag);
2904 infer(ph_collocated_from_l0_flag, 1);
2905 if ((current->ph_collocated_from_l0_flag &&
2906 current->ph_ref_pic_lists.rpl_ref_list[0].num_ref_entries > 1)
2907 || (!current->ph_collocated_from_l0_flag &&
2908 current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 1)) {
2910 current->ph_collocated_from_l0_flag ? 0 : 1;
2911 ue(ph_collocated_ref_idx, 0,
2912 current->ph_ref_pic_lists.rpl_ref_list[idx].
2913 num_ref_entries - 1);
2915 infer(ph_collocated_ref_idx, 0);
2919 if (
sps->sps_mmvd_fullpel_only_enabled_flag)
2920 flag(ph_mmvd_fullpel_only_flag);
2922 infer(ph_mmvd_fullpel_only_flag, 0);
2923 if (!
pps->pps_rpl_info_in_ph_flag ||
2924 current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0) {
2925 flag(ph_mvd_l1_zero_flag);
2926 if (
sps->sps_bdof_control_present_in_ph_flag) {
2927 flag(ph_bdof_disabled_flag);
2929 if (!
sps->sps_bdof_control_present_in_ph_flag)
2930 infer(ph_bdof_disabled_flag,
2931 1 -
sps->sps_bdof_enabled_flag);
2933 infer(ph_bdof_disabled_flag, 1);
2935 if (
sps->sps_dmvr_control_present_in_ph_flag) {
2936 flag(ph_dmvr_disabled_flag);
2938 if (!
sps->sps_dmvr_control_present_in_ph_flag)
2939 infer(ph_dmvr_disabled_flag,
2940 1 -
sps->sps_dmvr_enabled_flag);
2942 infer(ph_dmvr_disabled_flag, 1);
2945 infer(ph_mvd_l1_zero_flag, 1);
2947 if (
sps->sps_prof_control_present_in_ph_flag)
2948 flag(ph_prof_disabled_flag);
2950 infer(ph_prof_disabled_flag, !
sps->sps_affine_prof_enabled_flag);
2951 if ((
pps->pps_weighted_pred_flag ||
2952 pps->pps_weighted_bipred_flag) &&
pps->pps_wp_info_in_ph_flag) {
2956 uint8_t num_ref_idx_active[2] = { 0, 0 };
2958 (
ctx, rw,
sps,
pps, ¤t->ph_ref_pic_lists,
2959 num_ref_idx_active, ¤t->ph_pred_weight_table));
2963 qp_bd_offset = 6 *
sps->sps_bitdepth_minus8;
2964 if (
pps->pps_qp_delta_info_in_ph_flag)
2965 se(ph_qp_delta, -qp_bd_offset - (26 +
pps->pps_init_qp_minus26),
2966 63 - (26 +
pps->pps_init_qp_minus26));
2968 if (
sps->sps_joint_cbcr_enabled_flag)
2969 flag(ph_joint_cbcr_sign_flag);
2971 infer(ph_joint_cbcr_sign_flag, 0);
2972 if (
sps->sps_sao_enabled_flag &&
pps->pps_sao_info_in_ph_flag) {
2973 flag(ph_sao_luma_enabled_flag);
2974 if (
sps->sps_chroma_format_idc != 0)
2975 flag(ph_sao_chroma_enabled_flag);
2977 infer(ph_sao_chroma_enabled_flag, 0);
2979 infer(ph_sao_luma_enabled_flag, 0);
2980 infer(ph_sao_chroma_enabled_flag, 0);
2983 if (
pps->pps_dbf_info_in_ph_flag)
2984 flag(ph_deblocking_params_present_flag);
2986 infer(ph_deblocking_params_present_flag, 0);
2988 if (current->ph_deblocking_params_present_flag) {
2989 if (!
pps->pps_deblocking_filter_disabled_flag) {
2990 flag(ph_deblocking_filter_disabled_flag);
2991 if (!current->ph_deblocking_filter_disabled_flag) {
2992 se(ph_luma_beta_offset_div2, -12, 12);
2993 se(ph_luma_tc_offset_div2, -12, 12);
2994 if (
pps->pps_chroma_tool_offsets_present_flag) {
2995 se(ph_cb_beta_offset_div2, -12, 12);
2996 se(ph_cb_tc_offset_div2, -12, 12);
2997 se(ph_cr_beta_offset_div2, -12, 12);
2998 se(ph_cr_tc_offset_div2, -12, 12);
3000 infer(ph_cb_beta_offset_div2,
3001 current->ph_luma_beta_offset_div2);
3002 infer(ph_cb_tc_offset_div2,
3003 current->ph_luma_tc_offset_div2);
3004 infer(ph_cr_beta_offset_div2,
3005 current->ph_luma_beta_offset_div2);
3006 infer(ph_cr_tc_offset_div2,
3007 current->ph_luma_tc_offset_div2);
3011 infer(ph_deblocking_filter_disabled_flag, 0);
3014 infer(ph_deblocking_filter_disabled_flag,
pps->pps_deblocking_filter_disabled_flag);
3015 if (!current->ph_deblocking_filter_disabled_flag) {
3016 infer(ph_luma_beta_offset_div2,
pps->pps_luma_beta_offset_div2);
3017 infer(ph_luma_tc_offset_div2,
pps->pps_luma_tc_offset_div2);
3018 infer(ph_cb_beta_offset_div2,
pps->pps_cb_beta_offset_div2);
3019 infer(ph_cb_tc_offset_div2,
pps->pps_cb_tc_offset_div2);
3020 infer(ph_cr_beta_offset_div2,
pps->pps_cr_beta_offset_div2);
3021 infer(ph_cr_tc_offset_div2,
pps->pps_cr_tc_offset_div2);
3025 if (
pps->pps_picture_header_extension_present_flag) {
3026 ue(ph_extension_length, 0, 256);
3027 for (
i = 0;
i < current->ph_extension_length;
i++)
3028 us(8, ph_extension_data_byte[
i], 0x00, 0xff, 1,
i);
3039 HEADER(
"Picture Header");
3056 uint8_t nal_unit_type, qp_bd_offset;
3057 uint16_t num_slices_in_subpic;
3063 flag(sh_picture_header_in_slice_header_flag);
3064 if (current->sh_picture_header_in_slice_header_flag) {
3067 ph = ¤t->sh_picture_header;
3072 "Picture header not available.\n");
3077 pps = h266->
pps[
ph->ph_pic_parameter_set_id];
3080 ph->ph_pic_parameter_set_id);
3083 sps = h266->
sps[
pps->pps_seq_parameter_set_id];
3086 pps->pps_seq_parameter_set_id);
3090 if (
sps->sps_subpic_info_present_flag) {
3091 ub(
sps->sps_subpic_id_len_minus1 + 1, sh_subpic_id);
3092 for (
i = 0;
i <=
sps->sps_num_subpics_minus1;
i++) {
3093 if (
pps->sub_pic_id_val[
i] == current->sh_subpic_id) {
3094 current->curr_subpic_idx =
i;
3098 if (
i >
sps->sps_num_subpics_minus1) {
3103 current->curr_subpic_idx = 0;
3106 num_slices_in_subpic =
pps->num_slices_in_subpic[current->curr_subpic_idx];
3108 if ((
pps->pps_rect_slice_flag && num_slices_in_subpic > 1) ||
3109 (!
pps->pps_rect_slice_flag &&
pps->num_tiles_in_pic > 1)) {
3111 if (!
pps->pps_rect_slice_flag) {
3113 max =
pps->num_tiles_in_pic - 1;
3116 max = num_slices_in_subpic - 1;
3123 for (
i = 0;
i <
sps->sps_num_extra_sh_bytes * 8;
i++) {
3124 if (
sps->sps_extra_sh_bit_present_flag[
i])
3128 if (!
pps->pps_rect_slice_flag &&
3129 pps->num_tiles_in_pic - current->sh_slice_address > 1)
3130 ue(sh_num_tiles_in_slice_minus1, 0,
pps->num_tiles_in_pic - 1);
3132 infer(sh_num_tiles_in_slice_minus1, 0);
3134 if (
ph->ph_inter_slice_allowed_flag)
3135 ue(sh_slice_type, 0, 2);
3137 infer(sh_slice_type, 2);
3139 nal_unit_type = current->nal_unit_header.nal_unit_type;
3142 flag(sh_no_output_of_prior_pics_flag);
3144 if (
sps->sps_alf_enabled_flag) {
3145 if (!
pps->pps_alf_info_in_ph_flag) {
3146 flag(sh_alf_enabled_flag);
3147 if (current->sh_alf_enabled_flag) {
3148 ub(3, sh_num_alf_aps_ids_luma);
3149 for (
i = 0;
i < current->sh_num_alf_aps_ids_luma;
i++)
3150 ubs(3, sh_alf_aps_id_luma[
i], 1,
i);
3152 if (
sps->sps_chroma_format_idc != 0) {
3153 flag(sh_alf_cb_enabled_flag);
3154 flag(sh_alf_cr_enabled_flag);
3156 if (current->sh_alf_cb_enabled_flag ||
3157 current->sh_alf_cr_enabled_flag) {
3158 ub(3, sh_alf_aps_id_chroma);
3161 if (
sps->sps_ccalf_enabled_flag) {
3162 flag(sh_alf_cc_cb_enabled_flag);
3163 if (current->sh_alf_cc_cb_enabled_flag)
3164 ub(3, sh_alf_cc_cb_aps_id);
3166 flag(sh_alf_cc_cr_enabled_flag);
3167 if (current->sh_alf_cc_cr_enabled_flag)
3168 ub(3, sh_alf_cc_cr_aps_id);
3172 infer(sh_alf_enabled_flag,
ph->ph_alf_enabled_flag);
3173 if (current->sh_alf_enabled_flag) {
3174 infer(sh_num_alf_aps_ids_luma,
ph->ph_num_alf_aps_ids_luma);
3175 for (
i = 0;
i < current->sh_num_alf_aps_ids_luma;
i++)
3176 infer(sh_alf_aps_id_luma[
i],
ph->ph_alf_aps_id_luma[
i]);
3178 infer(sh_alf_cb_enabled_flag,
ph->ph_alf_cb_enabled_flag);
3179 infer(sh_alf_cr_enabled_flag,
ph->ph_alf_cr_enabled_flag);
3180 if (current->sh_alf_cb_enabled_flag ||current->sh_alf_cr_enabled_flag)
3181 infer(sh_alf_aps_id_chroma,
ph->ph_alf_aps_id_chroma);
3183 if (
sps->sps_ccalf_enabled_flag) {
3184 infer(sh_alf_cc_cb_enabled_flag,
ph->ph_alf_cc_cb_enabled_flag);
3185 if (current->sh_alf_cc_cb_enabled_flag)
3186 infer(sh_alf_cc_cb_aps_id,
ph->ph_alf_cc_cb_aps_id);
3188 infer(sh_alf_cc_cr_enabled_flag,
ph->ph_alf_cc_cr_enabled_flag);
3189 if (current->sh_alf_cc_cr_enabled_flag)
3190 infer(sh_alf_cc_cr_aps_id,
ph->ph_alf_cc_cr_aps_id);
3196 if (current->sh_picture_header_in_slice_header_flag) {
3197 infer(sh_lmcs_used_flag,
ph->ph_lmcs_enabled_flag);
3198 infer(sh_explicit_scaling_list_used_flag,
3199 ph->ph_explicit_scaling_list_enabled_flag);
3201 if (
ph->ph_lmcs_enabled_flag)
3202 flag(sh_lmcs_used_flag);
3204 infer(sh_lmcs_used_flag, 0);
3206 if (
ph->ph_explicit_scaling_list_enabled_flag)
3207 flag(sh_explicit_scaling_list_used_flag);
3209 infer(sh_explicit_scaling_list_used_flag, 0);
3212 if (!
pps->pps_rpl_info_in_ph_flag &&
3216 (
ctx, rw,
sps,
pps, ¤t->sh_ref_pic_lists));
3225 flag(sh_num_ref_idx_active_override_flag);
3226 if (current->sh_num_ref_idx_active_override_flag) {
3230 ues(sh_num_ref_idx_active_minus1[
i], 0, 14, 1,
i);
3232 infer(sh_num_ref_idx_active_minus1[
i], 0);
3235 infer(sh_num_ref_idx_active_override_flag, 1);
3238 for (
i = 0;
i < 2;
i++) {
3241 if (current->sh_num_ref_idx_active_override_flag) {
3242 current->num_ref_idx_active[
i] = current->sh_num_ref_idx_active_minus1[
i] + 1;
3244 current->num_ref_idx_active[
i] =
3246 pps->pps_num_ref_idx_default_active_minus1[
i] + 1);
3249 current->num_ref_idx_active[
i] = 0;
3254 if (
pps->pps_cabac_init_present_flag)
3255 flag(sh_cabac_init_flag);
3257 infer(sh_cabac_init_flag, 0);
3258 if (
ph->ph_temporal_mvp_enabled_flag) {
3259 if (!
pps->pps_rpl_info_in_ph_flag) {
3261 flag(sh_collocated_from_l0_flag);
3263 infer(sh_collocated_from_l0_flag, 1);
3264 if ((current->sh_collocated_from_l0_flag &&
3265 current->num_ref_idx_active[0] > 1) ||
3266 (!current->sh_collocated_from_l0_flag &&
3267 current->num_ref_idx_active[1] > 1)) {
3268 unsigned int idx = current->sh_collocated_from_l0_flag ? 0 : 1;
3269 ue(sh_collocated_ref_idx, 0, current->num_ref_idx_active[idx] - 1);
3271 infer(sh_collocated_ref_idx, 0);
3275 infer(sh_collocated_from_l0_flag,
ph->ph_collocated_from_l0_flag);
3277 infer(sh_collocated_from_l0_flag, 1);
3278 infer(sh_collocated_ref_idx,
ph->ph_collocated_ref_idx);
3281 if (!
pps->pps_wp_info_in_ph_flag &&
3282 ((
pps->pps_weighted_pred_flag &&
3284 (
pps->pps_weighted_bipred_flag &&
3287 current->num_ref_idx_active,
3288 ¤t->sh_pred_weight_table));
3291 qp_bd_offset = 6 *
sps->sps_bitdepth_minus8;
3292 if (!
pps->pps_qp_delta_info_in_ph_flag)
3293 se(sh_qp_delta, -qp_bd_offset - (26 +
pps->pps_init_qp_minus26),
3294 63 - (26 +
pps->pps_init_qp_minus26));
3295 if (
pps->pps_slice_chroma_qp_offsets_present_flag) {
3298 se(sh_cb_qp_offset, -12, 12);
3299 off =
pps->pps_cb_qp_offset + current->sh_cb_qp_offset;
3300 if (off < -12 || off > 12) {
3302 "pps_cb_qp_offset + sh_cb_qp_offset (%d) not in range [-12, 12].\n",
3307 se(sh_cr_qp_offset, -12, 12);
3308 off =
pps->pps_cr_qp_offset + current->sh_cr_qp_offset;
3309 if (off < -12 || off > 12) {
3311 "pps_cr_qp_offset + sh_cr_qp_offset (%d) not in range [-12, 12].\n",
3316 if (
sps->sps_joint_cbcr_enabled_flag) {
3317 se(sh_joint_cbcr_qp_offset, -12, 12);
3319 pps->pps_joint_cbcr_qp_offset_value +
3320 current->sh_joint_cbcr_qp_offset;
3321 if (off < -12 || off > 12) {
3323 "pps_joint_cbcr_qp_offset_value + sh_joint_cbcr_qp_offset (%d)"
3324 "not in range [-12, 12]. \n", off);
3328 infer(sh_joint_cbcr_qp_offset, 0);
3331 infer(sh_cb_qp_offset, 0);
3332 infer(sh_cr_qp_offset, 0);
3333 infer(sh_joint_cbcr_qp_offset, 0);
3335 if (
pps->pps_cu_chroma_qp_offset_list_enabled_flag)
3336 flag(sh_cu_chroma_qp_offset_enabled_flag);
3338 infer(sh_cu_chroma_qp_offset_enabled_flag, 0);
3339 if (
sps->sps_sao_enabled_flag && !
pps->pps_sao_info_in_ph_flag) {
3340 flag(sh_sao_luma_used_flag);
3341 if (
sps->sps_chroma_format_idc != 0)
3342 flag(sh_sao_chroma_used_flag);
3344 infer(sh_sao_chroma_used_flag,
ph->ph_sao_chroma_enabled_flag);
3346 infer(sh_sao_luma_used_flag,
ph->ph_sao_luma_enabled_flag);
3347 infer(sh_sao_chroma_used_flag,
ph->ph_sao_chroma_enabled_flag);
3350 if (
pps->pps_deblocking_filter_override_enabled_flag &&
3351 !
pps->pps_dbf_info_in_ph_flag)
3352 flag(sh_deblocking_params_present_flag);
3354 infer(sh_deblocking_params_present_flag, 0);
3355 if (current->sh_deblocking_params_present_flag) {
3356 if (!
pps->pps_deblocking_filter_disabled_flag)
3357 flag(sh_deblocking_filter_disabled_flag);
3359 infer(sh_deblocking_filter_disabled_flag, 0);
3360 if (!current->sh_deblocking_filter_disabled_flag) {
3361 se(sh_luma_beta_offset_div2, -12, 12);
3362 se(sh_luma_tc_offset_div2, -12, 12);
3363 if (
pps->pps_chroma_tool_offsets_present_flag) {
3364 se(sh_cb_beta_offset_div2, -12, 12);
3365 se(sh_cb_tc_offset_div2, -12, 12);
3366 se(sh_cr_beta_offset_div2, -12, 12);
3367 se(sh_cr_tc_offset_div2, -12, 12);
3369 infer(sh_cb_beta_offset_div2,
3370 current->sh_luma_beta_offset_div2);
3371 infer(sh_cb_tc_offset_div2, current->sh_luma_tc_offset_div2);
3372 infer(sh_cr_beta_offset_div2,
3373 current->sh_luma_beta_offset_div2);
3374 infer(sh_cr_tc_offset_div2, current->sh_luma_tc_offset_div2);
3378 infer(sh_deblocking_filter_disabled_flag,
ph->ph_deblocking_filter_disabled_flag);
3379 if (!current->sh_deblocking_filter_disabled_flag) {
3380 infer(sh_luma_beta_offset_div2,
ph->ph_luma_beta_offset_div2);
3381 infer(sh_luma_tc_offset_div2,
ph->ph_luma_tc_offset_div2);
3382 infer(sh_cb_beta_offset_div2,
ph->ph_cb_beta_offset_div2);
3383 infer(sh_cb_tc_offset_div2,
ph->ph_cb_tc_offset_div2);
3384 infer(sh_cr_beta_offset_div2,
ph->ph_cr_beta_offset_div2);
3385 infer(sh_cr_tc_offset_div2,
ph->ph_cr_tc_offset_div2);
3389 if (
sps->sps_dep_quant_enabled_flag)
3390 flag(sh_dep_quant_used_flag);
3392 infer(sh_dep_quant_used_flag, 0);
3394 if (
sps->sps_sign_data_hiding_enabled_flag &&
3395 !current->sh_dep_quant_used_flag)
3396 flag(sh_sign_data_hiding_used_flag);
3398 infer(sh_sign_data_hiding_used_flag, 0);
3400 if (
sps->sps_transform_skip_enabled_flag &&
3401 !current->sh_dep_quant_used_flag &&
3402 !current->sh_sign_data_hiding_used_flag)
3403 flag(sh_ts_residual_coding_disabled_flag);
3405 infer(sh_ts_residual_coding_disabled_flag, 0);
3407 if (!current->sh_ts_residual_coding_disabled_flag &&
3408 sps->sps_ts_residual_coding_rice_present_in_sh_flag)
3409 ub(3, sh_ts_residual_coding_rice_idx_minus1);
3411 infer(sh_ts_residual_coding_rice_idx_minus1, 0);
3413 if (
sps->sps_reverse_last_sig_coeff_enabled_flag)
3414 flag(sh_reverse_last_sig_coeff_flag);
3416 infer(sh_reverse_last_sig_coeff_flag, 0);
3418 if (
pps->pps_slice_header_extension_present_flag) {
3419 ue(sh_slice_header_extension_length, 0, 256);
3420 for (
i = 0;
i < current->sh_slice_header_extension_length;
i++)
3421 us(8, sh_slice_header_extension_data_byte[
i], 0x00, 0xff, 1,
i);
3424 current->num_entry_points = 0;
3425 if (
sps->sps_entry_point_offsets_present_flag) {
3426 uint8_t entropy_sync =
sps->sps_entropy_coding_sync_enabled_flag;
3428 if (
pps->pps_rect_slice_flag) {
3430 int slice_idx = current->sh_slice_address;
3431 for (
i = 0;
i < current->curr_subpic_idx;
i++) {
3432 slice_idx +=
pps->num_slices_in_subpic[
i];
3435 pps->pps_slice_width_in_tiles_minus1[slice_idx] + 1;
3438 height =
pps->slice_height_in_ctus[slice_idx];
3440 height =
pps->pps_slice_height_in_tiles_minus1[slice_idx] + 1;
3442 current->num_entry_points = width_in_tiles *
height;
3446 for (tile_idx = current->sh_slice_address;
3448 current->sh_slice_address +
3449 current->sh_num_tiles_in_slice_minus1; tile_idx++) {
3450 tile_y = tile_idx /
pps->num_tile_rows;
3452 current->num_entry_points += (entropy_sync ?
height : 1);
3455 current->num_entry_points--;
3458 "%" PRIu32
".\n", current->num_entry_points);
3461 if (current->num_entry_points > 0) {
3462 ue(sh_entry_offset_len_minus1, 0, 31);
3463 for (
i = 0;
i < current->num_entry_points;
i++) {
3464 ubs(current->sh_entry_offset_len_minus1 + 1,
3465 sh_entry_point_offset_minus1[
i], 1,
i);
3480 HEADER(
"Prefix Supplemental Enhancement Information");
3482 HEADER(
"Suffix Supplemental Enhancement Information");