36 16, 16, 16, 16, 17, 18, 21, 24,
37 16, 16, 16, 16, 17, 19, 22, 25,
38 16, 16, 17, 18, 20, 22, 25, 29,
39 16, 16, 18, 21, 24, 27, 31, 36,
40 17, 17, 20, 24, 30, 35, 41, 47,
41 18, 19, 22, 27, 35, 44, 54, 65,
42 21, 22, 25, 31, 41, 54, 70, 88,
43 24, 25, 29, 36, 47, 65, 88, 115
47 16, 16, 16, 16, 17, 18, 20, 24,
48 16, 16, 16, 17, 18, 20, 24, 25,
49 16, 16, 17, 18, 20, 24, 25, 28,
50 16, 17, 18, 20, 24, 25, 28, 33,
51 17, 18, 20, 24, 25, 28, 33, 41,
52 18, 20, 24, 25, 28, 33, 41, 54,
53 20, 24, 25, 28, 33, 41, 54, 71,
54 24, 25, 28, 33, 41, 54, 71, 91
68 if (
s->sps_list[
id]) {
71 if (
s->pps_list[
i] &&
s->pps_list[
i]->sps_id ==
id)
81 if (
s->vps_list[
id]) {
83 if (
s->sps_list[
i] &&
s->sps_list[
i]->vps_id ==
id)
100 if (rps !=
sps->st_rps &&
sps->nb_st_rps)
105 uint8_t used[32] = { 0 };
108 if (is_slice_header) {
112 "Invalid value of delta_idx in slice header RPS: %d > %d.\n",
119 rps_ridx = &
sps->st_rps[rps -
sps->st_rps - 1];
125 "Invalid value of abs_delta_rps: %d\n",
138 if (i < rps_ridx->num_delta_pocs)
139 delta_poc = delta_rps + rps_ridx->
delta_poc[
i];
141 delta_poc = delta_rps;
151 "Invalid num_delta_pocs: %d\n", k);
163 for (k =
i - 1; k >= 0; k--) {
165 if (delta_poc <
tmp) {
167 used[k + 1] = used[k];
190 rps->
used |= (uint32_t)used[
i] <<
i;
192 unsigned int nb_positive_pics;
209 if (delta_poc < 1 || delta_poc > 32768) {
211 "Invalid value of delta_poc: %d\n",
220 for (
i = 0;
i < nb_positive_pics;
i++) {
222 if (delta_poc < 1 || delta_poc > 32768) {
224 "Invalid value of delta_poc: %d\n",
241 const char *profile_name =
NULL;
259 "%s profile bitstream\n", profile_name ? profile_name :
"Unknown");
261 for (
i = 0;
i < 32;
i++) {
264 if (
ptl->profile_idc == 0 &&
i > 0 &&
ptl->profile_compatibility_flag[
i])
265 ptl->profile_idc =
i;
272 #define check_profile_idc(idc) \
273 ptl->profile_idc == idc || ptl->profile_compatibility_flag[idc]
308 #undef check_profile_idc
314 int profile_present,
PTL *
ptl,
int max_num_sub_layers)
318 if (profile_present) {
321 memset(&
ptl->general_ptl, 0,
sizeof(
ptl->general_ptl));
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) {
468 uint64_t layer1_id_included)
473 int splitting_flag, dimension_id_len, view_id_len, num_add_olss, num_scalability_types,
474 default_output_layer_idc, direct_dep_type_len, direct_dep_type,
475 sub_layers_max_present, sub_layer_flag_info_present_flag, nb_ptl;
476 unsigned non_vui_extension_length;
478 if (
vps->vps_max_layers == 1 ||
vps->vps_num_layer_sets == 1) {
483 if (
vps->vps_max_layers > 2) {
485 "VPS has %d layers, only 2 layers are supported\n",
486 vps->vps_max_layers);
489 if (
vps->vps_num_layer_sets > 2) {
491 "VPS has %d layer sets, only 2 layer sets are supported\n",
492 vps->vps_num_layer_sets);
531 if (
parse_ptl(gb, avctx, 0, &ptl_dummy,
vps->vps_max_sub_layers) < 0)
535 num_scalability_types = 0;
537 int scalability_mask_flag =
get_bits1(gb);
542 num_scalability_types += scalability_mask_flag;
544 if (num_scalability_types != 1)
548 dimension_id_len =
get_bits(gb, 3) + 1;
551 int layer_id_in_nuh =
get_bits(gb, 6);
557 vps->layer_idx[layer_id_in_nuh] = 1;
558 vps->layer_id_in_nuh[1] = layer_id_in_nuh;
560 vps->layer_idx[1] = 1;
561 vps->layer_id_in_nuh[1] = 1;
564 if (!splitting_flag) {
565 int view_idx =
get_bits(gb, dimension_id_len);
574 for (
int i = 0;
i < 2 ;
i++)
581 vps->num_direct_ref_layers[1] = 1;
584 for (
int i = 0;
i <
vps->vps_max_layers;
i++)
585 max_sub_layers[
i] = sub_layers_max_present ?
get_bits(gb, 3) + 1 :
586 vps->vps_max_sub_layers;
597 for (
int i = 2;
i < nb_ptl;
i++) {
599 if (
parse_ptl(gb, avctx, profile_present, &ptl_dummy,
vps->vps_max_sub_layers) < 0)
604 if (num_add_olss != 0) {
611 default_output_layer_idc =
get_bits(gb, 2);
612 if (default_output_layer_idc != 0) {
614 default_output_layer_idc);
619 if (layer1_id_included != ((1 <<
vps->layer_id_in_nuh[0]) |
620 (1 <<
vps->layer_id_in_nuh[1]))) {
625 vps->num_output_layer_sets = 2;
630 if (ptl_idx < 1 || ptl_idx >= nb_ptl) {
641 vps->rep_format.pic_width_in_luma_samples =
get_bits(gb, 16);
642 vps->rep_format.pic_height_in_luma_samples =
get_bits(gb, 16);
646 "chroma_and_bit_depth_vps_present_flag=0 in first rep_format\n");
649 vps->rep_format.chroma_format_idc =
get_bits(gb, 2);
650 if (
vps->rep_format.chroma_format_idc == 3)
651 vps->rep_format.separate_colour_plane_flag =
get_bits1(gb);
652 vps->rep_format.bit_depth_luma =
get_bits(gb, 4) + 8;
653 vps->rep_format.bit_depth_chroma =
get_bits(gb, 4) + 8;
654 if (
vps->rep_format.bit_depth_luma > 16 ||
655 vps->rep_format.bit_depth_chroma > 16 ||
656 vps->rep_format.bit_depth_luma !=
vps->rep_format.bit_depth_chroma) {
658 vps->rep_format.bit_depth_luma,
vps->rep_format.bit_depth_chroma);
674 sub_layer_flag_info_present_flag =
get_bits1(gb);
675 for (
int j = 0; j <
FFMAX(max_sub_layers[0], max_sub_layers[1]); j++) {
676 int sub_layer_dpb_info_present_flag = 1;
677 if (j > 0 && sub_layer_flag_info_present_flag)
678 sub_layer_dpb_info_present_flag =
get_bits1(gb);
679 if (sub_layer_dpb_info_present_flag) {
688 if (direct_dep_type_len > 32) {
690 direct_dep_type_len);
703 if (non_vui_extension_length > 4096) {
705 non_vui_extension_length);
723 uint64_t layer1_id_included = 0;
739 vps->data_size = nal_size;
745 vps->vps_id = vps_id;
763 vps->vps_max_sub_layers);
770 vps->vps_sub_layer_ordering_info_present_flag =
get_bits1(gb);
772 i =
vps->vps_sub_layer_ordering_info_present_flag ? 0 :
vps->vps_max_sub_layers - 1;
773 for (;
i <
vps->vps_max_sub_layers;
i++) {
780 vps->vps_max_dec_pic_buffering[
i] - 1);
783 if (
vps->vps_num_reorder_pics[
i] >
vps->vps_max_dec_pic_buffering[
i] - 1) {
785 vps->vps_num_reorder_pics[
i]);
793 if (
vps->vps_num_layer_sets < 1 ||
vps->vps_num_layer_sets > 1024 ||
799 vps->num_output_layer_sets = 1;
803 if (
vps->vps_num_layer_sets > 1)
804 layer1_id_included =
get_bits64(gb,
vps->vps_max_layer_id + 1);
805 if (
vps->vps_num_layer_sets > 2)
809 if (
vps->vps_timing_info_present_flag) {
812 vps->vps_poc_proportional_to_timing_flag =
get_bits1(gb);
813 if (
vps->vps_poc_proportional_to_timing_flag)
816 if (
vps->vps_num_hrd_parameters > (
unsigned)
vps->vps_num_layer_sets) {
818 "vps_num_hrd_parameters %d is invalid\n",
vps->vps_num_hrd_parameters);
822 if (
vps->vps_num_hrd_parameters) {
828 for (
i = 0;
i <
vps->vps_num_hrd_parameters;
i++) {
829 int common_inf_present = 1;
835 vps->vps_max_sub_layers);
840 vps->layer_idx[0] = 0;
842 vps->layer_idx[
i] = -1;
874 VUI backup_vui, *vui = &
sps->vui;
885 switch (
sps->pix_fmt) {
905 memcpy(&backup, gb,
sizeof(backup));
906 memcpy(&backup_vui, vui,
sizeof(backup_vui));
921 if (apply_defdispwin &&
924 "discarding vui default display window, "
925 "original values are l:%u r:%u t:%u b:%u\n",
946 "Strange VUI timing information, retrying...\n");
947 memcpy(vui, &backup_vui,
sizeof(backup_vui));
948 memcpy(gb, &backup,
sizeof(backup));
970 "Strange VUI bitstream restriction information, retrying"
971 " from timing information...\n");
972 memcpy(vui, &backup_vui,
sizeof(backup_vui));
973 memcpy(gb, &backup,
sizeof(backup));
990 "Overread in VUI, retrying from timing information...\n");
991 memcpy(vui, &backup_vui,
sizeof(backup_vui));
992 memcpy(gb, &backup,
sizeof(backup));
1002 for (matrixId = 0; matrixId < 6; matrixId++) {
1004 memset(sl->
sl[0][matrixId], 16, 16);
1005 sl->
sl_dc[0][matrixId] = 16;
1006 sl->
sl_dc[1][matrixId] = 16;
1031 uint8_t scaling_list_pred_mode_flag;
1032 uint8_t scaling_list_dc_coef[2][6];
1033 int size_id, matrix_id,
pos;
1036 for (size_id = 0; size_id < 4; size_id++)
1037 for (matrix_id = 0; matrix_id < 6; matrix_id += ((size_id == 3) ? 3 : 1)) {
1038 scaling_list_pred_mode_flag =
get_bits1(gb);
1039 if (!scaling_list_pred_mode_flag) {
1045 delta *= (size_id == 3) ? 3 : 1;
1046 if (matrix_id <
delta) {
1048 "Invalid delta in scaling list data: %d.\n",
delta);
1052 memcpy(sl->
sl[size_id][matrix_id],
1053 sl->
sl[size_id][matrix_id -
delta],
1054 size_id > 0 ? 64 : 16);
1056 sl->
sl_dc[size_id - 2][matrix_id] = sl->
sl_dc[size_id - 2][matrix_id -
delta];
1059 int next_coef, coef_num;
1060 int32_t scaling_list_delta_coef;
1063 coef_num =
FFMIN(64, 1 << (4 + (size_id << 1)));
1066 if (scaling_list_coeff_minus8 < -7 ||
1067 scaling_list_coeff_minus8 > 247)
1069 scaling_list_dc_coef[size_id - 2][matrix_id] = scaling_list_coeff_minus8 + 8;
1070 next_coef = scaling_list_dc_coef[size_id - 2][matrix_id];
1071 sl->
sl_dc[size_id - 2][matrix_id] = next_coef;
1073 for (
i = 0;
i < coef_num;
i++) {
1082 next_coef = (next_coef + 256
U + scaling_list_delta_coef) % 256;
1083 sl->
sl[size_id][matrix_id][
pos] = next_coef;
1088 if (
sps->chroma_format_idc == 3) {
1089 for (
i = 0;
i < 64;
i++) {
1090 sl->
sl[3][1][
i] = sl->
sl[2][1][
i];
1091 sl->
sl[3][2][
i] = sl->
sl[2][2][
i];
1092 sl->
sl[3][4][
i] = sl->
sl[2][4][
i];
1093 sl->
sl[3][5][
i] = sl->
sl[2][5][
i];
1108 switch (
sps->bit_depth) {
1135 "The following bit-depths are currently specified: 8, 9, 10 and 12 bits, "
1136 "chroma_format_idc is %d, depth is %d\n",
1137 sps->chroma_format_idc,
sps->bit_depth);
1145 sps->hshift[0] =
sps->vshift[0] = 0;
1146 sps->hshift[2] =
sps->hshift[1] =
desc->log2_chroma_w;
1147 sps->vshift[2] =
sps->vshift[1] =
desc->log2_chroma_h;
1149 sps->pixel_shift =
sps->bit_depth > 8;
1155 unsigned nuh_layer_id,
int apply_defdispwin,
1160 int bit_depth_chroma, num_comps, multi_layer_ext;
1161 int vps_max_sub_layers;
1169 if (!vps_list[
sps->vps_id]) {
1178 multi_layer_ext = nuh_layer_id > 0 &&
1180 if (multi_layer_ext) {
1184 sps->max_sub_layers =
sps->vps->vps_max_sub_layers;
1186 vps_max_sub_layers =
sps->vps ?
sps->vps->vps_max_sub_layers
1189 if (
sps->max_sub_layers > vps_max_sub_layers) {
1191 sps->max_sub_layers);
1195 if (!multi_layer_ext) {
1201 sps->temporal_id_nesting =
sps->max_sub_layers > 1 ?
1202 sps->vps->vps_max_sub_layers : 1;
1211 if (multi_layer_ext) {
1214 if (
sps->vps->nb_layers == 1) {
1227 sps->chroma_format_idc =
sps->separate_colour_plane ? 0 :
1240 if (
sps->chroma_format_idc > 3
U) {
1245 if (
sps->chroma_format_idc == 3)
1248 if (
sps->separate_colour_plane)
1249 sps->chroma_format_idc = 0;
1254 sps->height, 0, avctx)) < 0)
1258 if (
sps->conformance_window) {
1268 "discarding sps conformance window, "
1269 "original values are l:%u r:%u t:%u b:%u\n",
1270 sps->pic_conf_win.left_offset,
1271 sps->pic_conf_win.right_offset,
1272 sps->pic_conf_win.top_offset,
1273 sps->pic_conf_win.bottom_offset);
1275 sps->pic_conf_win.left_offset =
1276 sps->pic_conf_win.right_offset =
1277 sps->pic_conf_win.top_offset =
1278 sps->pic_conf_win.bottom_offset = 0;
1283 if (
sps->bit_depth > 16) {
1289 if (bit_depth_chroma > 16) {
1294 if (
sps->chroma_format_idc && bit_depth_chroma !=
sps->bit_depth) {
1296 "Luma bit depth (%d) is different from chroma bit depth (%d), "
1297 "this is unsupported.\n",
1298 sps->bit_depth, bit_depth_chroma);
1301 sps->bit_depth_chroma = bit_depth_chroma;
1304 sps->output_window =
sps->pic_conf_win;
1311 if (
sps->log2_max_poc_lsb > 16) {
1313 sps->log2_max_poc_lsb - 4);
1317 if (!multi_layer_ext) {
1321 start =
sps->sublayer_ordering_info ? 0 :
sps->max_sub_layers - 1;
1322 for (
i = start;
i <
sps->max_sub_layers;
i++) {
1328 sps->temporal_layer[
i].max_dec_pic_buffering - 1
U);
1331 if (
sps->temporal_layer[
i].num_reorder_pics >
sps->temporal_layer[
i].max_dec_pic_buffering - 1) {
1333 sps->temporal_layer[
i].num_reorder_pics);
1338 sps->temporal_layer[
i].max_dec_pic_buffering =
sps->temporal_layer[
i].num_reorder_pics + 1;
1342 if (!
sps->sublayer_ordering_info) {
1343 for (
i = 0;
i < start;
i++) {
1344 sps->temporal_layer[
i].max_dec_pic_buffering =
sps->temporal_layer[start].max_dec_pic_buffering;
1345 sps->temporal_layer[
i].num_reorder_pics =
sps->temporal_layer[start].num_reorder_pics;
1346 sps->temporal_layer[
i].max_latency_increase =
sps->temporal_layer[start].max_latency_increase;
1350 for (
int i = 0;
i <
sps->max_sub_layers;
i++) {
1351 sps->temporal_layer[
i].max_dec_pic_buffering =
sps->vps->dpb_size.max_dec_pic_buffering;
1352 sps->temporal_layer[
i].num_reorder_pics =
sps->vps->dpb_size.max_num_reorder_pics;
1353 sps->temporal_layer[
i].max_latency_increase =
sps->vps->dpb_size.max_latency_increase;
1361 sps->log2_max_trafo_size =
sps->log2_diff_max_min_transform_block_size +
1362 sps->log2_min_tb_size;
1364 if (
sps->log2_min_cb_size < 3 ||
sps->log2_min_cb_size > 30) {
1369 if (
sps->log2_diff_max_min_coding_block_size > 30) {
1370 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);
1374 if (
sps->log2_min_tb_size >=
sps->log2_min_cb_size ||
sps->log2_min_tb_size < 2) {
1379 if (
sps->log2_diff_max_min_transform_block_size > 30) {
1380 av_log(avctx,
AV_LOG_ERROR,
"Invalid value %d for log2_diff_max_min_transform_block_size",
1381 sps->log2_diff_max_min_transform_block_size);
1389 if (
sps->scaling_list_enabled) {
1408 if (
sps->pcm_enabled) {
1412 sps->pcm.log2_max_pcm_cb_size =
sps->pcm.log2_min_pcm_cb_size +
1414 if (
FFMAX(
sps->pcm.bit_depth,
sps->pcm.bit_depth_chroma) >
sps->bit_depth) {
1416 "PCM bit depth (%d, %d) is greater than normal bit depth (%d)\n",
1417 sps->pcm.bit_depth,
sps->pcm.bit_depth_chroma,
sps->bit_depth);
1430 for (
i = 0;
i <
sps->nb_st_rps;
i++) {
1437 if (
sps->long_term_ref_pics_present) {
1441 sps->num_long_term_ref_pics_sps);
1445 sps->used_by_curr_pic_lt = 0;
1446 for (
i = 0;
i <
sps->num_long_term_ref_pics_sps;
i++) {
1456 if (
sps->vui_present)
1460 if (
sps->extension_present) {
1467 if (
sps->range_extension) {
1474 if (
sps->extended_precision_processing)
1476 "extended_precision_processing_flag not yet implemented\n");
1480 if (
sps->high_precision_offsets_enabled)
1482 "high_precision_offsets_enabled_flag not yet implemented\n");
1484 sps->persistent_rice_adaptation_enabled =
get_bits1(gb);
1487 if (
sps->cabac_bypass_alignment_enabled)
1489 "cabac_bypass_alignment_enabled_flag not yet implemented\n");
1492 if (
sps->multilayer_extension) {
1496 if (
sps->sps_3d_extension) {
1497 for (
i = 0;
i <= 1;
i++) {
1517 "sps_3d_extension_flag not yet implemented\n");
1520 if (
sps->scc_extension) {
1523 if (
sps->palette_mode_enabled) {
1526 sps->palette_predictor_initializers_present =
get_bits1(gb);
1528 if (
sps->palette_predictor_initializers_present) {
1532 "sps_num_palette_predictor_initializers out of range: %u\n",
1533 sps->sps_num_palette_predictor_initializers);
1536 num_comps = !
sps->chroma_format_idc ? 1 : 3;
1539 for (
i = 0;
i <
sps->sps_num_palette_predictor_initializers;
i++)
1544 sps->motion_vector_resolution_control_idc =
get_bits(gb, 2);
1545 sps->intra_boundary_filtering_disabled =
get_bits1(gb);
1548 if (apply_defdispwin) {
1549 sps->output_window.left_offset +=
sps->vui.def_disp_win.left_offset;
1550 sps->output_window.right_offset +=
sps->vui.def_disp_win.right_offset;
1551 sps->output_window.top_offset +=
sps->vui.def_disp_win.top_offset;
1552 sps->output_window.bottom_offset +=
sps->vui.def_disp_win.bottom_offset;
1555 ow = &
sps->output_window;
1566 "Displaying the whole video surface.\n");
1567 memset(ow, 0,
sizeof(*ow));
1568 memset(&
sps->pic_conf_win, 0,
sizeof(
sps->pic_conf_win));
1572 sps->log2_ctb_size =
sps->log2_min_cb_size +
1573 sps->log2_diff_max_min_coding_block_size;
1574 sps->log2_min_pu_size =
sps->log2_min_cb_size - 1;
1580 if (
sps->log2_ctb_size < 4) {
1583 "log2_ctb_size %d differs from the bounds of any known profile\n",
1584 sps->log2_ctb_size);
1589 sps->ctb_width = (
sps->width + (1 <<
sps->log2_ctb_size) - 1) >>
sps->log2_ctb_size;
1590 sps->ctb_height = (
sps->height + (1 <<
sps->log2_ctb_size) - 1) >>
sps->log2_ctb_size;
1591 sps->ctb_size =
sps->ctb_width *
sps->ctb_height;
1593 sps->min_cb_width =
sps->width >>
sps->log2_min_cb_size;
1594 sps->min_cb_height =
sps->height >>
sps->log2_min_cb_size;
1595 sps->min_tb_width =
sps->width >>
sps->log2_min_tb_size;
1596 sps->min_tb_height =
sps->height >>
sps->log2_min_tb_size;
1597 sps->min_pu_width =
sps->width >>
sps->log2_min_pu_size;
1598 sps->min_pu_height =
sps->height >>
sps->log2_min_pu_size;
1599 sps->tb_mask = (1 << (
sps->log2_ctb_size -
sps->log2_min_tb_size)) - 1;
1601 sps->qp_bd_offset = 6 * (
sps->bit_depth - 8);
1609 if (
sps->max_transform_hierarchy_depth_inter >
sps->log2_ctb_size -
sps->log2_min_tb_size) {
1610 av_log(avctx,
AV_LOG_ERROR,
"max_transform_hierarchy_depth_inter out of range: %d\n",
1611 sps->max_transform_hierarchy_depth_inter);
1614 if (
sps->max_transform_hierarchy_depth_intra >
sps->log2_ctb_size -
sps->log2_min_tb_size) {
1615 av_log(avctx,
AV_LOG_ERROR,
"max_transform_hierarchy_depth_intra out of range: %d\n",
1616 sps->max_transform_hierarchy_depth_intra);
1619 if (
sps->log2_max_trafo_size >
FFMIN(
sps->log2_ctb_size, 5)) {
1621 "max transform block size out of range: %d\n",
1622 sps->log2_max_trafo_size);
1652 int apply_defdispwin)
1671 nuh_layer_id, apply_defdispwin,
1678 "Parsed SPS: id %d; coded wxh: %dx%d; "
1679 "cropped wxh: %dx%d; pix_fmt: %s.\n",
1681 sps->width - (
sps->output_window.left_offset +
sps->output_window.right_offset),
1682 sps->height - (
sps->output_window.top_offset +
sps->output_window.bottom_offset),
1723 int idx_y,
int idx_cb,
int idx_cr,
int inp_length)
1725 unsigned int split_octant_flag, part_num_y, coded_res_flag, res_coeff_q, res_coeff_r;
1728 part_num_y = 1 <<
pps->cm_y_part_num_log2;
1730 split_octant_flag = inp_depth <
pps->cm_octant_depth ?
get_bits1(gb) : 0;
1732 if (split_octant_flag)
1733 for (
int k = 0; k < 2; k++)
1734 for (
int m = 0; m < 2; m++)
1735 for (
int n = 0; n < 2; n++)
1737 idx_y + part_num_y * k * inp_length / 2,
1738 idx_cb + m * inp_length / 2,
1739 idx_cr + n * inp_length / 2,
1742 for (
int i = 0;
i < part_num_y;
i++) {
1743 for (
int j = 0; j < 4; j++) {
1746 for (
int c = 0;
c < 3;
c++) {
1748 cm_res_bits =
FFMAX(0, 10 +
pps->luma_bit_depth_cm_input -
1749 pps->luma_bit_depth_cm_output -
1750 pps->cm_res_quant_bits -
pps->cm_delta_flc_bits);
1751 res_coeff_r = cm_res_bits ?
get_bits(gb, cm_res_bits) : 0;
1752 if (res_coeff_q || res_coeff_r)
1762 if (
pps->num_cm_ref_layers > 62) {
1764 "num_cm_ref_layers_minus1 shall be in the range [0, 61].\n");
1767 for (
int i = 0;
i <
pps->num_cm_ref_layers;
i++)
1781 if (
pps->cm_octant_depth == 1) {
1796 if (
pps->pps_infer_scaling_list_flag)
1797 pps->pps_scaling_list_ref_layer_id =
get_bits(gb, 6);
1800 if (
pps->num_ref_loc_offsets >
vps->vps_max_layers - 1)
1803 for (
int i = 0;
i <
pps->num_ref_loc_offsets;
i++) {
1805 pps->scaled_ref_layer_offset_present_flag[
i] =
get_bits1(gb);
1806 if (
pps->scaled_ref_layer_offset_present_flag[
i]) {
1814 if (
pps->ref_region_offset_present_flag[
i]) {
1822 if (
pps->resample_phase_set_present_flag[
i]) {
1831 if (
pps->colour_mapping_enabled_flag) {
1842 unsigned int num_val_delta_dlt, max_diff = 0;
1843 int min_diff_minus1 = -1;
1846 num_val_delta_dlt =
get_bits(gb,
pps->pps_bit_depth_for_depth_layers_minus8 + 8);
1847 if (num_val_delta_dlt) {
1848 if (num_val_delta_dlt > 1)
1849 max_diff =
get_bits(gb,
pps->pps_bit_depth_for_depth_layers_minus8 + 8);
1850 if (num_val_delta_dlt > 2 && max_diff) {
1854 if (max_diff > (min_diff_minus1 + 1))
1855 for (
int k = 1; k < num_val_delta_dlt; k++) {
1856 len =
av_log2(max_diff - (min_diff_minus1 + 1)) + 1;
1865 unsigned int pps_depth_layers_minus1;
1868 pps_depth_layers_minus1 =
get_bits(gb, 6);
1869 pps->pps_bit_depth_for_depth_layers_minus8 =
get_bits(gb, 4);
1870 for (
int i = 0;
i <= pps_depth_layers_minus1;
i++) {
1874 for (
int j = 0; j <= ((1 << (
pps->pps_bit_depth_for_depth_layers_minus8 + 8)) - 1); j++)
1889 if (
pps->transform_skip_enabled_flag) {
1892 pps->cross_component_prediction_enabled_flag =
get_bits1(gb);
1893 pps->chroma_qp_offset_list_enabled_flag =
get_bits1(gb);
1894 if (
pps->chroma_qp_offset_list_enabled_flag) {
1897 if (
pps->chroma_qp_offset_list_len_minus1 > 5) {
1899 "chroma_qp_offset_list_len_minus1 shall be in the range [0, 5].\n");
1902 for (
int i = 0;
i <=
pps->chroma_qp_offset_list_len_minus1;
i++) {
1904 if (
pps->cb_qp_offset_list[
i]) {
1906 "cb_qp_offset_list not tested yet.\n");
1909 if (
pps->cr_qp_offset_list[
i]) {
1911 "cb_qp_offset_list not tested yet.\n");
1918 if (
pps->log2_sao_offset_scale_luma >
FFMAX(
sps->bit_depth - 10, 0)
1919 ||
pps->log2_sao_offset_scale_chroma >
FFMAX(
sps->bit_depth_chroma - 10, 0)
1932 if (
pps->residual_adaptive_colour_transform_enabled_flag =
get_bits1(gb)) {
1933 pps->pps_slice_act_qp_offsets_present_flag =
get_bits1(gb);
1938 #define CHECK_QP_OFFSET(name) (pps->pps_act_ ## name ## _qp_offset <= -12 || \
1939 pps->pps_act_ ## name ## _qp_offset >= 12)
1941 #undef CHECK_QP_OFFSET
1944 "PpsActQpOffsetY/Cb/Cr shall be in the range of [-12, 12].\n");
1949 if (
pps->pps_palette_predictor_initializers_present_flag =
get_bits1(gb)) {
1951 if (
pps->pps_num_palette_predictor_initializers > 0) {
1954 "pps_num_palette_predictor_initializers out of range: %u\n",
1955 pps->pps_num_palette_predictor_initializers);
1960 if (
pps->luma_bit_depth_entry !=
sps->bit_depth)
1962 if (!
pps->monochrome_palette_flag) {
1964 if (
pps->chroma_bit_depth_entry !=
sps->bit_depth_chroma)
1968 num_comps =
pps->monochrome_palette_flag ? 1 : 3;
1971 for (
int i = 0;
i <
pps->pps_num_palette_predictor_initializers;
i++)
1984 int pic_area_in_ctbs;
1985 int i, j, x, y, ctb_addr_rs,
tile_id;
1991 if (!
pps->col_bd || !
pps->row_bd || !
pps->col_idxX)
1994 if (
pps->uniform_spacing_flag) {
1995 if (!
pps->column_width) {
1999 if (!
pps->column_width || !
pps->row_height)
2002 for (
i = 0;
i <
pps->num_tile_columns;
i++) {
2003 pps->column_width[
i] = ((
i + 1) *
sps->ctb_width) /
pps->num_tile_columns -
2004 (
i *
sps->ctb_width) /
pps->num_tile_columns;
2007 for (
i = 0;
i <
pps->num_tile_rows;
i++) {
2008 pps->row_height[
i] = ((
i + 1) *
sps->ctb_height) /
pps->num_tile_rows -
2009 (
i *
sps->ctb_height) /
pps->num_tile_rows;
2014 for (
i = 0;
i <
pps->num_tile_columns;
i++)
2015 pps->col_bd[
i + 1] =
pps->col_bd[
i] +
pps->column_width[
i];
2018 for (
i = 0;
i <
pps->num_tile_rows;
i++)
2019 pps->row_bd[
i + 1] =
pps->row_bd[
i] +
pps->row_height[
i];
2021 for (
i = 0, j = 0;
i <
sps->ctb_width;
i++) {
2022 if (
i >
pps->col_bd[j])
2024 pps->col_idxX[
i] = j;
2030 pic_area_in_ctbs =
sps->ctb_width *
sps->ctb_height;
2036 if (!
pps->ctb_addr_rs_to_ts || !
pps->ctb_addr_ts_to_rs ||
2037 !
pps->tile_id || !
pps->min_tb_addr_zs_tab) {
2041 for (ctb_addr_rs = 0; ctb_addr_rs < pic_area_in_ctbs; ctb_addr_rs++) {
2042 int tb_x = ctb_addr_rs %
sps->ctb_width;
2043 int tb_y = ctb_addr_rs /
sps->ctb_width;
2048 for (
i = 0;
i <
pps->num_tile_columns;
i++) {
2049 if (tb_x < pps->
col_bd[
i + 1]) {
2055 for (
i = 0;
i <
pps->num_tile_rows;
i++) {
2056 if (tb_y < pps->
row_bd[
i + 1]) {
2062 for (
i = 0;
i < tile_x;
i++)
2063 val +=
pps->row_height[tile_y] *
pps->column_width[
i];
2064 for (
i = 0;
i < tile_y;
i++)
2067 val += (tb_y -
pps->row_bd[tile_y]) *
pps->column_width[tile_x] +
2068 tb_x -
pps->col_bd[tile_x];
2070 pps->ctb_addr_rs_to_ts[ctb_addr_rs] =
val;
2071 pps->ctb_addr_ts_to_rs[
val] = ctb_addr_rs;
2074 for (j = 0,
tile_id = 0; j <
pps->num_tile_rows; j++)
2076 for (y =
pps->row_bd[j]; y < pps->
row_bd[j + 1]; y++)
2077 for (x =
pps->col_bd[
i]; x < pps->
col_bd[
i + 1]; x++)
2081 if (!
pps->tile_pos_rs)
2084 for (j = 0; j <
pps->num_tile_rows; j++)
2085 for (
i = 0;
i <
pps->num_tile_columns;
i++)
2086 pps->tile_pos_rs[j *
pps->num_tile_columns +
i] =
2087 pps->row_bd[j] *
sps->ctb_width +
pps->col_bd[
i];
2089 log2_diff =
sps->log2_ctb_size -
sps->log2_min_tb_size;
2090 pps->min_tb_addr_zs = &
pps->min_tb_addr_zs_tab[1*(
sps->tb_mask+2)+1];
2091 for (y = 0; y <
sps->tb_mask+2; y++) {
2092 pps->min_tb_addr_zs_tab[y*(
sps->tb_mask+2)] = -1;
2093 pps->min_tb_addr_zs_tab[y] = -1;
2095 for (y = 0; y <
sps->tb_mask+1; y++) {
2096 for (x = 0; x <
sps->tb_mask+1; x++) {
2097 int tb_x = x >> log2_diff;
2098 int tb_y = y >> log2_diff;
2099 int rs =
sps->ctb_width * tb_y + tb_x;
2100 int val =
pps->ctb_addr_rs_to_ts[rs] << (log2_diff * 2);
2101 for (
i = 0;
i < log2_diff;
i++) {
2103 val += (m & x ? m * m : 0) + (m & y ? 2 * m * m : 0);
2105 pps->min_tb_addr_zs[y * (
sps->tb_mask+2) + x] =
val;
2120 unsigned log2_parallel_merge_level_minus2;
2141 pps->data_size = nal_size;
2149 pps->loop_filter_across_tiles_enabled_flag = 1;
2150 pps->num_tile_columns = 1;
2151 pps->num_tile_rows = 1;
2152 pps->uniform_spacing_flag = 1;
2153 pps->disable_dbf = 0;
2154 pps->beta_offset = 0;
2156 pps->log2_max_transform_skip_block_size = 2;
2176 pps->dependent_slice_segments_enabled_flag =
get_bits1(gb);
2178 pps->num_extra_slice_header_bits =
get_bits(gb, 3);
2189 pps->num_ref_idx_l0_default_active,
pps->num_ref_idx_l1_default_active);
2199 pps->diff_cu_qp_delta_depth = 0;
2200 if (
pps->cu_qp_delta_enabled_flag)
2203 if (
pps->diff_cu_qp_delta_depth < 0 ||
2204 pps->diff_cu_qp_delta_depth >
sps->log2_diff_max_min_coding_block_size) {
2206 pps->diff_cu_qp_delta_depth);
2212 if (
pps->cb_qp_offset < -12 ||
pps->cb_qp_offset > 12) {
2219 if (
pps->cr_qp_offset < -12 ||
pps->cr_qp_offset > 12) {
2225 pps->pic_slice_level_chroma_qp_offsets_present_flag =
get_bits1(gb);
2234 if (
pps->tiles_enabled_flag) {
2238 if (num_tile_columns_minus1 < 0 ||
2239 num_tile_columns_minus1 >=
sps->ctb_width) {
2241 num_tile_columns_minus1);
2245 if (num_tile_rows_minus1 < 0 ||
2246 num_tile_rows_minus1 >=
sps->ctb_height) {
2248 num_tile_rows_minus1);
2252 pps->num_tile_columns = num_tile_columns_minus1 + 1;
2253 pps->num_tile_rows = num_tile_rows_minus1 + 1;
2257 if (!
pps->column_width || !
pps->row_height) {
2263 if (!
pps->uniform_spacing_flag) {
2265 for (
i = 0;
i <
pps->num_tile_columns - 1;
i++) {
2267 sum +=
pps->column_width[
i];
2269 if (sum >=
sps->ctb_width) {
2274 pps->column_width[
pps->num_tile_columns - 1] =
sps->ctb_width - sum;
2277 for (
i = 0;
i <
pps->num_tile_rows - 1;
i++) {
2279 sum +=
pps->row_height[
i];
2281 if (sum >=
sps->ctb_height) {
2286 pps->row_height[
pps->num_tile_rows - 1] =
sps->ctb_height - sum;
2288 pps->loop_filter_across_tiles_enabled_flag =
get_bits1(gb);
2291 pps->seq_loop_filter_across_slices_enabled_flag =
get_bits1(gb);
2293 pps->deblocking_filter_control_present_flag =
get_bits1(gb);
2294 if (
pps->deblocking_filter_control_present_flag) {
2295 pps->deblocking_filter_override_enabled_flag =
get_bits1(gb);
2297 if (!
pps->disable_dbf) {
2300 if (beta_offset_div2 < -6 || beta_offset_div2 > 6) {
2306 if (tc_offset_div2 < -6 || tc_offset_div2 > 6) {
2312 pps->beta_offset = 2 * beta_offset_div2;
2313 pps->tc_offset = 2 * tc_offset_div2;
2318 if (
pps->scaling_list_data_present_flag) {
2326 if (log2_parallel_merge_level_minus2 >
sps->log2_ctb_size) {
2328 log2_parallel_merge_level_minus2);
2332 pps->log2_parallel_merge_level = log2_parallel_merge_level_minus2 + 2;
2334 pps->slice_header_extension_present_flag =
get_bits1(gb);
2337 if (
pps->pps_extension_present_flag) {
2349 if (
pps->pps_multilayer_extension_flag) {
2354 if (
pps->pps_3d_extension_flag) {
2359 if (
pps->pps_scc_extension_flag) {
2398 int max_poc_lsb = 1 <<
sps->log2_max_poc_lsb;
2399 int prev_poc_lsb = pocTid0 % max_poc_lsb;
2400 int prev_poc_msb = pocTid0 - prev_poc_lsb;
2403 if (poc_lsb < prev_poc_lsb && prev_poc_lsb - poc_lsb >= max_poc_lsb / 2)
2404 poc_msb = prev_poc_msb + max_poc_lsb;
2405 else if (poc_lsb > prev_poc_lsb && poc_lsb - prev_poc_lsb > max_poc_lsb / 2)
2406 poc_msb = prev_poc_msb - max_poc_lsb;
2408 poc_msb = prev_poc_msb;
2416 return poc_msb + poc_lsb;