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 namespace media { | 7 namespace media { |
8 | 8 |
9 BitReader::BitReader(const uint8* data, off_t size) | 9 BitReader::BitReader(const uint8* data, off_t size) |
10 : data_(data), bytes_left_(size), num_remaining_bits_in_curr_byte_(0) { | 10 : data_(data), bytes_left_(size), num_remaining_bits_in_curr_byte_(0) { |
11 DCHECK(data_ != NULL && bytes_left_ > 0); | 11 DCHECK(data_ != NULL && bytes_left_ > 0); |
12 | 12 |
13 UpdateCurrByte(); | 13 UpdateCurrByte(); |
14 } | 14 } |
15 | 15 |
16 BitReader::~BitReader() {} | 16 BitReader::~BitReader() {} |
17 | 17 |
18 bool BitReader::SkipBits(int num_bits) { | |
xhwang
2013/05/20 23:24:24
This seems mostly duplicate of ReadBitsInternal. H
jrummell
2013/05/22 18:27:39
Implemented Aaron's suggestion instead.
| |
19 while (num_remaining_bits_in_curr_byte_ != 0 && num_bits != 0) { | |
acolwell GONE FROM CHROMIUM
2013/05/18 01:22:09
You might want to take a stab at implementing this
jrummell
2013/05/22 18:27:39
Done.
| |
20 int bits_to_take = std::min(num_remaining_bits_in_curr_byte_, num_bits); | |
21 num_bits -= bits_to_take; | |
22 num_remaining_bits_in_curr_byte_ -= bits_to_take; | |
23 curr_byte_ &= (1 << num_remaining_bits_in_curr_byte_) - 1; | |
24 | |
25 if (num_remaining_bits_in_curr_byte_ == 0) | |
26 UpdateCurrByte(); | |
27 } | |
28 | |
29 return num_bits == 0; | |
30 } | |
31 | |
18 int BitReader::bits_available() const { | 32 int BitReader::bits_available() const { |
19 return 8 * bytes_left_ + num_remaining_bits_in_curr_byte_; | 33 return 8 * bytes_left_ + num_remaining_bits_in_curr_byte_; |
20 } | 34 } |
21 | 35 |
22 bool BitReader::ReadBitsInternal(int num_bits, uint64* out) { | 36 bool BitReader::ReadBitsInternal(int num_bits, uint64* out) { |
23 DCHECK_LE(num_bits, 64); | 37 DCHECK_LE(num_bits, 64); |
24 | 38 |
25 *out = 0; | 39 *out = 0; |
26 | 40 |
27 while (num_remaining_bits_in_curr_byte_ != 0 && num_bits != 0) { | 41 while (num_remaining_bits_in_curr_byte_ != 0 && num_bits != 0) { |
(...skipping 19 matching lines...) Expand all Loading... | |
47 return; | 61 return; |
48 | 62 |
49 // Load a new byte and advance pointers. | 63 // Load a new byte and advance pointers. |
50 curr_byte_ = *data_; | 64 curr_byte_ = *data_; |
51 ++data_; | 65 ++data_; |
52 --bytes_left_; | 66 --bytes_left_; |
53 num_remaining_bits_in_curr_byte_ = 8; | 67 num_remaining_bits_in_curr_byte_ = 8; |
54 } | 68 } |
55 | 69 |
56 } // namespace media | 70 } // namespace media |
OLD | NEW |