Index: media/base/bit_reader_base.h |
diff --git a/media/base/bit_reader.h b/media/base/bit_reader_base.h |
similarity index 54% |
copy from media/base/bit_reader.h |
copy to media/base/bit_reader_base.h |
index 8c15891c91576a6ce5e250088c71aae06e353a8d..3cd888d324cb9140f0d6ab55e498c915ec943e5a 100644 |
--- a/media/base/bit_reader.h |
+++ b/media/base/bit_reader_base.h |
@@ -1,11 +1,9 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#ifndef MEDIA_BASE_BIT_READER_H_ |
-#define MEDIA_BASE_BIT_READER_H_ |
- |
-#include <sys/types.h> |
+#ifndef MEDIA_BASE_BIT_READER_BASE_H_ |
+#define MEDIA_BASE_BIT_READER_BASE_H_ |
#include "base/basictypes.h" |
#include "base/logging.h" |
@@ -13,13 +11,12 @@ |
namespace media { |
-// A class to read bit streams. |
-class MEDIA_EXPORT BitReader { |
+class MEDIA_EXPORT BitReaderBase { |
public: |
- // Initialize the reader to start reading at |data|, |size| being size |
- // of |data| in bytes. |
- BitReader(const uint8* data, off_t size); |
- ~BitReader(); |
+ BitReaderBase(); |
+ virtual ~BitReaderBase(); |
+ |
+ virtual int GetBytes(int min_nbytes, int max_nbytes, const uint8** out) = 0; |
// Read |num_bits| next bits from stream and return in |*out|, first bit |
// from the stream starting at |num_bits| position in |*out|. |
@@ -29,6 +26,9 @@ class MEDIA_EXPORT BitReader { |
// 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. |
+ // T can especially not be a boolean since it generates |
+ // some optimization warnings during compilation on windows platforms, |
+ // use ReadFlag instead. |
template<typename T> bool ReadBits(int num_bits, T *out) { |
DCHECK_LE(num_bits, static_cast<int>(sizeof(T) * 8)); |
uint64 temp; |
@@ -37,41 +37,48 @@ class MEDIA_EXPORT BitReader { |
return ret; |
} |
+ // Read a boolean. |
+ bool ReadFlag(bool* flag); |
+ |
+ // Read an unsigned exp-golomb value. |
+ bool ReadUE(uint32* 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); |
- // Returns the number of bits available for reading. |
- int bits_available() const; |
+ protected: |
+ // Returns the number of bits available in the registers. |
+ int bits_available_in_registers() const; |
private: |
+ typedef uint64 RegType; |
+ |
// Help function used by ReadBits to avoid inlining the bit reading logic. |
bool ReadBitsInternal(int num_bits, uint64* out); |
- // 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(); |
+ // Refill bit registers to have at least |min_nbits| bits available. |
+ // Return true if the mininimum bit count condition is met after the refill. |
+ bool Refill(int min_nbits); |
- // Pointer to the next unread (not in curr_byte_) byte in the stream. |
- const uint8* data_; |
+ // Refill the current bit register from the next bit register. |
+ void RefillCurrentRegister(); |
- // Bytes left in the stream (without the curr_byte_). |
- off_t bytes_left_; |
+ void ResetRegisters(); |
- // Contents of the current byte; first unread bit starting at position |
- // 8 - num_remaining_bits_in_curr_byte_ from MSB. |
- uint8 curr_byte_; |
+ // Number of valid bits left in |reg|. |
+ int nbits_; |
+ RegType reg_; |
- // Number of bits remaining in curr_byte_ |
- int num_remaining_bits_in_curr_byte_; |
+ // Number of valid bits left in |reg_next_|. |
+ int nbits_next_; |
+ RegType reg_next_; |
- private: |
- DISALLOW_COPY_AND_ASSIGN(BitReader); |
+ DISALLOW_COPY_AND_ASSIGN(BitReaderBase); |
}; |
} // namespace media |
-#endif // MEDIA_BASE_BIT_READER_H_ |
+#endif // MEDIA_BASE_BIT_READER_BASE_H_ |