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);
147 flag(general_inbld_flag);
149 fixed(1, general_reserved_zero_bit, 0);
151 #undef profile_compatible
154 ub(8, general_level_idc);
156 for (
i = 0;
i < max_num_sub_layers_minus1;
i++) {
157 flags(sub_layer_profile_present_flag[
i], 1,
i);
158 flags(sub_layer_level_present_flag[
i], 1,
i);
161 if (max_num_sub_layers_minus1 > 0) {
162 for (
i = max_num_sub_layers_minus1;
i < 8;
i++)
163 fixed(2, reserved_zero_2bits, 0);
166 for (
i = 0;
i < max_num_sub_layers_minus1;
i++) {
167 if (current->sub_layer_profile_present_flag[
i]) {
168 us(2, sub_layer_profile_space[
i], 0, 0, 1,
i);
169 flags(sub_layer_tier_flag[
i], 1,
i);
170 ubs(5, sub_layer_profile_idc[
i], 1,
i);
172 for (j = 0; j < 32; j++)
173 flags(sub_layer_profile_compatibility_flag[
i][j], 2,
i, j);
175 flags(sub_layer_progressive_source_flag[
i], 1,
i);
176 flags(sub_layer_interlaced_source_flag[
i], 1,
i);
177 flags(sub_layer_non_packed_constraint_flag[
i], 1,
i);
178 flags(sub_layer_frame_only_constraint_flag[
i], 1,
i);
180 #define profile_compatible(x) (current->sub_layer_profile_idc[i] == (x) || \
181 current->sub_layer_profile_compatibility_flag[i][x])
186 flags(sub_layer_max_12bit_constraint_flag[
i], 1,
i);
187 flags(sub_layer_max_10bit_constraint_flag[
i], 1,
i);
188 flags(sub_layer_max_8bit_constraint_flag[
i], 1,
i);
189 flags(sub_layer_max_422chroma_constraint_flag[
i], 1,
i);
190 flags(sub_layer_max_420chroma_constraint_flag[
i], 1,
i);
191 flags(sub_layer_max_monochrome_constraint_flag[
i], 1,
i);
192 flags(sub_layer_intra_constraint_flag[
i], 1,
i);
193 flags(sub_layer_one_picture_only_constraint_flag[
i], 1,
i);
194 flags(sub_layer_lower_bit_rate_constraint_flag[
i], 1,
i);
198 flags(sub_layer_max_14bit_constraint_flag[
i], 1,
i);
199 fixed(24, sub_layer_reserved_zero_33bits, 0);
200 fixed( 9, sub_layer_reserved_zero_33bits, 0);
202 fixed(24, sub_layer_reserved_zero_34bits, 0);
203 fixed(10, sub_layer_reserved_zero_34bits, 0);
206 fixed(7, sub_layer_reserved_zero_7bits, 0);
207 flags(sub_layer_one_picture_only_constraint_flag[
i], 1,
i);
208 fixed(24, sub_layer_reserved_zero_43bits, 0);
209 fixed(11, sub_layer_reserved_zero_43bits, 0);
211 fixed(24, sub_layer_reserved_zero_43bits, 0);
212 fixed(19, sub_layer_reserved_zero_43bits, 0);
219 flags(sub_layer_inbld_flag[
i], 1,
i);
221 fixed(1, sub_layer_reserved_zero_bit, 0);
223 #undef profile_compatible
225 if (current->sub_layer_level_present_flag[
i])
226 ubs(8, sub_layer_level_idc[
i], 1,
i);
234 int nal,
int sub_layer_id)
240 current = &hrd->nal_sub_layer_hrd_parameters[sub_layer_id];
242 current = &hrd->vcl_sub_layer_hrd_parameters[sub_layer_id];
244 for (
i = 0;
i <= hrd->cpb_cnt_minus1[sub_layer_id];
i++) {
245 ues(bit_rate_value_minus1[
i], 0, UINT32_MAX - 1, 1,
i);
246 ues(cpb_size_value_minus1[
i], 0, UINT32_MAX - 1, 1,
i);
247 if (hrd->sub_pic_hrd_params_present_flag) {
248 ues(cpb_size_du_value_minus1[
i], 0, UINT32_MAX - 1, 1,
i);
249 ues(bit_rate_du_value_minus1[
i], 0, UINT32_MAX - 1, 1,
i);
259 int max_num_sub_layers_minus1)
263 if (common_inf_present_flag) {
264 flag(nal_hrd_parameters_present_flag);
265 flag(vcl_hrd_parameters_present_flag);
267 if (current->nal_hrd_parameters_present_flag ||
268 current->vcl_hrd_parameters_present_flag) {
269 flag(sub_pic_hrd_params_present_flag);
270 if (current->sub_pic_hrd_params_present_flag) {
271 ub(8, tick_divisor_minus2);
272 ub(5, du_cpb_removal_delay_increment_length_minus1);
273 flag(sub_pic_cpb_params_in_pic_timing_sei_flag);
274 ub(5, dpb_output_delay_du_length_minus1);
277 ub(4, bit_rate_scale);
278 ub(4, cpb_size_scale);
279 if (current->sub_pic_hrd_params_present_flag)
280 ub(4, cpb_size_du_scale);
282 ub(5, initial_cpb_removal_delay_length_minus1);
283 ub(5, au_cpb_removal_delay_length_minus1);
284 ub(5, dpb_output_delay_length_minus1);
286 infer(sub_pic_hrd_params_present_flag, 0);
288 infer(initial_cpb_removal_delay_length_minus1, 23);
289 infer(au_cpb_removal_delay_length_minus1, 23);
290 infer(dpb_output_delay_length_minus1, 23);
294 for (
i = 0;
i <= max_num_sub_layers_minus1;
i++) {
295 flags(fixed_pic_rate_general_flag[
i], 1,
i);
297 if (!current->fixed_pic_rate_general_flag[
i])
298 flags(fixed_pic_rate_within_cvs_flag[
i], 1,
i);
300 infer(fixed_pic_rate_within_cvs_flag[
i], 1);
302 if (current->fixed_pic_rate_within_cvs_flag[
i]) {
303 ues(elemental_duration_in_tc_minus1[
i], 0, 2047, 1,
i);
304 infer(low_delay_hrd_flag[
i], 0);
306 flags(low_delay_hrd_flag[
i], 1,
i);
308 if (!current->low_delay_hrd_flag[
i])
309 ues(cpb_cnt_minus1[
i], 0, 31, 1,
i);
311 infer(cpb_cnt_minus1[
i], 0);
313 if (current->nal_hrd_parameters_present_flag)
315 if (current->vcl_hrd_parameters_present_flag)
327 flag(aspect_ratio_info_present_flag);
328 if (current->aspect_ratio_info_present_flag) {
329 ub(8, aspect_ratio_idc);
330 if (current->aspect_ratio_idc == 255) {
335 infer(aspect_ratio_idc, 0);
338 flag(overscan_info_present_flag);
339 if (current->overscan_info_present_flag)
340 flag(overscan_appropriate_flag);
342 flag(video_signal_type_present_flag);
343 if (current->video_signal_type_present_flag) {
345 flag(video_full_range_flag);
346 flag(colour_description_present_flag);
347 if (current->colour_description_present_flag) {
348 ub(8, colour_primaries);
350 ub(8, matrix_coefficients);
352 infer(colour_primaries, 2);
354 infer(matrix_coefficients, 2);
357 infer(video_format, 5);
358 infer(video_full_range_flag, 0);
359 infer(colour_primaries, 2);
361 infer(matrix_coefficients, 2);
364 flag(chroma_loc_info_present_flag);
365 if (current->chroma_loc_info_present_flag) {
366 ue(chroma_sample_loc_type_top_field, 0, 5);
367 ue(chroma_sample_loc_type_bottom_field, 0, 5);
369 infer(chroma_sample_loc_type_top_field, 0);
370 infer(chroma_sample_loc_type_bottom_field, 0);
373 flag(neutral_chroma_indication_flag);
374 flag(field_seq_flag);
375 flag(frame_field_info_present_flag);
377 flag(default_display_window_flag);
378 if (current->default_display_window_flag) {
379 ue(def_disp_win_left_offset, 0, 16384);
380 ue(def_disp_win_right_offset, 0, 16384);
381 ue(def_disp_win_top_offset, 0, 16384);
382 ue(def_disp_win_bottom_offset, 0, 16384);
385 flag(vui_timing_info_present_flag);
386 if (current->vui_timing_info_present_flag) {
387 u(32, vui_num_units_in_tick, 1, UINT32_MAX);
388 u(32, vui_time_scale, 1, UINT32_MAX);
389 flag(vui_poc_proportional_to_timing_flag);
390 if (current->vui_poc_proportional_to_timing_flag)
391 ue(vui_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
393 flag(vui_hrd_parameters_present_flag);
394 if (current->vui_hrd_parameters_present_flag) {
396 1,
sps->sps_max_sub_layers_minus1));
400 flag(bitstream_restriction_flag);
401 if (current->bitstream_restriction_flag) {
402 flag(tiles_fixed_structure_flag);
403 flag(motion_vectors_over_pic_boundaries_flag);
404 flag(restricted_ref_pic_lists_flag);
405 ue(min_spatial_segmentation_idc, 0, 4095);
406 ue(max_bytes_per_pic_denom, 0, 16);
407 ue(max_bits_per_min_cu_denom, 0, 16);
408 ue(log2_max_mv_length_horizontal, 0, 16);
409 ue(log2_max_mv_length_vertical, 0, 16);
411 infer(tiles_fixed_structure_flag, 0);
412 infer(motion_vectors_over_pic_boundaries_flag, 1);
413 infer(min_spatial_segmentation_idc, 0);
414 infer(max_bytes_per_pic_denom, 2);
415 infer(max_bits_per_min_cu_denom, 1);
416 infer(log2_max_mv_length_horizontal, 15);
417 infer(log2_max_mv_length_vertical, 15);
428 HEADER(
"Video Parameter Set");
432 ub(4, vps_video_parameter_set_id);
434 flag(vps_base_layer_internal_flag);
435 flag(vps_base_layer_available_flag);
438 flag(vps_temporal_id_nesting_flag);
440 if (current->vps_max_sub_layers_minus1 == 0 &&
441 current->vps_temporal_id_nesting_flag != 1) {
443 "vps_temporal_id_nesting_flag must be 1 if "
444 "vps_max_sub_layers_minus1 is 0.\n");
448 fixed(16, vps_reserved_0xffff_16bits, 0xffff);
451 1, current->vps_max_sub_layers_minus1));
453 flag(vps_sub_layer_ordering_info_present_flag);
454 for (
i = (current->vps_sub_layer_ordering_info_present_flag ?
455 0 : current->vps_max_sub_layers_minus1);
456 i <= current->vps_max_sub_layers_minus1;
i++) {
457 ues(vps_max_dec_pic_buffering_minus1[
i],
459 ues(vps_max_num_reorder_pics[
i],
460 0, current->vps_max_dec_pic_buffering_minus1[
i], 1,
i);
461 ues(vps_max_latency_increase_plus1[
i],
462 0, UINT32_MAX - 1, 1,
i);
464 if (!current->vps_sub_layer_ordering_info_present_flag) {
465 for (
i = 0;
i < current->vps_max_sub_layers_minus1;
i++) {
466 infer(vps_max_dec_pic_buffering_minus1[
i],
467 current->vps_max_dec_pic_buffering_minus1[current->vps_max_sub_layers_minus1]);
468 infer(vps_max_num_reorder_pics[
i],
469 current->vps_max_num_reorder_pics[current->vps_max_sub_layers_minus1]);
470 infer(vps_max_latency_increase_plus1[
i],
471 current->vps_max_latency_increase_plus1[current->vps_max_sub_layers_minus1]);
477 for (
i = 1;
i <= current->vps_num_layer_sets_minus1;
i++) {
478 for (j = 0; j <= current->vps_max_layer_id; j++)
479 flags(layer_id_included_flag[
i][j], 2,
i, j);
481 for (j = 0; j <= current->vps_max_layer_id; j++)
482 infer(layer_id_included_flag[0][j], j == 0);
484 flag(vps_timing_info_present_flag);
485 if (current->vps_timing_info_present_flag) {
486 u(32, vps_num_units_in_tick, 1, UINT32_MAX);
487 u(32, vps_time_scale, 1, UINT32_MAX);
488 flag(vps_poc_proportional_to_timing_flag);
489 if (current->vps_poc_proportional_to_timing_flag)
490 ue(vps_num_ticks_poc_diff_one_minus1, 0, UINT32_MAX - 1);
491 ue(vps_num_hrd_parameters, 0, current->vps_num_layer_sets_minus1 + 1);
492 for (
i = 0;
i < current->vps_num_hrd_parameters;
i++) {
493 ues(hrd_layer_set_idx[
i],
494 current->vps_base_layer_internal_flag ? 0 : 1,
495 current->vps_num_layer_sets_minus1, 1,
i);
497 flags(cprms_present_flag[
i], 1,
i);
499 infer(cprms_present_flag[0], 1);
502 current->cprms_present_flag[
i],
503 current->vps_max_sub_layers_minus1));
507 flag(vps_extension_flag);
508 if (current->vps_extension_flag)
523 flag(inter_ref_pic_set_prediction_flag);
525 infer(inter_ref_pic_set_prediction_flag, 0);
527 if (current->inter_ref_pic_set_prediction_flag) {
528 unsigned int ref_rps_idx, num_delta_pocs, num_ref_pics;
530 int delta_rps, d_poc;
536 if (st_rps_idx ==
sps->num_short_term_ref_pic_sets)
537 ue(delta_idx_minus1, 0, st_rps_idx - 1);
539 infer(delta_idx_minus1, 0);
541 ref_rps_idx = st_rps_idx - (current->delta_idx_minus1 + 1);
542 ref = &
sps->st_ref_pic_set[ref_rps_idx];
543 num_delta_pocs =
ref->num_negative_pics +
ref->num_positive_pics;
546 flag(delta_rps_sign);
547 ue(abs_delta_rps_minus1, 0, INT16_MAX);
548 delta_rps = (1 - 2 * current->delta_rps_sign) *
549 (current->abs_delta_rps_minus1 + 1);
552 for (j = 0; j <= num_delta_pocs; j++) {
553 flags(used_by_curr_pic_flag[j], 1, j);
554 if (!current->used_by_curr_pic_flag[j])
555 flags(use_delta_flag[j], 1, j);
557 infer(use_delta_flag[j], 1);
558 if (current->use_delta_flag[j])
563 "short-term ref pic set %d "
564 "contains too many pictures.\n", st_rps_idx);
585 for (
i = 0;
i <
ref->num_negative_pics;
i++) {
586 d_poc -=
ref->delta_poc_s0_minus1[
i] + 1;
587 ref_delta_poc_s0[
i] = d_poc;
590 for (
i = 0;
i <
ref->num_positive_pics;
i++) {
591 d_poc +=
ref->delta_poc_s1_minus1[
i] + 1;
592 ref_delta_poc_s1[
i] = d_poc;
596 for (j =
ref->num_positive_pics - 1; j >= 0; j--) {
597 d_poc = ref_delta_poc_s1[j] + delta_rps;
598 if (d_poc < 0 && current->use_delta_flag[
ref->num_negative_pics + j]) {
599 delta_poc_s0[
i] = d_poc;
600 used_by_curr_pic_s0[
i++] =
601 current->used_by_curr_pic_flag[
ref->num_negative_pics + j];
604 if (delta_rps < 0 && current->use_delta_flag[num_delta_pocs]) {
605 delta_poc_s0[
i] = delta_rps;
606 used_by_curr_pic_s0[
i++] =
607 current->used_by_curr_pic_flag[num_delta_pocs];
609 for (j = 0; j <
ref->num_negative_pics; j++) {
610 d_poc = ref_delta_poc_s0[j] + delta_rps;
611 if (d_poc < 0 && current->use_delta_flag[j]) {
612 delta_poc_s0[
i] = d_poc;
613 used_by_curr_pic_s0[
i++] = current->used_by_curr_pic_flag[j];
617 infer(num_negative_pics,
i);
618 for (
i = 0;
i < current->num_negative_pics;
i++) {
619 infer(delta_poc_s0_minus1[
i],
620 -(delta_poc_s0[
i] - (
i == 0 ? 0 : delta_poc_s0[
i - 1])) - 1);
621 infer(used_by_curr_pic_s0_flag[
i], used_by_curr_pic_s0[
i]);
625 for (j =
ref->num_negative_pics - 1; j >= 0; j--) {
626 d_poc = ref_delta_poc_s0[j] + delta_rps;
627 if (d_poc > 0 && current->use_delta_flag[j]) {
628 delta_poc_s1[
i] = d_poc;
629 used_by_curr_pic_s1[
i++] = current->used_by_curr_pic_flag[j];
632 if (delta_rps > 0 && current->use_delta_flag[num_delta_pocs]) {
633 delta_poc_s1[
i] = delta_rps;
634 used_by_curr_pic_s1[
i++] =
635 current->used_by_curr_pic_flag[num_delta_pocs];
637 for (j = 0; j <
ref->num_positive_pics; j++) {
638 d_poc = ref_delta_poc_s1[j] + delta_rps;
639 if (d_poc > 0 && current->use_delta_flag[
ref->num_negative_pics + j]) {
640 delta_poc_s1[
i] = d_poc;
641 used_by_curr_pic_s1[
i++] =
642 current->used_by_curr_pic_flag[
ref->num_negative_pics + j];
646 infer(num_positive_pics,
i);
647 for (
i = 0;
i < current->num_positive_pics;
i++) {
648 infer(delta_poc_s1_minus1[
i],
649 delta_poc_s1[
i] - (
i == 0 ? 0 : delta_poc_s1[
i - 1]) - 1);
650 infer(used_by_curr_pic_s1_flag[
i], used_by_curr_pic_s1[
i]);
654 ue(num_negative_pics, 0, 15);
655 ue(num_positive_pics, 0, 15 - current->num_negative_pics);
657 for (
i = 0;
i < current->num_negative_pics;
i++) {
658 ues(delta_poc_s0_minus1[
i], 0, INT16_MAX, 1,
i);
659 flags(used_by_curr_pic_s0_flag[
i], 1,
i);
662 for (
i = 0;
i < current->num_positive_pics;
i++) {
663 ues(delta_poc_s1_minus1[
i], 0, INT16_MAX, 1,
i);
664 flags(used_by_curr_pic_s1_flag[
i], 1,
i);
674 int sizeId, matrixId;
677 for (sizeId = 0; sizeId < 4; sizeId++) {
678 for (matrixId = 0; matrixId < 6; matrixId += (sizeId == 3 ? 3 : 1)) {
679 flags(scaling_list_pred_mode_flag[sizeId][matrixId],
680 2, sizeId, matrixId);
681 if (!current->scaling_list_pred_mode_flag[sizeId][matrixId]) {
682 ues(scaling_list_pred_matrix_id_delta[sizeId][matrixId],
683 0, sizeId == 3 ? matrixId / 3 : matrixId,
684 2, sizeId, matrixId);
686 n =
FFMIN(64, 1 << (4 + (sizeId << 1)));
688 ses(scaling_list_dc_coef_minus8[sizeId - 2][matrixId], -7, +247,
689 2, sizeId - 2, matrixId);
691 for (
i = 0;
i < n;
i++) {
692 ses(scaling_list_delta_coeff[sizeId][matrixId][
i],
693 -128, +127, 3, sizeId, matrixId,
i);
707 flag(transform_skip_rotation_enabled_flag);
708 flag(transform_skip_context_enabled_flag);
709 flag(implicit_rdpcm_enabled_flag);
710 flag(explicit_rdpcm_enabled_flag);
711 flag(extended_precision_processing_flag);
712 flag(intra_smoothing_disabled_flag);
713 flag(high_precision_offsets_enabled_flag);
714 flag(persistent_rice_adaptation_enabled_flag);
715 flag(cabac_bypass_alignment_enabled_flag);
725 flag(sps_curr_pic_ref_enabled_flag);
727 flag(palette_mode_enabled_flag);
728 if (current->palette_mode_enabled_flag) {
729 ue(palette_max_size, 0, 64);
730 ue(delta_palette_max_predictor_size, 0, 128);
732 flag(sps_palette_predictor_initializer_present_flag);
733 if (current->sps_palette_predictor_initializer_present_flag) {
734 ue(sps_num_palette_predictor_initializer_minus1, 0, 127);
735 for (
comp = 0;
comp < (current->chroma_format_idc ? 3 : 1);
comp++) {
736 int bit_depth =
comp == 0 ? current->bit_depth_luma_minus8 + 8
737 : current->bit_depth_chroma_minus8 + 8;
738 for (
i = 0;
i <= current->sps_num_palette_predictor_initializer_minus1;
i++)
744 u(2, motion_vector_resolution_control_idc, 0, 2);
745 flag(intra_boundary_filtering_disable_flag);
754 infer(aspect_ratio_idc, 0);
756 infer(video_format, 5);
757 infer(video_full_range_flag, 0);
758 infer(colour_primaries, 2);
760 infer(matrix_coefficients, 2);
762 infer(chroma_sample_loc_type_top_field, 0);
763 infer(chroma_sample_loc_type_bottom_field, 0);
765 infer(tiles_fixed_structure_flag, 0);
766 infer(motion_vectors_over_pic_boundaries_flag, 1);
767 infer(min_spatial_segmentation_idc, 0);
768 infer(max_bytes_per_pic_denom, 2);
769 infer(max_bits_per_min_cu_denom, 1);
770 infer(log2_max_mv_length_horizontal, 15);
771 infer(log2_max_mv_length_vertical, 15);
782 unsigned int min_cb_log2_size_y, ctb_log2_size_y,
783 min_cb_size_y, min_tb_log2_size_y;
785 HEADER(
"Sequence Parameter Set");
789 ub(4, sps_video_parameter_set_id);
793 flag(sps_temporal_id_nesting_flag);
795 if (
vps->vps_max_sub_layers_minus1 > current->sps_max_sub_layers_minus1) {
797 "sps_max_sub_layers_minus1 (%d) must be less than or equal to "
798 "vps_max_sub_layers_minus1 (%d).\n",
799 vps->vps_max_sub_layers_minus1,
800 current->sps_max_sub_layers_minus1);
803 if (
vps->vps_temporal_id_nesting_flag &&
804 !current->sps_temporal_id_nesting_flag) {
806 "sps_temporal_id_nesting_flag must be 1 if "
807 "vps_temporal_id_nesting_flag is 1.\n");
813 1, current->sps_max_sub_layers_minus1));
815 ue(sps_seq_parameter_set_id, 0, 15);
817 ue(chroma_format_idc, 0, 3);
818 if (current->chroma_format_idc == 3)
819 flag(separate_colour_plane_flag);
821 infer(separate_colour_plane_flag, 0);
826 flag(conformance_window_flag);
827 if (current->conformance_window_flag) {
828 ue(conf_win_left_offset, 0, current->pic_width_in_luma_samples);
829 ue(conf_win_right_offset, 0, current->pic_width_in_luma_samples);
830 ue(conf_win_top_offset, 0, current->pic_height_in_luma_samples);
831 ue(conf_win_bottom_offset, 0, current->pic_height_in_luma_samples);
833 infer(conf_win_left_offset, 0);
834 infer(conf_win_right_offset, 0);
835 infer(conf_win_top_offset, 0);
836 infer(conf_win_bottom_offset, 0);
839 ue(bit_depth_luma_minus8, 0, 8);
840 ue(bit_depth_chroma_minus8, 0, 8);
842 ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12);
844 flag(sps_sub_layer_ordering_info_present_flag);
845 for (
i = (current->sps_sub_layer_ordering_info_present_flag ?
846 0 : current->sps_max_sub_layers_minus1);
847 i <= current->sps_max_sub_layers_minus1;
i++) {
848 ues(sps_max_dec_pic_buffering_minus1[
i],
850 ues(sps_max_num_reorder_pics[
i],
851 0, current->sps_max_dec_pic_buffering_minus1[
i], 1,
i);
852 ues(sps_max_latency_increase_plus1[
i],
853 0, UINT32_MAX - 1, 1,
i);
855 if (!current->sps_sub_layer_ordering_info_present_flag) {
856 for (
i = 0;
i < current->sps_max_sub_layers_minus1;
i++) {
857 infer(sps_max_dec_pic_buffering_minus1[
i],
858 current->sps_max_dec_pic_buffering_minus1[current->sps_max_sub_layers_minus1]);
859 infer(sps_max_num_reorder_pics[
i],
860 current->sps_max_num_reorder_pics[current->sps_max_sub_layers_minus1]);
861 infer(sps_max_latency_increase_plus1[
i],
862 current->sps_max_latency_increase_plus1[current->sps_max_sub_layers_minus1]);
866 ue(log2_min_luma_coding_block_size_minus3, 0, 3);
867 min_cb_log2_size_y = current->log2_min_luma_coding_block_size_minus3 + 3;
869 ue(log2_diff_max_min_luma_coding_block_size, 0, 3);
870 ctb_log2_size_y = min_cb_log2_size_y +
871 current->log2_diff_max_min_luma_coding_block_size;
873 min_cb_size_y = 1 << min_cb_log2_size_y;
874 if (current->pic_width_in_luma_samples % min_cb_size_y ||
875 current->pic_height_in_luma_samples % min_cb_size_y) {
877 "by MinCbSizeY = %u.\n", current->pic_width_in_luma_samples,
878 current->pic_height_in_luma_samples, min_cb_size_y);
882 ue(log2_min_luma_transform_block_size_minus2, 0, min_cb_log2_size_y - 3);
883 min_tb_log2_size_y = current->log2_min_luma_transform_block_size_minus2 + 2;
885 ue(log2_diff_max_min_luma_transform_block_size,
886 0,
FFMIN(ctb_log2_size_y, 5) - min_tb_log2_size_y);
888 ue(max_transform_hierarchy_depth_inter,
889 0, ctb_log2_size_y - min_tb_log2_size_y);
890 ue(max_transform_hierarchy_depth_intra,
891 0, ctb_log2_size_y - min_tb_log2_size_y);
893 flag(scaling_list_enabled_flag);
894 if (current->scaling_list_enabled_flag) {
895 flag(sps_scaling_list_data_present_flag);
896 if (current->sps_scaling_list_data_present_flag)
899 infer(sps_scaling_list_data_present_flag, 0);
902 flag(amp_enabled_flag);
903 flag(sample_adaptive_offset_enabled_flag);
905 flag(pcm_enabled_flag);
906 if (current->pcm_enabled_flag) {
907 u(4, pcm_sample_bit_depth_luma_minus1,
908 0, current->bit_depth_luma_minus8 + 8 - 1);
909 u(4, pcm_sample_bit_depth_chroma_minus1,
910 0, current->bit_depth_chroma_minus8 + 8 - 1);
912 ue(log2_min_pcm_luma_coding_block_size_minus3,
913 FFMIN(min_cb_log2_size_y, 5) - 3,
FFMIN(ctb_log2_size_y, 5) - 3);
914 ue(log2_diff_max_min_pcm_luma_coding_block_size,
915 0,
FFMIN(ctb_log2_size_y, 5) - (current->log2_min_pcm_luma_coding_block_size_minus3 + 3));
917 flag(pcm_loop_filter_disabled_flag);
921 for (
i = 0;
i < current->num_short_term_ref_pic_sets;
i++)
924 flag(long_term_ref_pics_present_flag);
925 if (current->long_term_ref_pics_present_flag) {
927 for (
i = 0;
i < current->num_long_term_ref_pics_sps;
i++) {
928 ubs(current->log2_max_pic_order_cnt_lsb_minus4 + 4,
929 lt_ref_pic_poc_lsb_sps[
i], 1,
i);
930 flags(used_by_curr_pic_lt_sps_flag[
i], 1,
i);
934 flag(sps_temporal_mvp_enabled_flag);
935 flag(strong_intra_smoothing_enabled_flag);
937 flag(vui_parameters_present_flag);
938 if (current->vui_parameters_present_flag)
943 flag(sps_extension_present_flag);
944 if (current->sps_extension_present_flag) {
945 flag(sps_range_extension_flag);
946 flag(sps_multilayer_extension_flag);
947 flag(sps_3d_extension_flag);
948 flag(sps_scc_extension_flag);
949 ub(4, sps_extension_4bits);
952 if (current->sps_range_extension_flag)
954 if (current->sps_multilayer_extension_flag)
956 if (current->sps_3d_extension_flag)
958 if (current->sps_scc_extension_flag)
960 if (current->sps_extension_4bits)
975 if (current->transform_skip_enabled_flag)
976 ue(log2_max_transform_skip_block_size_minus2, 0, 3);
977 flag(cross_component_prediction_enabled_flag);
979 flag(chroma_qp_offset_list_enabled_flag);
980 if (current->chroma_qp_offset_list_enabled_flag) {
981 ue(diff_cu_chroma_qp_offset_depth,
982 0,
sps->log2_diff_max_min_luma_coding_block_size);
983 ue(chroma_qp_offset_list_len_minus1, 0, 5);
984 for (
i = 0;
i <= current->chroma_qp_offset_list_len_minus1;
i++) {
985 ses(cb_qp_offset_list[
i], -12, +12, 1,
i);
986 ses(cr_qp_offset_list[
i], -12, +12, 1,
i);
990 ue(log2_sao_offset_scale_luma, 0,
FFMAX(0,
sps->bit_depth_luma_minus8 - 2));
991 ue(log2_sao_offset_scale_chroma, 0,
FFMAX(0,
sps->bit_depth_chroma_minus8 - 2));
1001 flag(pps_curr_pic_ref_enabled_flag);
1003 flag(residual_adaptive_colour_transform_enabled_flag);
1004 if (current->residual_adaptive_colour_transform_enabled_flag) {
1005 flag(pps_slice_act_qp_offsets_present_flag);
1006 se(pps_act_y_qp_offset_plus5, -7, +17);
1007 se(pps_act_cb_qp_offset_plus5, -7, +17);
1008 se(pps_act_cr_qp_offset_plus3, -9, +15);
1010 infer(pps_slice_act_qp_offsets_present_flag, 0);
1011 infer(pps_act_y_qp_offset_plus5, 0);
1012 infer(pps_act_cb_qp_offset_plus5, 0);
1013 infer(pps_act_cr_qp_offset_plus3, 0);
1016 flag(pps_palette_predictor_initializer_present_flag);
1017 if (current->pps_palette_predictor_initializer_present_flag) {
1018 ue(pps_num_palette_predictor_initializer, 0, 128);
1019 if (current->pps_num_palette_predictor_initializer > 0) {
1020 flag(monochrome_palette_flag);
1021 ue(luma_bit_depth_entry_minus8, 0, 8);
1022 if (!current->monochrome_palette_flag)
1023 ue(chroma_bit_depth_entry_minus8, 0, 8);
1024 for (
comp = 0;
comp < (current->monochrome_palette_flag ? 1 : 3);
comp++) {
1025 int bit_depth =
comp == 0 ? current->luma_bit_depth_entry_minus8 + 8
1026 : current->chroma_bit_depth_entry_minus8 + 8;
1027 for (
i = 0;
i < current->pps_num_palette_predictor_initializer;
i++)
1043 HEADER(
"Picture Parameter Set");
1047 ue(pps_pic_parameter_set_id, 0, 63);
1048 ue(pps_seq_parameter_set_id, 0, 15);
1049 sps = h265->
sps[current->pps_seq_parameter_set_id];
1052 current->pps_seq_parameter_set_id);
1057 flag(dependent_slice_segments_enabled_flag);
1058 flag(output_flag_present_flag);
1059 ub(3, num_extra_slice_header_bits);
1060 flag(sign_data_hiding_enabled_flag);
1061 flag(cabac_init_present_flag);
1063 ue(num_ref_idx_l0_default_active_minus1, 0, 14);
1064 ue(num_ref_idx_l1_default_active_minus1, 0, 14);
1066 se(init_qp_minus26, -(26 + 6 *
sps->bit_depth_luma_minus8), +25);
1068 flag(constrained_intra_pred_flag);
1069 flag(transform_skip_enabled_flag);
1070 flag(cu_qp_delta_enabled_flag);
1071 if (current->cu_qp_delta_enabled_flag)
1072 ue(diff_cu_qp_delta_depth,
1073 0,
sps->log2_diff_max_min_luma_coding_block_size);
1075 infer(diff_cu_qp_delta_depth, 0);
1077 se(pps_cb_qp_offset, -12, +12);
1078 se(pps_cr_qp_offset, -12, +12);
1079 flag(pps_slice_chroma_qp_offsets_present_flag);
1081 flag(weighted_pred_flag);
1082 flag(weighted_bipred_flag);
1084 flag(transquant_bypass_enabled_flag);
1085 flag(tiles_enabled_flag);
1086 flag(entropy_coding_sync_enabled_flag);
1088 if (current->tiles_enabled_flag) {
1091 flag(uniform_spacing_flag);
1092 if (!current->uniform_spacing_flag) {
1093 for (
i = 0;
i < current->num_tile_columns_minus1;
i++)
1094 ues(column_width_minus1[
i], 0,
sps->pic_width_in_luma_samples, 1,
i);
1095 for (
i = 0;
i < current->num_tile_rows_minus1;
i++)
1096 ues(row_height_minus1[
i], 0,
sps->pic_height_in_luma_samples, 1,
i);
1098 flag(loop_filter_across_tiles_enabled_flag);
1100 infer(num_tile_columns_minus1, 0);
1101 infer(num_tile_rows_minus1, 0);
1104 flag(pps_loop_filter_across_slices_enabled_flag);
1105 flag(deblocking_filter_control_present_flag);
1106 if (current->deblocking_filter_control_present_flag) {
1107 flag(deblocking_filter_override_enabled_flag);
1108 flag(pps_deblocking_filter_disabled_flag);
1109 if (!current->pps_deblocking_filter_disabled_flag) {
1110 se(pps_beta_offset_div2, -6, +6);
1111 se(pps_tc_offset_div2, -6, +6);
1113 infer(pps_beta_offset_div2, 0);
1114 infer(pps_tc_offset_div2, 0);
1117 infer(deblocking_filter_override_enabled_flag, 0);
1118 infer(pps_deblocking_filter_disabled_flag, 0);
1119 infer(pps_beta_offset_div2, 0);
1120 infer(pps_tc_offset_div2, 0);
1123 flag(pps_scaling_list_data_present_flag);
1124 if (current->pps_scaling_list_data_present_flag)
1127 flag(lists_modification_present_flag);
1129 ue(log2_parallel_merge_level_minus2,
1130 0, (
sps->log2_min_luma_coding_block_size_minus3 + 3 +
1131 sps->log2_diff_max_min_luma_coding_block_size - 2));
1133 flag(slice_segment_header_extension_present_flag);
1135 flag(pps_extension_present_flag);
1136 if (current->pps_extension_present_flag) {
1137 flag(pps_range_extension_flag);
1138 flag(pps_multilayer_extension_flag);
1139 flag(pps_3d_extension_flag);
1140 flag(pps_scc_extension_flag);
1141 ub(4, pps_extension_4bits);
1143 if (current->pps_range_extension_flag)
1145 if (current->pps_multilayer_extension_flag)
1147 if (current->pps_3d_extension_flag)
1149 if (current->pps_scc_extension_flag)
1151 if (current->pps_extension_4bits)
1164 HEADER(
"Access Unit Delimiter");
1168 u(3, pic_type, 0, 2);
1177 unsigned int num_pic_total_curr)
1179 unsigned int entry_size;
1182 entry_size =
av_log2(num_pic_total_curr - 1) + 1;
1184 flag(ref_pic_list_modification_flag_l0);
1185 if (current->ref_pic_list_modification_flag_l0) {
1186 for (
i = 0;
i <= current->num_ref_idx_l0_active_minus1;
i++)
1187 us(entry_size, list_entry_l0[
i], 0, num_pic_total_curr - 1, 1,
i);
1191 flag(ref_pic_list_modification_flag_l1);
1192 if (current->ref_pic_list_modification_flag_l1) {
1193 for (
i = 0;
i <= current->num_ref_idx_l1_active_minus1;
i++)
1194 us(entry_size, list_entry_l1[
i], 0, num_pic_total_curr - 1, 1,
i);
1207 int chroma = !
sps->separate_colour_plane_flag &&
1208 sps->chroma_format_idc != 0;
1210 ue(luma_log2_weight_denom, 0, 7);
1212 se(delta_chroma_log2_weight_denom, -7, 7);
1214 infer(delta_chroma_log2_weight_denom, 0);
1216 for (
i = 0;
i <= current->num_ref_idx_l0_active_minus1;
i++) {
1218 flags(luma_weight_l0_flag[
i], 1,
i);
1220 infer(luma_weight_l0_flag[
i], 0);
1223 for (
i = 0;
i <= current->num_ref_idx_l0_active_minus1;
i++) {
1225 flags(chroma_weight_l0_flag[
i], 1,
i);
1227 infer(chroma_weight_l0_flag[
i], 0);
1231 for (
i = 0;
i <= current->num_ref_idx_l0_active_minus1;
i++) {
1232 if (current->luma_weight_l0_flag[
i]) {
1233 ses(delta_luma_weight_l0[
i], -128, +127, 1,
i);
1234 ses(luma_offset_l0[
i],
1235 -(1 << (
sps->bit_depth_luma_minus8 + 8 - 1)),
1236 ((1 << (
sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1,
i);
1238 infer(delta_luma_weight_l0[
i], 0);
1239 infer(luma_offset_l0[
i], 0);
1241 if (current->chroma_weight_l0_flag[
i]) {
1242 for (j = 0; j < 2; j++) {
1243 ses(delta_chroma_weight_l0[
i][j], -128, +127, 2,
i, j);
1244 ses(chroma_offset_l0[
i][j],
1245 -(4 << (
sps->bit_depth_chroma_minus8 + 8 - 1)),
1246 ((4 << (
sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2,
i, j);
1249 for (j = 0; j < 2; j++) {
1250 infer(delta_chroma_weight_l0[
i][j], 0);
1251 infer(chroma_offset_l0[
i][j], 0);
1257 for (
i = 0;
i <= current->num_ref_idx_l1_active_minus1;
i++) {
1259 flags(luma_weight_l1_flag[
i], 1,
i);
1261 infer(luma_weight_l1_flag[
i], 0);
1264 for (
i = 0;
i <= current->num_ref_idx_l1_active_minus1;
i++) {
1266 flags(chroma_weight_l1_flag[
i], 1,
i);
1268 infer(chroma_weight_l1_flag[
i], 0);
1272 for (
i = 0;
i <= current->num_ref_idx_l1_active_minus1;
i++) {
1273 if (current->luma_weight_l1_flag[
i]) {
1274 ses(delta_luma_weight_l1[
i], -128, +127, 1,
i);
1275 ses(luma_offset_l1[
i],
1276 -(1 << (
sps->bit_depth_luma_minus8 + 8 - 1)),
1277 ((1 << (
sps->bit_depth_luma_minus8 + 8 - 1)) - 1), 1,
i);
1279 infer(delta_luma_weight_l1[
i], 0);
1280 infer(luma_offset_l1[
i], 0);
1282 if (current->chroma_weight_l1_flag[
i]) {
1283 for (j = 0; j < 2; j++) {
1284 ses(delta_chroma_weight_l1[
i][j], -128, +127, 2,
i, j);
1285 ses(chroma_offset_l1[
i][j],
1286 -(4 << (
sps->bit_depth_chroma_minus8 + 8 - 1)),
1287 ((4 << (
sps->bit_depth_chroma_minus8 + 8 - 1)) - 1), 2,
i, j);
1290 for (j = 0; j < 2; j++) {
1291 infer(delta_chroma_weight_l1[
i][j], 0);
1292 infer(chroma_offset_l1[
i][j], 0);
1307 unsigned int min_cb_log2_size_y, ctb_log2_size_y, ctb_size_y;
1308 unsigned int pic_width_in_ctbs_y, pic_height_in_ctbs_y, pic_size_in_ctbs_y;
1309 unsigned int num_pic_total_curr = 0;
1312 HEADER(
"Slice Segment Header");
1316 flag(first_slice_segment_in_pic_flag);
1320 flag(no_output_of_prior_pics_flag);
1322 ue(slice_pic_parameter_set_id, 0, 63);
1324 pps = h265->
pps[current->slice_pic_parameter_set_id];
1327 current->slice_pic_parameter_set_id);
1332 sps = h265->
sps[
pps->pps_seq_parameter_set_id];
1335 pps->pps_seq_parameter_set_id);
1340 min_cb_log2_size_y =
sps->log2_min_luma_coding_block_size_minus3 + 3;
1341 ctb_log2_size_y = min_cb_log2_size_y +
sps->log2_diff_max_min_luma_coding_block_size;
1342 ctb_size_y = 1 << ctb_log2_size_y;
1343 pic_width_in_ctbs_y =
1344 (
sps->pic_width_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1345 pic_height_in_ctbs_y =
1346 (
sps->pic_height_in_luma_samples + ctb_size_y - 1) / ctb_size_y;
1347 pic_size_in_ctbs_y = pic_width_in_ctbs_y * pic_height_in_ctbs_y;
1349 if (!current->first_slice_segment_in_pic_flag) {
1350 unsigned int address_size =
av_log2(pic_size_in_ctbs_y - 1) + 1;
1351 if (
pps->dependent_slice_segments_enabled_flag)
1352 flag(dependent_slice_segment_flag);
1354 infer(dependent_slice_segment_flag, 0);
1355 u(address_size, slice_segment_address, 0, pic_size_in_ctbs_y - 1);
1357 infer(dependent_slice_segment_flag, 0);
1360 if (!current->dependent_slice_segment_flag) {
1361 for (
i = 0;
i <
pps->num_extra_slice_header_bits;
i++)
1362 flags(slice_reserved_flag[
i], 1,
i);
1364 ue(slice_type, 0, 2);
1366 if (
pps->output_flag_present_flag)
1367 flag(pic_output_flag);
1369 if (
sps->separate_colour_plane_flag)
1370 u(2, colour_plane_id, 0, 2);
1375 int dpb_slots_remaining;
1377 ub(
sps->log2_max_pic_order_cnt_lsb_minus4 + 4, slice_pic_order_cnt_lsb);
1379 flag(short_term_ref_pic_set_sps_flag);
1380 if (!current->short_term_ref_pic_set_sps_flag) {
1382 sps->num_short_term_ref_pic_sets,
sps));
1383 rps = ¤t->short_term_ref_pic_set;
1384 }
else if (
sps->num_short_term_ref_pic_sets > 1) {
1385 unsigned int idx_size =
av_log2(
sps->num_short_term_ref_pic_sets - 1) + 1;
1386 u(idx_size, short_term_ref_pic_set_idx,
1387 0,
sps->num_short_term_ref_pic_sets - 1);
1388 rps = &
sps->st_ref_pic_set[current->short_term_ref_pic_set_idx];
1390 infer(short_term_ref_pic_set_idx, 0);
1391 rps = &
sps->st_ref_pic_set[0];
1396 if (
pps->pps_curr_pic_ref_enabled_flag &&
1397 (
sps->sample_adaptive_offset_enabled_flag ||
1398 !
pps->pps_deblocking_filter_disabled_flag ||
1399 pps->deblocking_filter_override_enabled_flag)) {
1401 if (dpb_slots_remaining == 0) {
1403 "short-term ref pic set contains too many pictures "
1404 "to use with current picture reference enabled.\n");
1407 --dpb_slots_remaining;
1410 num_pic_total_curr = 0;
1413 ++num_pic_total_curr;
1416 ++num_pic_total_curr;
1418 if (
sps->long_term_ref_pics_present_flag) {
1419 unsigned int idx_size;
1421 if (
sps->num_long_term_ref_pics_sps > 0) {
1422 ue(num_long_term_sps, 0,
FFMIN(
sps->num_long_term_ref_pics_sps,
1423 dpb_slots_remaining));
1424 idx_size =
av_log2(
sps->num_long_term_ref_pics_sps - 1) + 1;
1425 dpb_slots_remaining -= current->num_long_term_sps;
1427 infer(num_long_term_sps, 0);
1430 ue(num_long_term_pics, 0, dpb_slots_remaining);
1432 for (
i = 0;
i < current->num_long_term_sps +
1433 current->num_long_term_pics;
i++) {
1434 if (i < current->num_long_term_sps) {
1435 if (
sps->num_long_term_ref_pics_sps > 1)
1436 us(idx_size, lt_idx_sps[
i],
1437 0,
sps->num_long_term_ref_pics_sps - 1, 1,
i);
1438 if (
sps->used_by_curr_pic_lt_sps_flag[current->lt_idx_sps[
i]])
1439 ++num_pic_total_curr;
1441 ubs(
sps->log2_max_pic_order_cnt_lsb_minus4 + 4, poc_lsb_lt[
i], 1,
i);
1442 flags(used_by_curr_pic_lt_flag[
i], 1,
i);
1443 if (current->used_by_curr_pic_lt_flag[
i])
1444 ++num_pic_total_curr;
1446 flags(delta_poc_msb_present_flag[
i], 1,
i);
1447 if (current->delta_poc_msb_present_flag[
i])
1448 ues(delta_poc_msb_cycle_lt[
i], 0, UINT32_MAX - 1, 1,
i);
1450 infer(delta_poc_msb_cycle_lt[
i], 0);
1454 if (
sps->sps_temporal_mvp_enabled_flag)
1455 flag(slice_temporal_mvp_enabled_flag);
1457 infer(slice_temporal_mvp_enabled_flag, 0);
1459 if (
pps->pps_curr_pic_ref_enabled_flag)
1460 ++num_pic_total_curr;
1463 if (
sps->sample_adaptive_offset_enabled_flag) {
1464 flag(slice_sao_luma_flag);
1465 if (!
sps->separate_colour_plane_flag &&
sps->chroma_format_idc != 0)
1466 flag(slice_sao_chroma_flag);
1468 infer(slice_sao_chroma_flag, 0);
1470 infer(slice_sao_luma_flag, 0);
1471 infer(slice_sao_chroma_flag, 0);
1476 flag(num_ref_idx_active_override_flag);
1477 if (current->num_ref_idx_active_override_flag) {
1478 ue(num_ref_idx_l0_active_minus1, 0, 14);
1480 ue(num_ref_idx_l1_active_minus1, 0, 14);
1482 infer(num_ref_idx_l1_active_minus1,
pps->num_ref_idx_l1_default_active_minus1);
1484 infer(num_ref_idx_l0_active_minus1,
pps->num_ref_idx_l0_default_active_minus1);
1485 infer(num_ref_idx_l1_active_minus1,
pps->num_ref_idx_l1_default_active_minus1);
1488 if (
pps->lists_modification_present_flag && num_pic_total_curr > 1)
1490 num_pic_total_curr));
1493 flag(mvd_l1_zero_flag);
1494 if (
pps->cabac_init_present_flag)
1495 flag(cabac_init_flag);
1497 infer(cabac_init_flag, 0);
1498 if (current->slice_temporal_mvp_enabled_flag) {
1500 flag(collocated_from_l0_flag);
1502 infer(collocated_from_l0_flag, 1);
1503 if (current->collocated_from_l0_flag) {
1504 if (current->num_ref_idx_l0_active_minus1 > 0)
1505 ue(collocated_ref_idx, 0, current->num_ref_idx_l0_active_minus1);
1507 infer(collocated_ref_idx, 0);
1509 if (current->num_ref_idx_l1_active_minus1 > 0)
1510 ue(collocated_ref_idx, 0, current->num_ref_idx_l1_active_minus1);
1512 infer(collocated_ref_idx, 0);
1516 if ((
pps->weighted_pred_flag && current->slice_type ==
HEVC_SLICE_P) ||
1520 ue(five_minus_max_num_merge_cand, 0, 4);
1521 if (
sps->motion_vector_resolution_control_idc == 2)
1522 flag(use_integer_mv_flag);
1524 infer(use_integer_mv_flag,
sps->motion_vector_resolution_control_idc);
1528 - 6 *
sps->bit_depth_luma_minus8 - (
pps->init_qp_minus26 + 26),
1529 + 51 - (
pps->init_qp_minus26 + 26));
1530 if (
pps->pps_slice_chroma_qp_offsets_present_flag) {
1531 se(slice_cb_qp_offset, -12, +12);
1532 se(slice_cr_qp_offset, -12, +12);
1534 infer(slice_cb_qp_offset, 0);
1535 infer(slice_cr_qp_offset, 0);
1537 if (
pps->pps_slice_act_qp_offsets_present_flag) {
1538 se(slice_act_y_qp_offset,
1539 -12 - (
pps->pps_act_y_qp_offset_plus5 - 5),
1540 +12 - (
pps->pps_act_y_qp_offset_plus5 - 5));
1541 se(slice_act_cb_qp_offset,
1542 -12 - (
pps->pps_act_cb_qp_offset_plus5 - 5),
1543 +12 - (
pps->pps_act_cb_qp_offset_plus5 - 5));
1544 se(slice_act_cr_qp_offset,
1545 -12 - (
pps->pps_act_cr_qp_offset_plus3 - 3),
1546 +12 - (
pps->pps_act_cr_qp_offset_plus3 - 3));
1548 infer(slice_act_y_qp_offset, 0);
1549 infer(slice_act_cb_qp_offset, 0);
1550 infer(slice_act_cr_qp_offset, 0);
1552 if (
pps->chroma_qp_offset_list_enabled_flag)
1553 flag(cu_chroma_qp_offset_enabled_flag);
1555 infer(cu_chroma_qp_offset_enabled_flag, 0);
1557 if (
pps->deblocking_filter_override_enabled_flag)
1558 flag(deblocking_filter_override_flag);
1560 infer(deblocking_filter_override_flag, 0);
1561 if (current->deblocking_filter_override_flag) {
1562 flag(slice_deblocking_filter_disabled_flag);
1563 if (!current->slice_deblocking_filter_disabled_flag) {
1564 se(slice_beta_offset_div2, -6, +6);
1565 se(slice_tc_offset_div2, -6, +6);
1567 infer(slice_beta_offset_div2,
pps->pps_beta_offset_div2);
1568 infer(slice_tc_offset_div2,
pps->pps_tc_offset_div2);
1571 infer(slice_deblocking_filter_disabled_flag,
1572 pps->pps_deblocking_filter_disabled_flag);
1573 infer(slice_beta_offset_div2,
pps->pps_beta_offset_div2);
1574 infer(slice_tc_offset_div2,
pps->pps_tc_offset_div2);
1576 if (
pps->pps_loop_filter_across_slices_enabled_flag &&
1577 (current->slice_sao_luma_flag || current->slice_sao_chroma_flag ||
1578 !current->slice_deblocking_filter_disabled_flag))
1579 flag(slice_loop_filter_across_slices_enabled_flag);
1581 infer(slice_loop_filter_across_slices_enabled_flag,
1582 pps->pps_loop_filter_across_slices_enabled_flag);
1585 if (
pps->tiles_enabled_flag ||
pps->entropy_coding_sync_enabled_flag) {
1586 unsigned int num_entry_point_offsets_limit;
1587 if (!
pps->tiles_enabled_flag &&
pps->entropy_coding_sync_enabled_flag)
1588 num_entry_point_offsets_limit = pic_height_in_ctbs_y - 1;
1589 else if (
pps->tiles_enabled_flag && !
pps->entropy_coding_sync_enabled_flag)
1590 num_entry_point_offsets_limit =
1591 (
pps->num_tile_columns_minus1 + 1) * (
pps->num_tile_rows_minus1 + 1);
1593 num_entry_point_offsets_limit =
1594 (
pps->num_tile_columns_minus1 + 1) * pic_height_in_ctbs_y - 1;
1595 ue(num_entry_point_offsets, 0, num_entry_point_offsets_limit);
1599 "%"PRIu16
".\n", current->num_entry_point_offsets);
1603 if (current->num_entry_point_offsets > 0) {
1604 ue(offset_len_minus1, 0, 31);
1605 for (
i = 0;
i < current->num_entry_point_offsets;
i++)
1606 ubs(current->offset_len_minus1 + 1, entry_point_offset_minus1[
i], 1,
i);
1610 if (
pps->slice_segment_header_extension_present_flag) {
1611 ue(slice_segment_header_extension_length, 0, 256);
1612 for (
i = 0;
i < current->slice_segment_header_extension_length;
i++)
1613 us(8, slice_segment_header_extension_data_byte[
i], 0x00, 0xff, 1,
i);
1631 int start_pos, end_pos;
1635 HEADER(
"Buffering Period");
1639 sps = h265->
sps[current->bp_seq_parameter_set_id];
1642 current->bp_seq_parameter_set_id);
1647 if (!
sps->vui_parameters_present_flag ||
1648 !
sps->vui.vui_hrd_parameters_present_flag) {
1650 "HRD parameters to be present in SPS.\n");
1653 hrd = &
sps->vui.hrd_parameters;
1657 "NAL or VCL HRD parameters to be present.\n");
1662 flag(irap_cpb_params_present_flag);
1664 infer(irap_cpb_params_present_flag, 0);
1665 if (current->irap_cpb_params_present_flag) {
1667 ub(length, cpb_delay_offset);
1669 ub(length, dpb_delay_offset);
1671 infer(cpb_delay_offset, 0);
1672 infer(dpb_delay_offset, 0);
1675 flag(concatenation_flag);
1678 ub(length, au_cpb_removal_delay_delta_minus1);
1684 ubs(length, nal_initial_cpb_removal_delay[
i], 1,
i);
1685 ubs(length, nal_initial_cpb_removal_offset[
i], 1,
i);
1688 current->irap_cpb_params_present_flag) {
1689 ubs(length, nal_initial_alt_cpb_removal_delay[
i], 1,
i);
1690 ubs(length, nal_initial_alt_cpb_removal_offset[
i], 1,
i);
1698 ubs(length, vcl_initial_cpb_removal_delay[
i], 1,
i);
1699 ubs(length, vcl_initial_cpb_removal_offset[
i], 1,
i);
1702 current->irap_cpb_params_present_flag) {
1703 ubs(length, vcl_initial_alt_cpb_removal_delay[
i], 1,
i);
1704 ubs(length, vcl_initial_alt_cpb_removal_offset[
i], 1,
i);
1712 end_pos - start_pos))
1713 flag(use_alt_cpb_params_flag);
1715 infer(use_alt_cpb_params_flag, 0);
1719 if (current->use_alt_cpb_params_flag ||
sei->extension_present) {
1720 flag(use_alt_cpb_params_flag);
1724 sei->extension_present = 1;
1738 int err, expected_source_scan_type,
i, length;
1740 HEADER(
"Picture Timing");
1745 "No active SPS for pic_timing.\n");
1749 expected_source_scan_type = 2 -
1750 2 *
sps->profile_tier_level.general_interlaced_source_flag -
1751 sps->profile_tier_level.general_progressive_source_flag;
1753 if (
sps->vui.frame_field_info_present_flag) {
1754 u(4, pic_struct, 0, 12);
1755 u(2, source_scan_type,
1756 expected_source_scan_type >= 0 ? expected_source_scan_type : 0,
1757 expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1758 flag(duplicate_flag);
1760 infer(pic_struct, 0);
1761 infer(source_scan_type,
1762 expected_source_scan_type >= 0 ? expected_source_scan_type : 2);
1763 infer(duplicate_flag, 0);
1766 if (
sps->vui_parameters_present_flag &&
1767 sps->vui.vui_hrd_parameters_present_flag)
1768 hrd = &
sps->vui.hrd_parameters;
1774 ub(length, au_cpb_removal_delay_minus1);
1777 ub(length, pic_dpb_output_delay);
1781 ub(length, pic_dpb_output_du_delay);
1788 flag(du_common_cpb_removal_delay_flag);
1791 if (current->du_common_cpb_removal_delay_flag)
1792 ub(length, du_common_cpb_removal_delay_increment_minus1);
1794 for (
i = 0;
i <= current->num_decoding_units_minus1;
i++) {
1795 ues(num_nalus_in_du_minus1[
i],
1797 if (!current->du_common_cpb_removal_delay_flag &&
1798 i < current->num_decoding_units_minus1)
1799 ubs(length, du_cpb_removal_delay_increment_minus1[
i], 1,
i);
1813 HEADER(
"Pan-Scan Rectangle");
1815 ue(pan_scan_rect_id, 0, UINT32_MAX - 1);
1816 flag(pan_scan_rect_cancel_flag);
1818 if (!current->pan_scan_rect_cancel_flag) {
1819 ue(pan_scan_cnt_minus1, 0, 2);
1821 for (
i = 0;
i <= current->pan_scan_cnt_minus1;
i++) {
1822 ses(pan_scan_rect_left_offset[
i], INT32_MIN + 1, INT32_MAX, 1,
i);
1823 ses(pan_scan_rect_right_offset[
i], INT32_MIN + 1, INT32_MAX, 1,
i);
1824 ses(pan_scan_rect_top_offset[
i], INT32_MIN + 1, INT32_MAX, 1,
i);
1825 ses(pan_scan_rect_bottom_offset[
i], INT32_MIN + 1, INT32_MAX, 1,
i);
1828 flag(pan_scan_rect_persistence_flag);
1840 HEADER(
"Recovery Point");
1842 se(recovery_poc_cnt, -32768, 32767);
1844 flag(exact_match_flag);
1845 flag(broken_link_flag);
1858 HEADER(
"Film Grain Characteristics");
1860 flag(film_grain_characteristics_cancel_flag);
1861 if (!current->film_grain_characteristics_cancel_flag) {
1862 int filmGrainBitDepth[3];
1864 u(2, film_grain_model_id, 0, 1);
1865 flag(separate_colour_description_present_flag);
1866 if (current->separate_colour_description_present_flag) {
1867 ub(3, film_grain_bit_depth_luma_minus8);
1868 ub(3, film_grain_bit_depth_chroma_minus8);
1869 flag(film_grain_full_range_flag);
1870 ub(8, film_grain_colour_primaries);
1871 ub(8, film_grain_transfer_characteristics);
1872 ub(8, film_grain_matrix_coeffs);
1876 "No active SPS for film_grain_characteristics.\n");
1879 infer(film_grain_bit_depth_luma_minus8,
sps->bit_depth_luma_minus8);
1880 infer(film_grain_bit_depth_chroma_minus8,
sps->bit_depth_chroma_minus8);
1881 infer(film_grain_full_range_flag,
sps->vui.video_full_range_flag);
1882 infer(film_grain_colour_primaries,
sps->vui.colour_primaries);
1883 infer(film_grain_transfer_characteristics,
sps->vui.transfer_characteristics);
1884 infer(film_grain_matrix_coeffs,
sps->vui.matrix_coefficients);
1887 filmGrainBitDepth[0] = current->film_grain_bit_depth_luma_minus8 + 8;
1888 filmGrainBitDepth[1] =
1889 filmGrainBitDepth[2] = current->film_grain_bit_depth_chroma_minus8 + 8;
1891 u(2, blending_mode_id, 0, 1);
1892 ub(4, log2_scale_factor);
1893 for (
c = 0;
c < 3;
c++)
1894 flags(comp_model_present_flag[
c], 1,
c);
1895 for (
c = 0;
c < 3;
c++) {
1896 if (current->comp_model_present_flag[
c]) {
1897 ubs(8, num_intensity_intervals_minus1[
c], 1,
c);
1898 us(3, num_model_values_minus1[
c], 0, 5, 1,
c);
1899 for (
i = 0;
i <= current->num_intensity_intervals_minus1[
c];
i++) {
1900 ubs(8, intensity_interval_lower_bound[
c][
i], 2,
c,
i);
1901 ubs(8, intensity_interval_upper_bound[
c][
i], 2,
c,
i);
1902 for (j = 0; j <= current->num_model_values_minus1[
c]; j++)
1903 ses(comp_model_value[
c][
i][j], 0 - current->film_grain_model_id * (1 << (filmGrainBitDepth[
c] - 1)),
1904 ((1 << filmGrainBitDepth[
c]) - 1) - current->film_grain_model_id * (1 << (filmGrainBitDepth[
c] - 1)),
1909 flag(film_grain_characteristics_persistence_flag);
1921 HEADER(
"Display Orientation");
1923 flag(display_orientation_cancel_flag);
1924 if (!current->display_orientation_cancel_flag) {
1927 ub(16, anticlockwise_rotation);
1928 flag(display_orientation_persistence_flag);
1942 HEADER(
"Active Parameter Sets");
1945 vps = h265->
vps[current->active_video_parameter_set_id];
1948 "parameter sets.\n", current->active_video_parameter_set_id);
1953 flag(self_contained_cvs_flag);
1954 flag(no_parameter_set_update_flag);
1957 for (
i = 0;
i <= current->num_sps_ids_minus1;
i++)
1960 for (
i =
vps->vps_base_layer_internal_flag;
1961 i <=
FFMIN(62,
vps->vps_max_layers_minus1);
i++) {
1962 ues(layer_sps_idx[
i], 0, current->num_sps_ids_minus1, 1,
i);
1965 h265->
active_sps = h265->
sps[current->active_seq_parameter_set_id[current->layer_sps_idx[0]]];
1979 HEADER(
"Decoded Picture Hash");
1983 "No active SPS for decoded picture hash.\n");
1987 u(8, hash_type, 0, 2);
1989 for (
c = 0;
c < (
sps->chroma_format_idc == 0 ? 1 : 3);
c++) {
1990 if (current->hash_type == 0) {
1991 for (
i = 0;
i < 16;
i++)
1992 us(8, picture_md5[
c][
i], 0x00, 0xff, 2,
c,
i);
1993 }
else if (current->hash_type == 1) {
1994 us(16, picture_crc[
c], 0x0000, 0xffff, 1,
c);
1995 }
else if (current->hash_type == 2) {
1996 us(32, picture_checksum[
c], 0x00000000, 0xffffffff, 1,
c);
2011 u(2, num_clock_ts, 1, 3);
2013 for (
i = 0;
i < current->num_clock_ts;
i++) {
2014 flags(clock_timestamp_flag[
i], 1,
i);
2016 if (current->clock_timestamp_flag[
i]) {
2017 flags(units_field_based_flag[
i], 1,
i);
2018 us(5, counting_type[
i], 0, 6, 1,
i);
2019 flags(full_timestamp_flag[
i], 1,
i);
2020 flags(discontinuity_flag[
i], 1,
i);
2021 flags(cnt_dropped_flag[
i], 1,
i);
2023 ubs(9, n_frames[
i], 1,
i);
2025 if (current->full_timestamp_flag[
i]) {
2026 us(6, seconds_value[
i], 0, 59, 1,
i);
2027 us(6, minutes_value[
i], 0, 59, 1,
i);
2028 us(5, hours_value[
i], 0, 23, 1,
i);
2031 if (current->seconds_flag[
i]) {
2032 us(6, seconds_value[
i], 0, 59, 1,
i);
2034 if (current->minutes_flag[
i]) {
2035 us(6, minutes_value[
i], 0, 59, 1,
i);
2037 if (current->hours_flag[
i])
2038 us(5, hours_value[
i], 0, 23, 1,
i);
2043 ubs(5, time_offset_length[
i], 1,
i);
2044 if (current->time_offset_length[
i] > 0)
2045 ibs(current->time_offset_length[
i], time_offset_value[
i], 1,
i);
2047 infer(time_offset_value[
i], 0);
2060 HEADER(
"Alpha Channel Information");
2062 flag(alpha_channel_cancel_flag);
2063 if (!current->alpha_channel_cancel_flag) {
2064 ub(3, alpha_channel_use_idc);
2065 ub(3, alpha_channel_bit_depth_minus8);
2066 length = current->alpha_channel_bit_depth_minus8 + 9;
2067 ub(length, alpha_transparent_value);
2068 ub(length, alpha_opaque_value);
2069 flag(alpha_channel_incr_flag);
2070 flag(alpha_channel_clip_flag);
2071 if (current->alpha_channel_clip_flag)
2072 flag(alpha_channel_clip_type_flag);
2074 infer(alpha_channel_use_idc, 2);
2075 infer(alpha_channel_incr_flag, 0);
2076 infer(alpha_channel_clip_flag, 0);
2088 HEADER(
"Prefix Supplemental Enhancement Information");
2090 HEADER(
"Suffix Supplemental Enhancement Information");