1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2012-2014 L-SMASH project
6 * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
8 * Permission to use, copy, modify, and/or distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 *****************************************************************************/
21 /* This file is available under an ISC license. */
25 H264_NALU_TYPE_UNSPECIFIED0
= 0, /* Unspecified */
26 H264_NALU_TYPE_SLICE_N_IDR
= 1, /* Coded slice of a non-IDR picture */
27 H264_NALU_TYPE_SLICE_DP_A
= 2, /* Coded slice data partition A */
28 H264_NALU_TYPE_SLICE_DP_B
= 3, /* Coded slice data partition B */
29 H264_NALU_TYPE_SLICE_DP_C
= 4, /* Coded slice data partition C */
30 H264_NALU_TYPE_SLICE_IDR
= 5, /* Coded slice of an IDR picture */
31 H264_NALU_TYPE_SEI
= 6, /* Supplemental Enhancement Information */
32 H264_NALU_TYPE_SPS
= 7, /* Sequence Parameter Set */
33 H264_NALU_TYPE_PPS
= 8, /* Picture Parameter Set */
34 H264_NALU_TYPE_AUD
= 9, /* Access Unit Delimiter */
35 H264_NALU_TYPE_EOS
= 10, /* End of Sequence */
36 H264_NALU_TYPE_EOB
= 11, /* End of Bitstream */
37 H264_NALU_TYPE_FD
= 12, /* Filler Data */
38 H264_NALU_TYPE_SPS_EXT
= 13, /* Sequence Parameter Set Extension */
39 H264_NALU_TYPE_PREFIX
= 14, /* Prefix NAL unit */
40 H264_NALU_TYPE_SUBSET_SPS
= 15, /* Subset Sequence Parameter Set */
41 H264_NALU_TYPE_RSV_NVCL16
= 16, /* Reserved */
42 H264_NALU_TYPE_RSV_NVCL17
= 17, /* Reserved */
43 H264_NALU_TYPE_RSV_NVCL18
= 18, /* Reserved */
44 H264_NALU_TYPE_SLICE_AUX
= 19, /* Coded slice of an auxiliary coded picture without partitioning */
45 H264_NALU_TYPE_SLICE_EXT
= 20, /* Coded slice extension */
46 H264_NALU_TYPE_SLICE_EXT_DVC
= 21, /* Coded slice extension for depth view components */
47 H264_NALU_TYPE_RSV22
= 22, /* Reserved */
48 H264_NALU_TYPE_RSV23
= 23, /* Reserved */
49 H264_NALU_TYPE_UNSPECIFIED24
= 24, /* Unspecified */
50 H264_NALU_TYPE_UNSPECIFIED31
= 31, /* Unspecified */
53 struct lsmash_h264_parameter_sets_tag
55 /* Each list contains entries as isom_dcr_ps_entry_t. */
56 lsmash_entry_list_t sps_list
[1];
57 lsmash_entry_list_t pps_list
[1];
58 lsmash_entry_list_t spsext_list
[1];
63 unsigned forbidden_zero_bit
: 1;
64 unsigned nal_ref_idc
: 2;
65 unsigned nal_unit_type
: 5;
72 uint8_t CpbDpbDelaysPresentFlag
;
73 uint8_t cpb_removal_delay_length
;
74 uint8_t dpb_output_delay_length
;
81 uint8_t video_full_range_flag
;
82 uint8_t colour_primaries
;
83 uint8_t transfer_characteristics
;
84 uint8_t matrix_coefficients
;
85 uint32_t num_units_in_tick
;
87 uint8_t fixed_frame_rate_flag
;
88 uint8_t pic_struct_present_flag
;
96 uint8_t constraint_set_flags
;
98 uint8_t seq_parameter_set_id
;
99 uint8_t chroma_format_idc
;
100 uint8_t separate_colour_plane_flag
;
101 uint8_t ChromaArrayType
;
102 uint8_t bit_depth_luma_minus8
;
103 uint8_t bit_depth_chroma_minus8
;
104 uint8_t pic_order_cnt_type
;
105 uint8_t delta_pic_order_always_zero_flag
;
106 uint8_t num_ref_frames_in_pic_order_cnt_cycle
;
107 uint8_t frame_mbs_only_flag
;
108 int32_t offset_for_non_ref_pic
;
109 int32_t offset_for_top_to_bottom_field
;
110 int32_t offset_for_ref_frame
[255];
111 int64_t ExpectedDeltaPerPicOrderCntCycle
;
112 uint32_t max_num_ref_frames
;
113 uint32_t log2_max_frame_num
;
114 uint32_t MaxFrameNum
;
115 uint32_t log2_max_pic_order_cnt_lsb
;
116 uint32_t MaxPicOrderCntLsb
;
117 uint32_t PicSizeInMapUnits
;
118 uint32_t cropped_width
;
119 uint32_t cropped_height
;
126 uint8_t pic_parameter_set_id
;
127 uint8_t seq_parameter_set_id
;
128 uint8_t entropy_coding_mode_flag
;
129 uint8_t bottom_field_pic_order_in_frame_present_flag
;
130 uint8_t num_slice_groups_minus1
;
131 uint8_t slice_group_map_type
;
132 uint8_t num_ref_idx_l0_default_active_minus1
;
133 uint8_t num_ref_idx_l1_default_active_minus1
;
134 uint8_t weighted_pred_flag
;
135 uint8_t weighted_bipred_idc
;
136 uint8_t deblocking_filter_control_present_flag
;
137 uint8_t redundant_pic_cnt_present_flag
;
138 uint32_t SliceGroupChangeRate
;
150 uint8_t random_accessible
;
151 uint8_t broken_link_flag
;
152 uint32_t recovery_frame_cnt
;
153 } h264_recovery_point_t
;
157 h264_pic_timing_t pic_timing
;
158 h264_recovery_point_t recovery_point
;
164 uint8_t slice_id
; /* only for slice data partition */
166 uint8_t pic_order_cnt_type
;
169 uint8_t seq_parameter_set_id
;
170 uint8_t pic_parameter_set_id
;
171 uint8_t field_pic_flag
;
172 uint8_t bottom_field_flag
;
174 uint8_t has_redundancy
;
177 int32_t pic_order_cnt_lsb
;
178 int32_t delta_pic_order_cnt_bottom
;
179 int32_t delta_pic_order_cnt
[2];
184 H264_PICTURE_TYPE_IDR
= 0,
185 H264_PICTURE_TYPE_I
= 1,
186 H264_PICTURE_TYPE_I_P
= 2,
187 H264_PICTURE_TYPE_I_P_B
= 3,
188 H264_PICTURE_TYPE_SI
= 4,
189 H264_PICTURE_TYPE_SI_SP
= 5,
190 H264_PICTURE_TYPE_I_SI
= 6,
191 H264_PICTURE_TYPE_I_SI_P_SP
= 7,
192 H264_PICTURE_TYPE_I_SI_P_SP_B
= 8,
193 H264_PICTURE_TYPE_NONE
= 9,
198 h264_picture_type type
;
200 uint8_t random_accessible
;
202 uint8_t disposable
; /* 1: nal_ref_idc == 0, 0: otherwise */
203 uint8_t has_redundancy
;
205 uint8_t pic_parameter_set_id
;
206 uint8_t field_pic_flag
;
207 uint8_t bottom_field_flag
;
209 uint8_t broken_link_flag
;
212 uint8_t ref_pic_has_mmco5
;
213 uint8_t ref_pic_bottom_field_flag
;
214 int32_t ref_pic_TopFieldOrderCnt
;
215 int32_t ref_pic_PicOrderCntMsb
;
216 int32_t ref_pic_PicOrderCntLsb
;
217 int32_t pic_order_cnt_lsb
;
218 int32_t delta_pic_order_cnt_bottom
;
219 int32_t delta_pic_order_cnt
[2];
221 uint32_t FrameNumOffset
;
223 uint32_t recovery_frame_cnt
;
225 } h264_picture_info_t
;
230 uint8_t *incomplete_data
;
232 uint32_t incomplete_length
;
234 h264_picture_info_t picture
;
235 } h264_access_unit_t
;
237 typedef struct h264_info_tag h264_info_t
;
241 lsmash_multiple_buffers_t
*bank
;
243 } h264_stream_buffer_t
;
247 lsmash_h264_specific_parameters_t avcC_param
;
248 lsmash_h264_specific_parameters_t avcC_param_next
;
249 lsmash_entry_list_t sps_list
[1]; /* contains entries as h264_sps_t */
250 lsmash_entry_list_t pps_list
[1]; /* contains entries as h264_pps_t */
251 lsmash_entry_list_t slice_list
[1]; /* for slice data partition */
252 h264_sps_t sps
; /* active SPS */
253 h264_pps_t pps
; /* active PPS */
254 h264_sei_t sei
; /* active SEI */
255 h264_slice_info_t slice
; /* active slice */
256 h264_access_unit_t au
;
257 uint8_t prev_nalu_type
;
258 uint8_t avcC_pending
;
260 h264_stream_buffer_t buffer
;
263 int h264_setup_parser
269 void h264_cleanup_parser
274 uint64_t h264_find_next_start_code
277 h264_nalu_header_t
*nuh
,
278 uint64_t *start_code_length
,
279 uint64_t *trailing_zero_bytes
282 int h264_calculate_poc
285 h264_picture_info_t
*picture
,
286 h264_picture_info_t
*prev_picture
289 void h264_update_picture_info_for_slice
292 h264_picture_info_t
*picture
,
293 h264_slice_info_t
*slice
296 void h264_update_picture_info
299 h264_picture_info_t
*picture
,
300 h264_slice_info_t
*slice
,
304 int h264_find_au_delimit_by_slice_info
306 h264_slice_info_t
*slice
,
307 h264_slice_info_t
*prev_slice
310 int h264_find_au_delimit_by_nalu_type
313 uint8_t prev_nalu_type
316 int h264_supplement_buffer
318 h264_stream_buffer_t
*buffer
,
319 h264_access_unit_t
*au
,
326 uint8_t *rbsp_buffer
,
334 uint8_t *rbsp_buffer
,
344 uint8_t *rbsp_buffer
,
352 h264_nalu_header_t
*nuh
,
353 uint8_t *rbsp_buffer
,
358 int h264_try_to_append_parameter_set
361 lsmash_h264_parameter_set_type ps_type
,
366 int h264_move_pending_avcC_param