Commit | Line | Data |
---|---|---|
acf06f45 MT |
1 | /* |
2 | * This file is part of Libav. | |
3 | * | |
4 | * Libav 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 | * Libav 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 Libav; 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_H264_H | |
20 | #define AVCODEC_CBS_H264_H | |
21 | ||
22 | #include <stddef.h> | |
23 | #include <stdint.h> | |
24 | ||
25 | #include "cbs_h2645.h" | |
26 | #include "h264.h" | |
27 | ||
28 | ||
29 | enum { | |
30 | // This limit is arbitrary - it is sufficient for one message of each | |
31 | // type plus some repeats, and will therefore easily cover all sane | |
32 | // streams. However, it is possible to make technically-valid streams | |
33 | // for which it will fail (for example, by including a large number of | |
34 | // user-data-unregistered messages). | |
35 | H264_MAX_SEI_PAYLOADS = 64, | |
36 | }; | |
37 | ||
38 | ||
39 | typedef struct H264RawNALUnitHeader { | |
40 | uint8_t forbidden_zero_bit; | |
41 | uint8_t nal_ref_idc; | |
42 | uint8_t nal_unit_type; | |
43 | ||
44 | uint8_t svc_extension_flag; | |
45 | uint8_t avc_3d_extension_flag; | |
46 | } H264RawNALUnitHeader; | |
47 | ||
48 | typedef struct H264RawScalingList { | |
49 | int8_t delta_scale[64]; | |
50 | } H264RawScalingList; | |
51 | ||
52 | typedef struct H264RawHRD { | |
53 | uint8_t cpb_cnt_minus1; | |
54 | uint8_t bit_rate_scale; | |
55 | uint8_t cpb_size_scale; | |
56 | ||
57 | uint32_t bit_rate_value_minus1[H264_MAX_CPB_CNT]; | |
58 | uint32_t cpb_size_value_minus1[H264_MAX_CPB_CNT]; | |
59 | uint8_t cbr_flag[H264_MAX_CPB_CNT]; | |
60 | ||
61 | uint8_t initial_cpb_removal_delay_length_minus1; | |
62 | uint8_t cpb_removal_delay_length_minus1; | |
63 | uint8_t dpb_output_delay_length_minus1; | |
64 | uint8_t time_offset_length; | |
65 | } H264RawHRD; | |
66 | ||
67 | typedef struct H264RawVUI { | |
68 | uint8_t aspect_ratio_info_present_flag; | |
69 | uint8_t aspect_ratio_idc; | |
70 | uint16_t sar_width; | |
71 | uint16_t sar_height; | |
72 | ||
73 | uint8_t overscan_info_present_flag; | |
74 | uint8_t overscan_appropriate_flag; | |
75 | ||
76 | uint8_t video_signal_type_present_flag; | |
77 | uint8_t video_format; | |
78 | uint8_t video_full_range_flag; | |
79 | uint8_t colour_description_present_flag; | |
80 | uint8_t colour_primaries; | |
81 | uint8_t transfer_characteristics; | |
82 | uint8_t matrix_coefficients; | |
83 | ||
84 | uint8_t chroma_loc_info_present_flag; | |
85 | uint8_t chroma_sample_loc_type_top_field; | |
86 | uint8_t chroma_sample_loc_type_bottom_field; | |
87 | ||
88 | uint8_t timing_info_present_flag; | |
89 | uint32_t num_units_in_tick; | |
90 | uint32_t time_scale; | |
91 | uint8_t fixed_frame_rate_flag; | |
92 | ||
93 | uint8_t nal_hrd_parameters_present_flag; | |
94 | H264RawHRD nal_hrd_parameters; | |
95 | uint8_t vcl_hrd_parameters_present_flag; | |
96 | H264RawHRD vcl_hrd_parameters; | |
97 | uint8_t low_delay_hrd_flag; | |
98 | ||
99 | uint8_t pic_struct_present_flag; | |
100 | ||
101 | uint8_t bitstream_restriction_flag; | |
102 | uint8_t motion_vectors_over_pic_boundaries_flag; | |
103 | uint8_t max_bytes_per_pic_denom; | |
104 | uint8_t max_bits_per_mb_denom; | |
105 | uint8_t log2_max_mv_length_horizontal; | |
106 | uint8_t log2_max_mv_length_vertical; | |
107 | uint8_t max_num_reorder_frames; | |
108 | uint8_t max_dec_frame_buffering; | |
109 | } H264RawVUI; | |
110 | ||
111 | typedef struct H264RawSPS { | |
112 | H264RawNALUnitHeader nal_unit_header; | |
113 | ||
114 | uint8_t profile_idc; | |
115 | uint8_t constraint_set0_flag; | |
116 | uint8_t constraint_set1_flag; | |
117 | uint8_t constraint_set2_flag; | |
118 | uint8_t constraint_set3_flag; | |
119 | uint8_t constraint_set4_flag; | |
120 | uint8_t constraint_set5_flag; | |
121 | uint8_t reserved_zero_2bits; | |
122 | uint8_t level_idc; | |
123 | ||
124 | uint8_t seq_parameter_set_id; | |
125 | ||
126 | uint8_t chroma_format_idc; | |
127 | uint8_t separate_colour_plane_flag; | |
128 | uint8_t bit_depth_luma_minus8; | |
129 | uint8_t bit_depth_chroma_minus8; | |
130 | uint8_t qpprime_y_zero_transform_bypass_flag; | |
131 | ||
132 | uint8_t seq_scaling_matrix_present_flag; | |
133 | uint8_t seq_scaling_list_present_flag[12]; | |
134 | H264RawScalingList scaling_list_4x4[6]; | |
135 | H264RawScalingList scaling_list_8x8[6]; | |
136 | ||
137 | uint8_t log2_max_frame_num_minus4; | |
138 | uint8_t pic_order_cnt_type; | |
139 | uint8_t log2_max_pic_order_cnt_lsb_minus4; | |
140 | uint8_t delta_pic_order_always_zero_flag; | |
141 | int32_t offset_for_non_ref_pic; | |
142 | int32_t offset_for_top_to_bottom_field; | |
143 | uint8_t num_ref_frames_in_pic_order_cnt_cycle; | |
144 | int32_t offset_for_ref_frame[256]; | |
145 | ||
146 | uint8_t max_num_ref_frames; | |
147 | uint8_t gaps_in_frame_num_allowed_flag; | |
148 | ||
149 | uint16_t pic_width_in_mbs_minus1; | |
150 | uint16_t pic_height_in_map_units_minus1; | |
151 | ||
152 | uint8_t frame_mbs_only_flag; | |
153 | uint8_t mb_adaptive_frame_field_flag; | |
154 | uint8_t direct_8x8_inference_flag; | |
155 | ||
156 | uint8_t frame_cropping_flag; | |
157 | uint16_t frame_crop_left_offset; | |
158 | uint16_t frame_crop_right_offset; | |
159 | uint16_t frame_crop_top_offset; | |
160 | uint16_t frame_crop_bottom_offset; | |
161 | ||
162 | uint8_t vui_parameters_present_flag; | |
163 | H264RawVUI vui; | |
164 | } H264RawSPS; | |
165 | ||
166 | typedef struct H264RawSPSExtension { | |
167 | H264RawNALUnitHeader nal_unit_header; | |
168 | ||
169 | uint8_t seq_parameter_set_id; | |
170 | ||
171 | uint8_t aux_format_idc; | |
172 | uint8_t bit_depth_aux_minus8; | |
173 | uint8_t alpha_incr_flag; | |
174 | uint16_t alpha_opaque_value; | |
175 | uint16_t alpha_transparent_value; | |
176 | ||
177 | uint8_t additional_extension_flag; | |
178 | } H264RawSPSExtension; | |
179 | ||
180 | typedef struct H264RawPPS { | |
181 | H264RawNALUnitHeader nal_unit_header; | |
182 | ||
183 | uint8_t pic_parameter_set_id; | |
184 | uint8_t seq_parameter_set_id; | |
185 | ||
186 | uint8_t entropy_coding_mode_flag; | |
187 | uint8_t bottom_field_pic_order_in_frame_present_flag; | |
188 | ||
189 | uint8_t num_slice_groups_minus1; | |
190 | uint8_t slice_group_map_type; | |
191 | uint16_t run_length_minus1[H264_MAX_SLICE_GROUPS]; | |
192 | uint16_t top_left[H264_MAX_SLICE_GROUPS]; | |
193 | uint16_t bottom_right[H264_MAX_SLICE_GROUPS]; | |
194 | uint8_t slice_group_change_direction_flag; | |
195 | uint16_t slice_group_change_rate_minus1; | |
196 | uint16_t pic_size_in_map_units_minus1; | |
197 | uint8_t slice_group_id[H264_MAX_MB_PIC_SIZE]; | |
198 | ||
199 | uint8_t num_ref_idx_l0_default_active_minus1; | |
200 | uint8_t num_ref_idx_l1_default_active_minus1; | |
201 | ||
202 | uint8_t weighted_pred_flag; | |
203 | uint8_t weighted_bipred_idc; | |
204 | ||
205 | int8_t pic_init_qp_minus26; | |
206 | int8_t pic_init_qs_minus26; | |
207 | int8_t chroma_qp_index_offset; | |
208 | ||
209 | uint8_t deblocking_filter_control_present_flag; | |
210 | uint8_t constrained_intra_pred_flag; | |
211 | ||
212 | uint8_t more_rbsp_data; | |
213 | ||
214 | uint8_t redundant_pic_cnt_present_flag; | |
215 | uint8_t transform_8x8_mode_flag; | |
216 | ||
217 | uint8_t pic_scaling_matrix_present_flag; | |
218 | uint8_t pic_scaling_list_present_flag[12]; | |
219 | H264RawScalingList scaling_list_4x4[6]; | |
220 | H264RawScalingList scaling_list_8x8[6]; | |
221 | ||
222 | int8_t second_chroma_qp_index_offset; | |
223 | } H264RawPPS; | |
224 | ||
225 | typedef struct H264RawAUD { | |
226 | H264RawNALUnitHeader nal_unit_header; | |
227 | ||
228 | uint8_t primary_pic_type; | |
229 | } H264RawAUD; | |
230 | ||
231 | typedef struct H264RawSEIBufferingPeriod { | |
232 | uint8_t seq_parameter_set_id; | |
233 | struct { | |
234 | uint32_t initial_cpb_removal_delay[H264_MAX_CPB_CNT]; | |
235 | uint32_t initial_cpb_removal_delay_offset[H264_MAX_CPB_CNT]; | |
236 | } nal, vcl; | |
237 | } H264RawSEIBufferingPeriod; | |
238 | ||
239 | typedef struct H264RawSEIPicTimestamp { | |
240 | uint8_t ct_type; | |
241 | uint8_t nuit_field_based_flag; | |
242 | uint8_t counting_type; | |
243 | uint8_t full_timestamp_flag; | |
244 | uint8_t discontinuity_flag; | |
245 | uint8_t cnt_dropped_flag; | |
246 | uint8_t n_frames; | |
247 | uint8_t seconds_flag; | |
248 | uint8_t seconds_value; | |
249 | uint8_t minutes_flag; | |
250 | uint8_t minutes_value; | |
251 | uint8_t hours_flag; | |
252 | uint8_t hours_value; | |
253 | uint32_t time_offset; | |
254 | } H264RawSEIPicTimestamp; | |
255 | ||
256 | typedef struct H264RawSEIPicTiming { | |
257 | uint32_t cpb_removal_delay; | |
258 | uint32_t dpb_output_delay; | |
259 | uint8_t pic_struct; | |
260 | uint8_t clock_timestamp_flag[3]; | |
261 | H264RawSEIPicTimestamp timestamp[3]; | |
262 | } H264RawSEIPicTiming; | |
263 | ||
264 | typedef struct H264RawSEIUserDataRegistered { | |
265 | uint8_t itu_t_t35_country_code; | |
266 | uint8_t itu_t_t35_country_code_extension_byte; | |
267 | uint8_t *data; | |
268 | size_t data_length; | |
ce5870a3 | 269 | AVBufferRef *data_ref; |
acf06f45 MT |
270 | } H264RawSEIUserDataRegistered; |
271 | ||
272 | typedef struct H264RawSEIUserDataUnregistered { | |
273 | uint8_t uuid_iso_iec_11578[16]; | |
274 | uint8_t *data; | |
275 | size_t data_length; | |
ce5870a3 | 276 | AVBufferRef *data_ref; |
acf06f45 MT |
277 | } H264RawSEIUserDataUnregistered; |
278 | ||
279 | typedef struct H264RawSEIRecoveryPoint { | |
280 | uint16_t recovery_frame_cnt; | |
281 | uint8_t exact_match_flag; | |
282 | uint8_t broken_link_flag; | |
283 | uint8_t changing_slice_group_idc; | |
284 | } H264RawSEIRecoveryPoint; | |
285 | ||
286 | typedef struct H264RawSEIDisplayOrientation { | |
287 | uint8_t display_orientation_cancel_flag; | |
288 | uint8_t hor_flip; | |
289 | uint8_t ver_flip; | |
290 | uint16_t anticlockwise_rotation; | |
291 | uint16_t display_orientation_repetition_period; | |
292 | uint8_t display_orientation_extension_flag; | |
293 | } H264RawSEIDisplayOrientation; | |
294 | ||
295 | typedef struct H264RawSEIPayload { | |
296 | uint32_t payload_type; | |
297 | uint32_t payload_size; | |
298 | union { | |
299 | H264RawSEIBufferingPeriod buffering_period; | |
300 | H264RawSEIPicTiming pic_timing; | |
301 | // H264RawSEIFiller filler -> no fields. | |
302 | H264RawSEIUserDataRegistered user_data_registered; | |
303 | H264RawSEIUserDataUnregistered user_data_unregistered; | |
304 | H264RawSEIRecoveryPoint recovery_point; | |
305 | H264RawSEIDisplayOrientation display_orientation; | |
306 | struct { | |
307 | uint8_t *data; | |
308 | size_t data_length; | |
ce5870a3 | 309 | AVBufferRef *data_ref; |
acf06f45 MT |
310 | } other; |
311 | } payload; | |
312 | } H264RawSEIPayload; | |
313 | ||
314 | typedef struct H264RawSEI { | |
315 | H264RawNALUnitHeader nal_unit_header; | |
316 | ||
317 | H264RawSEIPayload payload[H264_MAX_SEI_PAYLOADS]; | |
318 | uint8_t payload_count; | |
319 | } H264RawSEI; | |
320 | ||
321 | typedef struct H264RawSliceHeader { | |
322 | H264RawNALUnitHeader nal_unit_header; | |
323 | ||
324 | uint32_t first_mb_in_slice; | |
325 | uint8_t slice_type; | |
326 | ||
327 | uint8_t pic_parameter_set_id; | |
328 | ||
329 | uint8_t colour_plane_id; | |
330 | ||
331 | uint16_t frame_num; | |
332 | uint8_t field_pic_flag; | |
333 | uint8_t bottom_field_flag; | |
334 | ||
335 | uint16_t idr_pic_id; | |
336 | ||
337 | uint16_t pic_order_cnt_lsb; | |
338 | int32_t delta_pic_order_cnt_bottom; | |
339 | int32_t delta_pic_order_cnt[2]; | |
340 | ||
341 | uint8_t redundant_pic_cnt; | |
342 | uint8_t direct_spatial_mv_pred_flag; | |
343 | ||
344 | uint8_t num_ref_idx_active_override_flag; | |
345 | uint8_t num_ref_idx_l0_active_minus1; | |
346 | uint8_t num_ref_idx_l1_active_minus1; | |
347 | ||
348 | uint8_t ref_pic_list_modification_flag_l0; | |
349 | uint8_t ref_pic_list_modification_flag_l1; | |
350 | struct { | |
351 | uint8_t modification_of_pic_nums_idc; | |
352 | int32_t abs_diff_pic_num_minus1; | |
353 | uint8_t long_term_pic_num; | |
354 | } rplm_l0[H264_MAX_RPLM_COUNT], rplm_l1[H264_MAX_RPLM_COUNT]; | |
355 | ||
356 | uint8_t luma_log2_weight_denom; | |
357 | uint8_t chroma_log2_weight_denom; | |
358 | ||
359 | uint8_t luma_weight_l0_flag[H264_MAX_REFS]; | |
360 | int8_t luma_weight_l0[H264_MAX_REFS]; | |
361 | int8_t luma_offset_l0[H264_MAX_REFS]; | |
362 | uint8_t chroma_weight_l0_flag[H264_MAX_REFS]; | |
363 | int8_t chroma_weight_l0[H264_MAX_REFS][2]; | |
364 | int8_t chroma_offset_l0[H264_MAX_REFS][2]; | |
365 | ||
366 | uint8_t luma_weight_l1_flag[H264_MAX_REFS]; | |
367 | int8_t luma_weight_l1[H264_MAX_REFS]; | |
368 | int8_t luma_offset_l1[H264_MAX_REFS]; | |
369 | uint8_t chroma_weight_l1_flag[H264_MAX_REFS]; | |
370 | int8_t chroma_weight_l1[H264_MAX_REFS][2]; | |
371 | int8_t chroma_offset_l1[H264_MAX_REFS][2]; | |
372 | ||
373 | uint8_t no_output_of_prior_pics_flag; | |
374 | uint8_t long_term_reference_flag; | |
375 | ||
376 | uint8_t adaptive_ref_pic_marking_mode_flag; | |
377 | struct { | |
378 | uint8_t memory_management_control_operation; | |
379 | int32_t difference_of_pic_nums_minus1; | |
380 | uint8_t long_term_pic_num; | |
381 | uint8_t long_term_frame_idx; | |
382 | uint8_t max_long_term_frame_idx_plus1; | |
383 | } mmco[H264_MAX_MMCO_COUNT]; | |
384 | ||
385 | uint8_t cabac_init_idc; | |
386 | ||
387 | int8_t slice_qp_delta; | |
388 | ||
389 | uint8_t sp_for_switch_flag; | |
390 | int8_t slice_qs_delta; | |
391 | ||
392 | uint8_t disable_deblocking_filter_idc; | |
393 | int8_t slice_alpha_c0_offset_div2; | |
394 | int8_t slice_beta_offset_div2; | |
395 | ||
396 | uint16_t slice_group_change_cycle; | |
397 | } H264RawSliceHeader; | |
398 | ||
399 | typedef struct H264RawSlice { | |
400 | H264RawSliceHeader header; | |
401 | ||
402 | uint8_t *data; | |
403 | size_t data_size; | |
404 | int data_bit_start; | |
ce5870a3 | 405 | AVBufferRef *data_ref; |
acf06f45 MT |
406 | } H264RawSlice; |
407 | ||
408 | ||
409 | typedef struct CodedBitstreamH264Context { | |
410 | // Reader/writer context in common with the H.265 implementation. | |
411 | CodedBitstreamH2645Context common; | |
412 | ||
413 | // All currently available parameter sets. These are updated when | |
414 | // any parameter set NAL unit is read/written with this context. | |
415 | H264RawSPS *sps[H264_MAX_SPS_COUNT]; | |
416 | H264RawPPS *pps[H264_MAX_PPS_COUNT]; | |
417 | ||
418 | // The currently active parameter sets. These are updated when any | |
419 | // NAL unit refers to the relevant parameter set. These pointers | |
420 | // must also be present in the arrays above. | |
421 | const H264RawSPS *active_sps; | |
422 | const H264RawPPS *active_pps; | |
423 | ||
424 | // The NAL unit type of the most recent normal slice. This is required | |
425 | // to be able to read/write auxiliary slices, because IdrPicFlag is | |
426 | // otherwise unknown. | |
427 | uint8_t last_slice_nal_unit_type; | |
428 | } CodedBitstreamH264Context; | |
429 | ||
430 | ||
431 | #endif /* AVCODEC_CBS_H264_H */ |