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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 return false; | 286 return false; |
287 } | 287 } |
288 uint64_t val_to_encode = static_cast<uint64_t>(val) + 1; | 288 uint64_t val_to_encode = static_cast<uint64_t>(val) + 1; |
289 | 289 |
290 // 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 |
291 // 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 |
292 // size worth of bits, knowing the value will appear last. | 292 // size worth of bits, knowing the value will appear last. |
293 return WriteBits(val_to_encode, CountBits(val_to_encode) * 2 - 1); | 293 return WriteBits(val_to_encode, CountBits(val_to_encode) * 2 - 1); |
294 } | 294 } |
295 | 295 |
| 296 bool BitBufferWriter::WriteSignedExponentialGolomb(int32_t val) { |
| 297 if (val == 0) { |
| 298 return WriteExponentialGolomb(0); |
| 299 } else if (val > 0) { |
| 300 uint32_t signed_val = val; |
| 301 return WriteExponentialGolomb((signed_val * 2) - 1); |
| 302 } else { |
| 303 if (val == std::numeric_limits<int32_t>::min()) |
| 304 return false; // Not supported, would cause overflow. |
| 305 uint32_t signed_val = -val; |
| 306 return WriteExponentialGolomb(signed_val * 2); |
| 307 } |
| 308 } |
| 309 |
296 } // namespace rtc | 310 } // namespace rtc |
OLD | NEW |