Index: webrtc/base/bitbuffer.cc |
diff --git a/webrtc/base/bitbuffer.cc b/webrtc/base/bitbuffer.cc |
index 1aa245e78c7932309c8f8aa313a0177847cdd8c8..48a1d0ccdbcc8b3ed04099f095f029f8c3065b08 100644 |
--- a/webrtc/base/bitbuffer.cc |
+++ b/webrtc/base/bitbuffer.cc |
@@ -293,4 +293,18 @@ bool BitBufferWriter::WriteExponentialGolomb(uint32_t val) { |
return WriteBits(val_to_encode, CountBits(val_to_encode) * 2 - 1); |
} |
+bool BitBufferWriter::WriteSignedExponentialGolomb(int32_t val) { |
+ if (val == 0) { |
+ return WriteExponentialGolomb(0); |
+ } else if (val > 0) { |
+ uint32_t signed_val = val; |
+ return WriteExponentialGolomb((signed_val * 2) - 1); |
+ } else { |
+ if (val == std::numeric_limits<int32_t>::min()) |
+ return false; // Not supported, would cause overflow. |
+ uint32_t signed_val = -val; |
+ return WriteExponentialGolomb(signed_val * 2); |
+ } |
+} |
+ |
} // namespace rtc |