| 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 24 matching lines...) Expand all Loading... |
| 35 const uint32 HALF = 0x80000000; | 35 const uint32 HALF = 0x80000000; |
| 36 | 36 |
| 37 uint64 TimeNanos() { | 37 uint64 TimeNanos() { |
| 38 int64 ticks = 0; | 38 int64 ticks = 0; |
| 39 #if defined(WEBRTC_MAC) | 39 #if defined(WEBRTC_MAC) |
| 40 static mach_timebase_info_data_t timebase; | 40 static mach_timebase_info_data_t timebase; |
| 41 if (timebase.denom == 0) { | 41 if (timebase.denom == 0) { |
| 42 // Get the timebase if this is the first time we run. | 42 // Get the timebase if this is the first time we run. |
| 43 // Recommended by Apple's QA1398. | 43 // Recommended by Apple's QA1398. |
| 44 if (mach_timebase_info(&timebase) != KERN_SUCCESS) { | 44 if (mach_timebase_info(&timebase) != KERN_SUCCESS) { |
| 45 DCHECK(false); | 45 RTC_DCHECK(false); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 // Use timebase to convert absolute time tick units into nanoseconds. | 48 // Use timebase to convert absolute time tick units into nanoseconds. |
| 49 ticks = mach_absolute_time() * timebase.numer / timebase.denom; | 49 ticks = mach_absolute_time() * timebase.numer / timebase.denom; |
| 50 #elif defined(WEBRTC_POSIX) | 50 #elif defined(WEBRTC_POSIX) |
| 51 struct timespec ts; | 51 struct timespec ts; |
| 52 // TODO: Do we need to handle the case when CLOCK_MONOTONIC | 52 // TODO: Do we need to handle the case when CLOCK_MONOTONIC |
| 53 // is not supported? | 53 // is not supported? |
| 54 clock_gettime(CLOCK_MONOTONIC, &ts); | 54 clock_gettime(CLOCK_MONOTONIC, &ts); |
| 55 ticks = kNumNanosecsPerSec * static_cast<int64>(ts.tv_sec) + | 55 ticks = kNumNanosecsPerSec * static_cast<int64>(ts.tv_sec) + |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 if (gettimeofday(&timeval, NULL) < 0) { | 129 if (gettimeofday(&timeval, NULL) < 0) { |
| 130 // Incredibly unlikely code path. | 130 // Incredibly unlikely code path. |
| 131 timeval.tv_sec = timeval.tv_usec = 0; | 131 timeval.tv_sec = timeval.tv_usec = 0; |
| 132 } | 132 } |
| 133 time_t secs = timeval.tv_sec; | 133 time_t secs = timeval.tv_sec; |
| 134 gmtime_r(&secs, tm); | 134 gmtime_r(&secs, tm); |
| 135 *microseconds = timeval.tv_usec; | 135 *microseconds = timeval.tv_usec; |
| 136 } | 136 } |
| 137 | 137 |
| 138 uint32 TimeAfter(int32 elapsed) { | 138 uint32 TimeAfter(int32 elapsed) { |
| 139 DCHECK_GE(elapsed, 0); | 139 RTC_DCHECK_GE(elapsed, 0); |
| 140 DCHECK_LT(static_cast<uint32>(elapsed), HALF); | 140 RTC_DCHECK_LT(static_cast<uint32>(elapsed), HALF); |
| 141 return Time() + elapsed; | 141 return Time() + elapsed; |
| 142 } | 142 } |
| 143 | 143 |
| 144 bool TimeIsBetween(uint32 earlier, uint32 middle, uint32 later) { | 144 bool TimeIsBetween(uint32 earlier, uint32 middle, uint32 later) { |
| 145 if (earlier <= later) { | 145 if (earlier <= later) { |
| 146 return ((earlier <= middle) && (middle <= later)); | 146 return ((earlier <= middle) && (middle <= later)); |
| 147 } else { | 147 } else { |
| 148 return !((later < middle) && (middle < earlier)); | 148 return !((later < middle) && (middle < earlier)); |
| 149 } | 149 } |
| 150 } | 150 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 if (last_ts_ > 0xf0000000 && ts < 0x0fffffff) { | 198 if (last_ts_ > 0xf0000000 && ts < 0x0fffffff) { |
| 199 ++num_wrap_; | 199 ++num_wrap_; |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 last_ts_ = ts; | 202 last_ts_ = ts; |
| 203 int64_t unwrapped_ts = ts + (num_wrap_ << 32); | 203 int64_t unwrapped_ts = ts + (num_wrap_ << 32); |
| 204 return unwrapped_ts; | 204 return unwrapped_ts; |
| 205 } | 205 } |
| 206 | 206 |
| 207 } // namespace rtc | 207 } // namespace rtc |
| OLD | NEW |