blob: a0ba93edf0893df474100591cb3befc6b70a6c6a [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020013#include "system_wrappers/include/clock.h"
danilchap9c6a0c72016-02-10 10:54:47 -080014
15namespace webrtc {
16namespace test {
17class DriftingClock : public Clock {
18 public:
19 // TODO(danilchap): Make this constants constexpr when it would be supported.
20 static const float kDoubleSpeed; // 2.0f;
21 static const float kNoDrift; // 1.0f;
22 static const float kHalfSpeed; // 0.5f;
23
24 DriftingClock(Clock* clock, float speed);
25
26 // TODO(danilchap): Make this functions constexpr when it would be supported.
27 static float PercentsFaster(float percent) { return 1.0f + percent / 100.0f; }
28 static float PercentsSlower(float percent) { return 1.0f - percent / 100.0f; }
29
30 int64_t TimeInMilliseconds() const override;
31 int64_t TimeInMicroseconds() const override;
danilchap21dc1892017-03-07 02:51:09 -080032 NtpTime CurrentNtpTime() const override;
danilchap9c6a0c72016-02-10 10:54:47 -080033 int64_t CurrentNtpInMilliseconds() const override;
34
35 private:
36 float Drift() const;
37
38 Clock* const clock_;
39 const float drift_;
40 const int64_t start_time_;
41};
42} // namespace test
43} // namespace webrtc
44
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020045#endif // TEST_DRIFTING_CLOCK_H_