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() | |
10 : data_(NULL), | |
11 bytes_left_(0), | |
12 position_(0), | |
13 curr_byte_(0), | |
14 num_remaining_bits_in_curr_byte_(0) { | |
15 } | |
16 | |
17 BitReader::BitReader(const void* data, off_t size) { | |
18 Initialize(data, size); | |
19 } | |
20 | |
21 BitReader::~BitReader() {} | |
22 | |
23 void BitReader::Initialize(const void* data, off_t size) { | |
acolwell GONE FROM CHROMIUM
2012/06/28 17:31:25
nit: Use uint8* here and above so you don't need t
| |
24 DCHECK(data != NULL || size == 0); // Data cannot be NULL if size if not 0. | |
25 | |
26 data_ = reinterpret_cast<const uint8*>(data); | |
27 bytes_left_ = size; | |
28 position_ = 0; | |
29 num_remaining_bits_in_curr_byte_ = 0; | |
30 | |
31 UpdateCurrByte(); | |
32 } | |
33 | |
34 void BitReader::UpdateCurrByte() { | |
35 DCHECK_EQ(num_remaining_bits_in_curr_byte_, 0); | |
36 | |
37 if (bytes_left_ >= 1) { | |
38 // Load a new byte and advance pointers. | |
39 curr_byte_ = *data_; | |
40 ++data_; | |
41 --bytes_left_; | |
42 num_remaining_bits_in_curr_byte_ = 8; | |
43 } | |
44 } | |
45 | |
46 bool BitReader::SkipBits(int num_bits) { | |
47 BitReader save = *this; | |
48 uint64 dummy; | |
acolwell GONE FROM CHROMIUM
2012/06/28 17:31:25
How about just using int here and adding a dummySi
| |
49 bool result = true; | |
50 | |
51 while (num_bits > 64) { | |
52 if (ReadBits(64, &dummy)) { | |
53 num_bits -= 64; | |
54 } else { | |
55 result = false; | |
56 break; | |
57 } | |
58 } | |
59 | |
60 result = result && ReadBits(num_bits, &dummy); | |
61 | |
62 if (!result) | |
63 *this = save; | |
64 | |
65 return result; | |
66 } | |
67 | |
68 off_t BitReader::Tell() const { | |
69 return position_; | |
70 } | |
71 | |
72 off_t BitReader::NumBitsLeft() const { | |
73 return (num_remaining_bits_in_curr_byte_ + bytes_left_ * 8); | |
74 } | |
75 | |
76 bool BitReader::HasMoreData() const { | |
77 return num_remaining_bits_in_curr_byte_ != 0; | |
78 } | |
79 | |
80 } // namespace media | |
OLD | NEW |