OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // Now in the time domain in us. | 49 // Now in the time domain in us. |
50 static int64_t MicrosecondTimestamp(); | 50 static int64_t MicrosecondTimestamp(); |
51 | 51 |
52 // Returns the number of ticks in the tick domain. | 52 // Returns the number of ticks in the tick domain. |
53 int64_t Ticks() const; | 53 int64_t Ticks() const; |
54 | 54 |
55 static int64_t MillisecondsToTicks(const int64_t ms); | 55 static int64_t MillisecondsToTicks(const int64_t ms); |
56 | 56 |
57 static int64_t TicksToMilliseconds(const int64_t ticks); | 57 static int64_t TicksToMilliseconds(const int64_t ticks); |
58 | 58 |
| 59 static int64_t TicksToMicroseconds(const int64_t ticks); |
| 60 |
59 // Returns a TickTime that is ticks later than the passed TickTime. | 61 // Returns a TickTime that is ticks later than the passed TickTime. |
60 friend TickTime operator+(const TickTime lhs, const int64_t ticks); | 62 friend TickTime operator+(const TickTime lhs, const int64_t ticks); |
61 TickTime& operator+=(const int64_t& ticks); | 63 TickTime& operator+=(const int64_t& ticks); |
62 | 64 |
63 // Returns a TickInterval that is the difference in ticks beween rhs and lhs. | 65 // Returns a TickInterval that is the difference in ticks beween rhs and lhs. |
64 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); | 66 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); |
65 | 67 |
66 // Call to engage the fake clock. This is useful for tests since relying on | 68 // Call to engage the fake clock. This is useful for tests since relying on |
67 // a real clock often makes the test flaky. | 69 // a real clock often makes the test flaky. |
68 static void UseFakeClock(int64_t start_millisecond); | 70 static void UseFakeClock(int64_t start_millisecond); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 friend bool operator>=(const TickInterval& lhs, const TickInterval& rhs); | 106 friend bool operator>=(const TickInterval& lhs, const TickInterval& rhs); |
105 | 107 |
106 private: | 108 private: |
107 friend class TickTime; | 109 friend class TickTime; |
108 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); | 110 friend TickInterval operator-(const TickTime& lhs, const TickTime& rhs); |
109 | 111 |
110 private: | 112 private: |
111 int64_t interval_; | 113 int64_t interval_; |
112 }; | 114 }; |
113 | 115 |
| 116 inline int64_t TickInterval::Milliseconds() const { |
| 117 return TickTime::TicksToMilliseconds(interval_); |
| 118 } |
| 119 |
| 120 inline int64_t TickInterval::Microseconds() const { |
| 121 return TickTime::TicksToMicroseconds(interval_); |
| 122 } |
| 123 |
114 inline TickInterval operator+(const TickInterval& lhs, | 124 inline TickInterval operator+(const TickInterval& lhs, |
115 const TickInterval& rhs) { | 125 const TickInterval& rhs) { |
116 return TickInterval(lhs.interval_ + rhs.interval_); | 126 return TickInterval(lhs.interval_ + rhs.interval_); |
117 } | 127 } |
118 | 128 |
119 inline TickInterval operator-(const TickInterval& lhs, | 129 inline TickInterval operator-(const TickInterval& lhs, |
120 const TickInterval& rhs) { | 130 const TickInterval& rhs) { |
121 return TickInterval(lhs.interval_ - rhs.interval_); | 131 return TickInterval(lhs.interval_ - rhs.interval_); |
122 } | 132 } |
123 | 133 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 : ticks_(ticks) { | 165 : ticks_(ticks) { |
156 } | 166 } |
157 | 167 |
158 inline TickTime TickTime::Now() { | 168 inline TickTime TickTime::Now() { |
159 if (use_fake_clock_) | 169 if (use_fake_clock_) |
160 return TickTime(fake_ticks_); | 170 return TickTime(fake_ticks_); |
161 else | 171 else |
162 return TickTime(QueryOsForTicks()); | 172 return TickTime(QueryOsForTicks()); |
163 } | 173 } |
164 | 174 |
165 inline int64_t TickTime::MillisecondTimestamp() { | |
166 int64_t ticks = TickTime::Now().Ticks(); | |
167 #if _WIN32 | |
168 #ifdef USE_QUERY_PERFORMANCE_COUNTER | |
169 LARGE_INTEGER qpfreq; | |
170 QueryPerformanceFrequency(&qpfreq); | |
171 return (ticks * 1000) / qpfreq.QuadPart; | |
172 #else | |
173 return ticks; | |
174 #endif | |
175 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) | |
176 return ticks / 1000000LL; | |
177 #else | |
178 return ticks / 1000LL; | |
179 #endif | |
180 } | |
181 | |
182 inline int64_t TickTime::MicrosecondTimestamp() { | |
183 int64_t ticks = TickTime::Now().Ticks(); | |
184 #if _WIN32 | |
185 #ifdef USE_QUERY_PERFORMANCE_COUNTER | |
186 LARGE_INTEGER qpfreq; | |
187 QueryPerformanceFrequency(&qpfreq); | |
188 return (ticks * 1000) / (qpfreq.QuadPart / 1000); | |
189 #else | |
190 return ticks * 1000LL; | |
191 #endif | |
192 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) | |
193 return ticks / 1000LL; | |
194 #else | |
195 return ticks; | |
196 #endif | |
197 } | |
198 | |
199 inline int64_t TickTime::Ticks() const { | 175 inline int64_t TickTime::Ticks() const { |
200 return ticks_; | 176 return ticks_; |
201 } | 177 } |
202 | 178 |
203 inline int64_t TickTime::MillisecondsToTicks(const int64_t ms) { | |
204 #if _WIN32 | |
205 #ifdef USE_QUERY_PERFORMANCE_COUNTER | |
206 LARGE_INTEGER qpfreq; | |
207 QueryPerformanceFrequency(&qpfreq); | |
208 return (qpfreq.QuadPart * ms) / 1000; | |
209 #else | |
210 return ms; | |
211 #endif | |
212 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) | |
213 return ms * 1000000LL; | |
214 #else | |
215 return ms * 1000LL; | |
216 #endif | |
217 } | |
218 | |
219 inline int64_t TickTime::TicksToMilliseconds(const int64_t ticks) { | |
220 #if _WIN32 | |
221 #ifdef USE_QUERY_PERFORMANCE_COUNTER | |
222 LARGE_INTEGER qpfreq; | |
223 QueryPerformanceFrequency(&qpfreq); | |
224 return (ticks * 1000) / qpfreq.QuadPart; | |
225 #else | |
226 return ticks; | |
227 #endif | |
228 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) | |
229 return ticks / 1000000LL; | |
230 #else | |
231 return ticks / 1000LL; | |
232 #endif | |
233 } | |
234 | |
235 inline TickTime& TickTime::operator+=(const int64_t& ticks) { | 179 inline TickTime& TickTime::operator+=(const int64_t& ticks) { |
236 ticks_ += ticks; | 180 ticks_ += ticks; |
237 return *this; | 181 return *this; |
238 } | 182 } |
239 | 183 |
240 inline TickInterval::TickInterval() : interval_(0) { | 184 inline TickInterval::TickInterval() : interval_(0) { |
241 } | 185 } |
242 | 186 |
243 inline TickInterval::TickInterval(const int64_t interval) | 187 inline TickInterval::TickInterval(const int64_t interval) |
244 : interval_(interval) { | 188 : interval_(interval) { |
245 } | 189 } |
246 | 190 |
247 inline int64_t TickInterval::Milliseconds() const { | |
248 #if _WIN32 | |
249 #ifdef USE_QUERY_PERFORMANCE_COUNTER | |
250 LARGE_INTEGER qpfreq; | |
251 QueryPerformanceFrequency(&qpfreq); | |
252 return (interval_ * 1000) / qpfreq.QuadPart; | |
253 #else | |
254 // interval_ is in ms | |
255 return interval_; | |
256 #endif | |
257 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) | |
258 // interval_ is in ns | |
259 return interval_ / 1000000; | |
260 #else | |
261 // interval_ is usecs | |
262 return interval_ / 1000; | |
263 #endif | |
264 } | |
265 | |
266 inline int64_t TickInterval::Microseconds() const { | |
267 #if _WIN32 | |
268 #ifdef USE_QUERY_PERFORMANCE_COUNTER | |
269 LARGE_INTEGER qpfreq; | |
270 QueryPerformanceFrequency(&qpfreq); | |
271 return (interval_ * 1000000) / qpfreq.QuadPart; | |
272 #else | |
273 // interval_ is in ms | |
274 return interval_ * 1000LL; | |
275 #endif | |
276 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) | |
277 // interval_ is in ns | |
278 return interval_ / 1000; | |
279 #else | |
280 // interval_ is usecs | |
281 return interval_; | |
282 #endif | |
283 } | |
284 | |
285 inline TickInterval& TickInterval::operator+=(const TickInterval& rhs) { | 191 inline TickInterval& TickInterval::operator+=(const TickInterval& rhs) { |
286 interval_ += rhs.interval_; | 192 interval_ += rhs.interval_; |
287 return *this; | 193 return *this; |
288 } | 194 } |
289 | 195 |
290 inline TickInterval& TickInterval::operator-=(const TickInterval& rhs) { | 196 inline TickInterval& TickInterval::operator-=(const TickInterval& rhs) { |
291 interval_ -= rhs.interval_; | 197 interval_ -= rhs.interval_; |
292 return *this; | 198 return *this; |
293 } | 199 } |
294 | 200 |
295 } // namespace webrtc | 201 } // namespace webrtc |
296 | 202 |
297 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_ | 203 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_TICK_UTIL_H_ |
OLD | NEW |