7 #ifndef MEDIA_FILTERS_H264_PARSER_H_
8 #define MEDIA_FILTERS_H264_PARSER_H_
11 #include <sys/types.h>
15 #include "packager/media/filters/h264_bit_reader.h"
17 namespace edash_packager {
25 bool ExtractResolutionFromDecoderConfig(
const uint8_t* avc_decoder_config_data,
26 size_t avc_decoder_config_data_size,
27 uint32_t* coded_width,
28 uint32_t* coded_height,
29 uint32_t* pixel_width,
30 uint32_t* pixel_height);
36 bool ExtractResolutionFromSpsData(
const uint8_t* sps_data,
38 uint32_t* coded_width,
39 uint32_t* coded_height,
40 uint32_t* pixel_width,
41 uint32_t* pixel_height);
43 bool ExtractResolutionFromSps(
const H264SPS& sps,
44 uint32_t* coded_width,
45 uint32_t* coded_height,
46 uint32_t* pixel_width,
47 uint32_t* pixel_height);
64 kCodedSliceExtension = 20,
77 kH264ScalingList4x4Length = 16,
78 kH264ScalingList8x8Length = 64,
85 bool constraint_set0_flag;
86 bool constraint_set1_flag;
87 bool constraint_set2_flag;
88 bool constraint_set3_flag;
89 bool constraint_set4_flag;
90 bool constraint_set5_flag;
92 int seq_parameter_set_id;
94 int chroma_format_idc;
95 bool separate_colour_plane_flag;
96 int bit_depth_luma_minus8;
97 int bit_depth_chroma_minus8;
98 bool qpprime_y_zero_transform_bypass_flag;
100 bool seq_scaling_matrix_present_flag;
101 int scaling_list4x4[6][kH264ScalingList4x4Length];
102 int scaling_list8x8[6][kH264ScalingList8x8Length];
104 int log2_max_frame_num_minus4;
105 int pic_order_cnt_type;
106 int log2_max_pic_order_cnt_lsb_minus4;
107 bool delta_pic_order_always_zero_flag;
108 int offset_for_non_ref_pic;
109 int offset_for_top_to_bottom_field;
110 int num_ref_frames_in_pic_order_cnt_cycle;
111 int expected_delta_per_pic_order_cnt_cycle;
112 int offset_for_ref_frame[255];
113 int max_num_ref_frames;
114 bool gaps_in_frame_num_value_allowed_flag;
115 int pic_width_in_mbs_minus1;
116 int pic_height_in_map_units_minus1;
117 bool frame_mbs_only_flag;
118 bool mb_adaptive_frame_field_flag;
119 bool direct_8x8_inference_flag;
120 bool frame_cropping_flag;
121 int frame_crop_left_offset;
122 int frame_crop_right_offset;
123 int frame_crop_top_offset;
124 int frame_crop_bottom_offset;
126 bool vui_parameters_present_flag;
129 bool bitstream_restriction_flag;
130 int max_num_reorder_frames;
131 int max_dec_frame_buffering;
133 int chroma_array_type;
139 int pic_parameter_set_id;
140 int seq_parameter_set_id;
141 bool entropy_coding_mode_flag;
142 bool bottom_field_pic_order_in_frame_present_flag;
143 int num_slice_groups_minus1;
144 int num_ref_idx_l0_default_active_minus1;
145 int num_ref_idx_l1_default_active_minus1;
146 bool weighted_pred_flag;
147 int weighted_bipred_idc;
148 int pic_init_qp_minus26;
149 int pic_init_qs_minus26;
150 int chroma_qp_index_offset;
151 bool deblocking_filter_control_present_flag;
152 bool constrained_intra_pred_flag;
153 bool redundant_pic_cnt_present_flag;
154 bool transform_8x8_mode_flag;
156 bool pic_scaling_matrix_present_flag;
157 int scaling_list4x4[6][kH264ScalingList4x4Length];
158 int scaling_list8x8[6][kH264ScalingList8x8Length];
160 int second_chroma_qp_index_offset;
164 int modification_of_pic_nums_idc;
166 int abs_diff_pic_num_minus1;
167 int long_term_pic_num;
172 bool luma_weight_flag;
173 bool chroma_weight_flag;
176 int chroma_weight[32][2];
177 int chroma_offset[32][2];
181 int memory_mgmnt_control_operation;
182 int difference_of_pic_nums_minus1;
183 int long_term_pic_num;
184 int long_term_frame_idx;
185 int max_long_term_frame_idx_plus1;
193 kRefListModSize = kRefListSize
204 bool IsPSlice()
const;
205 bool IsBSlice()
const;
206 bool IsISlice()
const;
207 bool IsSPSlice()
const;
208 bool IsSISlice()
const;
212 const uint8_t* nalu_data;
214 off_t header_bit_size;
216 int first_mb_in_slice;
218 int pic_parameter_set_id;
222 bool bottom_field_flag;
224 int pic_order_cnt_lsb;
225 int delta_pic_order_cnt_bottom;
226 int delta_pic_order_cnt[2];
227 int redundant_pic_cnt;
228 bool direct_spatial_mv_pred_flag;
230 bool num_ref_idx_active_override_flag;
231 int num_ref_idx_l0_active_minus1;
232 int num_ref_idx_l1_active_minus1;
233 bool ref_pic_list_modification_flag_l0;
234 bool ref_pic_list_modification_flag_l1;
238 int luma_log2_weight_denom;
239 int chroma_log2_weight_denom;
241 bool luma_weight_l0_flag;
242 bool chroma_weight_l0_flag;
245 bool luma_weight_l1_flag;
246 bool chroma_weight_l1_flag;
249 bool no_output_of_prior_pics_flag;
250 bool long_term_reference_flag;
252 bool adaptive_ref_pic_marking_mode_flag;
257 bool sp_for_switch_flag;
259 int disable_deblocking_filter_idc;
260 int slice_alpha_c0_offset_div2;
261 int slice_beta_offset_div2;
265 int recovery_frame_cnt;
266 bool exact_match_flag;
267 bool broken_link_flag;
268 int changing_slice_group_idc;
275 kSEIRecoveryPoint = 6,
309 static bool FindStartCode(
const uint8_t* data,
312 off_t* start_code_size);
320 void SetStream(
const uint8_t* stream, off_t stream_size);
328 Result AdvanceToNextNALU(
H264NALU* nalu);
343 Result ParseSPS(
int* sps_id);
344 Result ParsePPS(
int* pps_id);
347 Result ParseSPSFromArray(
const uint8_t* sps_data,
348 size_t sps_data_size,
353 const H264SPS* GetSPS(
int sps_id);
354 const H264PPS* GetPPS(
int pps_id);
377 bool LocateNALU(off_t* nalu_size, off_t* start_code_size);
381 Result ReadUE(
int* val);
384 Result ReadSE(
int* val);
387 Result ParseScalingList(
int size,
int* scaling_list,
bool* use_default);
388 Result ParseSPSScalingLists(
H264SPS* sps);
392 Result ParseVUIParameters(
H264SPS* sps);
394 Result ParseAndIgnoreHRDParameters(
bool* hrd_parameters_present);
398 Result ParseRefPicListModification(
int num_ref_idx_active_minus1,
405 Result ParseWeightingFactors(
int num_ref_idx_active_minus1,
406 int chroma_array_type,
407 int luma_log2_weight_denom,
408 int chroma_log2_weight_denom,
415 const uint8_t* stream_;
423 typedef std::map<int, H264SPS*> SPSById;
424 typedef std::map<int, H264PPS*> PPSById;
425 SPSById active_SPSes_;
426 PPSById active_PPSes_;
434 #endif // MEDIA_FILTERS_H264_PARSER_H_