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 RTC_CHECK(Seek(original_byte_offset, original_bit_offset)); | 183 RTC_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 uint32_t unsigned_val; |
| 192 if (!ReadExponentialGolomb(&unsigned_val)) { |
| 193 return false; |
| 194 } |
| 195 if ((unsigned_val & 1) == 0) { |
| 196 *val = -static_cast<int32_t>(unsigned_val / 2); |
| 197 } else { |
| 198 *val = (unsigned_val + 1) / 2; |
| 199 } |
| 200 return true; |
| 201 } |
| 202 |
190 void BitBuffer::GetCurrentOffset( | 203 void BitBuffer::GetCurrentOffset( |
191 size_t* out_byte_offset, size_t* out_bit_offset) { | 204 size_t* out_byte_offset, size_t* out_bit_offset) { |
192 RTC_CHECK(out_byte_offset != NULL); | 205 RTC_CHECK(out_byte_offset != NULL); |
193 RTC_CHECK(out_bit_offset != NULL); | 206 RTC_CHECK(out_bit_offset != NULL); |
194 *out_byte_offset = byte_offset_; | 207 *out_byte_offset = byte_offset_; |
195 *out_bit_offset = bit_offset_; | 208 *out_bit_offset = bit_offset_; |
196 } | 209 } |
197 | 210 |
198 bool BitBuffer::Seek(size_t byte_offset, size_t bit_offset) { | 211 bool BitBuffer::Seek(size_t byte_offset, size_t bit_offset) { |
199 if (byte_offset > byte_count_ || bit_offset > 7 || | 212 if (byte_offset > byte_count_ || bit_offset > 7 || |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 } | 287 } |
275 uint64_t val_to_encode = static_cast<uint64_t>(val) + 1; | 288 uint64_t val_to_encode = static_cast<uint64_t>(val) + 1; |
276 | 289 |
277 // We need to write CountBits(val+1) 0s and then val+1. Since val (as a | 290 // 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 | 291 // uint64_t) has leading zeros, we can just write the total golomb encoded |
279 // size worth of bits, knowing the value will appear last. | 292 // size worth of bits, knowing the value will appear last. |
280 return WriteBits(val_to_encode, CountBits(val_to_encode) * 2 - 1); | 293 return WriteBits(val_to_encode, CountBits(val_to_encode) * 2 - 1); |
281 } | 294 } |
282 | 295 |
283 } // namespace rtc | 296 } // namespace rtc |
OLD | NEW |