38 #define MIN_LOG2_MAX_FRAME_NUM 4
41 { 6, 13, 20, 28, 13, 20, 28, 32,
42 20, 28, 32, 37, 28, 32, 37, 42 },
43 { 10, 14, 20, 24, 14, 20, 24, 27,
44 20, 24, 27, 30, 24, 27, 30, 34 }
48 { 6, 10, 13, 16, 18, 23, 25, 27,
49 10, 11, 16, 18, 23, 25, 27, 29,
50 13, 16, 18, 23, 25, 27, 29, 31,
51 16, 18, 23, 25, 27, 29, 31, 33,
52 18, 23, 25, 27, 29, 31, 33, 36,
53 23, 25, 27, 29, 31, 33, 36, 38,
54 25, 27, 29, 31, 33, 36, 38, 40,
55 27, 29, 31, 33, 36, 38, 40, 42 },
56 { 9, 13, 15, 17, 19, 21, 22, 24,
57 13, 13, 17, 19, 21, 22, 24, 25,
58 15, 17, 19, 21, 22, 24, 25, 27,
59 17, 19, 21, 22, 24, 25, 27, 28,
60 19, 21, 22, 24, 25, 27, 28, 30,
61 21, 22, 24, 25, 27, 28, 30, 32,
62 22, 24, 25, 27, 28, 30, 32, 33,
63 24, 25, 27, 28, 30, 32, 33, 35 }
95 if (
s->sps_list[
id]) {
98 if (
s->pps_list[
i] && ((
PPS*)
s->pps_list[
i]->data)->sps_id ==
id)
111 if (cpb_count > 32
U) {
118 for (
i = 0;
i < cpb_count;
i++) {
123 sps->initial_cpb_removal_delay_length =
get_bits(gb, 5) + 1;
124 sps->cpb_removal_delay_length =
get_bits(gb, 5) + 1;
125 sps->dpb_output_delay_length =
get_bits(gb, 5) + 1;
127 sps->cpb_cnt = cpb_count;
142 if (
sps->timing_info_present_flag) {
145 if (!num_units_in_tick || !time_scale) {
147 "time_scale/num_units_in_tick invalid or unsupported (%u/%u)\n",
148 time_scale, num_units_in_tick);
149 sps->timing_info_present_flag = 0;
151 sps->num_units_in_tick = num_units_in_tick;
152 sps->time_scale = time_scale;
158 if (
sps->nal_hrd_parameters_present_flag)
162 if (
sps->vcl_hrd_parameters_present_flag)
165 if (
sps->nal_hrd_parameters_present_flag ||
166 sps->vcl_hrd_parameters_present_flag)
172 if (
sps->bitstream_restriction_flag) {
182 sps->num_reorder_frames = 0;
183 sps->bitstream_restriction_flag = 0;
186 if (
sps->num_reorder_frames > 16
U
189 "Clipping illegal num_reorder_frames %d\n",
190 sps->num_reorder_frames);
191 sps->num_reorder_frames = 16;
200 const uint8_t *jvt_list,
201 const uint8_t *fallback_list)
203 int i, last = 8, next = 8;
206 memcpy(factors, fallback_list,
size *
sizeof(uint8_t));
211 if (v < -128 || v > 127) {
215 next = (last + v) & 0xff;
218 memcpy(factors, jvt_list,
size *
sizeof(uint8_t));
221 last = factors[scan[
i]] = next ? next : last;
228 const PPS *
pps,
int is_sps,
229 uint8_t(*scaling_matrix4)[16],
230 uint8_t(*scaling_matrix8)[64])
232 int fallback_sps = !is_sps &&
sps->scaling_matrix_present;
233 const uint8_t *fallback[4] = {
247 if (is_sps ||
pps->transform_8x8_mode) {
250 if (
sps->chroma_format_idc == 3) {
286 int i, log2_max_frame_num_minus4;
296 if (
sps->data_size >
sizeof(
sps->data)) {
298 sps->data_size =
sizeof(
sps->data);
304 sps->data[
sps->data_size++] = 0x80;
307 constraint_set_flags |=
get_bits1(gb) << 0;
308 constraint_set_flags |=
get_bits1(gb) << 1;
309 constraint_set_flags |=
get_bits1(gb) << 2;
310 constraint_set_flags |=
get_bits1(gb) << 3;
311 constraint_set_flags |=
get_bits1(gb) << 4;
312 constraint_set_flags |=
get_bits1(gb) << 5;
322 sps->sps_id = sps_id;
323 sps->time_offset_length = 24;
325 sps->constraint_set_flags = constraint_set_flags;
327 sps->vui.video_full_range_flag = -1;
329 memset(
sps->scaling_matrix4, 16,
sizeof(
sps->scaling_matrix4));
330 memset(
sps->scaling_matrix8, 16,
sizeof(
sps->scaling_matrix8));
331 sps->scaling_matrix_present = 0;
334 if (
sps->profile_idc == 100 ||
335 sps->profile_idc == 110 ||
336 sps->profile_idc == 122 ||
337 sps->profile_idc == 244 ||
338 sps->profile_idc == 44 ||
339 sps->profile_idc == 83 ||
340 sps->profile_idc == 86 ||
341 sps->profile_idc == 118 ||
342 sps->profile_idc == 128 ||
343 sps->profile_idc == 138 ||
344 sps->profile_idc == 144) {
346 if (
sps->chroma_format_idc > 3
U) {
348 sps->chroma_format_idc);
350 }
else if (
sps->chroma_format_idc == 3) {
352 if (
sps->residual_color_transform_flag) {
359 if (
sps->bit_depth_chroma !=
sps->bit_depth_luma) {
361 "Different chroma and luma bit depth");
364 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
365 sps->bit_depth_chroma < 8 ||
sps->bit_depth_chroma > 14) {
367 sps->bit_depth_luma,
sps->bit_depth_chroma);
372 sps->scaling_matrix4,
sps->scaling_matrix8);
375 sps->scaling_matrix_present |=
ret;
377 sps->chroma_format_idc = 1;
378 sps->bit_depth_luma = 8;
379 sps->bit_depth_chroma = 8;
386 "log2_max_frame_num_minus4 out of range (0-12): %d\n",
387 log2_max_frame_num_minus4);
390 sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4;
394 if (
sps->poc_type == 0) {
400 sps->log2_max_poc_lsb = t + 4;
401 }
else if (
sps->poc_type == 1) {
406 if (
sps->offset_for_non_ref_pic == INT32_MIN
407 ||
sps->offset_for_top_to_bottom_field == INT32_MIN
410 "offset_for_non_ref_pic or offset_for_top_to_bottom_field is out of range\n");
416 if ((
unsigned)
sps->poc_cycle_length >=
419 "poc_cycle_length overflow %d\n",
sps->poc_cycle_length);
423 for (
i = 0;
i <
sps->poc_cycle_length;
i++) {
425 if (
sps->offset_for_ref_frame[
i] == INT32_MIN) {
427 "offset_for_ref_frame is out of range\n");
431 }
else if (
sps->poc_type != 2) {
438 sps->ref_frame_count =
FFMAX(2,
sps->ref_frame_count);
441 "too many reference frames %d\n",
sps->ref_frame_count);
450 if (
sps->mb_height >= INT_MAX / 2
U) {
454 sps->mb_height *= 2 -
sps->frame_mbs_only_flag;
456 if (!
sps->frame_mbs_only_flag)
461 if ((
unsigned)
sps->mb_width >= INT_MAX / 16 ||
462 (
unsigned)
sps->mb_height >= INT_MAX / 16 ||
464 16 *
sps->mb_height, 0, avctx)) {
482 "values are l:%d r:%d t:%d b:%d\n",
483 crop_left, crop_right, crop_top, crop_bottom);
488 sps->crop_bottom = 0;
490 int vsub = (
sps->chroma_format_idc == 1) ? 1 : 0;
491 int hsub = (
sps->chroma_format_idc == 1 ||
492 sps->chroma_format_idc == 2) ? 1 : 0;
493 int step_x = 1 <<
hsub;
494 int step_y = (2 -
sps->frame_mbs_only_flag) << vsub;
496 if (crop_left > (
unsigned)INT_MAX / 4 / step_x ||
497 crop_right > (unsigned)INT_MAX / 4 / step_x ||
498 crop_top > (
unsigned)INT_MAX / 4 / step_y ||
499 crop_bottom> (unsigned)INT_MAX / 4 / step_y ||
500 (crop_left + crop_right ) * step_x >=
width ||
501 (crop_top + crop_bottom) * step_y >=
height
507 sps->crop_left = crop_left * step_x;
508 sps->crop_right = crop_right * step_x;
509 sps->crop_top = crop_top * step_y;
510 sps->crop_bottom = crop_bottom * step_y;
521 if (
sps->vui_parameters_present_flag) {
530 "Overread %s by %d bits\n",
sps->vui_parameters_present_flag ?
"VUI" :
"SPS", -
get_bits_left(gb));
531 if (!ignore_truncation)
537 if (!
sps->bitstream_restriction_flag &&
543 sps->num_reorder_frames);
549 if (!
sps->vui.sar.den)
550 sps->vui.sar.den = 1;
553 static const char csp[4][5] = {
"Gray",
"420",
"422",
"444" };
555 "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",
556 sps_id,
sps->profile_idc,
sps->level_idc,
558 sps->ref_frame_count,
559 sps->mb_width,
sps->mb_height,
560 sps->frame_mbs_only_flag ?
"FRM" : (
sps->mb_aff ?
"MB-AFF" :
"PIC-AFF"),
561 sps->direct_8x8_inference_flag ?
"8B8" :
"",
562 sps->crop_left,
sps->crop_right,
563 sps->crop_top,
sps->crop_bottom,
564 sps->vui_parameters_present_flag ?
"VUI" :
"",
565 csp[
sps->chroma_format_idc],
566 sps->timing_info_present_flag ?
sps->num_units_in_tick : 0,
567 sps->timing_info_present_flag ?
sps->time_scale : 0,
569 sps->bitstream_restriction_flag ?
sps->num_reorder_frames : -1
594 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
596 for (
i = 0;
i < 6;
i++) {
597 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[
i];
598 for (j = 0; j <
i; j++)
599 if (!memcmp(
pps->scaling_matrix8[j],
pps->scaling_matrix8[
i],
600 64 *
sizeof(uint8_t))) {
601 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[j];
607 for (q = 0; q < max_qp + 1; q++) {
610 for (x = 0; x < 64; x++)
611 pps->dequant8_coeff[
i][q][(x >> 3) | ((x & 7) << 3)] =
621 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
622 for (
i = 0;
i < 6;
i++) {
623 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[
i];
624 for (j = 0; j <
i; j++)
625 if (!memcmp(
pps->scaling_matrix4[j],
pps->scaling_matrix4[
i],
626 16 *
sizeof(uint8_t))) {
627 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[j];
633 for (q = 0; q < max_qp + 1; q++) {
636 for (x = 0; x < 16; x++)
637 pps->dequant4_coeff[
i][q][(x >> 2) | ((x << 2) & 0xF)] =
648 memset(
pps->dequant8_coeff, 0,
sizeof(
pps->dequant8_coeff));
650 if (
pps->transform_8x8_mode)
652 if (
sps->transform_bypass) {
653 for (
i = 0;
i < 6;
i++)
654 for (x = 0; x < 16; x++)
655 pps->dequant4_coeff[
i][0][x] = 1 << 6;
656 if (
pps->transform_8x8_mode)
657 for (
i = 0;
i < 6;
i++)
658 for (x = 0; x < 64; x++)
659 pps->dequant8_coeff[
i][0][x] = 1 << 6;
666 const int max_qp = 51 + 6 * (depth - 8);
667 for (
i = 0;
i < max_qp + 1;
i++)
668 pps->chroma_qp_table[t][
i] =
679 "Current profile doesn't provide more RBSP data in PPS, skipping\n");
722 if (
pps->data_size >
sizeof(
pps->data)) {
725 pps->data_size,
sizeof(
pps->data));
726 pps->data_size =
sizeof(
pps->data);
731 if (!(bit_length & 7) &&
pps->data_size <
sizeof(
pps->data))
732 pps->data[
pps->data_size++] = 0x80;
746 pps->sps = (
const SPS*)
pps->sps_ref->data;
749 if (
sps->bit_depth_luma > 14) {
751 "Invalid luma bit depth=%d\n",
752 sps->bit_depth_luma);
755 }
else if (
sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13) {
757 "Unimplemented luma bit depth=%d",
758 sps->bit_depth_luma);
766 if (
pps->slice_group_count > 1) {
774 if (
pps->ref_count[0] - 1 > 32 - 1 ||
pps->ref_count[1] - 1 > 32 - 1) {
780 qp_bd_offset = 6 * (
sps->bit_depth_luma - 8);
787 if (
pps->chroma_qp_index_offset[0] < -12 ||
pps->chroma_qp_index_offset[0] > 12) {
792 pps->deblocking_filter_parameters_present =
get_bits1(gb);
796 pps->transform_8x8_mode = 0;
797 memcpy(
pps->scaling_matrix4,
sps->scaling_matrix4,
798 sizeof(
pps->scaling_matrix4));
799 memcpy(
pps->scaling_matrix8,
sps->scaling_matrix8,
800 sizeof(
pps->scaling_matrix8));
806 pps->scaling_matrix4,
pps->scaling_matrix8);
811 if (
pps->chroma_qp_index_offset[1] < -12 ||
pps->chroma_qp_index_offset[1] > 12) {
816 pps->chroma_qp_index_offset[1] =
pps->chroma_qp_index_offset[0];
820 sps->bit_depth_luma);
822 sps->bit_depth_luma);
826 if (
pps->chroma_qp_index_offset[0] !=
pps->chroma_qp_index_offset[1])
827 pps->chroma_qp_diff = 1;
831 "pps:%u sps:%u %s slice_groups:%d ref:%u/%u %s qp:%d/%d/%d/%d %s %s %s %s\n",
833 pps->cabac ?
"CABAC" :
"CAVLC",
834 pps->slice_group_count,
835 pps->ref_count[0],
pps->ref_count[1],
836 pps->weighted_pred ?
"weighted" :
"",
837 pps->init_qp,
pps->init_qs,
pps->chroma_qp_index_offset[0],
pps->chroma_qp_index_offset[1],
838 pps->deblocking_filter_parameters_present ?
"LPAR" :
"",
839 pps->constrained_intra_pred ?
"CONSTR" :
"",
840 pps->redundant_pic_cnt_present ?
"REDU" :
"",
841 pps->transform_8x8_mode ?
"8x8DCT" :
"");