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/renderers/audio_renderer_impl.h" | 5 #include "media/renderers/audio_renderer_impl.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 DCHECK_EQ(state_, kFlushed); | 174 DCHECK_EQ(state_, kFlushed); |
175 | 175 |
176 start_timestamp_ = time; | 176 start_timestamp_ = time; |
177 ended_timestamp_ = kInfiniteDuration; | 177 ended_timestamp_ = kInfiniteDuration; |
178 last_render_time_ = stop_rendering_time_ = base::TimeTicks(); | 178 last_render_time_ = stop_rendering_time_ = base::TimeTicks(); |
179 first_packet_timestamp_ = kNoTimestamp; | 179 first_packet_timestamp_ = kNoTimestamp; |
180 last_media_timestamp_ = base::TimeDelta(); | 180 last_media_timestamp_ = base::TimeDelta(); |
181 audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate())); | 181 audio_clock_.reset(new AudioClock(time, audio_parameters_.sample_rate())); |
182 } | 182 } |
183 | 183 |
184 base::TimeDelta AudioRendererImpl::CurrentMediaTime() { | 184 base::TimeDelta AudioRendererImpl::CurrentMediaTime( |
| 185 base::TimeTicks* reference) { |
185 base::AutoLock auto_lock(lock_); | 186 base::AutoLock auto_lock(lock_); |
186 | 187 |
187 // Return the current time based on the known extents of the rendered audio | 188 // Return the current time based on the known extents of the rendered audio |
188 // data plus an estimate based on the last time those values were calculated. | 189 // data plus an estimate based on the last time those values were calculated. |
| 190 base::TimeTicks now_ticks; |
189 base::TimeDelta current_media_time = audio_clock_->front_timestamp(); | 191 base::TimeDelta current_media_time = audio_clock_->front_timestamp(); |
190 if (!last_render_time_.is_null()) { | 192 if (!last_render_time_.is_null()) { |
191 current_media_time += | 193 now_ticks = tick_clock_->NowTicks(); |
192 (tick_clock_->NowTicks() - last_render_time_) * playback_rate_; | 194 current_media_time += (now_ticks - last_render_time_) * playback_rate_; |
193 if (current_media_time > audio_clock_->back_timestamp()) | 195 if (current_media_time > audio_clock_->back_timestamp()) |
194 current_media_time = audio_clock_->back_timestamp(); | 196 current_media_time = audio_clock_->back_timestamp(); |
195 } | 197 } |
196 | 198 |
197 // Clamp current media time to the last reported value, this prevents higher | 199 // Clamp current media time to the last reported value, this prevents higher |
198 // level clients from seeing time go backwards based on inaccurate or spurious | 200 // level clients from seeing time go backwards based on inaccurate or spurious |
199 // delay values reported to the AudioClock. | 201 // delay values reported to the AudioClock. |
200 // | 202 // |
201 // It is expected that such events are transient and will be recovered as | 203 // It is expected that such events are transient and will be recovered as |
202 // rendering continues over time. | 204 // rendering continues over time. |
203 if (current_media_time < last_media_timestamp_) { | 205 if (current_media_time < last_media_timestamp_) { |
204 DVLOG(2) << __func__ << ": " << last_media_timestamp_ | 206 DVLOG(2) << __func__ << ": " << last_media_timestamp_ |
205 << " (clamped), actual: " << current_media_time; | 207 << " (clamped), actual: " << current_media_time; |
206 return last_media_timestamp_; | 208 current_media_time = last_media_timestamp_; |
| 209 } else { |
| 210 last_media_timestamp_ = current_media_time; |
| 211 } |
| 212 |
| 213 if (reference) { |
| 214 *reference = now_ticks.is_null() ? tick_clock_->NowTicks() : now_ticks; |
207 } | 215 } |
208 | 216 |
209 DVLOG(2) << __func__ << ": " << current_media_time; | 217 DVLOG(2) << __func__ << ": " << current_media_time; |
210 last_media_timestamp_ = current_media_time; | |
211 return current_media_time; | 218 return current_media_time; |
212 } | 219 } |
213 | 220 |
214 bool AudioRendererImpl::GetWallClockTimes( | 221 bool AudioRendererImpl::GetWallClockTimes( |
215 const std::vector<base::TimeDelta>& media_timestamps, | 222 const std::vector<base::TimeDelta>& media_timestamps, |
216 std::vector<base::TimeTicks>* wall_clock_times) { | 223 std::vector<base::TimeTicks>* wall_clock_times) { |
217 base::AutoLock auto_lock(lock_); | 224 base::AutoLock auto_lock(lock_); |
218 DCHECK(wall_clock_times->empty()); | 225 DCHECK(wall_clock_times->empty()); |
219 | 226 |
220 // When playback is paused (rate is zero), assume a rate of 1.0. | 227 // When playback is paused (rate is zero), assume a rate of 1.0. |
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
968 DCHECK_NE(buffering_state_, buffering_state); | 975 DCHECK_NE(buffering_state_, buffering_state); |
969 lock_.AssertAcquired(); | 976 lock_.AssertAcquired(); |
970 buffering_state_ = buffering_state; | 977 buffering_state_ = buffering_state; |
971 | 978 |
972 task_runner_->PostTask( | 979 task_runner_->PostTask( |
973 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, | 980 FROM_HERE, base::Bind(&AudioRendererImpl::OnBufferingStateChange, |
974 weak_factory_.GetWeakPtr(), buffering_state_)); | 981 weak_factory_.GetWeakPtr(), buffering_state_)); |
975 } | 982 } |
976 | 983 |
977 } // namespace media | 984 } // namespace media |
OLD | NEW |