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) {
195 if (
sps->timing_info_present_flag) {
198 if (!num_units_in_tick || !time_scale) {
200 "time_scale/num_units_in_tick invalid or unsupported (%u/%u)\n",
201 time_scale, num_units_in_tick);
202 sps->timing_info_present_flag = 0;
204 sps->num_units_in_tick = num_units_in_tick;
205 sps->time_scale = time_scale;
211 if (
sps->nal_hrd_parameters_present_flag)
215 if (
sps->vcl_hrd_parameters_present_flag)
218 if (
sps->nal_hrd_parameters_present_flag ||
219 sps->vcl_hrd_parameters_present_flag)
225 if (
sps->bitstream_restriction_flag) {
235 sps->num_reorder_frames = 0;
236 sps->bitstream_restriction_flag = 0;
239 if (
sps->num_reorder_frames > 16
U
242 "Clipping illegal num_reorder_frames %d\n",
243 sps->num_reorder_frames);
244 sps->num_reorder_frames = 16;
256 int i, last = 8, next = 8;
259 memcpy(factors, fallback_list,
size *
sizeof(
uint8_t));
264 if (v < -128 || v > 127) {
268 next = (last + v) & 0xff;
274 last = factors[scan[
i]] = next ? next : last;
281 const PPS *
pps,
int is_sps,
285 int fallback_sps = !is_sps &&
sps->scaling_matrix_present;
300 if (is_sps ||
pps->transform_8x8_mode) {
303 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) {
584 "Overread %s by %d bits\n",
sps->vui_parameters_present_flag ?
"VUI" :
"SPS", -
get_bits_left(gb));
585 if (!ignore_truncation)
591 if (!
sps->bitstream_restriction_flag &&
597 sps->num_reorder_frames);
607 static const char csp[4][5] = {
"Gray",
"420",
"422",
"444" };
609 "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",
610 sps_id,
sps->profile_idc,
sps->level_idc,
612 sps->ref_frame_count,
613 sps->mb_width,
sps->mb_height,
614 sps->frame_mbs_only_flag ?
"FRM" : (
sps->mb_aff ?
"MB-AFF" :
"PIC-AFF"),
615 sps->direct_8x8_inference_flag ?
"8B8" :
"",
616 sps->crop_left,
sps->crop_right,
617 sps->crop_top,
sps->crop_bottom,
618 sps->vui_parameters_present_flag ?
"VUI" :
"",
619 csp[
sps->chroma_format_idc],
620 sps->timing_info_present_flag ?
sps->num_units_in_tick : 0,
621 sps->timing_info_present_flag ?
sps->time_scale : 0,
623 sps->bitstream_restriction_flag ?
sps->num_reorder_frames : -1
648 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
650 for (
i = 0;
i < 6;
i++) {
651 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[
i];
652 for (j = 0; j <
i; j++)
653 if (!memcmp(
pps->scaling_matrix8[j],
pps->scaling_matrix8[
i],
655 pps->dequant8_coeff[
i] =
pps->dequant8_buffer[j];
661 for (q = 0; q < max_qp + 1; q++) {
664 for (x = 0; x < 64; x++)
665 pps->dequant8_coeff[
i][q][(x >> 3) | ((x & 7) << 3)] =
675 const int max_qp = 51 + 6 * (
sps->bit_depth_luma - 8);
676 for (
i = 0;
i < 6;
i++) {
677 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[
i];
678 for (j = 0; j <
i; j++)
679 if (!memcmp(
pps->scaling_matrix4[j],
pps->scaling_matrix4[
i],
681 pps->dequant4_coeff[
i] =
pps->dequant4_buffer[j];
687 for (q = 0; q < max_qp + 1; q++) {
690 for (x = 0; x < 16; x++)
691 pps->dequant4_coeff[
i][q][(x >> 2) | ((x << 2) & 0xF)] =
702 memset(
pps->dequant8_coeff, 0,
sizeof(
pps->dequant8_coeff));
704 if (
pps->transform_8x8_mode)
706 if (
sps->transform_bypass) {
707 for (
i = 0;
i < 6;
i++)
708 for (x = 0; x < 16; x++)
709 pps->dequant4_coeff[
i][0][x] = 1 << 6;
710 if (
pps->transform_8x8_mode)
711 for (
i = 0;
i < 6;
i++)
712 for (x = 0; x < 64; x++)
713 pps->dequant8_coeff[
i][0][x] = 1 << 6;
720 const int max_qp = 51 + 6 * (depth - 8);
721 for (
i = 0;
i < max_qp + 1;
i++)
722 pps->chroma_qp_table[t][
i] =
733 "Current profile doesn't provide more RBSP data in PPS, skipping\n");
776 if (
pps->data_size >
sizeof(
pps->data)) {
779 pps->data_size,
sizeof(
pps->data));
780 pps->data_size =
sizeof(
pps->data);
796 pps->sps = (
const SPS*)
pps->sps_ref->data;
799 if (
sps->bit_depth_luma > 14) {
801 "Invalid luma bit depth=%d\n",
802 sps->bit_depth_luma);
805 }
else if (
sps->bit_depth_luma == 11 ||
sps->bit_depth_luma == 13) {
807 "Unimplemented luma bit depth=%d",
808 sps->bit_depth_luma);
816 if (
pps->slice_group_count > 1) {
824 if (
pps->ref_count[0] - 1 > 32 - 1 ||
pps->ref_count[1] - 1 > 32 - 1) {
830 qp_bd_offset = 6 * (
sps->bit_depth_luma - 8);
837 if (
pps->chroma_qp_index_offset[0] < -12 ||
pps->chroma_qp_index_offset[0] > 12) {
842 pps->deblocking_filter_parameters_present =
get_bits1(gb);
846 pps->transform_8x8_mode = 0;
847 memcpy(
pps->scaling_matrix4,
sps->scaling_matrix4,
848 sizeof(
pps->scaling_matrix4));
849 memcpy(
pps->scaling_matrix8,
sps->scaling_matrix8,
850 sizeof(
pps->scaling_matrix8));
856 pps->scaling_matrix4,
pps->scaling_matrix8);
861 if (
pps->chroma_qp_index_offset[1] < -12 ||
pps->chroma_qp_index_offset[1] > 12) {
866 pps->chroma_qp_index_offset[1] =
pps->chroma_qp_index_offset[0];
870 sps->bit_depth_luma);
872 sps->bit_depth_luma);
876 if (
pps->chroma_qp_index_offset[0] !=
pps->chroma_qp_index_offset[1])
877 pps->chroma_qp_diff = 1;
881 "pps:%u sps:%u %s slice_groups:%d ref:%u/%u %s qp:%d/%d/%d/%d %s %s %s %s\n",
883 pps->cabac ?
"CABAC" :
"CAVLC",
884 pps->slice_group_count,
885 pps->ref_count[0],
pps->ref_count[1],
886 pps->weighted_pred ?
"weighted" :
"",
887 pps->init_qp,
pps->init_qs,
pps->chroma_qp_index_offset[0],
pps->chroma_qp_index_offset[1],
888 pps->deblocking_filter_parameters_present ?
"LPAR" :
"",
889 pps->constrained_intra_pred ?
"CONSTR" :
"",
890 pps->redundant_pic_cnt_present ?
"REDU" :
"",
891 pps->transform_8x8_mode ?
"8x8DCT" :
"");