OLD | NEW |
---|---|
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 CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ |
8 #define CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ | 8 #define CONTENT_COMMON_GPU_MEDIA_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 "base/compiler_specific.h" | |
15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
17 #include "media/base/bit_reader.h" | |
16 | 18 |
17 namespace content { | 19 namespace content { |
18 | 20 |
19 // For explanations of each struct and its members, see H.264 specification | 21 // For explanations of each struct and its members, see H.264 specification |
20 // at http://www.itu.int/rec/T-REC-H.264. | 22 // at http://www.itu.int/rec/T-REC-H.264. |
21 struct CONTENT_EXPORT H264NALU { | 23 struct CONTENT_EXPORT H264NALU { |
22 H264NALU(); | 24 H264NALU(); |
23 | 25 |
24 enum Type { | 26 enum Type { |
25 kUnspecified = 0, | 27 kUnspecified = 0, |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 // Parse a slice header, returning it in |*shdr|. |*nalu| must be set to | 297 // Parse a slice header, returning it in |*shdr|. |*nalu| must be set to |
296 // the NALU returned from AdvanceToNextNALU() and corresponding to |*shdr|. | 298 // the NALU returned from AdvanceToNextNALU() and corresponding to |*shdr|. |
297 Result ParseSliceHeader(const H264NALU& nalu, H264SliceHeader* shdr); | 299 Result ParseSliceHeader(const H264NALU& nalu, H264SliceHeader* shdr); |
298 | 300 |
299 // Parse a SEI message, returning it in |*sei_msg|, provided and managed | 301 // Parse a SEI message, returning it in |*sei_msg|, provided and managed |
300 // by the caller. | 302 // by the caller. |
301 Result ParseSEI(H264SEIMessage* sei_msg); | 303 Result ParseSEI(H264SEIMessage* sei_msg); |
302 | 304 |
303 private: | 305 private: |
304 // A class to provide bit-granularity reading of H.264 streams. | 306 // A class to provide bit-granularity reading of H.264 streams. |
305 // This is not a generic bit reader class, as it takes into account | 307 // This class takes into account H.264 stream-specific constraints, such as |
306 // H.264 stream-specific constraints, such as skipping emulation-prevention | 308 // skipping emulation-prevention bytes and stop bits. See spec for more |
307 // bytes and stop bits. See spec for more details. | 309 // details. |
308 // TODO(posciak): need separate unittests for this class. | 310 // TODO(posciak): need separate unittests for this class. |
309 class H264BitReader { | 311 class H264BitReader : public media::BitReader { |
310 public: | 312 public: |
311 H264BitReader(); | 313 H264BitReader(); |
312 ~H264BitReader(); | 314 virtual ~H264BitReader() OVERRIDE; |
313 | |
314 // Initialize the reader to start reading at |data|, |size| being size | |
315 // of |data| in bytes. | |
316 // Return false on insufficient size of stream.. | |
317 // TODO(posciak,fischman): consider replacing Initialize() with | |
318 // heap-allocating and creating bit readers on demand instead. | |
319 bool Initialize(const uint8* data, off_t size); | |
320 | |
321 // Read |num_bits| next bits from stream and return in |*out|, first bit | |
322 // from the stream starting at |num_bits| position in |*out|. | |
323 // |num_bits| may be 1-32, inclusive. | |
324 // Return false if the given number of bits cannot be read (not enough | |
325 // bits in the stream), true otherwise. | |
326 bool ReadBits(int num_bits, int *out); | |
327 | |
328 // Return the number of bits left in the stream. | |
329 off_t NumBitsLeft(); | |
330 | |
331 // See the definition of more_rbsp_data() in spec. | |
332 bool HasMoreRBSPData(); | |
333 | 315 |
334 private: | 316 private: |
335 // Advance to the next byte, loading it into curr_byte_. | 317 // This function handles the H.264 escape sequence and stop bit. |
336 // Return false on end of stream. | 318 virtual void UpdateCurrByte() OVERRIDE; |
337 bool UpdateCurrByte(); | |
338 | |
339 // Pointer to the next unread (not in curr_byte_) byte in the stream. | |
340 const uint8* data_; | |
341 | |
342 // Bytes left in the stream (without the curr_byte_). | |
343 off_t bytes_left_; | |
344 | |
345 // Contents of the current byte; first unread bit starting at position | |
346 // 8 - num_remaining_bits_in_curr_byte_ from MSB. | |
347 int curr_byte_; | |
348 | |
349 // Number of bits remaining in curr_byte_ | |
350 int num_remaining_bits_in_curr_byte_; | |
351 | |
352 // Used in emulation prevention three byte detection (see spec). | |
353 // Initially set to 0xffff to accept all initial two-byte sequences. | |
354 int prev_two_bytes_; | |
355 | |
356 DISALLOW_COPY_AND_ASSIGN(H264BitReader); | |
acolwell GONE FROM CHROMIUM
2012/06/28 17:31:25
nit: You should keep the DISALLOW_COPY_AND_ASSIGN(
| |
357 }; | 319 }; |
358 | 320 |
359 // Exp-Golomb code parsing as specified in chapter 9.1 of the spec. | 321 // Exp-Golomb code parsing as specified in chapter 9.1 of the spec. |
360 // Read one unsigned exp-Golomb code from the stream and return in |*val|. | 322 // Read one unsigned exp-Golomb code from the stream and return in |*val|. |
361 Result ReadUE(int* val); | 323 Result ReadUE(int* val); |
362 | 324 |
363 // Read one signed exp-Golomb code from the stream and return in |*val|. | 325 // Read one signed exp-Golomb code from the stream and return in |*val|. |
364 Result ReadSE(int* val); | 326 Result ReadSE(int* val); |
365 | 327 |
366 // Parse scaling lists (see spec). | 328 // Parse scaling lists (see spec). |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
399 typedef std::map<int, H264PPS*> PPSById; | 361 typedef std::map<int, H264PPS*> PPSById; |
400 SPSById active_SPSes_; | 362 SPSById active_SPSes_; |
401 PPSById active_PPSes_; | 363 PPSById active_PPSes_; |
402 | 364 |
403 DISALLOW_COPY_AND_ASSIGN(H264Parser); | 365 DISALLOW_COPY_AND_ASSIGN(H264Parser); |
404 }; | 366 }; |
405 | 367 |
406 } // namespace content | 368 } // namespace content |
407 | 369 |
408 #endif // CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ | 370 #endif // CONTENT_COMMON_GPU_MEDIA_H264_PARSER_H_ |
OLD | NEW |