34 16, 16, 16, 16, 17, 18, 21, 24,
35 16, 16, 16, 16, 17, 19, 22, 25,
36 16, 16, 17, 18, 20, 22, 25, 29,
37 16, 16, 18, 21, 24, 27, 31, 36,
38 17, 17, 20, 24, 30, 35, 41, 47,
39 18, 19, 22, 27, 35, 44, 54, 65,
40 21, 22, 25, 31, 41, 54, 70, 88,
41 24, 25, 29, 36, 47, 65, 88, 115
45 16, 16, 16, 16, 17, 18, 20, 24,
46 16, 16, 16, 17, 18, 20, 24, 25,
47 16, 16, 17, 18, 20, 24, 25, 28,
48 16, 17, 18, 20, 24, 25, 28, 33,
49 17, 18, 20, 24, 25, 28, 33, 41,
50 18, 20, 24, 25, 28, 33, 41, 54,
51 20, 24, 25, 28, 33, 41, 54, 71,
52 24, 25, 28, 33, 41, 54, 71, 91
65 if (
s->pps ==
s->pps_list[
id])
73 if (
s->sps_list[
id]) {
74 if (
s->sps ==
s->sps_list[
id])
79 if (
s->pps_list[
i] &&
s->pps_list[
i]->sps_id ==
id)
90 if (
s->vps_list[
id]) {
91 if (
s->vps ==
s->vps_list[
id])
95 if (
s->sps_list[
i] &&
s->sps_list[
i]->vps_id ==
id)
111 if (rps !=
sps->st_rps &&
sps->nb_st_rps)
118 if (is_slice_header) {
122 "Invalid value of delta_idx in slice header RPS: %d > %d.\n",
129 rps_ridx = &
sps->st_rps[rps -
sps->st_rps - 1];
135 "Invalid value of abs_delta_rps: %d\n",
148 if (i < rps_ridx->num_delta_pocs)
149 delta_poc = delta_rps + rps_ridx->
delta_poc[
i];
151 delta_poc = delta_rps;
161 "Invalid num_delta_pocs: %d\n", k);
173 for (k =
i - 1; k >= 0; k--) {
175 if (delta_poc <
tmp) {
199 unsigned int prev, nb_positive_pics;
214 if (delta_poc < 1 || delta_poc > 32768) {
216 "Invalid value of delta_poc: %d\n",
225 for (
i = 0;
i < nb_positive_pics;
i++) {
227 if (delta_poc < 1 || delta_poc > 32768) {
229 "Invalid value of delta_poc: %d\n",
267 for (
i = 0;
i < 32;
i++) {
270 if (
ptl->profile_idc == 0 &&
i > 0 &&
ptl->profile_compatibility_flag[
i])
271 ptl->profile_idc =
i;
278 #define check_profile_idc(idc) \
279 ptl->profile_idc == idc || ptl->profile_compatibility_flag[idc]
314 #undef check_profile_idc
320 PTL *
ptl,
int max_num_sub_layers)
324 get_bits_left(gb) < 8 + (8*2 * (max_num_sub_layers - 1 > 0))) {
331 for (
i = 0;
i < max_num_sub_layers - 1;
i++) {
336 if (max_num_sub_layers - 1> 0)
337 for (
i = max_num_sub_layers - 1;
i < 8;
i++)
339 for (
i = 0;
i < max_num_sub_layers - 1;
i++) {
343 "PTL information for sublayer %i too short\n",
i);
349 "Not enough data for sublayer %i level_idc\n",
i);
364 for (
i = 0;
i < nb_cpb;
i++) {
368 if (subpic_params_present) {
380 if (common_inf_present) {
407 for (
int i = 0;
i < max_sublayers;
i++) {
408 unsigned fixed_pic_rate_general_flag =
get_bits1(gb);
409 unsigned fixed_pic_rate_within_cvs_flag = 0;
410 unsigned low_delay_hrd_flag = 0;
413 if (!fixed_pic_rate_general_flag)
414 fixed_pic_rate_within_cvs_flag =
get_bits1(gb);
417 if (fixed_pic_rate_within_cvs_flag || fixed_pic_rate_general_flag)
423 if (!low_delay_hrd_flag) {
425 if (cpb_cnt_minus1 > 31) {
454 if (!memcmp(vps1, vps2, offsetof(
HEVCVPS, hdr)))
475 if (nal_size >
sizeof(
vps->data)) {
478 nal_size,
sizeof(
vps->data));
479 vps->data_size =
sizeof(
vps->data);
481 vps->data_size = nal_size;
503 vps->vps_max_sub_layers);
510 vps->vps_sub_layer_ordering_info_present_flag =
get_bits1(gb);
512 i =
vps->vps_sub_layer_ordering_info_present_flag ? 0 :
vps->vps_max_sub_layers - 1;
513 for (;
i <
vps->vps_max_sub_layers;
i++) {
520 vps->vps_max_dec_pic_buffering[
i] - 1);
523 if (
vps->vps_num_reorder_pics[
i] >
vps->vps_max_dec_pic_buffering[
i] - 1) {
525 vps->vps_num_reorder_pics[
i]);
533 if (
vps->vps_num_layer_sets < 1 ||
vps->vps_num_layer_sets > 1024 ||
539 for (
i = 1;
i <
vps->vps_num_layer_sets;
i++)
540 for (j = 0; j <=
vps->vps_max_layer_id; j++)
544 if (
vps->vps_timing_info_present_flag) {
547 vps->vps_poc_proportional_to_timing_flag =
get_bits1(gb);
548 if (
vps->vps_poc_proportional_to_timing_flag)
551 if (
vps->vps_num_hrd_parameters > (
unsigned)
vps->vps_num_layer_sets) {
553 "vps_num_hrd_parameters %d is invalid\n",
vps->vps_num_hrd_parameters);
557 if (
vps->vps_num_hrd_parameters) {
563 for (
i = 0;
i <
vps->vps_num_hrd_parameters;
i++) {
564 int common_inf_present = 1;
570 vps->vps_max_sub_layers);
600 VUI backup_vui, *vui = &
sps->vui;
611 switch (
sps->pix_fmt) {
631 memcpy(&backup, gb,
sizeof(backup));
632 memcpy(&backup_vui, vui,
sizeof(backup_vui));
647 if (apply_defdispwin &&
650 "discarding vui default display window, "
651 "original values are l:%u r:%u t:%u b:%u\n",
672 "Strange VUI timing information, retrying...\n");
673 memcpy(vui, &backup_vui,
sizeof(backup_vui));
674 memcpy(gb, &backup,
sizeof(backup));
696 "Strange VUI bitstream restriction information, retrying"
697 " from timing information...\n");
698 memcpy(vui, &backup_vui,
sizeof(backup_vui));
699 memcpy(gb, &backup,
sizeof(backup));
716 "Overread in VUI, retrying from timing information...\n");
717 memcpy(vui, &backup_vui,
sizeof(backup_vui));
718 memcpy(gb, &backup,
sizeof(backup));
728 for (matrixId = 0; matrixId < 6; matrixId++) {
730 memset(sl->
sl[0][matrixId], 16, 16);
731 sl->
sl_dc[0][matrixId] = 16;
732 sl->
sl_dc[1][matrixId] = 16;
757 uint8_t scaling_list_pred_mode_flag;
758 uint8_t scaling_list_dc_coef[2][6];
759 int size_id, matrix_id,
pos;
762 for (size_id = 0; size_id < 4; size_id++)
763 for (matrix_id = 0; matrix_id < 6; matrix_id += ((size_id == 3) ? 3 : 1)) {
764 scaling_list_pred_mode_flag =
get_bits1(gb);
765 if (!scaling_list_pred_mode_flag) {
771 delta *= (size_id == 3) ? 3 : 1;
772 if (matrix_id <
delta) {
774 "Invalid delta in scaling list data: %d.\n",
delta);
778 memcpy(sl->
sl[size_id][matrix_id],
779 sl->
sl[size_id][matrix_id -
delta],
780 size_id > 0 ? 64 : 16);
782 sl->
sl_dc[size_id - 2][matrix_id] = sl->
sl_dc[size_id - 2][matrix_id -
delta];
785 int next_coef, coef_num;
786 int32_t scaling_list_delta_coef;
789 coef_num =
FFMIN(64, 1 << (4 + (size_id << 1)));
792 if (scaling_list_coeff_minus8 < -7 ||
793 scaling_list_coeff_minus8 > 247)
795 scaling_list_dc_coef[size_id - 2][matrix_id] = scaling_list_coeff_minus8 + 8;
796 next_coef = scaling_list_dc_coef[size_id - 2][matrix_id];
797 sl->
sl_dc[size_id - 2][matrix_id] = next_coef;
799 for (
i = 0;
i < coef_num;
i++) {
808 next_coef = (next_coef + 256
U + scaling_list_delta_coef) % 256;
809 sl->
sl[size_id][matrix_id][
pos] = next_coef;
814 if (
sps->chroma_format_idc == 3) {
815 for (
i = 0;
i < 64;
i++) {
816 sl->
sl[3][1][
i] = sl->
sl[2][1][
i];
817 sl->
sl[3][2][
i] = sl->
sl[2][2][
i];
818 sl->
sl[3][4][
i] = sl->
sl[2][4][
i];
819 sl->
sl[3][5][
i] = sl->
sl[2][5][
i];
834 switch (
sps->bit_depth) {
861 "The following bit-depths are currently specified: 8, 9, 10 and 12 bits, "
862 "chroma_format_idc is %d, depth is %d\n",
863 sps->chroma_format_idc,
sps->bit_depth);
871 sps->hshift[0] =
sps->vshift[0] = 0;
872 sps->hshift[2] =
sps->hshift[1] =
desc->log2_chroma_w;
873 sps->vshift[2] =
sps->vshift[1] =
desc->log2_chroma_h;
875 sps->pixel_shift =
sps->bit_depth > 8;
881 int apply_defdispwin,
const HEVCVPS *
const *vps_list,
886 int bit_depth_chroma, start, num_comps;
893 if (vps_list && !vps_list[
sps->vps_id]) {
902 sps->max_sub_layers);
918 if (
sps->chroma_format_idc > 3
U) {
923 if (
sps->chroma_format_idc == 3)
926 if (
sps->separate_colour_plane_flag)
927 sps->chroma_format_idc = 0;
932 sps->height, 0, avctx)) < 0)
936 if (
sps->conformance_window_flag) {
946 "discarding sps conformance window, "
947 "original values are l:%u r:%u t:%u b:%u\n",
948 sps->pic_conf_win.left_offset,
949 sps->pic_conf_win.right_offset,
950 sps->pic_conf_win.top_offset,
951 sps->pic_conf_win.bottom_offset);
953 sps->pic_conf_win.left_offset =
954 sps->pic_conf_win.right_offset =
955 sps->pic_conf_win.top_offset =
956 sps->pic_conf_win.bottom_offset = 0;
958 sps->output_window =
sps->pic_conf_win;
962 if (
sps->bit_depth > 16) {
968 if (bit_depth_chroma > 16) {
973 if (
sps->chroma_format_idc && bit_depth_chroma !=
sps->bit_depth) {
975 "Luma bit depth (%d) is different from chroma bit depth (%d), "
976 "this is unsupported.\n",
977 sps->bit_depth, bit_depth_chroma);
980 sps->bit_depth_chroma = bit_depth_chroma;
987 if (
sps->log2_max_poc_lsb > 16) {
989 sps->log2_max_poc_lsb - 4);
994 start =
sps->sublayer_ordering_info_flag ? 0 :
sps->max_sub_layers - 1;
995 for (
i = start;
i <
sps->max_sub_layers;
i++) {
1001 sps->temporal_layer[
i].max_dec_pic_buffering - 1
U);
1004 if (
sps->temporal_layer[
i].num_reorder_pics >
sps->temporal_layer[
i].max_dec_pic_buffering - 1) {
1006 sps->temporal_layer[
i].num_reorder_pics);
1011 sps->temporal_layer[
i].max_dec_pic_buffering =
sps->temporal_layer[
i].num_reorder_pics + 1;
1015 if (!
sps->sublayer_ordering_info_flag) {
1016 for (
i = 0;
i < start;
i++) {
1017 sps->temporal_layer[
i].max_dec_pic_buffering =
sps->temporal_layer[start].max_dec_pic_buffering;
1018 sps->temporal_layer[
i].num_reorder_pics =
sps->temporal_layer[start].num_reorder_pics;
1019 sps->temporal_layer[
i].max_latency_increase =
sps->temporal_layer[start].max_latency_increase;
1027 sps->log2_max_trafo_size =
sps->log2_diff_max_min_transform_block_size +
1028 sps->log2_min_tb_size;
1030 if (
sps->log2_min_cb_size < 3 ||
sps->log2_min_cb_size > 30) {
1035 if (
sps->log2_diff_max_min_coding_block_size > 30) {
1036 av_log(avctx,
AV_LOG_ERROR,
"Invalid value %d for log2_diff_max_min_coding_block_size",
sps->log2_diff_max_min_coding_block_size);
1040 if (
sps->log2_min_tb_size >=
sps->log2_min_cb_size ||
sps->log2_min_tb_size < 2) {
1045 if (
sps->log2_diff_max_min_transform_block_size > 30) {
1046 av_log(avctx,
AV_LOG_ERROR,
"Invalid value %d for log2_diff_max_min_transform_block_size",
1047 sps->log2_diff_max_min_transform_block_size);
1055 if (
sps->scaling_list_enable_flag) {
1069 if (
sps->pcm_enabled_flag) {
1073 sps->pcm.log2_max_pcm_cb_size =
sps->pcm.log2_min_pcm_cb_size +
1075 if (
FFMAX(
sps->pcm.bit_depth,
sps->pcm.bit_depth_chroma) >
sps->bit_depth) {
1077 "PCM bit depth (%d, %d) is greater than normal bit depth (%d)\n",
1078 sps->pcm.bit_depth,
sps->pcm.bit_depth_chroma,
sps->bit_depth);
1091 for (
i = 0;
i <
sps->nb_st_rps;
i++) {
1098 if (
sps->long_term_ref_pics_present_flag) {
1102 sps->num_long_term_ref_pics_sps);
1105 for (
i = 0;
i <
sps->num_long_term_ref_pics_sps;
i++) {
1112 sps->sps_strong_intra_smoothing_enable_flag =
get_bits1(gb);
1115 if (
sps->vui_present)
1119 if (
sps->sps_extension_present_flag) {
1126 if (
sps->sps_range_extension_flag) {
1127 sps->transform_skip_rotation_enabled_flag =
get_bits1(gb);
1128 sps->transform_skip_context_enabled_flag =
get_bits1(gb);
1133 sps->extended_precision_processing_flag =
get_bits1(gb);
1134 if (
sps->extended_precision_processing_flag)
1136 "extended_precision_processing_flag not yet implemented\n");
1139 sps->high_precision_offsets_enabled_flag =
get_bits1(gb);
1140 if (
sps->high_precision_offsets_enabled_flag)
1142 "high_precision_offsets_enabled_flag not yet implemented\n");
1144 sps->persistent_rice_adaptation_enabled_flag =
get_bits1(gb);
1146 sps->cabac_bypass_alignment_enabled_flag =
get_bits1(gb);
1147 if (
sps->cabac_bypass_alignment_enabled_flag)
1149 "cabac_bypass_alignment_enabled_flag not yet implemented\n");
1152 if (
sps->sps_multilayer_extension_flag) {
1155 "sps_multilayer_extension_flag not yet implemented\n");
1158 if (
sps->sps_3d_extension_flag) {
1159 for (
i = 0;
i <= 1;
i++) {
1179 "sps_3d_extension_flag not yet implemented\n");
1182 if (
sps->sps_scc_extension_flag) {
1185 if (
sps->palette_mode_enabled_flag) {
1188 sps->sps_palette_predictor_initializers_present_flag =
get_bits1(gb);
1190 if (
sps->sps_palette_predictor_initializers_present_flag) {
1194 "sps_num_palette_predictor_initializers out of range: %u\n",
1195 sps->sps_num_palette_predictor_initializers);
1198 num_comps = !
sps->chroma_format_idc ? 1 : 3;
1201 for (
i = 0;
i <
sps->sps_num_palette_predictor_initializers;
i++)
1206 sps->motion_vector_resolution_control_idc =
get_bits(gb, 2);
1207 sps->intra_boundary_filtering_disabled_flag =
get_bits1(gb);
1210 if (apply_defdispwin) {
1211 sps->output_window.left_offset +=
sps->vui.def_disp_win.left_offset;
1212 sps->output_window.right_offset +=
sps->vui.def_disp_win.right_offset;
1213 sps->output_window.top_offset +=
sps->vui.def_disp_win.top_offset;
1214 sps->output_window.bottom_offset +=
sps->vui.def_disp_win.bottom_offset;
1217 ow = &
sps->output_window;
1228 "Displaying the whole video surface.\n");
1229 memset(ow, 0,
sizeof(*ow));
1230 memset(&
sps->pic_conf_win, 0,
sizeof(
sps->pic_conf_win));
1234 sps->log2_ctb_size =
sps->log2_min_cb_size +
1235 sps->log2_diff_max_min_coding_block_size;
1236 sps->log2_min_pu_size =
sps->log2_min_cb_size - 1;
1242 if (
sps->log2_ctb_size < 4) {
1245 "log2_ctb_size %d differs from the bounds of any known profile\n",
1246 sps->log2_ctb_size);
1251 sps->ctb_width = (
sps->width + (1 <<
sps->log2_ctb_size) - 1) >>
sps->log2_ctb_size;
1252 sps->ctb_height = (
sps->height + (1 <<
sps->log2_ctb_size) - 1) >>
sps->log2_ctb_size;
1253 sps->ctb_size =
sps->ctb_width *
sps->ctb_height;
1255 sps->min_cb_width =
sps->width >>
sps->log2_min_cb_size;
1256 sps->min_cb_height =
sps->height >>
sps->log2_min_cb_size;
1257 sps->min_tb_width =
sps->width >>
sps->log2_min_tb_size;
1258 sps->min_tb_height =
sps->height >>
sps->log2_min_tb_size;
1259 sps->min_pu_width =
sps->width >>
sps->log2_min_pu_size;
1260 sps->min_pu_height =
sps->height >>
sps->log2_min_pu_size;
1261 sps->tb_mask = (1 << (
sps->log2_ctb_size -
sps->log2_min_tb_size)) - 1;
1263 sps->qp_bd_offset = 6 * (
sps->bit_depth - 8);
1271 if (
sps->max_transform_hierarchy_depth_inter >
sps->log2_ctb_size -
sps->log2_min_tb_size) {
1272 av_log(avctx,
AV_LOG_ERROR,
"max_transform_hierarchy_depth_inter out of range: %d\n",
1273 sps->max_transform_hierarchy_depth_inter);
1276 if (
sps->max_transform_hierarchy_depth_intra >
sps->log2_ctb_size -
sps->log2_min_tb_size) {
1277 av_log(avctx,
AV_LOG_ERROR,
"max_transform_hierarchy_depth_intra out of range: %d\n",
1278 sps->max_transform_hierarchy_depth_intra);
1281 if (
sps->log2_max_trafo_size >
FFMIN(
sps->log2_ctb_size, 5)) {
1283 "max transform block size out of range: %d\n",
1284 sps->log2_max_trafo_size);
1301 unsigned int sps_id;
1311 if (nal_size >
sizeof(
sps->data)) {
1314 nal_size,
sizeof(
sps->data));
1315 sps->data_size =
sizeof(
sps->data);
1317 sps->data_size = nal_size;
1331 "Parsed SPS: id %d; coded wxh: %dx%d; "
1332 "cropped wxh: %dx%d; pix_fmt: %s.\n",
1333 sps_id,
sps->width,
sps->height,
1334 sps->width - (
sps->output_window.left_offset +
sps->output_window.right_offset),
1335 sps->height - (
sps->output_window.top_offset +
sps->output_window.bottom_offset),
1370 int idx_y,
int idx_cb,
int idx_cr,
int inp_length)
1372 unsigned int split_octant_flag, part_num_y, coded_res_flag, res_coeff_q, res_coeff_r;
1375 part_num_y = 1 <<
pps->cm_y_part_num_log2;
1377 split_octant_flag = inp_depth <
pps->cm_octant_depth ?
get_bits1(gb) : 0;
1379 if (split_octant_flag)
1380 for (
int k = 0; k < 2; k++)
1381 for (
int m = 0; m < 2; m++)
1382 for (
int n = 0; n < 2; n++)
1384 idx_y + part_num_y * k * inp_length / 2,
1385 idx_cb + m * inp_length / 2,
1386 idx_cr + n * inp_length / 2,
1389 for (
int i = 0;
i < part_num_y;
i++) {
1390 for (
int j = 0; j < 4; j++) {
1393 for (
int c = 0;
c < 3;
c++) {
1395 cm_res_bits =
FFMAX(0, 10 +
pps->luma_bit_depth_cm_input -
1396 pps->luma_bit_depth_cm_output -
1397 pps->cm_res_quant_bits -
pps->cm_delta_flc_bits);
1398 res_coeff_r = cm_res_bits ?
get_bits(gb, cm_res_bits) : 0;
1399 if (res_coeff_q || res_coeff_r)
1409 if (
pps->num_cm_ref_layers > 62) {
1411 "num_cm_ref_layers_minus1 shall be in the range [0, 61].\n");
1414 for (
int i = 0;
i <
pps->num_cm_ref_layers;
i++)
1428 if (
pps->cm_octant_depth == 1) {
1443 if (
pps->pps_infer_scaling_list_flag)
1444 pps->pps_scaling_list_ref_layer_id =
get_bits(gb, 6);
1447 if (
pps->num_ref_loc_offsets >
vps->vps_max_layers - 1)
1450 for (
int i = 0;
i <
pps->num_ref_loc_offsets;
i++) {
1452 pps->scaled_ref_layer_offset_present_flag[
i] =
get_bits1(gb);
1453 if (
pps->scaled_ref_layer_offset_present_flag[
i]) {
1461 if (
pps->ref_region_offset_present_flag[
i]) {
1469 if (
pps->resample_phase_set_present_flag[
i]) {
1478 if (
pps->colour_mapping_enabled_flag) {
1489 unsigned int num_val_delta_dlt, max_diff = 0;
1490 int min_diff_minus1 = -1;
1493 num_val_delta_dlt =
get_bits(gb,
pps->pps_bit_depth_for_depth_layers_minus8 + 8);
1494 if (num_val_delta_dlt) {
1495 if (num_val_delta_dlt > 1)
1496 max_diff =
get_bits(gb,
pps->pps_bit_depth_for_depth_layers_minus8 + 8);
1497 if (num_val_delta_dlt > 2 && max_diff) {
1501 if (max_diff > (min_diff_minus1 + 1))
1502 for (
int k = 1; k < num_val_delta_dlt; k++) {
1503 len =
av_log2(max_diff - (min_diff_minus1 + 1)) + 1;
1512 unsigned int pps_depth_layers_minus1;
1515 pps_depth_layers_minus1 =
get_bits(gb, 6);
1516 pps->pps_bit_depth_for_depth_layers_minus8 =
get_bits(gb, 4);
1517 for (
int i = 0;
i <= pps_depth_layers_minus1;
i++) {
1521 for (
int j = 0; j <= ((1 << (
pps->pps_bit_depth_for_depth_layers_minus8 + 8)) - 1); j++)
1536 if (
pps->transform_skip_enabled_flag) {
1539 pps->cross_component_prediction_enabled_flag =
get_bits1(gb);
1540 pps->chroma_qp_offset_list_enabled_flag =
get_bits1(gb);
1541 if (
pps->chroma_qp_offset_list_enabled_flag) {
1544 if (
pps->chroma_qp_offset_list_len_minus1 > 5) {
1546 "chroma_qp_offset_list_len_minus1 shall be in the range [0, 5].\n");
1549 for (
int i = 0;
i <=
pps->chroma_qp_offset_list_len_minus1;
i++) {
1551 if (
pps->cb_qp_offset_list[
i]) {
1553 "cb_qp_offset_list not tested yet.\n");
1556 if (
pps->cr_qp_offset_list[
i]) {
1558 "cb_qp_offset_list not tested yet.\n");
1565 if (
pps->log2_sao_offset_scale_luma >
FFMAX(
sps->bit_depth - 10, 0)
1566 ||
pps->log2_sao_offset_scale_chroma >
FFMAX(
sps->bit_depth_chroma - 10, 0)
1579 if (
pps->residual_adaptive_colour_transform_enabled_flag =
get_bits1(gb)) {
1580 pps->pps_slice_act_qp_offsets_present_flag =
get_bits1(gb);
1585 #define CHECK_QP_OFFSET(name) (pps->pps_act_ ## name ## _qp_offset <= -12 || \
1586 pps->pps_act_ ## name ## _qp_offset >= 12)
1588 #undef CHECK_QP_OFFSET
1591 "PpsActQpOffsetY/Cb/Cr shall be in the range of [-12, 12].\n");
1596 if (
pps->pps_palette_predictor_initializers_present_flag =
get_bits1(gb)) {
1598 if (
pps->pps_num_palette_predictor_initializers > 0) {
1601 "pps_num_palette_predictor_initializers out of range: %u\n",
1602 pps->pps_num_palette_predictor_initializers);
1607 if (
pps->luma_bit_depth_entry !=
sps->bit_depth)
1609 if (!
pps->monochrome_palette_flag) {
1611 if (
pps->chroma_bit_depth_entry !=
sps->bit_depth_chroma)
1615 num_comps =
pps->monochrome_palette_flag ? 1 : 3;
1618 for (
int i = 0;
i <
pps->pps_num_palette_predictor_initializers;
i++)
1631 int pic_area_in_ctbs;
1632 int i, j, x, y, ctb_addr_rs, tile_id;
1638 if (!
pps->col_bd || !
pps->row_bd || !
pps->col_idxX)
1641 if (
pps->uniform_spacing_flag) {
1642 if (!
pps->column_width) {
1646 if (!
pps->column_width || !
pps->row_height)
1649 for (
i = 0;
i <
pps->num_tile_columns;
i++) {
1650 pps->column_width[
i] = ((
i + 1) *
sps->ctb_width) /
pps->num_tile_columns -
1651 (
i *
sps->ctb_width) /
pps->num_tile_columns;
1654 for (
i = 0;
i <
pps->num_tile_rows;
i++) {
1655 pps->row_height[
i] = ((
i + 1) *
sps->ctb_height) /
pps->num_tile_rows -
1656 (
i *
sps->ctb_height) /
pps->num_tile_rows;
1661 for (
i = 0;
i <
pps->num_tile_columns;
i++)
1662 pps->col_bd[
i + 1] =
pps->col_bd[
i] +
pps->column_width[
i];
1665 for (
i = 0;
i <
pps->num_tile_rows;
i++)
1666 pps->row_bd[
i + 1] =
pps->row_bd[
i] +
pps->row_height[
i];
1668 for (
i = 0, j = 0;
i <
sps->ctb_width;
i++) {
1669 if (
i >
pps->col_bd[j])
1671 pps->col_idxX[
i] = j;
1677 pic_area_in_ctbs =
sps->ctb_width *
sps->ctb_height;
1683 if (!
pps->ctb_addr_rs_to_ts || !
pps->ctb_addr_ts_to_rs ||
1684 !
pps->tile_id || !
pps->min_tb_addr_zs_tab) {
1688 for (ctb_addr_rs = 0; ctb_addr_rs < pic_area_in_ctbs; ctb_addr_rs++) {
1689 int tb_x = ctb_addr_rs %
sps->ctb_width;
1690 int tb_y = ctb_addr_rs /
sps->ctb_width;
1695 for (
i = 0;
i <
pps->num_tile_columns;
i++) {
1696 if (tb_x < pps->col_bd[
i + 1]) {
1702 for (
i = 0;
i <
pps->num_tile_rows;
i++) {
1703 if (tb_y < pps->row_bd[
i + 1]) {
1709 for (
i = 0;
i < tile_x;
i++)
1710 val +=
pps->row_height[tile_y] *
pps->column_width[
i];
1711 for (
i = 0;
i < tile_y;
i++)
1714 val += (tb_y -
pps->row_bd[tile_y]) *
pps->column_width[tile_x] +
1715 tb_x -
pps->col_bd[tile_x];
1717 pps->ctb_addr_rs_to_ts[ctb_addr_rs] =
val;
1718 pps->ctb_addr_ts_to_rs[
val] = ctb_addr_rs;
1721 for (j = 0, tile_id = 0; j <
pps->num_tile_rows; j++)
1722 for (
i = 0;
i <
pps->num_tile_columns;
i++, tile_id++)
1723 for (y =
pps->row_bd[j]; y < pps->row_bd[j + 1]; y++)
1724 for (x =
pps->col_bd[
i]; x < pps->col_bd[
i + 1]; x++)
1725 pps->tile_id[
pps->ctb_addr_rs_to_ts[y *
sps->ctb_width + x]] = tile_id;
1728 if (!
pps->tile_pos_rs)
1731 for (j = 0; j <
pps->num_tile_rows; j++)
1732 for (
i = 0;
i <
pps->num_tile_columns;
i++)
1733 pps->tile_pos_rs[j *
pps->num_tile_columns +
i] =
1734 pps->row_bd[j] *
sps->ctb_width +
pps->col_bd[
i];
1736 log2_diff =
sps->log2_ctb_size -
sps->log2_min_tb_size;
1737 pps->min_tb_addr_zs = &
pps->min_tb_addr_zs_tab[1*(
sps->tb_mask+2)+1];
1738 for (y = 0; y <
sps->tb_mask+2; y++) {
1739 pps->min_tb_addr_zs_tab[y*(
sps->tb_mask+2)] = -1;
1740 pps->min_tb_addr_zs_tab[y] = -1;
1742 for (y = 0; y <
sps->tb_mask+1; y++) {
1743 for (x = 0; x <
sps->tb_mask+1; x++) {
1744 int tb_x = x >> log2_diff;
1745 int tb_y = y >> log2_diff;
1746 int rs =
sps->ctb_width * tb_y + tb_x;
1747 int val =
pps->ctb_addr_rs_to_ts[rs] << (log2_diff * 2);
1748 for (
i = 0;
i < log2_diff;
i++) {
1750 val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0);
1752 pps->min_tb_addr_zs[y * (
sps->tb_mask+2) + x] =
val;
1765 unsigned int pps_id = 0;
1767 unsigned log2_parallel_merge_level_minus2;
1777 if (nal_size >
sizeof(
pps->data)) {
1780 nal_size,
sizeof(
pps->data));
1781 pps->data_size =
sizeof(
pps->data);
1783 pps->data_size = nal_size;
1788 pps->loop_filter_across_tiles_enabled_flag = 1;
1789 pps->num_tile_columns = 1;
1790 pps->num_tile_rows = 1;
1791 pps->uniform_spacing_flag = 1;
1792 pps->disable_dbf = 0;
1793 pps->beta_offset = 0;
1795 pps->log2_max_transform_skip_block_size = 2;
1818 pps->dependent_slice_segments_enabled_flag =
get_bits1(gb);
1820 pps->num_extra_slice_header_bits =
get_bits(gb, 3);
1831 pps->num_ref_idx_l0_default_active,
pps->num_ref_idx_l1_default_active);
1841 pps->diff_cu_qp_delta_depth = 0;
1842 if (
pps->cu_qp_delta_enabled_flag)
1845 if (
pps->diff_cu_qp_delta_depth < 0 ||
1846 pps->diff_cu_qp_delta_depth >
sps->log2_diff_max_min_coding_block_size) {
1848 pps->diff_cu_qp_delta_depth);
1854 if (
pps->cb_qp_offset < -12 ||
pps->cb_qp_offset > 12) {
1861 if (
pps->cr_qp_offset < -12 ||
pps->cr_qp_offset > 12) {
1867 pps->pic_slice_level_chroma_qp_offsets_present_flag =
get_bits1(gb);
1876 if (
pps->tiles_enabled_flag) {
1880 if (num_tile_columns_minus1 < 0 ||
1881 num_tile_columns_minus1 >=
sps->ctb_width) {
1883 num_tile_columns_minus1);
1887 if (num_tile_rows_minus1 < 0 ||
1888 num_tile_rows_minus1 >=
sps->ctb_height) {
1890 num_tile_rows_minus1);
1894 pps->num_tile_columns = num_tile_columns_minus1 + 1;
1895 pps->num_tile_rows = num_tile_rows_minus1 + 1;
1899 if (!
pps->column_width || !
pps->row_height) {
1905 if (!
pps->uniform_spacing_flag) {
1907 for (
i = 0;
i <
pps->num_tile_columns - 1;
i++) {
1909 sum +=
pps->column_width[
i];
1911 if (sum >=
sps->ctb_width) {
1916 pps->column_width[
pps->num_tile_columns - 1] =
sps->ctb_width - sum;
1919 for (
i = 0;
i <
pps->num_tile_rows - 1;
i++) {
1921 sum +=
pps->row_height[
i];
1923 if (sum >=
sps->ctb_height) {
1928 pps->row_height[
pps->num_tile_rows - 1] =
sps->ctb_height - sum;
1930 pps->loop_filter_across_tiles_enabled_flag =
get_bits1(gb);
1933 pps->seq_loop_filter_across_slices_enabled_flag =
get_bits1(gb);
1935 pps->deblocking_filter_control_present_flag =
get_bits1(gb);
1936 if (
pps->deblocking_filter_control_present_flag) {
1937 pps->deblocking_filter_override_enabled_flag =
get_bits1(gb);
1939 if (!
pps->disable_dbf) {
1942 if (beta_offset_div2 < -6 || beta_offset_div2 > 6) {
1948 if (tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1954 pps->beta_offset = 2 * beta_offset_div2;
1955 pps->tc_offset = 2 * tc_offset_div2;
1960 if (
pps->scaling_list_data_present_flag) {
1968 if (log2_parallel_merge_level_minus2 >
sps->log2_ctb_size) {
1970 log2_parallel_merge_level_minus2);
1974 pps->log2_parallel_merge_level = log2_parallel_merge_level_minus2 + 2;
1976 pps->slice_header_extension_present_flag =
get_bits1(gb);
1979 if (
pps->pps_extension_present_flag) {
1991 if (
pps->pps_multilayer_extension_flag) {
1996 if (
pps->pps_3d_extension_flag) {
2001 if (
pps->pps_scc_extension_flag) {
2044 int max_poc_lsb = 1 <<
sps->log2_max_poc_lsb;
2045 int prev_poc_lsb = pocTid0 % max_poc_lsb;
2046 int prev_poc_msb = pocTid0 - prev_poc_lsb;
2049 if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2)
2050 poc_msb = prev_poc_msb + max_poc_lsb;
2051 else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2)
2052 poc_msb = prev_poc_msb - max_poc_lsb;
2054 poc_msb = prev_poc_msb;
2062 return poc_msb + poc_lsb;