OLD | NEW |
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 20 matching lines...) Expand all Loading... |
31 namespace rtc { | 31 namespace rtc { |
32 | 32 |
33 ClockInterface* g_clock = nullptr; | 33 ClockInterface* g_clock = nullptr; |
34 | 34 |
35 ClockInterface* SetClockForTesting(ClockInterface* clock) { | 35 ClockInterface* SetClockForTesting(ClockInterface* clock) { |
36 ClockInterface* prev = g_clock; | 36 ClockInterface* prev = g_clock; |
37 g_clock = clock; | 37 g_clock = clock; |
38 return prev; | 38 return prev; |
39 } | 39 } |
40 | 40 |
41 uint64_t TimeNanos() { | 41 uint64_t SystemTimeNanos() { |
42 if (g_clock) { | |
43 return g_clock->TimeNanos(); | |
44 } | |
45 int64_t ticks; | 42 int64_t ticks; |
46 #if defined(WEBRTC_MAC) | 43 #if defined(WEBRTC_MAC) |
47 static mach_timebase_info_data_t timebase; | 44 static mach_timebase_info_data_t timebase; |
48 if (timebase.denom == 0) { | 45 if (timebase.denom == 0) { |
49 // Get the timebase if this is the first time we run. | 46 // Get the timebase if this is the first time we run. |
50 // Recommended by Apple's QA1398. | 47 // Recommended by Apple's QA1398. |
51 if (mach_timebase_info(&timebase) != KERN_SUCCESS) { | 48 if (mach_timebase_info(&timebase) != KERN_SUCCESS) { |
52 RTC_DCHECK(false); | 49 RTC_DCHECK(false); |
53 } | 50 } |
54 } | 51 } |
(...skipping 24 matching lines...) Expand all Loading... |
79 ticks = now + (num_wrap_timegettime << 32); | 76 ticks = now + (num_wrap_timegettime << 32); |
80 // TODO(deadbeef): Calculate with nanosecond precision. Otherwise, we're | 77 // TODO(deadbeef): Calculate with nanosecond precision. Otherwise, we're |
81 // just wasting a multiply and divide when doing Time() on Windows. | 78 // just wasting a multiply and divide when doing Time() on Windows. |
82 ticks = ticks * kNumNanosecsPerMillisec; | 79 ticks = ticks * kNumNanosecsPerMillisec; |
83 #else | 80 #else |
84 #error Unsupported platform. | 81 #error Unsupported platform. |
85 #endif | 82 #endif |
86 return ticks; | 83 return ticks; |
87 } | 84 } |
88 | 85 |
| 86 int64_t SystemTimeMillis() { |
| 87 return static_cast<int64_t>(SystemTimeNanos() / kNumNanosecsPerMillisec); |
| 88 } |
| 89 |
| 90 uint64_t TimeNanos() { |
| 91 if (g_clock) { |
| 92 return g_clock->TimeNanos(); |
| 93 } |
| 94 return SystemTimeNanos(); |
| 95 } |
| 96 |
89 uint32_t Time32() { | 97 uint32_t Time32() { |
90 return static_cast<uint32_t>(TimeNanos() / kNumNanosecsPerMillisec); | 98 return static_cast<uint32_t>(TimeNanos() / kNumNanosecsPerMillisec); |
91 } | 99 } |
92 | 100 |
93 int64_t TimeMillis() { | 101 int64_t TimeMillis() { |
94 return static_cast<int64_t>(TimeNanos() / kNumNanosecsPerMillisec); | 102 return static_cast<int64_t>(TimeNanos() / kNumNanosecsPerMillisec); |
95 } | 103 } |
96 | 104 |
97 uint64_t TimeMicros() { | 105 uint64_t TimeMicros() { |
98 return static_cast<uint64_t>(TimeNanos() / kNumNanosecsPerMicrosec); | 106 return static_cast<uint64_t>(TimeNanos() / kNumNanosecsPerMicrosec); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based. | 179 if (expiry_in_leap_year && month <= 2 - 1) // |month| is zero based. |
172 day -= 1; | 180 day -= 1; |
173 | 181 |
174 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| | 182 // Combine all variables into seconds from 1970-01-01 00:00 (except |month| |
175 // which was accumulated into |day| above). | 183 // which was accumulated into |day| above). |
176 return (((static_cast<int64_t> | 184 return (((static_cast<int64_t> |
177 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; | 185 (year - 1970) * 365 + day) * 24 + hour) * 60 + min) * 60 + sec; |
178 } | 186 } |
179 | 187 |
180 } // namespace rtc | 188 } // namespace rtc |
OLD | NEW |