32 #define MAX_SPATIAL_SEGMENTATION 4096 // max. value of u(12) field
44 #define FLAG_ARRAY_COMPLETENESS (1 << 0)
45 #define FLAG_IS_NALFF (1 << 1)
46 #define FLAG_IS_LHVC (1 << 2)
154 int profile_present_flag,
155 unsigned int max_sub_layers_minus1)
162 if (profile_present_flag) {
173 for (
i = 0;
i < max_sub_layers_minus1;
i++) {
174 sub_layer_profile_present_flag[
i] =
get_bits1(gb);
175 sub_layer_level_present_flag[
i] =
get_bits1(gb);
178 if (max_sub_layers_minus1 > 0)
179 for (
i = max_sub_layers_minus1;
i < 8;
i++)
182 for (
i = 0;
i < max_sub_layers_minus1;
i++) {
183 if (sub_layer_profile_present_flag[
i]) {
200 if (sub_layer_level_present_flag[
i])
206 unsigned int cpb_cnt_minus1,
207 uint8_t sub_pic_hrd_params_present_flag)
211 for (
i = 0;
i <= cpb_cnt_minus1;
i++) {
215 if (sub_pic_hrd_params_present_flag) {
225 unsigned int max_sub_layers_minus1)
228 uint8_t sub_pic_hrd_params_present_flag = 0;
229 uint8_t nal_hrd_parameters_present_flag = 0;
230 uint8_t vcl_hrd_parameters_present_flag = 0;
232 if (cprms_present_flag) {
233 nal_hrd_parameters_present_flag =
get_bits1(gb);
234 vcl_hrd_parameters_present_flag =
get_bits1(gb);
236 if (nal_hrd_parameters_present_flag ||
237 vcl_hrd_parameters_present_flag) {
238 sub_pic_hrd_params_present_flag =
get_bits1(gb);
240 if (sub_pic_hrd_params_present_flag)
255 if (sub_pic_hrd_params_present_flag)
267 for (
i = 0;
i <= max_sub_layers_minus1;
i++) {
268 unsigned int cpb_cnt_minus1 = 0;
269 uint8_t low_delay_hrd_flag = 0;
270 uint8_t fixed_pic_rate_within_cvs_flag = 0;
271 uint8_t fixed_pic_rate_general_flag =
get_bits1(gb);
273 if (!fixed_pic_rate_general_flag)
274 fixed_pic_rate_within_cvs_flag =
get_bits1(gb);
276 if (fixed_pic_rate_within_cvs_flag)
281 if (!low_delay_hrd_flag) {
283 if (cpb_cnt_minus1 > 31)
287 if (nal_hrd_parameters_present_flag)
289 sub_pic_hrd_params_present_flag);
291 if (vcl_hrd_parameters_present_flag)
293 sub_pic_hrd_params_present_flag);
310 unsigned int max_sub_layers_minus1)
312 unsigned int min_spatial_segmentation_idc;
377 min_spatial_segmentation_idc);
395 uint8_t vps_max_layers_minus1,
396 uint8_t vps_base_layer_internal_flag)
398 uint8_t num_scalability_types = 0;
399 uint8_t max_layers_minus_1 =
FFMIN(62, vps_max_layers_minus1);
400 uint8_t splitting_flag, vps_nuh_layer_id_present_flag;
401 uint8_t scalability_mask_flag[16] = { 0 };
402 uint8_t dimension_id_len[16] = { 0 };
403 uint8_t layer_id_in_nuh[64] = { 0 };
406 if (vps_max_layers_minus1 > 0 && vps_base_layer_internal_flag)
411 for (
i = 0;
i < 16;
i++)
413 scalability_mask_flag[num_scalability_types++] =
i;
415 for (j = 0; j < (num_scalability_types - splitting_flag); j++)
416 dimension_id_len[j] =
get_bits(gb, 3) + 1;
418 vps_nuh_layer_id_present_flag =
get_bits(gb, 1);
420 for (
i = 1;
i <= max_layers_minus_1;
i++) {
421 if (vps_nuh_layer_id_present_flag)
424 layer_id_in_nuh[
i] =
i;
426 if (!splitting_flag) {
427 for (j = 0; j < num_scalability_types; j++) {
428 int dimension_id =
get_bits(gb, dimension_id_len[j]);
430 if (dimension_id == 1 && scalability_mask_flag[j] == 3 )
436 if (splitting_flag) {
437 uint8_t dim_bit_offset[17] = { 0 };
439 dim_bit_offset[0] = 0;
440 for (j = 1; j < num_scalability_types; j++)
441 dim_bit_offset[j] = dim_bit_offset[j-1] + dimension_id_len[j-1];
442 dim_bit_offset[num_scalability_types] = 6;
444 if (num_scalability_types > 0 && dim_bit_offset[num_scalability_types - 1] >= 6)
447 for (
i = 1;
i <= max_layers_minus_1;
i++) {
448 for (j = 0; j < num_scalability_types; j++) {
449 int dimension_id = (layer_id_in_nuh[
i] & ((1 << dim_bit_offset[j+1]) - 1)) >> dim_bit_offset[j];
451 if (dimension_id == 1 && scalability_mask_flag[j] == 3 )
463 uint8_t vps_base_layer_internal_flag, vps_max_layers_minus1;
464 uint8_t vps_sub_layer_ordering_info_present_flag, vps_max_layer_id;
465 int vps_num_layer_sets_minus1;
470 vps_base_layer_internal_flag =
get_bits(gb, 1);
472 vps_max_layers_minus1 =
get_bits(gb, 6);
495 vps_sub_layer_ordering_info_present_flag =
get_bits(gb, 1);
497 i <= nal->vps_max_sub_layers_minus1;
i++) {
505 skip_bits_long(gb, (vps_max_layer_id + 1) * vps_num_layer_sets_minus1);
508 int vps_num_hrd_parameters;
517 for (
i = 0;
i < vps_num_hrd_parameters;
i++) {
518 int cprms_present_flag;
522 cprms_present_flag =
get_bits(gb, 1);
524 cprms_present_flag = 1;
533 vps_max_layers_minus1,
534 vps_base_layer_internal_flag) < 0)
544 int i, j, k, num_coeffs;
546 for (
i = 0;
i < 4;
i++)
547 for (j = 0; j < (
i == 3 ? 2 : 6); j++)
551 num_coeffs =
FFMIN(64, 1 << (4 + (
i << 1)));
556 for (k = 0; k < num_coeffs; k++)
562 unsigned int num_rps,
569 if (rps_idx >= num_rps)
575 num_delta_pocs[rps_idx] = 0;
596 for (
i = 0;
i <= num_delta_pocs[rps_idx - 1];
i++) {
597 uint8_t use_delta_flag = 0;
598 uint8_t used_by_curr_pic_flag =
get_bits1(gb);
599 if (!used_by_curr_pic_flag)
602 if (used_by_curr_pic_flag || use_delta_flag)
603 num_delta_pocs[rps_idx]++;
609 if ((num_positive_pics + (uint64_t)num_negative_pics) * 2 >
get_bits_left(gb))
612 num_delta_pocs[rps_idx] = num_negative_pics + num_positive_pics;
614 for (
i = 0;
i < num_negative_pics;
i++) {
619 for (
i = 0;
i < num_positive_pics;
i++) {
631 unsigned int i, sps_max_sub_layers_minus1, log2_max_pic_order_cnt_lsb_minus4;
633 unsigned int sps_ext_or_max_sub_layers_minus1, multi_layer_ext_sps_flag;
635 unsigned int sps_video_parameter_set_id =
get_bits(gb, 4);
638 sps_ext_or_max_sub_layers_minus1 = 0;
639 sps_max_sub_layers_minus1 =
get_bits(gb, 3);
641 sps_ext_or_max_sub_layers_minus1 =
get_bits(gb, 3);
642 if (sps_ext_or_max_sub_layers_minus1 == 7) {
646 for (
i = 0;
i <
array->numNalus;
i++)
647 if (sps_video_parameter_set_id ==
array->nal[
i].parameter_set_id) {
654 sps_max_sub_layers_minus1 =
vps->vps_max_sub_layers_minus1;
656 sps_max_sub_layers_minus1 = sps_ext_or_max_sub_layers_minus1;
659 sps_ext_or_max_sub_layers_minus1 == 7;
670 sps_max_sub_layers_minus1 + 1);
672 if (!multi_layer_ext_sps_flag) {
679 if (multi_layer_ext_sps_flag) {
703 if (!multi_layer_ext_sps_flag) {
705 i =
get_bits1(gb) ? 0 : sps_max_sub_layers_minus1;
706 for (;
i <= sps_max_sub_layers_minus1;
i++)
718 int sps_infer_scaling_list_flag = 0;
719 if (multi_layer_ext_sps_flag)
720 sps_infer_scaling_list_flag =
get_bits1(gb);
721 if (sps_infer_scaling_list_flag)
742 for (
i = 0;
i < num_short_term_ref_pic_sets;
i++) {
743 int ret =
parse_rps(gb,
i, num_short_term_ref_pic_sets, num_delta_pocs);
750 if (num_long_term_ref_pics_sps > 31
U)
752 for (
i = 0;
i < num_long_term_ref_pics_sps;
i++) {
753 int len =
FFMIN(log2_max_pic_order_cnt_lsb_minus4 + 4, 16);
772 uint8_t tiles_enabled_flag, entropy_coding_sync_enabled_flag;
811 entropy_coding_sync_enabled_flag =
get_bits1(gb);
813 if (entropy_coding_sync_enabled_flag && tiles_enabled_flag)
815 else if (entropy_coding_sync_enabled_flag)
817 else if (tiles_enabled_flag)
827 uint8_t *nuh_layer_id)
845 uint16_t numNalus =
array->numNalus;
851 nal = &
array->nal[numNalus];
861 int flags,
unsigned array_idx)
870 uint8_t nal_type, nuh_layer_id;
896 if (
array->numNalus == 1) {
898 array->NAL_unit_type = nal_type;
908 array->array_completeness = ps_array_completeness;
1006 if (
array->numNalus == 0)
1009 for (
unsigned j = 0; j <
array->numNalus; j++)
1010 numNalus[
i] += !is_lhvc || (
array->nal[j].nuh_layer_id != 0);
1011 numOfArrays += (numNalus[
i] > 0);
1058 if (numNalus[
i] == 0)
1062 j,
array->array_completeness);
1064 j,
array->NAL_unit_type);
1067 for (
unsigned k = 0; k <
array->numNalus; k++) {
1068 if (is_lhvc &&
array->nal[k].nuh_layer_id == 0)
1072 "nuh_layer_id[%u][%u]: %"PRIu8
"\n",
1073 j, k,
array->nal[k].nuh_layer_id);
1075 "parameter_set_id[%u][%u]: %"PRIu8
"\n",
1076 j, k,
array->nal[k].parameter_set_id);
1078 "nalUnitLength[%u][%u]: %"PRIu16
"\n",
1079 j, k,
array->nal[k].nalUnitLength);
1182 array->NAL_unit_type & 0x3f);
1187 for (
unsigned j = 0; j <
array->numNalus; j++) {
1205 int size,
int filter_ps,
int *ps_count)
1207 int num_ps = 0,
ret = 0;
1208 uint8_t *buf, *end, *start =
NULL;
1223 while (end - buf > 4) {
1225 uint8_t
type = (buf[4] >> 1) & 0x3f;
1253 int *
size,
int filter_ps,
int *ps_count)
1278 static const uint8_t array_idx_to_type[] =
1282 if (
type == array_idx_to_type[
i]) {
1297 uint8_t *buf, *end, *start =
NULL;
1303 }
else if (*
data == 1) {
1343 for (
int i = 0;
i < num_arrays;
i++) {
1344 int type, num_nalus;
1349 for (
int j = 0; j < num_nalus; j++) {
1380 while (end - buf > 4) {
1382 uint8_t
type = (buf[4] >> 1) & 0x3f;
1402 int size,
int ps_array_completeness,
void *logctx)
1409 int size,
int ps_array_completeness,
void *logctx)