OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/clock.h" | 5 #include "media/base/clock.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 Clock::Clock(base::TickClock* clock) : clock_(clock) { | 15 Clock::Clock(base::TickClock* clock) |
| 16 : clock_(clock), |
| 17 playing_(false), |
| 18 underflow_(false), |
| 19 playback_rate_(1.0f), |
| 20 max_time_(kNoTimestamp()), |
| 21 duration_(kNoTimestamp()) { |
16 DCHECK(clock_); | 22 DCHECK(clock_); |
17 Reset(); | |
18 } | 23 } |
19 | 24 |
20 Clock::~Clock() {} | 25 Clock::~Clock() {} |
21 | 26 |
22 bool Clock::IsPlaying() const { | 27 bool Clock::IsPlaying() const { |
23 return playing_; | 28 return playing_; |
24 } | 29 } |
25 | 30 |
26 base::TimeDelta Clock::Play() { | 31 base::TimeDelta Clock::Play() { |
27 DCHECK(!playing_); | 32 DCHECK(!playing_); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 now_us = static_cast<int64>(now_us * playback_rate_); | 101 now_us = static_cast<int64>(now_us * playback_rate_); |
97 return media_time_ + base::TimeDelta::FromMicroseconds(now_us); | 102 return media_time_ + base::TimeDelta::FromMicroseconds(now_us); |
98 } | 103 } |
99 | 104 |
100 base::TimeDelta Clock::ClampToValidTimeRange(base::TimeDelta time) const { | 105 base::TimeDelta Clock::ClampToValidTimeRange(base::TimeDelta time) const { |
101 if (duration_ == kNoTimestamp()) | 106 if (duration_ == kNoTimestamp()) |
102 return base::TimeDelta(); | 107 return base::TimeDelta(); |
103 return std::max(std::min(time, duration_), base::TimeDelta()); | 108 return std::max(std::min(time, duration_), base::TimeDelta()); |
104 } | 109 } |
105 | 110 |
106 void Clock::EndOfStream() { | |
107 Pause(); | |
108 SetTime(Duration(), Duration()); | |
109 } | |
110 | |
111 base::TimeDelta Clock::Duration() const { | 111 base::TimeDelta Clock::Duration() const { |
112 if (duration_ == kNoTimestamp()) | 112 if (duration_ == kNoTimestamp()) |
113 return base::TimeDelta(); | 113 return base::TimeDelta(); |
114 return duration_; | 114 return duration_; |
115 } | 115 } |
116 | 116 |
117 void Clock::UpdateReferencePoints() { | 117 void Clock::UpdateReferencePoints() { |
118 UpdateReferencePoints(Elapsed()); | 118 UpdateReferencePoints(Elapsed()); |
119 } | 119 } |
120 | 120 |
121 void Clock::UpdateReferencePoints(base::TimeDelta current_time) { | 121 void Clock::UpdateReferencePoints(base::TimeDelta current_time) { |
122 media_time_ = ClampToValidTimeRange(current_time); | 122 media_time_ = ClampToValidTimeRange(current_time); |
123 reference_ = clock_->NowTicks(); | 123 reference_ = clock_->NowTicks(); |
124 } | 124 } |
125 | 125 |
126 base::TimeDelta Clock::EstimatedElapsedTime() { | 126 base::TimeDelta Clock::EstimatedElapsedTime() { |
127 return ClampToValidTimeRange(ElapsedViaProvidedTime(clock_->NowTicks())); | 127 return ClampToValidTimeRange(ElapsedViaProvidedTime(clock_->NowTicks())); |
128 } | 128 } |
129 | 129 |
130 void Clock::Reset() { | |
131 playing_ = false; | |
132 playback_rate_ = 1.0f; | |
133 max_time_ = kNoTimestamp(); | |
134 duration_ = kNoTimestamp(); | |
135 media_time_ = base::TimeDelta(); | |
136 reference_ = base::TimeTicks(); | |
137 underflow_ = false; | |
138 } | |
139 | |
140 } // namespace media | 130 } // namespace media |
OLD | NEW |