blob: 3471c008a1637c15461a167c48388f1a9eba102b [file] [log] [blame]
danilchap9c6a0c72016-02-10 10:54:47 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020010#ifndef TEST_DRIFTING_CLOCK_H_
11#define TEST_DRIFTING_CLOCK_H_
danilchap9c6a0c72016-02-10 10:54:47 -080012
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <stdint.h>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "system_wrappers/include/clock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010016#include "system_wrappers/include/ntp_time.h"
danilchap9c6a0c72016-02-10 10:54:47 -080017
18namespace webrtc {
19namespace test {
20class DriftingClock : public Clock {
21 public:
Danil Chapovalov01b7e922019-09-10 13:28:58 +020022 static constexpr float kNoDrift = 1.0f;
danilchap9c6a0c72016-02-10 10:54:47 -080023
24 DriftingClock(Clock* clock, float speed);
25
Danil Chapovalov01b7e922019-09-10 13:28:58 +020026 static constexpr float PercentsFaster(float percent) {
27 return 1.0f + percent / 100.0f;
28 }
29 static constexpr float PercentsSlower(float percent) {
30 return 1.0f - percent / 100.0f;
31 }
danilchap9c6a0c72016-02-10 10:54:47 -080032
Paul Hallakb59e9042021-05-20 17:21:49 +020033 Timestamp CurrentTime() override { return Drift(clock_->CurrentTime()); }
34 NtpTime CurrentNtpTime() override { return Drift(clock_->CurrentNtpTime()); }
35 NtpTime ConvertTimestampToNtpTime(Timestamp timestamp) override {
36 return Drift(clock_->ConvertTimestampToNtpTime(timestamp));
37 }
danilchap9c6a0c72016-02-10 10:54:47 -080038
39 private:
Sebastian Jansson4de31152019-06-11 08:52:11 +020040 TimeDelta Drift() const;
Paul Hallakb59e9042021-05-20 17:21:49 +020041 Timestamp Drift(Timestamp timestamp) const;
42 NtpTime Drift(NtpTime ntp_time) const;
danilchap9c6a0c72016-02-10 10:54:47 -080043
44 Clock* const clock_;
45 const float drift_;
Sebastian Jansson4de31152019-06-11 08:52:11 +020046 const Timestamp start_time_;
danilchap9c6a0c72016-02-10 10:54:47 -080047};
48} // namespace test
49} // namespace webrtc
50
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020051#endif // TEST_DRIFTING_CLOCK_H_