| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/base/bit_reader.h" | 5 #include "media/base/bit_reader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 namespace media { | 9 namespace media { |
| 10 | 10 |
| 11 BitReader::BitReader(const uint8* data, off_t size) | 11 BitReader::BitReader(const uint8* data, off_t size) |
| 12 : data_(data), bytes_left_(size), num_remaining_bits_in_curr_byte_(0) { | 12 : data_(data), bytes_left_(size), num_remaining_bits_in_curr_byte_(0) { |
| 13 DCHECK(data_ != NULL && bytes_left_ > 0); | 13 DCHECK(data_ != NULL && bytes_left_ > 0); |
| 14 | 14 |
| 15 UpdateCurrByte(); | 15 UpdateCurrByte(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 BitReader::~BitReader() {} | 18 BitReader::~BitReader() {} |
| 19 | 19 |
| 20 bool BitReader::SkipBits(int num_bits) { | 20 bool BitReader::SkipBits(int num_bits) { |
| 21 DCHECK_GE(num_bits, 0); | 21 DCHECK_GE(num_bits, 0); |
| 22 DLOG_IF(INFO, num_bits > 100) | 22 DVLOG_IF(0, num_bits > 100) |
| 23 << "BitReader::SkipBits inefficient for large skips"; | 23 << "BitReader::SkipBits inefficient for large skips"; |
| 24 | 24 |
| 25 // Skip any bits in the current byte waiting to be processed, then | 25 // Skip any bits in the current byte waiting to be processed, then |
| 26 // process full bytes until less than 8 bits remaining. | 26 // process full bytes until less than 8 bits remaining. |
| 27 while (num_bits > 0 && num_bits > num_remaining_bits_in_curr_byte_) { | 27 while (num_bits > 0 && num_bits > num_remaining_bits_in_curr_byte_) { |
| 28 num_bits -= num_remaining_bits_in_curr_byte_; | 28 num_bits -= num_remaining_bits_in_curr_byte_; |
| 29 num_remaining_bits_in_curr_byte_ = 0; | 29 num_remaining_bits_in_curr_byte_ = 0; |
| 30 UpdateCurrByte(); | 30 UpdateCurrByte(); |
| 31 | 31 |
| 32 // If there is no more data remaining, only return true if we | 32 // If there is no more data remaining, only return true if we |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 return; | 74 return; |
| 75 | 75 |
| 76 // Load a new byte and advance pointers. | 76 // Load a new byte and advance pointers. |
| 77 curr_byte_ = *data_; | 77 curr_byte_ = *data_; |
| 78 ++data_; | 78 ++data_; |
| 79 --bytes_left_; | 79 --bytes_left_; |
| 80 num_remaining_bits_in_curr_byte_ = 8; | 80 num_remaining_bits_in_curr_byte_ = 8; |
| 81 } | 81 } |
| 82 | 82 |
| 83 } // namespace media | 83 } // namespace media |
| OLD | NEW |