summaryrefslogtreecommitdiffstats
path: root/media/cast/test/skewed_tick_clock.h
blob: a5539a34c70d7d5b15f60daac669980466f7b2e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CAST_MEDIA_TEST_SKEWED_TICK_CLOCK_H
#define CAST_MEDIA_TEST_SKEWED_TICK_CLOCK_H

#include "base/time/tick_clock.h"
#include "base/time/time.h"

namespace media {
namespace cast {
namespace test {

// Wraps a base::TickClock, and lets you change the speed and offset
// of time compared to the wrapped clock. See SetSkew for how usage.
class SkewedTickClock : public base::TickClock {
 public:
  // Does not take ownership of |clock_|.
  explicit SkewedTickClock(base::TickClock* clock_);
  // |skew| > 1.0 means clock runs faster.
  // |offset| > 0 means clock returns times from the future.
  // Note, |offset| is cumulative.
  // Also note that changing the skew will never make the clock
  // jump forwards or backwards, only changing the offset will
  // do that.
  void SetSkew(double skew, base::TimeDelta offset);
  base::TimeTicks NowTicks() override;

 private:
  base::TimeTicks SkewTicks(base::TimeTicks now);
  base::TickClock* clock_;  // Not owned.
  double skew_;
  base::TimeTicks last_skew_set_time_;
  base::TimeTicks skew_clock_at_last_set_;

  DISALLOW_COPY_AND_ASSIGN(SkewedTickClock);
};

}  // namespace test
}  // namespace cast
}  // namespace media

#endif  // CAST_MEDIA_TEST_SKEWED_TICK_CLOCK_H