Chromium Code Reviews| Index: media/base/bit_reader.h |
| diff --git a/media/base/bit_reader.h b/media/base/bit_reader.h |
| index 8c15891c91576a6ce5e250088c71aae06e353a8d..c69012174e20a52cd0538b1575c4fad91cc0aafd 100644 |
| --- a/media/base/bit_reader.h |
| +++ b/media/base/bit_reader.h |
| @@ -5,70 +5,54 @@ |
| #ifndef MEDIA_BASE_BIT_READER_H_ |
| #define MEDIA_BASE_BIT_READER_H_ |
| -#include <sys/types.h> |
| - |
| #include "base/basictypes.h" |
| -#include "base/logging.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "media/base/bit_reader_core.h" |
| #include "media/base/media_export.h" |
| namespace media { |
| -// A class to read bit streams. |
| -class MEDIA_EXPORT BitReader { |
| +class MEDIA_EXPORT BitReader |
| + : private BitReaderCore::ByteStreamProvider { |
|
damienv1
2013/12/28 06:27:40
Should be NON_EXPORTED_BASE(private BitReaderCore:
|
| public: |
| // Initialize the reader to start reading at |data|, |size| being size |
| // of |data| in bytes. |
| - BitReader(const uint8* data, off_t size); |
| - ~BitReader(); |
| - |
| - // Read |num_bits| next bits from stream and return in |*out|, first bit |
| - // from the stream starting at |num_bits| position in |*out|. |
| - // |num_bits| cannot be larger than the bits the type can hold. |
| - // Return false if the given number of bits cannot be read (not enough |
| - // bits in the stream), true otherwise. When return false, the stream will |
| - // enter a state where further ReadBits/SkipBits operations will always |
| - // return false unless |num_bits| is 0. The type |T| has to be a primitive |
| - // integer type. |
| - template<typename T> bool ReadBits(int num_bits, T *out) { |
| - DCHECK_LE(num_bits, static_cast<int>(sizeof(T) * 8)); |
| - uint64 temp; |
| - bool ret = ReadBitsInternal(num_bits, &temp); |
| - *out = static_cast<T>(temp); |
| - return ret; |
| + BitReader(const uint8* data, int size); |
| + virtual ~BitReader(); |
| + |
| + template<typename T> bool ReadBits(int num_bits, T* out) { |
| + return bit_reader_core_.ReadBits(num_bits, out); |
| } |
| - // Skip |num_bits| next bits from stream. Return false if the given number of |
| - // bits cannot be skipped (not enough bits in the stream), true otherwise. |
| - // When return false, the stream will enter a state where further ReadBits/ |
| - // SkipBits operations will always return false unless |num_bits| is 0. |
| - bool SkipBits(int num_bits); |
| + bool ReadFlag(bool* flag) { |
| + return bit_reader_core_.ReadFlag(flag); |
| + } |
| - // Returns the number of bits available for reading. |
| - int bits_available() const; |
| + bool SkipBits(int num_bits) { |
| + return bit_reader_core_.SkipBits(num_bits); |
| + } |
| - private: |
| - // Help function used by ReadBits to avoid inlining the bit reading logic. |
| - bool ReadBitsInternal(int num_bits, uint64* out); |
| + int bits_available() const { |
| + return bit_reader_core_.bits_available(); |
| + } |
| - // Advance to the next byte, loading it into curr_byte_. |
| - // If the num_remaining_bits_in_curr_byte_ is 0 after this function returns, |
| - // the stream has reached the end. |
| - void UpdateCurrByte(); |
| + int GetBitCount() { |
| + return bit_reader_core_.GetBitCount(); |
| + } |
| - // Pointer to the next unread (not in curr_byte_) byte in the stream. |
| - const uint8* data_; |
| + private: |
| + // BitReaderCore::ByteStreamProvider implementation. |
| + virtual int GetBytes(int max_n, const uint8** out) OVERRIDE; |
| + virtual int GetBytesLeft() const OVERRIDE; |
| - // Bytes left in the stream (without the curr_byte_). |
| - off_t bytes_left_; |
| + // Pointer to the next unread byte in the stream. |
| + const uint8* data_; |
| - // Contents of the current byte; first unread bit starting at position |
| - // 8 - num_remaining_bits_in_curr_byte_ from MSB. |
| - uint8 curr_byte_; |
| + // Bytes left in the stream. |
| + int bytes_left_; |
| - // Number of bits remaining in curr_byte_ |
| - int num_remaining_bits_in_curr_byte_; |
| + BitReaderCore bit_reader_core_; |
| - private: |
| DISALLOW_COPY_AND_ASSIGN(BitReader); |
| }; |