• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
10 #ifndef TEST_DRIFTING_CLOCK_H_
11 #define TEST_DRIFTING_CLOCK_H_
12 
13 #include <stdint.h>
14 
15 #include "system_wrappers/include/clock.h"
16 #include "system_wrappers/include/ntp_time.h"
17 
18 namespace webrtc {
19 namespace test {
20 class DriftingClock : public Clock {
21  public:
22   static constexpr float kNoDrift = 1.0f;
23 
24   DriftingClock(Clock* clock, float speed);
25 
PercentsFaster(float percent)26   static constexpr float PercentsFaster(float percent) {
27     return 1.0f + percent / 100.0f;
28   }
PercentsSlower(float percent)29   static constexpr float PercentsSlower(float percent) {
30     return 1.0f - percent / 100.0f;
31   }
32 
33   Timestamp CurrentTime() override;
34   NtpTime CurrentNtpTime() override;
35   int64_t CurrentNtpInMilliseconds() override;
36 
37  private:
38   TimeDelta Drift() const;
39 
40   Clock* const clock_;
41   const float drift_;
42   const Timestamp start_time_;
43 };
44 }  // namespace test
45 }  // namespace webrtc
46 
47 #endif  // TEST_DRIFTING_CLOCK_H_
48