37 #define MIN_LOG2_MAX_FRAME_NUM 4
39 #define EXTENDED_SAR 255
42 { 6, 13, 20, 28, 13, 20, 28, 32,
43 20, 28, 32, 37, 28, 32, 37, 42 },
44 { 10, 14, 20, 24, 14, 20, 24, 27,
45 20, 24, 27, 30, 24, 27, 30, 34 }
49 { 6, 10, 13, 16, 18, 23, 25, 27,
50 10, 11, 16, 18, 23, 25, 27, 29,
51 13, 16, 18, 23, 25, 27, 29, 31,
52 16, 18, 23, 25, 27, 29, 31, 33,
53 18, 23, 25, 27, 29, 31, 33, 36,
54 23, 25, 27, 29, 31, 33, 36, 38,
55 25, 27, 29, 31, 33, 36, 38, 40,
56 27, 29, 31, 33, 36, 38, 40, 42 },
57 { 9, 13, 15, 17, 19, 21, 22, 24,
58 13, 13, 17, 19, 21, 22, 24, 25,
59 15, 17, 19, 21, 22, 24, 25, 27,
60 17, 19, 21, 22, 24, 25, 27, 28,
61 19, 21, 22, 24, 25, 27, 28, 30,
62 21, 22, 24, 25, 27, 28, 30, 32,
63 22, 24, 25, 27, 28, 30, 32, 33,
64 24, 25, 27, 28, 30, 32, 33, 35 }
96 if (
s->sps_list[
id]) {
99 if (
s->pps_list[
i] && ((
PPS*)
s->pps_list[
i]->data)->sps_id ==
id)
112 if (cpb_count > 32
U) {
119 for (
i = 0;
i < cpb_count;
i++) {
124 sps->initial_cpb_removal_delay_length =
get_bits(gb, 5) + 1;
125 sps->cpb_removal_delay_length =
get_bits(gb, 5) + 1;
126 sps->dpb_output_delay_length =
get_bits(gb, 5) + 1;
128 sps->cpb_cnt = cpb_count;
135 int aspect_ratio_info_present_flag;
136 unsigned int aspect_ratio_idc;
138 aspect_ratio_info_present_flag =
get_bits1(gb);
140 if (aspect_ratio_info_present_flag) {
160 if (
sps->video_signal_type_present_flag) {
165 if (
sps->colour_description_present_flag) {
194 if (
sps->timing_info_present_flag) {
197 if (!num_units_in_tick || !time_scale) {
199 "time_scale/num_units_in_tick invalid or unsupported (%u/%u)\n",
200 time_scale, num_units_in_tick);
201 sps->timing_info_present_flag = 0;
203 sps->num_units_in_tick = num_units_in_tick;
204 sps->time_scale = time_scale;
210 if (
sps->nal_hrd_parameters_present_flag)
214 if (
sps->vcl_hrd_parameters_present_flag)
217 if (
sps->nal_hrd_parameters_present_flag ||
218 sps->vcl_hrd_parameters_present_flag)
224 if (
sps->bitstream_restriction_flag) {
234 sps->num_reorder_frames = 0;
235 sps->bitstream_restriction_flag = 0;
238 if (
sps->num_reorder_frames > 16
U
241 "Clipping illegal num_reorder_frames %d\n",
242 sps->num_reorder_frames);
243 sps->num_reorder_frames = 16;
252 const uint8_t *jvt_list,
253 const uint8_t *fallback_list)
255 int i, last = 8, next = 8;
258 memcpy(factors, fallback_list,
size *
sizeof(uint8_t));
263 if (v < -128 || v > 127) {
267 next = (last + v) & 0xff;
270 memcpy(factors, jvt_list,
size *
sizeof(uint8_t));
273 last = factors[scan[
i]] = next ? next : last;
280 const PPS *
pps,
int is_sps,
281 uint8_t(*scaling_matrix4)[16],
282 uint8_t(*scaling_matrix8)[64])
284 int fallback_sps = !is_sps &&
sps->scaling_matrix_present;
285 const uint8_t *fallback[4] = {
299 if (is_sps ||
pps->transform_8x8_mode) {
302 if (
sps->chroma_format_idc == 3) {
338 int i, log2_max_frame_num_minus4;
348 if (
sps->data_size >
sizeof(
sps->data)) {
350 sps->data_size =
sizeof(
sps->data);
355 constraint_set_flags |=
get_bits1(gb) << 0;
356 constraint_set_flags |=
get_bits1(gb) << 1;
357 constraint_set_flags |=
get_bits1(gb) << 2;
358 constraint_set_flags |=
get_bits1(gb) << 3;
359 constraint_set_flags |=
get_bits1(gb) << 4;
360 constraint_set_flags |=
get_bits1(gb) << 5;
370 sps->sps_id = sps_id;
371 sps->time_offset_length = 24;
373 sps->constraint_set_flags = constraint_set_flags;
375 sps->full_range = -1;
377 memset(
sps->scaling_matrix4, 16,
sizeof(
sps->scaling_matrix4));
378 memset(
sps->scaling_matrix8, 16,
sizeof(
sps->scaling_matrix8));
379 sps->scaling_matrix_present = 0;
382 if (
sps->profile_idc == 100 ||
383 sps->profile_idc == 110 ||
384 sps->profile_idc == 122 ||
385 sps->profile_idc == 244 ||
386 sps->profile_idc == 44 ||
387 sps->profile_idc == 83 ||
388 sps->profile_idc == 86 ||
389 sps->profile_idc == 118 ||
390 sps->profile_idc == 128 ||
391 sps->profile_idc == 138 ||
392 sps->profile_idc == 144) {
394 if (
sps->chroma_format_idc > 3
U) {
396 sps->chroma_format_idc);
398 }
else if (
sps->chroma_format_idc == 3) {
400 if (
sps->residual_color_transform_flag) {
407 if (
sps->bit_depth_chroma !=
sps->bit_depth_luma) {
409 "Different chroma and luma bit depth");
412 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
413 sps->bit_depth_chroma < 8 ||
sps->bit_depth_chroma > 14) {
415 sps->bit_depth_luma,
sps->bit_depth_chroma);
420 sps->scaling_matrix4,
sps->scaling_matrix8);
423 sps->scaling_matrix_present |=
ret;
425 sps->chroma_format_idc = 1;
426 sps->bit_depth_luma = 8;
427 sps->bit_depth_chroma = 8;
434 "log2_max_frame_num_minus4 out of range (0-12): %d\n",
435 log2_max_frame_num_minus4);
438 sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4;
442 if (
sps->poc_type == 0) {
448 sps->log2_max_poc_lsb = t + 4;
449 }
else if (
sps->poc_type == 1) {
454 if (
sps->offset_for_non_ref_pic == INT32_MIN
455 ||
sps->offset_for_top_to_bottom_field == INT32_MIN
458 "offset_for_non_ref_pic or offset_for_top_to_bottom_field is out of range\n");
464 if ((
unsigned)
sps->poc_cycle_length >=
467 "poc_cycle_length overflow %d\n",
sps->poc_cycle_length);
471 for (
i = 0;
i <
sps->poc_cycle_length;
i++) {
473 if (
sps->offset_for_ref_frame[
i] == INT32_MIN) {
475 "offset_for_ref_frame is out of range\n");
479 }
else if (
sps->poc_type != 2) {
486 sps->ref_frame_count =
FFMAX(2,
sps->ref_frame_count);
489 "too many reference frames %d\n",
sps->ref_frame_count);
498 if (
sps->mb_height >= INT_MAX / 2
U) {
502 sps->mb_height *= 2 -
sps->frame_mbs_only_flag;
504 if (!
sps->frame_mbs_only_flag)
509 if ((
unsigned)
sps->mb_width >= INT_MAX / 16 ||
510 (
unsigned)
sps->mb_height >= INT_MAX / 16 ||
512 16 *
sps->mb_height, 0, avctx)) {
530 "values are l:%d r:%d t:%d b:%d\n",
531 crop_left, crop_right, crop_top, crop_bottom);
536 sps->crop_bottom = 0;
538 int vsub = (
sps->chroma_format_idc == 1) ? 1 : 0;
539 int hsub = (
sps->chroma_format_idc == 1 ||
540 sps->chroma_format_idc == 2) ? 1 : 0;
541 int step_x = 1 <<
hsub;
542 int step_y = (2 -
sps->frame_mbs_only_flag) << vsub;
544 if (crop_left > (
unsigned)INT_MAX / 4 / step_x ||
545 crop_right > (unsigned)INT_MAX / 4 / step_x ||
546 crop_top > (
unsigned)INT_MAX / 4 / step_y ||
547 crop_bottom> (unsigned)INT_MAX / 4 / step_y ||
548 (crop_left + crop_right ) * step_x >=
width ||
549 (crop_top + crop_bottom) * step_y >=
height
555 sps->crop_left = crop_left * step_x;
556 sps->crop_right = crop_right * step_x;
557 sps->crop_top = crop_top * step_y;
558 sps->crop_bottom = crop_bottom * step_y;
569 if (
sps->vui_parameters_present_flag) {
578 "Overread %s by %d bits\n",
sps->vui_parameters_present_flag ?
"VUI" :
"SPS", -
get_bits_left(gb));
579 if (!ignore_truncation)
585 if (!
sps->bitstream_restriction_flag &&
591 sps->num_reorder_frames);
601 static const char csp[4][5] = {
"Gray",
"420",
"422",
"444" };
603 "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%u/%u/%u/%u %s %s %"PRId32
"/%"PRId32
" b%d reo:%d\n",
604 sps_id,
sps->profile_idc,
sps->level_idc,
606 sps->ref_frame_count,
607 sps->mb_width,
sps->mb_height,
608 sps->frame_mbs_only_flag ?
"FRM" : (
sps->mb_aff ?
"MB-AFF" :
"PIC-AFF"),
609 sps->direct_8x8_inference_flag ?
"8B8" :
"",
610 sps->crop_left,
sps->crop_right,
611 sps->crop_top,
sps->crop_bottom,
612 sps->vui_parameters_present_flag ?
"VUI" :
"",
613 csp[
sps->chroma_format_idc],
614 sps->timing_info_present_flag ?
sps->num_units_in_tick : 0,
615 sps->timing_info_present_flag ?
sps->time_scale : 0,
617 sps->bitstream_restriction_flag ?
sps->num_reorder_frames : -1
642 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
644 for (
i = 0;
i < 6;
i++) {
645 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[
i];
646 for (j = 0; j <
i; j++)
647 if (!memcmp(
pps->scaling_matrix8[j],
pps->scaling_matrix8[
i],
648 64 *
sizeof(uint8_t))) {
649 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[j];
655 for (q = 0; q < max_qp + 1; q++) {
658 for (x = 0; x < 64; x++)
659 pps->dequant8_coeff[
i][q][(x >> 3) | ((x & 7) << 3)] =
669 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
670 for (
i = 0;
i < 6;
i++) {
671 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[
i];
672 for (j = 0; j <
i; j++)
673 if (!memcmp(
pps->scaling_matrix4[j],
pps->scaling_matrix4[
i],
674 16 *
sizeof(uint8_t))) {
675 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[j];
681 for (q = 0; q < max_qp + 1; q++) {
684 for (x = 0; x < 16; x++)
685 pps->dequant4_coeff[
i][q][(x >> 2) | ((x << 2) & 0xF)] =
696 memset(
pps->dequant8_coeff, 0,
sizeof(
pps->dequant8_coeff));
698 if (
pps->transform_8x8_mode)
700 if (
sps->transform_bypass) {
701 for (
i = 0;
i < 6;
i++)
702 for (x = 0; x < 16; x++)
703 pps->dequant4_coeff[
i][0][x] = 1 << 6;
704 if (
pps->transform_8x8_mode)
705 for (
i = 0;
i < 6;
i++)
706 for (x = 0; x < 64; x++)
707 pps->dequant8_coeff[
i][0][x] = 1 << 6;
714 const int max_qp = 51 + 6 * (depth - 8);
715 for (
i = 0;
i < max_qp + 1;
i++)
716 pps->chroma_qp_table[t][
i] =
727 "Current profile doesn't provide more RBSP data in PPS, skipping\n");
770 if (
pps->data_size >
sizeof(
pps->data)) {
773 pps->data_size,
sizeof(
pps->data));
774 pps->data_size =
sizeof(
pps->data);
790 pps->sps = (
const SPS*)
pps->sps_ref->data;
793 if (
sps->bit_depth_luma > 14) {
795 "Invalid luma bit depth=%d\n",
796 sps->bit_depth_luma);
799 }
else if (
sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13) {
801 "Unimplemented luma bit depth=%d",
802 sps->bit_depth_luma);
810 if (
pps->slice_group_count > 1) {
818 if (
pps->ref_count[0] - 1 > 32 - 1 ||
pps->ref_count[1] - 1 > 32 - 1) {
824 qp_bd_offset = 6 * (
sps->bit_depth_luma - 8);
831 if (
pps->chroma_qp_index_offset[0] < -12 ||
pps->chroma_qp_index_offset[0] > 12) {
836 pps->deblocking_filter_parameters_present =
get_bits1(gb);
840 pps->transform_8x8_mode = 0;
841 memcpy(
pps->scaling_matrix4,
sps->scaling_matrix4,
842 sizeof(
pps->scaling_matrix4));
843 memcpy(
pps->scaling_matrix8,
sps->scaling_matrix8,
844 sizeof(
pps->scaling_matrix8));
850 pps->scaling_matrix4,
pps->scaling_matrix8);
855 if (
pps->chroma_qp_index_offset[1] < -12 ||
pps->chroma_qp_index_offset[1] > 12) {
860 pps->chroma_qp_index_offset[1] =
pps->chroma_qp_index_offset[0];
864 sps->bit_depth_luma);
866 sps->bit_depth_luma);
870 if (
pps->chroma_qp_index_offset[0] !=
pps->chroma_qp_index_offset[1])
871 pps->chroma_qp_diff = 1;
875 "pps:%u sps:%u %s slice_groups:%d ref:%u/%u %s qp:%d/%d/%d/%d %s %s %s %s\n",
877 pps->cabac ?
"CABAC" :
"CAVLC",
878 pps->slice_group_count,
879 pps->ref_count[0],
pps->ref_count[1],
880 pps->weighted_pred ?
"weighted" :
"",
881 pps->init_qp,
pps->init_qs,
pps->chroma_qp_index_offset[0],
pps->chroma_qp_index_offset[1],
882 pps->deblocking_filter_parameters_present ?
"LPAR" :
"",
883 pps->constrained_intra_pred ?
"CONSTR" :
"",
884 pps->redundant_pic_cnt_present ?
"REDU" :
"",
885 pps->transform_8x8_mode ?
"8x8DCT" :
"");