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);
802 for (
i = 0;
i <= current->vps_max_layers_minus1;
i++) {
803 for (j = 0; j <= current->vps_max_layers_minus1; j++) {
804 dependency_flag[
i][j] = current->vps_direct_ref_layer_flag[
i][j];
805 for (k = 0; k <
i; k++) {
806 if (current->vps_direct_ref_layer_flag[
i][k] &&
807 dependency_flag[k][j])
808 dependency_flag[
i][j] = 1;
812 for (
i = 0;
i <= current->vps_max_layers_minus1;
i++) {
814 for (j = 0,
r = 0; j <= current->vps_max_layers_minus1; j++) {
815 if (dependency_flag[
i][j])
816 reference_layer_idx[
i][
r++] = j;
818 num_ref_layers[
i] =
r;
822 num_output_layers_in_ols[0] = 1;
823 num_sub_layers_in_layer_in_ols[0][0] =
824 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[0]] + 1;
825 for (
i = 1;
i < total_num_olss;
i++) {
826 if (ols_mode_idc == 4 || ols_mode_idc == 0) {
827 num_output_layers_in_ols[
i] = 1;
828 if (current->vps_each_layer_is_an_ols_flag) {
829 num_sub_layers_in_layer_in_ols[
i][0] =
830 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[
i]] + 1;
832 num_sub_layers_in_layer_in_ols[
i][
i] =
833 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[
i]] + 1;
834 for (k =
i - 1; k >= 0; k--) {
835 num_sub_layers_in_layer_in_ols[
i][k] = 0;
836 for (m = k + 1; m <=
i; m++) {
837 uint8_t max_sublayer_needed =
838 FFMIN(num_sub_layers_in_layer_in_ols[
i][m],
839 current->vps_max_tid_il_ref_pics_plus1[m][k]);
840 if (current->vps_direct_ref_layer_flag[m][k] &&
841 num_sub_layers_in_layer_in_ols[
i][k] < max_sublayer_needed)
842 num_sub_layers_in_layer_in_ols[
i][k] = max_sublayer_needed;
846 }
else if (current->vps_ols_mode_idc == 1) {
847 num_output_layers_in_ols[
i] =
i + 1;
848 for (j = 0; j < num_output_layers_in_ols[
i]; j++) {
849 num_sub_layers_in_layer_in_ols[
i][j] =
850 current->vps_ptl_max_tid[current->vps_ols_ptl_idx[
i]] + 1;
852 }
else if (current->vps_ols_mode_idc == 2) {
853 uint8_t highest_included_layer = 0;
854 for (j = 0; j <= current->vps_max_layers_minus1; j++) {
855 layer_included_in_ols_flag[
i][j] = 0;
856 num_sub_layers_in_layer_in_ols[
i][j] = 0;
858 for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++) {
859 if (current->vps_ols_output_layer_flag[
i][k]) {
860 layer_included_in_ols_flag[
i][k] = 1;
861 highest_included_layer = k;
862 output_layer_idx[
i][j] = k;
863 num_sub_layers_in_layer_in_ols[
i][k] =
864 current->vps_ptl_max_tid[current->
865 vps_ols_ptl_idx[
i]] + 1;
869 num_output_layers_in_ols[
i] = j;
870 for (j = 0; j < num_output_layers_in_ols[
i]; j++) {
871 int idx = output_layer_idx[
i][j];
872 for (k = 0; k < num_ref_layers[idx]; k++) {
873 if (!layer_included_in_ols_flag[
i][reference_layer_idx[idx][k]])
874 layer_included_in_ols_flag[
i][reference_layer_idx[idx][k]] = 1;
877 for (k = highest_included_layer - 1; k >= 0; k--) {
878 if (layer_included_in_ols_flag[
i][k] &&
879 !current->vps_ols_output_layer_flag[
i][k]) {
880 for (m = k + 1; m <= highest_included_layer; m++) {
881 uint8_t max_sublayer_needed =
882 FFMIN(num_sub_layers_in_layer_in_ols[
i][m],
883 current->vps_max_tid_il_ref_pics_plus1[m][k]);
884 if (current->vps_direct_ref_layer_flag[m][k] &&
885 layer_included_in_ols_flag[
i][m] &&
886 num_sub_layers_in_layer_in_ols[
i][k] <
888 num_sub_layers_in_layer_in_ols[
i][k] =
894 if (!num_output_layers_in_ols[
i])
897 for (
i = 1;
i < total_num_olss;
i++) {
898 int num_layers_in_ols = 0;
899 if (current->vps_each_layer_is_an_ols_flag) {
900 num_layers_in_ols = 1;
901 }
else if (current->vps_ols_mode_idc == 0 ||
902 current->vps_ols_mode_idc == 1) {
903 num_layers_in_ols =
i + 1;
904 }
else if (current->vps_ols_mode_idc == 2) {
905 for (k = 0, j = 0; k <= current->vps_max_layers_minus1; k++)
906 if (layer_included_in_ols_flag[
i][k])
908 num_layers_in_ols = j;
910 if (num_layers_in_ols > 1) {
911 num_multi_layer_olss++;
914 if (!current->vps_each_layer_is_an_ols_flag && num_multi_layer_olss == 0)
918 for (
i = 0;
i <= current->vps_num_ptls_minus1;
i++) {
920 flags(vps_pt_present_flag[
i], 1,
i);
922 infer(vps_pt_present_flag[
i], 1);
924 if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
925 us(3, vps_ptl_max_tid[
i], 0, current->vps_max_sublayers_minus1, 1,
i);
927 infer(vps_ptl_max_tid[
i], current->vps_max_sublayers_minus1);
930 fixed(1, vps_ptl_alignment_zero_bit, 0);
931 for (
i = 0;
i <= current->vps_num_ptls_minus1;
i++) {
933 current->vps_profile_tier_level +
i,
934 current->vps_pt_present_flag[
i],
935 current->vps_ptl_max_tid[
i]));
937 for (
i = 0;
i < total_num_olss;
i++) {
938 if (current->vps_num_ptls_minus1 > 0 &&
939 current->vps_num_ptls_minus1 + 1 != total_num_olss) {
940 us(8, vps_ols_ptl_idx[
i], 0, current->vps_num_ptls_minus1, 1,
i);
941 }
else if (current->vps_num_ptls_minus1 == 0) {
942 infer(vps_ols_ptl_idx[
i], 0);
948 if (!current->vps_each_layer_is_an_ols_flag) {
949 uint16_t vps_num_dpb_params;
950 ue(vps_num_dpb_params_minus1, 0, num_multi_layer_olss - 1);
951 if (current->vps_each_layer_is_an_ols_flag)
952 vps_num_dpb_params = 0;
954 vps_num_dpb_params = current->vps_num_dpb_params_minus1 + 1;
956 if (current->vps_max_sublayers_minus1 > 0)
957 flag(vps_sublayer_dpb_params_present_flag);
959 infer(vps_sublayer_dpb_params_present_flag, 0);
961 for (
i = 0;
i < vps_num_dpb_params;
i++) {
962 if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
963 us(3, vps_dpb_max_tid[
i], 0, current->vps_max_sublayers_minus1,
966 infer(vps_dpb_max_tid[
i], current->vps_max_sublayers_minus1);
968 current->vps_dpb_max_tid[
i],
970 vps_sublayer_dpb_params_present_flag));
972 for (
i = 0;
i < num_multi_layer_olss;
i++) {
973 ues(vps_ols_dpb_pic_width[
i], 0, UINT16_MAX, 1,
i);
974 ues(vps_ols_dpb_pic_height[
i], 0, UINT16_MAX, 1,
i);
975 ubs(2, vps_ols_dpb_chroma_format[
i], 1,
i);
976 ues(vps_ols_dpb_bitdepth_minus8[
i], 0, 8, 1,
i);
977 if (vps_num_dpb_params > 1
978 && vps_num_dpb_params != num_multi_layer_olss)
979 ues(vps_ols_dpb_params_idx[
i], 0, vps_num_dpb_params - 1, 1,
i);
980 else if (vps_num_dpb_params == 1)
981 infer(vps_ols_dpb_params_idx[
i], 0);
983 infer(vps_ols_dpb_params_idx[
i],
i);
985 flag(vps_timing_hrd_params_present_flag);
986 if (current->vps_timing_hrd_params_present_flag) {
989 vps_general_timing_hrd_parameters));
990 if (current->vps_max_sublayers_minus1 > 0)
991 flag(vps_sublayer_cpb_params_present_flag);
993 infer(vps_sublayer_cpb_params_present_flag, 0);
994 ue(vps_num_ols_timing_hrd_params_minus1, 0,
995 num_multi_layer_olss - 1);
996 for (
i = 0;
i <= current->vps_num_ols_timing_hrd_params_minus1;
i++) {
997 uint8_t first_sublayer;
998 if (!current->vps_default_ptl_dpb_hrd_max_tid_flag)
999 us(3, vps_hrd_max_tid[
i], 0,
1000 current->vps_max_sublayers_minus1, 1,
i);
1002 infer(vps_hrd_max_tid[
i],
1003 current->vps_max_sublayers_minus1);
1004 first_sublayer = current->vps_sublayer_cpb_params_present_flag ?
1005 0 : current->vps_hrd_max_tid[
i];
1007 (
ctx, rw, ¤t->vps_ols_timing_hrd_parameters,
1008 first_sublayer, current->vps_max_sublayers_minus1,
1009 ¤t->vps_general_timing_hrd_parameters));
1012 if (current->vps_num_ols_timing_hrd_params_minus1 > 0 &&
1013 current->vps_num_ols_timing_hrd_params_minus1 + 1 !=
1014 num_multi_layer_olss) {
1015 for (
i = 0;
i < num_multi_layer_olss;
i++) {
1016 ues(vps_ols_timing_hrd_idx[
i], 0,
1017 current->vps_num_ols_timing_hrd_params_minus1, 1,
i);
1019 }
else if (current->vps_num_ols_timing_hrd_params_minus1 == 0) {
1020 for (
i = 0;
i < num_multi_layer_olss;
i++)
1021 infer(vps_ols_timing_hrd_idx[
i], 0);
1023 for (
i = 0;
i < num_multi_layer_olss;
i++)
1024 infer(vps_ols_timing_hrd_idx[
i],
i);
1029 flag(vps_extension_flag);
1030 if (current->vps_extension_flag)
1042 flag(sps_extended_precision_flag);
1043 if (current->sps_transform_skip_enabled_flag)
1044 flag(sps_ts_residual_coding_rice_present_in_sh_flag);
1046 infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1047 flag(sps_rrc_rice_extension_flag);
1048 flag(sps_persistent_rice_adaptation_enabled_flag);
1049 flag(sps_reverse_last_sig_coeff_enabled_flag);
1059 unsigned int ctb_log2_size_y, min_cb_log2_size_y,
1060 min_qt_log2_size_intra_y, min_qt_log2_size_inter_y,
1061 ctb_size_y, max_num_merge_cand, tmp_width_val, tmp_height_val;
1062 uint8_t qp_bd_offset;
1064 static const uint8_t h266_sub_width_c[] = {
1067 static const uint8_t h266_sub_height_c[] = {
1071 HEADER(
"Sequence Parameter Set");
1076 ub(4, sps_seq_parameter_set_id);
1077 ub(4, sps_video_parameter_set_id);
1078 if (current->sps_video_parameter_set_id == 0 && !h266->
vps[0]) {
1082 vps->vps_max_layers_minus1 = 0;
1083 vps->vps_independent_layer_flag[0] = 1;
1084 vps->vps_layer_id[0] = current->nal_unit_header.nuh_layer_id;
1089 u(2, sps_chroma_format_idc, 0, 3);
1090 u(2, sps_log2_ctu_size_minus5, 0, 3);
1091 ctb_log2_size_y = current->sps_log2_ctu_size_minus5 + 5;
1092 ctb_size_y = 1 << ctb_log2_size_y;
1094 flag(sps_ptl_dpb_hrd_params_present_flag);
1095 if (current->sps_ptl_dpb_hrd_params_present_flag) {
1097 1, current->sps_max_sublayers_minus1));
1099 flag(sps_gdr_enabled_flag);
1100 flag(sps_ref_pic_resampling_enabled_flag);
1101 if (current->sps_ref_pic_resampling_enabled_flag)
1102 flag(sps_res_change_in_clvs_allowed_flag);
1104 infer(sps_res_change_in_clvs_allowed_flag, 0);
1109 flag(sps_conformance_window_flag);
1110 if (current->sps_conformance_window_flag) {
1111 uint8_t sub_width_c = h266_sub_width_c[current->sps_chroma_format_idc];
1112 uint8_t sub_height_c = h266_sub_height_c[current->sps_chroma_format_idc];
1113 uint16_t
width = current->sps_pic_width_max_in_luma_samples / sub_width_c;
1114 uint16_t
height = current->sps_pic_height_max_in_luma_samples / sub_height_c;
1115 ue(sps_conf_win_left_offset, 0,
width);
1116 ue(sps_conf_win_right_offset, 0,
width - current->sps_conf_win_left_offset);
1117 ue(sps_conf_win_top_offset, 0,
height);
1118 ue(sps_conf_win_bottom_offset, 0,
height - current->sps_conf_win_top_offset);
1120 infer(sps_conf_win_left_offset, 0);
1121 infer(sps_conf_win_right_offset, 0);
1122 infer(sps_conf_win_top_offset, 0);
1123 infer(sps_conf_win_bottom_offset, 0);
1126 tmp_width_val =
AV_CEIL_RSHIFT(current->sps_pic_width_max_in_luma_samples,
1128 tmp_height_val =
AV_CEIL_RSHIFT(current->sps_pic_height_max_in_luma_samples,
1131 flag(sps_subpic_info_present_flag);
1132 if (current->sps_subpic_info_present_flag) {
1134 if (current->sps_num_subpics_minus1 > 0) {
1135 flag(sps_independent_subpics_flag);
1136 flag(sps_subpic_same_size_flag);
1139 if (current->sps_num_subpics_minus1 > 0) {
1142 infer(sps_subpic_ctu_top_left_x[0], 0);
1143 infer(sps_subpic_ctu_top_left_y[0], 0);
1144 if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1145 ubs(wlen, sps_subpic_width_minus1[0], 1, 0);
1147 infer(sps_subpic_width_minus1[0], tmp_width_val - 1);
1148 if (current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1149 ubs(hlen, sps_subpic_height_minus1[0], 1, 0);
1151 infer(sps_subpic_height_minus1[0], tmp_height_val - 1);
1152 if (!current->sps_independent_subpics_flag) {
1153 flags(sps_subpic_treated_as_pic_flag[0], 1, 0);
1154 flags(sps_loop_filter_across_subpic_enabled_flag[0], 1, 0);
1156 infer(sps_subpic_treated_as_pic_flag[0], 1);
1157 infer(sps_loop_filter_across_subpic_enabled_flag[0], 1);
1159 for (
i = 1;
i <= current->sps_num_subpics_minus1;
i++) {
1160 if (!current->sps_subpic_same_size_flag) {
1161 if (current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1162 ubs(wlen, sps_subpic_ctu_top_left_x[
i], 1,
i);
1164 infer(sps_subpic_ctu_top_left_x[
i], 0);
1165 if (current->sps_pic_height_max_in_luma_samples >
1167 ubs(hlen, sps_subpic_ctu_top_left_y[
i], 1,
i);
1169 infer(sps_subpic_ctu_top_left_y[
i], 0);
1170 if (i < current->sps_num_subpics_minus1 &&
1171 current->sps_pic_width_max_in_luma_samples >
1173 ubs(wlen, sps_subpic_width_minus1[
i], 1,
i);
1175 infer(sps_subpic_width_minus1[
i],
1177 current->sps_subpic_ctu_top_left_x[
i] - 1);
1179 if (i < current->sps_num_subpics_minus1 &&
1180 current->sps_pic_height_max_in_luma_samples >
1182 ubs(hlen, sps_subpic_height_minus1[
i], 1,
i);
1184 infer(sps_subpic_height_minus1[
i],
1186 current->sps_subpic_ctu_top_left_y[
i] - 1);
1189 int num_subpic_cols = tmp_width_val /
1190 (current->sps_subpic_width_minus1[0] + 1);
1191 if (tmp_width_val % (current->sps_subpic_width_minus1[0] + 1) ||
1192 tmp_height_val % (current->sps_subpic_width_minus1[0] + 1) ||
1193 current->sps_num_subpics_minus1 !=
1194 (num_subpic_cols * tmp_height_val /
1195 (current->sps_subpic_height_minus1[0] + 1) - 1))
1197 infer(sps_subpic_ctu_top_left_x[
i],
1198 (
i % num_subpic_cols) *
1199 (current->sps_subpic_width_minus1[0] + 1));
1200 infer(sps_subpic_ctu_top_left_y[
i],
1201 (
i / num_subpic_cols) *
1202 (current->sps_subpic_height_minus1[0] + 1));
1203 infer(sps_subpic_width_minus1[
i],
1204 current->sps_subpic_width_minus1[0]);
1205 infer(sps_subpic_height_minus1[
i],
1206 current->sps_subpic_height_minus1[0]);
1208 if (!current->sps_independent_subpics_flag) {
1209 flags(sps_subpic_treated_as_pic_flag[
i], 1,
i);
1210 flags(sps_loop_filter_across_subpic_enabled_flag[
i], 1,
i);
1212 infer(sps_subpic_treated_as_pic_flag[
i], 1);
1213 infer(sps_loop_filter_across_subpic_enabled_flag[
i], 0);
1217 infer(sps_subpic_ctu_top_left_x[0], 0);
1218 infer(sps_subpic_ctu_top_left_y[0], 0);
1219 infer(sps_subpic_width_minus1[0], tmp_width_val - 1);
1220 infer(sps_subpic_height_minus1[0], tmp_height_val - 1);
1222 ue(sps_subpic_id_len_minus1, 0, 15);
1223 if ((1 << (current->sps_subpic_id_len_minus1 + 1)) <
1224 current->sps_num_subpics_minus1 + 1) {
1226 "sps_subpic_id_len_minus1(%d) is too small\n",
1227 current->sps_subpic_id_len_minus1);
1230 flag(sps_subpic_id_mapping_explicitly_signalled_flag);
1231 if (current->sps_subpic_id_mapping_explicitly_signalled_flag) {
1232 flag(sps_subpic_id_mapping_present_flag);
1233 if (current->sps_subpic_id_mapping_present_flag) {
1234 for (
i = 0;
i <= current->sps_num_subpics_minus1;
i++) {
1235 ubs(current->sps_subpic_id_len_minus1 + 1,
1236 sps_subpic_id[
i], 1,
i);
1241 infer(sps_num_subpics_minus1, 0);
1242 infer(sps_independent_subpics_flag, 1);
1243 infer(sps_subpic_same_size_flag, 0);
1244 infer(sps_subpic_id_mapping_explicitly_signalled_flag, 0);
1245 infer(sps_subpic_ctu_top_left_x[0], 0);
1246 infer(sps_subpic_ctu_top_left_y[0], 0);
1247 infer(sps_subpic_width_minus1[0], tmp_width_val - 1);
1248 infer(sps_subpic_height_minus1[0], tmp_height_val - 1);
1252 ue(sps_bitdepth_minus8, 0, 8);
1253 qp_bd_offset = 6 * current->sps_bitdepth_minus8;
1255 flag(sps_entropy_coding_sync_enabled_flag);
1256 flag(sps_entry_point_offsets_present_flag);
1258 u(4, sps_log2_max_pic_order_cnt_lsb_minus4, 0, 12);
1259 flag(sps_poc_msb_cycle_flag);
1260 if (current->sps_poc_msb_cycle_flag)
1261 ue(sps_poc_msb_cycle_len_minus1,
1262 0, 32 - current->sps_log2_max_pic_order_cnt_lsb_minus4 - 5);
1264 u(2, sps_num_extra_ph_bytes, 0, 2);
1265 for (
i = 0;
i < (current->sps_num_extra_ph_bytes * 8);
i++) {
1266 flags(sps_extra_ph_bit_present_flag[
i], 1,
i);
1269 u(2, sps_num_extra_sh_bytes, 0, 2);
1270 for (
i = 0;
i < (current->sps_num_extra_sh_bytes * 8);
i++) {
1271 flags(sps_extra_sh_bit_present_flag[
i], 1,
i);
1274 if (current->sps_ptl_dpb_hrd_params_present_flag) {
1275 if (current->sps_max_sublayers_minus1 > 0)
1276 flag(sps_sublayer_dpb_params_flag);
1278 infer(sps_sublayer_dpb_params_flag, 0);
1280 current->sps_max_sublayers_minus1,
1281 current->sps_sublayer_dpb_params_flag));
1284 ue(sps_log2_min_luma_coding_block_size_minus2,
1285 0,
FFMIN(4, current->sps_log2_ctu_size_minus5 + 3));
1286 min_cb_log2_size_y =
1287 current->sps_log2_min_luma_coding_block_size_minus2 + 2;
1289 flag(sps_partition_constraints_override_enabled_flag);
1291 ue(sps_log2_diff_min_qt_min_cb_intra_slice_luma,
1292 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1293 min_qt_log2_size_intra_y =
1294 current->sps_log2_diff_min_qt_min_cb_intra_slice_luma +
1297 ue(sps_max_mtt_hierarchy_depth_intra_slice_luma,
1298 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1300 if (current->sps_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
1301 ue(sps_log2_diff_max_bt_min_qt_intra_slice_luma,
1302 0, ctb_log2_size_y - min_qt_log2_size_intra_y);
1303 ue(sps_log2_diff_max_tt_min_qt_intra_slice_luma,
1304 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
1306 infer(sps_log2_diff_max_bt_min_qt_intra_slice_luma, 0);
1307 infer(sps_log2_diff_max_tt_min_qt_intra_slice_luma, 0);
1310 if (current->sps_chroma_format_idc != 0) {
1311 flag(sps_qtbtt_dual_tree_intra_flag);
1313 infer(sps_qtbtt_dual_tree_intra_flag, 0);
1316 if (current->sps_qtbtt_dual_tree_intra_flag) {
1317 ue(sps_log2_diff_min_qt_min_cb_intra_slice_chroma,
1318 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1319 ue(sps_max_mtt_hierarchy_depth_intra_slice_chroma,
1320 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1321 if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
1322 unsigned int min_qt_log2_size_intra_c =
1323 current->sps_log2_diff_min_qt_min_cb_intra_slice_chroma +
1325 ue(sps_log2_diff_max_bt_min_qt_intra_slice_chroma,
1326 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1327 ue(sps_log2_diff_max_tt_min_qt_intra_slice_chroma,
1328 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1331 infer(sps_log2_diff_min_qt_min_cb_intra_slice_chroma, 0);
1332 infer(sps_max_mtt_hierarchy_depth_intra_slice_chroma, 0);
1334 if (current->sps_max_mtt_hierarchy_depth_intra_slice_chroma == 0) {
1335 infer(sps_log2_diff_max_bt_min_qt_intra_slice_chroma, 0);
1336 infer(sps_log2_diff_max_tt_min_qt_intra_slice_chroma, 0);
1339 ue(sps_log2_diff_min_qt_min_cb_inter_slice,
1340 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1341 min_qt_log2_size_inter_y =
1342 current->sps_log2_diff_min_qt_min_cb_inter_slice + min_cb_log2_size_y;
1344 ue(sps_max_mtt_hierarchy_depth_inter_slice,
1345 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1346 if (current->sps_max_mtt_hierarchy_depth_inter_slice != 0) {
1347 ue(sps_log2_diff_max_bt_min_qt_inter_slice,
1348 0, ctb_log2_size_y - min_qt_log2_size_inter_y);
1349 ue(sps_log2_diff_max_tt_min_qt_inter_slice,
1350 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
1352 infer(sps_log2_diff_max_bt_min_qt_inter_slice, 0);
1353 infer(sps_log2_diff_max_tt_min_qt_inter_slice, 0);
1356 if (ctb_size_y > 32)
1357 flag(sps_max_luma_transform_size_64_flag);
1359 infer(sps_max_luma_transform_size_64_flag, 0);
1361 flag(sps_transform_skip_enabled_flag);
1362 if (current->sps_transform_skip_enabled_flag) {
1363 ue(sps_log2_transform_skip_max_size_minus2, 0, 3);
1364 flag(sps_bdpcm_enabled_flag);
1367 flag(sps_mts_enabled_flag);
1368 if (current->sps_mts_enabled_flag) {
1369 flag(sps_explicit_mts_intra_enabled_flag);
1370 flag(sps_explicit_mts_inter_enabled_flag);
1372 infer(sps_explicit_mts_intra_enabled_flag, 0);
1373 infer(sps_explicit_mts_inter_enabled_flag, 0);
1376 flag(sps_lfnst_enabled_flag);
1378 if (current->sps_chroma_format_idc != 0) {
1379 uint8_t num_qp_tables;
1380 flag(sps_joint_cbcr_enabled_flag);
1381 flag(sps_same_qp_table_for_chroma_flag);
1382 num_qp_tables = current->sps_same_qp_table_for_chroma_flag ?
1383 1 : (current->sps_joint_cbcr_enabled_flag ? 3 : 2);
1384 for (
i = 0;
i < num_qp_tables;
i++) {
1385 ses(sps_qp_table_start_minus26[
i], -26 - qp_bd_offset, 36, 1,
i);
1386 ues(sps_num_points_in_qp_table_minus1[
i],
1387 0, 36 - current->sps_qp_table_start_minus26[
i], 1,
i);
1388 for (j = 0; j <= current->sps_num_points_in_qp_table_minus1[
i]; j++) {
1390 ues(sps_delta_qp_in_val_minus1[
i][j], 0,
max, 2,
i, j);
1391 ues(sps_delta_qp_diff_val[
i][j], 0,
max, 2,
i, j);
1395 infer(sps_joint_cbcr_enabled_flag, 0);
1396 infer(sps_same_qp_table_for_chroma_flag, 0);
1399 flag(sps_sao_enabled_flag);
1400 flag(sps_alf_enabled_flag);
1401 if (current->sps_alf_enabled_flag && current->sps_chroma_format_idc)
1402 flag(sps_ccalf_enabled_flag);
1404 infer(sps_ccalf_enabled_flag, 0);
1405 flag(sps_lmcs_enabled_flag);
1406 flag(sps_weighted_pred_flag);
1407 flag(sps_weighted_bipred_flag);
1408 flag(sps_long_term_ref_pics_flag);
1409 if (current->sps_video_parameter_set_id > 0)
1410 flag(sps_inter_layer_prediction_enabled_flag);
1412 infer(sps_inter_layer_prediction_enabled_flag, 0);
1413 flag(sps_idr_rpl_present_flag);
1414 flag(sps_rpl1_same_as_rpl0_flag);
1416 for (
i = 0;
i < (current->sps_rpl1_same_as_rpl0_flag ? 1 : 2);
i++) {
1418 for (j = 0; j < current->sps_num_ref_pic_lists[
i]; j++)
1421 sps_ref_pic_list_struct[
i][j],
i,
1425 if (current->sps_rpl1_same_as_rpl0_flag) {
1426 current->sps_num_ref_pic_lists[1] = current->sps_num_ref_pic_lists[0];
1427 for (j = 0; j < current->sps_num_ref_pic_lists[0]; j++)
1428 memcpy(¤t->sps_ref_pic_list_struct[1][j],
1429 ¤t->sps_ref_pic_list_struct[0][j],
1430 sizeof(current->sps_ref_pic_list_struct[0][j]));
1433 flag(sps_ref_wraparound_enabled_flag);
1435 flag(sps_temporal_mvp_enabled_flag);
1436 if (current->sps_temporal_mvp_enabled_flag)
1437 flag(sps_sbtmvp_enabled_flag);
1439 infer(sps_sbtmvp_enabled_flag, 0);
1441 flag(sps_amvr_enabled_flag);
1442 flag(sps_bdof_enabled_flag);
1443 if (current->sps_bdof_enabled_flag)
1444 flag(sps_bdof_control_present_in_ph_flag);
1446 infer(sps_bdof_control_present_in_ph_flag, 0);
1448 flag(sps_smvd_enabled_flag);
1449 flag(sps_dmvr_enabled_flag);
1450 if (current->sps_dmvr_enabled_flag)
1451 flag(sps_dmvr_control_present_in_ph_flag);
1453 infer(sps_dmvr_control_present_in_ph_flag, 0);
1455 flag(sps_mmvd_enabled_flag);
1456 if (current->sps_mmvd_enabled_flag)
1457 flag(sps_mmvd_fullpel_only_enabled_flag);
1459 infer(sps_mmvd_fullpel_only_enabled_flag, 0);
1461 ue(sps_six_minus_max_num_merge_cand, 0, 5);
1462 max_num_merge_cand = 6 - current->sps_six_minus_max_num_merge_cand;
1464 flag(sps_sbt_enabled_flag);
1466 flag(sps_affine_enabled_flag);
1467 if (current->sps_affine_enabled_flag) {
1468 ue(sps_five_minus_max_num_subblock_merge_cand,
1469 0, 5 - current->sps_sbtmvp_enabled_flag);
1470 flag(sps_6param_affine_enabled_flag);
1471 if (current->sps_amvr_enabled_flag)
1472 flag(sps_affine_amvr_enabled_flag);
1474 infer(sps_affine_amvr_enabled_flag, 0);
1475 flag(sps_affine_prof_enabled_flag);
1476 if (current->sps_affine_prof_enabled_flag)
1477 flag(sps_prof_control_present_in_ph_flag);
1479 infer(sps_prof_control_present_in_ph_flag, 0);
1481 infer(sps_6param_affine_enabled_flag, 0);
1482 infer(sps_affine_amvr_enabled_flag, 0);
1483 infer(sps_affine_prof_enabled_flag, 0);
1484 infer(sps_prof_control_present_in_ph_flag, 0);
1487 flag(sps_bcw_enabled_flag);
1488 flag(sps_ciip_enabled_flag);
1490 if (max_num_merge_cand >= 2) {
1491 flag(sps_gpm_enabled_flag);
1492 if (current->sps_gpm_enabled_flag && max_num_merge_cand >= 3)
1493 ue(sps_max_num_merge_cand_minus_max_num_gpm_cand,
1494 0, max_num_merge_cand - 2);
1496 infer(sps_gpm_enabled_flag, 0);
1499 ue(sps_log2_parallel_merge_level_minus2, 0, ctb_log2_size_y - 2);
1501 flag(sps_isp_enabled_flag);
1502 flag(sps_mrl_enabled_flag);
1503 flag(sps_mip_enabled_flag);
1505 if (current->sps_chroma_format_idc != 0)
1506 flag(sps_cclm_enabled_flag);
1508 infer(sps_cclm_enabled_flag, 0);
1509 if (current->sps_chroma_format_idc == 1) {
1510 flag(sps_chroma_horizontal_collocated_flag);
1511 flag(sps_chroma_vertical_collocated_flag);
1513 infer(sps_chroma_horizontal_collocated_flag, 1);
1514 infer(sps_chroma_vertical_collocated_flag, 1);
1517 flag(sps_palette_enabled_flag);
1518 if (current->sps_chroma_format_idc == 3 &&
1519 !current->sps_max_luma_transform_size_64_flag)
1520 flag(sps_act_enabled_flag);
1522 infer(sps_act_enabled_flag, 0);
1523 if (current->sps_transform_skip_enabled_flag ||
1524 current->sps_palette_enabled_flag)
1525 ue(sps_min_qp_prime_ts, 0, 8);
1527 flag(sps_ibc_enabled_flag);
1528 if (current->sps_ibc_enabled_flag)
1529 ue(sps_six_minus_max_num_ibc_merge_cand, 0, 5);
1531 flag(sps_ladf_enabled_flag);
1532 if (current->sps_ladf_enabled_flag) {
1533 ub(2, sps_num_ladf_intervals_minus2);
1534 se(sps_ladf_lowest_interval_qp_offset, -63, 63);
1535 for (
i = 0;
i < current->sps_num_ladf_intervals_minus2 + 1;
i++) {
1536 ses(sps_ladf_qp_offset[
i], -63, 63, 1,
i);
1537 ues(sps_ladf_delta_threshold_minus1[
i],
1538 0, (2 << (8 + current->sps_bitdepth_minus8)) - 3, 1,
i);
1542 flag(sps_explicit_scaling_list_enabled_flag);
1543 if (current->sps_lfnst_enabled_flag &&
1544 current->sps_explicit_scaling_list_enabled_flag)
1545 flag(sps_scaling_matrix_for_lfnst_disabled_flag);
1547 if (current->sps_act_enabled_flag &&
1548 current->sps_explicit_scaling_list_enabled_flag)
1549 flag(sps_scaling_matrix_for_alternative_colour_space_disabled_flag);
1551 infer(sps_scaling_matrix_for_alternative_colour_space_disabled_flag, 0);
1552 if (current->sps_scaling_matrix_for_alternative_colour_space_disabled_flag)
1553 flag(sps_scaling_matrix_designated_colour_space_flag);
1555 flag(sps_dep_quant_enabled_flag);
1556 flag(sps_sign_data_hiding_enabled_flag);
1558 flag(sps_virtual_boundaries_enabled_flag);
1559 if (current->sps_virtual_boundaries_enabled_flag) {
1560 flag(sps_virtual_boundaries_present_flag);
1561 if (current->sps_virtual_boundaries_present_flag) {
1562 ue(sps_num_ver_virtual_boundaries,
1563 0, current->sps_pic_width_max_in_luma_samples <= 8 ? 0 : 3);
1564 for (
i = 0;
i < current->sps_num_ver_virtual_boundaries;
i++)
1565 ues(sps_virtual_boundary_pos_x_minus1[
i],
1566 0, (current->sps_pic_width_max_in_luma_samples + 7) / 8 - 2,
1568 ue(sps_num_hor_virtual_boundaries,
1569 0, current->sps_pic_height_max_in_luma_samples <= 8 ? 0 : 3);
1570 for (
i = 0;
i < current->sps_num_hor_virtual_boundaries;
i++)
1571 ues(sps_virtual_boundary_pos_y_minus1[
i],
1572 0, (current->sps_pic_height_max_in_luma_samples + 7) /
1576 infer(sps_virtual_boundaries_present_flag, 0);
1577 infer(sps_num_ver_virtual_boundaries, 0);
1578 infer(sps_num_hor_virtual_boundaries, 0);
1581 if (current->sps_ptl_dpb_hrd_params_present_flag) {
1582 flag(sps_timing_hrd_params_present_flag);
1583 if (current->sps_timing_hrd_params_present_flag) {
1584 uint8_t first_sublayer;
1586 ¤t->sps_general_timing_hrd_parameters));
1587 if (current->sps_max_sublayers_minus1 > 0)
1588 flag(sps_sublayer_cpb_params_present_flag);
1590 infer(sps_sublayer_cpb_params_present_flag, 0);
1591 first_sublayer = current->sps_sublayer_cpb_params_present_flag ?
1592 0 : current->sps_max_sublayers_minus1;
1594 ¤t->sps_ols_timing_hrd_parameters, first_sublayer,
1595 current->sps_max_sublayers_minus1,
1596 ¤t->sps_general_timing_hrd_parameters));
1600 flag(sps_field_seq_flag);
1601 flag(sps_vui_parameters_present_flag);
1602 if (current->sps_vui_parameters_present_flag) {
1603 ue(sps_vui_payload_size_minus1, 0, 1023);
1605 fixed(1, sps_vui_alignment_zero_bit, 0);
1607 current->sps_vui_payload_size_minus1 + 1,
1608 current->sps_chroma_format_idc));
1613 flag(sps_extension_flag);
1614 if (current->sps_extension_flag) {
1615 flag(sps_range_extension_flag);
1616 ub(7, sps_extension_7bits);
1618 if (current->sps_range_extension_flag) {
1621 infer(sps_extended_precision_flag, 0);
1622 infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1623 infer(sps_rrc_rice_extension_flag, 0);
1624 infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1625 infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1628 infer(sps_range_extension_flag, 0);
1629 infer(sps_extension_7bits, 0);
1630 infer(sps_extended_precision_flag, 0);
1631 infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1632 infer(sps_rrc_rice_extension_flag, 0);
1633 infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1634 infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1637 if (current->sps_extension_7bits)
1651 unsigned int min_cb_size_y, divisor, ctb_size_y,
1652 pic_width_in_ctbs_y, pic_height_in_ctbs_y;
1653 uint8_t sub_width_c, sub_height_c, qp_bd_offset;
1655 static const uint8_t h266_sub_width_c[] = {
1658 static const uint8_t h266_sub_height_c[] = {
1662 HEADER(
"Picture Parameter Set");
1667 ub(6, pps_pic_parameter_set_id);
1668 ub(4, pps_seq_parameter_set_id);
1669 sps = h266->
sps[current->pps_seq_parameter_set_id];
1672 current->pps_seq_parameter_set_id);
1676 flag(pps_mixed_nalu_types_in_pic_flag);
1677 ue(pps_pic_width_in_luma_samples,
1678 1,
sps->sps_pic_width_max_in_luma_samples);
1679 ue(pps_pic_height_in_luma_samples,
1680 1,
sps->sps_pic_height_max_in_luma_samples);
1682 min_cb_size_y = 1 << (
sps->sps_log2_min_luma_coding_block_size_minus2 + 2);
1683 divisor =
FFMAX(min_cb_size_y, 8);
1684 if (current->pps_pic_width_in_luma_samples % divisor ||
1685 current->pps_pic_height_in_luma_samples % divisor) {
1687 "Invalid dimensions: %ux%u not divisible "
1688 "by %u, MinCbSizeY = %u.\n",
1689 current->pps_pic_width_in_luma_samples,
1690 current->pps_pic_height_in_luma_samples, divisor, min_cb_size_y);
1693 if (!
sps->sps_res_change_in_clvs_allowed_flag &&
1694 (current->pps_pic_width_in_luma_samples !=
1695 sps->sps_pic_width_max_in_luma_samples ||
1696 current->pps_pic_height_in_luma_samples !=
1697 sps->sps_pic_height_max_in_luma_samples)) {
1699 "Resoltuion change is not allowed, "
1700 "in max resolution (%ux%u) mismatched with pps(%ux%u).\n",
1701 sps->sps_pic_width_max_in_luma_samples,
1702 sps->sps_pic_height_max_in_luma_samples,
1703 current->pps_pic_width_in_luma_samples,
1704 current->pps_pic_height_in_luma_samples);
1708 ctb_size_y = 1 << (
sps->sps_log2_ctu_size_minus5 + 5);
1709 if (
sps->sps_ref_wraparound_enabled_flag) {
1710 if ((ctb_size_y / min_cb_size_y + 1) >
1711 (current->pps_pic_width_in_luma_samples / min_cb_size_y - 1)) {
1713 "Invalid width(%u), ctb_size_y = %u, min_cb_size_y = %u.\n",
1714 current->pps_pic_width_in_luma_samples,
1715 ctb_size_y, min_cb_size_y);
1720 flag(pps_conformance_window_flag);
1721 if (current->pps_pic_width_in_luma_samples ==
1722 sps->sps_pic_width_max_in_luma_samples &&
1723 current->pps_pic_height_in_luma_samples ==
1724 sps->sps_pic_height_max_in_luma_samples &&
1725 current->pps_conformance_window_flag) {
1727 "Conformance window flag should not true.\n");
1731 sub_width_c = h266_sub_width_c[
sps->sps_chroma_format_idc];
1732 sub_height_c = h266_sub_height_c[
sps->sps_chroma_format_idc];
1733 if (current->pps_conformance_window_flag) {
1734 ue(pps_conf_win_left_offset, 0, current->pps_pic_width_in_luma_samples);
1735 ue(pps_conf_win_right_offset,
1736 0, current->pps_pic_width_in_luma_samples);
1737 ue(pps_conf_win_top_offset, 0, current->pps_pic_height_in_luma_samples);
1738 ue(pps_conf_win_bottom_offset,
1739 0, current->pps_pic_height_in_luma_samples);
1741 (current->pps_conf_win_left_offset +
1742 current->pps_conf_win_right_offset) >=
1743 current->pps_pic_width_in_luma_samples ||
1745 (current->pps_conf_win_top_offset +
1746 current->pps_conf_win_bottom_offset) >=
1747 current->pps_pic_height_in_luma_samples) {
1749 "Invalid pps conformance window: (%u, %u, %u, %u), "
1750 "resolution is %ux%u, sub wxh is %ux%u.\n",
1751 current->pps_conf_win_left_offset,
1752 current->pps_conf_win_right_offset,
1753 current->pps_conf_win_top_offset,
1754 current->pps_conf_win_bottom_offset,
1755 current->pps_pic_width_in_luma_samples,
1756 current->pps_pic_height_in_luma_samples,
1757 sub_width_c, sub_height_c);
1761 if (current->pps_pic_width_in_luma_samples ==
1762 sps->sps_pic_width_max_in_luma_samples &&
1763 current->pps_pic_height_in_luma_samples ==
1764 sps->sps_pic_height_max_in_luma_samples) {
1765 infer(pps_conf_win_left_offset,
sps->sps_conf_win_left_offset);
1766 infer(pps_conf_win_right_offset,
sps->sps_conf_win_right_offset);
1767 infer(pps_conf_win_top_offset,
sps->sps_conf_win_top_offset);
1768 infer(pps_conf_win_bottom_offset,
sps->sps_conf_win_bottom_offset);
1770 infer(pps_conf_win_left_offset, 0);
1771 infer(pps_conf_win_right_offset, 0);
1772 infer(pps_conf_win_top_offset, 0);
1773 infer(pps_conf_win_bottom_offset, 0);
1778 flag(pps_scaling_window_explicit_signalling_flag);
1779 if (!
sps->sps_ref_pic_resampling_enabled_flag &&
1780 current->pps_scaling_window_explicit_signalling_flag) {
1782 "Invalid data: sps_ref_pic_resampling_enabled_flag is false, "
1783 "but pps_scaling_window_explicit_signalling_flag is true.\n");
1786 if (current->pps_scaling_window_explicit_signalling_flag) {
1787 se(pps_scaling_win_left_offset,
1788 -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1789 current->pps_pic_width_in_luma_samples / sub_width_c);
1790 se(pps_scaling_win_right_offset,
1791 -current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1792 current->pps_pic_width_in_luma_samples / sub_width_c);
1793 se(pps_scaling_win_top_offset,
1794 -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1795 current->pps_pic_height_in_luma_samples / sub_height_c);
1796 se(pps_scaling_win_bottom_offset,
1797 -current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1798 current->pps_pic_height_in_luma_samples / sub_height_c);
1800 infer(pps_scaling_win_left_offset, current->pps_conf_win_left_offset);
1801 infer(pps_scaling_win_right_offset, current->pps_conf_win_right_offset);
1802 infer(pps_scaling_win_top_offset, current->pps_conf_win_top_offset);
1803 infer(pps_scaling_win_bottom_offset, current->pps_conf_win_bottom_offset);
1806 flag(pps_output_flag_present_flag);
1807 flag(pps_no_pic_partition_flag);
1808 flag(pps_subpic_id_mapping_present_flag);
1810 if (current->pps_subpic_id_mapping_present_flag) {
1811 if (!current->pps_no_pic_partition_flag) {
1812 ue(pps_num_subpics_minus1,
1813 sps->sps_num_subpics_minus1,
sps->sps_num_subpics_minus1);
1815 infer(pps_num_subpics_minus1, 0);
1817 ue(pps_subpic_id_len_minus1,
sps->sps_subpic_id_len_minus1,
1818 sps->sps_subpic_id_len_minus1);
1819 for (
i = 0;
i <= current->pps_num_subpics_minus1;
i++) {
1820 ubs(
sps->sps_subpic_id_len_minus1 + 1, pps_subpic_id[
i], 1,
i);
1824 for (
i = 0;
i <=
sps->sps_num_subpics_minus1;
i++) {
1825 if (
sps->sps_subpic_id_mapping_explicitly_signalled_flag)
1826 current->sub_pic_id_val[
i] = current->pps_subpic_id_mapping_present_flag
1827 ? current->pps_subpic_id[
i]
1828 :
sps->sps_subpic_id[
i];
1830 current->sub_pic_id_val[
i] =
i;
1834 (current->pps_pic_width_in_luma_samples, (
sps->sps_log2_ctu_size_minus5 + 5));
1836 current->pps_pic_height_in_luma_samples,(
sps->sps_log2_ctu_size_minus5 + 5));
1837 if (!current->pps_no_pic_partition_flag) {
1838 unsigned int exp_tile_width = 0, exp_tile_height = 0;
1839 unsigned int unified_size, remaining_size;
1841 u(2, pps_log2_ctu_size_minus5,
1842 sps->sps_log2_ctu_size_minus5,
sps->sps_log2_ctu_size_minus5);
1843 ue(pps_num_exp_tile_columns_minus1,
1845 ue(pps_num_exp_tile_rows_minus1,
1848 for (
i = 0;
i <= current->pps_num_exp_tile_columns_minus1;
i++) {
1849 ues(pps_tile_column_width_minus1[
i],
1850 0, pic_width_in_ctbs_y - exp_tile_width - 1, 1,
i);
1851 exp_tile_width += current->pps_tile_column_width_minus1[
i] + 1;
1853 for (
i = 0;
i <= current->pps_num_exp_tile_rows_minus1;
i++) {
1854 ues(pps_tile_row_height_minus1[
i],
1855 0, pic_height_in_ctbs_y - exp_tile_height - 1, 1,
i);
1856 exp_tile_height += current->pps_tile_row_height_minus1[
i] + 1;
1859 remaining_size = pic_width_in_ctbs_y;
1860 for (
i = 0;
i <= current->pps_num_exp_tile_columns_minus1;
i++) {
1861 if (current->pps_tile_column_width_minus1[
i] >= remaining_size) {
1863 "Tile column width(%d) exceeds picture width\n",
i);
1866 current->col_width_val[
i] = current->pps_tile_column_width_minus1[
i] + 1;
1867 remaining_size -= (current->pps_tile_column_width_minus1[
i] + 1);
1869 unified_size = current->pps_tile_column_width_minus1[
i - 1] + 1;
1870 while (remaining_size > 0) {
1873 "NumTileColumns(%d) > than VVC_MAX_TILE_COLUMNS(%d)\n",
1877 unified_size =
FFMIN(remaining_size, unified_size);
1878 current->col_width_val[
i] = unified_size;
1879 remaining_size -= unified_size;
1882 current->num_tile_columns =
i;
1885 "NumTileColumns(%d) > than VVC_MAX_TILE_COLUMNS(%d)\n",
1890 remaining_size = pic_height_in_ctbs_y;
1891 for (
i = 0;
i <= current->pps_num_exp_tile_rows_minus1;
i++) {
1892 if (current->pps_tile_row_height_minus1[
i] >= remaining_size) {
1894 "Tile row height(%d) exceeds picture height\n",
i);
1897 current->row_height_val[
i] = current->pps_tile_row_height_minus1[
i] + 1;
1898 remaining_size -= (current->pps_tile_row_height_minus1[
i] + 1);
1900 unified_size = current->pps_tile_row_height_minus1[
i - 1] + 1;
1902 while (remaining_size > 0) {
1903 unified_size =
FFMIN(remaining_size, unified_size);
1904 current->row_height_val[
i] = unified_size;
1905 remaining_size -= unified_size;
1908 current->num_tile_rows=
i;
1911 "NumTileRows(%d) > than VVC_MAX_TILE_ROWS(%d)\n",
1916 current->num_tiles_in_pic = current->num_tile_columns *
1917 current->num_tile_rows;
1920 "NumTilesInPic(%d) > than VVC_MAX_TILES_PER_AU(%d)\n",
1925 if (current->num_tiles_in_pic > 1) {
1926 flag(pps_loop_filter_across_tiles_enabled_flag);
1927 flag(pps_rect_slice_flag);
1929 infer(pps_loop_filter_across_tiles_enabled_flag, 0);
1930 infer(pps_rect_slice_flag, 1);
1932 if (current->pps_rect_slice_flag)
1933 flag(pps_single_slice_per_subpic_flag);
1935 infer(pps_single_slice_per_subpic_flag, 1);
1936 if (current->pps_rect_slice_flag &&
1937 !current->pps_single_slice_per_subpic_flag) {
1939 uint16_t tile_idx = 0, tile_x, tile_y, ctu_x, ctu_y;
1943 if (current->pps_num_slices_in_pic_minus1 > 1)
1944 flag(pps_tile_idx_delta_present_flag);
1946 infer(pps_tile_idx_delta_present_flag, 0);
1947 for (
i = 0;
i < current->pps_num_slices_in_pic_minus1;
i++) {
1948 tile_x = tile_idx % current->num_tile_columns;
1949 tile_y = tile_idx / current->num_tile_columns;
1950 if (tile_x != current->num_tile_columns - 1) {
1951 ues(pps_slice_width_in_tiles_minus1[
i],
1952 0, current->num_tile_columns - 1, 1,
i);
1954 infer(pps_slice_width_in_tiles_minus1[
i], 0);
1956 if (tile_y != current->num_tile_rows - 1 &&
1957 (current->pps_tile_idx_delta_present_flag || tile_x == 0)) {
1958 ues(pps_slice_height_in_tiles_minus1[
i],
1959 0, current->num_tile_rows - 1, 1,
i);
1961 if (tile_y == current->num_tile_rows - 1)
1962 infer(pps_slice_height_in_tiles_minus1[
i], 0);
1964 infer(pps_slice_height_in_tiles_minus1[
i],
1965 current->pps_slice_height_in_tiles_minus1[
i - 1]);
1969 for (j = 0; j < tile_x; j++) {
1970 ctu_x += current->col_width_val[j];
1972 for (j = 0; j < tile_y; j++) {
1973 ctu_y += current->row_height_val[j];
1975 if (current->pps_slice_width_in_tiles_minus1[
i] == 0 &&
1976 current->pps_slice_height_in_tiles_minus1[
i] == 0 &&
1977 current->row_height_val[tile_y] > 1) {
1978 int num_slices_in_tile,
1979 uniform_slice_height, remaining_height_in_ctbs_y;
1980 remaining_height_in_ctbs_y =
1981 current->row_height_val[tile_y];
1982 ues(pps_num_exp_slices_in_tile[
i],
1983 0, current->row_height_val[tile_y] - 1, 1,
i);
1984 if (current->pps_num_exp_slices_in_tile[
i] == 0) {
1985 num_slices_in_tile = 1;
1986 current->slice_height_in_ctus[
i] = current->row_height_val[tile_y];
1987 slice_top_left_ctu_x[
i] = ctu_x;
1988 slice_top_left_ctu_y[
i] = ctu_y;
1990 uint16_t slice_height_in_ctus;
1991 for (j = 0; j < current->pps_num_exp_slices_in_tile[
i];
1993 ues(pps_exp_slice_height_in_ctus_minus1[
i][j], 0,
1994 current->row_height_val[tile_y] - 1, 2,
1996 slice_height_in_ctus =
1998 pps_exp_slice_height_in_ctus_minus1[
i][j] + 1;
2000 current->slice_height_in_ctus[
i + j] =
2001 slice_height_in_ctus;
2002 slice_top_left_ctu_x[
i + j] = ctu_x;
2003 slice_top_left_ctu_y[
i + j] = ctu_y;
2004 ctu_y += slice_height_in_ctus;
2006 remaining_height_in_ctbs_y -= slice_height_in_ctus;
2008 uniform_slice_height = 1 +
2009 (j == 0 ? current->row_height_val[tile_y] - 1:
2010 current->pps_exp_slice_height_in_ctus_minus1[
i][j-1]);
2011 while (remaining_height_in_ctbs_y > uniform_slice_height) {
2012 current->slice_height_in_ctus[
i + j] =
2013 uniform_slice_height;
2014 slice_top_left_ctu_x[
i + j] = ctu_x;
2015 slice_top_left_ctu_y[
i + j] = ctu_y;
2016 ctu_y += uniform_slice_height;
2018 remaining_height_in_ctbs_y -= uniform_slice_height;
2021 if (remaining_height_in_ctbs_y > 0) {
2022 current->slice_height_in_ctus[
i + j] =
2023 remaining_height_in_ctbs_y;
2024 slice_top_left_ctu_x[
i + j] = ctu_x;
2025 slice_top_left_ctu_y[
i + j] = ctu_y;
2028 num_slices_in_tile = j;
2030 i += num_slices_in_tile - 1;
2033 infer(pps_num_exp_slices_in_tile[
i], 0);
2035 j <= current->pps_slice_height_in_tiles_minus1[
i];
2038 current->row_height_val[tile_y + j];
2040 current->slice_height_in_ctus[
i] =
height;
2042 slice_top_left_ctu_x[
i] = ctu_x;
2043 slice_top_left_ctu_y[
i] = ctu_y;
2045 if (i < current->pps_num_slices_in_pic_minus1) {
2046 if (current->pps_tile_idx_delta_present_flag) {
2051 ses(pps_tile_idx_delta_val[
i],
2052 -tile_idx, current->num_tiles_in_pic - 1 - tile_idx, 1,
i);
2053 if (current->pps_tile_idx_delta_val[
i] == 0) {
2055 "pps_tile_idx_delta_val[i] shall not be equal to 0.\n");
2057 tile_idx += current->pps_tile_idx_delta_val[
i];
2059 infer(pps_tile_idx_delta_val[
i], 0);
2061 current->pps_slice_width_in_tiles_minus1[
i] + 1;
2062 if (tile_idx % current->num_tile_columns == 0) {
2064 current->pps_slice_height_in_tiles_minus1[
i] *
2065 current->num_tile_columns;
2070 if (
i == current->pps_num_slices_in_pic_minus1) {
2073 tile_x = tile_idx % current->num_tile_columns;
2074 tile_y = tile_idx / current->num_tile_columns;
2075 if (tile_y >= current->num_tile_rows)
2078 ctu_x = 0, ctu_y = 0;
2079 for (j = 0; j < tile_x; j++) {
2080 ctu_x += current->col_width_val[j];
2082 for (j = 0; j < tile_y; j++) {
2083 ctu_y += current->row_height_val[j];
2085 slice_top_left_ctu_x[
i] = ctu_x;
2086 slice_top_left_ctu_y[
i] = ctu_y;
2088 current->pps_slice_width_in_tiles_minus1[
i] =
2089 current->num_tile_columns - tile_x - 1;
2090 current->pps_slice_height_in_tiles_minus1[
i] =
2091 current->num_tile_rows - tile_y - 1;
2093 for (j = 0; j <= current->pps_slice_height_in_tiles_minus1[
i];
2096 current->row_height_val[tile_y + j];
2098 current->slice_height_in_ctus[
i] =
height;
2100 infer(pps_num_exp_slices_in_tile[
i], 0);
2103 for (
i = 0;
i <=
sps->sps_num_subpics_minus1;
i++) {
2104 current->num_slices_in_subpic[
i] = 0;
2105 for (j = 0; j <= current->pps_num_slices_in_pic_minus1; j++) {
2106 uint16_t pos_x = 0, pos_y = 0;
2107 pos_x = slice_top_left_ctu_x[j];
2108 pos_y = slice_top_left_ctu_y[j];
2109 if ((pos_x >=
sps->sps_subpic_ctu_top_left_x[
i]) &&
2111 sps->sps_subpic_ctu_top_left_x[
i] +
2112 sps->sps_subpic_width_minus1[
i] + 1) &&
2113 (pos_y >=
sps->sps_subpic_ctu_top_left_y[
i]) &&
2114 (pos_y < sps->sps_subpic_ctu_top_left_y[
i] +
2115 sps->sps_subpic_height_minus1[
i] + 1)) {
2116 current->num_slices_in_subpic[
i]++;
2121 if (current->pps_no_pic_partition_flag)
2122 infer(pps_num_slices_in_pic_minus1, 0);
2123 else if (current->pps_single_slice_per_subpic_flag)
2124 infer(pps_num_slices_in_pic_minus1,
2125 sps->sps_num_subpics_minus1);
2128 if (!current->pps_rect_slice_flag ||
2129 current->pps_single_slice_per_subpic_flag ||
2130 current->pps_num_slices_in_pic_minus1 > 0)
2131 flag(pps_loop_filter_across_slices_enabled_flag);
2133 infer(pps_loop_filter_across_slices_enabled_flag, 0);
2135 infer(pps_num_exp_tile_columns_minus1, 0);
2136 infer(pps_tile_column_width_minus1[0], pic_width_in_ctbs_y - 1);
2137 infer(pps_num_exp_tile_rows_minus1, 0);
2138 infer(pps_tile_row_height_minus1[0], pic_height_in_ctbs_y - 1);
2139 current->col_width_val[0] = pic_width_in_ctbs_y;
2140 current->row_height_val[0] = pic_height_in_ctbs_y;
2141 current->num_tile_columns = 1;
2142 current->num_tile_rows = 1;
2143 current->num_tiles_in_pic = 1;
2146 flag(pps_cabac_init_present_flag);
2147 for (
i = 0;
i < 2;
i++)
2148 ues(pps_num_ref_idx_default_active_minus1[
i], 0, 14, 1,
i);
2149 flag(pps_rpl1_idx_present_flag);
2150 flag(pps_weighted_pred_flag);
2151 flag(pps_weighted_bipred_flag);
2152 flag(pps_ref_wraparound_enabled_flag);
2153 if (current->pps_ref_wraparound_enabled_flag) {
2154 ue(pps_pic_width_minus_wraparound_offset,
2155 0, (current->pps_pic_width_in_luma_samples / min_cb_size_y)
2156 - (ctb_size_y / min_cb_size_y) - 2);
2159 qp_bd_offset = 6 *
sps->sps_bitdepth_minus8;
2160 se(pps_init_qp_minus26, -(26 + qp_bd_offset), 37);
2161 flag(pps_cu_qp_delta_enabled_flag);
2162 flag(pps_chroma_tool_offsets_present_flag);
2163 if (current->pps_chroma_tool_offsets_present_flag) {
2164 se(pps_cb_qp_offset, -12, 12);
2165 se(pps_cr_qp_offset, -12, 12);
2166 flag(pps_joint_cbcr_qp_offset_present_flag);
2167 if (current->pps_joint_cbcr_qp_offset_present_flag)
2168 se(pps_joint_cbcr_qp_offset_value, -12, 12);
2170 infer(pps_joint_cbcr_qp_offset_value, 0);
2171 flag(pps_slice_chroma_qp_offsets_present_flag);
2172 flag(pps_cu_chroma_qp_offset_list_enabled_flag);
2173 if (current->pps_cu_chroma_qp_offset_list_enabled_flag) {
2174 ue(pps_chroma_qp_offset_list_len_minus1, 0, 5);
2175 for (
i = 0;
i <= current->pps_chroma_qp_offset_list_len_minus1;
i++) {
2176 ses(pps_cb_qp_offset_list[
i], -12, 12, 1,
i);
2177 ses(pps_cr_qp_offset_list[
i], -12, 12, 1,
i);
2178 if (current->pps_joint_cbcr_qp_offset_present_flag)
2179 ses(pps_joint_cbcr_qp_offset_list[
i], -12, 12, 1,
i);
2181 infer(pps_joint_cbcr_qp_offset_list[
i], 0);
2185 infer(pps_cb_qp_offset, 0);
2186 infer(pps_cr_qp_offset, 0);
2187 infer(pps_joint_cbcr_qp_offset_present_flag, 0);
2188 infer(pps_joint_cbcr_qp_offset_value, 0);
2189 infer(pps_slice_chroma_qp_offsets_present_flag, 0);
2190 infer(pps_cu_chroma_qp_offset_list_enabled_flag, 0);
2192 flag(pps_deblocking_filter_control_present_flag);
2193 if (current->pps_deblocking_filter_control_present_flag) {
2194 flag(pps_deblocking_filter_override_enabled_flag);
2195 flag(pps_deblocking_filter_disabled_flag);
2196 if (!current->pps_no_pic_partition_flag &&
2197 current->pps_deblocking_filter_override_enabled_flag)
2198 flag(pps_dbf_info_in_ph_flag);
2200 infer(pps_dbf_info_in_ph_flag, 0);
2201 if (!current->pps_deblocking_filter_disabled_flag) {
2202 se(pps_luma_beta_offset_div2, -12, 12);
2203 se(pps_luma_tc_offset_div2, -12, 12);
2204 if (current->pps_chroma_tool_offsets_present_flag) {
2205 se(pps_cb_beta_offset_div2, -12, 12);
2206 se(pps_cb_tc_offset_div2, -12, 12);
2207 se(pps_cr_beta_offset_div2, -12, 12);
2208 se(pps_cr_tc_offset_div2, -12, 12);
2210 infer(pps_cb_beta_offset_div2,
2211 current->pps_luma_beta_offset_div2);
2212 infer(pps_cb_tc_offset_div2, current->pps_luma_tc_offset_div2);
2213 infer(pps_cr_beta_offset_div2,
2214 current->pps_luma_beta_offset_div2);
2215 infer(pps_cr_tc_offset_div2, current->pps_luma_tc_offset_div2);
2218 infer(pps_luma_beta_offset_div2, 0);
2219 infer(pps_luma_tc_offset_div2, 0);
2220 infer(pps_cb_beta_offset_div2, 0);
2221 infer(pps_cb_tc_offset_div2, 0);
2222 infer(pps_cr_beta_offset_div2, 0);
2223 infer(pps_cr_tc_offset_div2, 0);
2226 infer(pps_deblocking_filter_override_enabled_flag, 0);
2227 infer(pps_deblocking_filter_disabled_flag, 0);
2228 infer(pps_dbf_info_in_ph_flag, 0);
2229 infer(pps_luma_beta_offset_div2, 0);
2230 infer(pps_luma_tc_offset_div2, 0);
2231 infer(pps_cb_beta_offset_div2, 0);
2232 infer(pps_cb_tc_offset_div2, 0);
2233 infer(pps_cr_beta_offset_div2, 0);
2234 infer(pps_cr_tc_offset_div2, 0);
2237 if (!current->pps_no_pic_partition_flag) {
2238 flag(pps_rpl_info_in_ph_flag);
2239 flag(pps_sao_info_in_ph_flag);
2240 flag(pps_alf_info_in_ph_flag);
2241 if ((current->pps_weighted_pred_flag ||
2242 current->pps_weighted_bipred_flag) &&
2243 current->pps_rpl_info_in_ph_flag)
2244 flag(pps_wp_info_in_ph_flag);
2245 flag(pps_qp_delta_info_in_ph_flag);
2247 flag(pps_picture_header_extension_present_flag);
2248 flag(pps_slice_header_extension_present_flag);
2250 flag(pps_extension_flag);
2251 if (current->pps_extension_flag)
2263 flag(alf_luma_filter_signal_flag);
2265 if (current->aps_chroma_present_flag) {
2266 flag(alf_chroma_filter_signal_flag);
2267 flag(alf_cc_cb_filter_signal_flag);
2268 flag(alf_cc_cr_filter_signal_flag);
2270 infer(alf_chroma_filter_signal_flag, 0);
2271 infer(alf_cc_cb_filter_signal_flag, 0);
2272 infer(alf_cc_cr_filter_signal_flag, 0);
2275 if (current->alf_luma_filter_signal_flag) {
2276 flag(alf_luma_clip_flag);
2278 if (current->alf_luma_num_filters_signalled_minus1 > 0) {
2279 unsigned int bits =
av_ceil_log2(current->alf_luma_num_filters_signalled_minus1 + 1);
2281 us(
bits, alf_luma_coeff_delta_idx[filt_idx],
2282 0, current->alf_luma_num_filters_signalled_minus1,
2285 for (
int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++)
2286 for (j = 0; j < 12; j++) {
2287 ues(alf_luma_coeff_abs[sf_idx][j], 0, 128, 2, sf_idx, j);
2288 if (current->alf_luma_coeff_abs[sf_idx][j])
2289 ubs(1, alf_luma_coeff_sign[sf_idx][j], 2, sf_idx, j);
2291 infer(alf_luma_coeff_sign[sf_idx][j], 0);
2294 infer(alf_luma_clip_flag, 0);
2295 infer(alf_luma_num_filters_signalled_minus1, 0);
2297 for (
int sf_idx = 0; sf_idx <= current->alf_luma_num_filters_signalled_minus1; sf_idx++) {
2298 for (j = 0; j < 12; j++) {
2299 if (current->alf_luma_clip_flag)
2300 ubs(2, alf_luma_clip_idx[sf_idx][j], 2, sf_idx, j);
2302 infer(alf_luma_clip_idx[sf_idx][j], 0);
2306 if (current->alf_chroma_filter_signal_flag) {
2307 flag(alf_chroma_clip_flag);
2308 ue(alf_chroma_num_alt_filters_minus1, 0, 7);
2310 infer(alf_chroma_clip_flag, 0);
2311 infer(alf_chroma_num_alt_filters_minus1, 0);
2313 for (
int alt_idx = 0; alt_idx <= current->alf_chroma_num_alt_filters_minus1; alt_idx++) {
2314 for (j = 0; j < 6; j++) {
2315 if (current->alf_chroma_filter_signal_flag)
2316 ues(alf_chroma_coeff_abs[alt_idx][j], 0, 128, 2, alt_idx, j);
2318 infer(alf_chroma_coeff_abs[alt_idx][j], 0);
2319 if (current->alf_chroma_coeff_abs[alt_idx][j] > 0)
2320 ubs(1, alf_chroma_coeff_sign[alt_idx][j], 2, alt_idx, j);
2322 infer(alf_chroma_coeff_sign[alt_idx][j], 0);
2324 for (j = 0; j < 6; j++) {
2325 if (current->alf_chroma_clip_flag)
2326 ubs(2, alf_chroma_clip_idx[alt_idx][j], 2, alt_idx, j);
2328 infer(alf_chroma_clip_idx[alt_idx][j], 0);
2332 if (current->alf_cc_cb_filter_signal_flag)
2333 ue(alf_cc_cb_filters_signalled_minus1, 0, 3);
2335 infer(alf_cc_cb_filters_signalled_minus1, 0);
2336 for (k = 0; k <= current->alf_cc_cb_filters_signalled_minus1; k++) {
2337 for (j = 0; j < 7; j++) {
2338 if (current->alf_cc_cb_filter_signal_flag)
2339 ubs(3, alf_cc_cb_mapped_coeff_abs[k][j], 2, k, j);
2341 infer(alf_cc_cb_mapped_coeff_abs[k][j], 0);
2342 if (current->alf_cc_cb_mapped_coeff_abs[k][j])
2343 ubs(1, alf_cc_cb_coeff_sign[k][j], 2, k, j);
2345 infer(alf_cc_cb_coeff_sign[k][j], 0);
2349 if (current->alf_cc_cr_filter_signal_flag)
2350 ue(alf_cc_cr_filters_signalled_minus1, 0, 3);
2352 infer(alf_cc_cr_filters_signalled_minus1, 0);
2353 for (k = 0; k < current->alf_cc_cr_filters_signalled_minus1 + 1; k++) {
2354 for (j = 0; j < 7; j++) {
2355 if (current->alf_cc_cr_filter_signal_flag)
2356 ubs(3, alf_cc_cr_mapped_coeff_abs[k][j], 2, k, j);
2358 infer(alf_cc_cr_mapped_coeff_abs[k][j], 0);
2359 if (current->alf_cc_cr_mapped_coeff_abs[k][j])
2360 ubs(1, alf_cc_cr_coeff_sign[k][j], 2, k, j);
2362 infer(alf_cc_cr_coeff_sign[k][j], 0);
2372 int err,
i, lmcs_max_bin_idx;
2374 ue(lmcs_min_bin_idx, 0, 15);
2375 ue(lmcs_delta_max_bin_idx, 0, 15);
2376 ue(lmcs_delta_cw_prec_minus1, 0, 14);
2378 lmcs_max_bin_idx = 15 - current->lmcs_delta_max_bin_idx;
2380 if (lmcs_max_bin_idx < current->lmcs_min_bin_idx)
2383 for (
i = current->lmcs_min_bin_idx;
i <= lmcs_max_bin_idx;
i++) {
2384 ubs(current->lmcs_delta_cw_prec_minus1 + 1, lmcs_delta_abs_cw[
i], 1,
i);
2385 if (current->lmcs_delta_abs_cw[
i] > 0)
2386 flags(lmcs_delta_sign_cw_flag[
i], 1,
i);
2388 infer(lmcs_delta_sign_cw_flag[
i], 0);
2391 if (current->aps_chroma_present_flag) {
2392 ub(3, lmcs_delta_abs_crs);
2393 if (current->lmcs_delta_abs_crs > 0)
2394 flag(lmcs_delta_sign_crs_flag);
2396 infer(lmcs_delta_sign_crs_flag, 0);
2398 infer(lmcs_delta_abs_crs, 0);
2399 infer(lmcs_delta_sign_crs_flag, 0);
2409 static const uint8_t diag_scan_order[64][2] = {
2410 { 0, 0, }, { 0, 1, }, { 1, 0, }, { 0, 2, }, { 1, 1, }, { 2, 0, }, { 0, 3, }, { 1, 2, },
2411 { 2, 1, }, { 3, 0, }, { 0, 4, }, { 1, 3, }, { 2, 2, }, { 3, 1, }, { 4, 0, }, { 0, 5, },
2412 { 1, 4, }, { 2, 3, }, { 3, 2, }, { 4, 1, }, { 5, 0, }, { 0, 6, }, { 1, 5, }, { 2, 4, },
2413 { 3, 3, }, { 4, 2, }, { 5, 1, }, { 6, 0, }, { 0, 7, }, { 1, 6, }, { 2, 5, }, { 3, 4, },
2414 { 4, 3, }, { 5, 2, }, { 6, 1, }, { 7, 0, }, { 1, 7, }, { 2, 6, }, { 3, 5, }, { 4, 4, },
2415 { 5, 3, }, { 6, 2, }, { 7, 1, }, { 2, 7, }, { 3, 6, }, { 4, 5, }, { 5, 4, }, { 6, 3, },
2416 { 7, 2, }, { 3, 7, }, { 4, 6, }, { 5, 5, }, { 6, 4, }, { 7, 3, }, { 4, 7, }, { 5, 6, },
2417 { 6, 5, }, { 7, 4, }, { 5, 7, }, { 6, 6, }, { 7, 5, }, { 6, 7, }, { 7, 6, }, { 7, 7, }, };
2420 for (
int id = 0;
id < 28;
id ++) {
2421 if (current->aps_chroma_present_flag ||
id % 3 == 2 ||
id == 27) {
2422 flags(scaling_list_copy_mode_flag[
id], 1,
id);
2423 if (!current->scaling_list_copy_mode_flag[
id])
2424 flags(scaling_list_pred_mode_flag[
id], 1,
id);
2426 infer(scaling_list_pred_mode_flag[
id], 0);
2427 if ((current->scaling_list_copy_mode_flag[
id] ||
2428 current->scaling_list_pred_mode_flag[
id]) &&
2429 id != 0 &&
id != 2 &&
id != 8) {
2430 int max_id_delta = (
id < 2) ?
id : ((
id < 8) ? (
id - 2) : (
id - 8));
2431 ues(scaling_list_pred_id_delta[
id], 0, max_id_delta, 1,
id);
2433 if (!current->scaling_list_copy_mode_flag[
id]) {
2434 int matrix_size =
id < 2 ? 2 : (
id < 8 ? 4 : 8);
2437 ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
2439 for (
int i = 0;
i < matrix_size * matrix_size;
i++) {
2440 int x = diag_scan_order[
i][0];
2441 int y = diag_scan_order[
i][1];
2442 if (!(
id > 25 && x >= 4 && y >= 4))
2443 ses(scaling_list_delta_coef[
id][
i], -128, 127, 2,
id,
i);
2445 }
else if (
id > 13) {
2447 infer(scaling_list_dc_coef[idx], 0);
2450 infer(scaling_list_copy_mode_flag[
id], 1);
2451 infer(scaling_list_pred_mode_flag[
id], 0);
2465 HEADER(
"Prefix Adaptation parameter set");
2467 HEADER(
"Suffix Adaptation parameter set");
2473 ub(3, aps_params_type);
2479 u(5, aps_adaptation_parameter_set_id, 0, aps_id_max);
2480 flag(aps_chroma_present_flag);
2487 flag(aps_extension_flag);
2488 if (current->aps_extension_flag)
2500 HEADER(
"Access Unit Delimiter");
2505 flag(aud_irap_or_gdr_flag);
2506 u(3, aud_pic_type, 0, 2);
2516 uint8_t num_ref_idx_active[2],
2520 ue(luma_log2_weight_denom, 0, 7);
2521 if (
sps->sps_chroma_format_idc != 0) {
2522 se(delta_chroma_log2_weight_denom,
2523 -current->luma_log2_weight_denom,
2524 7 - current->luma_log2_weight_denom);
2526 infer(delta_chroma_log2_weight_denom, 0);
2528 if (
pps->pps_wp_info_in_ph_flag) {
2529 ue(num_l0_weights, 0,
2530 FFMIN(15, ref_lists->rpl_ref_list[0].num_ref_entries));
2531 infer(num_weights_l0, current->num_l0_weights);
2533 infer(num_weights_l0, num_ref_idx_active[0]);
2535 for (
i = 0;
i < current->num_weights_l0;
i++) {
2536 flags(luma_weight_l0_flag[
i], 1,
i);
2538 if (
sps->sps_chroma_format_idc != 0) {
2539 for (
i = 0;
i < current->num_weights_l0;
i++)
2540 flags(chroma_weight_l0_flag[
i], 1,
i);
2542 for (
i = 0;
i < current->num_weights_l0;
i++) {
2543 if (current->luma_weight_l0_flag[
i]) {
2544 ses(delta_luma_weight_l0[
i], -128, 127, 1,
i);
2545 ses(luma_offset_l0[
i], -128, 127, 1,
i);
2547 infer(delta_luma_weight_l0[
i], 0);
2548 infer(luma_offset_l0[
i], 0);
2550 if (current->chroma_weight_l0_flag[
i]) {
2551 for (j = 0; j < 2; j++) {
2552 ses(delta_chroma_weight_l0[
i][j], -128, 127, 2,
i, j);
2553 ses(delta_chroma_offset_l0[
i][j], -4 * 128, 4 * 127, 2,
i, j);
2558 if (
pps->pps_weighted_bipred_flag &&
2559 ref_lists->rpl_ref_list[1].num_ref_entries > 0) {
2560 if (
pps->pps_wp_info_in_ph_flag) {
2561 ue(num_l1_weights, 0,
2562 FFMIN(15, ref_lists->rpl_ref_list[1].num_ref_entries));
2563 infer(num_weights_l1, current->num_l1_weights);
2565 infer(num_weights_l1, num_ref_idx_active[1]);
2568 infer(num_weights_l1, 0);
2571 for (
i = 0;
i < current->num_weights_l1;
i++)
2572 flags(luma_weight_l1_flag[
i], 1,
i);
2573 if (
sps->sps_chroma_format_idc != 0) {
2574 for (
i = 0;
i < current->num_weights_l1;
i++)
2575 flags(chroma_weight_l1_flag[
i], 1,
i);
2577 for (
i = 0;
i < current->num_weights_l1;
i++) {
2578 if (current->luma_weight_l1_flag[
i]) {
2579 ses(delta_luma_weight_l1[
i], -128, 127, 1,
i);
2580 ses(luma_offset_l1[
i], -128, 127, 1,
i);
2582 infer(delta_luma_weight_l1[
i], 0);
2583 infer(luma_offset_l1[
i], 0);
2585 if (current->chroma_weight_l1_flag[
i]) {
2586 for (j = 0; j < 2; j++) {
2587 ses(delta_chroma_weight_l1[
i][j], -128, 127, 2,
i, j);
2588 ses(delta_chroma_offset_l1[
i][j], -4 * 128, 4 * 127, 2,
i, j);
2602 unsigned int ctb_log2_size_y, min_cb_log2_size_y,
2603 min_qt_log2_size_intra_y, min_qt_log2_size_inter_y;
2604 uint8_t qp_bd_offset;
2606 flag(ph_gdr_or_irap_pic_flag);
2607 flag(ph_non_ref_pic_flag);
2608 if (current->ph_gdr_or_irap_pic_flag)
2609 flag(ph_gdr_pic_flag);
2611 infer(ph_gdr_pic_flag, 0);
2612 flag(ph_inter_slice_allowed_flag);
2613 if (current->ph_inter_slice_allowed_flag)
2614 flag(ph_intra_slice_allowed_flag);
2616 infer(ph_intra_slice_allowed_flag, 1);
2618 pps = h266->
pps[current->ph_pic_parameter_set_id];
2621 current->ph_pic_parameter_set_id);
2624 sps = h266->
sps[
pps->pps_seq_parameter_set_id];
2627 pps->pps_seq_parameter_set_id);
2630 vps = h266->
vps[
sps->sps_video_parameter_set_id];
2633 sps->sps_video_parameter_set_id);
2637 ub(
sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4, ph_pic_order_cnt_lsb);
2638 if (current->ph_gdr_pic_flag)
2639 ue(ph_recovery_poc_cnt, 0,
2640 1 << (
sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4));
2642 for (
i = 0;
i <
sps->sps_num_extra_ph_bytes * 8;
i++) {
2643 if (
sps->sps_extra_ph_bit_present_flag[
i])
2646 if (
sps->sps_poc_msb_cycle_flag) {
2647 flag(ph_poc_msb_cycle_present_flag);
2648 if (current->ph_poc_msb_cycle_present_flag)
2649 ub(
sps->sps_poc_msb_cycle_len_minus1 + 1, ph_poc_msb_cycle_val);
2651 if (
sps->sps_alf_enabled_flag &&
pps->pps_alf_info_in_ph_flag) {
2652 flag(ph_alf_enabled_flag);
2653 if (current->ph_alf_enabled_flag) {
2655 ub(3, ph_num_alf_aps_ids_luma);
2656 for (
i = 0;
i < current->ph_num_alf_aps_ids_luma;
i++)
2657 ubs(3, ph_alf_aps_id_luma[
i], 1,
i);
2659 if (
sps->sps_chroma_format_idc != 0) {
2660 flag(ph_alf_cb_enabled_flag);
2661 flag(ph_alf_cr_enabled_flag);
2663 infer(ph_alf_cb_enabled_flag, 0);
2664 infer(ph_alf_cr_enabled_flag, 0);
2667 if (current->ph_alf_cb_enabled_flag
2668 || current->ph_alf_cr_enabled_flag) {
2669 ub(3, ph_alf_aps_id_chroma);
2672 if (
sps->sps_ccalf_enabled_flag) {
2673 flag(ph_alf_cc_cb_enabled_flag);
2674 if (current->ph_alf_cc_cb_enabled_flag)
2675 ub(3, ph_alf_cc_cb_aps_id);
2676 flag(ph_alf_cc_cr_enabled_flag);
2677 if (current->ph_alf_cc_cr_enabled_flag)
2678 ub(3, ph_alf_cc_cr_aps_id);
2682 infer(ph_alf_enabled_flag, 0);
2684 if (
sps->sps_lmcs_enabled_flag) {
2685 flag(ph_lmcs_enabled_flag);
2686 if (current->ph_lmcs_enabled_flag) {
2687 ub(2, ph_lmcs_aps_id);
2688 if (
sps->sps_chroma_format_idc != 0)
2689 flag(ph_chroma_residual_scale_flag);
2691 infer(ph_chroma_residual_scale_flag, 0);
2694 infer(ph_lmcs_enabled_flag, 0);
2695 infer(ph_chroma_residual_scale_flag, 0);
2698 if (
sps->sps_explicit_scaling_list_enabled_flag) {
2699 flag(ph_explicit_scaling_list_enabled_flag);
2700 if (current->ph_explicit_scaling_list_enabled_flag) {
2702 ub(3, ph_scaling_list_aps_id);
2705 infer(ph_explicit_scaling_list_enabled_flag, 0);
2707 if (
sps->sps_virtual_boundaries_enabled_flag &&
2708 !
sps->sps_virtual_boundaries_present_flag) {
2709 flag(ph_virtual_boundaries_present_flag);
2710 if (current->ph_virtual_boundaries_present_flag) {
2711 ue(ph_num_ver_virtual_boundaries,
2712 0,
pps->pps_pic_width_in_luma_samples <= 8 ? 0 : 3);
2713 for (
i = 0;
i < current->ph_num_ver_virtual_boundaries;
i++) {
2714 ues(ph_virtual_boundary_pos_x_minus1[
i],
2715 0, (
pps->pps_pic_width_in_luma_samples + 7) / 8 - 2, 1,
i);
2717 ue(ph_num_hor_virtual_boundaries,
2718 0,
pps->pps_pic_height_in_luma_samples <= 8 ? 0 : 3);
2719 for (
i = 0;
i < current->ph_num_hor_virtual_boundaries;
i++) {
2720 ues(ph_virtual_boundary_pos_y_minus1[
i],
2721 0, (
pps->pps_pic_height_in_luma_samples + 7) / 8 - 2, 1,
i);
2724 infer(ph_num_ver_virtual_boundaries, 0);
2725 infer(ph_num_hor_virtual_boundaries, 0);
2728 if (
pps->pps_output_flag_present_flag && !current->ph_non_ref_pic_flag)
2729 flag(ph_pic_output_flag);
2731 infer(ph_pic_output_flag, 1);
2732 if (
pps->pps_rpl_info_in_ph_flag) {
2734 (
ctx, rw,
sps,
pps, ¤t->ph_ref_pic_lists));
2736 if (
sps->sps_partition_constraints_override_enabled_flag)
2737 flag(ph_partition_constraints_override_flag);
2739 infer(ph_partition_constraints_override_flag, 0);
2741 ctb_log2_size_y =
sps->sps_log2_ctu_size_minus5 + 5;
2742 min_cb_log2_size_y =
sps->sps_log2_min_luma_coding_block_size_minus2 + 2;
2743 if (current->ph_intra_slice_allowed_flag) {
2744 if (current->ph_partition_constraints_override_flag) {
2745 ue(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2746 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2747 ue(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2748 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2749 if (current->ph_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
2750 min_qt_log2_size_intra_y =
2751 current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2753 ue(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2754 0, (
sps->sps_qtbtt_dual_tree_intra_flag ?
2755 FFMIN(6, ctb_log2_size_y) :
2756 ctb_log2_size_y) - min_qt_log2_size_intra_y);
2757 ue(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2758 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
2760 infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2761 sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2762 infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2763 sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2765 if (
sps->sps_qtbtt_dual_tree_intra_flag) {
2766 ue(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2767 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2768 ue(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2769 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2770 if (
sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
2771 unsigned int min_qt_log2_size_intra_c =
2772 sps->sps_log2_diff_min_qt_min_cb_intra_slice_chroma +
2774 ue(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2775 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2776 ue(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2777 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2779 infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2780 sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2781 infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2782 sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2786 infer(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2787 sps->sps_log2_diff_min_qt_min_cb_intra_slice_luma);
2788 infer(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2789 sps->sps_max_mtt_hierarchy_depth_intra_slice_luma);
2790 infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2791 sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2792 infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2793 sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2794 infer(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2795 sps->sps_log2_diff_min_qt_min_cb_intra_slice_chroma);
2796 infer(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2797 sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma);
2798 infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2799 sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2800 infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2801 sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2804 min_qt_log2_size_intra_y =
2805 current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2807 if (
pps->pps_cu_qp_delta_enabled_flag)
2808 ue(ph_cu_qp_delta_subdiv_intra_slice, 0,
2809 2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2810 current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2812 infer(ph_cu_qp_delta_subdiv_intra_slice, 0);
2814 if (
pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2815 ue(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0,
2816 2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2817 current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2819 infer(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0);
2821 if (current->ph_inter_slice_allowed_flag) {
2822 if (current->ph_partition_constraints_override_flag) {
2823 ue(ph_log2_diff_min_qt_min_cb_inter_slice,
2824 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2825 min_qt_log2_size_inter_y =
2826 current->ph_log2_diff_min_qt_min_cb_inter_slice +
2828 ue(ph_max_mtt_hierarchy_depth_inter_slice, 0,
2829 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2830 if (current->ph_max_mtt_hierarchy_depth_inter_slice != 0) {
2831 ue(ph_log2_diff_max_bt_min_qt_inter_slice,
2832 0, ctb_log2_size_y - min_qt_log2_size_inter_y);
2833 ue(ph_log2_diff_max_tt_min_qt_inter_slice,
2834 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
2837 infer(ph_log2_diff_min_qt_min_cb_inter_slice,
2838 sps->sps_log2_diff_min_qt_min_cb_inter_slice);
2839 min_qt_log2_size_inter_y =
2840 current->ph_log2_diff_min_qt_min_cb_inter_slice +
2842 infer(ph_max_mtt_hierarchy_depth_inter_slice,
2843 sps->sps_max_mtt_hierarchy_depth_inter_slice);
2844 infer(ph_log2_diff_max_bt_min_qt_inter_slice,
2845 sps->sps_log2_diff_max_bt_min_qt_inter_slice);
2846 infer(ph_log2_diff_max_tt_min_qt_inter_slice,
2847 sps->sps_log2_diff_max_tt_min_qt_inter_slice);
2850 if (
pps->pps_cu_qp_delta_enabled_flag)
2851 ue(ph_cu_qp_delta_subdiv_inter_slice, 0,
2852 2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2853 current->ph_max_mtt_hierarchy_depth_inter_slice));
2855 infer(ph_cu_qp_delta_subdiv_inter_slice, 0);
2857 if (
pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2858 ue(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0,
2859 2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2860 current->ph_max_mtt_hierarchy_depth_inter_slice));
2862 infer(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0);
2863 if (
sps->sps_temporal_mvp_enabled_flag) {
2864 flag(ph_temporal_mvp_enabled_flag);
2865 if (current->ph_temporal_mvp_enabled_flag &&
2866 pps->pps_rpl_info_in_ph_flag) {
2867 if (current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0)
2868 flag(ph_collocated_from_l0_flag);
2870 infer(ph_collocated_from_l0_flag, 1);
2871 if ((current->ph_collocated_from_l0_flag &&
2872 current->ph_ref_pic_lists.rpl_ref_list[0].num_ref_entries > 1)
2873 || (!current->ph_collocated_from_l0_flag &&
2874 current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 1)) {
2876 current->ph_collocated_from_l0_flag ? 0 : 1;
2877 ue(ph_collocated_ref_idx, 0,
2878 current->ph_ref_pic_lists.rpl_ref_list[idx].
2879 num_ref_entries - 1);
2881 infer(ph_collocated_ref_idx, 0);
2885 if (
sps->sps_mmvd_fullpel_only_enabled_flag)
2886 flag(ph_mmvd_fullpel_only_flag);
2888 infer(ph_mmvd_fullpel_only_flag, 0);
2889 if (!
pps->pps_rpl_info_in_ph_flag ||
2890 current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0) {
2891 flag(ph_mvd_l1_zero_flag);
2892 if (
sps->sps_bdof_control_present_in_ph_flag) {
2893 flag(ph_bdof_disabled_flag);
2895 if (!
sps->sps_bdof_control_present_in_ph_flag)
2896 infer(ph_bdof_disabled_flag,
2897 1 -
sps->sps_bdof_enabled_flag);
2899 infer(ph_bdof_disabled_flag, 1);
2901 if (
sps->sps_dmvr_control_present_in_ph_flag) {
2902 flag(ph_dmvr_disabled_flag);
2904 if (!
sps->sps_dmvr_control_present_in_ph_flag)
2905 infer(ph_dmvr_disabled_flag,
2906 1 -
sps->sps_dmvr_enabled_flag);
2908 infer(ph_dmvr_disabled_flag, 1);
2911 infer(ph_mvd_l1_zero_flag, 1);
2913 if (
sps->sps_prof_control_present_in_ph_flag)
2914 flag(ph_prof_disabled_flag);
2916 infer(ph_prof_disabled_flag, !
sps->sps_affine_prof_enabled_flag);
2917 if ((
pps->pps_weighted_pred_flag ||
2918 pps->pps_weighted_bipred_flag) &&
pps->pps_wp_info_in_ph_flag) {
2922 uint8_t num_ref_idx_active[2] = { 0, 0 };
2924 (
ctx, rw,
sps,
pps, ¤t->ph_ref_pic_lists,
2925 num_ref_idx_active, ¤t->ph_pred_weight_table));
2929 qp_bd_offset = 6 *
sps->sps_bitdepth_minus8;
2930 if (
pps->pps_qp_delta_info_in_ph_flag)
2931 se(ph_qp_delta, -qp_bd_offset - (26 +
pps->pps_init_qp_minus26),
2932 63 - (26 +
pps->pps_init_qp_minus26));
2934 if (
sps->sps_joint_cbcr_enabled_flag)
2935 flag(ph_joint_cbcr_sign_flag);
2937 infer(ph_joint_cbcr_sign_flag, 0);
2938 if (
sps->sps_sao_enabled_flag &&
pps->pps_sao_info_in_ph_flag) {
2939 flag(ph_sao_luma_enabled_flag);
2940 if (
sps->sps_chroma_format_idc != 0)
2941 flag(ph_sao_chroma_enabled_flag);
2943 infer(ph_sao_chroma_enabled_flag, 0);
2945 infer(ph_sao_luma_enabled_flag, 0);
2946 infer(ph_sao_chroma_enabled_flag, 0);
2949 if (
pps->pps_dbf_info_in_ph_flag)
2950 flag(ph_deblocking_params_present_flag);
2952 infer(ph_deblocking_params_present_flag, 0);
2954 if (current->ph_deblocking_params_present_flag) {
2955 if (!
pps->pps_deblocking_filter_disabled_flag) {
2956 flag(ph_deblocking_filter_disabled_flag);
2957 if (!current->ph_deblocking_filter_disabled_flag) {
2958 se(ph_luma_beta_offset_div2, -12, 12);
2959 se(ph_luma_tc_offset_div2, -12, 12);
2960 if (
pps->pps_chroma_tool_offsets_present_flag) {
2961 se(ph_cb_beta_offset_div2, -12, 12);
2962 se(ph_cb_tc_offset_div2, -12, 12);
2963 se(ph_cr_beta_offset_div2, -12, 12);
2964 se(ph_cr_tc_offset_div2, -12, 12);
2966 infer(ph_cb_beta_offset_div2,
2967 current->ph_luma_beta_offset_div2);
2968 infer(ph_cb_tc_offset_div2,
2969 current->ph_luma_tc_offset_div2);
2970 infer(ph_cr_beta_offset_div2,
2971 current->ph_luma_beta_offset_div2);
2972 infer(ph_cr_tc_offset_div2,
2973 current->ph_luma_tc_offset_div2);
2977 infer(ph_deblocking_filter_disabled_flag, 0);
2980 infer(ph_deblocking_filter_disabled_flag,
pps->pps_deblocking_filter_disabled_flag);
2981 if (!current->ph_deblocking_filter_disabled_flag) {
2982 infer(ph_luma_beta_offset_div2,
pps->pps_luma_beta_offset_div2);
2983 infer(ph_luma_tc_offset_div2,
pps->pps_luma_tc_offset_div2);
2984 infer(ph_cb_beta_offset_div2,
pps->pps_cb_beta_offset_div2);
2985 infer(ph_cb_tc_offset_div2,
pps->pps_cb_tc_offset_div2);
2986 infer(ph_cr_beta_offset_div2,
pps->pps_cr_beta_offset_div2);
2987 infer(ph_cr_tc_offset_div2,
pps->pps_cr_tc_offset_div2);
2991 if (
pps->pps_picture_header_extension_present_flag) {
2992 ue(ph_extension_length, 0, 256);
2993 for (
i = 0;
i < current->ph_extension_length;
i++)
2994 us(8, ph_extension_data_byte[
i], 0x00, 0xff, 1,
i);
3005 HEADER(
"Picture Header");
3022 uint8_t nal_unit_type, qp_bd_offset;
3023 uint16_t curr_subpic_idx;
3024 uint16_t num_slices_in_subpic;
3030 flag(sh_picture_header_in_slice_header_flag);
3031 if (current->sh_picture_header_in_slice_header_flag) {
3034 ph = ¤t->sh_picture_header;
3039 "Picture header not available.\n");
3044 pps = h266->
pps[
ph->ph_pic_parameter_set_id];
3047 ph->ph_pic_parameter_set_id);
3050 sps = h266->
sps[
pps->pps_seq_parameter_set_id];
3053 pps->pps_seq_parameter_set_id);
3057 if (
sps->sps_subpic_info_present_flag) {
3058 ub(
sps->sps_subpic_id_len_minus1 + 1, sh_subpic_id);
3059 for (
i = 0;
i <=
sps->sps_num_subpics_minus1;
i++) {
3060 if (
pps->sub_pic_id_val[
i] == current->sh_subpic_id) {
3061 curr_subpic_idx =
i;
3065 if (
i >
sps->sps_num_subpics_minus1) {
3070 curr_subpic_idx = 0;
3073 num_slices_in_subpic =
pps->num_slices_in_subpic[curr_subpic_idx];
3075 if ((
pps->pps_rect_slice_flag && num_slices_in_subpic > 1) ||
3076 (!
pps->pps_rect_slice_flag &&
pps->num_tiles_in_pic > 1)) {
3078 if (!
pps->pps_rect_slice_flag) {
3080 max =
pps->num_tiles_in_pic - 1;
3083 max = num_slices_in_subpic - 1;
3087 infer(sh_slice_address, 0);
3090 for (
i = 0;
i <
sps->sps_num_extra_sh_bytes * 8;
i++) {
3091 if (
sps->sps_extra_sh_bit_present_flag[
i])
3095 if (!
pps->pps_rect_slice_flag &&
3096 pps->num_tiles_in_pic - current->sh_slice_address > 1)
3097 ue(sh_num_tiles_in_slice_minus1, 0,
pps->num_tiles_in_pic - 1);
3099 infer(sh_num_tiles_in_slice_minus1, 0);
3101 if (
ph->ph_inter_slice_allowed_flag)
3102 ue(sh_slice_type, 0, 2);
3104 infer(sh_slice_type, 2);
3106 nal_unit_type = current->nal_unit_header.nal_unit_type;
3109 flag(sh_no_output_of_prior_pics_flag);
3111 if (
sps->sps_alf_enabled_flag) {
3112 if (!
pps->pps_alf_info_in_ph_flag) {
3113 flag(sh_alf_enabled_flag);
3114 if (current->sh_alf_enabled_flag) {
3115 ub(3, sh_num_alf_aps_ids_luma);
3116 for (
i = 0;
i < current->sh_num_alf_aps_ids_luma;
i++)
3117 ubs(3, sh_alf_aps_id_luma[
i], 1,
i);
3119 if (
sps->sps_chroma_format_idc != 0) {
3120 flag(sh_alf_cb_enabled_flag);
3121 flag(sh_alf_cr_enabled_flag);
3123 if (current->sh_alf_cb_enabled_flag ||
3124 current->sh_alf_cr_enabled_flag) {
3125 ub(3, sh_alf_aps_id_chroma);
3128 if (
sps->sps_ccalf_enabled_flag) {
3129 flag(sh_alf_cc_cb_enabled_flag);
3130 if (current->sh_alf_cc_cb_enabled_flag)
3131 ub(3, sh_alf_cc_cb_aps_id);
3133 flag(sh_alf_cc_cr_enabled_flag);
3134 if (current->sh_alf_cc_cr_enabled_flag)
3135 ub(3, sh_alf_cc_cr_aps_id);
3139 infer(sh_alf_enabled_flag,
ph->ph_alf_enabled_flag);
3140 if (current->sh_alf_enabled_flag) {
3141 infer(sh_num_alf_aps_ids_luma,
ph->ph_num_alf_aps_ids_luma);
3142 for (
i = 0;
i < current->sh_num_alf_aps_ids_luma;
i++)
3143 infer(sh_alf_aps_id_luma[
i],
ph->ph_alf_aps_id_luma[
i]);
3145 infer(sh_alf_cb_enabled_flag,
ph->ph_alf_cb_enabled_flag);
3146 infer(sh_alf_cr_enabled_flag,
ph->ph_alf_cr_enabled_flag);
3147 if (current->sh_alf_cb_enabled_flag ||current->sh_alf_cr_enabled_flag)
3148 infer(sh_alf_aps_id_chroma,
ph->ph_alf_aps_id_chroma);
3150 if (
sps->sps_ccalf_enabled_flag) {
3151 infer(sh_alf_cc_cb_enabled_flag,
ph->ph_alf_cc_cb_enabled_flag);
3152 if (current->sh_alf_cc_cb_enabled_flag)
3153 infer(sh_alf_cc_cb_aps_id,
ph->ph_alf_cc_cb_aps_id);
3155 infer(sh_alf_cc_cr_enabled_flag,
ph->ph_alf_cc_cr_enabled_flag);
3156 if (current->sh_alf_cc_cr_enabled_flag)
3157 infer(sh_alf_cc_cr_aps_id,
ph->ph_alf_cc_cr_aps_id);
3163 if (current->sh_picture_header_in_slice_header_flag) {
3164 infer(sh_lmcs_used_flag,
ph->ph_lmcs_enabled_flag);
3165 infer(sh_explicit_scaling_list_used_flag,
3166 ph->ph_explicit_scaling_list_enabled_flag);
3168 if (
ph->ph_lmcs_enabled_flag)
3169 flag(sh_lmcs_used_flag);
3171 infer(sh_lmcs_used_flag, 0);
3173 if (
ph->ph_explicit_scaling_list_enabled_flag)
3174 flag(sh_explicit_scaling_list_used_flag);
3176 infer(sh_explicit_scaling_list_used_flag, 0);
3179 if (!
pps->pps_rpl_info_in_ph_flag &&
3183 (
ctx, rw,
sps,
pps, ¤t->sh_ref_pic_lists));
3192 flag(sh_num_ref_idx_active_override_flag);
3193 if (current->sh_num_ref_idx_active_override_flag) {
3197 ues(sh_num_ref_idx_active_minus1[
i], 0, 14, 1,
i);
3199 infer(sh_num_ref_idx_active_minus1[
i], 0);
3202 infer(sh_num_ref_idx_active_override_flag, 1);
3205 for (
i = 0;
i < 2;
i++) {
3208 if (current->sh_num_ref_idx_active_override_flag) {
3209 current->num_ref_idx_active[
i] = current->sh_num_ref_idx_active_minus1[
i] + 1;
3211 current->num_ref_idx_active[
i] =
3213 pps->pps_num_ref_idx_default_active_minus1[
i] + 1);
3216 current->num_ref_idx_active[
i] = 0;
3221 if (
pps->pps_cabac_init_present_flag)
3222 flag(sh_cabac_init_flag);
3224 infer(sh_cabac_init_flag, 0);
3225 if (
ph->ph_temporal_mvp_enabled_flag && !
pps->pps_rpl_info_in_ph_flag) {
3227 flag(sh_collocated_from_l0_flag);
3229 infer(sh_collocated_from_l0_flag, 1);
3230 if ((current->sh_collocated_from_l0_flag &&
3231 current->num_ref_idx_active[0] > 1) ||
3232 (!current->sh_collocated_from_l0_flag &&
3233 current->num_ref_idx_active[1] > 1)) {
3234 unsigned int idx = current->sh_collocated_from_l0_flag ? 0 : 1;
3235 ue(sh_collocated_ref_idx, 0, current->num_ref_idx_active[idx] - 1);
3237 infer(sh_collocated_ref_idx, 0);
3240 if (!
pps->pps_wp_info_in_ph_flag &&
3241 ((
pps->pps_weighted_pred_flag &&
3243 (
pps->pps_weighted_bipred_flag &&
3246 current->num_ref_idx_active,
3247 ¤t->sh_pred_weight_table));
3250 qp_bd_offset = 6 *
sps->sps_bitdepth_minus8;
3251 if (!
pps->pps_qp_delta_info_in_ph_flag)
3252 se(sh_qp_delta, -qp_bd_offset - (26 +
pps->pps_init_qp_minus26),
3253 63 - (26 +
pps->pps_init_qp_minus26));
3254 if (
pps->pps_slice_chroma_qp_offsets_present_flag) {
3257 se(sh_cb_qp_offset, -12, 12);
3258 off =
pps->pps_cb_qp_offset + current->sh_cb_qp_offset;
3259 if (off < -12 || off > 12) {
3261 "pps_cb_qp_offset + sh_cb_qp_offset (%d) not in range [-12, 12].\n",
3266 se(sh_cr_qp_offset, -12, 12);
3267 off =
pps->pps_cr_qp_offset + current->sh_cr_qp_offset;
3268 if (off < -12 || off > 12) {
3270 "pps_cr_qp_offset + sh_cr_qp_offset (%d) not in range [-12, 12].\n",
3275 if (
sps->sps_joint_cbcr_enabled_flag) {
3276 se(sh_joint_cbcr_qp_offset, -12, 12);
3278 pps->pps_joint_cbcr_qp_offset_value +
3279 current->sh_joint_cbcr_qp_offset;
3280 if (off < -12 || off > 12) {
3282 "pps_joint_cbcr_qp_offset_value + sh_joint_cbcr_qp_offset (%d)"
3283 "not in range [-12, 12]. \n", off);
3287 infer(sh_joint_cbcr_qp_offset, 0);
3290 infer(sh_cb_qp_offset, 0);
3291 infer(sh_cr_qp_offset, 0);
3292 infer(sh_joint_cbcr_qp_offset, 0);
3294 if (
pps->pps_cu_chroma_qp_offset_list_enabled_flag)
3295 flag(sh_cu_chroma_qp_offset_enabled_flag);
3297 infer(sh_cu_chroma_qp_offset_enabled_flag, 0);
3298 if (
sps->sps_sao_enabled_flag && !
pps->pps_sao_info_in_ph_flag) {
3299 flag(sh_sao_luma_used_flag);
3300 if (
sps->sps_chroma_format_idc != 0)
3301 flag(sh_sao_chroma_used_flag);
3303 infer(sh_sao_chroma_used_flag,
ph->ph_sao_chroma_enabled_flag);
3305 infer(sh_sao_luma_used_flag,
ph->ph_sao_luma_enabled_flag);
3306 infer(sh_sao_chroma_used_flag,
ph->ph_sao_chroma_enabled_flag);
3309 if (
pps->pps_deblocking_filter_override_enabled_flag &&
3310 !
pps->pps_dbf_info_in_ph_flag)
3311 flag(sh_deblocking_params_present_flag);
3313 infer(sh_deblocking_params_present_flag, 0);
3314 if (current->sh_deblocking_params_present_flag) {
3315 if (!
pps->pps_deblocking_filter_disabled_flag)
3316 flag(sh_deblocking_filter_disabled_flag);
3318 infer(sh_deblocking_filter_disabled_flag, 0);
3319 if (!current->sh_deblocking_filter_disabled_flag) {
3320 se(sh_luma_beta_offset_div2, -12, 12);
3321 se(sh_luma_tc_offset_div2, -12, 12);
3322 if (
pps->pps_chroma_tool_offsets_present_flag) {
3323 se(sh_cb_beta_offset_div2, -12, 12);
3324 se(sh_cb_tc_offset_div2, -12, 12);
3325 se(sh_cr_beta_offset_div2, -12, 12);
3326 se(sh_cr_tc_offset_div2, -12, 12);
3328 infer(sh_cb_beta_offset_div2,
3329 current->sh_luma_beta_offset_div2);
3330 infer(sh_cb_tc_offset_div2, current->sh_luma_tc_offset_div2);
3331 infer(sh_cr_beta_offset_div2,
3332 current->sh_luma_beta_offset_div2);
3333 infer(sh_cr_tc_offset_div2, current->sh_luma_tc_offset_div2);
3337 infer(sh_deblocking_filter_disabled_flag,
ph->ph_deblocking_filter_disabled_flag);
3338 if (!current->sh_deblocking_filter_disabled_flag) {
3339 infer(sh_luma_beta_offset_div2,
ph->ph_luma_beta_offset_div2);
3340 infer(sh_luma_tc_offset_div2,
ph->ph_luma_tc_offset_div2);
3341 infer(sh_cb_beta_offset_div2,
ph->ph_cb_beta_offset_div2);
3342 infer(sh_cb_tc_offset_div2,
ph->ph_cb_tc_offset_div2);
3343 infer(sh_cr_beta_offset_div2,
ph->ph_cr_beta_offset_div2);
3344 infer(sh_cr_tc_offset_div2,
ph->ph_cr_tc_offset_div2);
3348 if (
sps->sps_dep_quant_enabled_flag)
3349 flag(sh_dep_quant_used_flag);
3351 infer(sh_dep_quant_used_flag, 0);
3353 if (
sps->sps_sign_data_hiding_enabled_flag &&
3354 !current->sh_dep_quant_used_flag)
3355 flag(sh_sign_data_hiding_used_flag);
3357 infer(sh_sign_data_hiding_used_flag, 0);
3359 if (
sps->sps_transform_skip_enabled_flag &&
3360 !current->sh_dep_quant_used_flag &&
3361 !current->sh_sign_data_hiding_used_flag)
3362 flag(sh_ts_residual_coding_disabled_flag);
3364 infer(sh_ts_residual_coding_disabled_flag, 0);
3366 if (!current->sh_ts_residual_coding_disabled_flag &&
3367 sps->sps_ts_residual_coding_rice_present_in_sh_flag)
3368 ub(3, sh_ts_residual_coding_rice_idx_minus1);
3370 infer(sh_ts_residual_coding_rice_idx_minus1, 0);
3372 if (
sps->sps_reverse_last_sig_coeff_enabled_flag)
3373 flag(sh_reverse_last_sig_coeff_flag);
3375 infer(sh_reverse_last_sig_coeff_flag, 0);
3377 if (
pps->pps_slice_header_extension_present_flag) {
3378 ue(sh_slice_header_extension_length, 0, 256);
3379 for (
i = 0;
i < current->sh_slice_header_extension_length;
i++)
3380 us(8, sh_slice_header_extension_data_byte[
i], 0x00, 0xff, 1,
i);
3383 current->num_entry_points = 0;
3384 if (
sps->sps_entry_point_offsets_present_flag) {
3385 uint8_t entropy_sync =
sps->sps_entropy_coding_sync_enabled_flag;
3387 if (
pps->pps_rect_slice_flag) {
3389 int slice_idx = current->sh_slice_address;
3390 for (
i = 0;
i < curr_subpic_idx;
i++) {
3391 slice_idx +=
pps->num_slices_in_subpic[
i];
3394 pps->pps_slice_width_in_tiles_minus1[slice_idx] + 1;
3397 height =
pps->slice_height_in_ctus[slice_idx];
3399 height =
pps->pps_slice_height_in_tiles_minus1[slice_idx] + 1;
3401 current->num_entry_points = width_in_tiles *
height;
3405 for (tile_idx = current->sh_slice_address;
3407 current->sh_slice_address +
3408 current->sh_num_tiles_in_slice_minus1; tile_idx++) {
3409 tile_y = tile_idx /
pps->num_tile_rows;
3411 current->num_entry_points += (entropy_sync ?
height : 1);
3414 current->num_entry_points--;
3417 "%" PRIu16
".\n", current->num_entry_points);
3420 if (current->num_entry_points > 0) {
3421 ue(sh_entry_offset_len_minus1, 0, 31);
3422 for (
i = 0;
i < current->num_entry_points;
i++) {
3423 ubs(current->sh_entry_offset_len_minus1 + 1,
3424 sh_entry_point_offset_minus1[
i], 1,
i);
3440 HEADER(
"Decoded Picture Hash");
3442 u(8, dph_sei_hash_type, 0, 2);
3443 flag(dph_sei_single_component_flag);
3444 ub(7, dph_sei_reserved_zero_7bits);
3449 for (
i = 0;
i < 16;
i++)
3450 us(8, dph_sei_picture_md5[c_idx][
i], 0x00, 0xff, 2, c_idx,
i);
3452 us(16, dph_sei_picture_crc[c_idx], 0x0000, 0xffff, 1, c_idx);
3454 us(32, dph_sei_picture_checksum[c_idx], 0x00000000, 0xffffffff, 1,
3467 HEADER(
"Prefix Supplemental Enhancement Information");
3469 HEADER(
"Suffix Supplemental Enhancement Information");