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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/video/video_quality_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 193 }
194 194
195 TimestampWrapAroundHandler::TimestampWrapAroundHandler() 195 TimestampWrapAroundHandler::TimestampWrapAroundHandler()
196 : last_ts_(0), num_wrap_(0) {} 196 : last_ts_(0), num_wrap_(0) {}
197 197
198 int64_t TimestampWrapAroundHandler::Unwrap(uint32_t ts) { 198 int64_t TimestampWrapAroundHandler::Unwrap(uint32_t ts) {
199 if (ts < last_ts_) { 199 if (ts < last_ts_) {
200 if (last_ts_ > 0xf0000000 && ts < 0x0fffffff) { 200 if (last_ts_ > 0xf0000000 && ts < 0x0fffffff) {
201 ++num_wrap_; 201 ++num_wrap_;
202 } 202 }
203 } else if (num_wrap_ > 0 && (ts - last_ts_) >= 0x0fffffff) {
204 // Backwards wrap. Unwrap with last wrap count and don't update last_ts_.
205 return ts + ((num_wrap_ -1) << 32);
mflodman 2016/03/09 15:01:57 Functionality LG, but can this be written in an ea
sprang_webrtc 2016/03/09 15:40:30 Not without duplicating "last_ts = ts" or adding a
203 } 206 }
204 last_ts_ = ts; 207 last_ts_ = ts;
205 int64_t unwrapped_ts = ts + (num_wrap_ << 32); 208 return ts + (num_wrap_ << 32);
206 return unwrapped_ts;
207 } 209 }
208 210
209 int64_t TmToSeconds(const std::tm& tm) { 211 int64_t TmToSeconds(const std::tm& tm) {
210 static short int mdays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 212 static short int mdays[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
211 static short int cumul_mdays[12] = {0, 31, 59, 90, 120, 151, 213 static short int cumul_mdays[12] = {0, 31, 59, 90, 120, 151,
212 181, 212, 243, 273, 304, 334}; 214 181, 212, 243, 273, 304, 334};
213 int year = tm.tm_year + 1900; 215 int year = tm.tm_year + 1900;
214 int month = tm.tm_mon; 216 int month = tm.tm_mon;
215 int day = tm.tm_mday - 1; // Make 0-based like the rest. 217 int day = tm.tm_mday - 1; // Make 0-based like the rest.
216 int hour = tm.tm_hour; 218 int hour = tm.tm_hour;
(...skipping 27 matching lines...) Expand all
244 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based. 246 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based.
245 day -= 1; 247 day -= 1;
246 248
247 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| 249 // Combine all variables into seconds from 1970-01-01 00:00 (except |month|
248 // which was accumulated into |day| above). 250 // which was accumulated into |day| above).
249 return (((static_cast<int64_t> 251 return (((static_cast<int64_t>
250 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; 252 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec;
251 } 253 }
252 254
253 } // namespace rtc 255 } // namespace rtc
OLDNEW
« no previous file with comments | « no previous file | webrtc/video/video_quality_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698