39 #define MIN_LOG2_MAX_FRAME_NUM 4
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] &&
s->pps_list[
i]->sps_id ==
id)
112 if (cpb_count > 32
U) {
120 for (
i = 0;
i < cpb_count;
i++) {
125 sps->initial_cpb_removal_delay_length =
get_bits(gb, 5) + 1;
126 sps->cpb_removal_delay_length =
get_bits(gb, 5) + 1;
127 sps->dpb_output_delay_length =
get_bits(gb, 5) + 1;
129 sps->cpb_cnt = cpb_count;
144 if (
sps->timing_info_present_flag) {
147 if (!num_units_in_tick || !time_scale) {
149 "time_scale/num_units_in_tick invalid or unsupported (%u/%u)\n",
150 time_scale, num_units_in_tick);
151 sps->timing_info_present_flag = 0;
153 sps->num_units_in_tick = num_units_in_tick;
154 sps->time_scale = time_scale;
160 if (
sps->nal_hrd_parameters_present_flag)
164 if (
sps->vcl_hrd_parameters_present_flag)
167 if (
sps->nal_hrd_parameters_present_flag ||
168 sps->vcl_hrd_parameters_present_flag)
174 if (
sps->bitstream_restriction_flag) {
184 sps->num_reorder_frames = 0;
185 sps->bitstream_restriction_flag = 0;
188 if (
sps->num_reorder_frames > 16
U
191 "Clipping illegal num_reorder_frames %d\n",
192 sps->num_reorder_frames);
193 sps->num_reorder_frames = 16;
202 const uint8_t *jvt_list,
const uint8_t *fallback_list,
205 int i, last = 8, next = 8;
207 uint16_t seq_scaling_list_present_flag =
get_bits1(gb);
208 *
mask |= (seq_scaling_list_present_flag <<
pos);
209 if (!seq_scaling_list_present_flag)
210 memcpy(factors, fallback_list,
size *
sizeof(uint8_t));
215 if (v < -128 || v > 127) {
219 next = (last + v) & 0xff;
222 memcpy(factors, jvt_list,
size *
sizeof(uint8_t));
225 last = factors[scan[
i]] = next ? next : last;
232 const PPS *
pps,
int is_sps,
233 int present_flag, uint16_t *
mask,
234 uint8_t(*scaling_matrix4)[16],
235 uint8_t(*scaling_matrix8)[64])
237 int fallback_sps = !is_sps &&
sps->scaling_matrix_present;
238 const uint8_t *fallback[4] = {
253 if (is_sps ||
pps->transform_8x8_mode) {
256 if (
sps->chroma_format_idc == 3) {
289 int i, log2_max_frame_num_minus4;
298 if (
sps->data_size >
sizeof(
sps->data)) {
300 sps->data_size =
sizeof(
sps->data);
306 sps->data[
sps->data_size++] = 0x80;
309 constraint_set_flags |=
get_bits1(gb) << 0;
310 constraint_set_flags |=
get_bits1(gb) << 1;
311 constraint_set_flags |=
get_bits1(gb) << 2;
312 constraint_set_flags |=
get_bits1(gb) << 3;
313 constraint_set_flags |=
get_bits1(gb) << 4;
314 constraint_set_flags |=
get_bits1(gb) << 5;
324 sps->sps_id = sps_id;
325 sps->time_offset_length = 24;
327 sps->constraint_set_flags = constraint_set_flags;
329 sps->vui.video_full_range_flag = -1;
331 memset(
sps->scaling_matrix4, 16,
sizeof(
sps->scaling_matrix4));
332 memset(
sps->scaling_matrix8, 16,
sizeof(
sps->scaling_matrix8));
333 sps->scaling_matrix_present = 0;
336 if (
sps->profile_idc == 100 ||
337 sps->profile_idc == 110 ||
338 sps->profile_idc == 122 ||
339 sps->profile_idc == 244 ||
340 sps->profile_idc == 44 ||
341 sps->profile_idc == 83 ||
342 sps->profile_idc == 86 ||
343 sps->profile_idc == 118 ||
344 sps->profile_idc == 128 ||
345 sps->profile_idc == 138 ||
346 sps->profile_idc == 144) {
348 if (
sps->chroma_format_idc > 3
U) {
350 sps->chroma_format_idc);
352 }
else if (
sps->chroma_format_idc == 3) {
354 if (
sps->residual_color_transform_flag) {
361 if (
sps->bit_depth_chroma !=
sps->bit_depth_luma) {
363 "Different chroma and luma bit depth");
366 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
367 sps->bit_depth_chroma < 8 ||
sps->bit_depth_chroma > 14) {
369 sps->bit_depth_luma,
sps->bit_depth_chroma);
374 &
sps->scaling_matrix_present_mask,
375 sps->scaling_matrix4,
sps->scaling_matrix8);
378 sps->scaling_matrix_present |=
ret;
380 sps->chroma_format_idc = 1;
381 sps->bit_depth_luma = 8;
382 sps->bit_depth_chroma = 8;
389 "log2_max_frame_num_minus4 out of range (0-12): %d\n",
390 log2_max_frame_num_minus4);
393 sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4;
397 if (
sps->poc_type == 0) {
403 sps->log2_max_poc_lsb = t + 4;
404 }
else if (
sps->poc_type == 1) {
409 if (
sps->offset_for_non_ref_pic == INT32_MIN
410 ||
sps->offset_for_top_to_bottom_field == INT32_MIN
413 "offset_for_non_ref_pic or offset_for_top_to_bottom_field is out of range\n");
419 if ((
unsigned)
sps->poc_cycle_length >=
422 "poc_cycle_length overflow %d\n",
sps->poc_cycle_length);
426 for (
i = 0;
i <
sps->poc_cycle_length;
i++) {
428 if (
sps->offset_for_ref_frame[
i] == INT32_MIN) {
430 "offset_for_ref_frame is out of range\n");
434 }
else if (
sps->poc_type != 2) {
441 sps->ref_frame_count =
FFMAX(2,
sps->ref_frame_count);
444 "too many reference frames %d\n",
sps->ref_frame_count);
453 if (
sps->mb_height >= INT_MAX / 2
U) {
457 sps->mb_height *= 2 -
sps->frame_mbs_only_flag;
459 if (!
sps->frame_mbs_only_flag)
464 if ((
unsigned)
sps->mb_width >= INT_MAX / 16 ||
465 (
unsigned)
sps->mb_height >= INT_MAX / 16 ||
467 16 *
sps->mb_height, 0, avctx)) {
485 "values are l:%d r:%d t:%d b:%d\n",
486 crop_left, crop_right, crop_top, crop_bottom);
491 sps->crop_bottom = 0;
493 int vsub = (
sps->chroma_format_idc == 1) ? 1 : 0;
494 int hsub = (
sps->chroma_format_idc == 1 ||
495 sps->chroma_format_idc == 2) ? 1 : 0;
496 int step_x = 1 <<
hsub;
497 int step_y = (2 -
sps->frame_mbs_only_flag) << vsub;
499 if (crop_left > (
unsigned)INT_MAX / 4 / step_x ||
500 crop_right > (unsigned)INT_MAX / 4 / step_x ||
501 crop_top > (
unsigned)INT_MAX / 4 / step_y ||
502 crop_bottom> (unsigned)INT_MAX / 4 / step_y ||
503 (crop_left + crop_right ) * step_x >=
width ||
504 (crop_top + crop_bottom) * step_y >=
height
510 sps->crop_left = crop_left * step_x;
511 sps->crop_right = crop_right * step_x;
512 sps->crop_top = crop_top * step_y;
513 sps->crop_bottom = crop_bottom * step_y;
524 if (
sps->vui_parameters_present_flag) {
533 "Overread %s by %d bits\n",
sps->vui_parameters_present_flag ?
"VUI" :
"SPS", -
get_bits_left(gb));
534 if (!ignore_truncation)
540 if (!
sps->bitstream_restriction_flag &&
546 sps->num_reorder_frames);
552 if (!
sps->vui.sar.den)
553 sps->vui.sar.den = 1;
556 static const char csp[4][5] = {
"Gray",
"420",
"422",
"444" };
558 "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",
559 sps_id,
sps->profile_idc,
sps->level_idc,
561 sps->ref_frame_count,
562 sps->mb_width,
sps->mb_height,
563 sps->frame_mbs_only_flag ?
"FRM" : (
sps->mb_aff ?
"MB-AFF" :
"PIC-AFF"),
564 sps->direct_8x8_inference_flag ?
"8B8" :
"",
565 sps->crop_left,
sps->crop_right,
566 sps->crop_top,
sps->crop_bottom,
567 sps->vui_parameters_present_flag ?
"VUI" :
"",
568 csp[
sps->chroma_format_idc],
569 sps->timing_info_present_flag ?
sps->num_units_in_tick : 0,
570 sps->timing_info_present_flag ?
sps->time_scale : 0,
572 sps->bitstream_restriction_flag ?
sps->num_reorder_frames : -1
597 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
599 for (
i = 0;
i < 6;
i++) {
600 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[
i];
601 for (j = 0; j <
i; j++)
602 if (!memcmp(
pps->scaling_matrix8[j],
pps->scaling_matrix8[
i],
603 64 *
sizeof(uint8_t))) {
604 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[j];
610 for (q = 0; q < max_qp + 1; q++) {
613 for (x = 0; x < 64; x++)
614 pps->dequant8_coeff[
i][q][(x >> 3) | ((x & 7) << 3)] =
624 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
625 for (
i = 0;
i < 6;
i++) {
626 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[
i];
627 for (j = 0; j <
i; j++)
628 if (!memcmp(
pps->scaling_matrix4[j],
pps->scaling_matrix4[
i],
629 16 *
sizeof(uint8_t))) {
630 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[j];
636 for (q = 0; q < max_qp + 1; q++) {
639 for (x = 0; x < 16; x++)
640 pps->dequant4_coeff[
i][q][(x >> 2) | ((x << 2) & 0xF)] =
651 memset(
pps->dequant8_coeff, 0,
sizeof(
pps->dequant8_coeff));
653 if (
pps->transform_8x8_mode)
655 if (
sps->transform_bypass) {
656 for (
i = 0;
i < 6;
i++)
657 for (x = 0; x < 16; x++)
658 pps->dequant4_coeff[
i][0][x] = 1 << 6;
659 if (
pps->transform_8x8_mode)
660 for (
i = 0;
i < 6;
i++)
661 for (x = 0; x < 64; x++)
662 pps->dequant8_coeff[
i][0][x] = 1 << 6;
669 const int max_qp = 51 + 6 * (depth - 8);
670 for (
i = 0;
i < max_qp + 1;
i++)
671 pps->chroma_qp_table[t][
i] =
682 "Current profile doesn't provide more RBSP data in PPS, skipping\n");
716 if (
pps->data_size >
sizeof(
pps->data)) {
719 pps->data_size,
sizeof(
pps->data));
720 pps->data_size =
sizeof(
pps->data);
725 if (!(bit_length & 7) &&
pps->data_size <
sizeof(
pps->data))
726 pps->data[
pps->data_size++] = 0x80;
728 pps->pps_id = pps_id;
739 if (
sps->bit_depth_luma > 14) {
741 "Invalid luma bit depth=%d\n",
742 sps->bit_depth_luma);
745 }
else if (
sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13) {
747 "Unimplemented luma bit depth=%d",
748 sps->bit_depth_luma);
756 if (
pps->slice_group_count > 1) {
764 if (
pps->ref_count[0] - 1 > 32 - 1 ||
pps->ref_count[1] - 1 > 32 - 1) {
770 qp_bd_offset = 6 * (
sps->bit_depth_luma - 8);
777 if (
pps->chroma_qp_index_offset[0] < -12 ||
pps->chroma_qp_index_offset[0] > 12) {
782 pps->deblocking_filter_parameters_present =
get_bits1(gb);
786 pps->transform_8x8_mode = 0;
787 memcpy(
pps->scaling_matrix4,
sps->scaling_matrix4,
788 sizeof(
pps->scaling_matrix4));
789 memcpy(
pps->scaling_matrix8,
sps->scaling_matrix8,
790 sizeof(
pps->scaling_matrix8));
797 pps->pic_scaling_matrix_present_flag,
798 &
pps->pic_scaling_matrix_present_mask,
799 pps->scaling_matrix4,
pps->scaling_matrix8);
804 if (
pps->chroma_qp_index_offset[1] < -12 ||
pps->chroma_qp_index_offset[1] > 12) {
809 pps->chroma_qp_index_offset[1] =
pps->chroma_qp_index_offset[0];
813 sps->bit_depth_luma);
815 sps->bit_depth_luma);
819 if (
pps->chroma_qp_index_offset[0] !=
pps->chroma_qp_index_offset[1])
820 pps->chroma_qp_diff = 1;
824 "pps:%u sps:%u %s slice_groups:%d ref:%u/%u %s qp:%d/%d/%d/%d %s %s %s %s\n",
826 pps->cabac ?
"CABAC" :
"CAVLC",
827 pps->slice_group_count,
828 pps->ref_count[0],
pps->ref_count[1],
829 pps->weighted_pred ?
"weighted" :
"",
830 pps->init_qp,
pps->init_qs,
pps->chroma_qp_index_offset[0],
pps->chroma_qp_index_offset[1],
831 pps->deblocking_filter_parameters_present ?
"LPAR" :
"",
832 pps->constrained_intra_pred ?
"CONSTR" :
"",
833 pps->redundant_pic_cnt_present ?
"REDU" :
"",
834 pps->transform_8x8_mode ?
"8x8DCT" :
"");