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) {
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;
143 if (
sps->timing_info_present_flag) {
146 if (!num_units_in_tick || !time_scale) {
148 "time_scale/num_units_in_tick invalid or unsupported (%u/%u)\n",
149 time_scale, num_units_in_tick);
150 sps->timing_info_present_flag = 0;
152 sps->num_units_in_tick = num_units_in_tick;
153 sps->time_scale = time_scale;
159 if (
sps->nal_hrd_parameters_present_flag)
163 if (
sps->vcl_hrd_parameters_present_flag)
166 if (
sps->nal_hrd_parameters_present_flag ||
167 sps->vcl_hrd_parameters_present_flag)
173 if (
sps->bitstream_restriction_flag) {
183 sps->num_reorder_frames = 0;
184 sps->bitstream_restriction_flag = 0;
187 if (
sps->num_reorder_frames > 16
U
190 "Clipping illegal num_reorder_frames %d\n",
191 sps->num_reorder_frames);
192 sps->num_reorder_frames = 16;
201 const uint8_t *jvt_list,
const uint8_t *fallback_list,
204 int i, last = 8, next = 8;
206 uint16_t seq_scaling_list_present_flag =
get_bits1(gb);
207 *
mask |= (seq_scaling_list_present_flag <<
pos);
208 if (!seq_scaling_list_present_flag)
209 memcpy(factors, fallback_list,
size *
sizeof(uint8_t));
214 if (v < -128 || v > 127) {
218 next = (last + v) & 0xff;
221 memcpy(factors, jvt_list,
size *
sizeof(uint8_t));
224 last = factors[scan[
i]] = next ? next : last;
231 const PPS *
pps,
int is_sps,
232 int present_flag, uint16_t *
mask,
233 uint8_t(*scaling_matrix4)[16],
234 uint8_t(*scaling_matrix8)[64])
236 int fallback_sps = !is_sps &&
sps->scaling_matrix_present;
237 const uint8_t *fallback[4] = {
252 if (is_sps ||
pps->transform_8x8_mode) {
255 if (
sps->chroma_format_idc == 3) {
291 int i, log2_max_frame_num_minus4;
301 if (
sps->data_size >
sizeof(
sps->data)) {
303 sps->data_size =
sizeof(
sps->data);
309 sps->data[
sps->data_size++] = 0x80;
312 constraint_set_flags |=
get_bits1(gb) << 0;
313 constraint_set_flags |=
get_bits1(gb) << 1;
314 constraint_set_flags |=
get_bits1(gb) << 2;
315 constraint_set_flags |=
get_bits1(gb) << 3;
316 constraint_set_flags |=
get_bits1(gb) << 4;
317 constraint_set_flags |=
get_bits1(gb) << 5;
327 sps->sps_id = sps_id;
328 sps->time_offset_length = 24;
330 sps->constraint_set_flags = constraint_set_flags;
332 sps->vui.video_full_range_flag = -1;
334 memset(
sps->scaling_matrix4, 16,
sizeof(
sps->scaling_matrix4));
335 memset(
sps->scaling_matrix8, 16,
sizeof(
sps->scaling_matrix8));
336 sps->scaling_matrix_present = 0;
339 if (
sps->profile_idc == 100 ||
340 sps->profile_idc == 110 ||
341 sps->profile_idc == 122 ||
342 sps->profile_idc == 244 ||
343 sps->profile_idc == 44 ||
344 sps->profile_idc == 83 ||
345 sps->profile_idc == 86 ||
346 sps->profile_idc == 118 ||
347 sps->profile_idc == 128 ||
348 sps->profile_idc == 138 ||
349 sps->profile_idc == 144) {
351 if (
sps->chroma_format_idc > 3
U) {
353 sps->chroma_format_idc);
355 }
else if (
sps->chroma_format_idc == 3) {
357 if (
sps->residual_color_transform_flag) {
364 if (
sps->bit_depth_chroma !=
sps->bit_depth_luma) {
366 "Different chroma and luma bit depth");
369 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
370 sps->bit_depth_chroma < 8 ||
sps->bit_depth_chroma > 14) {
372 sps->bit_depth_luma,
sps->bit_depth_chroma);
377 &
sps->scaling_matrix_present_mask,
378 sps->scaling_matrix4,
sps->scaling_matrix8);
381 sps->scaling_matrix_present |=
ret;
383 sps->chroma_format_idc = 1;
384 sps->bit_depth_luma = 8;
385 sps->bit_depth_chroma = 8;
392 "log2_max_frame_num_minus4 out of range (0-12): %d\n",
393 log2_max_frame_num_minus4);
396 sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4;
400 if (
sps->poc_type == 0) {
406 sps->log2_max_poc_lsb = t + 4;
407 }
else if (
sps->poc_type == 1) {
412 if (
sps->offset_for_non_ref_pic == INT32_MIN
413 ||
sps->offset_for_top_to_bottom_field == INT32_MIN
416 "offset_for_non_ref_pic or offset_for_top_to_bottom_field is out of range\n");
422 if ((
unsigned)
sps->poc_cycle_length >=
425 "poc_cycle_length overflow %d\n",
sps->poc_cycle_length);
429 for (
i = 0;
i <
sps->poc_cycle_length;
i++) {
431 if (
sps->offset_for_ref_frame[
i] == INT32_MIN) {
433 "offset_for_ref_frame is out of range\n");
437 }
else if (
sps->poc_type != 2) {
444 sps->ref_frame_count =
FFMAX(2,
sps->ref_frame_count);
447 "too many reference frames %d\n",
sps->ref_frame_count);
456 if (
sps->mb_height >= INT_MAX / 2
U) {
460 sps->mb_height *= 2 -
sps->frame_mbs_only_flag;
462 if (!
sps->frame_mbs_only_flag)
467 if ((
unsigned)
sps->mb_width >= INT_MAX / 16 ||
468 (
unsigned)
sps->mb_height >= INT_MAX / 16 ||
470 16 *
sps->mb_height, 0, avctx)) {
488 "values are l:%d r:%d t:%d b:%d\n",
489 crop_left, crop_right, crop_top, crop_bottom);
494 sps->crop_bottom = 0;
496 int vsub = (
sps->chroma_format_idc == 1) ? 1 : 0;
497 int hsub = (
sps->chroma_format_idc == 1 ||
498 sps->chroma_format_idc == 2) ? 1 : 0;
499 int step_x = 1 <<
hsub;
500 int step_y = (2 -
sps->frame_mbs_only_flag) << vsub;
502 if (crop_left > (
unsigned)INT_MAX / 4 / step_x ||
503 crop_right > (unsigned)INT_MAX / 4 / step_x ||
504 crop_top > (
unsigned)INT_MAX / 4 / step_y ||
505 crop_bottom> (unsigned)INT_MAX / 4 / step_y ||
506 (crop_left + crop_right ) * step_x >=
width ||
507 (crop_top + crop_bottom) * step_y >=
height
513 sps->crop_left = crop_left * step_x;
514 sps->crop_right = crop_right * step_x;
515 sps->crop_top = crop_top * step_y;
516 sps->crop_bottom = crop_bottom * step_y;
527 if (
sps->vui_parameters_present_flag) {
536 "Overread %s by %d bits\n",
sps->vui_parameters_present_flag ?
"VUI" :
"SPS", -
get_bits_left(gb));
537 if (!ignore_truncation)
543 if (!
sps->bitstream_restriction_flag &&
549 sps->num_reorder_frames);
555 if (!
sps->vui.sar.den)
556 sps->vui.sar.den = 1;
559 static const char csp[4][5] = {
"Gray",
"420",
"422",
"444" };
561 "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",
562 sps_id,
sps->profile_idc,
sps->level_idc,
564 sps->ref_frame_count,
565 sps->mb_width,
sps->mb_height,
566 sps->frame_mbs_only_flag ?
"FRM" : (
sps->mb_aff ?
"MB-AFF" :
"PIC-AFF"),
567 sps->direct_8x8_inference_flag ?
"8B8" :
"",
568 sps->crop_left,
sps->crop_right,
569 sps->crop_top,
sps->crop_bottom,
570 sps->vui_parameters_present_flag ?
"VUI" :
"",
571 csp[
sps->chroma_format_idc],
572 sps->timing_info_present_flag ?
sps->num_units_in_tick : 0,
573 sps->timing_info_present_flag ?
sps->time_scale : 0,
575 sps->bitstream_restriction_flag ?
sps->num_reorder_frames : -1
600 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
602 for (
i = 0;
i < 6;
i++) {
603 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[
i];
604 for (j = 0; j <
i; j++)
605 if (!memcmp(
pps->scaling_matrix8[j],
pps->scaling_matrix8[
i],
606 64 *
sizeof(uint8_t))) {
607 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[j];
613 for (q = 0; q < max_qp + 1; q++) {
616 for (x = 0; x < 64; x++)
617 pps->dequant8_coeff[
i][q][(x >> 3) | ((x & 7) << 3)] =
627 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
628 for (
i = 0;
i < 6;
i++) {
629 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[
i];
630 for (j = 0; j <
i; j++)
631 if (!memcmp(
pps->scaling_matrix4[j],
pps->scaling_matrix4[
i],
632 16 *
sizeof(uint8_t))) {
633 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[j];
639 for (q = 0; q < max_qp + 1; q++) {
642 for (x = 0; x < 16; x++)
643 pps->dequant4_coeff[
i][q][(x >> 2) | ((x << 2) & 0xF)] =
654 memset(
pps->dequant8_coeff, 0,
sizeof(
pps->dequant8_coeff));
656 if (
pps->transform_8x8_mode)
658 if (
sps->transform_bypass) {
659 for (
i = 0;
i < 6;
i++)
660 for (x = 0; x < 16; x++)
661 pps->dequant4_coeff[
i][0][x] = 1 << 6;
662 if (
pps->transform_8x8_mode)
663 for (
i = 0;
i < 6;
i++)
664 for (x = 0; x < 64; x++)
665 pps->dequant8_coeff[
i][0][x] = 1 << 6;
672 const int max_qp = 51 + 6 * (depth - 8);
673 for (
i = 0;
i < max_qp + 1;
i++)
674 pps->chroma_qp_table[t][
i] =
685 "Current profile doesn't provide more RBSP data in PPS, skipping\n");
728 if (
pps->data_size >
sizeof(
pps->data)) {
731 pps->data_size,
sizeof(
pps->data));
732 pps->data_size =
sizeof(
pps->data);
737 if (!(bit_length & 7) &&
pps->data_size <
sizeof(
pps->data))
738 pps->data[
pps->data_size++] = 0x80;
740 pps->pps_id = pps_id;
753 pps->sps = (
const SPS*)
pps->sps_ref->data;
756 if (
sps->bit_depth_luma > 14) {
758 "Invalid luma bit depth=%d\n",
759 sps->bit_depth_luma);
762 }
else if (
sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13) {
764 "Unimplemented luma bit depth=%d",
765 sps->bit_depth_luma);
773 if (
pps->slice_group_count > 1) {
781 if (
pps->ref_count[0] - 1 > 32 - 1 ||
pps->ref_count[1] - 1 > 32 - 1) {
787 qp_bd_offset = 6 * (
sps->bit_depth_luma - 8);
794 if (
pps->chroma_qp_index_offset[0] < -12 ||
pps->chroma_qp_index_offset[0] > 12) {
799 pps->deblocking_filter_parameters_present =
get_bits1(gb);
803 pps->transform_8x8_mode = 0;
804 memcpy(
pps->scaling_matrix4,
sps->scaling_matrix4,
805 sizeof(
pps->scaling_matrix4));
806 memcpy(
pps->scaling_matrix8,
sps->scaling_matrix8,
807 sizeof(
pps->scaling_matrix8));
814 pps->pic_scaling_matrix_present_flag,
815 &
pps->pic_scaling_matrix_present_mask,
816 pps->scaling_matrix4,
pps->scaling_matrix8);
821 if (
pps->chroma_qp_index_offset[1] < -12 ||
pps->chroma_qp_index_offset[1] > 12) {
826 pps->chroma_qp_index_offset[1] =
pps->chroma_qp_index_offset[0];
830 sps->bit_depth_luma);
832 sps->bit_depth_luma);
836 if (
pps->chroma_qp_index_offset[0] !=
pps->chroma_qp_index_offset[1])
837 pps->chroma_qp_diff = 1;
841 "pps:%u sps:%u %s slice_groups:%d ref:%u/%u %s qp:%d/%d/%d/%d %s %s %s %s\n",
843 pps->cabac ?
"CABAC" :
"CAVLC",
844 pps->slice_group_count,
845 pps->ref_count[0],
pps->ref_count[1],
846 pps->weighted_pred ?
"weighted" :
"",
847 pps->init_qp,
pps->init_qs,
pps->chroma_qp_index_offset[0],
pps->chroma_qp_index_offset[1],
848 pps->deblocking_filter_parameters_present ?
"LPAR" :
"",
849 pps->constrained_intra_pred ?
"CONSTR" :
"",
850 pps->redundant_pic_cnt_present ?
"REDU" :
"",
851 pps->transform_8x8_mode ?
"8x8DCT" :
"");