1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "media/cast/test/skewed_tick_clock.h" 6 7 #include "base/time/time.h" 8 9 namespace media { 10 namespace cast { 11 namespace test { 12 13 SkewedTickClock::SkewedTickClock(base::TickClock* clock) 14 : clock_(clock), 15 skew_(1.0), 16 last_skew_set_time_(clock_->NowTicks()), 17 skew_clock_at_last_set_(last_skew_set_time_) { 18 } 19 20 base::TimeTicks SkewedTickClock::SkewTicks(base::TimeTicks now) { 21 return base::TimeDelta::FromMicroseconds( 22 (now - last_skew_set_time_).InMicroseconds() * skew_) + 23 skew_clock_at_last_set_; 24 } 25 26 void SkewedTickClock::SetSkew(double skew, base::TimeDelta offset) { 27 base::TimeTicks now = clock_->NowTicks(); 28 skew_clock_at_last_set_ = SkewTicks(now) + offset; 29 skew_ = skew; 30 last_skew_set_time_ = now; 31 } 32 33 base::TimeTicks SkewedTickClock::NowTicks() { 34 return SkewTicks(clock_->NowTicks()); 35 } 36 37 } // namespace test 38 } // namespace cast 39 } // namespace media 40