Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Unified Diff: webrtc/base/timeutils.cc

Issue 1779773002: Make rtc::TimestampWrapAroundHandler handle backwards wrapping (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added unit test for "no negative start" Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/base/timeutils_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/timeutils.cc
diff --git a/webrtc/base/timeutils.cc b/webrtc/base/timeutils.cc
index 24b04ee2ee46342c1551901309042f8f4438955a..b7803aea10bbfef842c88f4f7f371baa770fa257 100644
--- a/webrtc/base/timeutils.cc
+++ b/webrtc/base/timeutils.cc
@@ -193,17 +193,25 @@ int32_t TimeDiff(uint32_t later, uint32_t earlier) {
}
TimestampWrapAroundHandler::TimestampWrapAroundHandler()
- : last_ts_(0), num_wrap_(0) {}
+ : last_ts_(0), num_wrap_(-1) {}
int64_t TimestampWrapAroundHandler::Unwrap(uint32_t ts) {
+ if (num_wrap_ == -1) {
+ last_ts_ = ts;
+ num_wrap_ = 0;
+ return ts;
+ }
+
if (ts < last_ts_) {
- if (last_ts_ > 0xf0000000 && ts < 0x0fffffff) {
+ if (last_ts_ >= 0xf0000000 && ts < 0x0fffffff)
++num_wrap_;
- }
+ } else if ((ts - last_ts_) > 0xf0000000) {
+ // Backwards wrap. Unwrap with last wrap count and don't update last_ts_.
+ return ts + ((num_wrap_ - 1) << 32);
}
+
last_ts_ = ts;
- int64_t unwrapped_ts = ts + (num_wrap_ << 32);
- return unwrapped_ts;
+ return ts + (num_wrap_ << 32);
}
int64_t TmToSeconds(const std::tm& tm) {
« no previous file with comments | « no previous file | webrtc/base/timeutils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698