drifting_clock.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #include <stdint.h>
  13. #include "system_wrappers/include/clock.h"
  14. #include "system_wrappers/include/ntp_time.h"
  15. namespace webrtc {
  16. namespace test {
  17. class DriftingClock : public Clock {
  18. public:
  19. static constexpr float kNoDrift = 1.0f;
  20. DriftingClock(Clock* clock, float speed);
  21. static constexpr float PercentsFaster(float percent) {
  22. return 1.0f + percent / 100.0f;
  23. }
  24. static constexpr float PercentsSlower(float percent) {
  25. return 1.0f - percent / 100.0f;
  26. }
  27. Timestamp CurrentTime() override;
  28. NtpTime CurrentNtpTime() override;
  29. int64_t CurrentNtpInMilliseconds() override;
  30. private:
  31. TimeDelta Drift() const;
  32. Clock* const clock_;
  33. const float drift_;
  34. const Timestamp start_time_;
  35. };
  36. } // namespace test
  37. } // namespace webrtc
  38. #endif // TEST_DRIFTING_CLOCK_H_