Chromium Code Reviews| Index: media/base/bit_reader.cc |
| diff --git a/media/base/bit_reader.cc b/media/base/bit_reader.cc |
| index ed3dc6050f1f11383db82d6784c37ff82e9d124b..55b9b7e412c01991b9e273d11500703f174318e5 100644 |
| --- a/media/base/bit_reader.cc |
| +++ b/media/base/bit_reader.cc |
| @@ -15,6 +15,29 @@ BitReader::BitReader(const uint8* data, off_t size) |
| BitReader::~BitReader() {} |
| +bool BitReader::SkipBits(int num_bits) { |
| + DCHECK_GE(num_bits, 0); |
| + |
| + // Skip any bits in the current byte waiting to be processed, then |
| + // process full bytes until less than 8 bits remaining. |
| + while (num_bits > 0 && num_bits > num_remaining_bits_in_curr_byte_) { |
| + num_bits -= num_remaining_bits_in_curr_byte_; |
| + num_remaining_bits_in_curr_byte_ = 0; |
| + UpdateCurrByte(); |
|
xhwang
2013/05/22 22:18:32
nit: can we skip multiple bytes in one operation i
jrummell
2013/05/22 23:59:46
I added a DLOG message to print a warning if large
|
| + |
| + // If there is no more data remaining, only return true if we |
| + // skipped all that were requested. |
| + if (num_remaining_bits_in_curr_byte_ == 0) |
| + return (num_bits == 0); |
| + } |
| + |
| + // Less than 8 bits remaining to skip. Use ReadBitsInternal to verify |
| + // that the remaining bits we need exist, and adjust them as necessary |
| + // for subsequent operations. |
| + uint64 not_needed; |
| + return ReadBitsInternal(num_bits, ¬_needed); |
| +} |
| + |
| int BitReader::bits_available() const { |
| return 8 * bytes_left_ + num_remaining_bits_in_curr_byte_; |
| } |