danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #ifndef TEST_DRIFTING_CLOCK_H_ |
| 11 | #define TEST_DRIFTING_CLOCK_H_ |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include <stdint.h> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "system_wrappers/include/clock.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 16 | #include "system_wrappers/include/ntp_time.h" |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | namespace test { |
| 20 | class DriftingClock : public Clock { |
| 21 | public: |
| 22 | // TODO(danilchap): Make this constants constexpr when it would be supported. |
| 23 | static const float kDoubleSpeed; // 2.0f; |
| 24 | static const float kNoDrift; // 1.0f; |
| 25 | static const float kHalfSpeed; // 0.5f; |
| 26 | |
| 27 | DriftingClock(Clock* clock, float speed); |
| 28 | |
| 29 | // TODO(danilchap): Make this functions constexpr when it would be supported. |
| 30 | static float PercentsFaster(float percent) { return 1.0f + percent / 100.0f; } |
| 31 | static float PercentsSlower(float percent) { return 1.0f - percent / 100.0f; } |
| 32 | |
Sebastian Jansson | 2a96ab2 | 2019-01-30 20:44:45 +0100 | [diff] [blame] | 33 | int64_t TimeInMilliseconds() override; |
| 34 | int64_t TimeInMicroseconds() override; |
| 35 | NtpTime CurrentNtpTime() override; |
| 36 | int64_t CurrentNtpInMilliseconds() override; |
danilchap | 9c6a0c7 | 2016-02-10 10:54:47 -0800 | [diff] [blame] | 37 | |
| 38 | private: |
| 39 | float Drift() const; |
| 40 | |
| 41 | Clock* const clock_; |
| 42 | const float drift_; |
| 43 | const int64_t start_time_; |
| 44 | }; |
| 45 | } // namespace test |
| 46 | } // namespace webrtc |
| 47 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 48 | #endif // TEST_DRIFTING_CLOCK_H_ |