23 fixed(1, rbsp_stop_one_bit, 1);
25 fixed(1, rbsp_alignment_zero_bit, 0);
32 int expected_nal_unit_type)
36 fixed(1, forbidden_zero_bit, 0);
38 if (expected_nal_unit_type >= 0)
39 u(6, nal_unit_type, expected_nal_unit_type,
40 expected_nal_unit_type);
44 u(6, nuh_layer_id, 0, 62);
45 u(3, nuh_temporal_id_plus1, 1, 7);
54 fixed(1, alignment_bit_equal_to_one, 1);
56 fixed(1, alignment_bit_equal_to_zero, 0);
72 current->bit_length = k;
75 allocate(current->data, (current->bit_length + 7) / 8);
76 for (k = 0; k < current->bit_length; k++) {
78 current->data[k / 8] |=
bit << (7 - k % 8);
82 for (k = 0; k < current->bit_length; k++)
90 int profile_present_flag,
91 int max_num_sub_layers_minus1)
95 if (profile_present_flag) {
96 u(2, general_profile_space, 0, 0);
97 flag(general_tier_flag);
98 ub(5, general_profile_idc);
100 for (j = 0; j < 32; j++)
101 flags(general_profile_compatibility_flag[j], 1, j);
103 flag(general_progressive_source_flag);
104 flag(general_interlaced_source_flag);
105 flag(general_non_packed_constraint_flag);
106 flag(general_frame_only_constraint_flag);
108 #define profile_compatible(x) (current->general_profile_idc == (x) || \
109 current->general_profile_compatibility_flag[x])
114 flag(general_max_12bit_constraint_flag);
115 flag(general_max_10bit_constraint_flag);
116 flag(general_max_8bit_constraint_flag);
117 flag(general_max_422chroma_constraint_flag);
118 flag(general_max_420chroma_constraint_flag);
119 flag(general_max_monochrome_constraint_flag);
120 flag(general_intra_constraint_flag);
121 flag(general_one_picture_only_constraint_flag);
122 flag(general_lower_bit_rate_constraint_flag);
126 flag(general_max_14bit_constraint_flag);
127 fixed(24, general_reserved_zero_33bits, 0);
128 fixed( 9, general_reserved_zero_33bits, 0);
130 fixed(24, general_reserved_zero_34bits, 0);
131 fixed(10, general_reserved_zero_34bits, 0);
134 fixed(7, general_reserved_zero_7bits, 0);
135 flag(general_one_picture_only_constraint_flag);
136 fixed(24, general_reserved_zero_35bits, 0);
137 fixed(11, general_reserved_zero_35bits, 0);
139 fixed(24, general_reserved_zero_43bits, 0);
140 fixed(19, general_reserved_zero_43bits, 0);
146 flag(general_inbld_flag);
148 fixed(1, general_reserved_zero_bit, 0);
150 #undef profile_compatible
153 ub(8, general_level_idc);
155 for (
i = 0;
i < max_num_sub_layers_minus1;
i++) {
156 flags(sub_layer_profile_present_flag[
i], 1,
i);
157 flags(sub_layer_level_present_flag[
i], 1,
i);
160 if (max_num_sub_layers_minus1 > 0) {
161 for (
i = max_num_sub_layers_minus1;
i < 8;
i++)
162 fixed(2, reserved_zero_2bits, 0);
165 for (
i = 0;
i < max_num_sub_layers_minus1;
i++) {
166 if (current->sub_layer_profile_present_flag[
i]) {
167 us(2, sub_layer_profile_space[
i], 0, 0, 1,
i);
168 flags(sub_layer_tier_flag[
i], 1,
i);
169 ubs(5, sub_layer_profile_idc[
i], 1,
i);
171 for (j = 0; j < 32; j++)
172 flags(sub_layer_profile_compatibility_flag[
i][j], 2,
i, j);
174 flags(sub_layer_progressive_source_flag[
i], 1,
i);
175 flags(sub_layer_interlaced_source_flag[
i], 1,
i);
176 flags(sub_layer_non_packed_constraint_flag[
i], 1,
i);
177 flags(sub_layer_frame_only_constraint_flag[
i], 1,
i);
179 #define profile_compatible(x) (current->sub_layer_profile_idc[i] == (x) || \
180 current->sub_layer_profile_compatibility_flag[i][x])
185 flags(sub_layer_max_12bit_constraint_flag[
i], 1,
i);
186 flags(sub_layer_max_10bit_constraint_flag[
i], 1,
i);
187 flags(sub_layer_max_8bit_constraint_flag[
i], 1,
i);
188 flags(sub_layer_max_422chroma_constraint_flag[
i], 1,
i);
189 flags(sub_layer_max_420chroma_constraint_flag[
i], 1,
i);
190 flags(sub_layer_max_monochrome_constraint_flag[
i], 1,
i);
191 flags(sub_layer_intra_constraint_flag[
i], 1,
i);
192 flags(sub_layer_one_picture_only_constraint_flag[
i], 1,
i);
193 flags(sub_layer_lower_bit_rate_constraint_flag[
i], 1,
i);
196 flags(sub_layer_max_14bit_constraint_flag[
i], 1,
i);
197 fixed(24, sub_layer_reserved_zero_33bits, 0);
198 fixed( 9, sub_layer_reserved_zero_33bits, 0);
200 fixed(24, sub_layer_reserved_zero_34bits, 0);
201 fixed(10, sub_layer_reserved_zero_34bits, 0);
204 fixed(7, sub_layer_reserved_zero_7bits, 0);
205 flags(sub_layer_one_picture_only_constraint_flag[
i], 1,
i);
206 fixed(24, sub_layer_reserved_zero_43bits, 0);
207 fixed(11, sub_layer_reserved_zero_43bits, 0);
209 fixed(24, sub_layer_reserved_zero_43bits, 0);
210 fixed(19, sub_layer_reserved_zero_43bits, 0);
216 flags(sub_layer_inbld_flag[
i], 1,
i);
218 fixed(1, sub_layer_reserved_zero_bit, 0);
220 #undef profile_compatible
222 if (current->sub_layer_level_present_flag[
i])
223 ubs(8, sub_layer_level_idc[
i], 1,
i);
231 int nal,
int sub_layer_id)
237 current = &hrd->nal_sub_layer_hrd_parameters[sub_layer_id];
239 current = &hrd->vcl_sub_layer_hrd_parameters[sub_layer_id];
241 for (
i = 0;
i <= hrd->cpb_cnt_minus1[sub_layer_id];
i++) {
242 ues(bit_rate_value_minus1[
i], 0, UINT32_MAX - 1, 1,
i);
243 ues(cpb_size_value_minus1[
i], 0, UINT32_MAX - 1, 1,
i);
244 if (hrd->sub_pic_hrd_params_present_flag) {
245 ues(cpb_size_du_value_minus1[
i], 0, UINT32_MAX - 1, 1,
i);
246 ues(bit_rate_du_value_minus1[
i], 0, UINT32_MAX - 1, 1,
i);
256 int max_num_sub_layers_minus1)
260 if (common_inf_present_flag) {
261 flag(nal_hrd_parameters_present_flag);
262 flag(vcl_hrd_parameters_present_flag);
264 if (current->nal_hrd_parameters_present_flag ||
265 current->vcl_hrd_parameters_present_flag) {
266 flag(sub_pic_hrd_params_present_flag);
267 if (current->sub_pic_hrd_params_present_flag) {
268 ub(8, tick_divisor_minus2);
269 ub(5, du_cpb_removal_delay_increment_length_minus1);
270 flag(sub_pic_cpb_params_in_pic_timing_sei_flag);
271 ub(5, dpb_output_delay_du_length_minus1);
274 ub(4, bit_rate_scale);
275 ub(4, cpb_size_scale);
276 if (current->sub_pic_hrd_params_present_flag)
277 ub(4, cpb_size_du_scale);
279 ub(5, initial_cpb_removal_delay_length_minus1);
280 ub(5, au_cpb_removal_delay_length_minus1);
281 ub(5, dpb_output_delay_length_minus1);
283 infer(sub_pic_hrd_params_present_flag, 0);
285 infer(initial_cpb_removal_delay_length_minus1, 23);
286 infer(au_cpb_removal_delay_length_minus1, 23);
287 infer(dpb_output_delay_length_minus1, 23);
291 for (
i = 0;
i <= max_num_sub_layers_minus1;
i++) {
292 flags(fixed_pic_rate_general_flag[
i], 1,
i);
294 if (!current->fixed_pic_rate_general_flag[
i])
295 flags(fixed_pic_rate_within_cvs_flag[
i], 1,
i);
297 infer(fixed_pic_rate_within_cvs_flag[
i], 1);
299 if (current->fixed_pic_rate_within_cvs_flag[
i]) {
300 ues(elemental_duration_in_tc_minus1[
i], 0, 2047, 1,
i);
301 infer(low_delay_hrd_flag[
i], 0);
303 flags(low_delay_hrd_flag[
i], 1,
i);
305 if (!current->low_delay_hrd_flag[
i])
306 ues(cpb_cnt_minus1[
i], 0, 31, 1,
i);
308 infer(cpb_cnt_minus1[
i], 0);
310 if (current->nal_hrd_parameters_present_flag)
312 if (current->vcl_hrd_parameters_present_flag)
324 flag(aspect_ratio_info_present_flag);
325 if (current->aspect_ratio_info_present_flag) {
326 ub(8, aspect_ratio_idc);
327 if (current->aspect_ratio_idc == 255) {
332 infer(aspect_ratio_idc, 0);
335 flag(overscan_info_present_flag);
336 if (current->overscan_info_present_flag)
337 flag(overscan_appropriate_flag);
339 flag(video_signal_type_present_flag);
340 if (current->video_signal_type_present_flag) {
342 flag(video_full_range_flag);
343 flag(colour_description_present_flag);
344 if (current->colour_description_present_flag) {
345 ub(8, colour_primaries);
347 ub(8, matrix_coefficients);
349 infer(colour_primaries, 2);
351 infer(matrix_coefficients, 2);
354 infer(video_format, 5);
355 infer(video_full_range_flag, 0);
356 infer(colour_primaries, 2);
358 infer(matrix_coefficients, 2);
361 flag(chroma_loc_info_present_flag);
362 if (current->chroma_loc_info_present_flag) {
363 ue(chroma_sample_loc_type_top_field, 0, 5);
364 ue(chroma_sample_loc_type_bottom_field, 0, 5);
366 infer(chroma_sample_loc_type_top_field, 0);
367 infer(chroma_sample_loc_type_bottom_field, 0);
370 flag(neutral_chroma_indication_flag);
371 flag(field_seq_flag);
372 flag(frame_field_info_present_flag);
374 flag(default_display_window_flag);
375 if (current->default_display_window_flag) {
376 ue(def_disp_win_left_offset, 0, 16384);
377 ue(def_disp_win_right_offset, 0, 16384);
378 ue(def_disp_win_top_offset, 0, 16384);
379 ue(def_disp_win_bottom_offset, 0, 16384);
382 flag(vui_timing_info_present_flag);
383 if (current->vui_timing_info_present_flag) {
384 u(32, vui_num_units_in_tick, 1, UINT32_MAX);
385 u(32, vui_time_scale, 1, UINT32_MAX);
386 flag(vui_poc_proportional_to_timing_flag);
387 if (current->vui_poc_proportional_to_timing_flag)
388 ue(vui_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
390 flag(vui_hrd_parameters_present_flag);
391 if (current->vui_hrd_parameters_present_flag) {
393 1,
sps->sps_max_sub_layers_minus1));
397 flag(bitstream_restriction_flag);
398 if (current->bitstream_restriction_flag) {
399 flag(tiles_fixed_structure_flag);
400 flag(motion_vectors_over_pic_boundaries_flag);
401 flag(restricted_ref_pic_lists_flag);
402 ue(min_spatial_segmentation_idc, 0, 4095);
403 ue(max_bytes_per_pic_denom, 0, 16);
404 ue(max_bits_per_min_cu_denom, 0, 16);
405 ue(log2_max_mv_length_horizontal, 0, 16);
406 ue(log2_max_mv_length_vertical, 0, 16);
408 infer(tiles_fixed_structure_flag, 0);
409 infer(motion_vectors_over_pic_boundaries_flag, 1);
410 infer(min_spatial_segmentation_idc, 0);
411 infer(max_bytes_per_pic_denom, 2);
412 infer(max_bits_per_min_cu_denom, 1);
413 infer(log2_max_mv_length_horizontal, 15);
414 infer(log2_max_mv_length_vertical, 15);
425 HEADER(
"Video Parameter Set");
429 ub(4, vps_video_parameter_set_id);
431 flag(vps_base_layer_internal_flag);
432 flag(vps_base_layer_available_flag);
435 flag(vps_temporal_id_nesting_flag);
437 if (current->vps_max_sub_layers_minus1 == 0 &&
438 current->vps_temporal_id_nesting_flag != 1) {
440 "vps_temporal_id_nesting_flag must be 1 if "
441 "vps_max_sub_layers_minus1 is 0.\n");
445 fixed(16, vps_reserved_0xffff_16bits, 0xffff);
448 1, current->vps_max_sub_layers_minus1));
450 flag(vps_sub_layer_ordering_info_present_flag);
451 for (
i = (current->vps_sub_layer_ordering_info_present_flag ?
452 0 : current->vps_max_sub_layers_minus1);
453 i <= current->vps_max_sub_layers_minus1;
i++) {
454 ues(vps_max_dec_pic_buffering_minus1[
i],
456 ues(vps_max_num_reorder_pics[
i],
457 0, current->vps_max_dec_pic_buffering_minus1[
i], 1,
i);
458 ues(vps_max_latency_increase_plus1[
i],
459 0, UINT32_MAX - 1, 1,
i);
461 if (!current->vps_sub_layer_ordering_info_present_flag) {
462 for (
i = 0;
i < current->vps_max_sub_layers_minus1;
i++) {
463 infer(vps_max_dec_pic_buffering_minus1[
i],
464 current->vps_max_dec_pic_buffering_minus1[current->vps_max_sub_layers_minus1]);
465 infer(vps_max_num_reorder_pics[
i],
466 current->vps_max_num_reorder_pics[current->vps_max_sub_layers_minus1]);
467 infer(vps_max_latency_increase_plus1[
i],
468 current->vps_max_latency_increase_plus1[current->vps_max_sub_layers_minus1]);
474 for (
i = 1;
i <= current->vps_num_layer_sets_minus1;
i++) {
475 for (j = 0; j <= current->vps_max_layer_id; j++)
476 flags(layer_id_included_flag[
i][j], 2,
i, j);
478 for (j = 0; j <= current->vps_max_layer_id; j++)
479 infer(layer_id_included_flag[0][j], j == 0);
481 flag(vps_timing_info_present_flag);
482 if (current->vps_timing_info_present_flag) {
483 u(32, vps_num_units_in_tick, 1, UINT32_MAX);
484 u(32, vps_time_scale, 1, UINT32_MAX);
485 flag(vps_poc_proportional_to_timing_flag);
486 if (current->vps_poc_proportional_to_timing_flag)
487 ue(vps_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
488 ue(vps_num_hrd_parameters, 0, current->vps_num_layer_sets_minus1 + 1);
489 for (
i = 0;
i < current->vps_num_hrd_parameters;
i++) {
490 ues(hrd_layer_set_idx[
i],
491 current->vps_base_layer_internal_flag ? 0 : 1,
492 current->vps_num_layer_sets_minus1, 1,
i);
494 flags(cprms_present_flag[
i], 1,
i);
496 infer(cprms_present_flag[0], 1);
499 current->cprms_present_flag[
i],
500 current->vps_max_sub_layers_minus1));
504 flag(vps_extension_flag);
505 if (current->vps_extension_flag)
520 flag(inter_ref_pic_set_prediction_flag);
522 infer(inter_ref_pic_set_prediction_flag, 0);
524 if (current->inter_ref_pic_set_prediction_flag) {
525 unsigned int ref_rps_idx, num_delta_pocs, num_ref_pics;
527 int delta_rps, d_poc;
533 if (st_rps_idx ==
sps->num_short_term_ref_pic_sets)
534 ue(delta_idx_minus1, 0, st_rps_idx - 1);
536 infer(delta_idx_minus1, 0);
538 ref_rps_idx = st_rps_idx - (current->delta_idx_minus1 + 1);
539 ref = &
sps->st_ref_pic_set[ref_rps_idx];
540 num_delta_pocs =
ref->num_negative_pics +
ref->num_positive_pics;
543 flag(delta_rps_sign);
544 ue(abs_delta_rps_minus1, 0, INT16_MAX);
545 delta_rps = (1 - 2 * current->delta_rps_sign) *
546 (current->abs_delta_rps_minus1 + 1);
549 for (j = 0; j <= num_delta_pocs; j++) {
550 flags(used_by_curr_pic_flag[j], 1, j);
551 if (!current->used_by_curr_pic_flag[j])
552 flags(use_delta_flag[j], 1, j);
554 infer(use_delta_flag[j], 1);
555 if (current->use_delta_flag[j])
560 "short-term ref pic set %d "
561 "contains too many pictures.\n", st_rps_idx);
582 for (
i = 0;
i <
ref->num_negative_pics;
i++) {
583 d_poc -=
ref->delta_poc_s0_minus1[
i] + 1;
584 ref_delta_poc_s0[
i] = d_poc;
587 for (
i = 0;
i <
ref->num_positive_pics;
i++) {
588 d_poc +=
ref->delta_poc_s1_minus1[
i] + 1;
589 ref_delta_poc_s1[
i] = d_poc;
593 for (j =
ref->num_positive_pics - 1; j >= 0; j--) {
594 d_poc = ref_delta_poc_s1[j] + delta_rps;
595 if (d_poc < 0 && current->use_delta_flag[
ref->num_negative_pics + j]) {
596 delta_poc_s0[
i] = d_poc;
597 used_by_curr_pic_s0[
i++] =
598 current->used_by_curr_pic_flag[
ref->num_negative_pics + j];
601 if (delta_rps < 0 && current->use_delta_flag[num_delta_pocs]) {
602 delta_poc_s0[
i] = delta_rps;
603 used_by_curr_pic_s0[
i++] =
604 current->used_by_curr_pic_flag[num_delta_pocs];
606 for (j = 0; j <
ref->num_negative_pics; j++) {
607 d_poc = ref_delta_poc_s0[j] + delta_rps;
608 if (d_poc < 0 && current->use_delta_flag[j]) {
609 delta_poc_s0[
i] = d_poc;
610 used_by_curr_pic_s0[
i++] = current->used_by_curr_pic_flag[j];
614 infer(num_negative_pics,
i);
615 for (
i = 0;
i < current->num_negative_pics;
i++) {
616 infer(delta_poc_s0_minus1[
i],
617 -(delta_poc_s0[
i] - (
i == 0 ? 0 : delta_poc_s0[
i - 1])) - 1);
618 infer(used_by_curr_pic_s0_flag[
i], used_by_curr_pic_s0[
i]);
622 for (j =
ref->num_negative_pics - 1; j >= 0; j--) {
623 d_poc = ref_delta_poc_s0[j] + delta_rps;
624 if (d_poc > 0 && current->use_delta_flag[j]) {
625 delta_poc_s1[
i] = d_poc;
626 used_by_curr_pic_s1[
i++] = current->used_by_curr_pic_flag[j];
629 if (delta_rps > 0 && current->use_delta_flag[num_delta_pocs]) {
630 delta_poc_s1[
i] = delta_rps;
631 used_by_curr_pic_s1[
i++] =
632 current->used_by_curr_pic_flag[num_delta_pocs];
634 for (j = 0; j <
ref->num_positive_pics; j++) {
635 d_poc = ref_delta_poc_s1[j] + delta_rps;
636 if (d_poc > 0 && current->use_delta_flag[
ref->num_negative_pics + j]) {
637 delta_poc_s1[
i] = d_poc;
638 used_by_curr_pic_s1[
i++] =
639 current->used_by_curr_pic_flag[
ref->num_negative_pics + j];
643 infer(num_positive_pics,
i);
644 for (
i = 0;
i < current->num_positive_pics;
i++) {
645 infer(delta_poc_s1_minus1[
i],
646 delta_poc_s1[
i] - (
i == 0 ? 0 : delta_poc_s1[
i - 1]) - 1);
647 infer(used_by_curr_pic_s1_flag[
i], used_by_curr_pic_s1[
i]);
651 ue(num_negative_pics, 0, 15);
652 ue(num_positive_pics, 0, 15 - current->num_negative_pics);
654 for (
i = 0;
i < current->num_negative_pics;
i++) {
655 ues(delta_poc_s0_minus1[
i], 0, INT16_MAX, 1,
i);
656 flags(used_by_curr_pic_s0_flag[
i], 1,
i);
659 for (
i = 0;
i < current->num_positive_pics;
i++) {
660 ues(delta_poc_s1_minus1[
i], 0, INT16_MAX, 1,
i);
661 flags(used_by_curr_pic_s1_flag[
i], 1,
i);
671 int sizeId, matrixId;
674 for (sizeId = 0; sizeId < 4; sizeId++) {
675 for (matrixId = 0; matrixId < 6; matrixId += (sizeId == 3 ? 3 : 1)) {
676 flags(scaling_list_pred_mode_flag[sizeId][matrixId],
677 2, sizeId, matrixId);
678 if (!current->scaling_list_pred_mode_flag[sizeId][matrixId]) {
679 ues(scaling_list_pred_matrix_id_delta[sizeId][matrixId],
680 0, sizeId == 3 ? matrixId / 3 : matrixId,
681 2, sizeId, matrixId);
683 n =
FFMIN(64, 1 << (4 + (sizeId << 1)));
685 ses(scaling_list_dc_coef_minus8[sizeId - 2][matrixId], -7, +247,
686 2, sizeId - 2, matrixId);
688 for (
i = 0;
i < n;
i++) {
689 ses(scaling_list_delta_coeff[sizeId][matrixId][
i],
690 -128, +127, 3, sizeId, matrixId,
i);
704 flag(transform_skip_rotation_enabled_flag);
705 flag(transform_skip_context_enabled_flag);
706 flag(implicit_rdpcm_enabled_flag);
707 flag(explicit_rdpcm_enabled_flag);
708 flag(extended_precision_processing_flag);
709 flag(intra_smoothing_disabled_flag);
710 flag(high_precision_offsets_enabled_flag);
711 flag(persistent_rice_adaptation_enabled_flag);
712 flag(cabac_bypass_alignment_enabled_flag);
722 flag(sps_curr_pic_ref_enabled_flag);
724 flag(palette_mode_enabled_flag);
725 if (current->palette_mode_enabled_flag) {
726 ue(palette_max_size, 0, 64);
727 ue(delta_palette_max_predictor_size, 0, 128);
729 flag(sps_palette_predictor_initializer_present_flag);
730 if (current->sps_palette_predictor_initializer_present_flag) {
731 ue(sps_num_palette_predictor_initializer_minus1, 0, 127);
732 for (
comp = 0;
comp < (current->chroma_format_idc ? 3 : 1);
comp++) {
733 int bit_depth =
comp == 0 ? current->bit_depth_luma_minus8 + 8
734 : current->bit_depth_chroma_minus8 + 8;
735 for (
i = 0;
i <= current->sps_num_palette_predictor_initializer_minus1;
i++)
741 u(2, motion_vector_resolution_control_idc, 0, 2);
742 flag(intra_boundary_filtering_disable_flag);
751 infer(aspect_ratio_idc, 0);
753 infer(video_format, 5);
754 infer(video_full_range_flag, 0);
755 infer(colour_primaries, 2);
757 infer(matrix_coefficients, 2);
759 infer(chroma_sample_loc_type_top_field, 0);
760 infer(chroma_sample_loc_type_bottom_field, 0);
762 infer(tiles_fixed_structure_flag, 0);
763 infer(motion_vectors_over_pic_boundaries_flag, 1);
764 infer(min_spatial_segmentation_idc, 0);
765 infer(max_bytes_per_pic_denom, 2);
766 infer(max_bits_per_min_cu_denom, 1);
767 infer(log2_max_mv_length_horizontal, 15);
768 infer(log2_max_mv_length_vertical, 15);
779 unsigned int min_cb_log2_size_y, ctb_log2_size_y,
780 min_cb_size_y, min_tb_log2_size_y;
782 HEADER(
"Sequence Parameter Set");
786 ub(4, sps_video_parameter_set_id);
790 flag(sps_temporal_id_nesting_flag);
792 if (
vps->vps_max_sub_layers_minus1 > current->sps_max_sub_layers_minus1) {
794 "sps_max_sub_layers_minus1 (%d) must be less than or equal to "
795 "vps_max_sub_layers_minus1 (%d).\n",
796 vps->vps_max_sub_layers_minus1,
797 current->sps_max_sub_layers_minus1);
800 if (
vps->vps_temporal_id_nesting_flag &&
801 !current->sps_temporal_id_nesting_flag) {
803 "sps_temporal_id_nesting_flag must be 1 if "
804 "vps_temporal_id_nesting_flag is 1.\n");
810 1, current->sps_max_sub_layers_minus1));
812 ue(sps_seq_parameter_set_id, 0, 15);
814 ue(chroma_format_idc, 0, 3);
815 if (current->chroma_format_idc == 3)
816 flag(separate_colour_plane_flag);
818 infer(separate_colour_plane_flag, 0);
823 flag(conformance_window_flag);
824 if (current->conformance_window_flag) {
825 ue(conf_win_left_offset, 0, current->pic_width_in_luma_samples);
826 ue(conf_win_right_offset, 0, current->pic_width_in_luma_samples);
827 ue(conf_win_top_offset, 0, current->pic_height_in_luma_samples);
828 ue(conf_win_bottom_offset, 0, current->pic_height_in_luma_samples);
830 infer(conf_win_left_offset, 0);
831 infer(conf_win_right_offset, 0);
832 infer(conf_win_top_offset, 0);
833 infer(conf_win_bottom_offset, 0);
836 ue(bit_depth_luma_minus8, 0, 8);
837 ue(bit_depth_chroma_minus8, 0, 8);
839 ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12);
841 flag(sps_sub_layer_ordering_info_present_flag);
842 for (
i = (current->sps_sub_layer_ordering_info_present_flag ?
843 0 : current->sps_max_sub_layers_minus1);
844 i <= current->sps_max_sub_layers_minus1;
i++) {
845 ues(sps_max_dec_pic_buffering_minus1[
i],
847 ues(sps_max_num_reorder_pics[
i],
848 0, current->sps_max_dec_pic_buffering_minus1[
i], 1,
i);
849 ues(sps_max_latency_increase_plus1[
i],
850 0, UINT32_MAX - 1, 1,
i);
852 if (!current->sps_sub_layer_ordering_info_present_flag) {
853 for (
i = 0;
i < current->sps_max_sub_layers_minus1;
i++) {
854 infer(sps_max_dec_pic_buffering_minus1[
i],
855 current->sps_max_dec_pic_buffering_minus1[current->sps_max_sub_layers_minus1]);
856 infer(sps_max_num_reorder_pics[
i],
857 current->sps_max_num_reorder_pics[current->sps_max_sub_layers_minus1]);
858 infer(sps_max_latency_increase_plus1[
i],
859 current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]);
863 ue(log2_min_luma_coding_block_size_minus3, 0, 3);
864 min_cb_log2_size_y = current->log2_min_luma_coding_block_size_minus3 + 3;
866 ue(log2_diff_max_min_luma_coding_block_size, 0, 3);
867 ctb_log2_size_y = min_cb_log2_size_y +
868 current->log2_diff_max_min_luma_coding_block_size;
870 min_cb_size_y = 1 << min_cb_log2_size_y;
871 if (current->pic_width_in_luma_samples % min_cb_size_y ||
872 current->pic_height_in_luma_samples % min_cb_size_y) {
874 "by MinCbSizeY = %u.\n", current->pic_width_in_luma_samples,
875 current->pic_height_in_luma_samples, min_cb_size_y);
879 ue(log2_min_luma_transform_block_size_minus2, 0, min_cb_log2_size_y - 3);
880 min_tb_log2_size_y = current->log2_min_luma_transform_block_size_minus2 + 2;
882 ue(log2_diff_max_min_luma_transform_block_size,
883 0,
FFMIN(ctb_log2_size_y, 5) - min_tb_log2_size_y);
885 ue(max_transform_hierarchy_depth_inter,
886 0, ctb_log2_size_y - min_tb_log2_size_y);
887 ue(max_transform_hierarchy_depth_intra,
888 0, ctb_log2_size_y - min_tb_log2_size_y);
890 flag(scaling_list_enabled_flag);
891 if (current->scaling_list_enabled_flag) {
892 flag(sps_scaling_list_data_present_flag);
893 if (current->sps_scaling_list_data_present_flag)
896 infer(sps_scaling_list_data_present_flag, 0);
899 flag(amp_enabled_flag);
900 flag(sample_adaptive_offset_enabled_flag);
902 flag(pcm_enabled_flag);
903 if (current->pcm_enabled_flag) {
904 u(4, pcm_sample_bit_depth_luma_minus1,
905 0, current->bit_depth_luma_minus8 + 8 - 1);
906 u(4, pcm_sample_bit_depth_chroma_minus1,
907 0, current->bit_depth_chroma_minus8 + 8 - 1);
909 ue(log2_min_pcm_luma_coding_block_size_minus3,
910 FFMIN(min_cb_log2_size_y, 5) - 3,
FFMIN(ctb_log2_size_y, 5) - 3);
911 ue(log2_diff_max_min_pcm_luma_coding_block_size,
912 0,
FFMIN(ctb_log2_size_y, 5) - (current->log2_min_pcm_luma_coding_block_size_minus3 + 3));
914 flag(pcm_loop_filter_disabled_flag);
918 for (
i = 0;
i < current->num_short_term_ref_pic_sets;
i++)
921 flag(long_term_ref_pics_present_flag);
922 if (current->long_term_ref_pics_present_flag) {
924 for (
i = 0;
i < current->num_long_term_ref_pics_sps;
i++) {
925 ubs(current->log2_max_pic_order_cnt_lsb_minus4 + 4,
926 lt_ref_pic_poc_lsb_sps[
i], 1,
i);
927 flags(used_by_curr_pic_lt_sps_flag[
i], 1,
i);
931 flag(sps_temporal_mvp_enabled_flag);
932 flag(strong_intra_smoothing_enabled_flag);
934 flag(vui_parameters_present_flag);
935 if (current->vui_parameters_present_flag)
940 flag(sps_extension_present_flag);
941 if (current->sps_extension_present_flag) {
942 flag(sps_range_extension_flag);
943 flag(sps_multilayer_extension_flag);
944 flag(sps_3d_extension_flag);
945 flag(sps_scc_extension_flag);
946 ub(4, sps_extension_4bits);
949 if (current->sps_range_extension_flag)
951 if (current->sps_multilayer_extension_flag)
953 if (current->sps_3d_extension_flag)
955 if (current->sps_scc_extension_flag)
957 if (current->sps_extension_4bits)
972 if (current->transform_skip_enabled_flag)
973 ue(log2_max_transform_skip_block_size_minus2, 0, 3);
974 flag(cross_component_prediction_enabled_flag);
976 flag(chroma_qp_offset_list_enabled_flag);
977 if (current->chroma_qp_offset_list_enabled_flag) {
978 ue(diff_cu_chroma_qp_offset_depth,
979 0,
sps->log2_diff_max_min_luma_coding_block_size);
980 ue(chroma_qp_offset_list_len_minus1, 0, 5);
981 for (
i = 0;
i <= current->chroma_qp_offset_list_len_minus1;
i++) {
982 ses(cb_qp_offset_list[
i], -12, +12, 1,
i);
983 ses(cr_qp_offset_list[
i], -12, +12, 1,
i);
987 ue(log2_sao_offset_scale_luma, 0,
FFMAX(0,
sps->bit_depth_luma_minus8 - 2));
988 ue(log2_sao_offset_scale_chroma, 0,
FFMAX(0,
sps->bit_depth_chroma_minus8 - 2));
998 flag(pps_curr_pic_ref_enabled_flag);
1000 flag(residual_adaptive_colour_transform_enabled_flag);
1001 if (current->residual_adaptive_colour_transform_enabled_flag) {
1002 flag(pps_slice_act_qp_offsets_present_flag);
1003 se(pps_act_y_qp_offset_plus5, -7, +17);
1004 se(pps_act_cb_qp_offset_plus5, -7, +17);
1005 se(pps_act_cr_qp_offset_plus3, -9, +15);
1007 infer(pps_slice_act_qp_offsets_present_flag, 0);
1008 infer(pps_act_y_qp_offset_plus5, 0);
1009 infer(pps_act_cb_qp_offset_plus5, 0);
1010 infer(pps_act_cr_qp_offset_plus3, 0);
1013 flag(pps_palette_predictor_initializer_present_flag);
1014 if (current->pps_palette_predictor_initializer_present_flag) {
1015 ue(pps_num_palette_predictor_initializer, 0, 128);
1016 if (current->pps_num_palette_predictor_initializer > 0) {
1017 flag(monochrome_palette_flag);
1018 ue(luma_bit_depth_entry_minus8, 0, 8);
1019 if (!current->monochrome_palette_flag)
1020 ue(chroma_bit_depth_entry_minus8, 0, 8);
1021 for (
comp = 0;
comp < (current->monochrome_palette_flag ? 1 : 3);
comp++) {
1022 int bit_depth =
comp == 0 ? current->luma_bit_depth_entry_minus8 + 8
1023 : current->chroma_bit_depth_entry_minus8 + 8;
1024 for (
i = 0;
i < current->pps_num_palette_predictor_initializer;
i++)
1040 HEADER(
"Picture Parameter Set");
1044 ue(pps_pic_parameter_set_id, 0, 63);
1045 ue(pps_seq_parameter_set_id, 0, 15);
1046 sps = h265->
sps[current->pps_seq_parameter_set_id];
1049 current->pps_seq_parameter_set_id);
1054 flag(dependent_slice_segments_enabled_flag);
1055 flag(output_flag_present_flag);
1056 ub(3, num_extra_slice_header_bits);
1057 flag(sign_data_hiding_enabled_flag);
1058 flag(cabac_init_present_flag);
1060 ue(num_ref_idx_l0_default_active_minus1, 0, 14);
1061 ue(num_ref_idx_l1_default_active_minus1, 0, 14);
1063 se(init_qp_minus26, -(26 + 6 *
sps->bit_depth_luma_minus8), +25);
1065 flag(constrained_intra_pred_flag);
1066 flag(transform_skip_enabled_flag);
1067 flag(cu_qp_delta_enabled_flag);
1068 if (current->cu_qp_delta_enabled_flag)
1069 ue(diff_cu_qp_delta_depth,
1070 0,
sps->log2_diff_max_min_luma_coding_block_size);
1072 infer(diff_cu_qp_delta_depth, 0);
1074 se(pps_cb_qp_offset, -12, +12);
1075 se(pps_cr_qp_offset, -12, +12);
1076 flag(pps_slice_chroma_qp_offsets_present_flag);
1078 flag(weighted_pred_flag);
1079 flag(weighted_bipred_flag);
1081 flag(transquant_bypass_enabled_flag);
1082 flag(tiles_enabled_flag);
1083 flag(entropy_coding_sync_enabled_flag);
1085 if (current->tiles_enabled_flag) {
1088 flag(uniform_spacing_flag);
1089 if (!current->uniform_spacing_flag) {
1090 for (
i = 0;
i < current->num_tile_columns_minus1;
i++)
1091 ues(column_width_minus1[
i], 0,
sps->pic_width_in_luma_samples, 1,
i);
1092 for (
i = 0;
i < current->num_tile_rows_minus1;
i++)
1093 ues(row_height_minus1[
i], 0,
sps->pic_height_in_luma_samples, 1,
i);
1095 flag(loop_filter_across_tiles_enabled_flag);
1097 infer(num_tile_columns_minus1, 0);
1098 infer(num_tile_rows_minus1, 0);
1101 flag(pps_loop_filter_across_slices_enabled_flag);
1102 flag(deblocking_filter_control_present_flag);
1103 if (current->deblocking_filter_control_present_flag) {
1104 flag(deblocking_filter_override_enabled_flag);
1105 flag(pps_deblocking_filter_disabled_flag);
1106 if (!current->pps_deblocking_filter_disabled_flag) {
1107 se(pps_beta_offset_div2, -6, +6);
1108 se(pps_tc_offset_div2, -6, +6);
1110 infer(pps_beta_offset_div2, 0);
1111 infer(pps_tc_offset_div2, 0);
1114 infer(deblocking_filter_override_enabled_flag, 0);
1115 infer(pps_deblocking_filter_disabled_flag, 0);
1116 infer(pps_beta_offset_div2, 0);
1117 infer(pps_tc_offset_div2, 0);
1120 flag(pps_scaling_list_data_present_flag);
1121 if (current->pps_scaling_list_data_present_flag)
1124 flag(lists_modification_present_flag);
1126 ue(log2_parallel_merge_level_minus2,
1127 0, (
sps->log2_min_luma_coding_block_size_minus3 + 3 +
1128 sps->log2_diff_max_min_luma_coding_block_size - 2));
1130 flag(slice_segment_header_extension_present_flag);
1132 flag(pps_extension_present_flag);
1133 if (current->pps_extension_present_flag) {
1134 flag(pps_range_extension_flag);
1135 flag(pps_multilayer_extension_flag);
1136 flag(pps_3d_extension_flag);
1137 flag(pps_scc_extension_flag);
1138 ub(4, pps_extension_4bits);
1140 if (current->pps_range_extension_flag)
1142 if (current->pps_multilayer_extension_flag)
1144 if (current->pps_3d_extension_flag)
1146 if (current->pps_scc_extension_flag)
1148 if (current->pps_extension_4bits)
1161 HEADER(
"Access Unit Delimiter");
1165 u(3, pic_type, 0, 2);
1174 unsigned int num_pic_total_curr)
1176 unsigned int entry_size;
1179 entry_size =
av_log2(num_pic_total_curr - 1) + 1;
1181 flag(ref_pic_list_modification_flag_l0);
1182 if (current->ref_pic_list_modification_flag_l0) {
1183 for (
i = 0;
i <= current->num_ref_idx_l0_active_minus1;
i++)
1184 us(entry_size, list_entry_l0[
i], 0, num_pic_total_curr - 1, 1,
i);
1188 flag(ref_pic_list_modification_flag_l1);
1189 if (current->ref_pic_list_modification_flag_l1) {
1190 for (
i = 0;
i <= current->num_ref_idx_l1_active_minus1;
i++)
1191 us(entry_size, list_entry_l1[
i], 0, num_pic_total_curr - 1, 1,
i);
1204 int chroma = !
sps->separate_colour_plane_flag &&
1205 sps->chroma_format_idc != 0;
1207 ue(luma_log2_weight_denom, 0, 7);
1209 se(delta_chroma_log2_weight_denom, -7, 7);
1211 infer(delta_chroma_log2_weight_denom, 0);
1213 for (
i = 0;
i <= current->num_ref_idx_l0_active_minus1;
i++) {
1215 flags(luma_weight_l0_flag[
i], 1,
i);
1217 infer(luma_weight_l0_flag[
i], 0);
1220 for (
i = 0;
i <= current->num_ref_idx_l0_active_minus1;
i++) {
1222 flags(chroma_weight_l0_flag[
i], 1,
i);
1224 infer(chroma_weight_l0_flag[
i], 0);
1228 for (
i = 0;
i <= current->num_ref_idx_l0_active_minus1;
i++) {
1229 if (current->luma_weight_l0_flag[
i]) {
1230 ses(delta_luma_weight_l0[
i], -128, +127, 1,
i);
1231 ses(luma_offset_l0[
i],
1232 -(1 << (
sps->bit_depth_luma_minus8 + 8 - 1)),
1233 ((1 << (
sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1,
i);
1235 infer(delta_luma_weight_l0[
i], 0);
1236 infer(luma_offset_l0[
i], 0);
1238 if (current->chroma_weight_l0_flag[
i]) {
1239 for (j = 0; j < 2; j++) {
1240 ses(delta_chroma_weight_l0[
i][j], -128, +127, 2,
i, j);
1241 ses(chroma_offset_l0[
i][j],
1242 -(4 << (
sps->bit_depth_chroma_minus8 + 8 - 1)),
1243 ((4 << (
sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2,
i, j);
1246 for (j = 0; j < 2; j++) {
1247 infer(delta_chroma_weight_l0[
i][j], 0);
1248 infer(chroma_offset_l0[
i][j], 0);
1254 for (
i = 0;
i <= current->num_ref_idx_l1_active_minus1;
i++) {
1256 flags(luma_weight_l1_flag[
i], 1,
i);
1258 infer(luma_weight_l1_flag[
i], 0);
1261 for (
i = 0;
i <= current->num_ref_idx_l1_active_minus1;
i++) {
1263 flags(chroma_weight_l1_flag[
i], 1,
i);
1265 infer(chroma_weight_l1_flag[
i], 0);
1269 for (
i = 0;
i <= current->num_ref_idx_l1_active_minus1;
i++) {
1270 if (current->luma_weight_l1_flag[
i]) {
1271 ses(delta_luma_weight_l1[
i], -128, +127, 1,
i);
1272 ses(luma_offset_l1[
i],
1273 -(1 << (
sps->bit_depth_luma_minus8 + 8 - 1)),
1274 ((1 << (
sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1,
i);
1276 infer(delta_luma_weight_l1[
i], 0);
1277 infer(luma_offset_l1[
i], 0);
1279 if (current->chroma_weight_l1_flag[
i]) {
1280 for (j = 0; j < 2; j++) {
1281 ses(delta_chroma_weight_l1[
i][j], -128, +127, 2,
i, j);
1282 ses(chroma_offset_l1[
i][j],
1283 -(4 << (
sps->bit_depth_chroma_minus8 + 8 - 1)),
1284 ((4 << (
sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2,
i, j);
1287 for (j = 0; j < 2; j++) {
1288 infer(delta_chroma_weight_l1[
i][j], 0);
1289 infer(chroma_offset_l1[
i][j], 0);
1304 unsigned int min_cb_log2_size_y, ctb_log2_size_y, ctb_size_y;
1305 unsigned int pic_width_in_ctbs_y, pic_height_in_ctbs_y, pic_size_in_ctbs_y;
1306 unsigned int num_pic_total_curr = 0;
1309 HEADER(
"Slice Segment Header");
1313 flag(first_slice_segment_in_pic_flag);
1317 flag(no_output_of_prior_pics_flag);
1319 ue(slice_pic_parameter_set_id, 0, 63);
1321 pps = h265->
pps[current->slice_pic_parameter_set_id];
1324 current->slice_pic_parameter_set_id);
1329 sps = h265->
sps[
pps->pps_seq_parameter_set_id];
1332 pps->pps_seq_parameter_set_id);
1337 min_cb_log2_size_y =
sps->log2_min_luma_coding_block_size_minus3 + 3;
1338 ctb_log2_size_y = min_cb_log2_size_y +
sps->log2_diff_max_min_luma_coding_block_size;
1339 ctb_size_y = 1 << ctb_log2_size_y;
1340 pic_width_in_ctbs_y =
1341 (
sps->pic_width_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1342 pic_height_in_ctbs_y =
1343 (
sps->pic_height_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1344 pic_size_in_ctbs_y = pic_width_in_ctbs_y * pic_height_in_ctbs_y;
1346 if (!current->first_slice_segment_in_pic_flag) {
1347 unsigned int address_size =
av_log2(pic_size_in_ctbs_y - 1) + 1;
1348 if (
pps->dependent_slice_segments_enabled_flag)
1349 flag(dependent_slice_segment_flag);
1351 infer(dependent_slice_segment_flag, 0);
1352 u(address_size, slice_segment_address, 0, pic_size_in_ctbs_y - 1);
1354 infer(dependent_slice_segment_flag, 0);
1357 if (!current->dependent_slice_segment_flag) {
1358 for (
i = 0;
i <
pps->num_extra_slice_header_bits;
i++)
1359 flags(slice_reserved_flag[
i], 1,
i);
1361 ue(slice_type, 0, 2);
1363 if (
pps->output_flag_present_flag)
1364 flag(pic_output_flag);
1366 if (
sps->separate_colour_plane_flag)
1367 u(2, colour_plane_id, 0, 2);
1373 ub(
sps->log2_max_pic_order_cnt_lsb_minus4 + 4, slice_pic_order_cnt_lsb);
1375 flag(short_term_ref_pic_set_sps_flag);
1376 if (!current->short_term_ref_pic_set_sps_flag) {
1378 sps->num_short_term_ref_pic_sets,
sps));
1379 rps = ¤t->short_term_ref_pic_set;
1380 }
else if (
sps->num_short_term_ref_pic_sets > 1) {
1381 unsigned int idx_size =
av_log2(
sps->num_short_term_ref_pic_sets - 1) + 1;
1382 u(idx_size, short_term_ref_pic_set_idx,
1383 0,
sps->num_short_term_ref_pic_sets - 1);
1384 rps = &
sps->st_ref_pic_set[current->short_term_ref_pic_set_idx];
1386 infer(short_term_ref_pic_set_idx, 0);
1387 rps = &
sps->st_ref_pic_set[0];
1390 num_pic_total_curr = 0;
1393 ++num_pic_total_curr;
1396 ++num_pic_total_curr;
1398 if (
sps->long_term_ref_pics_present_flag) {
1399 unsigned int idx_size;
1401 if (
sps->num_long_term_ref_pics_sps > 0) {
1402 ue(num_long_term_sps, 0,
sps->num_long_term_ref_pics_sps);
1403 idx_size =
av_log2(
sps->num_long_term_ref_pics_sps - 1) + 1;
1405 infer(num_long_term_sps, 0);
1408 ue(num_long_term_pics, 0,
HEVC_MAX_REFS - current->num_long_term_sps);
1410 for (
i = 0;
i < current->num_long_term_sps +
1411 current->num_long_term_pics;
i++) {
1412 if (i < current->num_long_term_sps) {
1413 if (
sps->num_long_term_ref_pics_sps > 1)
1414 us(idx_size, lt_idx_sps[
i],
1415 0,
sps->num_long_term_ref_pics_sps - 1, 1,
i);
1416 if (
sps->used_by_curr_pic_lt_sps_flag[current->lt_idx_sps[
i]])
1417 ++num_pic_total_curr;
1419 ubs(
sps->log2_max_pic_order_cnt_lsb_minus4 + 4, poc_lsb_lt[
i], 1,
i);
1420 flags(used_by_curr_pic_lt_flag[
i], 1,
i);
1421 if (current->used_by_curr_pic_lt_flag[
i])
1422 ++num_pic_total_curr;
1424 flags(delta_poc_msb_present_flag[
i], 1,
i);
1425 if (current->delta_poc_msb_present_flag[
i])
1426 ues(delta_poc_msb_cycle_lt[
i], 0, UINT32_MAX - 1, 1,
i);
1428 infer(delta_poc_msb_cycle_lt[
i], 0);
1432 if (
sps->sps_temporal_mvp_enabled_flag)
1433 flag(slice_temporal_mvp_enabled_flag);
1435 infer(slice_temporal_mvp_enabled_flag, 0);
1437 if (
pps->pps_curr_pic_ref_enabled_flag)
1438 ++num_pic_total_curr;
1441 if (
sps->sample_adaptive_offset_enabled_flag) {
1442 flag(slice_sao_luma_flag);
1443 if (!
sps->separate_colour_plane_flag &&
sps->chroma_format_idc != 0)
1444 flag(slice_sao_chroma_flag);
1446 infer(slice_sao_chroma_flag, 0);
1448 infer(slice_sao_luma_flag, 0);
1449 infer(slice_sao_chroma_flag, 0);
1454 flag(num_ref_idx_active_override_flag);
1455 if (current->num_ref_idx_active_override_flag) {
1456 ue(num_ref_idx_l0_active_minus1, 0, 14);
1458 ue(num_ref_idx_l1_active_minus1, 0, 14);
1460 infer(num_ref_idx_l1_active_minus1,
pps->num_ref_idx_l1_default_active_minus1);
1462 infer(num_ref_idx_l0_active_minus1,
pps->num_ref_idx_l0_default_active_minus1);
1463 infer(num_ref_idx_l1_active_minus1,
pps->num_ref_idx_l1_default_active_minus1);
1466 if (
pps->lists_modification_present_flag && num_pic_total_curr > 1)
1468 num_pic_total_curr));
1471 flag(mvd_l1_zero_flag);
1472 if (
pps->cabac_init_present_flag)
1473 flag(cabac_init_flag);
1475 infer(cabac_init_flag, 0);
1476 if (current->slice_temporal_mvp_enabled_flag) {
1478 flag(collocated_from_l0_flag);
1480 infer(collocated_from_l0_flag, 1);
1481 if (current->collocated_from_l0_flag) {
1482 if (current->num_ref_idx_l0_active_minus1 > 0)
1483 ue(collocated_ref_idx, 0, current->num_ref_idx_l0_active_minus1);
1485 infer(collocated_ref_idx, 0);
1487 if (current->num_ref_idx_l1_active_minus1 > 0)
1488 ue(collocated_ref_idx, 0, current->num_ref_idx_l1_active_minus1);
1490 infer(collocated_ref_idx, 0);
1494 if ((
pps->weighted_pred_flag && current->slice_type ==
HEVC_SLICE_P) ||
1498 ue(five_minus_max_num_merge_cand, 0, 4);
1499 if (
sps->motion_vector_resolution_control_idc == 2)
1500 flag(use_integer_mv_flag);
1502 infer(use_integer_mv_flag,
sps->motion_vector_resolution_control_idc);
1506 - 6 *
sps->bit_depth_luma_minus8 - (
pps->init_qp_minus26 + 26),
1507 + 51 - (
pps->init_qp_minus26 + 26));
1508 if (
pps->pps_slice_chroma_qp_offsets_present_flag) {
1509 se(slice_cb_qp_offset, -12, +12);
1510 se(slice_cr_qp_offset, -12, +12);
1512 infer(slice_cb_qp_offset, 0);
1513 infer(slice_cr_qp_offset, 0);
1515 if (
pps->pps_slice_act_qp_offsets_present_flag) {
1516 se(slice_act_y_qp_offset,
1517 -12 - (
pps->pps_act_y_qp_offset_plus5 - 5),
1518 +12 - (
pps->pps_act_y_qp_offset_plus5 - 5));
1519 se(slice_act_cb_qp_offset,
1520 -12 - (
pps->pps_act_cb_qp_offset_plus5 - 5),
1521 +12 - (
pps->pps_act_cb_qp_offset_plus5 - 5));
1522 se(slice_act_cr_qp_offset,
1523 -12 - (
pps->pps_act_cr_qp_offset_plus3 - 3),
1524 +12 - (
pps->pps_act_cr_qp_offset_plus3 - 3));
1526 infer(slice_act_y_qp_offset, 0);
1527 infer(slice_act_cb_qp_offset, 0);
1528 infer(slice_act_cr_qp_offset, 0);
1530 if (
pps->chroma_qp_offset_list_enabled_flag)
1531 flag(cu_chroma_qp_offset_enabled_flag);
1533 infer(cu_chroma_qp_offset_enabled_flag, 0);
1535 if (
pps->deblocking_filter_override_enabled_flag)
1536 flag(deblocking_filter_override_flag);
1538 infer(deblocking_filter_override_flag, 0);
1539 if (current->deblocking_filter_override_flag) {
1540 flag(slice_deblocking_filter_disabled_flag);
1541 if (!current->slice_deblocking_filter_disabled_flag) {
1542 se(slice_beta_offset_div2, -6, +6);
1543 se(slice_tc_offset_div2, -6, +6);
1545 infer(slice_beta_offset_div2,
pps->pps_beta_offset_div2);
1546 infer(slice_tc_offset_div2,
pps->pps_tc_offset_div2);
1549 infer(slice_deblocking_filter_disabled_flag,
1550 pps->pps_deblocking_filter_disabled_flag);
1551 infer(slice_beta_offset_div2,
pps->pps_beta_offset_div2);
1552 infer(slice_tc_offset_div2,
pps->pps_tc_offset_div2);
1554 if (
pps->pps_loop_filter_across_slices_enabled_flag &&
1555 (current->slice_sao_luma_flag || current->slice_sao_chroma_flag ||
1556 !current->slice_deblocking_filter_disabled_flag))
1557 flag(slice_loop_filter_across_slices_enabled_flag);
1559 infer(slice_loop_filter_across_slices_enabled_flag,
1560 pps->pps_loop_filter_across_slices_enabled_flag);
1563 if (
pps->tiles_enabled_flag ||
pps->entropy_coding_sync_enabled_flag) {
1564 unsigned int num_entry_point_offsets_limit;
1565 if (!
pps->tiles_enabled_flag &&
pps->entropy_coding_sync_enabled_flag)
1566 num_entry_point_offsets_limit = pic_height_in_ctbs_y - 1;
1567 else if (
pps->tiles_enabled_flag && !
pps->entropy_coding_sync_enabled_flag)
1568 num_entry_point_offsets_limit =
1569 (
pps->num_tile_columns_minus1 + 1) * (
pps->num_tile_rows_minus1 + 1);
1571 num_entry_point_offsets_limit =
1572 (
pps->num_tile_columns_minus1 + 1) * pic_height_in_ctbs_y - 1;
1573 ue(num_entry_point_offsets, 0, num_entry_point_offsets_limit);
1577 "%"PRIu16
".\n", current->num_entry_point_offsets);
1581 if (current->num_entry_point_offsets > 0) {
1582 ue(offset_len_minus1, 0, 31);
1583 for (
i = 0;
i < current->num_entry_point_offsets;
i++)
1584 ubs(current->offset_len_minus1 + 1, entry_point_offset_minus1[
i], 1,
i);
1588 if (
pps->slice_segment_header_extension_present_flag) {
1589 ue(slice_segment_header_extension_length, 0, 256);
1590 for (
i = 0;
i < current->slice_segment_header_extension_length;
i++)
1591 us(8, slice_segment_header_extension_data_byte[
i], 0x00, 0xff, 1,
i);
1601 uint32_t *payload_size,
1610 int start_pos, end_pos;
1614 HEADER(
"Buffering Period");
1618 sps = h265->
sps[current->bp_seq_parameter_set_id];
1621 current->bp_seq_parameter_set_id);
1626 if (!
sps->vui_parameters_present_flag ||
1627 !
sps->vui.vui_hrd_parameters_present_flag) {
1629 "HRD parameters to be present in SPS.\n");
1632 hrd = &
sps->vui.hrd_parameters;
1636 "NAL or VCL HRD parameters to be present.\n");
1641 flag(irap_cpb_params_present_flag);
1643 infer(irap_cpb_params_present_flag, 0);
1644 if (current->irap_cpb_params_present_flag) {
1646 ub(length, cpb_delay_offset);
1648 ub(length, dpb_delay_offset);
1650 infer(cpb_delay_offset, 0);
1651 infer(dpb_delay_offset, 0);
1654 flag(concatenation_flag);
1657 ub(length, au_cpb_removal_delay_delta_minus1);
1663 ubs(length, nal_initial_cpb_removal_delay[
i], 1,
i);
1664 ubs(length, nal_initial_cpb_removal_offset[
i], 1,
i);
1667 current->irap_cpb_params_present_flag) {
1668 ubs(length, nal_initial_alt_cpb_removal_delay[
i], 1,
i);
1669 ubs(length, nal_initial_alt_cpb_removal_offset[
i], 1,
i);
1677 ubs(length, vcl_initial_cpb_removal_delay[
i], 1,
i);
1678 ubs(length, vcl_initial_cpb_removal_offset[
i], 1,
i);
1681 current->irap_cpb_params_present_flag) {
1682 ubs(length, vcl_initial_alt_cpb_removal_delay[
i], 1,
i);
1683 ubs(length, vcl_initial_alt_cpb_removal_offset[
i], 1,
i);
1691 end_pos - start_pos))
1692 flag(use_alt_cpb_params_flag);
1694 infer(use_alt_cpb_params_flag, 0);
1698 if (current->use_alt_cpb_params_flag || *more_data) {
1699 flag(use_alt_cpb_params_flag);
1716 int err, expected_source_scan_type,
i, length;
1718 HEADER(
"Picture Timing");
1723 "No active SPS for pic_timing.\n");
1727 expected_source_scan_type = 2 -
1728 2 *
sps->profile_tier_level.general_interlaced_source_flag -
1729 sps->profile_tier_level.general_progressive_source_flag;
1731 if (
sps->vui.frame_field_info_present_flag) {
1732 u(4, pic_struct, 0, 12);
1733 u(2, source_scan_type,
1734 expected_source_scan_type >= 0 ? expected_source_scan_type : 0,
1735 expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1736 flag(duplicate_flag);
1738 infer(pic_struct, 0);
1739 infer(source_scan_type,
1740 expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1741 infer(duplicate_flag, 0);
1744 if (
sps->vui_parameters_present_flag &&
1745 sps->vui.vui_hrd_parameters_present_flag)
1746 hrd = &
sps->vui.hrd_parameters;
1752 ub(length, au_cpb_removal_delay_minus1);
1755 ub(length, pic_dpb_output_delay);
1759 ub(length, pic_dpb_output_du_delay);
1766 flag(du_common_cpb_removal_delay_flag);
1769 if (current->du_common_cpb_removal_delay_flag)
1770 ub(length, du_common_cpb_removal_delay_increment_minus1);
1772 for (
i = 0;
i <= current->num_decoding_units_minus1;
i++) {
1773 ues(num_nalus_in_du_minus1[
i],
1775 if (!current->du_common_cpb_removal_delay_flag &&
1776 i < current->num_decoding_units_minus1)
1777 ubs(length, du_cpb_removal_delay_increment_minus1[
i], 1,
i);
1790 HEADER(
"Pan-Scan Rectangle");
1792 ue(pan_scan_rect_id, 0, UINT32_MAX - 1);
1793 flag(pan_scan_rect_cancel_flag);
1795 if (!current->pan_scan_rect_cancel_flag) {
1796 ue(pan_scan_cnt_minus1, 0, 2);
1798 for (
i = 0;
i <= current->pan_scan_cnt_minus1;
i++) {
1799 ses(pan_scan_rect_left_offset[
i], INT32_MIN + 1, INT32_MAX, 1,
i);
1800 ses(pan_scan_rect_right_offset[
i], INT32_MIN + 1, INT32_MAX, 1,
i);
1801 ses(pan_scan_rect_top_offset[
i], INT32_MIN + 1, INT32_MAX, 1,
i);
1802 ses(pan_scan_rect_bottom_offset[
i], INT32_MIN + 1, INT32_MAX, 1,
i);
1805 flag(pan_scan_rect_persistence_flag);
1813 uint32_t *payload_size)
1817 HEADER(
"User Data Registered ITU-T T.35");
1819 u(8, itu_t_t35_country_code, 0x00, 0xff);
1820 if (current->itu_t_t35_country_code != 0xff)
1823 u(8, itu_t_t35_country_code_extension_byte, 0x00, 0xff);
1828 if (*payload_size <
i) {
1830 "Invalid SEI user data registered payload.\n");
1833 current->data_length = *payload_size -
i;
1835 *payload_size =
i + current->data_length;
1838 allocate(current->data, current->data_length);
1839 for (j = 0; j < current->data_length; j++)
1840 xu(8, itu_t_t35_payload_byte[
i], current->data[j], 0x00, 0xff, 1,
i + j);
1847 uint32_t *payload_size)
1851 HEADER(
"User Data Unregistered");
1854 if (*payload_size < 16) {
1856 "Invalid SEI user data unregistered payload.\n");
1859 current->data_length = *payload_size - 16;
1861 *payload_size = 16 + current->data_length;
1864 for (
i = 0;
i < 16;
i++)
1865 us(8, uuid_iso_iec_11578[
i], 0x00, 0xff, 1,
i);
1867 allocate(current->data, current->data_length);
1869 for (
i = 0;
i < current->data_length;
i++)
1870 xu(8, user_data_payload_byte[
i], current->data[
i], 0x00, 0xff, 1,
i);
1880 HEADER(
"Recovery Point");
1882 se(recovery_poc_cnt, -32768, 32767);
1884 flag(exact_match_flag);
1885 flag(broken_link_flag);
1895 HEADER(
"Display Orientation");
1897 flag(display_orientation_cancel_flag);
1898 if (!current->display_orientation_cancel_flag) {
1901 ub(16, anticlockwise_rotation);
1902 flag(display_orientation_persistence_flag);
1915 HEADER(
"Active Parameter Sets");
1918 vps = h265->
vps[current->active_video_parameter_set_id];
1921 "parameter sets.\n", current->active_video_parameter_set_id);
1926 flag(self_contained_cvs_flag);
1927 flag(no_parameter_set_update_flag);
1930 for (
i = 0;
i <= current->num_sps_ids_minus1;
i++)
1933 for (
i =
vps->vps_base_layer_internal_flag;
1934 i <=
FFMIN(62,
vps->vps_max_layers_minus1);
i++) {
1935 ues(layer_sps_idx[
i], 0, current->num_sps_ids_minus1, 1,
i);
1938 h265->
active_sps = h265->
sps[current->active_seq_parameter_set_id[current->layer_sps_idx[0]]];
1951 HEADER(
"Decoded Picture Hash");
1955 "No active SPS for decoded picture hash.\n");
1959 u(8, hash_type, 0, 2);
1961 for (
c = 0;
c < (
sps->chroma_format_idc == 0 ? 1 : 3);
c++) {
1962 if (current->hash_type == 0) {
1963 for (
i = 0;
i < 16;
i++)
1964 us(8, picture_md5[
c][
i], 0x00, 0xff, 2,
c,
i);
1965 }
else if (current->hash_type == 1) {
1966 us(16, picture_crc[
c], 0x0000, 0xffff, 1,
c);
1967 }
else if (current->hash_type == 2) {
1968 us(32, picture_checksum[
c], 0x00000000, 0xffffffff, 1,
c);
1982 u(2, num_clock_ts, 1, 3);
1984 for (
i = 0;
i < current->num_clock_ts;
i++) {
1985 flags(clock_timestamp_flag[
i], 1,
i);
1987 if (current->clock_timestamp_flag[
i]) {
1988 flags(units_field_based_flag[
i], 1,
i);
1989 us(5, counting_type[
i], 0, 6, 1,
i);
1990 flags(full_timestamp_flag[
i], 1,
i);
1991 flags(discontinuity_flag[
i], 1,
i);
1992 flags(cnt_dropped_flag[
i], 1,
i);
1994 ubs(9, n_frames[
i], 1,
i);
1996 if (current->full_timestamp_flag[
i]) {
1997 us(6, seconds_value[
i], 0, 59, 1,
i);
1998 us(6, minutes_value[
i], 0, 59, 1,
i);
1999 us(5, hours_value[
i], 0, 23, 1,
i);
2002 if (current->seconds_flag[
i]) {
2003 us(6, seconds_value[
i], 0, 59, 1,
i);
2005 if (current->minutes_flag[
i]) {
2006 us(6, minutes_value[
i], 0, 59, 1,
i);
2008 if (current->hours_flag[
i])
2009 us(5, hours_value[
i], 0, 23, 1,
i);
2014 ubs(5, time_offset_length[
i], 1,
i);
2015 if (current->time_offset_length[
i] > 0)
2016 ibs(current->time_offset_length[
i], time_offset_value[
i], 1,
i);
2018 infer(time_offset_value[
i], 0);
2030 HEADER(
"Mastering Display Colour Volume");
2032 for (
c = 0;
c < 3;
c++) {
2033 us(16, display_primaries_x[
c], 0, 50000, 1,
c);
2034 us(16, display_primaries_y[
c], 0, 50000, 1,
c);
2037 u(16, white_point_x, 0, 50000);
2038 u(16, white_point_y, 0, 50000);
2040 u(32, max_display_mastering_luminance,
2042 u(32, min_display_mastering_luminance,
2043 0, current->max_display_mastering_luminance - 1);
2053 HEADER(
"Content Light Level");
2055 ub(16, max_content_light_level);
2056 ub(16, max_pic_average_light_level);
2067 HEADER(
"Alternative Transfer Characteristics");
2069 ub(8, preferred_transfer_characteristics);
2080 HEADER(
"Alpha Channel Information");
2082 flag(alpha_channel_cancel_flag);
2083 if (!current->alpha_channel_cancel_flag) {
2084 ub(3, alpha_channel_use_idc);
2085 ub(3, alpha_channel_bit_depth_minus8);
2086 length = current->alpha_channel_bit_depth_minus8 + 9;
2087 ub(length, alpha_transparent_value);
2088 ub(length, alpha_opaque_value);
2089 flag(alpha_channel_incr_flag);
2090 flag(alpha_channel_clip_flag);
2091 if (current->alpha_channel_clip_flag)
2092 flag(alpha_channel_clip_type_flag);
2094 infer(alpha_channel_use_idc, 2);
2095 infer(alpha_channel_incr_flag, 0);
2096 infer(alpha_channel_clip_flag, 0);
2107 size_t byte_length, k;
2111 int bits_left, payload_zero_bits;
2116 bits_left = 8 * payload_size - cur_pos;
2121 if (!payload_zero_bits)
2123 payload_zero_bits =
ff_ctz(payload_zero_bits);
2124 current->bit_length = bits_left - payload_zero_bits - 1;
2125 allocate(current->data, (current->bit_length + 7) / 8);
2128 byte_length = (current->bit_length + 7) / 8;
2129 for (k = 0; k < byte_length; k++) {
2130 int length =
FFMIN(current->bit_length - k * 8, 8);
2131 xu(length, reserved_payload_extension_data, current->data[k],
2142 int start_position, current_position;
2143 int more_data = !!current->extension_data.bit_length;
2151 switch (current->payload_type) {
2152 #define SEI_TYPE_CHECK_VALID(name, prefix_valid, suffix_valid) do { \
2153 if (prefix && !prefix_valid) { \
2154 av_log(ctx->log_ctx, AV_LOG_ERROR, "SEI type %s invalid " \
2155 "as prefix SEI!\n", #name); \
2156 return AVERROR_INVALIDDATA; \
2158 if (!prefix && !suffix_valid) { \
2159 av_log(ctx->log_ctx, AV_LOG_ERROR, "SEI type %s invalid " \
2160 "as suffix SEI!\n", #name); \
2161 return AVERROR_INVALIDDATA; \
2164 #define SEI_TYPE_N(type, prefix_valid, suffix_valid, name) \
2165 case HEVC_SEI_TYPE_ ## type: \
2166 SEI_TYPE_CHECK_VALID(name, prefix_valid, suffix_valid); \
2167 CHECK(FUNC(sei_ ## name)(ctx, rw, ¤t->payload.name)); \
2169 #define SEI_TYPE_S(type, prefix_valid, suffix_valid, name) \
2170 case HEVC_SEI_TYPE_ ## type: \
2171 SEI_TYPE_CHECK_VALID(name, prefix_valid, suffix_valid); \
2172 CHECK(FUNC(sei_ ## name)(ctx, rw, ¤t->payload.name, \
2173 ¤t->payload_size)); \
2175 #define SEI_TYPE_E(type, prefix_valid, suffix_valid, name) \
2176 case HEVC_SEI_TYPE_ ## type: \
2177 SEI_TYPE_CHECK_VALID(name, prefix_valid, suffix_valid); \
2178 CHECK(FUNC(sei_ ## name)(ctx, rw, ¤t->payload.name, \
2179 ¤t->payload_size, \
2183 SEI_TYPE_E(BUFFERING_PERIOD, 1, 0, buffering_period);
2184 SEI_TYPE_N(PICTURE_TIMING, 1, 0, pic_timing);
2185 SEI_TYPE_N(PAN_SCAN_RECT, 1, 0, pan_scan_rect);
2187 1, 1, user_data_registered);
2188 SEI_TYPE_S(USER_DATA_UNREGISTERED, 1, 1, user_data_unregistered);
2189 SEI_TYPE_N(RECOVERY_POINT, 1, 0, recovery_point);
2190 SEI_TYPE_N(DISPLAY_ORIENTATION, 1, 0, display_orientation);
2191 SEI_TYPE_N(ACTIVE_PARAMETER_SETS, 1, 0, active_parameter_sets);
2192 SEI_TYPE_N(DECODED_PICTURE_HASH, 0, 1, decoded_picture_hash);
2194 SEI_TYPE_N(MASTERING_DISPLAY_INFO, 1, 0, mastering_display);
2195 SEI_TYPE_N(CONTENT_LIGHT_LEVEL_INFO, 1, 0, content_light_level);
2196 SEI_TYPE_N(ALTERNATIVE_TRANSFER_CHARACTERISTICS,
2197 1, 0, alternative_transfer_characteristics);
2198 SEI_TYPE_N(ALPHA_CHANNEL_INFO, 1, 0, alpha_channel_info);
2204 current->payload.other.data_length = current->payload_size;
2206 allocate(current->payload.other.data, current->payload.other.data_length);
2208 for (
i = 0;
i < current->payload_size;
i++)
2209 xu(8, payload_byte[
i], current->payload.other.data[
i], 0, 255,
2217 if (current_position < 8 * current->payload_size) {
2223 current->payload_size, current_position));
2224 fixed(1, bit_equal_to_one, 1);
2226 fixed(1, bit_equal_to_zero, 0);
2230 current->payload_size = (
put_bits_count(rw) - start_position) >> 3;
2242 HEADER(
"Prefix Supplemental Enhancement Information");
2244 HEADER(
"Suffix Supplemental Enhancement Information");
2252 uint32_t payload_type = 0;
2253 uint32_t payload_size = 0;
2257 fixed(8, ff_byte, 0xff);
2258 payload_type += 255;
2260 xu(8, last_payload_type_byte,
tmp, 0, 254, 0);
2261 payload_type +=
tmp;
2264 fixed(8, ff_byte, 0xff);
2265 payload_size += 255;
2267 xu(8, last_payload_size_byte,
tmp, 0, 254, 0);
2268 payload_size +=
tmp;
2270 current->payload[k].payload_type = payload_type;
2271 current->payload[k].payload_size = payload_size;
2273 current->payload_count++;
2281 "SEI message: found %d.\n", k);
2285 for (k = 0; k < current->payload_count; k++) {
2294 need_size = !current->payload[k].payload_size;
2295 for (
i = 0;
i < 1 + need_size;
i++) {
2298 tmp = current->payload[k].payload_type;
2299 while (
tmp >= 255) {
2300 fixed(8, ff_byte, 0xff);
2303 xu(8, last_payload_type_byte,
tmp, 0, 254, 0);
2305 tmp = current->payload[k].payload_size;
2306 while (
tmp >= 255) {
2307 fixed(8, ff_byte, 0xff);
2310 xu(8, last_payload_size_byte,
tmp, 0, 254, 0);