OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 // read the value. | 180 // read the value. |
181 size_t value_bit_count = zero_bit_count + 1; | 181 size_t value_bit_count = zero_bit_count + 1; |
182 if (value_bit_count > 32 || !ReadBits(val, value_bit_count)) { | 182 if (value_bit_count > 32 || !ReadBits(val, value_bit_count)) { |
183 CHECK(Seek(original_byte_offset, original_bit_offset)); | 183 CHECK(Seek(original_byte_offset, original_bit_offset)); |
184 return false; | 184 return false; |
185 } | 185 } |
186 *val -= 1; | 186 *val -= 1; |
187 return true; | 187 return true; |
188 } | 188 } |
189 | 189 |
| 190 bool BitBuffer::ReadSignedExponentialGolomb(int32_t* val) { |
| 191 // Signed exponential golomb values are just the unsigned values |
| 192 // mapped to the sequence 0, 1, -1, 2, -2, etc. in order. |
| 193 uint32_t unsigned_val; |
| 194 if (!ReadExponentialGolomb(&unsigned_val)) { |
| 195 return false; |
| 196 } |
| 197 if ((unsigned_val & 1) == 0) { |
| 198 *val = -static_cast<int32_t>(unsigned_val / 2); |
| 199 } else { |
| 200 *val = (unsigned_val + 1) / 2; |
| 201 } |
| 202 return true; |
| 203 } |
| 204 |
190 void BitBuffer::GetCurrentOffset( | 205 void BitBuffer::GetCurrentOffset( |
191 size_t* out_byte_offset, size_t* out_bit_offset) { | 206 size_t* out_byte_offset, size_t* out_bit_offset) { |
192 CHECK(out_byte_offset != NULL); | 207 CHECK(out_byte_offset != NULL); |
193 CHECK(out_bit_offset != NULL); | 208 CHECK(out_bit_offset != NULL); |
194 *out_byte_offset = byte_offset_; | 209 *out_byte_offset = byte_offset_; |
195 *out_bit_offset = bit_offset_; | 210 *out_bit_offset = bit_offset_; |
196 } | 211 } |
197 | 212 |
198 bool BitBuffer::Seek(size_t byte_offset, size_t bit_offset) { | 213 bool BitBuffer::Seek(size_t byte_offset, size_t bit_offset) { |
199 if (byte_offset > byte_count_ || bit_offset > 7 || | 214 if (byte_offset > byte_count_ || bit_offset > 7 || |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 289 } |
275 uint64_t val_to_encode = static_cast<uint64_t>(val) + 1; | 290 uint64_t val_to_encode = static_cast<uint64_t>(val) + 1; |
276 | 291 |
277 // We need to write CountBits(val+1) 0s and then val+1. Since val (as a | 292 // We need to write CountBits(val+1) 0s and then val+1. Since val (as a |
278 // uint64_t) has leading zeros, we can just write the total golomb encoded | 293 // uint64_t) has leading zeros, we can just write the total golomb encoded |
279 // size worth of bits, knowing the value will appear last. | 294 // size worth of bits, knowing the value will appear last. |
280 return WriteBits(val_to_encode, CountBits(val_to_encode) * 2 - 1); | 295 return WriteBits(val_to_encode, CountBits(val_to_encode) * 2 - 1); |
281 } | 296 } |
282 | 297 |
283 } // namespace rtc | 298 } // namespace rtc |
OLD | NEW |