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 {
24 bool ExtractResolutionFromSps(
const H264SPS& sps,
25 uint32_t* coded_width,
26 uint32_t* coded_height,
27 uint32_t* pixel_width,
28 uint32_t* pixel_height);
45 kCodedSliceExtension = 20,
58 kH264ScalingList4x4Length = 16,
59 kH264ScalingList8x8Length = 64,
66 bool constraint_set0_flag;
67 bool constraint_set1_flag;
68 bool constraint_set2_flag;
69 bool constraint_set3_flag;
70 bool constraint_set4_flag;
71 bool constraint_set5_flag;
73 int seq_parameter_set_id;
75 int chroma_format_idc;
76 bool separate_colour_plane_flag;
77 int bit_depth_luma_minus8;
78 int bit_depth_chroma_minus8;
79 bool qpprime_y_zero_transform_bypass_flag;
81 bool seq_scaling_matrix_present_flag;
82 int scaling_list4x4[6][kH264ScalingList4x4Length];
83 int scaling_list8x8[6][kH264ScalingList8x8Length];
85 int log2_max_frame_num_minus4;
86 int pic_order_cnt_type;
87 int log2_max_pic_order_cnt_lsb_minus4;
88 bool delta_pic_order_always_zero_flag;
89 int offset_for_non_ref_pic;
90 int offset_for_top_to_bottom_field;
91 int num_ref_frames_in_pic_order_cnt_cycle;
92 int expected_delta_per_pic_order_cnt_cycle;
93 int offset_for_ref_frame[255];
94 int max_num_ref_frames;
95 bool gaps_in_frame_num_value_allowed_flag;
96 int pic_width_in_mbs_minus1;
97 int pic_height_in_map_units_minus1;
98 bool frame_mbs_only_flag;
99 bool mb_adaptive_frame_field_flag;
100 bool direct_8x8_inference_flag;
101 bool frame_cropping_flag;
102 int frame_crop_left_offset;
103 int frame_crop_right_offset;
104 int frame_crop_top_offset;
105 int frame_crop_bottom_offset;
107 bool vui_parameters_present_flag;
110 bool bitstream_restriction_flag;
111 int max_num_reorder_frames;
112 int max_dec_frame_buffering;
114 int chroma_array_type;
120 int pic_parameter_set_id;
121 int seq_parameter_set_id;
122 bool entropy_coding_mode_flag;
123 bool bottom_field_pic_order_in_frame_present_flag;
124 int num_slice_groups_minus1;
125 int num_ref_idx_l0_default_active_minus1;
126 int num_ref_idx_l1_default_active_minus1;
127 bool weighted_pred_flag;
128 int weighted_bipred_idc;
129 int pic_init_qp_minus26;
130 int pic_init_qs_minus26;
131 int chroma_qp_index_offset;
132 bool deblocking_filter_control_present_flag;
133 bool constrained_intra_pred_flag;
134 bool redundant_pic_cnt_present_flag;
135 bool transform_8x8_mode_flag;
137 bool pic_scaling_matrix_present_flag;
138 int scaling_list4x4[6][kH264ScalingList4x4Length];
139 int scaling_list8x8[6][kH264ScalingList8x8Length];
141 int second_chroma_qp_index_offset;
145 int modification_of_pic_nums_idc;
147 int abs_diff_pic_num_minus1;
148 int long_term_pic_num;
153 bool luma_weight_flag;
154 bool chroma_weight_flag;
157 int chroma_weight[32][2];
158 int chroma_offset[32][2];
162 int memory_mgmnt_control_operation;
163 int difference_of_pic_nums_minus1;
164 int long_term_pic_num;
165 int long_term_frame_idx;
166 int max_long_term_frame_idx_plus1;
174 kRefListModSize = kRefListSize
185 bool IsPSlice()
const;
186 bool IsBSlice()
const;
187 bool IsISlice()
const;
188 bool IsSPSlice()
const;
189 bool IsSISlice()
const;
193 const uint8_t* nalu_data;
195 off_t header_bit_size;
197 int first_mb_in_slice;
199 int pic_parameter_set_id;
203 bool bottom_field_flag;
205 int pic_order_cnt_lsb;
206 int delta_pic_order_cnt_bottom;
207 int delta_pic_order_cnt[2];
208 int redundant_pic_cnt;
209 bool direct_spatial_mv_pred_flag;
211 bool num_ref_idx_active_override_flag;
212 int num_ref_idx_l0_active_minus1;
213 int num_ref_idx_l1_active_minus1;
214 bool ref_pic_list_modification_flag_l0;
215 bool ref_pic_list_modification_flag_l1;
219 int luma_log2_weight_denom;
220 int chroma_log2_weight_denom;
222 bool luma_weight_l0_flag;
223 bool chroma_weight_l0_flag;
226 bool luma_weight_l1_flag;
227 bool chroma_weight_l1_flag;
230 bool no_output_of_prior_pics_flag;
231 bool long_term_reference_flag;
233 bool adaptive_ref_pic_marking_mode_flag;
238 bool sp_for_switch_flag;
240 int disable_deblocking_filter_idc;
241 int slice_alpha_c0_offset_div2;
242 int slice_beta_offset_div2;
246 int recovery_frame_cnt;
247 bool exact_match_flag;
248 bool broken_link_flag;
249 int changing_slice_group_idc;
256 kSEIRecoveryPoint = 6,
290 static bool FindStartCode(
const uint8_t* data,
293 off_t* start_code_size);
301 void SetStream(
const uint8_t* stream, off_t stream_size);
309 Result AdvanceToNextNALU(
H264NALU* nalu);
324 Result ParseSPS(
int* sps_id);
325 Result ParsePPS(
int* pps_id);
328 Result ParseSPSFromArray(
const uint8_t* sps_data,
329 size_t sps_data_size,
334 const H264SPS* GetSPS(
int sps_id);
335 const H264PPS* GetPPS(
int pps_id);
358 bool LocateNALU(off_t* nalu_size, off_t* start_code_size);
362 Result ReadUE(
int* val);
365 Result ReadSE(
int* val);
368 Result ParseScalingList(
int size,
int* scaling_list,
bool* use_default);
369 Result ParseSPSScalingLists(
H264SPS* sps);
373 Result ParseVUIParameters(
H264SPS* sps);
375 Result ParseAndIgnoreHRDParameters(
bool* hrd_parameters_present);
379 Result ParseRefPicListModification(
int num_ref_idx_active_minus1,
386 Result ParseWeightingFactors(
int num_ref_idx_active_minus1,
387 int chroma_array_type,
388 int luma_log2_weight_denom,
389 int chroma_log2_weight_denom,
396 const uint8_t* stream_;
404 typedef std::map<int, H264SPS*> SPSById;
405 typedef std::map<int, H264PPS*> PPSById;
406 SPSById active_SPSes_;
407 PPSById active_PPSes_;
415 #endif // MEDIA_FILTERS_H264_PARSER_H_