OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/time_delta_interpolator.h" | 5 #include "media/base/time_delta_interpolator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time/tick_clock.h" | 10 #include "base/time/tick_clock.h" |
11 #include "media/base/buffers.h" | 11 #include "media/base/buffers.h" |
12 | 12 |
13 namespace media { | 13 namespace media { |
14 | 14 |
15 TimeDeltaInterpolator::TimeDeltaInterpolator(base::TickClock* tick_clock) | 15 TimeDeltaInterpolator::TimeDeltaInterpolator(base::TickClock* tick_clock) |
16 : tick_clock_(tick_clock), | 16 : tick_clock_(tick_clock), |
17 interpolating_(false), | 17 interpolating_(false), |
18 upper_bound_(kNoTimestamp()), | 18 upper_bound_(kNoTimestamp()), |
19 playback_rate_(1.0f) { | 19 playback_rate_(1.0) { |
20 DCHECK(tick_clock_); | 20 DCHECK(tick_clock_); |
21 } | 21 } |
22 | 22 |
23 TimeDeltaInterpolator::~TimeDeltaInterpolator() { | 23 TimeDeltaInterpolator::~TimeDeltaInterpolator() { |
24 } | 24 } |
25 | 25 |
26 base::TimeDelta TimeDeltaInterpolator::StartInterpolating() { | 26 base::TimeDelta TimeDeltaInterpolator::StartInterpolating() { |
27 DCHECK(!interpolating_); | 27 DCHECK(!interpolating_); |
28 reference_ = tick_clock_->NowTicks(); | 28 reference_ = tick_clock_->NowTicks(); |
29 interpolating_ = true; | 29 interpolating_ = true; |
30 return lower_bound_; | 30 return lower_bound_; |
31 } | 31 } |
32 | 32 |
33 base::TimeDelta TimeDeltaInterpolator::StopInterpolating() { | 33 base::TimeDelta TimeDeltaInterpolator::StopInterpolating() { |
34 DCHECK(interpolating_); | 34 DCHECK(interpolating_); |
35 lower_bound_ = GetInterpolatedTime(); | 35 lower_bound_ = GetInterpolatedTime(); |
36 interpolating_ = false; | 36 interpolating_ = false; |
37 return lower_bound_; | 37 return lower_bound_; |
38 } | 38 } |
39 | 39 |
40 void TimeDeltaInterpolator::SetPlaybackRate(float playback_rate) { | 40 void TimeDeltaInterpolator::SetPlaybackRate(double playback_rate) { |
41 lower_bound_ = GetInterpolatedTime(); | 41 lower_bound_ = GetInterpolatedTime(); |
42 reference_ = tick_clock_->NowTicks(); | 42 reference_ = tick_clock_->NowTicks(); |
43 playback_rate_ = playback_rate; | 43 playback_rate_ = playback_rate; |
44 } | 44 } |
45 | 45 |
46 void TimeDeltaInterpolator::SetBounds(base::TimeDelta lower_bound, | 46 void TimeDeltaInterpolator::SetBounds(base::TimeDelta lower_bound, |
47 base::TimeDelta upper_bound) { | 47 base::TimeDelta upper_bound) { |
48 DCHECK(lower_bound <= upper_bound); | 48 DCHECK(lower_bound <= upper_bound); |
49 DCHECK(lower_bound != kNoTimestamp()); | 49 DCHECK(lower_bound != kNoTimestamp()); |
50 | 50 |
(...skipping 19 matching lines...) Expand all Loading... |
70 base::TimeDelta interpolated_time = | 70 base::TimeDelta interpolated_time = |
71 lower_bound_ + base::TimeDelta::FromMicroseconds(now_us); | 71 lower_bound_ + base::TimeDelta::FromMicroseconds(now_us); |
72 | 72 |
73 if (upper_bound_ == kNoTimestamp()) | 73 if (upper_bound_ == kNoTimestamp()) |
74 return interpolated_time; | 74 return interpolated_time; |
75 | 75 |
76 return std::min(interpolated_time, upper_bound_); | 76 return std::min(interpolated_time, upper_bound_); |
77 } | 77 } |
78 | 78 |
79 } // namespace media | 79 } // namespace media |
OLD | NEW |