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

Unified Diff: media/base/bit_reader.h

Issue 112343011: Split the bit reader functionalities from the byte stream provider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unit test for the removal of the emulation prevention byte. Created 7 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/base/bit_reader.cc » ('j') | media/base/bit_reader.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/bit_reader.h
diff --git a/media/base/bit_reader.h b/media/base/bit_reader.h
index 8c15891c91576a6ce5e250088c71aae06e353a8d..fa55cabc2e3740171a03075b9e0f195a3f60cf68 100644
--- a/media/base/bit_reader.h
+++ b/media/base/bit_reader.h
@@ -8,12 +8,12 @@
#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 {
public:
// Initialize the reader to start reading at |data|, |size| being size
@@ -21,54 +21,32 @@ class MEDIA_EXPORT BitReader {
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;
+ 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);
-
- // Returns the number of bits available for reading.
- int bits_available() const;
-
- private:
- // Help function used by ReadBits to avoid inlining the bit reading logic.
- bool ReadBitsInternal(int num_bits, uint64* out);
+ bool ReadFlag(bool* flag) {
acolwell GONE FROM CHROMIUM 2013/12/28 01:54:42 Why is this being added? It doesn't appear to be u
damienv1 2013/12/28 02:26:17 If we don't expose ReadFlag, all the parsers will
acolwell GONE FROM CHROMIUM 2014/01/06 22:44:06 I understand. I'd prefer you add it in a follow-up
+ return bit_reader_core_.ReadFlag(flag);
+ }
- // 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();
+ bool SkipBits(int num_bits) {
+ return bit_reader_core_.SkipBits(num_bits);
+ }
- // Pointer to the next unread (not in curr_byte_) byte in the stream.
- const uint8* data_;
+ // Returns the number of bits available for reading.
+ int bits_available() const {
+ return bit_reader_core_.bits_available();
+ }
- // Bytes left in the stream (without the curr_byte_).
- off_t bytes_left_;
+ int GetBitCount() {
acolwell GONE FROM CHROMIUM 2013/12/28 01:54:42 ditto
damienv1 2013/12/28 02:26:17 GetBitCount will remove the need of both: - NumEmu
acolwell GONE FROM CHROMIUM 2014/01/06 22:44:06 Ok, but I'd prefer you defer the addition of the m
+ return bit_reader_core_.GetBitCount();
+ }
- // Contents of the current byte; first unread bit starting at position
- // 8 - num_remaining_bits_in_curr_byte_ from MSB.
- uint8 curr_byte_;
+ private:
+ scoped_ptr<BitReaderCore::ByteStreamProvider> byte_stream_provider_;
- // Number of bits remaining in curr_byte_
- int num_remaining_bits_in_curr_byte_;
+ BitReaderCore bit_reader_core_;
- private:
DISALLOW_COPY_AND_ASSIGN(BitReader);
};
« no previous file with comments | « no previous file | media/base/bit_reader.cc » ('j') | media/base/bit_reader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698