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);
356 sps->data[
sps->data_size++] = 0x80;
359 constraint_set_flags |=
get_bits1(gb) << 0;
360 constraint_set_flags |=
get_bits1(gb) << 1;
361 constraint_set_flags |=
get_bits1(gb) << 2;
362 constraint_set_flags |=
get_bits1(gb) << 3;
363 constraint_set_flags |=
get_bits1(gb) << 4;
364 constraint_set_flags |=
get_bits1(gb) << 5;
374 sps->sps_id = sps_id;
375 sps->time_offset_length = 24;
377 sps->constraint_set_flags = constraint_set_flags;
379 sps->full_range = -1;
381 memset(
sps->scaling_matrix4, 16,
sizeof(
sps->scaling_matrix4));
382 memset(
sps->scaling_matrix8, 16,
sizeof(
sps->scaling_matrix8));
383 sps->scaling_matrix_present = 0;
386 if (
sps->profile_idc == 100 ||
387 sps->profile_idc == 110 ||
388 sps->profile_idc == 122 ||
389 sps->profile_idc == 244 ||
390 sps->profile_idc == 44 ||
391 sps->profile_idc == 83 ||
392 sps->profile_idc == 86 ||
393 sps->profile_idc == 118 ||
394 sps->profile_idc == 128 ||
395 sps->profile_idc == 138 ||
396 sps->profile_idc == 144) {
398 if (
sps->chroma_format_idc > 3
U) {
400 sps->chroma_format_idc);
402 }
else if (
sps->chroma_format_idc == 3) {
404 if (
sps->residual_color_transform_flag) {
411 if (
sps->bit_depth_chroma !=
sps->bit_depth_luma) {
413 "Different chroma and luma bit depth");
416 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
417 sps->bit_depth_chroma < 8 ||
sps->bit_depth_chroma > 14) {
419 sps->bit_depth_luma,
sps->bit_depth_chroma);
424 sps->scaling_matrix4,
sps->scaling_matrix8);
427 sps->scaling_matrix_present |=
ret;
429 sps->chroma_format_idc = 1;
430 sps->bit_depth_luma = 8;
431 sps->bit_depth_chroma = 8;
438 "log2_max_frame_num_minus4 out of range (0-12): %d\n",
439 log2_max_frame_num_minus4);
442 sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4;
446 if (
sps->poc_type == 0) {
452 sps->log2_max_poc_lsb = t + 4;
453 }
else if (
sps->poc_type == 1) {
458 if (
sps->offset_for_non_ref_pic == INT32_MIN
459 ||
sps->offset_for_top_to_bottom_field == INT32_MIN
462 "offset_for_non_ref_pic or offset_for_top_to_bottom_field is out of range\n");
468 if ((
unsigned)
sps->poc_cycle_length >=
471 "poc_cycle_length overflow %d\n",
sps->poc_cycle_length);
475 for (
i = 0;
i <
sps->poc_cycle_length;
i++) {
477 if (
sps->offset_for_ref_frame[
i] == INT32_MIN) {
479 "offset_for_ref_frame is out of range\n");
483 }
else if (
sps->poc_type != 2) {
490 sps->ref_frame_count =
FFMAX(2,
sps->ref_frame_count);
493 "too many reference frames %d\n",
sps->ref_frame_count);
502 if (
sps->mb_height >= INT_MAX / 2
U) {
506 sps->mb_height *= 2 -
sps->frame_mbs_only_flag;
508 if (!
sps->frame_mbs_only_flag)
513 if ((
unsigned)
sps->mb_width >= INT_MAX / 16 ||
514 (
unsigned)
sps->mb_height >= INT_MAX / 16 ||
516 16 *
sps->mb_height, 0, avctx)) {
534 "values are l:%d r:%d t:%d b:%d\n",
535 crop_left, crop_right, crop_top, crop_bottom);
540 sps->crop_bottom = 0;
542 int vsub = (
sps->chroma_format_idc == 1) ? 1 : 0;
543 int hsub = (
sps->chroma_format_idc == 1 ||
544 sps->chroma_format_idc == 2) ? 1 : 0;
545 int step_x = 1 <<
hsub;
546 int step_y = (2 -
sps->frame_mbs_only_flag) << vsub;
548 if (crop_left > (
unsigned)INT_MAX / 4 / step_x ||
549 crop_right > (unsigned)INT_MAX / 4 / step_x ||
550 crop_top > (
unsigned)INT_MAX / 4 / step_y ||
551 crop_bottom> (unsigned)INT_MAX / 4 / step_y ||
552 (crop_left + crop_right ) * step_x >=
width ||
553 (crop_top + crop_bottom) * step_y >=
height
559 sps->crop_left = crop_left * step_x;
560 sps->crop_right = crop_right * step_x;
561 sps->crop_top = crop_top * step_y;
562 sps->crop_bottom = crop_bottom * step_y;
573 if (
sps->vui_parameters_present_flag) {
582 "Overread %s by %d bits\n",
sps->vui_parameters_present_flag ?
"VUI" :
"SPS", -
get_bits_left(gb));
583 if (!ignore_truncation)
589 if (!
sps->bitstream_restriction_flag &&
595 sps->num_reorder_frames);
605 static const char csp[4][5] = {
"Gray",
"420",
"422",
"444" };
607 "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",
608 sps_id,
sps->profile_idc,
sps->level_idc,
610 sps->ref_frame_count,
611 sps->mb_width,
sps->mb_height,
612 sps->frame_mbs_only_flag ?
"FRM" : (
sps->mb_aff ?
"MB-AFF" :
"PIC-AFF"),
613 sps->direct_8x8_inference_flag ?
"8B8" :
"",
614 sps->crop_left,
sps->crop_right,
615 sps->crop_top,
sps->crop_bottom,
616 sps->vui_parameters_present_flag ?
"VUI" :
"",
617 csp[
sps->chroma_format_idc],
618 sps->timing_info_present_flag ?
sps->num_units_in_tick : 0,
619 sps->timing_info_present_flag ?
sps->time_scale : 0,
621 sps->bitstream_restriction_flag ?
sps->num_reorder_frames : -1
646 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
648 for (
i = 0;
i < 6;
i++) {
649 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[
i];
650 for (j = 0; j <
i; j++)
651 if (!memcmp(
pps->scaling_matrix8[j],
pps->scaling_matrix8[
i],
652 64 *
sizeof(uint8_t))) {
653 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[j];
659 for (q = 0; q < max_qp + 1; q++) {
662 for (x = 0; x < 64; x++)
663 pps->dequant8_coeff[
i][q][(x >> 3) | ((x & 7) << 3)] =
673 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
674 for (
i = 0;
i < 6;
i++) {
675 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[
i];
676 for (j = 0; j <
i; j++)
677 if (!memcmp(
pps->scaling_matrix4[j],
pps->scaling_matrix4[
i],
678 16 *
sizeof(uint8_t))) {
679 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[j];
685 for (q = 0; q < max_qp + 1; q++) {
688 for (x = 0; x < 16; x++)
689 pps->dequant4_coeff[
i][q][(x >> 2) | ((x << 2) & 0xF)] =
700 memset(
pps->dequant8_coeff, 0,
sizeof(
pps->dequant8_coeff));
702 if (
pps->transform_8x8_mode)
704 if (
sps->transform_bypass) {
705 for (
i = 0;
i < 6;
i++)
706 for (x = 0; x < 16; x++)
707 pps->dequant4_coeff[
i][0][x] = 1 << 6;
708 if (
pps->transform_8x8_mode)
709 for (
i = 0;
i < 6;
i++)
710 for (x = 0; x < 64; x++)
711 pps->dequant8_coeff[
i][0][x] = 1 << 6;
718 const int max_qp = 51 + 6 * (depth - 8);
719 for (
i = 0;
i < max_qp + 1;
i++)
720 pps->chroma_qp_table[t][
i] =
731 "Current profile doesn't provide more RBSP data in PPS, skipping\n");
774 if (
pps->data_size >
sizeof(
pps->data)) {
777 pps->data_size,
sizeof(
pps->data));
778 pps->data_size =
sizeof(
pps->data);
783 if (!(bit_length & 7) &&
pps->data_size <
sizeof(
pps->data))
784 pps->data[
pps->data_size++] = 0x80;
798 pps->sps = (
const SPS*)
pps->sps_ref->data;
801 if (
sps->bit_depth_luma > 14) {
803 "Invalid luma bit depth=%d\n",
804 sps->bit_depth_luma);
807 }
else if (
sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13) {
809 "Unimplemented luma bit depth=%d",
810 sps->bit_depth_luma);
818 if (
pps->slice_group_count > 1) {
826 if (
pps->ref_count[0] - 1 > 32 - 1 ||
pps->ref_count[1] - 1 > 32 - 1) {
832 qp_bd_offset = 6 * (
sps->bit_depth_luma - 8);
839 if (
pps->chroma_qp_index_offset[0] < -12 ||
pps->chroma_qp_index_offset[0] > 12) {
844 pps->deblocking_filter_parameters_present =
get_bits1(gb);
848 pps->transform_8x8_mode = 0;
849 memcpy(
pps->scaling_matrix4,
sps->scaling_matrix4,
850 sizeof(
pps->scaling_matrix4));
851 memcpy(
pps->scaling_matrix8,
sps->scaling_matrix8,
852 sizeof(
pps->scaling_matrix8));
858 pps->scaling_matrix4,
pps->scaling_matrix8);
863 if (
pps->chroma_qp_index_offset[1] < -12 ||
pps->chroma_qp_index_offset[1] > 12) {
868 pps->chroma_qp_index_offset[1] =
pps->chroma_qp_index_offset[0];
872 sps->bit_depth_luma);
874 sps->bit_depth_luma);
878 if (
pps->chroma_qp_index_offset[0] !=
pps->chroma_qp_index_offset[1])
879 pps->chroma_qp_diff = 1;
883 "pps:%u sps:%u %s slice_groups:%d ref:%u/%u %s qp:%d/%d/%d/%d %s %s %s %s\n",
885 pps->cabac ?
"CABAC" :
"CAVLC",
886 pps->slice_group_count,
887 pps->ref_count[0],
pps->ref_count[1],
888 pps->weighted_pred ?
"weighted" :
"",
889 pps->init_qp,
pps->init_qs,
pps->chroma_qp_index_offset[0],
pps->chroma_qp_index_offset[1],
890 pps->deblocking_filter_parameters_present ?
"LPAR" :
"",
891 pps->constrained_intra_pred ?
"CONSTR" :
"",
892 pps->redundant_pic_cnt_present ?
"REDU" :
"",
893 pps->transform_8x8_mode ?
"8x8DCT" :
"");