avcodec/cbs_h265: fix storage type for time_offset_value in Time Code SEI
[ffmpeg.git] / libavcodec / cbs_h265.h
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18
19 #ifndef AVCODEC_CBS_H265_H
20 #define AVCODEC_CBS_H265_H
21
22 #include <stddef.h>
23 #include <stdint.h>
24
25 #include "cbs_h2645.h"
26 #include "hevc.h"
27
28 enum {
29     // This limit is arbitrary - it is sufficient for one message of each
30     // type plus some repeats, and will therefore easily cover all sane
31     // streams.  However, it is possible to make technically-valid streams
32     // for which it will fail (for example, by including a large number of
33     // user-data-unregistered messages).
34     H265_MAX_SEI_PAYLOADS = 64,
35 };
36
37 typedef struct H265RawNALUnitHeader {
38     uint8_t forbidden_zero_bit;
39     uint8_t nal_unit_type;
40     uint8_t nuh_layer_id;
41     uint8_t nuh_temporal_id_plus1;
42 } H265RawNALUnitHeader;
43
44 typedef struct H265RawProfileTierLevel {
45     uint8_t general_profile_space;
46     uint8_t general_tier_flag;
47     uint8_t general_profile_idc;
48
49     uint8_t general_profile_compatibility_flag[32];
50
51     uint8_t general_progressive_source_flag;
52     uint8_t general_interlaced_source_flag;
53     uint8_t general_non_packed_constraint_flag;
54     uint8_t general_frame_only_constraint_flag;
55
56     uint8_t general_max_12bit_constraint_flag;
57     uint8_t general_max_10bit_constraint_flag;
58     uint8_t general_max_8bit_constraint_flag;
59     uint8_t general_max_422chroma_constraint_flag;
60     uint8_t general_max_420chroma_constraint_flag;
61     uint8_t general_max_monochrome_constraint_flag;
62     uint8_t general_intra_constraint_flag;
63     uint8_t general_one_picture_only_constraint_flag;
64     uint8_t general_lower_bit_rate_constraint_flag;
65     uint8_t general_max_14bit_constraint_flag;
66
67     uint8_t general_inbld_flag;
68
69     uint8_t general_level_idc;
70
71     uint8_t sub_layer_profile_present_flag[HEVC_MAX_SUB_LAYERS];
72     uint8_t sub_layer_level_present_flag[HEVC_MAX_SUB_LAYERS];
73
74     uint8_t sub_layer_profile_space[HEVC_MAX_SUB_LAYERS];
75     uint8_t sub_layer_tier_flag[HEVC_MAX_SUB_LAYERS];
76     uint8_t sub_layer_profile_idc[HEVC_MAX_SUB_LAYERS];
77
78     uint8_t sub_layer_profile_compatibility_flag[HEVC_MAX_SUB_LAYERS][32];
79
80     uint8_t sub_layer_progressive_source_flag[HEVC_MAX_SUB_LAYERS];
81     uint8_t sub_layer_interlaced_source_flag[HEVC_MAX_SUB_LAYERS];
82     uint8_t sub_layer_non_packed_constraint_flag[HEVC_MAX_SUB_LAYERS];
83     uint8_t sub_layer_frame_only_constraint_flag[HEVC_MAX_SUB_LAYERS];
84
85     uint8_t sub_layer_max_12bit_constraint_flag[HEVC_MAX_SUB_LAYERS];
86     uint8_t sub_layer_max_10bit_constraint_flag[HEVC_MAX_SUB_LAYERS];
87     uint8_t sub_layer_max_8bit_constraint_flag[HEVC_MAX_SUB_LAYERS];
88     uint8_t sub_layer_max_422chroma_constraint_flag[HEVC_MAX_SUB_LAYERS];
89     uint8_t sub_layer_max_420chroma_constraint_flag[HEVC_MAX_SUB_LAYERS];
90     uint8_t sub_layer_max_monochrome_constraint_flag[HEVC_MAX_SUB_LAYERS];
91     uint8_t sub_layer_intra_constraint_flag[HEVC_MAX_SUB_LAYERS];
92     uint8_t sub_layer_one_picture_only_constraint_flag[HEVC_MAX_SUB_LAYERS];
93     uint8_t sub_layer_lower_bit_rate_constraint_flag[HEVC_MAX_SUB_LAYERS];
94     uint8_t sub_layer_max_14bit_constraint_flag[HEVC_MAX_SUB_LAYERS];
95
96     uint8_t sub_layer_inbld_flag[HEVC_MAX_SUB_LAYERS];
97
98     uint8_t sub_layer_level_idc[HEVC_MAX_SUB_LAYERS];
99 } H265RawProfileTierLevel;
100
101 typedef struct H265RawSubLayerHRDParameters {
102     uint32_t bit_rate_value_minus1[HEVC_MAX_CPB_CNT];
103     uint32_t cpb_size_value_minus1[HEVC_MAX_CPB_CNT];
104     uint32_t cpb_size_du_value_minus1[HEVC_MAX_CPB_CNT];
105     uint32_t bit_rate_du_value_minus1[HEVC_MAX_CPB_CNT];
106     uint8_t cbr_flag[HEVC_MAX_CPB_CNT];
107 } H265RawSubLayerHRDParameters;
108
109 typedef struct H265RawHRDParameters {
110     uint8_t nal_hrd_parameters_present_flag;
111     uint8_t vcl_hrd_parameters_present_flag;
112
113     uint8_t sub_pic_hrd_params_present_flag;
114     uint8_t tick_divisor_minus2;
115     uint8_t du_cpb_removal_delay_increment_length_minus1;
116     uint8_t sub_pic_cpb_params_in_pic_timing_sei_flag;
117     uint8_t dpb_output_delay_du_length_minus1;
118
119     uint8_t bit_rate_scale;
120     uint8_t cpb_size_scale;
121     uint8_t cpb_size_du_scale;
122
123     uint8_t initial_cpb_removal_delay_length_minus1;
124     uint8_t au_cpb_removal_delay_length_minus1;
125     uint8_t dpb_output_delay_length_minus1;
126
127     uint8_t fixed_pic_rate_general_flag[HEVC_MAX_SUB_LAYERS];
128     uint8_t fixed_pic_rate_within_cvs_flag[HEVC_MAX_SUB_LAYERS];
129     uint16_t elemental_duration_in_tc_minus1[HEVC_MAX_SUB_LAYERS];
130     uint8_t low_delay_hrd_flag[HEVC_MAX_SUB_LAYERS];
131     uint8_t cpb_cnt_minus1[HEVC_MAX_SUB_LAYERS];
132     H265RawSubLayerHRDParameters nal_sub_layer_hrd_parameters[HEVC_MAX_SUB_LAYERS];
133     H265RawSubLayerHRDParameters vcl_sub_layer_hrd_parameters[HEVC_MAX_SUB_LAYERS];
134 } H265RawHRDParameters;
135
136 typedef struct H265RawVUI {
137     uint8_t aspect_ratio_info_present_flag;
138     uint8_t aspect_ratio_idc;
139     uint16_t sar_width;
140     uint16_t sar_height;
141
142     uint8_t overscan_info_present_flag;
143     uint8_t overscan_appropriate_flag;
144
145     uint8_t video_signal_type_present_flag;
146     uint8_t video_format;
147     uint8_t video_full_range_flag;
148     uint8_t colour_description_present_flag;
149     uint8_t colour_primaries;
150     uint8_t transfer_characteristics;
151     uint8_t matrix_coefficients;
152
153     uint8_t chroma_loc_info_present_flag;
154     uint8_t chroma_sample_loc_type_top_field;
155     uint8_t chroma_sample_loc_type_bottom_field;
156
157     uint8_t neutral_chroma_indication_flag;
158     uint8_t field_seq_flag;
159     uint8_t frame_field_info_present_flag;
160
161     uint8_t default_display_window_flag;
162     uint16_t def_disp_win_left_offset;
163     uint16_t def_disp_win_right_offset;
164     uint16_t def_disp_win_top_offset;
165     uint16_t def_disp_win_bottom_offset;
166
167     uint8_t vui_timing_info_present_flag;
168     uint32_t vui_num_units_in_tick;
169     uint32_t vui_time_scale;
170     uint8_t vui_poc_proportional_to_timing_flag;
171     uint32_t vui_num_ticks_poc_diff_one_minus1;
172     uint8_t vui_hrd_parameters_present_flag;
173     H265RawHRDParameters hrd_parameters;
174
175     uint8_t bitstream_restriction_flag;
176     uint8_t tiles_fixed_structure_flag;
177     uint8_t motion_vectors_over_pic_boundaries_flag;
178     uint8_t restricted_ref_pic_lists_flag;
179     uint16_t min_spatial_segmentation_idc;
180     uint8_t max_bytes_per_pic_denom;
181     uint8_t max_bits_per_min_cu_denom;
182     uint8_t log2_max_mv_length_horizontal;
183     uint8_t log2_max_mv_length_vertical;
184 } H265RawVUI;
185
186 typedef struct H265RawPSExtensionData {
187     uint8_t *data;
188     size_t bit_length;
189     AVBufferRef *data_ref;
190 } H265RawPSExtensionData;
191
192 typedef struct H265RawVPS {
193     H265RawNALUnitHeader nal_unit_header;
194
195     uint8_t vps_video_parameter_set_id;
196
197     uint8_t vps_base_layer_internal_flag;
198     uint8_t vps_base_layer_available_flag;
199     uint8_t vps_max_layers_minus1;
200     uint8_t vps_max_sub_layers_minus1;
201     uint8_t vps_temporal_id_nesting_flag;
202
203     H265RawProfileTierLevel profile_tier_level;
204
205     uint8_t vps_sub_layer_ordering_info_present_flag;
206     uint8_t vps_max_dec_pic_buffering_minus1[HEVC_MAX_SUB_LAYERS];
207     uint8_t vps_max_num_reorder_pics[HEVC_MAX_SUB_LAYERS];
208     uint32_t vps_max_latency_increase_plus1[HEVC_MAX_SUB_LAYERS];
209
210     uint8_t vps_max_layer_id;
211     uint16_t vps_num_layer_sets_minus1;
212     uint8_t layer_id_included_flag[HEVC_MAX_LAYER_SETS][HEVC_MAX_LAYERS];
213
214     uint8_t vps_timing_info_present_flag;
215     uint32_t vps_num_units_in_tick;
216     uint32_t vps_time_scale;
217     uint8_t vps_poc_proportional_to_timing_flag;
218     uint32_t vps_num_ticks_poc_diff_one_minus1;
219     uint16_t vps_num_hrd_parameters;
220     uint16_t hrd_layer_set_idx[HEVC_MAX_LAYER_SETS];
221     uint8_t cprms_present_flag[HEVC_MAX_LAYER_SETS];
222     H265RawHRDParameters hrd_parameters[HEVC_MAX_LAYER_SETS];
223
224     uint8_t vps_extension_flag;
225     H265RawPSExtensionData extension_data;
226 } H265RawVPS;
227
228 typedef struct H265RawSTRefPicSet {
229     uint8_t inter_ref_pic_set_prediction_flag;
230
231     uint8_t delta_idx_minus1;
232     uint8_t delta_rps_sign;
233     uint16_t abs_delta_rps_minus1;
234
235     uint8_t used_by_curr_pic_flag[HEVC_MAX_REFS];
236     uint8_t use_delta_flag[HEVC_MAX_REFS];
237
238     uint8_t num_negative_pics;
239     uint8_t num_positive_pics;
240     uint16_t delta_poc_s0_minus1[HEVC_MAX_REFS];
241     uint8_t used_by_curr_pic_s0_flag[HEVC_MAX_REFS];
242     uint16_t delta_poc_s1_minus1[HEVC_MAX_REFS];
243     uint8_t used_by_curr_pic_s1_flag[HEVC_MAX_REFS];
244 } H265RawSTRefPicSet;
245
246 typedef struct H265RawScalingList {
247     uint8_t scaling_list_pred_mode_flag[4][6];
248     uint8_t scaling_list_pred_matrix_id_delta[4][6];
249     int16_t scaling_list_dc_coef_minus8[4][6];
250     int8_t scaling_list_delta_coeff[4][6][64];
251 } H265RawScalingList;
252
253 typedef struct H265RawSPS {
254     H265RawNALUnitHeader nal_unit_header;
255
256     uint8_t sps_video_parameter_set_id;
257
258     uint8_t sps_max_sub_layers_minus1;
259     uint8_t sps_temporal_id_nesting_flag;
260
261     H265RawProfileTierLevel profile_tier_level;
262
263     uint8_t sps_seq_parameter_set_id;
264
265     uint8_t chroma_format_idc;
266     uint8_t separate_colour_plane_flag;
267
268     uint16_t pic_width_in_luma_samples;
269     uint16_t pic_height_in_luma_samples;
270
271     uint8_t conformance_window_flag;
272     uint16_t conf_win_left_offset;
273     uint16_t conf_win_right_offset;
274     uint16_t conf_win_top_offset;
275     uint16_t conf_win_bottom_offset;
276
277     uint8_t bit_depth_luma_minus8;
278     uint8_t bit_depth_chroma_minus8;
279
280     uint8_t log2_max_pic_order_cnt_lsb_minus4;
281
282     uint8_t sps_sub_layer_ordering_info_present_flag;
283     uint8_t sps_max_dec_pic_buffering_minus1[HEVC_MAX_SUB_LAYERS];
284     uint8_t sps_max_num_reorder_pics[HEVC_MAX_SUB_LAYERS];
285     uint32_t sps_max_latency_increase_plus1[HEVC_MAX_SUB_LAYERS];
286
287     uint8_t log2_min_luma_coding_block_size_minus3;
288     uint8_t log2_diff_max_min_luma_coding_block_size;
289     uint8_t log2_min_luma_transform_block_size_minus2;
290     uint8_t log2_diff_max_min_luma_transform_block_size;
291     uint8_t max_transform_hierarchy_depth_inter;
292     uint8_t max_transform_hierarchy_depth_intra;
293
294     uint8_t scaling_list_enabled_flag;
295     uint8_t sps_scaling_list_data_present_flag;
296     H265RawScalingList scaling_list;
297
298     uint8_t amp_enabled_flag;
299     uint8_t sample_adaptive_offset_enabled_flag;
300
301     uint8_t pcm_enabled_flag;
302     uint8_t pcm_sample_bit_depth_luma_minus1;
303     uint8_t pcm_sample_bit_depth_chroma_minus1;
304     uint8_t log2_min_pcm_luma_coding_block_size_minus3;
305     uint8_t log2_diff_max_min_pcm_luma_coding_block_size;
306     uint8_t pcm_loop_filter_disabled_flag;
307
308     uint8_t num_short_term_ref_pic_sets;
309     H265RawSTRefPicSet st_ref_pic_set[HEVC_MAX_SHORT_TERM_REF_PIC_SETS];
310
311     uint8_t long_term_ref_pics_present_flag;
312     uint8_t num_long_term_ref_pics_sps;
313     uint16_t lt_ref_pic_poc_lsb_sps[HEVC_MAX_LONG_TERM_REF_PICS];
314     uint8_t used_by_curr_pic_lt_sps_flag[HEVC_MAX_LONG_TERM_REF_PICS];
315
316     uint8_t sps_temporal_mvp_enabled_flag;
317     uint8_t strong_intra_smoothing_enabled_flag;
318
319     uint8_t vui_parameters_present_flag;
320     H265RawVUI vui;
321
322     uint8_t sps_extension_present_flag;
323     uint8_t sps_range_extension_flag;
324     uint8_t sps_multilayer_extension_flag;
325     uint8_t sps_3d_extension_flag;
326     uint8_t sps_scc_extension_flag;
327     uint8_t sps_extension_4bits;
328
329     H265RawPSExtensionData extension_data;
330
331     // Range extension.
332     uint8_t transform_skip_rotation_enabled_flag;
333     uint8_t transform_skip_context_enabled_flag;
334     uint8_t implicit_rdpcm_enabled_flag;
335     uint8_t explicit_rdpcm_enabled_flag;
336     uint8_t extended_precision_processing_flag;
337     uint8_t intra_smoothing_disabled_flag;
338     uint8_t high_precision_offsets_enabled_flag;
339     uint8_t persistent_rice_adaptation_enabled_flag;
340     uint8_t cabac_bypass_alignment_enabled_flag;
341
342     // Screen content coding extension.
343     uint8_t sps_curr_pic_ref_enabled_flag;
344     uint8_t palette_mode_enabled_flag;
345     uint8_t palette_max_size;
346     uint8_t delta_palette_max_predictor_size;
347     uint8_t sps_palette_predictor_initializer_present_flag;
348     uint8_t sps_num_palette_predictor_initializer_minus1;
349     uint16_t sps_palette_predictor_initializers[3][128];
350
351     uint8_t motion_vector_resolution_control_idc;
352     uint8_t intra_boundary_filtering_disable_flag;
353 } H265RawSPS;
354
355 typedef struct H265RawPPS {
356     H265RawNALUnitHeader nal_unit_header;
357
358     uint8_t pps_pic_parameter_set_id;
359     uint8_t pps_seq_parameter_set_id;
360
361     uint8_t dependent_slice_segments_enabled_flag;
362     uint8_t output_flag_present_flag;
363     uint8_t num_extra_slice_header_bits;
364     uint8_t sign_data_hiding_enabled_flag;
365     uint8_t cabac_init_present_flag;
366
367     uint8_t num_ref_idx_l0_default_active_minus1;
368     uint8_t num_ref_idx_l1_default_active_minus1;
369
370     int8_t init_qp_minus26;
371
372     uint8_t constrained_intra_pred_flag;
373     uint8_t transform_skip_enabled_flag;
374     uint8_t cu_qp_delta_enabled_flag;
375     uint8_t diff_cu_qp_delta_depth;
376
377     int8_t pps_cb_qp_offset;
378     int8_t pps_cr_qp_offset;
379     uint8_t pps_slice_chroma_qp_offsets_present_flag;
380
381     uint8_t weighted_pred_flag;
382     uint8_t weighted_bipred_flag;
383
384     uint8_t transquant_bypass_enabled_flag;
385     uint8_t tiles_enabled_flag;
386     uint8_t entropy_coding_sync_enabled_flag;
387
388     uint8_t num_tile_columns_minus1;
389     uint8_t num_tile_rows_minus1;
390     uint8_t uniform_spacing_flag;
391     uint16_t column_width_minus1[HEVC_MAX_TILE_COLUMNS];
392     uint16_t row_height_minus1[HEVC_MAX_TILE_ROWS];
393     uint8_t loop_filter_across_tiles_enabled_flag;
394
395     uint8_t pps_loop_filter_across_slices_enabled_flag;
396     uint8_t deblocking_filter_control_present_flag;
397     uint8_t deblocking_filter_override_enabled_flag;
398     uint8_t pps_deblocking_filter_disabled_flag;
399     int8_t pps_beta_offset_div2;
400     int8_t pps_tc_offset_div2;
401
402     uint8_t pps_scaling_list_data_present_flag;
403     H265RawScalingList scaling_list;
404
405     uint8_t lists_modification_present_flag;
406     uint8_t log2_parallel_merge_level_minus2;
407
408     uint8_t slice_segment_header_extension_present_flag;
409
410     uint8_t pps_extension_present_flag;
411     uint8_t pps_range_extension_flag;
412     uint8_t pps_multilayer_extension_flag;
413     uint8_t pps_3d_extension_flag;
414     uint8_t pps_scc_extension_flag;
415     uint8_t pps_extension_4bits;
416
417     H265RawPSExtensionData extension_data;
418
419     // Range extension.
420     uint8_t log2_max_transform_skip_block_size_minus2;
421     uint8_t cross_component_prediction_enabled_flag;
422     uint8_t chroma_qp_offset_list_enabled_flag;
423     uint8_t diff_cu_chroma_qp_offset_depth;
424     uint8_t chroma_qp_offset_list_len_minus1;
425     int8_t cb_qp_offset_list[6];
426     int8_t cr_qp_offset_list[6];
427     uint8_t log2_sao_offset_scale_luma;
428     uint8_t log2_sao_offset_scale_chroma;
429
430     // Screen content coding extension.
431     uint8_t pps_curr_pic_ref_enabled_flag;
432     uint8_t residual_adaptive_colour_transform_enabled_flag;
433     uint8_t pps_slice_act_qp_offsets_present_flag;
434     int8_t pps_act_y_qp_offset_plus5;
435     int8_t pps_act_cb_qp_offset_plus5;
436     int8_t pps_act_cr_qp_offset_plus3;
437
438     uint8_t pps_palette_predictor_initializer_present_flag;
439     uint8_t pps_num_palette_predictor_initializer;
440     uint8_t monochrome_palette_flag;
441     uint8_t luma_bit_depth_entry_minus8;
442     uint8_t chroma_bit_depth_entry_minus8;
443     uint16_t pps_palette_predictor_initializers[3][128];
444 } H265RawPPS;
445
446 typedef struct H265RawAUD {
447     H265RawNALUnitHeader nal_unit_header;
448
449     uint8_t pic_type;
450 } H265RawAUD;
451
452 typedef struct  H265RawSliceHeader {
453     H265RawNALUnitHeader nal_unit_header;
454
455     uint8_t first_slice_segment_in_pic_flag;
456     uint8_t no_output_of_prior_pics_flag;
457     uint8_t slice_pic_parameter_set_id;
458
459     uint8_t dependent_slice_segment_flag;
460     uint16_t slice_segment_address;
461
462     uint8_t slice_reserved_flag[8];
463     uint8_t slice_type;
464
465     uint8_t pic_output_flag;
466     uint8_t colour_plane_id;
467
468     uint16_t slice_pic_order_cnt_lsb;
469
470     uint8_t short_term_ref_pic_set_sps_flag;
471     H265RawSTRefPicSet short_term_ref_pic_set;
472     uint8_t short_term_ref_pic_set_idx;
473
474     uint8_t num_long_term_sps;
475     uint8_t num_long_term_pics;
476     uint8_t lt_idx_sps[HEVC_MAX_REFS];
477     uint8_t poc_lsb_lt[HEVC_MAX_REFS];
478     uint8_t used_by_curr_pic_lt_flag[HEVC_MAX_REFS];
479     uint8_t delta_poc_msb_present_flag[HEVC_MAX_REFS];
480     uint32_t delta_poc_msb_cycle_lt[HEVC_MAX_REFS];
481
482     uint8_t slice_temporal_mvp_enabled_flag;
483
484     uint8_t slice_sao_luma_flag;
485     uint8_t slice_sao_chroma_flag;
486
487     uint8_t num_ref_idx_active_override_flag;
488     uint8_t num_ref_idx_l0_active_minus1;
489     uint8_t num_ref_idx_l1_active_minus1;
490
491     uint8_t ref_pic_list_modification_flag_l0;
492     uint8_t list_entry_l0[HEVC_MAX_REFS];
493     uint8_t ref_pic_list_modification_flag_l1;
494     uint8_t list_entry_l1[HEVC_MAX_REFS];
495
496     uint8_t mvd_l1_zero_flag;
497     uint8_t cabac_init_flag;
498     uint8_t collocated_from_l0_flag;
499     uint8_t collocated_ref_idx;
500
501     uint8_t luma_log2_weight_denom;
502     int8_t delta_chroma_log2_weight_denom;
503     uint8_t luma_weight_l0_flag[HEVC_MAX_REFS];
504     uint8_t chroma_weight_l0_flag[HEVC_MAX_REFS];
505     int8_t delta_luma_weight_l0[HEVC_MAX_REFS];
506     int16_t luma_offset_l0[HEVC_MAX_REFS];
507     int8_t delta_chroma_weight_l0[HEVC_MAX_REFS][2];
508     int16_t chroma_offset_l0[HEVC_MAX_REFS][2];
509     uint8_t luma_weight_l1_flag[HEVC_MAX_REFS];
510     uint8_t chroma_weight_l1_flag[HEVC_MAX_REFS];
511     int8_t delta_luma_weight_l1[HEVC_MAX_REFS];
512     int16_t luma_offset_l1[HEVC_MAX_REFS];
513     int8_t delta_chroma_weight_l1[HEVC_MAX_REFS][2];
514     int16_t chroma_offset_l1[HEVC_MAX_REFS][2];
515
516     uint8_t five_minus_max_num_merge_cand;
517     uint8_t use_integer_mv_flag;
518
519     int8_t slice_qp_delta;
520     int8_t slice_cb_qp_offset;
521     int8_t slice_cr_qp_offset;
522     int8_t slice_act_y_qp_offset;
523     int8_t slice_act_cb_qp_offset;
524     int8_t slice_act_cr_qp_offset;
525     uint8_t cu_chroma_qp_offset_enabled_flag;
526
527     uint8_t deblocking_filter_override_flag;
528     uint8_t slice_deblocking_filter_disabled_flag;
529     int8_t slice_beta_offset_div2;
530     int8_t slice_tc_offset_div2;
531     uint8_t slice_loop_filter_across_slices_enabled_flag;
532
533     uint16_t num_entry_point_offsets;
534     uint8_t offset_len_minus1;
535     uint32_t entry_point_offset_minus1[HEVC_MAX_ENTRY_POINT_OFFSETS];
536
537     uint16_t slice_segment_header_extension_length;
538     uint8_t slice_segment_header_extension_data_byte[256];
539 } H265RawSliceHeader;
540
541
542 typedef struct H265RawSlice {
543     H265RawSliceHeader header;
544
545     uint8_t *data;
546     size_t   data_size;
547     int      data_bit_start;
548     AVBufferRef *data_ref;
549 } H265RawSlice;
550
551
552 typedef struct H265RawSEIBufferingPeriod {
553     uint8_t  bp_seq_parameter_set_id;
554     uint8_t  irap_cpb_params_present_flag;
555     uint32_t cpb_delay_offset;
556     uint32_t dpb_delay_offset;
557     uint8_t  concatenation_flag;
558     uint32_t au_cpb_removal_delay_delta_minus1;
559
560     uint32_t nal_initial_cpb_removal_delay[HEVC_MAX_CPB_CNT];
561     uint32_t nal_initial_cpb_removal_offset[HEVC_MAX_CPB_CNT];
562     uint32_t nal_initial_alt_cpb_removal_delay[HEVC_MAX_CPB_CNT];
563     uint32_t nal_initial_alt_cpb_removal_offset[HEVC_MAX_CPB_CNT];
564
565     uint32_t vcl_initial_cpb_removal_delay[HEVC_MAX_CPB_CNT];
566     uint32_t vcl_initial_cpb_removal_offset[HEVC_MAX_CPB_CNT];
567     uint32_t vcl_initial_alt_cpb_removal_delay[HEVC_MAX_CPB_CNT];
568     uint32_t vcl_initial_alt_cpb_removal_offset[HEVC_MAX_CPB_CNT];
569
570     uint8_t  use_alt_cpb_params_flag;
571 } H265RawSEIBufferingPeriod;
572
573 typedef struct H265RawSEIPicTiming {
574     uint8_t pic_struct;
575     uint8_t source_scan_type;
576     uint8_t duplicate_flag;
577
578     uint32_t au_cpb_removal_delay_minus1;
579     uint32_t pic_dpb_output_delay;
580     uint32_t pic_dpb_output_du_delay;
581
582     uint16_t num_decoding_units_minus1;
583     uint8_t  du_common_cpb_removal_delay_flag;
584     uint32_t du_common_cpb_removal_delay_increment_minus1;
585     uint16_t num_nalus_in_du_minus1[HEVC_MAX_SLICE_SEGMENTS];
586     uint32_t du_cpb_removal_delay_increment_minus1[HEVC_MAX_SLICE_SEGMENTS];
587 } H265RawSEIPicTiming;
588
589 typedef struct H265RawSEIPanScanRect {
590     uint32_t pan_scan_rect_id;
591     uint8_t  pan_scan_rect_cancel_flag;
592     uint8_t  pan_scan_cnt_minus1;
593     int32_t  pan_scan_rect_left_offset[3];
594     int32_t  pan_scan_rect_right_offset[3];
595     int32_t  pan_scan_rect_top_offset[3];
596     int32_t  pan_scan_rect_bottom_offset[3];
597     uint16_t pan_scan_rect_persistence_flag;
598 } H265RawSEIPanScanRect;
599
600 typedef struct H265RawSEIUserDataRegistered {
601     uint8_t itu_t_t35_country_code;
602     uint8_t itu_t_t35_country_code_extension_byte;
603     uint8_t     *data;
604     size_t       data_length;
605     AVBufferRef *data_ref;
606 } H265RawSEIUserDataRegistered;
607
608 typedef struct H265RawSEIUserDataUnregistered {
609     uint8_t uuid_iso_iec_11578[16];
610     uint8_t     *data;
611     size_t       data_length;
612     AVBufferRef *data_ref;
613 } H265RawSEIUserDataUnregistered;
614
615 typedef struct H265RawSEIRecoveryPoint {
616     int16_t recovery_poc_cnt;
617     uint8_t exact_match_flag;
618     uint8_t broken_link_flag;
619 } H265RawSEIRecoveryPoint;
620
621 typedef struct H265RawSEIDisplayOrientation {
622     uint8_t display_orientation_cancel_flag;
623     uint8_t hor_flip;
624     uint8_t ver_flip;
625     uint16_t anticlockwise_rotation;
626     uint16_t display_orientation_repetition_period;
627     uint8_t display_orientation_persistence_flag;
628 } H265RawSEIDisplayOrientation;
629
630 typedef struct H265RawSEIActiveParameterSets {
631     uint8_t active_video_parameter_set_id;
632     uint8_t self_contained_cvs_flag;
633     uint8_t no_parameter_set_update_flag;
634     uint8_t num_sps_ids_minus1;
635     uint8_t active_seq_parameter_set_id[HEVC_MAX_SPS_COUNT];
636     uint8_t layer_sps_idx[HEVC_MAX_LAYERS];
637 } H265RawSEIActiveParameterSets;
638
639 typedef struct H265RawSEIDecodedPictureHash {
640     uint8_t  hash_type;
641     uint8_t  picture_md5[3][16];
642     uint16_t picture_crc[3];
643     uint32_t picture_checksum[3];
644 } H265RawSEIDecodedPictureHash;
645
646 typedef struct H265RawSEITimeCode {
647     uint8_t  num_clock_ts;
648     uint8_t  clock_timestamp_flag[3];
649     uint8_t  units_field_based_flag[3];
650     uint8_t  counting_type[3];
651     uint8_t  full_timestamp_flag[3];
652     uint8_t  discontinuity_flag[3];
653     uint8_t  cnt_dropped_flag[3];
654     uint16_t n_frames[3];
655     uint8_t  seconds_value[3];
656     uint8_t  minutes_value[3];
657     uint8_t  hours_value[3];
658     uint8_t  seconds_flag[3];
659     uint8_t  minutes_flag[3];
660     uint8_t  hours_flag[3];
661     uint8_t  time_offset_length[3];
662     int32_t  time_offset_value[3];
663 } H265RawSEITimeCode;
664
665 typedef struct H265RawSEIMasteringDisplayColourVolume {
666     uint16_t display_primaries_x[3];
667     uint16_t display_primaries_y[3];
668     uint16_t white_point_x;
669     uint16_t white_point_y;
670     uint32_t max_display_mastering_luminance;
671     uint32_t min_display_mastering_luminance;
672 } H265RawSEIMasteringDisplayColourVolume;
673
674 typedef struct H265RawSEIContentLightLevelInfo {
675     uint16_t max_content_light_level;
676     uint16_t max_pic_average_light_level;
677 } H265RawSEIContentLightLevelInfo;
678
679 typedef struct H265RawSEIAlternativeTransferCharacteristics {
680     uint8_t preferred_transfer_characteristics;
681 } H265RawSEIAlternativeTransferCharacteristics;
682
683 typedef struct H265RawSEIPayload {
684     uint32_t payload_type;
685     uint32_t payload_size;
686     union {
687         H265RawSEIBufferingPeriod buffering_period;
688         H265RawSEIPicTiming pic_timing;
689         H265RawSEIPanScanRect pan_scan_rect;
690         H265RawSEIUserDataRegistered user_data_registered;
691         H265RawSEIUserDataUnregistered user_data_unregistered;
692         H265RawSEIRecoveryPoint recovery_point;
693         H265RawSEIDisplayOrientation display_orientation;
694         H265RawSEIActiveParameterSets active_parameter_sets;
695         H265RawSEIDecodedPictureHash decoded_picture_hash;
696         H265RawSEITimeCode time_code;
697         H265RawSEIMasteringDisplayColourVolume mastering_display;
698         H265RawSEIContentLightLevelInfo content_light_level;
699         H265RawSEIAlternativeTransferCharacteristics
700             alternative_transfer_characteristics;
701         struct {
702             uint8_t *data;
703             size_t data_length;
704             AVBufferRef *data_ref;
705         } other;
706     } payload;
707 } H265RawSEIPayload;
708
709 typedef struct H265RawSEI {
710     H265RawNALUnitHeader nal_unit_header;
711
712     H265RawSEIPayload payload[H265_MAX_SEI_PAYLOADS];
713     uint8_t payload_count;
714 } H265RawSEI;
715
716 typedef struct CodedBitstreamH265Context {
717     // Reader/writer context in common with the H.264 implementation.
718     CodedBitstreamH2645Context common;
719
720     // All currently available parameter sets.  These are updated when
721     // any parameter set NAL unit is read/written with this context.
722     AVBufferRef *vps_ref[HEVC_MAX_VPS_COUNT];
723     AVBufferRef *sps_ref[HEVC_MAX_SPS_COUNT];
724     AVBufferRef *pps_ref[HEVC_MAX_PPS_COUNT];
725     H265RawVPS *vps[HEVC_MAX_VPS_COUNT];
726     H265RawSPS *sps[HEVC_MAX_SPS_COUNT];
727     H265RawPPS *pps[HEVC_MAX_PPS_COUNT];
728
729     // The currently active parameter sets.  These are updated when any
730     // NAL unit refers to the relevant parameter set.  These pointers
731     // must also be present in the arrays above.
732     const H265RawVPS *active_vps;
733     const H265RawSPS *active_sps;
734     const H265RawPPS *active_pps;
735 } CodedBitstreamH265Context;
736
737
738 #endif /* AVCODEC_CBS_H265_H */