35 16, 16, 16, 16, 17, 18, 21, 24,
36 16, 16, 16, 16, 17, 19, 22, 25,
37 16, 16, 17, 18, 20, 22, 25, 29,
38 16, 16, 18, 21, 24, 27, 31, 36,
39 17, 17, 20, 24, 30, 35, 41, 47,
40 18, 19, 22, 27, 35, 44, 54, 65,
41 21, 22, 25, 31, 41, 54, 70, 88,
42 24, 25, 29, 36, 47, 65, 88, 115
46 16, 16, 16, 16, 17, 18, 20, 24,
47 16, 16, 16, 17, 18, 20, 24, 25,
48 16, 16, 17, 18, 20, 24, 25, 28,
49 16, 17, 18, 20, 24, 25, 28, 33,
50 17, 18, 20, 24, 25, 28, 33, 41,
51 18, 20, 24, 25, 28, 33, 41, 54,
52 20, 24, 25, 28, 33, 41, 54, 71,
53 24, 25, 28, 33, 41, 54, 71, 91
66 if (
s->pps ==
s->pps_list[
id])
74 if (
s->sps_list[
id]) {
75 if (
s->sps ==
s->sps_list[
id])
80 if (
s->pps_list[
i] &&
s->pps_list[
i]->sps_id ==
id)
91 if (
s->vps_list[
id]) {
92 if (
s->vps ==
s->vps_list[
id])
96 if (
s->sps_list[
i] &&
s->sps_list[
i]->vps_id ==
id)
113 if (rps !=
sps->st_rps &&
sps->nb_st_rps)
118 uint8_t used[32] = { 0 };
121 if (is_slice_header) {
125 "Invalid value of delta_idx in slice header RPS: %d > %d.\n",
132 rps_ridx = &
sps->st_rps[rps -
sps->st_rps - 1];
138 "Invalid value of abs_delta_rps: %d\n",
151 if (i < rps_ridx->num_delta_pocs)
152 delta_poc = delta_rps + rps_ridx->
delta_poc[
i];
154 delta_poc = delta_rps;
164 "Invalid num_delta_pocs: %d\n", k);
176 for (k =
i - 1; k >= 0; k--) {
178 if (delta_poc <
tmp) {
180 used[k + 1] = used[k];
203 rps->
used |= (uint32_t)used[
i] <<
i;
205 unsigned int nb_positive_pics;
222 if (delta_poc < 1 || delta_poc > 32768) {
224 "Invalid value of delta_poc: %d\n",
233 for (
i = 0;
i < nb_positive_pics;
i++) {
235 if (delta_poc < 1 || delta_poc > 32768) {
237 "Invalid value of delta_poc: %d\n",
275 for (
i = 0;
i < 32;
i++) {
278 if (
ptl->profile_idc == 0 &&
i > 0 &&
ptl->profile_compatibility_flag[
i])
279 ptl->profile_idc =
i;
286 #define check_profile_idc(idc) \
287 ptl->profile_idc == idc || ptl->profile_compatibility_flag[idc]
322 #undef check_profile_idc
328 PTL *
ptl,
int max_num_sub_layers)
332 get_bits_left(gb) < 8 + (8*2 * (max_num_sub_layers - 1 > 0))) {
339 for (
i = 0;
i < max_num_sub_layers - 1;
i++) {
344 if (max_num_sub_layers - 1> 0)
345 for (
i = max_num_sub_layers - 1;
i < 8;
i++)
347 for (
i = 0;
i < max_num_sub_layers - 1;
i++) {
351 "PTL information for sublayer %i too short\n",
i);
357 "Not enough data for sublayer %i level_idc\n",
i);
372 for (
i = 0;
i < nb_cpb;
i++) {
376 if (subpic_params_present) {
388 if (common_inf_present) {
415 for (
int i = 0;
i < max_sublayers;
i++) {
416 unsigned fixed_pic_rate_general_flag =
get_bits1(gb);
417 unsigned fixed_pic_rate_within_cvs_flag = 0;
418 unsigned low_delay_hrd_flag = 0;
421 if (!fixed_pic_rate_general_flag)
422 fixed_pic_rate_within_cvs_flag =
get_bits1(gb);
425 if (fixed_pic_rate_within_cvs_flag || fixed_pic_rate_general_flag)
431 if (!low_delay_hrd_flag) {
433 if (cpb_cnt_minus1 > 31) {
483 vps->data_size = nal_size;
489 vps->vps_id = vps_id;
507 vps->vps_max_sub_layers);
514 vps->vps_sub_layer_ordering_info_present_flag =
get_bits1(gb);
516 i =
vps->vps_sub_layer_ordering_info_present_flag ? 0 :
vps->vps_max_sub_layers - 1;
517 for (;
i <
vps->vps_max_sub_layers;
i++) {
524 vps->vps_max_dec_pic_buffering[
i] - 1);
527 if (
vps->vps_num_reorder_pics[
i] >
vps->vps_max_dec_pic_buffering[
i] - 1) {
529 vps->vps_num_reorder_pics[
i]);
537 if (
vps->vps_num_layer_sets < 1 ||
vps->vps_num_layer_sets > 1024 ||
543 for (
i = 1;
i <
vps->vps_num_layer_sets;
i++)
544 for (j = 0; j <=
vps->vps_max_layer_id; j++)
548 if (
vps->vps_timing_info_present_flag) {
551 vps->vps_poc_proportional_to_timing_flag =
get_bits1(gb);
552 if (
vps->vps_poc_proportional_to_timing_flag)
555 if (
vps->vps_num_hrd_parameters > (
unsigned)
vps->vps_num_layer_sets) {
557 "vps_num_hrd_parameters %d is invalid\n",
vps->vps_num_hrd_parameters);
561 if (
vps->vps_num_hrd_parameters) {
567 for (
i = 0;
i <
vps->vps_num_hrd_parameters;
i++) {
568 int common_inf_present = 1;
574 vps->vps_max_sub_layers);
599 VUI backup_vui, *vui = &
sps->vui;
610 switch (
sps->pix_fmt) {
630 memcpy(&backup, gb,
sizeof(backup));
631 memcpy(&backup_vui, vui,
sizeof(backup_vui));
646 if (apply_defdispwin &&
649 "discarding vui default display window, "
650 "original values are l:%u r:%u t:%u b:%u\n",
671 "Strange VUI timing information, retrying...\n");
672 memcpy(vui, &backup_vui,
sizeof(backup_vui));
673 memcpy(gb, &backup,
sizeof(backup));
695 "Strange VUI bitstream restriction information, retrying"
696 " from timing information...\n");
697 memcpy(vui, &backup_vui,
sizeof(backup_vui));
698 memcpy(gb, &backup,
sizeof(backup));
715 "Overread in VUI, retrying from timing information...\n");
716 memcpy(vui, &backup_vui,
sizeof(backup_vui));
717 memcpy(gb, &backup,
sizeof(backup));
727 for (matrixId = 0; matrixId < 6; matrixId++) {
729 memset(sl->
sl[0][matrixId], 16, 16);
730 sl->
sl_dc[0][matrixId] = 16;
731 sl->
sl_dc[1][matrixId] = 16;
756 uint8_t scaling_list_pred_mode_flag;
757 uint8_t scaling_list_dc_coef[2][6];
758 int size_id, matrix_id,
pos;
761 for (size_id = 0; size_id < 4; size_id++)
762 for (matrix_id = 0; matrix_id < 6; matrix_id += ((size_id == 3) ? 3 : 1)) {
763 scaling_list_pred_mode_flag =
get_bits1(gb);
764 if (!scaling_list_pred_mode_flag) {
770 delta *= (size_id == 3) ? 3 : 1;
771 if (matrix_id <
delta) {
773 "Invalid delta in scaling list data: %d.\n",
delta);
777 memcpy(sl->
sl[size_id][matrix_id],
778 sl->
sl[size_id][matrix_id -
delta],
779 size_id > 0 ? 64 : 16);
781 sl->
sl_dc[size_id - 2][matrix_id] = sl->
sl_dc[size_id - 2][matrix_id -
delta];
784 int next_coef, coef_num;
785 int32_t scaling_list_delta_coef;
788 coef_num =
FFMIN(64, 1 << (4 + (size_id << 1)));
791 if (scaling_list_coeff_minus8 < -7 ||
792 scaling_list_coeff_minus8 > 247)
794 scaling_list_dc_coef[size_id - 2][matrix_id] = scaling_list_coeff_minus8 + 8;
795 next_coef = scaling_list_dc_coef[size_id - 2][matrix_id];
796 sl->
sl_dc[size_id - 2][matrix_id] = next_coef;
798 for (
i = 0;
i < coef_num;
i++) {
807 next_coef = (next_coef + 256
U + scaling_list_delta_coef) % 256;
808 sl->
sl[size_id][matrix_id][
pos] = next_coef;
813 if (
sps->chroma_format_idc == 3) {
814 for (
i = 0;
i < 64;
i++) {
815 sl->
sl[3][1][
i] = sl->
sl[2][1][
i];
816 sl->
sl[3][2][
i] = sl->
sl[2][2][
i];
817 sl->
sl[3][4][
i] = sl->
sl[2][4][
i];
818 sl->
sl[3][5][
i] = sl->
sl[2][5][
i];
833 switch (
sps->bit_depth) {
860 "The following bit-depths are currently specified: 8, 9, 10 and 12 bits, "
861 "chroma_format_idc is %d, depth is %d\n",
862 sps->chroma_format_idc,
sps->bit_depth);
870 sps->hshift[0] =
sps->vshift[0] = 0;
871 sps->hshift[2] =
sps->hshift[1] =
desc->log2_chroma_w;
872 sps->vshift[2] =
sps->vshift[1] =
desc->log2_chroma_h;
874 sps->pixel_shift =
sps->bit_depth > 8;
880 int apply_defdispwin,
const HEVCVPS *
const *vps_list,
885 int bit_depth_chroma, start, num_comps;
892 if (vps_list && !vps_list[
sps->vps_id]) {
901 sps->max_sub_layers);
917 if (
sps->chroma_format_idc > 3
U) {
922 if (
sps->chroma_format_idc == 3)
925 if (
sps->separate_colour_plane)
926 sps->chroma_format_idc = 0;
931 sps->height, 0, avctx)) < 0)
935 if (
sps->conformance_window) {
945 "discarding sps conformance window, "
946 "original values are l:%u r:%u t:%u b:%u\n",
947 sps->pic_conf_win.left_offset,
948 sps->pic_conf_win.right_offset,
949 sps->pic_conf_win.top_offset,
950 sps->pic_conf_win.bottom_offset);
952 sps->pic_conf_win.left_offset =
953 sps->pic_conf_win.right_offset =
954 sps->pic_conf_win.top_offset =
955 sps->pic_conf_win.bottom_offset = 0;
957 sps->output_window =
sps->pic_conf_win;
961 if (
sps->bit_depth > 16) {
967 if (bit_depth_chroma > 16) {
972 if (
sps->chroma_format_idc && bit_depth_chroma !=
sps->bit_depth) {
974 "Luma bit depth (%d) is different from chroma bit depth (%d), "
975 "this is unsupported.\n",
976 sps->bit_depth, bit_depth_chroma);
979 sps->bit_depth_chroma = bit_depth_chroma;
986 if (
sps->log2_max_poc_lsb > 16) {
988 sps->log2_max_poc_lsb - 4);
993 start =
sps->sublayer_ordering_info ? 0 :
sps->max_sub_layers - 1;
994 for (
i = start;
i <
sps->max_sub_layers;
i++) {
1000 sps->temporal_layer[
i].max_dec_pic_buffering - 1
U);
1003 if (
sps->temporal_layer[
i].num_reorder_pics >
sps->temporal_layer[
i].max_dec_pic_buffering - 1) {
1005 sps->temporal_layer[
i].num_reorder_pics);
1010 sps->temporal_layer[
i].max_dec_pic_buffering =
sps->temporal_layer[
i].num_reorder_pics + 1;
1014 if (!
sps->sublayer_ordering_info) {
1015 for (
i = 0;
i < start;
i++) {
1016 sps->temporal_layer[
i].max_dec_pic_buffering =
sps->temporal_layer[start].max_dec_pic_buffering;
1017 sps->temporal_layer[
i].num_reorder_pics =
sps->temporal_layer[start].num_reorder_pics;
1018 sps->temporal_layer[
i].max_latency_increase =
sps->temporal_layer[start].max_latency_increase;
1026 sps->log2_max_trafo_size =
sps->log2_diff_max_min_transform_block_size +
1027 sps->log2_min_tb_size;
1029 if (
sps->log2_min_cb_size < 3 ||
sps->log2_min_cb_size > 30) {
1034 if (
sps->log2_diff_max_min_coding_block_size > 30) {
1035 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);
1039 if (
sps->log2_min_tb_size >=
sps->log2_min_cb_size ||
sps->log2_min_tb_size < 2) {
1044 if (
sps->log2_diff_max_min_transform_block_size > 30) {
1045 av_log(avctx,
AV_LOG_ERROR,
"Invalid value %d for log2_diff_max_min_transform_block_size",
1046 sps->log2_diff_max_min_transform_block_size);
1054 if (
sps->scaling_list_enabled) {
1068 if (
sps->pcm_enabled) {
1072 sps->pcm.log2_max_pcm_cb_size =
sps->pcm.log2_min_pcm_cb_size +
1074 if (
FFMAX(
sps->pcm.bit_depth,
sps->pcm.bit_depth_chroma) >
sps->bit_depth) {
1076 "PCM bit depth (%d, %d) is greater than normal bit depth (%d)\n",
1077 sps->pcm.bit_depth,
sps->pcm.bit_depth_chroma,
sps->bit_depth);
1090 for (
i = 0;
i <
sps->nb_st_rps;
i++) {
1097 if (
sps->long_term_ref_pics_present) {
1101 sps->num_long_term_ref_pics_sps);
1105 sps->used_by_curr_pic_lt = 0;
1106 for (
i = 0;
i <
sps->num_long_term_ref_pics_sps;
i++) {
1116 if (
sps->vui_present)
1120 if (
sps->extension_present) {
1127 if (
sps->range_extension) {
1134 if (
sps->extended_precision_processing)
1136 "extended_precision_processing_flag not yet implemented\n");
1140 if (
sps->high_precision_offsets_enabled)
1142 "high_precision_offsets_enabled_flag not yet implemented\n");
1144 sps->persistent_rice_adaptation_enabled =
get_bits1(gb);
1147 if (
sps->cabac_bypass_alignment_enabled)
1149 "cabac_bypass_alignment_enabled_flag not yet implemented\n");
1152 if (
sps->multilayer_extension) {
1155 "sps_multilayer_extension_flag not yet implemented\n");
1158 if (
sps->sps_3d_extension) {
1159 for (
i = 0;
i <= 1;
i++) {
1179 "sps_3d_extension_flag not yet implemented\n");
1182 if (
sps->scc_extension) {
1185 if (
sps->palette_mode_enabled) {
1188 sps->palette_predictor_initializers_present =
get_bits1(gb);
1190 if (
sps->palette_predictor_initializers_present) {
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 =
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);
1314 unsigned int sps_id;
1337 "Parsed SPS: id %d; coded wxh: %dx%d; "
1338 "cropped wxh: %dx%d; pix_fmt: %s.\n",
1339 sps_id,
sps->width,
sps->height,
1340 sps->width - (
sps->output_window.left_offset +
sps->output_window.right_offset),
1341 sps->height - (
sps->output_window.top_offset +
sps->output_window.bottom_offset),
1380 int idx_y,
int idx_cb,
int idx_cr,
int inp_length)
1382 unsigned int split_octant_flag, part_num_y, coded_res_flag, res_coeff_q, res_coeff_r;
1385 part_num_y = 1 <<
pps->cm_y_part_num_log2;
1387 split_octant_flag = inp_depth <
pps->cm_octant_depth ?
get_bits1(gb) : 0;
1389 if (split_octant_flag)
1390 for (
int k = 0; k < 2; k++)
1391 for (
int m = 0; m < 2; m++)
1392 for (
int n = 0; n < 2; n++)
1394 idx_y + part_num_y * k * inp_length / 2,
1395 idx_cb + m * inp_length / 2,
1396 idx_cr + n * inp_length / 2,
1399 for (
int i = 0;
i < part_num_y;
i++) {
1400 for (
int j = 0; j < 4; j++) {
1403 for (
int c = 0;
c < 3;
c++) {
1405 cm_res_bits =
FFMAX(0, 10 +
pps->luma_bit_depth_cm_input -
1406 pps->luma_bit_depth_cm_output -
1407 pps->cm_res_quant_bits -
pps->cm_delta_flc_bits);
1408 res_coeff_r = cm_res_bits ?
get_bits(gb, cm_res_bits) : 0;
1409 if (res_coeff_q || res_coeff_r)
1419 if (
pps->num_cm_ref_layers > 62) {
1421 "num_cm_ref_layers_minus1 shall be in the range [0, 61].\n");
1424 for (
int i = 0;
i <
pps->num_cm_ref_layers;
i++)
1438 if (
pps->cm_octant_depth == 1) {
1453 if (
pps->pps_infer_scaling_list_flag)
1454 pps->pps_scaling_list_ref_layer_id =
get_bits(gb, 6);
1457 if (
pps->num_ref_loc_offsets >
vps->vps_max_layers - 1)
1460 for (
int i = 0;
i <
pps->num_ref_loc_offsets;
i++) {
1462 pps->scaled_ref_layer_offset_present_flag[
i] =
get_bits1(gb);
1463 if (
pps->scaled_ref_layer_offset_present_flag[
i]) {
1471 if (
pps->ref_region_offset_present_flag[
i]) {
1479 if (
pps->resample_phase_set_present_flag[
i]) {
1488 if (
pps->colour_mapping_enabled_flag) {
1499 unsigned int num_val_delta_dlt, max_diff = 0;
1500 int min_diff_minus1 = -1;
1503 num_val_delta_dlt =
get_bits(gb,
pps->pps_bit_depth_for_depth_layers_minus8 + 8);
1504 if (num_val_delta_dlt) {
1505 if (num_val_delta_dlt > 1)
1506 max_diff =
get_bits(gb,
pps->pps_bit_depth_for_depth_layers_minus8 + 8);
1507 if (num_val_delta_dlt > 2 && max_diff) {
1511 if (max_diff > (min_diff_minus1 + 1))
1512 for (
int k = 1; k < num_val_delta_dlt; k++) {
1513 len =
av_log2(max_diff - (min_diff_minus1 + 1)) + 1;
1522 unsigned int pps_depth_layers_minus1;
1525 pps_depth_layers_minus1 =
get_bits(gb, 6);
1526 pps->pps_bit_depth_for_depth_layers_minus8 =
get_bits(gb, 4);
1527 for (
int i = 0;
i <= pps_depth_layers_minus1;
i++) {
1531 for (
int j = 0; j <= ((1 << (
pps->pps_bit_depth_for_depth_layers_minus8 + 8)) - 1); j++)
1546 if (
pps->transform_skip_enabled_flag) {
1549 pps->cross_component_prediction_enabled_flag =
get_bits1(gb);
1550 pps->chroma_qp_offset_list_enabled_flag =
get_bits1(gb);
1551 if (
pps->chroma_qp_offset_list_enabled_flag) {
1554 if (
pps->chroma_qp_offset_list_len_minus1 > 5) {
1556 "chroma_qp_offset_list_len_minus1 shall be in the range [0, 5].\n");
1559 for (
int i = 0;
i <=
pps->chroma_qp_offset_list_len_minus1;
i++) {
1561 if (
pps->cb_qp_offset_list[
i]) {
1563 "cb_qp_offset_list not tested yet.\n");
1566 if (
pps->cr_qp_offset_list[
i]) {
1568 "cb_qp_offset_list not tested yet.\n");
1575 if (
pps->log2_sao_offset_scale_luma >
FFMAX(
sps->bit_depth - 10, 0)
1576 ||
pps->log2_sao_offset_scale_chroma >
FFMAX(
sps->bit_depth_chroma - 10, 0)
1589 if (
pps->residual_adaptive_colour_transform_enabled_flag =
get_bits1(gb)) {
1590 pps->pps_slice_act_qp_offsets_present_flag =
get_bits1(gb);
1595 #define CHECK_QP_OFFSET(name) (pps->pps_act_ ## name ## _qp_offset <= -12 || \
1596 pps->pps_act_ ## name ## _qp_offset >= 12)
1598 #undef CHECK_QP_OFFSET
1601 "PpsActQpOffsetY/Cb/Cr shall be in the range of [-12, 12].\n");
1606 if (
pps->pps_palette_predictor_initializers_present_flag =
get_bits1(gb)) {
1608 if (
pps->pps_num_palette_predictor_initializers > 0) {
1611 "pps_num_palette_predictor_initializers out of range: %u\n",
1612 pps->pps_num_palette_predictor_initializers);
1617 if (
pps->luma_bit_depth_entry !=
sps->bit_depth)
1619 if (!
pps->monochrome_palette_flag) {
1621 if (
pps->chroma_bit_depth_entry !=
sps->bit_depth_chroma)
1625 num_comps =
pps->monochrome_palette_flag ? 1 : 3;
1628 for (
int i = 0;
i <
pps->pps_num_palette_predictor_initializers;
i++)
1641 int pic_area_in_ctbs;
1642 int i, j, x, y, ctb_addr_rs, tile_id;
1648 if (!
pps->col_bd || !
pps->row_bd || !
pps->col_idxX)
1651 if (
pps->uniform_spacing_flag) {
1652 if (!
pps->column_width) {
1656 if (!
pps->column_width || !
pps->row_height)
1659 for (
i = 0;
i <
pps->num_tile_columns;
i++) {
1660 pps->column_width[
i] = ((
i + 1) *
sps->ctb_width) /
pps->num_tile_columns -
1661 (
i *
sps->ctb_width) /
pps->num_tile_columns;
1664 for (
i = 0;
i <
pps->num_tile_rows;
i++) {
1665 pps->row_height[
i] = ((
i + 1) *
sps->ctb_height) /
pps->num_tile_rows -
1666 (
i *
sps->ctb_height) /
pps->num_tile_rows;
1671 for (
i = 0;
i <
pps->num_tile_columns;
i++)
1672 pps->col_bd[
i + 1] =
pps->col_bd[
i] +
pps->column_width[
i];
1675 for (
i = 0;
i <
pps->num_tile_rows;
i++)
1676 pps->row_bd[
i + 1] =
pps->row_bd[
i] +
pps->row_height[
i];
1678 for (
i = 0, j = 0;
i <
sps->ctb_width;
i++) {
1679 if (
i >
pps->col_bd[j])
1681 pps->col_idxX[
i] = j;
1687 pic_area_in_ctbs =
sps->ctb_width *
sps->ctb_height;
1693 if (!
pps->ctb_addr_rs_to_ts || !
pps->ctb_addr_ts_to_rs ||
1694 !
pps->tile_id || !
pps->min_tb_addr_zs_tab) {
1698 for (ctb_addr_rs = 0; ctb_addr_rs < pic_area_in_ctbs; ctb_addr_rs++) {
1699 int tb_x = ctb_addr_rs %
sps->ctb_width;
1700 int tb_y = ctb_addr_rs /
sps->ctb_width;
1705 for (
i = 0;
i <
pps->num_tile_columns;
i++) {
1706 if (tb_x < pps->col_bd[
i + 1]) {
1712 for (
i = 0;
i <
pps->num_tile_rows;
i++) {
1713 if (tb_y < pps->row_bd[
i + 1]) {
1719 for (
i = 0;
i < tile_x;
i++)
1720 val +=
pps->row_height[tile_y] *
pps->column_width[
i];
1721 for (
i = 0;
i < tile_y;
i++)
1724 val += (tb_y -
pps->row_bd[tile_y]) *
pps->column_width[tile_x] +
1725 tb_x -
pps->col_bd[tile_x];
1727 pps->ctb_addr_rs_to_ts[ctb_addr_rs] =
val;
1728 pps->ctb_addr_ts_to_rs[
val] = ctb_addr_rs;
1731 for (j = 0, tile_id = 0; j <
pps->num_tile_rows; j++)
1732 for (
i = 0;
i <
pps->num_tile_columns;
i++, tile_id++)
1733 for (y =
pps->row_bd[j]; y < pps->row_bd[j + 1]; y++)
1734 for (x =
pps->col_bd[
i]; x < pps->col_bd[
i + 1]; x++)
1735 pps->tile_id[
pps->ctb_addr_rs_to_ts[y *
sps->ctb_width + x]] = tile_id;
1738 if (!
pps->tile_pos_rs)
1741 for (j = 0; j <
pps->num_tile_rows; j++)
1742 for (
i = 0;
i <
pps->num_tile_columns;
i++)
1743 pps->tile_pos_rs[j *
pps->num_tile_columns +
i] =
1744 pps->row_bd[j] *
sps->ctb_width +
pps->col_bd[
i];
1746 log2_diff =
sps->log2_ctb_size -
sps->log2_min_tb_size;
1747 pps->min_tb_addr_zs = &
pps->min_tb_addr_zs_tab[1*(
sps->tb_mask+2)+1];
1748 for (y = 0; y <
sps->tb_mask+2; y++) {
1749 pps->min_tb_addr_zs_tab[y*(
sps->tb_mask+2)] = -1;
1750 pps->min_tb_addr_zs_tab[y] = -1;
1752 for (y = 0; y <
sps->tb_mask+1; y++) {
1753 for (x = 0; x <
sps->tb_mask+1; x++) {
1754 int tb_x = x >> log2_diff;
1755 int tb_y = y >> log2_diff;
1756 int rs =
sps->ctb_width * tb_y + tb_x;
1757 int val =
pps->ctb_addr_rs_to_ts[rs] << (log2_diff * 2);
1758 for (
i = 0;
i < log2_diff;
i++) {
1760 val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0);
1762 pps->min_tb_addr_zs[y * (
sps->tb_mask+2) + x] =
val;
1777 unsigned log2_parallel_merge_level_minus2;
1798 pps->data_size = nal_size;
1806 pps->loop_filter_across_tiles_enabled_flag = 1;
1807 pps->num_tile_columns = 1;
1808 pps->num_tile_rows = 1;
1809 pps->uniform_spacing_flag = 1;
1810 pps->disable_dbf = 0;
1811 pps->beta_offset = 0;
1813 pps->log2_max_transform_skip_block_size = 2;
1816 pps->pps_id = pps_id;
1831 pps->dependent_slice_segments_enabled_flag =
get_bits1(gb);
1833 pps->num_extra_slice_header_bits =
get_bits(gb, 3);
1844 pps->num_ref_idx_l0_default_active,
pps->num_ref_idx_l1_default_active);
1854 pps->diff_cu_qp_delta_depth = 0;
1855 if (
pps->cu_qp_delta_enabled_flag)
1858 if (
pps->diff_cu_qp_delta_depth < 0 ||
1859 pps->diff_cu_qp_delta_depth >
sps->log2_diff_max_min_coding_block_size) {
1861 pps->diff_cu_qp_delta_depth);
1867 if (
pps->cb_qp_offset < -12 ||
pps->cb_qp_offset > 12) {
1874 if (
pps->cr_qp_offset < -12 ||
pps->cr_qp_offset > 12) {
1880 pps->pic_slice_level_chroma_qp_offsets_present_flag =
get_bits1(gb);
1889 if (
pps->tiles_enabled_flag) {
1893 if (num_tile_columns_minus1 < 0 ||
1894 num_tile_columns_minus1 >=
sps->ctb_width) {
1896 num_tile_columns_minus1);
1900 if (num_tile_rows_minus1 < 0 ||
1901 num_tile_rows_minus1 >=
sps->ctb_height) {
1903 num_tile_rows_minus1);
1907 pps->num_tile_columns = num_tile_columns_minus1 + 1;
1908 pps->num_tile_rows = num_tile_rows_minus1 + 1;
1912 if (!
pps->column_width || !
pps->row_height) {
1918 if (!
pps->uniform_spacing_flag) {
1920 for (
i = 0;
i <
pps->num_tile_columns - 1;
i++) {
1922 sum +=
pps->column_width[
i];
1924 if (sum >=
sps->ctb_width) {
1929 pps->column_width[
pps->num_tile_columns - 1] =
sps->ctb_width - sum;
1932 for (
i = 0;
i <
pps->num_tile_rows - 1;
i++) {
1934 sum +=
pps->row_height[
i];
1936 if (sum >=
sps->ctb_height) {
1941 pps->row_height[
pps->num_tile_rows - 1] =
sps->ctb_height - sum;
1943 pps->loop_filter_across_tiles_enabled_flag =
get_bits1(gb);
1946 pps->seq_loop_filter_across_slices_enabled_flag =
get_bits1(gb);
1948 pps->deblocking_filter_control_present_flag =
get_bits1(gb);
1949 if (
pps->deblocking_filter_control_present_flag) {
1950 pps->deblocking_filter_override_enabled_flag =
get_bits1(gb);
1952 if (!
pps->disable_dbf) {
1955 if (beta_offset_div2 < -6 || beta_offset_div2 > 6) {
1961 if (tc_offset_div2 < -6 || tc_offset_div2 > 6) {
1967 pps->beta_offset = 2 * beta_offset_div2;
1968 pps->tc_offset = 2 * tc_offset_div2;
1973 if (
pps->scaling_list_data_present_flag) {
1981 if (log2_parallel_merge_level_minus2 >
sps->log2_ctb_size) {
1983 log2_parallel_merge_level_minus2);
1987 pps->log2_parallel_merge_level = log2_parallel_merge_level_minus2 + 2;
1989 pps->slice_header_extension_present_flag =
get_bits1(gb);
1992 if (
pps->pps_extension_present_flag) {
2004 if (
pps->pps_multilayer_extension_flag) {
2009 if (
pps->pps_3d_extension_flag) {
2014 if (
pps->pps_scc_extension_flag) {
2057 int max_poc_lsb = 1 <<
sps->log2_max_poc_lsb;
2058 int prev_poc_lsb = pocTid0 % max_poc_lsb;
2059 int prev_poc_msb = pocTid0 - prev_poc_lsb;
2062 if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2)
2063 poc_msb = prev_poc_msb + max_poc_lsb;
2064 else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2)
2065 poc_msb = prev_poc_msb - max_poc_lsb;
2067 poc_msb = prev_poc_msb;
2075 return poc_msb + poc_lsb;