summaryrefslogtreecommitdiffstats
path: root/media/cast/test/skewed_tick_clock.cc
blob: 272c61e6c9882e4e2b75f436f5d544a8685e4c86 (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
// 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.

#include "media/cast/test/skewed_tick_clock.h"

#include "base/time/time.h"

namespace media {
namespace cast {
namespace test {

SkewedTickClock::SkewedTickClock(base::TickClock* clock)
    : clock_(clock),
      skew_(1.0),
      last_skew_set_time_(clock_->NowTicks()),
      skew_clock_at_last_set_(last_skew_set_time_) {
}

base::TimeTicks SkewedTickClock::SkewTicks(base::TimeTicks now) {
  return base::TimeDelta::FromMicroseconds(
      (now - last_skew_set_time_).InMicroseconds() * skew_) +
      skew_clock_at_last_set_;
}

void SkewedTickClock::SetSkew(double skew, base::TimeDelta offset) {
  base::TimeTicks now = clock_->NowTicks();
  skew_clock_at_last_set_ = SkewTicks(now) + offset;
  skew_ = skew;
  last_skew_set_time_ = now;
}

base::TimeTicks SkewedTickClock::NowTicks() {
  return SkewTicks(clock_->NowTicks());
}

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