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);
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);
728 "vps_layer_id[%d](%d) should > vps_layer_id[%d](%d).\n",
733 if (
i > 0 && !
current->vps_all_independent_layers_flag) {
734 flags(vps_independent_layer_flag[
i], 1,
i);
735 if (!
current->vps_independent_layer_flag[
i]) {
736 flags(vps_max_tid_ref_present_flag[
i], 1,
i);
737 for (j = 0; j <
i; j++) {
738 flags(vps_direct_ref_layer_flag[
i][j], 2,
i, j);
739 if (
current->vps_max_tid_ref_present_flag[
i] &&
740 current->vps_direct_ref_layer_flag[
i][j]) {
741 ubs(3, vps_max_tid_il_ref_pics_plus1[
i][j], 2,
i, j);
743 infer(vps_max_tid_il_ref_pics_plus1[
i][j],
744 current->vps_max_sublayers_minus1 + 1);
748 for (j = 0; j <
i; j++) {
749 infer(vps_direct_ref_layer_flag[
i][j], 0);
753 infer(vps_independent_layer_flag[
i], 1);
754 for (j = 0; j <
i; j++) {
755 infer(vps_direct_ref_layer_flag[
i][j], 0);
760 if (
current->vps_max_layers_minus1 > 0) {
761 if (
current->vps_all_independent_layers_flag)
762 flag(vps_each_layer_is_an_ols_flag);
764 infer(vps_each_layer_is_an_ols_flag, 0);
765 if (!
current->vps_each_layer_is_an_ols_flag) {
766 if (!
current->vps_all_independent_layers_flag)
767 ub(2, vps_ols_mode_idc);
769 infer(vps_ols_mode_idc, 2);
770 if (
current->vps_ols_mode_idc == 2) {
771 ub(8, vps_num_output_layer_sets_minus2);
772 for (
i = 1;
i <=
current->vps_num_output_layer_sets_minus2 + 1;
774 for (j = 0; j <=
current->vps_max_layers_minus1; j++)
775 flags(vps_ols_output_layer_flag[
i][j], 2,
i, j);
777 ols_mode_idc =
current->vps_ols_mode_idc;
781 if (ols_mode_idc == 4 || ols_mode_idc == 0 || ols_mode_idc == 1)
782 total_num_olss =
current->vps_max_layers_minus1 + 1;
783 else if (ols_mode_idc == 2)
784 total_num_olss =
current->vps_num_output_layer_sets_minus2 + 2;
787 "ols_mode_idc == 3, patch welcome");
788 u(8, vps_num_ptls_minus1, 0, total_num_olss - 1);
790 infer(vps_each_layer_is_an_ols_flag, 1);
791 infer(vps_num_ptls_minus1, 0);
794 for (
i = 0;
i <=
current->vps_num_ptls_minus1;
i++) {
796 flags(vps_pt_present_flag[
i], 1,
i);
798 infer(vps_pt_present_flag[
i], 1);
800 if (!
current->vps_default_ptl_dpb_hrd_max_tid_flag)
801 us(3, vps_ptl_max_tid[
i], 0,
current->vps_max_sublayers_minus1, 1,
i);
803 infer(vps_ptl_max_tid[
i],
current->vps_max_sublayers_minus1);
806 fixed(1, vps_ptl_alignment_zero_bit, 0);
817 for (
i = 0;
i <=
current->vps_max_layers_minus1;
i++) {
818 for (j = 0; j <=
current->vps_max_layers_minus1; j++) {
819 dependency_flag[
i][j] =
current->vps_direct_ref_layer_flag[
i][j];
820 for (k = 0; k <
i; k++) {
821 if (
current->vps_direct_ref_layer_flag[
i][k] &&
822 dependency_flag[k][j])
823 dependency_flag[
i][j] = 1;
827 for (
i = 0;
i <=
current->vps_max_layers_minus1;
i++) {
829 for (j = 0,
r = 0; j <=
current->vps_max_layers_minus1; j++) {
830 if (dependency_flag[
i][j])
831 reference_layer_idx[
i][
r++] = j;
833 num_ref_layers[
i] =
r;
837 num_output_layers_in_ols[0] = 1;
838 num_sub_layers_in_layer_in_ols[0][0] =
840 for (
i = 1;
i < total_num_olss;
i++) {
841 if (ols_mode_idc == 4 || ols_mode_idc == 0) {
842 num_output_layers_in_ols[
i] = 1;
843 if (
current->vps_each_layer_is_an_ols_flag) {
844 num_sub_layers_in_layer_in_ols[
i][0] =
847 num_sub_layers_in_layer_in_ols[
i][
i] =
849 for (k =
i - 1; k >= 0; k--) {
850 num_sub_layers_in_layer_in_ols[
i][k] = 0;
851 for (m = k + 1; m <=
i; m++) {
852 uint8_t max_sublayer_needed =
853 FFMIN(num_sub_layers_in_layer_in_ols[
i][m],
854 current->vps_max_tid_il_ref_pics_plus1[m][k]);
855 if (
current->vps_direct_ref_layer_flag[m][k] &&
856 num_sub_layers_in_layer_in_ols[
i][k] < max_sublayer_needed)
857 num_sub_layers_in_layer_in_ols[
i][k] = max_sublayer_needed;
861 }
else if (
current->vps_ols_mode_idc == 1) {
862 num_output_layers_in_ols[
i] =
i + 1;
863 for (j = 0; j < num_output_layers_in_ols[
i]; j++) {
864 num_sub_layers_in_layer_in_ols[
i][j] =
867 }
else if (
current->vps_ols_mode_idc == 2) {
868 uint8_t highest_included_layer = 0;
869 for (j = 0; j <=
current->vps_max_layers_minus1; j++) {
870 layer_included_in_ols_flag[
i][j] = 0;
871 num_sub_layers_in_layer_in_ols[
i][j] = 0;
873 for (k = 0, j = 0; k <=
current->vps_max_layers_minus1; k++) {
874 if (
current->vps_ols_output_layer_flag[
i][k]) {
875 layer_included_in_ols_flag[
i][k] = 1;
876 highest_included_layer = k;
877 output_layer_idx[
i][j] = k;
878 num_sub_layers_in_layer_in_ols[
i][k] =
880 vps_ols_ptl_idx[
i]] + 1;
884 num_output_layers_in_ols[
i] = j;
885 for (j = 0; j < num_output_layers_in_ols[
i]; j++) {
886 int idx = output_layer_idx[
i][j];
887 for (k = 0; k < num_ref_layers[idx]; k++) {
888 if (!layer_included_in_ols_flag[
i][reference_layer_idx[idx][k]])
889 layer_included_in_ols_flag[
i][reference_layer_idx[idx][k]] = 1;
892 for (k = highest_included_layer - 1; k >= 0; k--) {
893 if (layer_included_in_ols_flag[
i][k] &&
894 !
current->vps_ols_output_layer_flag[
i][k]) {
895 for (m = k + 1; m <= highest_included_layer; m++) {
896 uint8_t max_sublayer_needed =
897 FFMIN(num_sub_layers_in_layer_in_ols[
i][m],
898 current->vps_max_tid_il_ref_pics_plus1[m][k]);
899 if (
current->vps_direct_ref_layer_flag[m][k] &&
900 layer_included_in_ols_flag[
i][m] &&
901 num_sub_layers_in_layer_in_ols[
i][k] <
903 num_sub_layers_in_layer_in_ols[
i][k] =
909 if (!num_output_layers_in_ols[
i])
912 for (
i = 1;
i < total_num_olss;
i++) {
913 int num_layers_in_ols = 0;
914 if (
current->vps_each_layer_is_an_ols_flag) {
915 num_layers_in_ols = 1;
916 }
else if (
current->vps_ols_mode_idc == 0 ||
917 current->vps_ols_mode_idc == 1) {
918 num_layers_in_ols =
i + 1;
919 }
else if (
current->vps_ols_mode_idc == 2) {
920 for (k = 0, j = 0; k <=
current->vps_max_layers_minus1; k++)
921 if (layer_included_in_ols_flag[
i][k])
923 num_layers_in_ols = j;
925 if (num_layers_in_ols > 1) {
926 num_multi_layer_olss++;
929 if (!
current->vps_each_layer_is_an_ols_flag && num_multi_layer_olss == 0)
934 (
current->vps_num_ptls_minus1 + 1) *
935 sizeof(*
current->vps_profile_tier_level));
936 for (
i = 0;
i <=
current->vps_num_ptls_minus1;
i++) {
938 current->vps_profile_tier_level +
i,
942 for (
i = 0;
i < total_num_olss;
i++) {
943 if (
current->vps_num_ptls_minus1 > 0 &&
944 current->vps_num_ptls_minus1 + 1 != total_num_olss) {
945 us(8, vps_ols_ptl_idx[
i], 0,
current->vps_num_ptls_minus1, 1,
i);
946 }
else if (
current->vps_num_ptls_minus1 == 0) {
947 infer(vps_ols_ptl_idx[
i], 0);
953 if (!
current->vps_each_layer_is_an_ols_flag) {
954 uint16_t vps_num_dpb_params;
955 ue(vps_num_dpb_params_minus1, 0, num_multi_layer_olss - 1);
956 if (
current->vps_each_layer_is_an_ols_flag)
957 vps_num_dpb_params = 0;
959 vps_num_dpb_params =
current->vps_num_dpb_params_minus1 + 1;
961 if (
current->vps_max_sublayers_minus1 > 0)
962 flag(vps_sublayer_dpb_params_present_flag);
964 infer(vps_sublayer_dpb_params_present_flag, 0);
966 for (
i = 0;
i < vps_num_dpb_params;
i++) {
967 if (!
current->vps_default_ptl_dpb_hrd_max_tid_flag)
968 us(3, vps_dpb_max_tid[
i], 0,
current->vps_max_sublayers_minus1,
971 infer(vps_dpb_max_tid[
i],
current->vps_max_sublayers_minus1);
975 vps_sublayer_dpb_params_present_flag));
977 for (
i = 0;
i < num_multi_layer_olss;
i++) {
978 ues(vps_ols_dpb_pic_width[
i], 0, UINT16_MAX, 1,
i);
979 ues(vps_ols_dpb_pic_height[
i], 0, UINT16_MAX, 1,
i);
980 ubs(2, vps_ols_dpb_chroma_format[
i], 1,
i);
981 ues(vps_ols_dpb_bitdepth_minus8[
i], 0, 8, 1,
i);
982 if (vps_num_dpb_params > 1
983 && vps_num_dpb_params != num_multi_layer_olss)
984 ues(vps_ols_dpb_params_idx[
i], 0, vps_num_dpb_params - 1, 1,
i);
985 else if (vps_num_dpb_params == 1)
986 infer(vps_ols_dpb_params_idx[
i], 0);
988 infer(vps_ols_dpb_params_idx[
i],
i);
990 flag(vps_timing_hrd_params_present_flag);
991 if (
current->vps_timing_hrd_params_present_flag) {
994 vps_general_timing_hrd_parameters));
995 if (
current->vps_max_sublayers_minus1 > 0)
996 flag(vps_sublayer_cpb_params_present_flag);
998 infer(vps_sublayer_cpb_params_present_flag, 0);
999 ue(vps_num_ols_timing_hrd_params_minus1, 0,
1000 num_multi_layer_olss - 1);
1001 for (
i = 0;
i <=
current->vps_num_ols_timing_hrd_params_minus1;
i++) {
1002 uint8_t first_sublayer;
1003 if (!
current->vps_default_ptl_dpb_hrd_max_tid_flag)
1004 us(3, vps_hrd_max_tid[
i], 0,
1005 current->vps_max_sublayers_minus1, 1,
i);
1007 infer(vps_hrd_max_tid[
i],
1008 current->vps_max_sublayers_minus1);
1009 first_sublayer =
current->vps_sublayer_cpb_params_present_flag ?
1012 (
ctx, rw, &
current->vps_ols_timing_hrd_parameters,
1013 first_sublayer,
current->vps_max_sublayers_minus1,
1014 &
current->vps_general_timing_hrd_parameters));
1017 if (
current->vps_num_ols_timing_hrd_params_minus1 > 0 &&
1018 current->vps_num_ols_timing_hrd_params_minus1 + 1 !=
1019 num_multi_layer_olss) {
1020 for (
i = 0;
i < num_multi_layer_olss;
i++) {
1021 ues(vps_ols_timing_hrd_idx[
i], 0,
1022 current->vps_num_ols_timing_hrd_params_minus1, 1,
i);
1024 }
else if (
current->vps_num_ols_timing_hrd_params_minus1 == 0) {
1025 for (
i = 0;
i < num_multi_layer_olss;
i++)
1026 infer(vps_ols_timing_hrd_idx[
i], 0);
1028 for (
i = 0;
i < num_multi_layer_olss;
i++)
1029 infer(vps_ols_timing_hrd_idx[
i],
i);
1034 flag(vps_extension_flag);
1035 if (
current->vps_extension_flag)
1063 int err,
i, j, max_width_minus1, max_height_minus1;
1064 unsigned int ctb_log2_size_y, min_cb_log2_size_y,
1065 min_qt_log2_size_intra_y, min_qt_log2_size_inter_y,
1066 ctb_size_y, max_num_merge_cand, tmp_width_val, tmp_height_val;
1067 uint8_t qp_bd_offset, sub_width_c, sub_height_c;
1069 static const uint8_t h266_sub_width_c[] = {
1072 static const uint8_t h266_sub_height_c[] = {
1076 HEADER(
"Sequence Parameter Set");
1081 ub(4, sps_seq_parameter_set_id);
1082 ub(4, sps_video_parameter_set_id);
1083 if (
current->sps_video_parameter_set_id == 0 && !h266->
vps[0]) {
1087 vps->vps_max_layers_minus1 = 0;
1088 vps->vps_independent_layer_flag[0] = 1;
1089 vps->vps_layer_id[0] =
current->nal_unit_header.nuh_layer_id;
1094 u(2, sps_chroma_format_idc, 0, 3);
1095 sub_width_c = h266_sub_width_c[
current->sps_chroma_format_idc];
1096 sub_height_c = h266_sub_height_c[
current->sps_chroma_format_idc];
1098 u(2, sps_log2_ctu_size_minus5, 0, 3);
1099 ctb_log2_size_y =
current->sps_log2_ctu_size_minus5 + 5;
1100 ctb_size_y = 1 << ctb_log2_size_y;
1102 flag(sps_ptl_dpb_hrd_params_present_flag);
1103 if (
current->sps_ptl_dpb_hrd_params_present_flag) {
1105 1,
current->sps_max_sublayers_minus1));
1107 flag(sps_gdr_enabled_flag);
1108 flag(sps_ref_pic_resampling_enabled_flag);
1109 if (
current->sps_ref_pic_resampling_enabled_flag)
1110 flag(sps_res_change_in_clvs_allowed_flag);
1112 infer(sps_res_change_in_clvs_allowed_flag, 0);
1117 flag(sps_conformance_window_flag);
1118 if (
current->sps_conformance_window_flag) {
1119 uint16_t
width =
current->sps_pic_width_max_in_luma_samples / sub_width_c;
1120 uint16_t
height =
current->sps_pic_height_max_in_luma_samples / sub_height_c;
1121 ue(sps_conf_win_left_offset, 0,
width);
1122 ue(sps_conf_win_right_offset, 0,
width -
current->sps_conf_win_left_offset);
1123 ue(sps_conf_win_top_offset, 0,
height);
1124 ue(sps_conf_win_bottom_offset, 0,
height -
current->sps_conf_win_top_offset);
1126 infer(sps_conf_win_left_offset, 0);
1127 infer(sps_conf_win_right_offset, 0);
1128 infer(sps_conf_win_top_offset, 0);
1129 infer(sps_conf_win_bottom_offset, 0);
1136 max_width_minus1 = tmp_width_val - 1;
1137 max_height_minus1 = tmp_height_val - 1;
1139 u(1, sps_subpic_info_present_flag, 0, !
current->sps_res_change_in_clvs_allowed_flag);
1140 if (
current->sps_subpic_info_present_flag) {
1142 if (
current->sps_num_subpics_minus1 > 0) {
1143 flag(sps_independent_subpics_flag);
1144 flag(sps_subpic_same_size_flag);
1147 if (
current->sps_num_subpics_minus1 > 0) {
1150 infer(sps_subpic_ctu_top_left_x[0], 0);
1151 infer(sps_subpic_ctu_top_left_y[0], 0);
1152 if (
current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1153 us(wlen, sps_subpic_width_minus1[0], 0, max_width_minus1, 1, 0);
1155 infer(sps_subpic_width_minus1[0], max_width_minus1);
1156 if (
current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1157 us(hlen, sps_subpic_height_minus1[0], 0, max_height_minus1, 1, 0);
1159 infer(sps_subpic_height_minus1[0], max_height_minus1);
1160 if (!
current->sps_independent_subpics_flag) {
1161 flags(sps_subpic_treated_as_pic_flag[0], 1, 0);
1162 flags(sps_loop_filter_across_subpic_enabled_flag[0], 1, 0);
1164 infer(sps_subpic_treated_as_pic_flag[0], 1);
1165 infer(sps_loop_filter_across_subpic_enabled_flag[0], 1);
1167 for (
i = 1;
i <=
current->sps_num_subpics_minus1;
i++) {
1168 if (!
current->sps_subpic_same_size_flag) {
1169 const int win_right_edge =
1170 current->sps_pic_width_max_in_luma_samples -
1171 current->sps_conf_win_right_offset * sub_width_c;
1172 const int win_bottom_edge =
1173 current->sps_pic_height_max_in_luma_samples -
1174 current->sps_conf_win_bottom_offset * sub_height_c;
1175 const int win_left_edge =
1176 current->sps_conf_win_left_offset * sub_width_c;
1177 const int win_top_edge =
1178 current->sps_conf_win_top_offset * sub_height_c;
1179 const int win_left_edge_ctus =
1181 const int win_right_edge_ctus =
1183 const int win_top_edge_ctus =
1185 const int win_bottom_edge_ctus =
1187 const int min_width =
1188 FFMAX(win_left_edge_ctus -
current->sps_subpic_ctu_top_left_x[
i], 0);
1189 const int min_height =
1190 FFMAX(win_top_edge_ctus -
current->sps_subpic_ctu_top_left_y[
i], 0);
1192 if (
current->sps_pic_width_max_in_luma_samples > ctb_size_y)
1193 us(wlen, sps_subpic_ctu_top_left_x[
i], 0, win_right_edge_ctus - 1, 1,
i);
1195 infer(sps_subpic_ctu_top_left_x[
i], 0);
1197 if (
current->sps_pic_height_max_in_luma_samples > ctb_size_y)
1198 us(hlen, sps_subpic_ctu_top_left_y[
i], 0, win_bottom_edge_ctus - 1, 1,
i);
1200 infer(sps_subpic_ctu_top_left_y[
i], 0);
1202 max_width_minus1 = tmp_width_val -
current->sps_subpic_ctu_top_left_x[
i] - 1;
1203 max_height_minus1 = tmp_height_val -
current->sps_subpic_ctu_top_left_y[
i] - 1;
1206 current->sps_pic_width_max_in_luma_samples > ctb_size_y) {
1207 us(wlen, sps_subpic_width_minus1[
i], min_width, max_width_minus1, 1,
i);
1209 infer(sps_subpic_width_minus1[
i], max_width_minus1);
1213 current->sps_pic_height_max_in_luma_samples > ctb_size_y) {
1214 us(hlen, sps_subpic_height_minus1[
i], min_height, max_height_minus1, 1,
i);
1216 infer(sps_subpic_height_minus1[
i], max_height_minus1);
1219 int num_subpic_cols = tmp_width_val /
1220 (
current->sps_subpic_width_minus1[0] + 1);
1221 if (tmp_width_val % (
current->sps_subpic_width_minus1[0] + 1) ||
1222 tmp_height_val % (
current->sps_subpic_height_minus1[0] + 1) ||
1223 current->sps_num_subpics_minus1 !=
1224 (num_subpic_cols * tmp_height_val /
1225 (
current->sps_subpic_height_minus1[0] + 1) - 1))
1227 infer(sps_subpic_ctu_top_left_x[
i],
1228 (
i % num_subpic_cols) *
1229 (
current->sps_subpic_width_minus1[0] + 1));
1230 infer(sps_subpic_ctu_top_left_y[
i],
1231 (
i / num_subpic_cols) *
1232 (
current->sps_subpic_height_minus1[0] + 1));
1233 infer(sps_subpic_width_minus1[
i],
1234 current->sps_subpic_width_minus1[0]);
1235 infer(sps_subpic_height_minus1[
i],
1236 current->sps_subpic_height_minus1[0]);
1238 if (!
current->sps_independent_subpics_flag) {
1239 flags(sps_subpic_treated_as_pic_flag[
i], 1,
i);
1240 flags(sps_loop_filter_across_subpic_enabled_flag[
i], 1,
i);
1242 infer(sps_subpic_treated_as_pic_flag[
i], 1);
1243 infer(sps_loop_filter_across_subpic_enabled_flag[
i], 0);
1247 infer(sps_subpic_ctu_top_left_x[0], 0);
1248 infer(sps_subpic_ctu_top_left_y[0], 0);
1249 infer(sps_subpic_width_minus1[0], max_width_minus1);
1250 infer(sps_subpic_height_minus1[0], max_height_minus1);
1252 ue(sps_subpic_id_len_minus1, 0, 15);
1253 if ((1 << (
current->sps_subpic_id_len_minus1 + 1)) <
1254 current->sps_num_subpics_minus1 + 1) {
1256 "sps_subpic_id_len_minus1(%d) is too small\n",
1257 current->sps_subpic_id_len_minus1);
1260 flag(sps_subpic_id_mapping_explicitly_signalled_flag);
1261 if (
current->sps_subpic_id_mapping_explicitly_signalled_flag) {
1262 flag(sps_subpic_id_mapping_present_flag);
1263 if (
current->sps_subpic_id_mapping_present_flag) {
1264 for (
i = 0;
i <=
current->sps_num_subpics_minus1;
i++) {
1266 sps_subpic_id[
i], 1,
i);
1271 infer(sps_num_subpics_minus1, 0);
1272 infer(sps_independent_subpics_flag, 1);
1273 infer(sps_subpic_same_size_flag, 0);
1274 infer(sps_subpic_id_mapping_explicitly_signalled_flag, 0);
1275 infer(sps_subpic_ctu_top_left_x[0], 0);
1276 infer(sps_subpic_ctu_top_left_y[0], 0);
1277 infer(sps_subpic_width_minus1[0], max_width_minus1);
1278 infer(sps_subpic_height_minus1[0], max_height_minus1);
1282 ue(sps_bitdepth_minus8, 0, 8);
1283 qp_bd_offset = 6 *
current->sps_bitdepth_minus8;
1285 flag(sps_entropy_coding_sync_enabled_flag);
1286 flag(sps_entry_point_offsets_present_flag);
1288 u(4, sps_log2_max_pic_order_cnt_lsb_minus4, 0, 12);
1289 flag(sps_poc_msb_cycle_flag);
1290 if (
current->sps_poc_msb_cycle_flag)
1291 ue(sps_poc_msb_cycle_len_minus1,
1292 0, 32 -
current->sps_log2_max_pic_order_cnt_lsb_minus4 - 5);
1294 u(2, sps_num_extra_ph_bytes, 0, 2);
1295 for (
i = 0;
i < (
current->sps_num_extra_ph_bytes * 8);
i++) {
1296 flags(sps_extra_ph_bit_present_flag[
i], 1,
i);
1299 u(2, sps_num_extra_sh_bytes, 0, 2);
1300 for (
i = 0;
i < (
current->sps_num_extra_sh_bytes * 8);
i++) {
1301 flags(sps_extra_sh_bit_present_flag[
i], 1,
i);
1304 if (
current->sps_ptl_dpb_hrd_params_present_flag) {
1305 if (
current->sps_max_sublayers_minus1 > 0)
1306 flag(sps_sublayer_dpb_params_flag);
1308 infer(sps_sublayer_dpb_params_flag, 0);
1310 current->sps_max_sublayers_minus1,
1311 current->sps_sublayer_dpb_params_flag));
1314 ue(sps_log2_min_luma_coding_block_size_minus2,
1316 min_cb_log2_size_y =
1317 current->sps_log2_min_luma_coding_block_size_minus2 + 2;
1319 flag(sps_partition_constraints_override_enabled_flag);
1321 ue(sps_log2_diff_min_qt_min_cb_intra_slice_luma,
1322 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1323 min_qt_log2_size_intra_y =
1324 current->sps_log2_diff_min_qt_min_cb_intra_slice_luma +
1327 ue(sps_max_mtt_hierarchy_depth_intra_slice_luma,
1328 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1330 if (
current->sps_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
1331 ue(sps_log2_diff_max_bt_min_qt_intra_slice_luma,
1332 0, ctb_log2_size_y - min_qt_log2_size_intra_y);
1333 ue(sps_log2_diff_max_tt_min_qt_intra_slice_luma,
1334 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
1336 infer(sps_log2_diff_max_bt_min_qt_intra_slice_luma, 0);
1337 infer(sps_log2_diff_max_tt_min_qt_intra_slice_luma, 0);
1340 if (
current->sps_chroma_format_idc != 0) {
1341 flag(sps_qtbtt_dual_tree_intra_flag);
1343 infer(sps_qtbtt_dual_tree_intra_flag, 0);
1346 if (
current->sps_qtbtt_dual_tree_intra_flag) {
1347 ue(sps_log2_diff_min_qt_min_cb_intra_slice_chroma,
1348 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1349 ue(sps_max_mtt_hierarchy_depth_intra_slice_chroma,
1350 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1351 if (
current->sps_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
1352 unsigned int min_qt_log2_size_intra_c =
1353 current->sps_log2_diff_min_qt_min_cb_intra_slice_chroma +
1355 ue(sps_log2_diff_max_bt_min_qt_intra_slice_chroma,
1356 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1357 ue(sps_log2_diff_max_tt_min_qt_intra_slice_chroma,
1358 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
1361 infer(sps_log2_diff_min_qt_min_cb_intra_slice_chroma, 0);
1362 infer(sps_max_mtt_hierarchy_depth_intra_slice_chroma, 0);
1364 if (
current->sps_max_mtt_hierarchy_depth_intra_slice_chroma == 0) {
1365 infer(sps_log2_diff_max_bt_min_qt_intra_slice_chroma, 0);
1366 infer(sps_log2_diff_max_tt_min_qt_intra_slice_chroma, 0);
1369 ue(sps_log2_diff_min_qt_min_cb_inter_slice,
1370 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
1371 min_qt_log2_size_inter_y =
1372 current->sps_log2_diff_min_qt_min_cb_inter_slice + min_cb_log2_size_y;
1374 ue(sps_max_mtt_hierarchy_depth_inter_slice,
1375 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
1376 if (
current->sps_max_mtt_hierarchy_depth_inter_slice != 0) {
1377 ue(sps_log2_diff_max_bt_min_qt_inter_slice,
1378 0, ctb_log2_size_y - min_qt_log2_size_inter_y);
1379 ue(sps_log2_diff_max_tt_min_qt_inter_slice,
1380 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
1382 infer(sps_log2_diff_max_bt_min_qt_inter_slice, 0);
1383 infer(sps_log2_diff_max_tt_min_qt_inter_slice, 0);
1386 if (ctb_size_y > 32)
1387 flag(sps_max_luma_transform_size_64_flag);
1389 infer(sps_max_luma_transform_size_64_flag, 0);
1391 flag(sps_transform_skip_enabled_flag);
1392 if (
current->sps_transform_skip_enabled_flag) {
1393 ue(sps_log2_transform_skip_max_size_minus2, 0, 3);
1394 flag(sps_bdpcm_enabled_flag);
1397 flag(sps_mts_enabled_flag);
1398 if (
current->sps_mts_enabled_flag) {
1399 flag(sps_explicit_mts_intra_enabled_flag);
1400 flag(sps_explicit_mts_inter_enabled_flag);
1402 infer(sps_explicit_mts_intra_enabled_flag, 0);
1403 infer(sps_explicit_mts_inter_enabled_flag, 0);
1406 flag(sps_lfnst_enabled_flag);
1408 if (
current->sps_chroma_format_idc != 0) {
1409 uint8_t num_qp_tables;
1410 flag(sps_joint_cbcr_enabled_flag);
1411 flag(sps_same_qp_table_for_chroma_flag);
1412 num_qp_tables =
current->sps_same_qp_table_for_chroma_flag ?
1413 1 : (
current->sps_joint_cbcr_enabled_flag ? 3 : 2);
1414 for (
i = 0;
i < num_qp_tables;
i++) {
1415 ses(sps_qp_table_start_minus26[
i], -26 - qp_bd_offset, 36, 1,
i);
1416 ues(sps_num_points_in_qp_table_minus1[
i],
1417 0, 36 -
current->sps_qp_table_start_minus26[
i], 1,
i);
1418 for (j = 0; j <=
current->sps_num_points_in_qp_table_minus1[
i]; j++) {
1420 ues(sps_delta_qp_in_val_minus1[
i][j], 0,
max, 2,
i, j);
1421 ues(sps_delta_qp_diff_val[
i][j], 0,
max, 2,
i, j);
1425 infer(sps_joint_cbcr_enabled_flag, 0);
1426 infer(sps_same_qp_table_for_chroma_flag, 0);
1429 flag(sps_sao_enabled_flag);
1430 flag(sps_alf_enabled_flag);
1431 if (
current->sps_alf_enabled_flag &&
current->sps_chroma_format_idc)
1432 flag(sps_ccalf_enabled_flag);
1434 infer(sps_ccalf_enabled_flag, 0);
1435 flag(sps_lmcs_enabled_flag);
1436 flag(sps_weighted_pred_flag);
1437 flag(sps_weighted_bipred_flag);
1438 flag(sps_long_term_ref_pics_flag);
1439 if (
current->sps_video_parameter_set_id > 0)
1440 flag(sps_inter_layer_prediction_enabled_flag);
1442 infer(sps_inter_layer_prediction_enabled_flag, 0);
1443 flag(sps_idr_rpl_present_flag);
1444 flag(sps_rpl1_same_as_rpl0_flag);
1446 for (
i = 0;
i < (
current->sps_rpl1_same_as_rpl0_flag ? 1 : 2);
i++) {
1448 for (j = 0; j <
current->sps_num_ref_pic_lists[
i]; j++)
1451 sps_ref_pic_list_struct[
i][j],
i,
1455 if (
current->sps_rpl1_same_as_rpl0_flag) {
1456 current->sps_num_ref_pic_lists[1] =
current->sps_num_ref_pic_lists[0];
1457 for (j = 0; j <
current->sps_num_ref_pic_lists[0]; j++)
1458 memcpy(&
current->sps_ref_pic_list_struct[1][j],
1459 &
current->sps_ref_pic_list_struct[0][j],
1460 sizeof(
current->sps_ref_pic_list_struct[0][j]));
1463 flag(sps_ref_wraparound_enabled_flag);
1465 flag(sps_temporal_mvp_enabled_flag);
1466 if (
current->sps_temporal_mvp_enabled_flag)
1467 flag(sps_sbtmvp_enabled_flag);
1469 infer(sps_sbtmvp_enabled_flag, 0);
1471 flag(sps_amvr_enabled_flag);
1472 flag(sps_bdof_enabled_flag);
1473 if (
current->sps_bdof_enabled_flag)
1474 flag(sps_bdof_control_present_in_ph_flag);
1476 infer(sps_bdof_control_present_in_ph_flag, 0);
1478 flag(sps_smvd_enabled_flag);
1479 flag(sps_dmvr_enabled_flag);
1480 if (
current->sps_dmvr_enabled_flag)
1481 flag(sps_dmvr_control_present_in_ph_flag);
1483 infer(sps_dmvr_control_present_in_ph_flag, 0);
1485 flag(sps_mmvd_enabled_flag);
1486 if (
current->sps_mmvd_enabled_flag)
1487 flag(sps_mmvd_fullpel_only_enabled_flag);
1489 infer(sps_mmvd_fullpel_only_enabled_flag, 0);
1491 ue(sps_six_minus_max_num_merge_cand, 0, 5);
1492 max_num_merge_cand = 6 -
current->sps_six_minus_max_num_merge_cand;
1494 flag(sps_sbt_enabled_flag);
1496 flag(sps_affine_enabled_flag);
1497 if (
current->sps_affine_enabled_flag) {
1498 ue(sps_five_minus_max_num_subblock_merge_cand,
1499 0, 5 -
current->sps_sbtmvp_enabled_flag);
1500 flag(sps_6param_affine_enabled_flag);
1501 if (
current->sps_amvr_enabled_flag)
1502 flag(sps_affine_amvr_enabled_flag);
1504 infer(sps_affine_amvr_enabled_flag, 0);
1505 flag(sps_affine_prof_enabled_flag);
1506 if (
current->sps_affine_prof_enabled_flag)
1507 flag(sps_prof_control_present_in_ph_flag);
1509 infer(sps_prof_control_present_in_ph_flag, 0);
1511 infer(sps_6param_affine_enabled_flag, 0);
1512 infer(sps_affine_amvr_enabled_flag, 0);
1513 infer(sps_affine_prof_enabled_flag, 0);
1514 infer(sps_prof_control_present_in_ph_flag, 0);
1517 flag(sps_bcw_enabled_flag);
1518 flag(sps_ciip_enabled_flag);
1520 if (max_num_merge_cand >= 2) {
1521 flag(sps_gpm_enabled_flag);
1522 if (
current->sps_gpm_enabled_flag && max_num_merge_cand >= 3)
1523 ue(sps_max_num_merge_cand_minus_max_num_gpm_cand,
1524 0, max_num_merge_cand - 2);
1526 infer(sps_gpm_enabled_flag, 0);
1529 ue(sps_log2_parallel_merge_level_minus2, 0, ctb_log2_size_y - 2);
1531 flag(sps_isp_enabled_flag);
1532 flag(sps_mrl_enabled_flag);
1533 flag(sps_mip_enabled_flag);
1535 if (
current->sps_chroma_format_idc != 0)
1536 flag(sps_cclm_enabled_flag);
1538 infer(sps_cclm_enabled_flag, 0);
1539 if (
current->sps_chroma_format_idc == 1) {
1540 flag(sps_chroma_horizontal_collocated_flag);
1541 flag(sps_chroma_vertical_collocated_flag);
1543 infer(sps_chroma_horizontal_collocated_flag, 1);
1544 infer(sps_chroma_vertical_collocated_flag, 1);
1547 flag(sps_palette_enabled_flag);
1548 if (
current->sps_chroma_format_idc == 3 &&
1549 !
current->sps_max_luma_transform_size_64_flag)
1550 flag(sps_act_enabled_flag);
1552 infer(sps_act_enabled_flag, 0);
1553 if (
current->sps_transform_skip_enabled_flag ||
1554 current->sps_palette_enabled_flag)
1555 ue(sps_min_qp_prime_ts, 0, 8);
1557 flag(sps_ibc_enabled_flag);
1558 if (
current->sps_ibc_enabled_flag)
1559 ue(sps_six_minus_max_num_ibc_merge_cand, 0, 5);
1561 flag(sps_ladf_enabled_flag);
1562 if (
current->sps_ladf_enabled_flag) {
1563 ub(2, sps_num_ladf_intervals_minus2);
1564 se(sps_ladf_lowest_interval_qp_offset, -63, 63);
1565 for (
i = 0;
i <
current->sps_num_ladf_intervals_minus2 + 1;
i++) {
1566 ses(sps_ladf_qp_offset[
i], -63, 63, 1,
i);
1567 ues(sps_ladf_delta_threshold_minus1[
i],
1568 0, (2 << (8 +
current->sps_bitdepth_minus8)) - 3, 1,
i);
1572 flag(sps_explicit_scaling_list_enabled_flag);
1573 if (
current->sps_lfnst_enabled_flag &&
1574 current->sps_explicit_scaling_list_enabled_flag)
1575 flag(sps_scaling_matrix_for_lfnst_disabled_flag);
1577 if (
current->sps_act_enabled_flag &&
1578 current->sps_explicit_scaling_list_enabled_flag)
1579 flag(sps_scaling_matrix_for_alternative_colour_space_disabled_flag);
1581 infer(sps_scaling_matrix_for_alternative_colour_space_disabled_flag, 0);
1582 if (
current->sps_scaling_matrix_for_alternative_colour_space_disabled_flag)
1583 flag(sps_scaling_matrix_designated_colour_space_flag);
1585 flag(sps_dep_quant_enabled_flag);
1586 flag(sps_sign_data_hiding_enabled_flag);
1588 flag(sps_virtual_boundaries_enabled_flag);
1589 if (
current->sps_virtual_boundaries_enabled_flag) {
1590 flag(sps_virtual_boundaries_present_flag);
1591 if (
current->sps_virtual_boundaries_present_flag) {
1592 ue(sps_num_ver_virtual_boundaries,
1594 for (
i = 0;
i <
current->sps_num_ver_virtual_boundaries;
i++)
1595 ues(sps_virtual_boundary_pos_x_minus1[
i],
1596 0, (
current->sps_pic_width_max_in_luma_samples + 7) / 8 - 2,
1598 ue(sps_num_hor_virtual_boundaries,
1600 for (
i = 0;
i <
current->sps_num_hor_virtual_boundaries;
i++)
1601 ues(sps_virtual_boundary_pos_y_minus1[
i],
1602 0, (
current->sps_pic_height_max_in_luma_samples + 7) /
1606 infer(sps_virtual_boundaries_present_flag, 0);
1607 infer(sps_num_ver_virtual_boundaries, 0);
1608 infer(sps_num_hor_virtual_boundaries, 0);
1611 if (
current->sps_ptl_dpb_hrd_params_present_flag) {
1612 flag(sps_timing_hrd_params_present_flag);
1613 if (
current->sps_timing_hrd_params_present_flag) {
1614 uint8_t first_sublayer;
1616 &
current->sps_general_timing_hrd_parameters));
1617 if (
current->sps_max_sublayers_minus1 > 0)
1618 flag(sps_sublayer_cpb_params_present_flag);
1620 infer(sps_sublayer_cpb_params_present_flag, 0);
1621 first_sublayer =
current->sps_sublayer_cpb_params_present_flag ?
1622 0 :
current->sps_max_sublayers_minus1;
1624 &
current->sps_ols_timing_hrd_parameters, first_sublayer,
1625 current->sps_max_sublayers_minus1,
1626 &
current->sps_general_timing_hrd_parameters));
1630 flag(sps_field_seq_flag);
1631 flag(sps_vui_parameters_present_flag);
1632 if (
current->sps_vui_parameters_present_flag) {
1633 ue(sps_vui_payload_size_minus1, 0, 1023);
1635 fixed(1, sps_vui_alignment_zero_bit, 0);
1637 current->sps_vui_payload_size_minus1 + 1,
1638 current->sps_chroma_format_idc));
1643 flag(sps_extension_flag);
1644 if (
current->sps_extension_flag) {
1645 flag(sps_range_extension_flag);
1646 ub(7, sps_extension_7bits);
1648 if (
current->sps_range_extension_flag) {
1649 if (
current->sps_bitdepth_minus8 <= 10 - 8)
1653 infer(sps_extended_precision_flag, 0);
1654 infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1655 infer(sps_rrc_rice_extension_flag, 0);
1656 infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1657 infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1660 infer(sps_range_extension_flag, 0);
1661 infer(sps_extension_7bits, 0);
1662 infer(sps_extended_precision_flag, 0);
1663 infer(sps_ts_residual_coding_rice_present_in_sh_flag, 0);
1664 infer(sps_rrc_rice_extension_flag, 0);
1665 infer(sps_persistent_rice_adaptation_enabled_flag, 0);
1666 infer(sps_reverse_last_sig_coeff_enabled_flag, 0);
1669 if (
current->sps_extension_7bits)
1683 unsigned int min_cb_size_y, divisor, ctb_size_y,
1684 pic_width_in_ctbs_y, pic_height_in_ctbs_y;
1685 uint8_t sub_width_c, sub_height_c, qp_bd_offset;
1687 static const uint8_t h266_sub_width_c[] = {
1690 static const uint8_t h266_sub_height_c[] = {
1694 HEADER(
"Picture Parameter Set");
1699 ub(6, pps_pic_parameter_set_id);
1700 ub(4, pps_seq_parameter_set_id);
1704 current->pps_seq_parameter_set_id);
1708 flag(pps_mixed_nalu_types_in_pic_flag);
1709 ue(pps_pic_width_in_luma_samples,
1710 1,
sps->sps_pic_width_max_in_luma_samples);
1711 ue(pps_pic_height_in_luma_samples,
1712 1,
sps->sps_pic_height_max_in_luma_samples);
1714 min_cb_size_y = 1 << (
sps->sps_log2_min_luma_coding_block_size_minus2 + 2);
1715 divisor =
FFMAX(min_cb_size_y, 8);
1716 if (
current->pps_pic_width_in_luma_samples % divisor ||
1717 current->pps_pic_height_in_luma_samples % divisor) {
1719 "Invalid dimensions: %ux%u not divisible "
1720 "by %u, MinCbSizeY = %u.\n",
1721 current->pps_pic_width_in_luma_samples,
1722 current->pps_pic_height_in_luma_samples, divisor, min_cb_size_y);
1725 if (!
sps->sps_res_change_in_clvs_allowed_flag &&
1726 (
current->pps_pic_width_in_luma_samples !=
1727 sps->sps_pic_width_max_in_luma_samples ||
1728 current->pps_pic_height_in_luma_samples !=
1729 sps->sps_pic_height_max_in_luma_samples)) {
1731 "Resolution change is not allowed, "
1732 "in max resolution (%ux%u) mismatched with pps(%ux%u).\n",
1733 sps->sps_pic_width_max_in_luma_samples,
1734 sps->sps_pic_height_max_in_luma_samples,
1735 current->pps_pic_width_in_luma_samples,
1736 current->pps_pic_height_in_luma_samples);
1740 ctb_size_y = 1 << (
sps->sps_log2_ctu_size_minus5 + 5);
1741 if (
sps->sps_ref_wraparound_enabled_flag) {
1742 if ((ctb_size_y / min_cb_size_y + 1) >
1743 (
current->pps_pic_width_in_luma_samples / min_cb_size_y - 1)) {
1745 "Invalid width(%u), ctb_size_y = %u, min_cb_size_y = %u.\n",
1746 current->pps_pic_width_in_luma_samples,
1747 ctb_size_y, min_cb_size_y);
1752 flag(pps_conformance_window_flag);
1753 if (
current->pps_pic_width_in_luma_samples ==
1754 sps->sps_pic_width_max_in_luma_samples &&
1755 current->pps_pic_height_in_luma_samples ==
1756 sps->sps_pic_height_max_in_luma_samples &&
1757 current->pps_conformance_window_flag) {
1759 "Conformance window flag should not true.\n");
1763 sub_width_c = h266_sub_width_c[
sps->sps_chroma_format_idc];
1764 sub_height_c = h266_sub_height_c[
sps->sps_chroma_format_idc];
1765 if (
current->pps_conformance_window_flag) {
1766 ue(pps_conf_win_left_offset, 0,
current->pps_pic_width_in_luma_samples);
1767 ue(pps_conf_win_right_offset,
1768 0,
current->pps_pic_width_in_luma_samples);
1769 ue(pps_conf_win_top_offset, 0,
current->pps_pic_height_in_luma_samples);
1770 ue(pps_conf_win_bottom_offset,
1771 0,
current->pps_pic_height_in_luma_samples);
1773 (
current->pps_conf_win_left_offset +
1774 current->pps_conf_win_right_offset) >=
1775 current->pps_pic_width_in_luma_samples ||
1777 (
current->pps_conf_win_top_offset +
1778 current->pps_conf_win_bottom_offset) >=
1779 current->pps_pic_height_in_luma_samples) {
1781 "Invalid pps conformance window: (%u, %u, %u, %u), "
1782 "resolution is %ux%u, sub wxh is %ux%u.\n",
1783 current->pps_conf_win_left_offset,
1784 current->pps_conf_win_right_offset,
1785 current->pps_conf_win_top_offset,
1786 current->pps_conf_win_bottom_offset,
1787 current->pps_pic_width_in_luma_samples,
1788 current->pps_pic_height_in_luma_samples,
1789 sub_width_c, sub_height_c);
1793 if (
current->pps_pic_width_in_luma_samples ==
1794 sps->sps_pic_width_max_in_luma_samples &&
1795 current->pps_pic_height_in_luma_samples ==
1796 sps->sps_pic_height_max_in_luma_samples) {
1797 infer(pps_conf_win_left_offset,
sps->sps_conf_win_left_offset);
1798 infer(pps_conf_win_right_offset,
sps->sps_conf_win_right_offset);
1799 infer(pps_conf_win_top_offset,
sps->sps_conf_win_top_offset);
1800 infer(pps_conf_win_bottom_offset,
sps->sps_conf_win_bottom_offset);
1802 infer(pps_conf_win_left_offset, 0);
1803 infer(pps_conf_win_right_offset, 0);
1804 infer(pps_conf_win_top_offset, 0);
1805 infer(pps_conf_win_bottom_offset, 0);
1810 flag(pps_scaling_window_explicit_signalling_flag);
1811 if (!
sps->sps_ref_pic_resampling_enabled_flag &&
1812 current->pps_scaling_window_explicit_signalling_flag) {
1814 "Invalid data: sps_ref_pic_resampling_enabled_flag is false, "
1815 "but pps_scaling_window_explicit_signalling_flag is true.\n");
1818 if (
current->pps_scaling_window_explicit_signalling_flag) {
1819 se(pps_scaling_win_left_offset,
1820 -
current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1821 current->pps_pic_width_in_luma_samples / sub_width_c);
1822 se(pps_scaling_win_right_offset,
1823 -
current->pps_pic_width_in_luma_samples * 15 / sub_width_c,
1824 current->pps_pic_width_in_luma_samples / sub_width_c);
1825 se(pps_scaling_win_top_offset,
1826 -
current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1827 current->pps_pic_height_in_luma_samples / sub_height_c);
1828 se(pps_scaling_win_bottom_offset,
1829 -
current->pps_pic_height_in_luma_samples * 15 / sub_height_c,
1830 current->pps_pic_height_in_luma_samples / sub_height_c);
1832 infer(pps_scaling_win_left_offset,
current->pps_conf_win_left_offset);
1833 infer(pps_scaling_win_right_offset,
current->pps_conf_win_right_offset);
1834 infer(pps_scaling_win_top_offset,
current->pps_conf_win_top_offset);
1835 infer(pps_scaling_win_bottom_offset,
current->pps_conf_win_bottom_offset);
1838 flag(pps_output_flag_present_flag);
1839 flag(pps_no_pic_partition_flag);
1840 flag(pps_subpic_id_mapping_present_flag);
1842 if (
current->pps_subpic_id_mapping_present_flag) {
1843 if (!
current->pps_no_pic_partition_flag) {
1844 ue(pps_num_subpics_minus1,
1845 sps->sps_num_subpics_minus1,
sps->sps_num_subpics_minus1);
1847 infer(pps_num_subpics_minus1, 0);
1849 ue(pps_subpic_id_len_minus1,
sps->sps_subpic_id_len_minus1,
1850 sps->sps_subpic_id_len_minus1);
1851 for (
i = 0;
i <=
current->pps_num_subpics_minus1;
i++) {
1852 ubs(
sps->sps_subpic_id_len_minus1 + 1, pps_subpic_id[
i], 1,
i);
1856 for (
i = 0;
i <=
sps->sps_num_subpics_minus1;
i++) {
1857 if (
sps->sps_subpic_id_mapping_explicitly_signalled_flag)
1858 current->sub_pic_id_val[
i] =
current->pps_subpic_id_mapping_present_flag
1860 :
sps->sps_subpic_id[
i];
1866 (
current->pps_pic_width_in_luma_samples, (
sps->sps_log2_ctu_size_minus5 + 5));
1868 current->pps_pic_height_in_luma_samples,(
sps->sps_log2_ctu_size_minus5 + 5));
1869 if (!
current->pps_no_pic_partition_flag) {
1870 unsigned int exp_tile_width = 0, exp_tile_height = 0;
1871 unsigned int unified_size, remaining_size;
1873 u(2, pps_log2_ctu_size_minus5,
1874 sps->sps_log2_ctu_size_minus5,
sps->sps_log2_ctu_size_minus5);
1875 ue(pps_num_exp_tile_columns_minus1,
1877 ue(pps_num_exp_tile_rows_minus1,
1880 for (
i = 0;
i <=
current->pps_num_exp_tile_columns_minus1;
i++) {
1881 ues(pps_tile_column_width_minus1[
i],
1882 0, pic_width_in_ctbs_y - exp_tile_width - 1, 1,
i);
1883 exp_tile_width +=
current->pps_tile_column_width_minus1[
i] + 1;
1885 for (
i = 0;
i <=
current->pps_num_exp_tile_rows_minus1;
i++) {
1886 ues(pps_tile_row_height_minus1[
i],
1887 0, pic_height_in_ctbs_y - exp_tile_height - 1, 1,
i);
1888 exp_tile_height +=
current->pps_tile_row_height_minus1[
i] + 1;
1891 remaining_size = pic_width_in_ctbs_y;
1892 for (
i = 0;
i <=
current->pps_num_exp_tile_columns_minus1;
i++) {
1893 if (
current->pps_tile_column_width_minus1[
i] >= remaining_size) {
1895 "Tile column width(%d) exceeds picture width\n",
i);
1899 remaining_size -= (
current->pps_tile_column_width_minus1[
i] + 1);
1901 unified_size =
current->pps_tile_column_width_minus1[
i - 1] + 1;
1902 while (remaining_size > 0) {
1905 "Exceeded maximum tile columns (%d) (remaining size: %u)\n",
1909 unified_size =
FFMIN(remaining_size, unified_size);
1910 current->col_width_val[
i] = unified_size;
1911 remaining_size -= unified_size;
1916 remaining_size = pic_height_in_ctbs_y;
1917 for (
i = 0;
i <=
current->pps_num_exp_tile_rows_minus1;
i++) {
1918 if (
current->pps_tile_row_height_minus1[
i] >= remaining_size) {
1920 "Tile row height(%d) exceeds picture height\n",
i);
1924 remaining_size -= (
current->pps_tile_row_height_minus1[
i] + 1);
1926 unified_size =
current->pps_tile_row_height_minus1[
i - 1] + 1;
1928 while (remaining_size > 0) {
1931 "Exceeded maximum tile rows (%d) (remaining size: %u)\n",
1935 unified_size =
FFMIN(remaining_size, unified_size);
1936 current->row_height_val[
i] = unified_size;
1937 remaining_size -= unified_size;
1946 "NumTilesInPic(%d) > than VVC_MAX_TILES_PER_AU(%d)\n",
1951 if (
current->num_tiles_in_pic > 1) {
1952 flag(pps_loop_filter_across_tiles_enabled_flag);
1953 flag(pps_rect_slice_flag);
1955 infer(pps_loop_filter_across_tiles_enabled_flag, 0);
1956 infer(pps_rect_slice_flag, 1);
1958 if (
current->pps_rect_slice_flag)
1959 flag(pps_single_slice_per_subpic_flag);
1961 infer(pps_single_slice_per_subpic_flag, 1);
1962 if (
current->pps_rect_slice_flag &&
1963 !
current->pps_single_slice_per_subpic_flag) {
1964 int j, num_slices = 0;
1965 uint16_t tile_idx = 0, tile_x, tile_y, ctu_x, ctu_y;
1969 if (
current->pps_num_slices_in_pic_minus1 > 1)
1970 flag(pps_tile_idx_delta_present_flag);
1972 infer(pps_tile_idx_delta_present_flag, 0);
1973 for (
i = 0;
i <
current->pps_num_slices_in_pic_minus1;
i++) {
1974 current->slice_top_left_tile_idx[
i] = tile_idx;
1975 tile_x = tile_idx %
current->num_tile_columns;
1976 tile_y = tile_idx /
current->num_tile_columns;
1977 if (tile_y >=
current->num_tile_rows)
1979 if (tile_x !=
current->num_tile_columns - 1) {
1980 ues(pps_slice_width_in_tiles_minus1[
i],
1981 0,
current->num_tile_columns - 1 - tile_x, 1,
i);
1983 infer(pps_slice_width_in_tiles_minus1[
i], 0);
1985 if (tile_y !=
current->num_tile_rows - 1 &&
1986 (
current->pps_tile_idx_delta_present_flag || tile_x == 0)) {
1987 ues(pps_slice_height_in_tiles_minus1[
i],
1988 0,
current->num_tile_rows - 1 - tile_y, 1,
i);
1990 if (tile_y ==
current->num_tile_rows - 1)
1991 infer(pps_slice_height_in_tiles_minus1[
i], 0);
1993 infer(pps_slice_height_in_tiles_minus1[
i],
1994 current->pps_slice_height_in_tiles_minus1[
i - 1]);
1998 for (j = 0; j < tile_x; j++) {
1999 ctu_x +=
current->col_width_val[j];
2001 for (j = 0; j < tile_y; j++) {
2002 ctu_y +=
current->row_height_val[j];
2004 if (
current->pps_slice_width_in_tiles_minus1[
i] == 0 &&
2005 current->pps_slice_height_in_tiles_minus1[
i] == 0 &&
2006 current->row_height_val[tile_y] > 1) {
2007 int uniform_slice_height, remaining_height_in_ctbs_y;
2008 remaining_height_in_ctbs_y =
2009 current->row_height_val[tile_y];
2010 ues(pps_num_exp_slices_in_tile[
i],
2011 0,
current->row_height_val[tile_y] - 1, 1,
i);
2012 if (
current->pps_num_exp_slices_in_tile[
i] == 0) {
2013 current->num_slices_in_tile[
i] = 1;
2015 slice_top_left_ctu_x[
i] = ctu_x;
2016 slice_top_left_ctu_y[
i] = ctu_y;
2018 uint16_t slice_height_in_ctus;
2019 int num_uniform_slices;
2021 if (
i +
current->pps_num_exp_slices_in_tile[
i] >
2022 current->pps_num_slices_in_pic_minus1 + 1)
2025 for (j = 0; j <
current->pps_num_exp_slices_in_tile[
i];
2027 ues(pps_exp_slice_height_in_ctus_minus1[
i][j], 0,
2028 remaining_height_in_ctbs_y - (
current->pps_num_exp_slices_in_tile[
i] - j), 2,
2030 slice_height_in_ctus =
2032 pps_exp_slice_height_in_ctus_minus1[
i][j] + 1;
2034 current->slice_height_in_ctus[
i + j] =
2035 slice_height_in_ctus;
2036 slice_top_left_ctu_x[
i + j] = ctu_x;
2037 slice_top_left_ctu_y[
i + j] = ctu_y;
2038 ctu_y += slice_height_in_ctus;
2040 remaining_height_in_ctbs_y -= slice_height_in_ctus;
2042 uniform_slice_height = 1 +
2043 (j == 0 ?
current->row_height_val[tile_y] - 1:
2044 current->pps_exp_slice_height_in_ctus_minus1[
i][j-1]);
2046 num_uniform_slices = (remaining_height_in_ctbs_y + uniform_slice_height - 1)
2047 / uniform_slice_height;
2048 if (
i +
current->pps_num_exp_slices_in_tile[
i] + num_uniform_slices >
2049 current->pps_num_slices_in_pic_minus1 + 1)
2052 while (remaining_height_in_ctbs_y > uniform_slice_height) {
2053 current->slice_height_in_ctus[
i + j] =
2054 uniform_slice_height;
2055 slice_top_left_ctu_x[
i + j] = ctu_x;
2056 slice_top_left_ctu_y[
i + j] = ctu_y;
2057 ctu_y += uniform_slice_height;
2059 remaining_height_in_ctbs_y -= uniform_slice_height;
2062 if (remaining_height_in_ctbs_y > 0) {
2063 current->slice_height_in_ctus[
i + j] =
2064 remaining_height_in_ctbs_y;
2065 slice_top_left_ctu_x[
i + j] = ctu_x;
2066 slice_top_left_ctu_y[
i + j] = ctu_y;
2069 current->num_slices_in_tile[
i] = j;
2071 for (
int k = 0; k <
current->num_slices_in_tile[
i]; k++)
2072 current->slice_top_left_tile_idx[
i + k] = tile_idx;
2073 i +=
current->num_slices_in_tile[
i] - 1;
2076 infer(pps_num_exp_slices_in_tile[
i], 0);
2077 if (
current->pps_slice_width_in_tiles_minus1[
i] == 0 &&
2078 current->pps_slice_height_in_tiles_minus1[
i] == 0)
2079 current->num_slices_in_tile[
i] = 1;
2082 j <=
current->pps_slice_height_in_tiles_minus1[
i];
2085 current->row_height_val[tile_y + j];
2089 slice_top_left_ctu_x[
i] = ctu_x;
2090 slice_top_left_ctu_y[
i] = ctu_y;
2093 if (
current->pps_tile_idx_delta_present_flag) {
2098 ses(pps_tile_idx_delta_val[
i],
2099 -tile_idx,
current->num_tiles_in_pic - 1 - tile_idx, 1,
i);
2100 if (
current->pps_tile_idx_delta_val[
i] == 0) {
2102 "pps_tile_idx_delta_val[i] shall not be equal to 0.\n");
2104 tile_idx +=
current->pps_tile_idx_delta_val[
i];
2106 infer(pps_tile_idx_delta_val[
i], 0);
2108 current->pps_slice_width_in_tiles_minus1[
i] + 1;
2109 if (tile_idx %
current->num_tile_columns == 0) {
2111 current->pps_slice_height_in_tiles_minus1[
i] *
2117 if (
i ==
current->pps_num_slices_in_pic_minus1) {
2120 current->slice_top_left_tile_idx[
i] = tile_idx;
2121 current->num_slices_in_tile[
i] = 1;
2122 tile_x = tile_idx %
current->num_tile_columns;
2123 tile_y = tile_idx /
current->num_tile_columns;
2124 if (tile_y >=
current->num_tile_rows)
2127 ctu_x = 0, ctu_y = 0;
2128 for (j = 0; j < tile_x; j++) {
2129 ctu_x +=
current->col_width_val[j];
2131 for (j = 0; j < tile_y; j++) {
2132 ctu_y +=
current->row_height_val[j];
2134 slice_top_left_ctu_x[
i] = ctu_x;
2135 slice_top_left_ctu_y[
i] = ctu_y;
2137 current->pps_slice_width_in_tiles_minus1[
i] =
2138 current->num_tile_columns - tile_x - 1;
2139 current->pps_slice_height_in_tiles_minus1[
i] =
2140 current->num_tile_rows - tile_y - 1;
2142 for (j = 0; j <=
current->pps_slice_height_in_tiles_minus1[
i];
2145 current->row_height_val[tile_y + j];
2149 infer(pps_num_exp_slices_in_tile[
i], 0);
2152 for (
i = 0;
i <=
sps->sps_num_subpics_minus1;
i++) {
2153 current->num_slices_in_subpic[
i] = 0;
2154 for (j = 0; j <=
current->pps_num_slices_in_pic_minus1; j++) {
2155 uint16_t pos_x = 0, pos_y = 0;
2156 pos_x = slice_top_left_ctu_x[j];
2157 pos_y = slice_top_left_ctu_y[j];
2158 if ((pos_x >=
sps->sps_subpic_ctu_top_left_x[
i]) &&
2160 sps->sps_subpic_ctu_top_left_x[
i] +
2161 sps->sps_subpic_width_minus1[
i] + 1) &&
2162 (pos_y >=
sps->sps_subpic_ctu_top_left_y[
i]) &&
2163 (pos_y < sps->sps_subpic_ctu_top_left_y[
i] +
2164 sps->sps_subpic_height_minus1[
i] + 1)) {
2165 current->num_slices_in_subpic[
i]++;
2168 if (!
current->num_slices_in_subpic[
i])
2170 num_slices +=
current->num_slices_in_subpic[
i];
2172 if (
current->pps_num_slices_in_pic_minus1 + 1 != num_slices)
2175 if (
current->pps_no_pic_partition_flag)
2176 infer(pps_num_slices_in_pic_minus1, 0);
2177 else if (
current->pps_single_slice_per_subpic_flag) {
2178 for (
i = 0;
i <=
sps->sps_num_subpics_minus1;
i++)
2179 current->num_slices_in_subpic[
i] = 1;
2180 infer(pps_num_slices_in_pic_minus1,
2181 sps->sps_num_subpics_minus1);
2185 if (!
current->pps_rect_slice_flag ||
2186 current->pps_single_slice_per_subpic_flag ||
2187 current->pps_num_slices_in_pic_minus1 > 0)
2188 flag(pps_loop_filter_across_slices_enabled_flag);
2190 infer(pps_loop_filter_across_slices_enabled_flag, 0);
2192 infer(pps_num_exp_tile_columns_minus1, 0);
2193 infer(pps_tile_column_width_minus1[0], pic_width_in_ctbs_y - 1);
2194 infer(pps_num_exp_tile_rows_minus1, 0);
2195 infer(pps_tile_row_height_minus1[0], pic_height_in_ctbs_y - 1);
2196 current->col_width_val[0] = pic_width_in_ctbs_y;
2197 current->row_height_val[0] = pic_height_in_ctbs_y;
2198 current->num_tile_columns = 1;
2200 current->num_tiles_in_pic = 1;
2203 flag(pps_cabac_init_present_flag);
2204 for (
i = 0;
i < 2;
i++)
2205 ues(pps_num_ref_idx_default_active_minus1[
i], 0, 14, 1,
i);
2206 flag(pps_rpl1_idx_present_flag);
2207 flag(pps_weighted_pred_flag);
2208 flag(pps_weighted_bipred_flag);
2209 flag(pps_ref_wraparound_enabled_flag);
2210 if (
current->pps_ref_wraparound_enabled_flag) {
2211 ue(pps_pic_width_minus_wraparound_offset,
2212 0, (
current->pps_pic_width_in_luma_samples / min_cb_size_y)
2213 - (ctb_size_y / min_cb_size_y) - 2);
2216 qp_bd_offset = 6 *
sps->sps_bitdepth_minus8;
2217 se(pps_init_qp_minus26, -(26 + qp_bd_offset), 37);
2218 flag(pps_cu_qp_delta_enabled_flag);
2219 flag(pps_chroma_tool_offsets_present_flag);
2220 if (
current->pps_chroma_tool_offsets_present_flag) {
2221 se(pps_cb_qp_offset, -12, 12);
2222 se(pps_cr_qp_offset, -12, 12);
2223 flag(pps_joint_cbcr_qp_offset_present_flag);
2224 if (
current->pps_joint_cbcr_qp_offset_present_flag)
2225 se(pps_joint_cbcr_qp_offset_value, -12, 12);
2227 infer(pps_joint_cbcr_qp_offset_value, 0);
2228 flag(pps_slice_chroma_qp_offsets_present_flag);
2229 flag(pps_cu_chroma_qp_offset_list_enabled_flag);
2230 if (
current->pps_cu_chroma_qp_offset_list_enabled_flag) {
2231 ue(pps_chroma_qp_offset_list_len_minus1, 0, 5);
2232 for (
i = 0;
i <=
current->pps_chroma_qp_offset_list_len_minus1;
i++) {
2233 ses(pps_cb_qp_offset_list[
i], -12, 12, 1,
i);
2234 ses(pps_cr_qp_offset_list[
i], -12, 12, 1,
i);
2235 if (
current->pps_joint_cbcr_qp_offset_present_flag)
2236 ses(pps_joint_cbcr_qp_offset_list[
i], -12, 12, 1,
i);
2238 infer(pps_joint_cbcr_qp_offset_list[
i], 0);
2242 infer(pps_cb_qp_offset, 0);
2243 infer(pps_cr_qp_offset, 0);
2244 infer(pps_joint_cbcr_qp_offset_present_flag, 0);
2245 infer(pps_joint_cbcr_qp_offset_value, 0);
2246 infer(pps_slice_chroma_qp_offsets_present_flag, 0);
2247 infer(pps_cu_chroma_qp_offset_list_enabled_flag, 0);
2249 flag(pps_deblocking_filter_control_present_flag);
2250 if (
current->pps_deblocking_filter_control_present_flag) {
2251 flag(pps_deblocking_filter_override_enabled_flag);
2252 flag(pps_deblocking_filter_disabled_flag);
2253 if (!
current->pps_no_pic_partition_flag &&
2254 current->pps_deblocking_filter_override_enabled_flag)
2255 flag(pps_dbf_info_in_ph_flag);
2257 infer(pps_dbf_info_in_ph_flag, 0);
2258 if (!
current->pps_deblocking_filter_disabled_flag) {
2259 se(pps_luma_beta_offset_div2, -12, 12);
2260 se(pps_luma_tc_offset_div2, -12, 12);
2261 if (
current->pps_chroma_tool_offsets_present_flag) {
2262 se(pps_cb_beta_offset_div2, -12, 12);
2263 se(pps_cb_tc_offset_div2, -12, 12);
2264 se(pps_cr_beta_offset_div2, -12, 12);
2265 se(pps_cr_tc_offset_div2, -12, 12);
2267 infer(pps_cb_beta_offset_div2,
2268 current->pps_luma_beta_offset_div2);
2269 infer(pps_cb_tc_offset_div2,
current->pps_luma_tc_offset_div2);
2270 infer(pps_cr_beta_offset_div2,
2271 current->pps_luma_beta_offset_div2);
2272 infer(pps_cr_tc_offset_div2,
current->pps_luma_tc_offset_div2);
2275 infer(pps_luma_beta_offset_div2, 0);
2276 infer(pps_luma_tc_offset_div2, 0);
2277 infer(pps_cb_beta_offset_div2, 0);
2278 infer(pps_cb_tc_offset_div2, 0);
2279 infer(pps_cr_beta_offset_div2, 0);
2280 infer(pps_cr_tc_offset_div2, 0);
2283 infer(pps_deblocking_filter_override_enabled_flag, 0);
2284 infer(pps_deblocking_filter_disabled_flag, 0);
2285 infer(pps_dbf_info_in_ph_flag, 0);
2286 infer(pps_luma_beta_offset_div2, 0);
2287 infer(pps_luma_tc_offset_div2, 0);
2288 infer(pps_cb_beta_offset_div2, 0);
2289 infer(pps_cb_tc_offset_div2, 0);
2290 infer(pps_cr_beta_offset_div2, 0);
2291 infer(pps_cr_tc_offset_div2, 0);
2294 if (!
current->pps_no_pic_partition_flag) {
2295 flag(pps_rpl_info_in_ph_flag);
2296 flag(pps_sao_info_in_ph_flag);
2297 flag(pps_alf_info_in_ph_flag);
2298 if ((
current->pps_weighted_pred_flag ||
2299 current->pps_weighted_bipred_flag) &&
2300 current->pps_rpl_info_in_ph_flag)
2301 flag(pps_wp_info_in_ph_flag);
2302 flag(pps_qp_delta_info_in_ph_flag);
2304 flag(pps_picture_header_extension_present_flag);
2305 flag(pps_slice_header_extension_present_flag);
2307 flag(pps_extension_flag);
2308 if (
current->pps_extension_flag)
2466 static const uint8_t diag_scan_order[64][2] = {
2467 { 0, 0, }, { 0, 1, }, { 1, 0, }, { 0, 2, }, { 1, 1, }, { 2, 0, }, { 0, 3, }, { 1, 2, },
2468 { 2, 1, }, { 3, 0, }, { 0, 4, }, { 1, 3, }, { 2, 2, }, { 3, 1, }, { 4, 0, }, { 0, 5, },
2469 { 1, 4, }, { 2, 3, }, { 3, 2, }, { 4, 1, }, { 5, 0, }, { 0, 6, }, { 1, 5, }, { 2, 4, },
2470 { 3, 3, }, { 4, 2, }, { 5, 1, }, { 6, 0, }, { 0, 7, }, { 1, 6, }, { 2, 5, }, { 3, 4, },
2471 { 4, 3, }, { 5, 2, }, { 6, 1, }, { 7, 0, }, { 1, 7, }, { 2, 6, }, { 3, 5, }, { 4, 4, },
2472 { 5, 3, }, { 6, 2, }, { 7, 1, }, { 2, 7, }, { 3, 6, }, { 4, 5, }, { 5, 4, }, { 6, 3, },
2473 { 7, 2, }, { 3, 7, }, { 4, 6, }, { 5, 5, }, { 6, 4, }, { 7, 3, }, { 4, 7, }, { 5, 6, },
2474 { 6, 5, }, { 7, 4, }, { 5, 7, }, { 6, 6, }, { 7, 5, }, { 6, 7, }, { 7, 6, }, { 7, 7, }, };
2477 for (
int id = 0;
id < 28;
id ++) {
2478 if (
current->aps_chroma_present_flag ||
id % 3 == 2 ||
id == 27) {
2479 flags(scaling_list_copy_mode_flag[
id], 1,
id);
2480 if (!
current->scaling_list_copy_mode_flag[
id])
2481 flags(scaling_list_pred_mode_flag[
id], 1,
id);
2483 infer(scaling_list_pred_mode_flag[
id], 0);
2484 if ((
current->scaling_list_copy_mode_flag[
id] ||
2485 current->scaling_list_pred_mode_flag[
id]) &&
2486 id != 0 &&
id != 2 &&
id != 8) {
2487 int max_id_delta = (
id < 2) ?
id : ((
id < 8) ? (
id - 2) : (
id - 8));
2488 ues(scaling_list_pred_id_delta[
id], 0, max_id_delta, 1,
id);
2490 if (!
current->scaling_list_copy_mode_flag[
id]) {
2491 int matrix_size =
id < 2 ? 2 : (
id < 8 ? 4 : 8);
2494 ses(scaling_list_dc_coef[idx], -128, 127, 1, idx);
2496 for (
int i = 0;
i < matrix_size * matrix_size;
i++) {
2497 int x = diag_scan_order[
i][0];
2498 int y = diag_scan_order[
i][1];
2499 if (!(
id > 25 && x >= 4 && y >= 4))
2500 ses(scaling_list_delta_coef[
id][
i], -128, 127, 2,
id,
i);
2502 }
else if (
id > 13) {
2504 infer(scaling_list_dc_coef[idx], 0);
2507 infer(scaling_list_copy_mode_flag[
id], 1);
2508 infer(scaling_list_pred_mode_flag[
id], 0);
2659 unsigned int ctb_log2_size_y, min_cb_log2_size_y,
2660 min_qt_log2_size_intra_y, min_qt_log2_size_inter_y;
2661 uint8_t qp_bd_offset;
2663 flag(ph_gdr_or_irap_pic_flag);
2664 flag(ph_non_ref_pic_flag);
2665 if (
current->ph_gdr_or_irap_pic_flag)
2666 flag(ph_gdr_pic_flag);
2668 infer(ph_gdr_pic_flag, 0);
2669 flag(ph_inter_slice_allowed_flag);
2670 if (
current->ph_inter_slice_allowed_flag)
2671 flag(ph_intra_slice_allowed_flag);
2673 infer(ph_intra_slice_allowed_flag, 1);
2678 current->ph_pic_parameter_set_id);
2681 sps = h266->
sps[
pps->pps_seq_parameter_set_id];
2684 pps->pps_seq_parameter_set_id);
2687 vps = h266->
vps[
sps->sps_video_parameter_set_id];
2690 sps->sps_video_parameter_set_id);
2694 ub(
sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4, ph_pic_order_cnt_lsb);
2695 if (
current->ph_gdr_pic_flag) {
2699 ue(ph_recovery_poc_cnt, 0, UINT32_MAX - 1);
2701 ue(ph_recovery_poc_cnt, 0,
2702 (1 << (
sps->sps_log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1);
2706 for (
i = 0;
i <
sps->sps_num_extra_ph_bytes * 8;
i++) {
2707 if (
sps->sps_extra_ph_bit_present_flag[
i])
2710 if (
sps->sps_poc_msb_cycle_flag) {
2711 flag(ph_poc_msb_cycle_present_flag);
2712 if (
current->ph_poc_msb_cycle_present_flag)
2713 ub(
sps->sps_poc_msb_cycle_len_minus1 + 1, ph_poc_msb_cycle_val);
2715 if (
sps->sps_alf_enabled_flag &&
pps->pps_alf_info_in_ph_flag) {
2716 flag(ph_alf_enabled_flag);
2717 if (
current->ph_alf_enabled_flag) {
2719 ub(3, ph_num_alf_aps_ids_luma);
2720 for (
i = 0;
i <
current->ph_num_alf_aps_ids_luma;
i++)
2721 ubs(3, ph_alf_aps_id_luma[
i], 1,
i);
2723 if (
sps->sps_chroma_format_idc != 0) {
2724 flag(ph_alf_cb_enabled_flag);
2725 flag(ph_alf_cr_enabled_flag);
2727 infer(ph_alf_cb_enabled_flag, 0);
2728 infer(ph_alf_cr_enabled_flag, 0);
2731 if (
current->ph_alf_cb_enabled_flag
2732 ||
current->ph_alf_cr_enabled_flag) {
2733 ub(3, ph_alf_aps_id_chroma);
2736 if (
sps->sps_ccalf_enabled_flag) {
2737 flag(ph_alf_cc_cb_enabled_flag);
2738 if (
current->ph_alf_cc_cb_enabled_flag)
2739 ub(3, ph_alf_cc_cb_aps_id);
2740 flag(ph_alf_cc_cr_enabled_flag);
2741 if (
current->ph_alf_cc_cr_enabled_flag)
2742 ub(3, ph_alf_cc_cr_aps_id);
2746 infer(ph_alf_enabled_flag, 0);
2748 if (
sps->sps_lmcs_enabled_flag) {
2749 flag(ph_lmcs_enabled_flag);
2750 if (
current->ph_lmcs_enabled_flag) {
2751 ub(2, ph_lmcs_aps_id);
2752 if (
sps->sps_chroma_format_idc != 0)
2753 flag(ph_chroma_residual_scale_flag);
2755 infer(ph_chroma_residual_scale_flag, 0);
2758 infer(ph_lmcs_enabled_flag, 0);
2759 infer(ph_chroma_residual_scale_flag, 0);
2762 if (
sps->sps_explicit_scaling_list_enabled_flag) {
2763 flag(ph_explicit_scaling_list_enabled_flag);
2764 if (
current->ph_explicit_scaling_list_enabled_flag) {
2766 ub(3, ph_scaling_list_aps_id);
2769 infer(ph_explicit_scaling_list_enabled_flag, 0);
2771 if (
sps->sps_virtual_boundaries_enabled_flag &&
2772 !
sps->sps_virtual_boundaries_present_flag) {
2773 flag(ph_virtual_boundaries_present_flag);
2774 if (
current->ph_virtual_boundaries_present_flag) {
2775 ue(ph_num_ver_virtual_boundaries,
2777 for (
i = 0;
i <
current->ph_num_ver_virtual_boundaries;
i++) {
2778 ues(ph_virtual_boundary_pos_x_minus1[
i],
2779 0, (
pps->pps_pic_width_in_luma_samples + 7) / 8 - 2, 1,
i);
2781 ue(ph_num_hor_virtual_boundaries,
2783 for (
i = 0;
i <
current->ph_num_hor_virtual_boundaries;
i++) {
2784 ues(ph_virtual_boundary_pos_y_minus1[
i],
2785 0, (
pps->pps_pic_height_in_luma_samples + 7) / 8 - 2, 1,
i);
2788 infer(ph_num_ver_virtual_boundaries, 0);
2789 infer(ph_num_hor_virtual_boundaries, 0);
2792 if (
pps->pps_output_flag_present_flag && !
current->ph_non_ref_pic_flag)
2793 flag(ph_pic_output_flag);
2795 infer(ph_pic_output_flag, 1);
2796 if (
pps->pps_rpl_info_in_ph_flag) {
2800 if (
sps->sps_partition_constraints_override_enabled_flag)
2801 flag(ph_partition_constraints_override_flag);
2803 infer(ph_partition_constraints_override_flag, 0);
2805 ctb_log2_size_y =
sps->sps_log2_ctu_size_minus5 + 5;
2806 min_cb_log2_size_y =
sps->sps_log2_min_luma_coding_block_size_minus2 + 2;
2807 if (
current->ph_intra_slice_allowed_flag) {
2808 if (
current->ph_partition_constraints_override_flag) {
2809 ue(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2810 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2811 ue(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2812 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2813 if (
current->ph_max_mtt_hierarchy_depth_intra_slice_luma != 0) {
2814 min_qt_log2_size_intra_y =
2815 current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2817 ue(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2818 0, (
sps->sps_qtbtt_dual_tree_intra_flag ?
2819 FFMIN(6, ctb_log2_size_y) :
2820 ctb_log2_size_y) - min_qt_log2_size_intra_y);
2821 ue(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2822 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_y);
2824 infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2825 sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2826 infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2827 sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2829 if (
sps->sps_qtbtt_dual_tree_intra_flag) {
2830 ue(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2831 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2832 ue(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2833 0, 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2834 if (
current->ph_max_mtt_hierarchy_depth_intra_slice_chroma != 0) {
2835 unsigned int min_qt_log2_size_intra_c =
2836 current->ph_log2_diff_min_qt_min_cb_intra_slice_chroma +
2838 ue(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2839 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2840 ue(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2841 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_intra_c);
2843 infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2844 sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2845 infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2846 sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2850 infer(ph_log2_diff_min_qt_min_cb_intra_slice_luma,
2851 sps->sps_log2_diff_min_qt_min_cb_intra_slice_luma);
2852 infer(ph_max_mtt_hierarchy_depth_intra_slice_luma,
2853 sps->sps_max_mtt_hierarchy_depth_intra_slice_luma);
2854 infer(ph_log2_diff_max_bt_min_qt_intra_slice_luma,
2855 sps->sps_log2_diff_max_bt_min_qt_intra_slice_luma);
2856 infer(ph_log2_diff_max_tt_min_qt_intra_slice_luma,
2857 sps->sps_log2_diff_max_tt_min_qt_intra_slice_luma);
2858 infer(ph_log2_diff_min_qt_min_cb_intra_slice_chroma,
2859 sps->sps_log2_diff_min_qt_min_cb_intra_slice_chroma);
2860 infer(ph_max_mtt_hierarchy_depth_intra_slice_chroma,
2861 sps->sps_max_mtt_hierarchy_depth_intra_slice_chroma);
2862 infer(ph_log2_diff_max_bt_min_qt_intra_slice_chroma,
2863 sps->sps_log2_diff_max_bt_min_qt_intra_slice_chroma);
2864 infer(ph_log2_diff_max_tt_min_qt_intra_slice_chroma,
2865 sps->sps_log2_diff_max_tt_min_qt_intra_slice_chroma);
2868 min_qt_log2_size_intra_y =
2869 current->ph_log2_diff_min_qt_min_cb_intra_slice_luma +
2871 if (
pps->pps_cu_qp_delta_enabled_flag)
2872 ue(ph_cu_qp_delta_subdiv_intra_slice, 0,
2873 2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2874 current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2876 infer(ph_cu_qp_delta_subdiv_intra_slice, 0);
2878 if (
pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2879 ue(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0,
2880 2 * (ctb_log2_size_y - min_qt_log2_size_intra_y +
2881 current->ph_max_mtt_hierarchy_depth_intra_slice_luma));
2883 infer(ph_cu_chroma_qp_offset_subdiv_intra_slice, 0);
2885 if (
current->ph_inter_slice_allowed_flag) {
2886 if (
current->ph_partition_constraints_override_flag) {
2887 ue(ph_log2_diff_min_qt_min_cb_inter_slice,
2888 0,
FFMIN(6, ctb_log2_size_y) - min_cb_log2_size_y);
2889 min_qt_log2_size_inter_y =
2890 current->ph_log2_diff_min_qt_min_cb_inter_slice +
2892 ue(ph_max_mtt_hierarchy_depth_inter_slice, 0,
2893 2 * (ctb_log2_size_y - min_cb_log2_size_y));
2894 if (
current->ph_max_mtt_hierarchy_depth_inter_slice != 0) {
2895 ue(ph_log2_diff_max_bt_min_qt_inter_slice,
2896 0, ctb_log2_size_y - min_qt_log2_size_inter_y);
2897 ue(ph_log2_diff_max_tt_min_qt_inter_slice,
2898 0,
FFMIN(6, ctb_log2_size_y) - min_qt_log2_size_inter_y);
2901 infer(ph_log2_diff_min_qt_min_cb_inter_slice,
2902 sps->sps_log2_diff_min_qt_min_cb_inter_slice);
2903 min_qt_log2_size_inter_y =
2904 current->ph_log2_diff_min_qt_min_cb_inter_slice +
2906 infer(ph_max_mtt_hierarchy_depth_inter_slice,
2907 sps->sps_max_mtt_hierarchy_depth_inter_slice);
2908 infer(ph_log2_diff_max_bt_min_qt_inter_slice,
2909 sps->sps_log2_diff_max_bt_min_qt_inter_slice);
2910 infer(ph_log2_diff_max_tt_min_qt_inter_slice,
2911 sps->sps_log2_diff_max_tt_min_qt_inter_slice);
2914 if (
pps->pps_cu_qp_delta_enabled_flag)
2915 ue(ph_cu_qp_delta_subdiv_inter_slice, 0,
2916 2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2917 current->ph_max_mtt_hierarchy_depth_inter_slice));
2919 infer(ph_cu_qp_delta_subdiv_inter_slice, 0);
2921 if (
pps->pps_cu_chroma_qp_offset_list_enabled_flag)
2922 ue(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0,
2923 2 * (ctb_log2_size_y - min_qt_log2_size_inter_y +
2924 current->ph_max_mtt_hierarchy_depth_inter_slice));
2926 infer(ph_cu_chroma_qp_offset_subdiv_inter_slice, 0);
2927 if (
sps->sps_temporal_mvp_enabled_flag) {
2928 flag(ph_temporal_mvp_enabled_flag);
2929 if (
current->ph_temporal_mvp_enabled_flag &&
2930 pps->pps_rpl_info_in_ph_flag) {
2931 if (
current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0)
2932 flag(ph_collocated_from_l0_flag);
2934 infer(ph_collocated_from_l0_flag, 1);
2935 if ((
current->ph_collocated_from_l0_flag &&
2936 current->ph_ref_pic_lists.rpl_ref_list[0].num_ref_entries > 1)
2937 || (!
current->ph_collocated_from_l0_flag &&
2938 current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 1)) {
2940 current->ph_collocated_from_l0_flag ? 0 : 1;
2941 ue(ph_collocated_ref_idx, 0,
2942 current->ph_ref_pic_lists.rpl_ref_list[idx].
2943 num_ref_entries - 1);
2945 infer(ph_collocated_ref_idx, 0);
2949 if (
sps->sps_mmvd_fullpel_only_enabled_flag)
2950 flag(ph_mmvd_fullpel_only_flag);
2952 infer(ph_mmvd_fullpel_only_flag, 0);
2953 if (!
pps->pps_rpl_info_in_ph_flag ||
2954 current->ph_ref_pic_lists.rpl_ref_list[1].num_ref_entries > 0) {
2955 flag(ph_mvd_l1_zero_flag);
2956 if (
sps->sps_bdof_control_present_in_ph_flag) {
2957 flag(ph_bdof_disabled_flag);
2959 if (!
sps->sps_bdof_control_present_in_ph_flag)
2960 infer(ph_bdof_disabled_flag,
2961 1 -
sps->sps_bdof_enabled_flag);
2963 infer(ph_bdof_disabled_flag, 1);
2965 if (
sps->sps_dmvr_control_present_in_ph_flag) {
2966 flag(ph_dmvr_disabled_flag);
2968 if (!
sps->sps_dmvr_control_present_in_ph_flag)
2969 infer(ph_dmvr_disabled_flag,
2970 1 -
sps->sps_dmvr_enabled_flag);
2972 infer(ph_dmvr_disabled_flag, 1);
2975 infer(ph_mvd_l1_zero_flag, 1);
2977 if (
sps->sps_prof_control_present_in_ph_flag)
2978 flag(ph_prof_disabled_flag);
2980 infer(ph_prof_disabled_flag, !
sps->sps_affine_prof_enabled_flag);
2981 if ((
pps->pps_weighted_pred_flag ||
2982 pps->pps_weighted_bipred_flag) &&
pps->pps_wp_info_in_ph_flag) {
2986 uint8_t num_ref_idx_active[2] = { 0, 0 };
2989 num_ref_idx_active, &
current->ph_pred_weight_table));
2993 qp_bd_offset = 6 *
sps->sps_bitdepth_minus8;
2994 if (
pps->pps_qp_delta_info_in_ph_flag)
2995 se(ph_qp_delta, -qp_bd_offset - (26 +
pps->pps_init_qp_minus26),
2996 63 - (26 +
pps->pps_init_qp_minus26));
2998 if (
sps->sps_joint_cbcr_enabled_flag)
2999 flag(ph_joint_cbcr_sign_flag);
3001 infer(ph_joint_cbcr_sign_flag, 0);
3002 if (
sps->sps_sao_enabled_flag &&
pps->pps_sao_info_in_ph_flag) {
3003 flag(ph_sao_luma_enabled_flag);
3004 if (
sps->sps_chroma_format_idc != 0)
3005 flag(ph_sao_chroma_enabled_flag);
3007 infer(ph_sao_chroma_enabled_flag, 0);
3009 infer(ph_sao_luma_enabled_flag, 0);
3010 infer(ph_sao_chroma_enabled_flag, 0);
3013 if (
pps->pps_dbf_info_in_ph_flag)
3014 flag(ph_deblocking_params_present_flag);
3016 infer(ph_deblocking_params_present_flag, 0);
3018 if (
current->ph_deblocking_params_present_flag) {
3019 if (!
pps->pps_deblocking_filter_disabled_flag) {
3020 flag(ph_deblocking_filter_disabled_flag);
3021 if (!
current->ph_deblocking_filter_disabled_flag) {
3022 se(ph_luma_beta_offset_div2, -12, 12);
3023 se(ph_luma_tc_offset_div2, -12, 12);
3024 if (
pps->pps_chroma_tool_offsets_present_flag) {
3025 se(ph_cb_beta_offset_div2, -12, 12);
3026 se(ph_cb_tc_offset_div2, -12, 12);
3027 se(ph_cr_beta_offset_div2, -12, 12);
3028 se(ph_cr_tc_offset_div2, -12, 12);
3030 infer(ph_cb_beta_offset_div2,
3031 current->ph_luma_beta_offset_div2);
3032 infer(ph_cb_tc_offset_div2,
3033 current->ph_luma_tc_offset_div2);
3034 infer(ph_cr_beta_offset_div2,
3035 current->ph_luma_beta_offset_div2);
3036 infer(ph_cr_tc_offset_div2,
3037 current->ph_luma_tc_offset_div2);
3041 infer(ph_deblocking_filter_disabled_flag, 0);
3044 infer(ph_deblocking_filter_disabled_flag,
pps->pps_deblocking_filter_disabled_flag);
3045 if (!
current->ph_deblocking_filter_disabled_flag) {
3046 infer(ph_luma_beta_offset_div2,
pps->pps_luma_beta_offset_div2);
3047 infer(ph_luma_tc_offset_div2,
pps->pps_luma_tc_offset_div2);
3048 infer(ph_cb_beta_offset_div2,
pps->pps_cb_beta_offset_div2);
3049 infer(ph_cb_tc_offset_div2,
pps->pps_cb_tc_offset_div2);
3050 infer(ph_cr_beta_offset_div2,
pps->pps_cr_beta_offset_div2);
3051 infer(ph_cr_tc_offset_div2,
pps->pps_cr_tc_offset_div2);
3055 if (
pps->pps_picture_header_extension_present_flag) {
3056 ue(ph_extension_length, 0, 256);
3057 for (
i = 0;
i <
current->ph_extension_length;
i++)
3058 us(8, ph_extension_data_byte[
i], 0x00, 0xff, 1,
i);
3086 uint8_t nal_unit_type, qp_bd_offset;
3087 uint16_t num_slices_in_subpic;
3093 flag(sh_picture_header_in_slice_header_flag);
3094 if (
current->sh_picture_header_in_slice_header_flag) {
3102 "Picture header not available.\n");
3107 pps = h266->
pps[
ph->ph_pic_parameter_set_id];
3110 ph->ph_pic_parameter_set_id);
3113 sps = h266->
sps[
pps->pps_seq_parameter_set_id];
3116 pps->pps_seq_parameter_set_id);
3120 if (
sps->sps_subpic_info_present_flag) {
3121 ub(
sps->sps_subpic_id_len_minus1 + 1, sh_subpic_id);
3122 for (
i = 0;
i <=
sps->sps_num_subpics_minus1;
i++) {
3123 if (
pps->sub_pic_id_val[
i] ==
current->sh_subpic_id) {
3128 if (
i >
sps->sps_num_subpics_minus1) {
3136 num_slices_in_subpic =
pps->num_slices_in_subpic[
current->curr_subpic_idx];
3138 if ((
pps->pps_rect_slice_flag && num_slices_in_subpic > 1) ||
3139 (!
pps->pps_rect_slice_flag &&
pps->num_tiles_in_pic > 1)) {
3141 if (!
pps->pps_rect_slice_flag) {
3143 max =
pps->num_tiles_in_pic - 1;
3146 max = num_slices_in_subpic - 1;
3153 for (
i = 0;
i <
sps->sps_num_extra_sh_bytes * 8;
i++) {
3154 if (
sps->sps_extra_sh_bit_present_flag[
i])
3158 if (!
pps->pps_rect_slice_flag &&
3159 pps->num_tiles_in_pic -
current->sh_slice_address > 1)
3160 ue(sh_num_tiles_in_slice_minus1, 0,
pps->num_tiles_in_pic - 1 -
current->sh_slice_address);
3162 infer(sh_num_tiles_in_slice_minus1, 0);
3164 if (
ph->ph_inter_slice_allowed_flag)
3165 ue(sh_slice_type, 0, 2);
3167 infer(sh_slice_type, 2);
3169 nal_unit_type =
current->nal_unit_header.nal_unit_type;
3172 flag(sh_no_output_of_prior_pics_flag);
3174 if (
sps->sps_alf_enabled_flag) {
3175 if (!
pps->pps_alf_info_in_ph_flag) {
3176 flag(sh_alf_enabled_flag);
3177 if (
current->sh_alf_enabled_flag) {
3178 ub(3, sh_num_alf_aps_ids_luma);
3179 for (
i = 0;
i <
current->sh_num_alf_aps_ids_luma;
i++)
3180 ubs(3, sh_alf_aps_id_luma[
i], 1,
i);
3182 if (
sps->sps_chroma_format_idc != 0) {
3183 flag(sh_alf_cb_enabled_flag);
3184 flag(sh_alf_cr_enabled_flag);
3186 if (
current->sh_alf_cb_enabled_flag ||
3187 current->sh_alf_cr_enabled_flag) {
3188 ub(3, sh_alf_aps_id_chroma);
3191 if (
sps->sps_ccalf_enabled_flag) {
3192 flag(sh_alf_cc_cb_enabled_flag);
3193 if (
current->sh_alf_cc_cb_enabled_flag)
3194 ub(3, sh_alf_cc_cb_aps_id);
3196 flag(sh_alf_cc_cr_enabled_flag);
3197 if (
current->sh_alf_cc_cr_enabled_flag)
3198 ub(3, sh_alf_cc_cr_aps_id);
3202 infer(sh_alf_enabled_flag,
ph->ph_alf_enabled_flag);
3203 if (
current->sh_alf_enabled_flag) {
3204 infer(sh_num_alf_aps_ids_luma,
ph->ph_num_alf_aps_ids_luma);
3205 for (
i = 0;
i <
current->sh_num_alf_aps_ids_luma;
i++)
3206 infer(sh_alf_aps_id_luma[
i],
ph->ph_alf_aps_id_luma[
i]);
3208 infer(sh_alf_cb_enabled_flag,
ph->ph_alf_cb_enabled_flag);
3209 infer(sh_alf_cr_enabled_flag,
ph->ph_alf_cr_enabled_flag);
3210 if (
current->sh_alf_cb_enabled_flag ||
current->sh_alf_cr_enabled_flag)
3211 infer(sh_alf_aps_id_chroma,
ph->ph_alf_aps_id_chroma);
3213 if (
sps->sps_ccalf_enabled_flag) {
3214 infer(sh_alf_cc_cb_enabled_flag,
ph->ph_alf_cc_cb_enabled_flag);
3215 if (
current->sh_alf_cc_cb_enabled_flag)
3216 infer(sh_alf_cc_cb_aps_id,
ph->ph_alf_cc_cb_aps_id);
3218 infer(sh_alf_cc_cr_enabled_flag,
ph->ph_alf_cc_cr_enabled_flag);
3219 if (
current->sh_alf_cc_cr_enabled_flag)
3220 infer(sh_alf_cc_cr_aps_id,
ph->ph_alf_cc_cr_aps_id);
3226 if (
current->sh_picture_header_in_slice_header_flag) {
3227 infer(sh_lmcs_used_flag,
ph->ph_lmcs_enabled_flag);
3228 infer(sh_explicit_scaling_list_used_flag,
3229 ph->ph_explicit_scaling_list_enabled_flag);
3231 if (
ph->ph_lmcs_enabled_flag)
3232 flag(sh_lmcs_used_flag);
3234 infer(sh_lmcs_used_flag, 0);
3236 if (
ph->ph_explicit_scaling_list_enabled_flag)
3237 flag(sh_explicit_scaling_list_used_flag);
3239 infer(sh_explicit_scaling_list_used_flag, 0);
3242 if (!
pps->pps_rpl_info_in_ph_flag &&
3255 flag(sh_num_ref_idx_active_override_flag);
3256 if (
current->sh_num_ref_idx_active_override_flag) {
3260 ues(sh_num_ref_idx_active_minus1[
i], 0, 14, 1,
i);
3262 infer(sh_num_ref_idx_active_minus1[
i], 0);
3265 infer(sh_num_ref_idx_active_override_flag, 1);
3268 for (
i = 0;
i < 2;
i++) {
3271 if (
current->sh_num_ref_idx_active_override_flag) {
3272 current->num_ref_idx_active[
i] =
current->sh_num_ref_idx_active_minus1[
i] + 1;
3276 pps->pps_num_ref_idx_default_active_minus1[
i] + 1);
3279 if (
current->num_ref_idx_active[
i] <= 0) {
3281 "Inter slice but no reference pictures available for RPL%d.\n",
i);
3285 current->num_ref_idx_active[
i] = 0;
3290 if (
pps->pps_cabac_init_present_flag)
3291 flag(sh_cabac_init_flag);
3293 infer(sh_cabac_init_flag, 0);
3294 if (
ph->ph_temporal_mvp_enabled_flag) {
3295 if (!
pps->pps_rpl_info_in_ph_flag) {
3297 flag(sh_collocated_from_l0_flag);
3299 infer(sh_collocated_from_l0_flag, 1);
3300 if ((
current->sh_collocated_from_l0_flag &&
3301 current->num_ref_idx_active[0] > 1) ||
3302 (!
current->sh_collocated_from_l0_flag &&
3303 current->num_ref_idx_active[1] > 1)) {
3304 unsigned int idx =
current->sh_collocated_from_l0_flag ? 0 : 1;
3305 ue(sh_collocated_ref_idx, 0,
current->num_ref_idx_active[idx] - 1);
3307 infer(sh_collocated_ref_idx, 0);
3311 infer(sh_collocated_from_l0_flag,
ph->ph_collocated_from_l0_flag);
3313 infer(sh_collocated_from_l0_flag, 1);
3314 infer(sh_collocated_ref_idx,
ph->ph_collocated_ref_idx);
3317 if (!
pps->pps_wp_info_in_ph_flag &&
3318 ((
pps->pps_weighted_pred_flag &&
3320 (
pps->pps_weighted_bipred_flag &&
3324 &
current->sh_pred_weight_table));
3327 qp_bd_offset = 6 *
sps->sps_bitdepth_minus8;
3328 if (!
pps->pps_qp_delta_info_in_ph_flag)
3329 se(sh_qp_delta, -qp_bd_offset - (26 +
pps->pps_init_qp_minus26),
3330 63 - (26 +
pps->pps_init_qp_minus26));
3331 if (
pps->pps_slice_chroma_qp_offsets_present_flag) {
3334 se(sh_cb_qp_offset, -12, 12);
3335 off =
pps->pps_cb_qp_offset +
current->sh_cb_qp_offset;
3336 if (off < -12 || off > 12) {
3338 "pps_cb_qp_offset + sh_cb_qp_offset (%d) not in range [-12, 12].\n",
3343 se(sh_cr_qp_offset, -12, 12);
3344 off =
pps->pps_cr_qp_offset +
current->sh_cr_qp_offset;
3345 if (off < -12 || off > 12) {
3347 "pps_cr_qp_offset + sh_cr_qp_offset (%d) not in range [-12, 12].\n",
3352 if (
sps->sps_joint_cbcr_enabled_flag) {
3353 se(sh_joint_cbcr_qp_offset, -12, 12);
3355 pps->pps_joint_cbcr_qp_offset_value +
3356 current->sh_joint_cbcr_qp_offset;
3357 if (off < -12 || off > 12) {
3359 "pps_joint_cbcr_qp_offset_value + sh_joint_cbcr_qp_offset (%d)"
3360 "not in range [-12, 12]. \n", off);
3364 infer(sh_joint_cbcr_qp_offset, 0);
3367 infer(sh_cb_qp_offset, 0);
3368 infer(sh_cr_qp_offset, 0);
3369 infer(sh_joint_cbcr_qp_offset, 0);
3371 if (
pps->pps_cu_chroma_qp_offset_list_enabled_flag)
3372 flag(sh_cu_chroma_qp_offset_enabled_flag);
3374 infer(sh_cu_chroma_qp_offset_enabled_flag, 0);
3375 if (
sps->sps_sao_enabled_flag && !
pps->pps_sao_info_in_ph_flag) {
3376 flag(sh_sao_luma_used_flag);
3377 if (
sps->sps_chroma_format_idc != 0)
3378 flag(sh_sao_chroma_used_flag);
3380 infer(sh_sao_chroma_used_flag,
ph->ph_sao_chroma_enabled_flag);
3382 infer(sh_sao_luma_used_flag,
ph->ph_sao_luma_enabled_flag);
3383 infer(sh_sao_chroma_used_flag,
ph->ph_sao_chroma_enabled_flag);
3386 if (
pps->pps_deblocking_filter_override_enabled_flag &&
3387 !
pps->pps_dbf_info_in_ph_flag)
3388 flag(sh_deblocking_params_present_flag);
3390 infer(sh_deblocking_params_present_flag, 0);
3391 if (
current->sh_deblocking_params_present_flag) {
3392 if (!
pps->pps_deblocking_filter_disabled_flag)
3393 flag(sh_deblocking_filter_disabled_flag);
3395 infer(sh_deblocking_filter_disabled_flag, 0);
3396 if (!
current->sh_deblocking_filter_disabled_flag) {
3397 se(sh_luma_beta_offset_div2, -12, 12);
3398 se(sh_luma_tc_offset_div2, -12, 12);
3399 if (
pps->pps_chroma_tool_offsets_present_flag) {
3400 se(sh_cb_beta_offset_div2, -12, 12);
3401 se(sh_cb_tc_offset_div2, -12, 12);
3402 se(sh_cr_beta_offset_div2, -12, 12);
3403 se(sh_cr_tc_offset_div2, -12, 12);
3405 infer(sh_cb_beta_offset_div2,
3406 current->sh_luma_beta_offset_div2);
3407 infer(sh_cb_tc_offset_div2,
current->sh_luma_tc_offset_div2);
3408 infer(sh_cr_beta_offset_div2,
3409 current->sh_luma_beta_offset_div2);
3410 infer(sh_cr_tc_offset_div2,
current->sh_luma_tc_offset_div2);
3414 infer(sh_deblocking_filter_disabled_flag,
ph->ph_deblocking_filter_disabled_flag);
3415 if (!
current->sh_deblocking_filter_disabled_flag) {
3416 infer(sh_luma_beta_offset_div2,
ph->ph_luma_beta_offset_div2);
3417 infer(sh_luma_tc_offset_div2,
ph->ph_luma_tc_offset_div2);
3418 infer(sh_cb_beta_offset_div2,
ph->ph_cb_beta_offset_div2);
3419 infer(sh_cb_tc_offset_div2,
ph->ph_cb_tc_offset_div2);
3420 infer(sh_cr_beta_offset_div2,
ph->ph_cr_beta_offset_div2);
3421 infer(sh_cr_tc_offset_div2,
ph->ph_cr_tc_offset_div2);
3425 if (
sps->sps_dep_quant_enabled_flag)
3426 flag(sh_dep_quant_used_flag);
3428 infer(sh_dep_quant_used_flag, 0);
3430 if (
sps->sps_sign_data_hiding_enabled_flag &&
3431 !
current->sh_dep_quant_used_flag)
3432 flag(sh_sign_data_hiding_used_flag);
3434 infer(sh_sign_data_hiding_used_flag, 0);
3436 if (
sps->sps_transform_skip_enabled_flag &&
3437 !
current->sh_dep_quant_used_flag &&
3438 !
current->sh_sign_data_hiding_used_flag)
3439 flag(sh_ts_residual_coding_disabled_flag);
3441 infer(sh_ts_residual_coding_disabled_flag, 0);
3443 if (!
current->sh_ts_residual_coding_disabled_flag &&
3444 sps->sps_ts_residual_coding_rice_present_in_sh_flag)
3445 ub(3, sh_ts_residual_coding_rice_idx_minus1);
3447 infer(sh_ts_residual_coding_rice_idx_minus1, 0);
3449 if (
sps->sps_reverse_last_sig_coeff_enabled_flag)
3450 flag(sh_reverse_last_sig_coeff_flag);
3452 infer(sh_reverse_last_sig_coeff_flag, 0);
3454 if (
pps->pps_slice_header_extension_present_flag) {
3455 ue(sh_slice_header_extension_length, 0, 256);
3456 for (
i = 0;
i <
current->sh_slice_header_extension_length;
i++)
3457 us(8, sh_slice_header_extension_data_byte[
i], 0x00, 0xff, 1,
i);
3460 current->num_entry_points = 0;
3461 if (
sps->sps_entry_point_offsets_present_flag) {
3462 uint8_t entropy_sync =
sps->sps_entropy_coding_sync_enabled_flag;
3464 if (
pps->pps_rect_slice_flag) {
3466 int slice_idx =
current->sh_slice_address;
3467 for (
i = 0;
i <
current->curr_subpic_idx;
i++) {
3468 slice_idx +=
pps->num_slices_in_subpic[
i];
3470 if (slice_idx >
pps->pps_num_slices_in_pic_minus1) {
3475 if (
pps->pps_single_slice_per_subpic_flag) {
3476 int width_in_ctus, height_in_ctus;
3477 if (
sps->sps_subpic_info_present_flag) {
3478 width_in_ctus =
sps->sps_subpic_width_minus1[slice_idx] + 1;
3479 height_in_ctus =
sps->sps_subpic_height_minus1[slice_idx] + 1;
3481 const int log2_ctb_size =
sps->sps_log2_ctu_size_minus5 + 5;
3482 const int ctb_size = 1 << log2_ctb_size;
3483 width_in_ctus = (
pps->pps_pic_width_in_luma_samples + ctb_size - 1) >> log2_ctb_size;
3484 height_in_ctus = (
pps->pps_pic_height_in_luma_samples + ctb_size - 1) >> log2_ctb_size;
3487 const int subpic_l =
sps->sps_subpic_ctu_top_left_x[slice_idx];
3488 const int subpic_r = subpic_l + width_in_ctus;
3490 int ctb_x = 0, tile_x = 0;
3491 for (; ctb_x < subpic_l && tile_x <
pps->num_tile_columns; tile_x++)
3492 ctb_x +=
pps->col_width_val[tile_x];
3495 for (; ctb_x < subpic_r && tile_x <
pps->num_tile_columns; tile_x++) {
3496 ctb_x +=
pps->col_width_val[tile_x];
3503 const int subpic_t =
sps->sps_subpic_ctu_top_left_y[slice_idx];
3504 const int subpic_b = subpic_t + height_in_ctus;
3506 int ctb_y = 0, tile_y = 0, height_in_tiles;
3507 for (; ctb_y < subpic_t && tile_y <
pps->num_tile_rows; tile_y++)
3508 ctb_y +=
pps->row_height_val[tile_y];
3510 height_in_tiles = 0;
3511 for (; ctb_y < subpic_b && tile_y <
pps->num_tile_rows; tile_y++) {
3512 ctb_y +=
pps->row_height_val[tile_y];
3516 height = height_in_tiles;
3520 pps->pps_slice_width_in_tiles_minus1[slice_idx] + 1;
3523 height =
pps->slice_height_in_ctus[slice_idx];
3525 height =
pps->pps_slice_height_in_tiles_minus1[slice_idx] + 1;
3532 for (tile_idx =
current->sh_slice_address;
3535 current->sh_num_tiles_in_slice_minus1; tile_idx++) {
3536 tile_y = tile_idx /
pps->num_tile_columns;
3544 "%" PRIu32
".\n",
current->num_entry_points);
3547 if (
current->num_entry_points > 0) {
3548 ue(sh_entry_offset_len_minus1, 0, 31);
3549 for (
i = 0;
i <
current->num_entry_points;
i++) {
3551 sh_entry_point_offset_minus1[
i], 1,
i);