Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: media/filters/h264_parser.h

Issue 119153002: Move H264Parser and H264BitReader to media/filters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/filters/h264_bit_reader_unittest.cc ('k') | media/filters/h264_parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // This file contains an implementation of an H264 Annex-B video stream parser. 5 // This file contains an implementation of an H264 Annex-B video stream parser.
6 6
7 #ifndef CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ 7 #ifndef MEDIA_FILTERS_H264_PARSER_H_
8 #define CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ 8 #define MEDIA_FILTERS_H264_PARSER_H_
9 9
10 #include <sys/types.h> 10 #include <sys/types.h>
11 11
12 #include <map> 12 #include <map>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "content/common/content_export.h" 15 #include "media/base/media_export.h"
16 #include "content/common/gpu/media/h264_bit_reader.h" 16 #include "media/filters/h264_bit_reader.h"
17 17
18 namespace content { 18 namespace media {
19 19
20 // For explanations of each struct and its members, see H.264 specification 20 // For explanations of each struct and its members, see H.264 specification
21 // at http://www.itu.int/rec/T-REC-H.264. 21 // at http://www.itu.int/rec/T-REC-H.264.
22 struct CONTENT_EXPORT H264NALU { 22 struct MEDIA_EXPORT H264NALU {
23 H264NALU(); 23 H264NALU();
24 24
25 enum Type { 25 enum Type {
26 kUnspecified = 0, 26 kUnspecified = 0,
27 kNonIDRSlice = 1, 27 kNonIDRSlice = 1,
28 kIDRSlice = 5, 28 kIDRSlice = 5,
29 kSEIMessage = 6, 29 kSEIMessage = 6,
30 kSPS = 7, 30 kSPS = 7,
31 kPPS = 8, 31 kPPS = 8,
32 kEOSeq = 9, 32 kEOSeq = 9,
33 kEOStream = 11, 33 kEOStream = 11,
34 kCodedSliceExtension = 20, 34 kCodedSliceExtension = 20,
35 }; 35 };
36 36
37 // After (without) start code; we don't own the underlying memory 37 // After (without) start code; we don't own the underlying memory
38 // and a shallow copy should be made when copying this struct. 38 // and a shallow copy should be made when copying this struct.
39 const uint8* data; 39 const uint8* data;
40 off_t size; // From after start code to start code of next NALU (or EOS). 40 off_t size; // From after start code to start code of next NALU (or EOS).
41 41
42 int nal_ref_idc; 42 int nal_ref_idc;
43 int nal_unit_type; 43 int nal_unit_type;
44 }; 44 };
45 45
46 enum { kH264ScalingList4x4Length = 16, kH264ScalingList8x8Length = 64, }; 46 enum {
47 kH264ScalingList4x4Length = 16,
48 kH264ScalingList8x8Length = 64,
49 };
47 50
48 struct CONTENT_EXPORT H264SPS { 51 struct MEDIA_EXPORT H264SPS {
49 H264SPS(); 52 H264SPS();
50 53
51 int profile_idc; 54 int profile_idc;
52 int constraint_setx_flag; 55 int constraint_setx_flag;
53 int level_idc; 56 int level_idc;
54 int seq_parameter_set_id; 57 int seq_parameter_set_id;
55 58
56 int chroma_format_idc; 59 int chroma_format_idc;
57 bool separate_colour_plane_flag; 60 bool separate_colour_plane_flag;
58 int bit_depth_luma_minus8; 61 int bit_depth_luma_minus8;
59 int bit_depth_chroma_minus8; 62 int bit_depth_chroma_minus8;
60 bool qpprime_y_zero_transform_bypass_flag; 63 bool qpprime_y_zero_transform_bypass_flag;
61 64
62 bool seq_scaling_matrix_present_flag; 65 bool seq_scaling_matrix_present_flag;
63 int scaling_list4x4[6][kH264ScalingList4x4Length]; 66 int scaling_list4x4[6][kH264ScalingList4x4Length];
64 int scaling_list8x8[6][kH264ScalingList8x8Length]; 67 int scaling_list8x8[6][kH264ScalingList8x8Length];
65 68
66 int log2_max_frame_num_minus4; 69 int log2_max_frame_num_minus4;
67 int pic_order_cnt_type; 70 int pic_order_cnt_type;
68 int log2_max_pic_order_cnt_lsb_minus4; 71 int log2_max_pic_order_cnt_lsb_minus4;
69 bool delta_pic_order_always_zero_flag; 72 bool delta_pic_order_always_zero_flag;
70 int offset_for_non_ref_pic; 73 int offset_for_non_ref_pic;
71 int offset_for_top_to_bottom_field; 74 int offset_for_top_to_bottom_field;
72 int num_ref_frames_in_pic_order_cnt_cycle; 75 int num_ref_frames_in_pic_order_cnt_cycle;
73 int expected_delta_per_pic_order_cnt_cycle; // calculated 76 int expected_delta_per_pic_order_cnt_cycle; // calculated
74 int offset_for_ref_frame[255]; 77 int offset_for_ref_frame[255];
75 int max_num_ref_frames; 78 int max_num_ref_frames;
76 bool gaps_in_frame_num_value_allowed_flag; 79 bool gaps_in_frame_num_value_allowed_flag;
77 int pic_width_in_mbs_minus1; 80 int pic_width_in_mbs_minus1;
78 int pic_height_in_map_units_minus1; 81 int pic_height_in_map_units_minus1;
79 bool frame_mbs_only_flag; 82 bool frame_mbs_only_flag;
80 bool mb_adaptive_frame_field_flag; 83 bool mb_adaptive_frame_field_flag;
81 bool direct_8x8_inference_flag; 84 bool direct_8x8_inference_flag;
82 bool frame_cropping_flag; 85 bool frame_cropping_flag;
83 int frame_crop_left_offset; 86 int frame_crop_left_offset;
84 int frame_crop_right_offset; 87 int frame_crop_right_offset;
85 int frame_crop_top_offset; 88 int frame_crop_top_offset;
86 int frame_crop_bottom_offset; 89 int frame_crop_bottom_offset;
87 bool vui_parameters_present_flag; 90 bool vui_parameters_present_flag;
88 int chroma_array_type; 91 int chroma_array_type;
89 }; 92 };
90 93
91 struct CONTENT_EXPORT H264PPS { 94 struct MEDIA_EXPORT H264PPS {
92 H264PPS(); 95 H264PPS();
93 96
94 int pic_parameter_set_id; 97 int pic_parameter_set_id;
95 int seq_parameter_set_id; 98 int seq_parameter_set_id;
96 bool entropy_coding_mode_flag; 99 bool entropy_coding_mode_flag;
97 bool bottom_field_pic_order_in_frame_present_flag; 100 bool bottom_field_pic_order_in_frame_present_flag;
98 int num_slice_groups_minus1; 101 int num_slice_groups_minus1;
99 // TODO(posciak): Slice groups not implemented, could be added at some point. 102 // TODO(posciak): Slice groups not implemented, could be added at some point.
100 int num_ref_idx_l0_default_active_minus1; 103 int num_ref_idx_l0_default_active_minus1;
101 int num_ref_idx_l1_default_active_minus1; 104 int num_ref_idx_l1_default_active_minus1;
102 bool weighted_pred_flag; 105 bool weighted_pred_flag;
103 int weighted_bipred_idc; 106 int weighted_bipred_idc;
104 int pic_init_qp_minus26; 107 int pic_init_qp_minus26;
105 int pic_init_qs_minus26; 108 int pic_init_qs_minus26;
106 int chroma_qp_index_offset; 109 int chroma_qp_index_offset;
107 bool deblocking_filter_control_present_flag; 110 bool deblocking_filter_control_present_flag;
108 bool constrained_intra_pred_flag; 111 bool constrained_intra_pred_flag;
109 bool redundant_pic_cnt_present_flag; 112 bool redundant_pic_cnt_present_flag;
110 bool transform_8x8_mode_flag; 113 bool transform_8x8_mode_flag;
111 114
112 bool pic_scaling_matrix_present_flag; 115 bool pic_scaling_matrix_present_flag;
113 int scaling_list4x4[6][kH264ScalingList4x4Length]; 116 int scaling_list4x4[6][kH264ScalingList4x4Length];
114 int scaling_list8x8[6][kH264ScalingList8x8Length]; 117 int scaling_list8x8[6][kH264ScalingList8x8Length];
115 118
116 int second_chroma_qp_index_offset; 119 int second_chroma_qp_index_offset;
117 }; 120 };
118 121
119 struct CONTENT_EXPORT H264ModificationOfPicNum { 122 struct MEDIA_EXPORT H264ModificationOfPicNum {
120 int modification_of_pic_nums_idc; 123 int modification_of_pic_nums_idc;
121 union { 124 union {
122 int abs_diff_pic_num_minus1; 125 int abs_diff_pic_num_minus1;
123 int long_term_pic_num; 126 int long_term_pic_num;
124 }; 127 };
125 }; 128 };
126 129
127 struct CONTENT_EXPORT H264WeightingFactors { 130 struct MEDIA_EXPORT H264WeightingFactors {
128 bool luma_weight_flag; 131 bool luma_weight_flag;
129 bool chroma_weight_flag; 132 bool chroma_weight_flag;
130 int luma_weight[32]; 133 int luma_weight[32];
131 int luma_offset[32]; 134 int luma_offset[32];
132 int chroma_weight[32][2]; 135 int chroma_weight[32][2];
133 int chroma_offset[32][2]; 136 int chroma_offset[32][2];
134 }; 137 };
135 138
136 struct CONTENT_EXPORT H264DecRefPicMarking { 139 struct MEDIA_EXPORT H264DecRefPicMarking {
137 int memory_mgmnt_control_operation; 140 int memory_mgmnt_control_operation;
138 int difference_of_pic_nums_minus1; 141 int difference_of_pic_nums_minus1;
139 int long_term_pic_num; 142 int long_term_pic_num;
140 int long_term_frame_idx; 143 int long_term_frame_idx;
141 int max_long_term_frame_idx_plus1; 144 int max_long_term_frame_idx_plus1;
142 }; 145 };
143 146
144 struct CONTENT_EXPORT H264SliceHeader { 147 struct MEDIA_EXPORT H264SliceHeader {
145 H264SliceHeader(); 148 H264SliceHeader();
146 149
147 enum { 150 enum {
148 kRefListSize = 32, 151 kRefListSize = 32,
149 kRefListModSize = kRefListSize 152 kRefListModSize = kRefListSize
150 }; 153 };
151 154
152 enum Type { 155 enum Type {
153 kPSlice = 0, 156 kPSlice = 0,
154 kBSlice = 1, 157 kBSlice = 1,
155 kISlice = 2, 158 kISlice = 2,
156 kSPSlice = 3, 159 kSPSlice = 3,
157 kSISlice = 4, 160 kSISlice = 4,
158 }; 161 };
159 162
160 bool IsPSlice() const; 163 bool IsPSlice() const;
161 bool IsBSlice() const; 164 bool IsBSlice() const;
162 bool IsISlice() const; 165 bool IsISlice() const;
163 bool IsSPSlice() const; 166 bool IsSPSlice() const;
164 bool IsSISlice() const; 167 bool IsSISlice() const;
165 168
166 bool idr_pic_flag; // from NAL header 169 bool idr_pic_flag; // from NAL header
167 int nal_ref_idc; // from NAL header 170 int nal_ref_idc; // from NAL header
168 const uint8* nalu_data; // from NAL header 171 const uint8* nalu_data; // from NAL header
169 off_t nalu_size; // from NAL header 172 off_t nalu_size; // from NAL header
170 off_t header_bit_size; // calculated 173 off_t header_bit_size; // calculated
171 174
172 int first_mb_in_slice; 175 int first_mb_in_slice;
173 int slice_type; 176 int slice_type;
174 int pic_parameter_set_id; 177 int pic_parameter_set_id;
175 int colour_plane_id; // TODO(posciak): use this! http://crbug.com/139878 178 int colour_plane_id; // TODO(posciak): use this! http://crbug.com/139878
176 int frame_num; 179 int frame_num;
177 bool field_pic_flag; 180 bool field_pic_flag;
178 bool bottom_field_flag; 181 bool bottom_field_flag;
179 int idr_pic_id; 182 int idr_pic_id;
180 int pic_order_cnt_lsb; 183 int pic_order_cnt_lsb;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 int slice_beta_offset_div2; 220 int slice_beta_offset_div2;
218 }; 221 };
219 222
220 struct H264SEIRecoveryPoint { 223 struct H264SEIRecoveryPoint {
221 int recovery_frame_cnt; 224 int recovery_frame_cnt;
222 bool exact_match_flag; 225 bool exact_match_flag;
223 bool broken_link_flag; 226 bool broken_link_flag;
224 int changing_slice_group_idc; 227 int changing_slice_group_idc;
225 }; 228 };
226 229
227 struct CONTENT_EXPORT H264SEIMessage { 230 struct MEDIA_EXPORT H264SEIMessage {
228 H264SEIMessage(); 231 H264SEIMessage();
229 232
230 enum Type { 233 enum Type {
231 kSEIRecoveryPoint = 6, 234 kSEIRecoveryPoint = 6,
232 }; 235 };
233 236
234 int type; 237 int type;
235 int payload_size; 238 int payload_size;
236 union { 239 union {
237 // Placeholder; in future more supported types will contribute to more 240 // Placeholder; in future more supported types will contribute to more
238 // union members here. 241 // union members here.
239 H264SEIRecoveryPoint recovery_point; 242 H264SEIRecoveryPoint recovery_point;
240 }; 243 };
241 }; 244 };
242 245
243 // Class to parse an Annex-B H.264 stream, 246 // Class to parse an Annex-B H.264 stream,
244 // as specified in chapters 7 and Annex B of the H.264 spec. 247 // as specified in chapters 7 and Annex B of the H.264 spec.
245 class CONTENT_EXPORT H264Parser { 248 class MEDIA_EXPORT H264Parser {
246 public: 249 public:
247 enum Result { 250 enum Result {
248 kOk, 251 kOk,
249 kInvalidStream, // error in stream 252 kInvalidStream, // error in stream
250 kUnsupportedStream, // stream not supported by the parser 253 kUnsupportedStream, // stream not supported by the parser
251 kEOStream, // end of stream 254 kEOStream, // end of stream
252 }; 255 };
253 256
254 H264Parser(); 257 H264Parser();
255 ~H264Parser(); 258 ~H264Parser();
256 259
257 void Reset(); 260 void Reset();
258 // Set current stream pointer to |stream| of |stream_size| in bytes, 261 // Set current stream pointer to |stream| of |stream_size| in bytes,
259 // |stream| owned by caller. 262 // |stream| owned by caller.
260 void SetStream(const uint8* stream, off_t stream_size); 263 void SetStream(const uint8* stream, off_t stream_size);
261 264
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 Result ParsePredWeightTable(const H264SPS& sps, H264SliceHeader* shdr); 327 Result ParsePredWeightTable(const H264SPS& sps, H264SliceHeader* shdr);
325 328
326 // Parse weighting factors (see spec). 329 // Parse weighting factors (see spec).
327 Result ParseWeightingFactors(int num_ref_idx_active_minus1, 330 Result ParseWeightingFactors(int num_ref_idx_active_minus1,
328 int chroma_array_type, 331 int chroma_array_type,
329 int luma_log2_weight_denom, 332 int luma_log2_weight_denom,
330 int chroma_log2_weight_denom, 333 int chroma_log2_weight_denom,
331 H264WeightingFactors* w_facts); 334 H264WeightingFactors* w_facts);
332 335
333 // Parse decoded reference picture marking information (see spec). 336 // Parse decoded reference picture marking information (see spec).
334 Result ParseDecRefPicMarking(H264SliceHeader *shdr); 337 Result ParseDecRefPicMarking(H264SliceHeader* shdr);
335 338
336 // Pointer to the current NALU in the stream. 339 // Pointer to the current NALU in the stream.
337 const uint8* stream_; 340 const uint8* stream_;
338 341
339 // Bytes left in the stream after the current NALU. 342 // Bytes left in the stream after the current NALU.
340 off_t bytes_left_; 343 off_t bytes_left_;
341 344
342 H264BitReader br_; 345 H264BitReader br_;
343 346
344 // PPSes and SPSes stored for future reference. 347 // PPSes and SPSes stored for future reference.
345 typedef std::map<int, H264SPS*> SPSById; 348 typedef std::map<int, H264SPS*> SPSById;
346 typedef std::map<int, H264PPS*> PPSById; 349 typedef std::map<int, H264PPS*> PPSById;
347 SPSById active_SPSes_; 350 SPSById active_SPSes_;
348 PPSById active_PPSes_; 351 PPSById active_PPSes_;
349 352
350 DISALLOW_COPY_AND_ASSIGN(H264Parser); 353 DISALLOW_COPY_AND_ASSIGN(H264Parser);
351 }; 354 };
352 355
353 } // namespace content 356 } // namespace media
354 357
355 #endif // CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ 358 #endif // MEDIA_FILTERS_H264_PARSER_H_
OLDNEW
« no previous file with comments | « media/filters/h264_bit_reader_unittest.cc ('k') | media/filters/h264_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698