Chromium Code Reviews

Side by Side Diff: webrtc/base/timeutils.h

Issue 1835053002: Change default timestamp to 64 bits in all webrtc directories. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
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 11 matching lines...)
22 static const int64_t kNumMicrosecsPerSec = INT64_C(1000000); 22 static const int64_t kNumMicrosecsPerSec = INT64_C(1000000);
23 static const int64_t kNumNanosecsPerSec = INT64_C(1000000000); 23 static const int64_t kNumNanosecsPerSec = INT64_C(1000000000);
24 24
25 static const int64_t kNumMicrosecsPerMillisec = 25 static const int64_t kNumMicrosecsPerMillisec =
26 kNumMicrosecsPerSec / kNumMillisecsPerSec; 26 kNumMicrosecsPerSec / kNumMillisecsPerSec;
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 typedef uint32_t TimeStamp;
33
34 // Returns the current time in milliseconds in 32 bits. 32 // Returns the current time in milliseconds in 32 bits.
35 uint32_t Time32(); 33 uint32_t Time32();
36 34
37 // Returns the current time in milliseconds in 64 bits. 35 // Returns the current time in milliseconds in 64 bits.
36 // TODO(honghaiz): remove this and replace the call with Time().
pthatcher1 2016/05/02 16:57:56 I think it's OK to leave this so callers can be ex
honghaiz3 2016/05/03 21:18:25 Removed this and replaced with TimeMillis()
38 int64_t Time64(); 37 int64_t Time64();
39 38
40 // Returns the current time in milliseconds. 39 // Returns the current time in milliseconds.
41 // TODO(honghaiz): Returns Time64 once majority of the webrtc code migrates to 40 inline int64_t Time() {
42 // 64-bit timestamp. 41 return Time64();
43 inline uint32_t Time() {
44 return Time32();
45 } 42 }
46 43
47 // Returns the current time in microseconds. 44 // Returns the current time in microseconds.
48 uint64_t TimeMicros(); 45 uint64_t TimeMicros();
49 // Returns the current time in nanoseconds. 46 // Returns the current time in nanoseconds.
50 uint64_t TimeNanos(); 47 uint64_t TimeNanos();
51 48
52 // Returns a future timestamp, 'elapsed' milliseconds from now. 49 // Returns a future timestamp, 'elapsed' milliseconds from now.
53 uint32_t TimeAfter(int32_t elapsed); 50 int64_t TimeAfter(int64_t elapsed);
54
55 bool TimeIsLaterOrEqual(uint32_t earlier, uint32_t later); // Inclusive
56 bool TimeIsLater(uint32_t earlier, uint32_t later); // Exclusive
57
58 // Returns the later of two timestamps.
59 inline uint32_t TimeMax(uint32_t ts1, uint32_t ts2) {
60 return TimeIsLaterOrEqual(ts1, ts2) ? ts2 : ts1;
61 }
62
63 // Returns the earlier of two timestamps.
64 inline uint32_t TimeMin(uint32_t ts1, uint32_t ts2) {
65 return TimeIsLaterOrEqual(ts1, ts2) ? ts1 : ts2;
66 }
67 51
68 // Number of milliseconds that would elapse between 'earlier' and 'later' 52 // Number of milliseconds that would elapse between 'earlier' and 'later'
69 // timestamps. The value is negative if 'later' occurs before 'earlier'. 53 // timestamps. The value is negative if 'later' occurs before 'earlier'.
70 int32_t TimeDiff(uint32_t later, uint32_t earlier); 54 int64_t TimeDiff(int64_t later, int64_t earlier);
71 55 int32_t TimeDiff32(uint32_t later, uint32_t earlier);
72 // Number of milliseconds that would elapse between 'earlier' and 'later'
73 // timestamps. The value is negative if 'later' occurs before 'earlier'.
74 int64_t TimeDiff64(int64_t later, int64_t earlier);
75 56
76 // The number of milliseconds that have elapsed since 'earlier'. 57 // The number of milliseconds that have elapsed since 'earlier'.
77 inline int32_t TimeSince(uint32_t earlier) { 58 inline int64_t TimeSince(int64_t earlier) {
78 return TimeDiff(Time(), earlier); 59 return Time() - earlier;
79 } 60 }
80 61
81 // The number of milliseconds that will elapse between now and 'later'. 62 // The number of milliseconds that will elapse between now and 'later'.
82 inline int32_t TimeUntil(uint32_t later) { 63 inline int64_t TimeUntil(uint64_t later) {
83 return TimeDiff(later, Time()); 64 return later - Time();
84 } 65 }
85 66
86 class TimestampWrapAroundHandler { 67 class TimestampWrapAroundHandler {
87 public: 68 public:
88 TimestampWrapAroundHandler(); 69 TimestampWrapAroundHandler();
89 70
90 int64_t Unwrap(uint32_t ts); 71 int64_t Unwrap(uint32_t ts);
91 72
92 private: 73 private:
93 uint32_t last_ts_; 74 uint32_t last_ts_;
94 int64_t num_wrap_; 75 int64_t num_wrap_;
95 }; 76 };
96 77
97 // Convert from std::tm, which is relative to 1900-01-01 00:00 to number of 78 // 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 79 // seconds from 1970-01-01 00:00 ("epoch"). Don't return time_t since that
99 // is still 32 bits on many systems. 80 // is still 32 bits on many systems.
100 int64_t TmToSeconds(const std::tm& tm); 81 int64_t TmToSeconds(const std::tm& tm);
101 82
102 } // namespace rtc 83 } // namespace rtc
103 84
104 #endif // WEBRTC_BASE_TIMEUTILS_H_ 85 #endif // WEBRTC_BASE_TIMEUTILS_H_
OLDNEW

Powered by Google App Engine