OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "media/base/bit_reader.h" | |
6 | |
7 namespace media { | |
8 | |
9 BitReader::BitReader(const uint8* data, off_t size) | |
10 : data_(data), bytes_left_(size), num_remaining_bits_in_curr_byte_(0) { | |
11 DCHECK(data_ != NULL && bytes_left_ > 0); | |
12 | |
13 UpdateCurrByte(); | |
14 } | |
15 | |
16 BitReader::~BitReader() {} | |
17 | |
18 bool BitReader::ReadBitsInternal(int num_bits, uint64* out) { | |
19 DCHECK_LE(num_bits, 64); | |
20 | |
21 *out = 0; | |
22 | |
23 while (num_remaining_bits_in_curr_byte_ != 0 && num_bits != 0) { | |
24 int bits_to_take = std::min(num_remaining_bits_in_curr_byte_, num_bits); | |
25 | |
26 if (*out != 0) | |
Ami GONE FROM CHROMIUM
2012/07/19 00:28:59
This conditional is unnecessary.
xiaomings
2012/07/19 01:11:02
Done.
| |
27 *out <<= bits_to_take; | |
28 *out += curr_byte_ >> (num_remaining_bits_in_curr_byte_ - bits_to_take); | |
29 num_bits -= bits_to_take; | |
30 num_remaining_bits_in_curr_byte_ -= bits_to_take; | |
31 curr_byte_ &= (1 << num_remaining_bits_in_curr_byte_) - 1; | |
32 | |
33 if (num_remaining_bits_in_curr_byte_ == 0) | |
34 UpdateCurrByte(); | |
35 } | |
36 | |
37 if (num_bits == 0) | |
38 return true; | |
39 | |
40 *out = 0; | |
Ami GONE FROM CHROMIUM
2012/07/19 00:28:59
I'm not sure why you want this. It smells like ho
xiaomings
2012/07/19 01:11:02
Done.
| |
41 | |
Ami GONE FROM CHROMIUM
2012/07/19 00:28:59
extra newline
xiaomings
2012/07/19 01:11:02
Removed the if.
| |
42 return false; | |
43 } | |
44 | |
45 void BitReader::UpdateCurrByte() { | |
46 DCHECK_EQ(num_remaining_bits_in_curr_byte_, 0); | |
47 | |
48 if (bytes_left_ == 0) | |
49 return; | |
50 | |
51 // Load a new byte and advance pointers. | |
52 curr_byte_ = *data_; | |
53 ++data_; | |
54 --bytes_left_; | |
55 num_remaining_bits_in_curr_byte_ = 8; | |
56 } | |
57 | |
58 } // namespace media | |
OLD | NEW |