OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2005 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2005 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 16 matching lines...) Expand all Loading... |
27 static const int64_t kNumNanosecsPerMillisec = | 27 static const int64_t kNumNanosecsPerMillisec = |
28 kNumNanosecsPerSec / kNumMillisecsPerSec; | 28 kNumNanosecsPerSec / kNumMillisecsPerSec; |
29 static const int64_t kNumNanosecsPerMicrosec = | 29 static const int64_t kNumNanosecsPerMicrosec = |
30 kNumNanosecsPerSec / kNumMicrosecsPerSec; | 30 kNumNanosecsPerSec / kNumMicrosecsPerSec; |
31 | 31 |
32 // January 1970, in NTP milliseconds. | 32 // January 1970, in NTP milliseconds. |
33 static const int64_t kJan1970AsNtpMillisecs = INT64_C(2208988800000); | 33 static const int64_t kJan1970AsNtpMillisecs = INT64_C(2208988800000); |
34 | 34 |
35 typedef uint32_t TimeStamp; | 35 typedef uint32_t TimeStamp; |
36 | 36 |
| 37 // Returns the current time in milliseconds in 32 bits. |
| 38 uint32_t Time32(); |
| 39 |
| 40 // Returns the current time in milliseconds in 64 bits. |
| 41 int64_t Time64(); |
| 42 |
37 // Returns the current time in milliseconds. | 43 // Returns the current time in milliseconds. |
38 uint32_t Time(); | 44 // TODO(honghaiz): Returns Time64 once majority of the webrtc code migrates to |
| 45 // 64-bit timestamp. |
| 46 inline uint32_t Time() { |
| 47 return Time32(); |
| 48 } |
| 49 |
39 // Returns the current time in microseconds. | 50 // Returns the current time in microseconds. |
40 uint64_t TimeMicros(); | 51 uint64_t TimeMicros(); |
41 // Returns the current time in nanoseconds. | 52 // Returns the current time in nanoseconds. |
42 uint64_t TimeNanos(); | 53 uint64_t TimeNanos(); |
43 | 54 |
44 // Stores current time in *tm and microseconds in *microseconds. | 55 // Stores current time in *tm and microseconds in *microseconds. |
45 void CurrentTmTime(struct tm *tm, int *microseconds); | 56 void CurrentTmTime(struct tm *tm, int *microseconds); |
46 | 57 |
47 // Returns a future timestamp, 'elapsed' milliseconds from now. | 58 // Returns a future timestamp, 'elapsed' milliseconds from now. |
48 uint32_t TimeAfter(int32_t elapsed); | 59 uint32_t TimeAfter(int32_t elapsed); |
(...skipping 12 matching lines...) Expand all Loading... |
61 | 72 |
62 // Returns the earlier of two timestamps. | 73 // Returns the earlier of two timestamps. |
63 inline uint32_t TimeMin(uint32_t ts1, uint32_t ts2) { | 74 inline uint32_t TimeMin(uint32_t ts1, uint32_t ts2) { |
64 return TimeIsLaterOrEqual(ts1, ts2) ? ts1 : ts2; | 75 return TimeIsLaterOrEqual(ts1, ts2) ? ts1 : ts2; |
65 } | 76 } |
66 | 77 |
67 // Number of milliseconds that would elapse between 'earlier' and 'later' | 78 // Number of milliseconds that would elapse between 'earlier' and 'later' |
68 // timestamps. The value is negative if 'later' occurs before 'earlier'. | 79 // timestamps. The value is negative if 'later' occurs before 'earlier'. |
69 int32_t TimeDiff(uint32_t later, uint32_t earlier); | 80 int32_t TimeDiff(uint32_t later, uint32_t earlier); |
70 | 81 |
| 82 // Number of milliseconds that would elapse between 'earlier' and 'later' |
| 83 // timestamps. The value is negative if 'later' occurs before 'earlier'. |
| 84 int64_t TimeDiff64(int64_t later, int64_t earlier); |
| 85 |
71 // The number of milliseconds that have elapsed since 'earlier'. | 86 // The number of milliseconds that have elapsed since 'earlier'. |
72 inline int32_t TimeSince(uint32_t earlier) { | 87 inline int32_t TimeSince(uint32_t earlier) { |
73 return TimeDiff(Time(), earlier); | 88 return TimeDiff(Time(), earlier); |
74 } | 89 } |
75 | 90 |
76 // The number of milliseconds that will elapse between now and 'later'. | 91 // The number of milliseconds that will elapse between now and 'later'. |
77 inline int32_t TimeUntil(uint32_t later) { | 92 inline int32_t TimeUntil(uint32_t later) { |
78 return TimeDiff(later, Time()); | 93 return TimeDiff(later, Time()); |
79 } | 94 } |
80 | 95 |
(...skipping 14 matching lines...) Expand all Loading... |
95 }; | 110 }; |
96 | 111 |
97 // Convert from std::tm, which is relative to 1900-01-01 00:00 to number of | 112 // Convert from std::tm, which is relative to 1900-01-01 00:00 to number of |
98 // seconds from 1970-01-01 00:00 ("epoch"). Don't return time_t since that | 113 // seconds from 1970-01-01 00:00 ("epoch"). Don't return time_t since that |
99 // is still 32 bits on many systems. | 114 // is still 32 bits on many systems. |
100 int64_t TmToSeconds(const std::tm& tm); | 115 int64_t TmToSeconds(const std::tm& tm); |
101 | 116 |
102 } // namespace rtc | 117 } // namespace rtc |
103 | 118 |
104 #endif // WEBRTC_BASE_TIMEUTILS_H_ | 119 #endif // WEBRTC_BASE_TIMEUTILS_H_ |
OLD | NEW |