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
3 // found in the LICENSE file.
5 // This file contains an implementation of an H264 Annex-B video stream parser.
7 #ifndef CONTENT_COMMON_GPU_MEDIA_H264_BIT_READER_H_
8 #define CONTENT_COMMON_GPU_MEDIA_H264_BIT_READER_H_
10 #include <sys/types.h>
12 #include "base/basictypes.h"
13 #include "content/common/content_export.h"
17 // A class to provide bit-granularity reading of H.264 streams.
18 // This is not a generic bit reader class, as it takes into account
19 // H.264 stream-specific constraints, such as skipping emulation-prevention
20 // bytes and stop bits. See spec for more details.
21 class CONTENT_EXPORT H264BitReader
{
26 // Initialize the reader to start reading at |data|, |size| being size
27 // of |data| in bytes.
28 // Return false on insufficient size of stream..
29 // TODO(posciak,fischman): consider replacing Initialize() with
30 // heap-allocating and creating bit readers on demand instead.
31 bool Initialize(const uint8
* data
, off_t size
);
33 // Read |num_bits| next bits from stream and return in |*out|, first bit
34 // from the stream starting at |num_bits| position in |*out|.
35 // |num_bits| may be 1-32, inclusive.
36 // Return false if the given number of bits cannot be read (not enough
37 // bits in the stream), true otherwise.
38 bool ReadBits(int num_bits
, int *out
);
40 // Return the number of bits left in the stream.
43 // See the definition of more_rbsp_data() in spec.
44 bool HasMoreRBSPData();
47 // Advance to the next byte, loading it into curr_byte_.
48 // Return false on end of stream.
49 bool UpdateCurrByte();
51 // Pointer to the next unread (not in curr_byte_) byte in the stream.
54 // Bytes left in the stream (without the curr_byte_).
57 // Contents of the current byte; first unread bit starting at position
58 // 8 - num_remaining_bits_in_curr_byte_ from MSB.
61 // Number of bits remaining in curr_byte_
62 int num_remaining_bits_in_curr_byte_
;
64 // Used in emulation prevention three byte detection (see spec).
65 // Initially set to 0xffff to accept all initial two-byte sequences.
68 DISALLOW_COPY_AND_ASSIGN(H264BitReader
);
71 } // namespace content
73 #endif // CONTENT_COMMON_GPU_MEDIA_H264_BIT_READER_H_