OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_core.h" | 5 #include "media/base/bit_reader_core.h" |
6 | 6 |
7 #include <base/port.h> | 7 #include <base/port.h> |
8 #include <base/sys_byteorder.h> | 8 #include <base/sys_byteorder.h> |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 | 44 |
45 int BitReaderCore::PeekBitsMsbAligned(int num_bits, uint64* out) { | 45 int BitReaderCore::PeekBitsMsbAligned(int num_bits, uint64* out) { |
46 // Try to have at least |num_bits| in the bit register. | 46 // Try to have at least |num_bits| in the bit register. |
47 if (nbits_ < num_bits) | 47 if (nbits_ < num_bits) |
48 Refill(num_bits); | 48 Refill(num_bits); |
49 | 49 |
50 *out = reg_; | 50 *out = reg_; |
51 return nbits_; | 51 return nbits_; |
52 } | 52 } |
53 | 53 |
54 bool BitReaderCore::SkipBits(int num_bits) { | 54 bool BitReaderCore::SkipBitsSmall(int num_bits) { |
55 // TODO(dalecurtis): Rewrite to be efficient, see http://crbug.com/376450 | |
56 DCHECK_GE(num_bits, 0); | 55 DCHECK_GE(num_bits, 0); |
57 DVLOG_IF(1, num_bits > 100) | |
58 << "BitReader::SkipBits inefficient for large skips"; | |
59 | |
60 uint64 dummy; | 56 uint64 dummy; |
61 while (num_bits >= kRegWidthInBits) { | 57 while (num_bits >= kRegWidthInBits) { |
62 if (!ReadBitsInternal(kRegWidthInBits, &dummy)) | 58 if (!ReadBitsInternal(kRegWidthInBits, &dummy)) |
63 return false; | 59 return false; |
64 num_bits -= kRegWidthInBits; | 60 num_bits -= kRegWidthInBits; |
65 } | 61 } |
66 return ReadBitsInternal(num_bits, &dummy); | 62 return ReadBitsInternal(num_bits, &dummy); |
67 } | 63 } |
68 | 64 |
65 bool BitReaderCore::SkipBits(int num_bits) { | |
66 DCHECK_GE(num_bits, 0); | |
67 | |
68 const int remaining_bits = nbits_ + nbits_next_; | |
69 if (remaining_bits >= num_bits) | |
70 return SkipBitsSmall(num_bits); | |
71 | |
72 // Skip first the remaining available bits. | |
73 num_bits -= remaining_bits; | |
74 bits_read_ += remaining_bits; | |
75 nbits_ = 0; | |
76 reg_ = 0; | |
77 nbits_next_ = 0; | |
78 reg_next_ = 0; | |
79 | |
80 // Next, skip an integer number of bytes. | |
81 const int nbytes = num_bits / 8; | |
82 if (nbytes > 0) { | |
83 const uint8* byte_stream_window; | |
84 int window_size = | |
DaleCurtis
2014/09/24 18:35:43
const since you're doing so above.
damienv1
2014/09/25 00:50:06
Done.
| |
85 byte_stream_provider_->GetBytes(nbytes, &byte_stream_window); | |
86 DCHECK_GE(window_size, 0); | |
87 DCHECK_LE(window_size, nbytes); | |
88 if (window_size < nbytes) | |
89 return false; | |
90 num_bits -= 8 * nbytes; | |
91 bits_read_ += 8 * nbytes; | |
92 } | |
93 | |
94 // Skip the remaining bits. | |
95 return SkipBitsSmall(num_bits); | |
96 } | |
97 | |
69 int BitReaderCore::bits_read() const { | 98 int BitReaderCore::bits_read() const { |
70 return bits_read_; | 99 return bits_read_; |
71 } | 100 } |
72 | 101 |
73 bool BitReaderCore::ReadBitsInternal(int num_bits, uint64* out) { | 102 bool BitReaderCore::ReadBitsInternal(int num_bits, uint64* out) { |
74 DCHECK_GE(num_bits, 0); | 103 DCHECK_GE(num_bits, 0); |
75 | 104 |
76 if (num_bits == 0) { | 105 if (num_bits == 0) { |
77 *out = 0; | 106 *out = 0; |
78 return true; | 107 return true; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 nbits_next_ = 0; | 180 nbits_next_ = 0; |
152 return; | 181 return; |
153 } | 182 } |
154 | 183 |
155 nbits_ += free_nbits; | 184 nbits_ += free_nbits; |
156 reg_next_ <<= free_nbits; | 185 reg_next_ <<= free_nbits; |
157 nbits_next_ -= free_nbits; | 186 nbits_next_ -= free_nbits; |
158 } | 187 } |
159 | 188 |
160 } // namespace media | 189 } // namespace media |
OLD | NEW |