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

Side by Side Diff: webrtc/base/timeutils.cc

Issue 1835053002: Change default timestamp to 64 bits in all webrtc directories. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Add TODO for timestamp. Created 4 years, 7 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 | « webrtc/base/timeutils.h ('k') | webrtc/base/timeutils_unittest.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 12 matching lines...) Expand all
23 #endif 23 #endif
24 #include <windows.h> 24 #include <windows.h>
25 #include <mmsystem.h> 25 #include <mmsystem.h>
26 #endif 26 #endif
27 27
28 #include "webrtc/base/checks.h" 28 #include "webrtc/base/checks.h"
29 #include "webrtc/base/timeutils.h" 29 #include "webrtc/base/timeutils.h"
30 30
31 namespace rtc { 31 namespace rtc {
32 32
33 const uint32_t HALF = 0x80000000;
34
35 uint64_t TimeNanos() { 33 uint64_t TimeNanos() {
36 int64_t ticks = 0; 34 int64_t ticks = 0;
37 #if defined(WEBRTC_MAC) 35 #if defined(WEBRTC_MAC)
38 static mach_timebase_info_data_t timebase; 36 static mach_timebase_info_data_t timebase;
39 if (timebase.denom == 0) { 37 if (timebase.denom == 0) {
40 // Get the timebase if this is the first time we run. 38 // Get the timebase if this is the first time we run.
41 // Recommended by Apple's QA1398. 39 // Recommended by Apple's QA1398.
42 if (mach_timebase_info(&timebase) != KERN_SUCCESS) { 40 if (mach_timebase_info(&timebase) != KERN_SUCCESS) {
43 RTC_DCHECK(false); 41 RTC_DCHECK(false);
44 } 42 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 81 }
84 82
85 int64_t TimeMillis() { 83 int64_t TimeMillis() {
86 return static_cast<int64_t>(TimeNanos() / kNumNanosecsPerMillisec); 84 return static_cast<int64_t>(TimeNanos() / kNumNanosecsPerMillisec);
87 } 85 }
88 86
89 uint64_t TimeMicros() { 87 uint64_t TimeMicros() {
90 return static_cast<uint64_t>(TimeNanos() / kNumNanosecsPerMicrosec); 88 return static_cast<uint64_t>(TimeNanos() / kNumNanosecsPerMicrosec);
91 } 89 }
92 90
93 uint32_t TimeAfter(int32_t elapsed) { 91 int64_t TimeAfter(int64_t elapsed) {
94 RTC_DCHECK_GE(elapsed, 0); 92 RTC_DCHECK_GE(elapsed, 0);
95 RTC_DCHECK_LT(static_cast<uint32_t>(elapsed), HALF); 93 return TimeMillis() + elapsed;
96 return Time() + elapsed;
97 } 94 }
98 95
99 bool TimeIsLaterOrEqual(uint32_t earlier, uint32_t later) { 96 int32_t TimeDiff32(uint32_t later, uint32_t earlier) {
100 int32_t diff = later - earlier;
101 return (diff >= 0 && static_cast<uint32_t>(diff) < HALF);
102 }
103
104 bool TimeIsLater(uint32_t earlier, uint32_t later) {
105 int32_t diff = later - earlier;
106 return (diff > 0 && static_cast<uint32_t>(diff) < HALF);
107 }
108
109 int32_t TimeDiff(uint32_t later, uint32_t earlier) {
110 return later - earlier; 97 return later - earlier;
111 } 98 }
112 99
113 int64_t TimeDiff64(int64_t later, int64_t earlier) { 100 int64_t TimeDiff(int64_t later, int64_t earlier) {
114 return later - earlier; 101 return later - earlier;
115 } 102 }
116 103
117 TimestampWrapAroundHandler::TimestampWrapAroundHandler() 104 TimestampWrapAroundHandler::TimestampWrapAroundHandler()
118 : last_ts_(0), num_wrap_(-1) {} 105 : last_ts_(0), num_wrap_(-1) {}
119 106
120 int64_t TimestampWrapAroundHandler::Unwrap(uint32_t ts) { 107 int64_t TimestampWrapAroundHandler::Unwrap(uint32_t ts) {
121 if (num_wrap_ == -1) { 108 if (num_wrap_ == -1) {
122 last_ts_ = ts; 109 last_ts_ = ts;
123 num_wrap_ = 0; 110 num_wrap_ = 0;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based. 161 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based.
175 day -= 1; 162 day -= 1;
176 163
177 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| 164 // Combine all variables into seconds from 1970-01-01 00:00 (except |month|
178 // which was accumulated into |day| above). 165 // which was accumulated into |day| above).
179 return (((static_cast<int64_t> 166 return (((static_cast<int64_t>
180 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; 167 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec;
181 } 168 }
182 169
183 } // namespace rtc 170 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/timeutils.h ('k') | webrtc/base/timeutils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698