| 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 |
| 11 #include "webrtc/system_wrappers/include/tick_util.h" | 11 #include "webrtc/system_wrappers/include/tick_util.h" |
| 12 | 12 |
| 13 #include <assert.h> | 13 #include <assert.h> |
| 14 | 14 |
| 15 namespace webrtc { | 15 namespace webrtc { |
| 16 | 16 |
| 17 bool TickTime::use_fake_clock_ = false; | |
| 18 int64_t TickTime::fake_ticks_ = 0; | |
| 19 | |
| 20 int64_t TickTime::MillisecondTimestamp() { | 17 int64_t TickTime::MillisecondTimestamp() { |
| 21 return TicksToMilliseconds(TickTime::Now().Ticks()); | 18 return TicksToMilliseconds(TickTime::Now().Ticks()); |
| 22 } | 19 } |
| 23 | 20 |
| 24 int64_t TickTime::MicrosecondTimestamp() { | 21 int64_t TickTime::MicrosecondTimestamp() { |
| 25 return TicksToMicroseconds(TickTime::Now().Ticks()); | 22 return TicksToMicroseconds(TickTime::Now().Ticks()); |
| 26 } | 23 } |
| 27 | 24 |
| 28 int64_t TickTime::MillisecondsToTicks(const int64_t ms) { | 25 int64_t TickTime::MillisecondsToTicks(const int64_t ms) { |
| 29 #if _WIN32 | 26 #if _WIN32 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 mach_timebase_info_data_t timebase; | 72 mach_timebase_info_data_t timebase; |
| 76 (void)mach_timebase_info(&timebase); | 73 (void)mach_timebase_info(&timebase); |
| 77 timebase_microsecond_fract = timebase.numer / (timebase.denom * 1e3); | 74 timebase_microsecond_fract = timebase.numer / (timebase.denom * 1e3); |
| 78 } | 75 } |
| 79 return ticks * timebase_microsecond_fract; | 76 return ticks * timebase_microsecond_fract; |
| 80 #else | 77 #else |
| 81 return ticks; | 78 return ticks; |
| 82 #endif | 79 #endif |
| 83 } | 80 } |
| 84 | 81 |
| 85 void TickTime::UseFakeClock(int64_t start_millisecond) { | |
| 86 use_fake_clock_ = true; | |
| 87 fake_ticks_ = MillisecondsToTicks(start_millisecond); | |
| 88 } | |
| 89 | |
| 90 void TickTime::AdvanceFakeClock(int64_t milliseconds) { | |
| 91 assert(use_fake_clock_); | |
| 92 fake_ticks_ += MillisecondsToTicks(milliseconds); | |
| 93 } | |
| 94 | |
| 95 // Gets the native system tick count. The actual unit, resolution, and epoch | 82 // Gets the native system tick count. The actual unit, resolution, and epoch |
| 96 // varies by platform: | 83 // varies by platform: |
| 97 // Windows: Milliseconds of uptime with rollover count in the upper 32-bits. | 84 // Windows: Milliseconds of uptime with rollover count in the upper 32-bits. |
| 98 // Linux/Android: Nanoseconds since the Unix epoch. | 85 // Linux/Android: Nanoseconds since the Unix epoch. |
| 99 // Mach (Mac/iOS): "absolute" time since first call. | 86 // Mach (Mac/iOS): "absolute" time since first call. |
| 100 // Unknown POSIX: Microseconds since the Unix epoch. | 87 // Unknown POSIX: Microseconds since the Unix epoch. |
| 101 int64_t TickTime::QueryOsForTicks() { | 88 int64_t TickTime::QueryOsForTicks() { |
| 102 #if _WIN32 | 89 #if _WIN32 |
| 103 static volatile LONG last_time_get_time = 0; | 90 static volatile LONG last_time_get_time = 0; |
| 104 static volatile int64_t num_wrap_time_get_time = 0; | 91 static volatile int64_t num_wrap_time_get_time = 0; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 126 } |
| 140 return mach_absolute_time() - timebase_start; | 127 return mach_absolute_time() - timebase_start; |
| 141 #else | 128 #else |
| 142 struct timeval tv; | 129 struct timeval tv; |
| 143 gettimeofday(&tv, NULL); | 130 gettimeofday(&tv, NULL); |
| 144 return 1000000LL * tv.tv_sec + tv.tv_usec; | 131 return 1000000LL * tv.tv_sec + tv.tv_usec; |
| 145 #endif | 132 #endif |
| 146 } | 133 } |
| 147 | 134 |
| 148 } // namespace webrtc | 135 } // namespace webrtc |
| OLD | NEW |