38 #define MIN_LOG2_MAX_FRAME_NUM 4
40 #define EXTENDED_SAR 255
43 { 6, 13, 20, 28, 13, 20, 28, 32,
44 20, 28, 32, 37, 28, 32, 37, 42 },
45 { 10, 14, 20, 24, 14, 20, 24, 27,
46 20, 24, 27, 30, 24, 27, 30, 34 }
50 { 6, 10, 13, 16, 18, 23, 25, 27,
51 10, 11, 16, 18, 23, 25, 27, 29,
52 13, 16, 18, 23, 25, 27, 29, 31,
53 16, 18, 23, 25, 27, 29, 31, 33,
54 18, 23, 25, 27, 29, 31, 33, 36,
55 23, 25, 27, 29, 31, 33, 36, 38,
56 25, 27, 29, 31, 33, 36, 38, 40,
57 27, 29, 31, 33, 36, 38, 40, 42 },
58 { 9, 13, 15, 17, 19, 21, 22, 24,
59 13, 13, 17, 19, 21, 22, 24, 25,
60 15, 17, 19, 21, 22, 24, 25, 27,
61 17, 19, 21, 22, 24, 25, 27, 28,
62 19, 21, 22, 24, 25, 27, 28, 30,
63 21, 22, 24, 25, 27, 28, 30, 32,
64 22, 24, 25, 27, 28, 30, 32, 33,
65 24, 25, 27, 28, 30, 32, 33, 35 }
97 if (
s->sps_list[
id]) {
100 if (
s->pps_list[
i] && ((
PPS*)
s->pps_list[
i]->data)->sps_id ==
id)
113 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;
136 int aspect_ratio_info_present_flag;
137 unsigned int aspect_ratio_idc;
139 aspect_ratio_info_present_flag =
get_bits1(gb);
141 if (aspect_ratio_info_present_flag) {
161 if (
sps->video_signal_type_present_flag) {
166 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;
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;
273 last = factors[scan[
i]] = next ? next : last;
280 const PPS *
pps,
int is_sps,
284 int fallback_sps = !is_sps &&
sps->scaling_matrix_present;
299 if (is_sps ||
pps->transform_8x8_mode) {
302 if (
sps->chroma_format_idc == 3) {
339 int i, log2_max_frame_num_minus4;
349 if (
sps->data_size >
sizeof(
sps->data)) {
351 sps->data_size =
sizeof(
sps->data);
356 constraint_set_flags |=
get_bits1(gb) << 0;
357 constraint_set_flags |=
get_bits1(gb) << 1;
358 constraint_set_flags |=
get_bits1(gb) << 2;
359 constraint_set_flags |=
get_bits1(gb) << 3;
360 constraint_set_flags |=
get_bits1(gb) << 4;
361 constraint_set_flags |=
get_bits1(gb) << 5;
371 sps->sps_id = sps_id;
372 sps->time_offset_length = 24;
374 sps->constraint_set_flags = constraint_set_flags;
376 sps->full_range = -1;
378 memset(
sps->scaling_matrix4, 16,
sizeof(
sps->scaling_matrix4));
379 memset(
sps->scaling_matrix8, 16,
sizeof(
sps->scaling_matrix8));
380 sps->scaling_matrix_present = 0;
383 if (
sps->profile_idc == 100 ||
384 sps->profile_idc == 110 ||
385 sps->profile_idc == 122 ||
386 sps->profile_idc == 244 ||
387 sps->profile_idc == 44 ||
388 sps->profile_idc == 83 ||
389 sps->profile_idc == 86 ||
390 sps->profile_idc == 118 ||
391 sps->profile_idc == 128 ||
392 sps->profile_idc == 138 ||
393 sps->profile_idc == 144) {
395 if (
sps->chroma_format_idc > 3
U) {
397 sps->chroma_format_idc);
399 }
else if (
sps->chroma_format_idc == 3) {
401 if (
sps->residual_color_transform_flag) {
408 if (
sps->bit_depth_chroma !=
sps->bit_depth_luma) {
410 "Different chroma and luma bit depth");
413 if (
sps->bit_depth_luma < 8 ||
sps->bit_depth_luma > 14 ||
414 sps->bit_depth_chroma < 8 ||
sps->bit_depth_chroma > 14) {
416 sps->bit_depth_luma,
sps->bit_depth_chroma);
421 sps->scaling_matrix4,
sps->scaling_matrix8);
424 sps->scaling_matrix_present |=
ret;
426 sps->chroma_format_idc = 1;
427 sps->bit_depth_luma = 8;
428 sps->bit_depth_chroma = 8;
435 "log2_max_frame_num_minus4 out of range (0-12): %d\n",
436 log2_max_frame_num_minus4);
439 sps->log2_max_frame_num = log2_max_frame_num_minus4 + 4;
443 if (
sps->poc_type == 0) {
449 sps->log2_max_poc_lsb = t + 4;
450 }
else if (
sps->poc_type == 1) {
455 if (
sps->offset_for_non_ref_pic == INT32_MIN
456 ||
sps->offset_for_top_to_bottom_field == INT32_MIN
459 "offset_for_non_ref_pic or offset_for_top_to_bottom_field is out of range\n");
465 if ((
unsigned)
sps->poc_cycle_length >=
468 "poc_cycle_length overflow %d\n",
sps->poc_cycle_length);
472 for (
i = 0;
i <
sps->poc_cycle_length;
i++) {
474 if (
sps->offset_for_ref_frame[
i] == INT32_MIN) {
476 "offset_for_ref_frame is out of range\n");
480 }
else if (
sps->poc_type != 2) {
487 sps->ref_frame_count =
FFMAX(2,
sps->ref_frame_count);
490 "too many reference frames %d\n",
sps->ref_frame_count);
499 if (
sps->mb_height >= INT_MAX / 2
U) {
503 sps->mb_height *= 2 -
sps->frame_mbs_only_flag;
505 if (!
sps->frame_mbs_only_flag)
510 if ((
unsigned)
sps->mb_width >= INT_MAX / 16 ||
511 (
unsigned)
sps->mb_height >= INT_MAX / 16 ||
513 16 *
sps->mb_height, 0, avctx)) {
520 #ifndef ALLOW_INTERLACE
523 "MBAFF support not included; enable it at compile-time.\n");
536 "values are l:%d r:%d t:%d b:%d\n",
537 crop_left, crop_right, crop_top, crop_bottom);
542 sps->crop_bottom = 0;
544 int vsub = (
sps->chroma_format_idc == 1) ? 1 : 0;
545 int hsub = (
sps->chroma_format_idc == 1 ||
546 sps->chroma_format_idc == 2) ? 1 : 0;
547 int step_x = 1 << hsub;
548 int step_y = (2 -
sps->frame_mbs_only_flag) << vsub;
550 if (crop_left > (
unsigned)INT_MAX / 4 / step_x ||
551 crop_right > (unsigned)INT_MAX / 4 / step_x ||
552 crop_top > (
unsigned)INT_MAX / 4 / step_y ||
553 crop_bottom> (unsigned)INT_MAX / 4 / step_y ||
554 (crop_left + crop_right ) * step_x >=
width ||
555 (crop_top + crop_bottom) * step_y >=
height
561 sps->crop_left = crop_left * step_x;
562 sps->crop_right = crop_right * step_x;
563 sps->crop_top = crop_top * step_y;
564 sps->crop_bottom = crop_bottom * step_y;
575 if (
sps->vui_parameters_present_flag) {
583 "Overread %s by %d bits\n",
sps->vui_parameters_present_flag ?
"VUI" :
"SPS", -
get_bits_left(gb));
584 if (!ignore_truncation)
590 if (!
sps->bitstream_restriction_flag &&
596 sps->num_reorder_frames);
606 static const char csp[4][5] = {
"Gray",
"420",
"422",
"444" };
608 "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",
609 sps_id,
sps->profile_idc,
sps->level_idc,
611 sps->ref_frame_count,
612 sps->mb_width,
sps->mb_height,
613 sps->frame_mbs_only_flag ?
"FRM" : (
sps->mb_aff ?
"MB-AFF" :
"PIC-AFF"),
614 sps->direct_8x8_inference_flag ?
"8B8" :
"",
615 sps->crop_left,
sps->crop_right,
616 sps->crop_top,
sps->crop_bottom,
617 sps->vui_parameters_present_flag ?
"VUI" :
"",
618 csp[
sps->chroma_format_idc],
619 sps->timing_info_present_flag ?
sps->num_units_in_tick : 0,
620 sps->timing_info_present_flag ?
sps->time_scale : 0,
622 sps->bitstream_restriction_flag ?
sps->num_reorder_frames : -1
647 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
649 for (
i = 0;
i < 6;
i++) {
650 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[
i];
651 for (j = 0; j <
i; j++)
652 if (!memcmp(
pps->scaling_matrix8[j],
pps->scaling_matrix8[
i],
654 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[j];
660 for (q = 0; q < max_qp + 1; q++) {
663 for (x = 0; x < 64; x++)
664 pps->dequant8_coeff[
i][q][(x >> 3) | ((x & 7) << 3)] =
674 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
675 for (
i = 0;
i < 6;
i++) {
676 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[
i];
677 for (j = 0; j <
i; j++)
678 if (!memcmp(
pps->scaling_matrix4[j],
pps->scaling_matrix4[
i],
680 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[j];
686 for (q = 0; q < max_qp + 1; q++) {
689 for (x = 0; x < 16; x++)
690 pps->dequant4_coeff[
i][q][(x >> 2) | ((x << 2) & 0xF)] =
701 memset(
pps->dequant8_coeff, 0,
sizeof(
pps->dequant8_coeff));
703 if (
pps->transform_8x8_mode)
705 if (
sps->transform_bypass) {
706 for (
i = 0;
i < 6;
i++)
707 for (x = 0; x < 16; x++)
708 pps->dequant4_coeff[
i][0][x] = 1 << 6;
709 if (
pps->transform_8x8_mode)
710 for (
i = 0;
i < 6;
i++)
711 for (x = 0; x < 64; x++)
712 pps->dequant8_coeff[
i][0][x] = 1 << 6;
719 const int max_qp = 51 + 6 * (depth - 8);
720 for (
i = 0;
i < max_qp + 1;
i++)
721 pps->chroma_qp_table[t][
i] =
732 "Current profile doesn't provide more RBSP data in PPS, skipping\n");
761 if (
pps->data_size >
sizeof(
pps->data)) {
764 pps->data_size,
sizeof(
pps->data));
765 pps->data_size =
sizeof(
pps->data);
777 if (
sps->bit_depth_luma > 14) {
779 "Invalid luma bit depth=%d\n",
780 sps->bit_depth_luma);
783 }
else if (
sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13) {
785 "Unimplemented luma bit depth=%d",
786 sps->bit_depth_luma);
794 if (
pps->slice_group_count > 1) {
800 if (
pps->ref_count[0] - 1 > 32 - 1 ||
pps->ref_count[1] - 1 > 32 - 1) {
806 qp_bd_offset = 6 * (
sps->bit_depth_luma - 8);
813 if (
pps->chroma_qp_index_offset[0] < -12 ||
pps->chroma_qp_index_offset[0] > 12) {
818 pps->deblocking_filter_parameters_present =
get_bits1(gb);
822 pps->transform_8x8_mode = 0;
823 memcpy(
pps->scaling_matrix4,
sps->scaling_matrix4,
824 sizeof(
pps->scaling_matrix4));
825 memcpy(
pps->scaling_matrix8,
sps->scaling_matrix8,
826 sizeof(
pps->scaling_matrix8));
832 pps->scaling_matrix4,
pps->scaling_matrix8);
837 if (
pps->chroma_qp_index_offset[1] < -12 ||
pps->chroma_qp_index_offset[1] > 12) {
842 pps->chroma_qp_index_offset[1] =
pps->chroma_qp_index_offset[0];
846 sps->bit_depth_luma);
848 sps->bit_depth_luma);
852 if (
pps->chroma_qp_index_offset[0] !=
pps->chroma_qp_index_offset[1])
853 pps->chroma_qp_diff = 1;
857 "pps:%u sps:%u %s slice_groups:%d ref:%u/%u %s qp:%d/%d/%d/%d %s %s %s %s\n",
859 pps->cabac ?
"CABAC" :
"CAVLC",
860 pps->slice_group_count,
861 pps->ref_count[0],
pps->ref_count[1],
862 pps->weighted_pred ?
"weighted" :
"",
863 pps->init_qp,
pps->init_qs,
pps->chroma_qp_index_offset[0],
pps->chroma_qp_index_offset[1],
864 pps->deblocking_filter_parameters_present ?
"LPAR" :
"",
865 pps->constrained_intra_pred ?
"CONSTR" :
"",
866 pps->redundant_pic_cnt_present ?
"REDU" :
"",
867 pps->transform_8x8_mode ?
"8x8DCT" :
"");