| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 virtual ~Clock() {} | 31 virtual ~Clock() {} |
| 32 | 32 |
| 33 // Return a timestamp in milliseconds relative to some arbitrary source; the | 33 // Return a timestamp in milliseconds relative to some arbitrary source; the |
| 34 // source is fixed for this clock. | 34 // source is fixed for this clock. |
| 35 virtual int64_t TimeInMilliseconds() const = 0; | 35 virtual int64_t TimeInMilliseconds() const = 0; |
| 36 | 36 |
| 37 // Return a timestamp in microseconds relative to some arbitrary source; the | 37 // Return a timestamp in microseconds relative to some arbitrary source; the |
| 38 // source is fixed for this clock. | 38 // source is fixed for this clock. |
| 39 virtual int64_t TimeInMicroseconds() const = 0; | 39 virtual int64_t TimeInMicroseconds() const = 0; |
| 40 | 40 |
| 41 // Retrieve an NTP absolute timestamp in seconds and fractions of a second. | 41 // Retrieve an NTP absolute timestamp. |
| 42 virtual void CurrentNtp(uint32_t& seconds, uint32_t& fractions) const = 0; | 42 virtual NtpTime CurrentNtpTime() const = 0; |
| 43 | 43 |
| 44 // Retrieve an NTP absolute timestamp in milliseconds. | 44 // Retrieve an NTP absolute timestamp in milliseconds. |
| 45 virtual int64_t CurrentNtpInMilliseconds() const = 0; | 45 virtual int64_t CurrentNtpInMilliseconds() const = 0; |
| 46 | 46 |
| 47 // TODO(danilchap): Make pure virtual once implemented in derived classed | |
| 48 // replacing CurrentNtp function. | |
| 49 virtual NtpTime CurrentNtpTime() const; | |
| 50 | |
| 51 // Converts an NTP timestamp to a millisecond timestamp. | 47 // Converts an NTP timestamp to a millisecond timestamp. |
| 52 static int64_t NtpToMs(uint32_t seconds, uint32_t fractions) { | 48 static int64_t NtpToMs(uint32_t seconds, uint32_t fractions) { |
| 53 return NtpTime(seconds, fractions).ToMs(); | 49 return NtpTime(seconds, fractions).ToMs(); |
| 54 } | 50 } |
| 55 | 51 |
| 56 // Returns an instance of the real-time system clock implementation. | 52 // Returns an instance of the real-time system clock implementation. |
| 57 static Clock* GetRealTimeClock(); | 53 static Clock* GetRealTimeClock(); |
| 58 }; | 54 }; |
| 59 | 55 |
| 60 class SimulatedClock : public Clock { | 56 class SimulatedClock : public Clock { |
| 61 public: | 57 public: |
| 62 explicit SimulatedClock(int64_t initial_time_us); | 58 explicit SimulatedClock(int64_t initial_time_us); |
| 63 | 59 |
| 64 ~SimulatedClock() override; | 60 ~SimulatedClock() override; |
| 65 | 61 |
| 66 // Return a timestamp in milliseconds relative to some arbitrary source; the | 62 // Return a timestamp in milliseconds relative to some arbitrary source; the |
| 67 // source is fixed for this clock. | 63 // source is fixed for this clock. |
| 68 int64_t TimeInMilliseconds() const override; | 64 int64_t TimeInMilliseconds() const override; |
| 69 | 65 |
| 70 // Return a timestamp in microseconds relative to some arbitrary source; the | 66 // Return a timestamp in microseconds relative to some arbitrary source; the |
| 71 // source is fixed for this clock. | 67 // source is fixed for this clock. |
| 72 int64_t TimeInMicroseconds() const override; | 68 int64_t TimeInMicroseconds() const override; |
| 73 | 69 |
| 74 // Retrieve an NTP absolute timestamp in milliseconds. | 70 // Retrieve an NTP absolute timestamp. |
| 75 void CurrentNtp(uint32_t& seconds, uint32_t& fractions) const override; | 71 NtpTime CurrentNtpTime() const override; |
| 76 | 72 |
| 77 // Converts an NTP timestamp to a millisecond timestamp. | 73 // Converts an NTP timestamp to a millisecond timestamp. |
| 78 int64_t CurrentNtpInMilliseconds() const override; | 74 int64_t CurrentNtpInMilliseconds() const override; |
| 79 | 75 |
| 80 // Advance the simulated clock with a given number of milliseconds or | 76 // Advance the simulated clock with a given number of milliseconds or |
| 81 // microseconds. | 77 // microseconds. |
| 82 void AdvanceTimeMilliseconds(int64_t milliseconds); | 78 void AdvanceTimeMilliseconds(int64_t milliseconds); |
| 83 void AdvanceTimeMicroseconds(int64_t microseconds); | 79 void AdvanceTimeMicroseconds(int64_t microseconds); |
| 84 | 80 |
| 85 private: | 81 private: |
| 86 int64_t time_us_; | 82 int64_t time_us_; |
| 87 std::unique_ptr<RWLockWrapper> lock_; | 83 std::unique_ptr<RWLockWrapper> lock_; |
| 88 }; | 84 }; |
| 89 | 85 |
| 90 }; // namespace webrtc | 86 }; // namespace webrtc |
| 91 | 87 |
| 92 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CLOCK_H_ | 88 #endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_CLOCK_H_ |
| OLD | NEW |