Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

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: Add TODO for timestamp. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/base/thread.cc ('k') | webrtc/base/timeutils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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...) Expand all
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; 32 // TODO(honghaiz): Define a type for the time value specifically.
33 33
34 // Returns the current time in milliseconds in 32 bits. 34 // Returns the current time in milliseconds in 32 bits.
35 uint32_t Time32(); 35 uint32_t Time32();
36 36
37 // Returns the current time in milliseconds in 64 bits. 37 // Returns the current time in milliseconds in 64 bits.
38 int64_t TimeMillis(); 38 int64_t TimeMillis();
39 39 // Deprecated. Do not use this in any new code.
40 // Returns the current time in milliseconds. 40 inline int64_t Time() {
41 // TODO(honghaiz): Change to return TimeMillis() once majority of the webrtc 41 return TimeMillis();
42 // code migrates to 64-bit timestamp.
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();
46
49 // Returns the current time in nanoseconds. 47 // Returns the current time in nanoseconds.
50 uint64_t TimeNanos(); 48 uint64_t TimeNanos();
51 49
52 // Returns a future timestamp, 'elapsed' milliseconds from now. 50 // Returns a future timestamp, 'elapsed' milliseconds from now.
53 uint32_t TimeAfter(int32_t elapsed); 51 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 52
68 // Number of milliseconds that would elapse between 'earlier' and 'later' 53 // Number of milliseconds that would elapse between 'earlier' and 'later'
69 // timestamps. The value is negative if 'later' occurs before 'earlier'. 54 // timestamps. The value is negative if 'later' occurs before 'earlier'.
70 int32_t TimeDiff(uint32_t later, uint32_t earlier); 55 int64_t TimeDiff(int64_t later, int64_t earlier);
71 56 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 57
76 // The number of milliseconds that have elapsed since 'earlier'. 58 // The number of milliseconds that have elapsed since 'earlier'.
77 inline int32_t TimeSince(uint32_t earlier) { 59 inline int64_t TimeSince(int64_t earlier) {
78 return TimeDiff(Time(), earlier); 60 return TimeMillis() - earlier;
79 } 61 }
80 62
81 // The number of milliseconds that will elapse between now and 'later'. 63 // The number of milliseconds that will elapse between now and 'later'.
82 inline int32_t TimeUntil(uint32_t later) { 64 inline int64_t TimeUntil(uint64_t later) {
83 return TimeDiff(later, Time()); 65 return later - TimeMillis();
84 } 66 }
85 67
86 class TimestampWrapAroundHandler { 68 class TimestampWrapAroundHandler {
87 public: 69 public:
88 TimestampWrapAroundHandler(); 70 TimestampWrapAroundHandler();
89 71
90 int64_t Unwrap(uint32_t ts); 72 int64_t Unwrap(uint32_t ts);
91 73
92 private: 74 private:
93 uint32_t last_ts_; 75 uint32_t last_ts_;
94 int64_t num_wrap_; 76 int64_t num_wrap_;
95 }; 77 };
96 78
97 // Convert from std::tm, which is relative to 1900-01-01 00:00 to number of 79 // 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 80 // seconds from 1970-01-01 00:00 ("epoch"). Don't return time_t since that
99 // is still 32 bits on many systems. 81 // is still 32 bits on many systems.
100 int64_t TmToSeconds(const std::tm& tm); 82 int64_t TmToSeconds(const std::tm& tm);
101 83
102 } // namespace rtc 84 } // namespace rtc
103 85
104 #endif // WEBRTC_BASE_TIMEUTILS_H_ 86 #endif // WEBRTC_BASE_TIMEUTILS_H_
OLDNEW
« no previous file with comments | « webrtc/base/thread.cc ('k') | webrtc/base/timeutils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698