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

Unified Diff: media/base/bit_reader.cc

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: 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
Index: media/base/bit_reader.cc
diff --git a/media/base/bit_reader.cc b/media/base/bit_reader.cc
index e4d83af74107a09a2f745bd363ff1615af6fcd36..310a3e05f577da2fa168eb16ed367f5c8c031f1a 100644
--- a/media/base/bit_reader.cc
+++ b/media/base/bit_reader.cc
@@ -9,14 +9,14 @@
namespace media {
BitReader::BitReader(const uint8* data, off_t size)
- : data_(data), bytes_left_(size), num_remaining_bits_in_curr_byte_(0) {
+ : data_(data),
+ bytes_left_(size) {
DCHECK(data_ != NULL && bytes_left_ > 0);
-
- UpdateCurrByte();
}
BitReader::~BitReader() {}
+#if 0
damienv1 2013/12/19 02:01:25 Forgot to remove the code between #if 0 / #endif.
damienv1 2013/12/19 21:46:34 Done.
bool BitReader::SkipBits(int num_bits) {
DCHECK_GE(num_bits, 0);
DVLOG_IF(0, num_bits > 100)
@@ -41,43 +41,21 @@ bool BitReader::SkipBits(int num_bits) {
uint64 not_needed;
return ReadBitsInternal(num_bits, &not_needed);
}
+#endif
-int BitReader::bits_available() const {
- return 8 * bytes_left_ + num_remaining_bits_in_curr_byte_;
-}
-
-bool BitReader::ReadBitsInternal(int num_bits, uint64* out) {
- DCHECK_LE(num_bits, 64);
-
- *out = 0;
-
- while (num_remaining_bits_in_curr_byte_ != 0 && num_bits != 0) {
- int bits_to_take = std::min(num_remaining_bits_in_curr_byte_, num_bits);
-
- *out <<= bits_to_take;
- *out += curr_byte_ >> (num_remaining_bits_in_curr_byte_ - bits_to_take);
- num_bits -= bits_to_take;
- num_remaining_bits_in_curr_byte_ -= bits_to_take;
- curr_byte_ &= (1 << num_remaining_bits_in_curr_byte_) - 1;
+int BitReader::GetBytes(int min_nbytes, int max_nbytes, const uint8** out) {
+ int nbytes = max_nbytes;
+ if (nbytes > bytes_left_)
+ nbytes = bytes_left_;
- if (num_remaining_bits_in_curr_byte_ == 0)
- UpdateCurrByte();
- }
-
- return num_bits == 0;
+ *out = data_;
+ data_ += nbytes;
+ bytes_left_ -= nbytes;
+ return nbytes;
}
-void BitReader::UpdateCurrByte() {
- DCHECK_EQ(num_remaining_bits_in_curr_byte_, 0);
-
- if (bytes_left_ == 0)
- return;
-
- // Load a new byte and advance pointers.
- curr_byte_ = *data_;
- ++data_;
- --bytes_left_;
- num_remaining_bits_in_curr_byte_ = 8;
+int BitReader::bits_available() const {
+ return 8 * bytes_left_ + bits_available_in_registers();
damienv1 2013/12/19 03:21:08 Should be: bytes_left_ * CHAR_BIT
damienv1 2013/12/19 21:46:34 Done.
}
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698