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/filters/renderer_impl.h" | 5 #include "media/filters/renderer_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 error_cb_ = error_cb; | 75 error_cb_ = error_cb; |
76 buffering_state_cb_ = buffering_state_cb; | 76 buffering_state_cb_ = buffering_state_cb; |
77 get_duration_cb_ = get_duration_cb; | 77 get_duration_cb_ = get_duration_cb; |
78 | 78 |
79 init_cb_ = init_cb; | 79 init_cb_ = init_cb; |
80 state_ = STATE_INITIALIZING; | 80 state_ = STATE_INITIALIZING; |
81 InitializeAudioRenderer(); | 81 InitializeAudioRenderer(); |
82 } | 82 } |
83 | 83 |
84 void RendererImpl::Flush(const base::Closure& flush_cb) { | 84 void RendererImpl::Flush(const base::Closure& flush_cb) { |
85 DVLOG(2) << __FUNCTION__; | 85 DVLOG(1) << __FUNCTION__; |
86 DCHECK(task_runner_->BelongsToCurrentThread()); | 86 DCHECK(task_runner_->BelongsToCurrentThread()); |
87 DCHECK_EQ(state_, STATE_PLAYING) << state_; | 87 DCHECK_EQ(state_, STATE_PLAYING) << state_; |
88 DCHECK(flush_cb_.is_null()); | 88 DCHECK(flush_cb_.is_null()); |
89 | 89 |
90 { | 90 { |
91 base::AutoLock auto_lock(interpolator_lock_); | 91 base::AutoLock auto_lock(interpolator_lock_); |
92 PauseClockAndStopTicking_Locked(); | 92 PauseClockAndStopTicking_Locked(); |
93 } | 93 } |
94 | 94 |
95 flush_cb_ = flush_cb; | 95 flush_cb_ = flush_cb; |
96 state_ = STATE_FLUSHING; | 96 state_ = STATE_FLUSHING; |
97 FlushAudioRenderer(); | 97 FlushAudioRenderer(); |
98 } | 98 } |
99 | 99 |
100 void RendererImpl::StartPlayingFrom(base::TimeDelta time) { | 100 void RendererImpl::StartPlayingFrom(base::TimeDelta time) { |
101 DVLOG(2) << __FUNCTION__; | 101 DVLOG(1) << __FUNCTION__; |
102 DCHECK(task_runner_->BelongsToCurrentThread()); | 102 DCHECK(task_runner_->BelongsToCurrentThread()); |
103 DCHECK_EQ(state_, STATE_PLAYING) << state_; | 103 DCHECK_EQ(state_, STATE_PLAYING) << state_; |
104 | 104 |
105 { | 105 { |
106 base::AutoLock auto_lock(interpolator_lock_); | 106 base::AutoLock auto_lock(interpolator_lock_); |
107 interpolator_->SetBounds(time, time); | 107 interpolator_->SetBounds(time, time); |
108 } | 108 } |
109 | 109 |
110 if (time_source_) | 110 if (time_source_) |
111 time_source_->SetMediaTime(time); | 111 time_source_->SetMediaTime(time); |
112 if (audio_renderer_) | 112 if (audio_renderer_) |
113 audio_renderer_->StartPlaying(); | 113 audio_renderer_->StartPlaying(); |
114 if (video_renderer_) | 114 if (video_renderer_) |
115 video_renderer_->StartPlaying(); | 115 video_renderer_->StartPlaying(); |
116 } | 116 } |
117 | 117 |
118 void RendererImpl::SetPlaybackRate(float playback_rate) { | 118 void RendererImpl::SetPlaybackRate(float playback_rate) { |
119 DVLOG(2) << __FUNCTION__ << "(" << playback_rate << ")"; | 119 DVLOG(1) << __FUNCTION__ << "(" << playback_rate << ")"; |
120 DCHECK(task_runner_->BelongsToCurrentThread()); | 120 DCHECK(task_runner_->BelongsToCurrentThread()); |
121 | 121 |
122 // Playback rate changes are only carried out while playing. | 122 // Playback rate changes are only carried out while playing. |
123 if (state_ != STATE_PLAYING) | 123 if (state_ != STATE_PLAYING) |
124 return; | 124 return; |
125 | 125 |
126 { | 126 { |
127 base::AutoLock auto_lock(interpolator_lock_); | 127 base::AutoLock auto_lock(interpolator_lock_); |
128 interpolator_->SetPlaybackRate(playback_rate); | 128 interpolator_->SetPlaybackRate(playback_rate); |
129 } | 129 } |
(...skipping 29 matching lines...) Expand all Loading... |
159 | 159 |
160 void RendererImpl::SetCdm(MediaKeys* cdm) { | 160 void RendererImpl::SetCdm(MediaKeys* cdm) { |
161 DVLOG(1) << __FUNCTION__; | 161 DVLOG(1) << __FUNCTION__; |
162 DCHECK(task_runner_->BelongsToCurrentThread()); | 162 DCHECK(task_runner_->BelongsToCurrentThread()); |
163 // TODO(xhwang): Explore to possibility to move CDM setting from | 163 // TODO(xhwang): Explore to possibility to move CDM setting from |
164 // WebMediaPlayerImpl to this class. See http://crbug.com/401264 | 164 // WebMediaPlayerImpl to this class. See http://crbug.com/401264 |
165 NOTREACHED(); | 165 NOTREACHED(); |
166 } | 166 } |
167 | 167 |
168 void RendererImpl::DisableUnderflowForTesting() { | 168 void RendererImpl::DisableUnderflowForTesting() { |
169 DVLOG(2) << __FUNCTION__; | 169 DVLOG(1) << __FUNCTION__; |
170 DCHECK(task_runner_->BelongsToCurrentThread()); | 170 DCHECK(task_runner_->BelongsToCurrentThread()); |
171 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 171 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
172 | 172 |
173 underflow_disabled_for_testing_ = true; | 173 underflow_disabled_for_testing_ = true; |
174 } | 174 } |
175 | 175 |
176 void RendererImpl::SetTimeDeltaInterpolatorForTesting( | 176 void RendererImpl::SetTimeDeltaInterpolatorForTesting( |
177 TimeDeltaInterpolator* interpolator) { | 177 TimeDeltaInterpolator* interpolator) { |
178 DVLOG(2) << __FUNCTION__; | 178 DVLOG(1) << __FUNCTION__; |
179 DCHECK(task_runner_->BelongsToCurrentThread()); | 179 DCHECK(task_runner_->BelongsToCurrentThread()); |
180 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 180 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
181 | 181 |
182 interpolator_.reset(interpolator); | 182 interpolator_.reset(interpolator); |
183 } | 183 } |
184 | 184 |
185 base::TimeDelta RendererImpl::GetMediaDuration() { | 185 base::TimeDelta RendererImpl::GetMediaDuration() { |
186 DCHECK(task_runner_->BelongsToCurrentThread()); | 186 DCHECK(task_runner_->BelongsToCurrentThread()); |
187 return get_duration_cb_.Run(); | 187 return get_duration_cb_.Run(); |
188 } | 188 } |
189 | 189 |
190 void RendererImpl::InitializeAudioRenderer() { | 190 void RendererImpl::InitializeAudioRenderer() { |
191 DVLOG(2) << __FUNCTION__; | 191 DVLOG(1) << __FUNCTION__; |
192 DCHECK(task_runner_->BelongsToCurrentThread()); | 192 DCHECK(task_runner_->BelongsToCurrentThread()); |
193 DCHECK_EQ(state_, STATE_INITIALIZING) << state_; | 193 DCHECK_EQ(state_, STATE_INITIALIZING) << state_; |
194 DCHECK(!init_cb_.is_null()); | 194 DCHECK(!init_cb_.is_null()); |
195 | 195 |
196 PipelineStatusCB done_cb = | 196 PipelineStatusCB done_cb = |
197 base::Bind(&RendererImpl::OnAudioRendererInitializeDone, weak_this_); | 197 base::Bind(&RendererImpl::OnAudioRendererInitializeDone, weak_this_); |
198 | 198 |
199 if (!demuxer_->GetStream(DemuxerStream::AUDIO)) { | 199 if (!demuxer_->GetStream(DemuxerStream::AUDIO)) { |
200 audio_renderer_.reset(); | 200 audio_renderer_.reset(); |
201 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); | 201 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); |
202 return; | 202 return; |
203 } | 203 } |
204 | 204 |
205 audio_renderer_->Initialize( | 205 audio_renderer_->Initialize( |
206 demuxer_->GetStream(DemuxerStream::AUDIO), | 206 demuxer_->GetStream(DemuxerStream::AUDIO), |
207 done_cb, | 207 done_cb, |
208 base::Bind(&RendererImpl::OnUpdateStatistics, weak_this_), | 208 base::Bind(&RendererImpl::OnUpdateStatistics, weak_this_), |
209 base::Bind(&RendererImpl::OnAudioTimeUpdate, weak_this_), | 209 base::Bind(&RendererImpl::OnAudioTimeUpdate, weak_this_), |
210 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, | 210 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, |
211 &audio_buffering_state_), | 211 &audio_buffering_state_), |
212 base::Bind(&RendererImpl::OnAudioRendererEnded, weak_this_), | 212 base::Bind(&RendererImpl::OnAudioRendererEnded, weak_this_), |
213 base::Bind(&RendererImpl::OnError, weak_this_)); | 213 base::Bind(&RendererImpl::OnError, weak_this_)); |
214 } | 214 } |
215 | 215 |
216 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) { | 216 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) { |
217 DVLOG(2) << __FUNCTION__ << ": " << status; | 217 DVLOG(1) << __FUNCTION__ << ": " << status; |
218 DCHECK(task_runner_->BelongsToCurrentThread()); | 218 DCHECK(task_runner_->BelongsToCurrentThread()); |
219 DCHECK_EQ(state_, STATE_INITIALIZING) << state_; | 219 DCHECK_EQ(state_, STATE_INITIALIZING) << state_; |
220 DCHECK(!init_cb_.is_null()); | 220 DCHECK(!init_cb_.is_null()); |
221 | 221 |
222 if (status != PIPELINE_OK) { | 222 if (status != PIPELINE_OK) { |
223 audio_renderer_.reset(); | 223 audio_renderer_.reset(); |
224 state_ = STATE_ERROR; | 224 state_ = STATE_ERROR; |
225 base::ResetAndReturn(&init_cb_).Run(status); | 225 base::ResetAndReturn(&init_cb_).Run(status); |
226 return; | 226 return; |
227 } | 227 } |
228 | 228 |
229 if (audio_renderer_) | 229 if (audio_renderer_) |
230 time_source_ = audio_renderer_->GetTimeSource(); | 230 time_source_ = audio_renderer_->GetTimeSource(); |
231 | 231 |
232 InitializeVideoRenderer(); | 232 InitializeVideoRenderer(); |
233 } | 233 } |
234 | 234 |
235 void RendererImpl::InitializeVideoRenderer() { | 235 void RendererImpl::InitializeVideoRenderer() { |
236 DVLOG(2) << __FUNCTION__; | 236 DVLOG(1) << __FUNCTION__; |
237 DCHECK(task_runner_->BelongsToCurrentThread()); | 237 DCHECK(task_runner_->BelongsToCurrentThread()); |
238 DCHECK_EQ(state_, STATE_INITIALIZING) << state_; | 238 DCHECK_EQ(state_, STATE_INITIALIZING) << state_; |
239 DCHECK(!init_cb_.is_null()); | 239 DCHECK(!init_cb_.is_null()); |
240 | 240 |
241 PipelineStatusCB done_cb = | 241 PipelineStatusCB done_cb = |
242 base::Bind(&RendererImpl::OnVideoRendererInitializeDone, weak_this_); | 242 base::Bind(&RendererImpl::OnVideoRendererInitializeDone, weak_this_); |
243 | 243 |
244 if (!demuxer_->GetStream(DemuxerStream::VIDEO)) { | 244 if (!demuxer_->GetStream(DemuxerStream::VIDEO)) { |
245 video_renderer_.reset(); | 245 video_renderer_.reset(); |
246 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); | 246 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); |
247 return; | 247 return; |
248 } | 248 } |
249 | 249 |
250 video_renderer_->Initialize( | 250 video_renderer_->Initialize( |
251 demuxer_->GetStream(DemuxerStream::VIDEO), | 251 demuxer_->GetStream(DemuxerStream::VIDEO), |
252 demuxer_->GetLiveness() == Demuxer::LIVENESS_LIVE, | 252 demuxer_->GetLiveness() == Demuxer::LIVENESS_LIVE, |
253 done_cb, | 253 done_cb, |
254 base::Bind(&RendererImpl::OnUpdateStatistics, weak_this_), | 254 base::Bind(&RendererImpl::OnUpdateStatistics, weak_this_), |
255 base::Bind(&RendererImpl::OnVideoTimeUpdate, weak_this_), | 255 base::Bind(&RendererImpl::OnVideoTimeUpdate, weak_this_), |
256 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, | 256 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, |
257 &video_buffering_state_), | 257 &video_buffering_state_), |
258 base::Bind(&RendererImpl::OnVideoRendererEnded, weak_this_), | 258 base::Bind(&RendererImpl::OnVideoRendererEnded, weak_this_), |
259 base::Bind(&RendererImpl::OnError, weak_this_), | 259 base::Bind(&RendererImpl::OnError, weak_this_), |
260 base::Bind(&RendererImpl::GetMediaTime, base::Unretained(this)), | 260 base::Bind(&RendererImpl::GetMediaTime, base::Unretained(this)), |
261 base::Bind(&RendererImpl::GetMediaDuration, base::Unretained(this))); | 261 base::Bind(&RendererImpl::GetMediaDuration, base::Unretained(this))); |
262 } | 262 } |
263 | 263 |
264 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) { | 264 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) { |
265 DVLOG(2) << __FUNCTION__ << ": " << status; | 265 DVLOG(1) << __FUNCTION__ << ": " << status; |
266 DCHECK(task_runner_->BelongsToCurrentThread()); | 266 DCHECK(task_runner_->BelongsToCurrentThread()); |
267 DCHECK_EQ(state_, STATE_INITIALIZING) << state_; | 267 DCHECK_EQ(state_, STATE_INITIALIZING) << state_; |
268 DCHECK(!init_cb_.is_null()); | 268 DCHECK(!init_cb_.is_null()); |
269 | 269 |
270 if (status != PIPELINE_OK) { | 270 if (status != PIPELINE_OK) { |
271 audio_renderer_.reset(); | 271 audio_renderer_.reset(); |
272 video_renderer_.reset(); | 272 video_renderer_.reset(); |
273 state_ = STATE_ERROR; | 273 state_ = STATE_ERROR; |
274 base::ResetAndReturn(&init_cb_).Run(status); | 274 base::ResetAndReturn(&init_cb_).Run(status); |
275 return; | 275 return; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 DCHECK(!flush_cb_.is_null()); | 340 DCHECK(!flush_cb_.is_null()); |
341 | 341 |
342 DCHECK_EQ(video_buffering_state_, BUFFERING_HAVE_NOTHING); | 342 DCHECK_EQ(video_buffering_state_, BUFFERING_HAVE_NOTHING); |
343 video_ended_ = false; | 343 video_ended_ = false; |
344 state_ = STATE_PLAYING; | 344 state_ = STATE_PLAYING; |
345 base::ResetAndReturn(&flush_cb_).Run(); | 345 base::ResetAndReturn(&flush_cb_).Run(); |
346 } | 346 } |
347 | 347 |
348 void RendererImpl::OnAudioTimeUpdate(base::TimeDelta time, | 348 void RendererImpl::OnAudioTimeUpdate(base::TimeDelta time, |
349 base::TimeDelta max_time) { | 349 base::TimeDelta max_time) { |
350 DVLOG(3) << __FUNCTION__ << "(" << time.InMilliseconds() | 350 DVLOG(2) << __FUNCTION__ << "(" << time.InMilliseconds() |
351 << ", " << max_time.InMilliseconds() << ")"; | 351 << ", " << max_time.InMilliseconds() << ")"; |
352 DCHECK(task_runner_->BelongsToCurrentThread()); | 352 DCHECK(task_runner_->BelongsToCurrentThread()); |
353 DCHECK_LE(time.InMicroseconds(), max_time.InMicroseconds()); | 353 DCHECK_LE(time.InMicroseconds(), max_time.InMicroseconds()); |
354 | 354 |
355 base::AutoLock auto_lock(interpolator_lock_); | 355 base::AutoLock auto_lock(interpolator_lock_); |
356 | 356 |
357 if (interpolation_state_ == INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE && | 357 if (interpolation_state_ == INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE && |
358 time < interpolator_->GetInterpolatedTime()) { | 358 time < interpolator_->GetInterpolatedTime()) { |
359 return; | 359 return; |
360 } | 360 } |
361 | 361 |
362 if (state_ == STATE_FLUSHING) | 362 if (state_ == STATE_FLUSHING) |
363 return; | 363 return; |
364 | 364 |
365 interpolator_->SetBounds(time, max_time); | 365 interpolator_->SetBounds(time, max_time); |
366 StartClockIfWaitingForTimeUpdate_Locked(); | 366 StartClockIfWaitingForTimeUpdate_Locked(); |
367 } | 367 } |
368 | 368 |
369 void RendererImpl::OnVideoTimeUpdate(base::TimeDelta max_time) { | 369 void RendererImpl::OnVideoTimeUpdate(base::TimeDelta max_time) { |
370 DVLOG(3) << __FUNCTION__ << "(" << max_time.InMilliseconds() << ")"; | 370 DVLOG(2) << __FUNCTION__ << "(" << max_time.InMilliseconds() << ")"; |
371 DCHECK(task_runner_->BelongsToCurrentThread()); | 371 DCHECK(task_runner_->BelongsToCurrentThread()); |
372 | 372 |
373 if (audio_renderer_) | 373 if (audio_renderer_) |
374 return; | 374 return; |
375 | 375 |
376 if (state_ == STATE_FLUSHING) | 376 if (state_ == STATE_FLUSHING) |
377 return; | 377 return; |
378 | 378 |
379 base::AutoLock auto_lock(interpolator_lock_); | 379 base::AutoLock auto_lock(interpolator_lock_); |
380 DCHECK_NE(interpolation_state_, INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE); | 380 DCHECK_NE(interpolation_state_, INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE); |
381 interpolator_->SetUpperBound(max_time); | 381 interpolator_->SetUpperBound(max_time); |
382 } | 382 } |
383 | 383 |
384 void RendererImpl::OnUpdateStatistics(const PipelineStatistics& stats) { | 384 void RendererImpl::OnUpdateStatistics(const PipelineStatistics& stats) { |
385 DCHECK(task_runner_->BelongsToCurrentThread()); | 385 DCHECK(task_runner_->BelongsToCurrentThread()); |
386 statistics_cb_.Run(stats); | 386 statistics_cb_.Run(stats); |
387 } | 387 } |
388 | 388 |
389 void RendererImpl::OnBufferingStateChanged(BufferingState* buffering_state, | 389 void RendererImpl::OnBufferingStateChanged(BufferingState* buffering_state, |
390 BufferingState new_buffering_state) { | 390 BufferingState new_buffering_state) { |
391 DVLOG(2) << __FUNCTION__ << "(" << *buffering_state << ", " | 391 DVLOG(1) << __FUNCTION__ << "(" << *buffering_state << ", " |
392 << new_buffering_state << ") " | 392 << new_buffering_state << ") " |
393 << (buffering_state == &audio_buffering_state_ ? "audio" : "video"); | 393 << (buffering_state == &audio_buffering_state_ ? "audio" : "video"); |
394 DCHECK(task_runner_->BelongsToCurrentThread()); | 394 DCHECK(task_runner_->BelongsToCurrentThread()); |
395 bool was_waiting_for_enough_data = WaitingForEnoughData(); | 395 bool was_waiting_for_enough_data = WaitingForEnoughData(); |
396 | 396 |
397 *buffering_state = new_buffering_state; | 397 *buffering_state = new_buffering_state; |
398 | 398 |
399 // Disable underflow by ignoring updates that renderers have ran out of data. | 399 // Disable underflow by ignoring updates that renderers have ran out of data. |
400 if (state_ == STATE_PLAYING && underflow_disabled_for_testing_ && | 400 if (state_ == STATE_PLAYING && underflow_disabled_for_testing_ && |
401 interpolation_state_ != INTERPOLATION_STOPPED) { | 401 interpolation_state_ != INTERPOLATION_STOPPED) { |
402 DVLOG(2) << "Update ignored because underflow is disabled for testing."; | 402 DVLOG(1) << "Update ignored because underflow is disabled for testing."; |
403 return; | 403 return; |
404 } | 404 } |
405 | 405 |
406 // Renderer underflowed. | 406 // Renderer underflowed. |
407 if (!was_waiting_for_enough_data && WaitingForEnoughData()) { | 407 if (!was_waiting_for_enough_data && WaitingForEnoughData()) { |
408 PausePlayback(); | 408 PausePlayback(); |
409 | 409 |
410 // TODO(scherkus): Fire BUFFERING_HAVE_NOTHING callback to alert clients of | 410 // TODO(scherkus): Fire BUFFERING_HAVE_NOTHING callback to alert clients of |
411 // underflow state http://crbug.com/144683 | 411 // underflow state http://crbug.com/144683 |
412 return; | 412 return; |
(...skipping 12 matching lines...) Expand all Loading... |
425 if (state_ != STATE_PLAYING) | 425 if (state_ != STATE_PLAYING) |
426 return false; | 426 return false; |
427 if (audio_renderer_ && audio_buffering_state_ != BUFFERING_HAVE_ENOUGH) | 427 if (audio_renderer_ && audio_buffering_state_ != BUFFERING_HAVE_ENOUGH) |
428 return true; | 428 return true; |
429 if (video_renderer_ && video_buffering_state_ != BUFFERING_HAVE_ENOUGH) | 429 if (video_renderer_ && video_buffering_state_ != BUFFERING_HAVE_ENOUGH) |
430 return true; | 430 return true; |
431 return false; | 431 return false; |
432 } | 432 } |
433 | 433 |
434 void RendererImpl::PausePlayback() { | 434 void RendererImpl::PausePlayback() { |
435 DVLOG(2) << __FUNCTION__; | 435 DVLOG(1) << __FUNCTION__; |
436 DCHECK(task_runner_->BelongsToCurrentThread()); | 436 DCHECK(task_runner_->BelongsToCurrentThread()); |
437 DCHECK_EQ(state_, STATE_PLAYING); | 437 DCHECK_EQ(state_, STATE_PLAYING); |
438 DCHECK(WaitingForEnoughData()); | 438 DCHECK(WaitingForEnoughData()); |
439 | 439 |
440 base::AutoLock auto_lock(interpolator_lock_); | 440 base::AutoLock auto_lock(interpolator_lock_); |
441 PauseClockAndStopTicking_Locked(); | 441 PauseClockAndStopTicking_Locked(); |
442 } | 442 } |
443 | 443 |
444 void RendererImpl::StartPlayback() { | 444 void RendererImpl::StartPlayback() { |
445 DVLOG(2) << __FUNCTION__; | 445 DVLOG(1) << __FUNCTION__; |
446 DCHECK(task_runner_->BelongsToCurrentThread()); | 446 DCHECK(task_runner_->BelongsToCurrentThread()); |
447 DCHECK_EQ(state_, STATE_PLAYING); | 447 DCHECK_EQ(state_, STATE_PLAYING); |
448 DCHECK_EQ(interpolation_state_, INTERPOLATION_STOPPED); | 448 DCHECK_EQ(interpolation_state_, INTERPOLATION_STOPPED); |
449 DCHECK(!WaitingForEnoughData()); | 449 DCHECK(!WaitingForEnoughData()); |
450 | 450 |
451 if (time_source_) { | 451 if (time_source_) { |
452 // We use audio stream to update the interpolator. So if there is such a | 452 // We use audio stream to update the interpolator. So if there is such a |
453 // stream, we pause the interpolator until we receive a valid time update. | 453 // stream, we pause the interpolator until we receive a valid time update. |
454 base::AutoLock auto_lock(interpolator_lock_); | 454 base::AutoLock auto_lock(interpolator_lock_); |
455 interpolation_state_ = INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE; | 455 interpolation_state_ = INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE; |
456 time_source_->StartTicking(); | 456 time_source_->StartTicking(); |
457 } else { | 457 } else { |
458 base::TimeDelta duration = get_duration_cb_.Run(); | 458 base::TimeDelta duration = get_duration_cb_.Run(); |
459 base::AutoLock auto_lock(interpolator_lock_); | 459 base::AutoLock auto_lock(interpolator_lock_); |
460 interpolation_state_ = INTERPOLATION_STARTED; | 460 interpolation_state_ = INTERPOLATION_STARTED; |
461 interpolator_->SetUpperBound(duration); | 461 interpolator_->SetUpperBound(duration); |
462 interpolator_->StartInterpolating(); | 462 interpolator_->StartInterpolating(); |
463 } | 463 } |
464 } | 464 } |
465 | 465 |
466 void RendererImpl::PauseClockAndStopTicking_Locked() { | 466 void RendererImpl::PauseClockAndStopTicking_Locked() { |
467 DVLOG(2) << __FUNCTION__; | 467 DVLOG(1) << __FUNCTION__; |
468 interpolator_lock_.AssertAcquired(); | 468 interpolator_lock_.AssertAcquired(); |
469 switch (interpolation_state_) { | 469 switch (interpolation_state_) { |
470 case INTERPOLATION_STOPPED: | 470 case INTERPOLATION_STOPPED: |
471 return; | 471 return; |
472 | 472 |
473 case INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE: | 473 case INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE: |
474 time_source_->StopTicking(); | 474 time_source_->StopTicking(); |
475 break; | 475 break; |
476 | 476 |
477 case INTERPOLATION_STARTED: | 477 case INTERPOLATION_STARTED: |
478 if (time_source_) | 478 if (time_source_) |
479 time_source_->StopTicking(); | 479 time_source_->StopTicking(); |
480 interpolator_->StopInterpolating(); | 480 interpolator_->StopInterpolating(); |
481 break; | 481 break; |
482 } | 482 } |
483 | 483 |
484 interpolation_state_ = INTERPOLATION_STOPPED; | 484 interpolation_state_ = INTERPOLATION_STOPPED; |
485 } | 485 } |
486 | 486 |
487 void RendererImpl::StartClockIfWaitingForTimeUpdate_Locked() { | 487 void RendererImpl::StartClockIfWaitingForTimeUpdate_Locked() { |
488 interpolator_lock_.AssertAcquired(); | 488 interpolator_lock_.AssertAcquired(); |
489 if (interpolation_state_ != INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE) | 489 if (interpolation_state_ != INTERPOLATION_WAITING_FOR_AUDIO_TIME_UPDATE) |
490 return; | 490 return; |
491 | 491 |
492 interpolation_state_ = INTERPOLATION_STARTED; | 492 interpolation_state_ = INTERPOLATION_STARTED; |
493 interpolator_->StartInterpolating(); | 493 interpolator_->StartInterpolating(); |
494 } | 494 } |
495 | 495 |
496 void RendererImpl::OnAudioRendererEnded() { | 496 void RendererImpl::OnAudioRendererEnded() { |
497 DVLOG(2) << __FUNCTION__; | 497 DVLOG(1) << __FUNCTION__; |
498 DCHECK(task_runner_->BelongsToCurrentThread()); | 498 DCHECK(task_runner_->BelongsToCurrentThread()); |
499 | 499 |
500 if (state_ != STATE_PLAYING) | 500 if (state_ != STATE_PLAYING) |
501 return; | 501 return; |
502 | 502 |
503 DCHECK(!audio_ended_); | 503 DCHECK(!audio_ended_); |
504 audio_ended_ = true; | 504 audio_ended_ = true; |
505 | 505 |
506 // Start clock since there is no more audio to trigger clock updates. | 506 // Start clock since there is no more audio to trigger clock updates. |
507 { | 507 { |
508 base::TimeDelta duration = get_duration_cb_.Run(); | 508 base::TimeDelta duration = get_duration_cb_.Run(); |
509 base::AutoLock auto_lock(interpolator_lock_); | 509 base::AutoLock auto_lock(interpolator_lock_); |
510 interpolator_->SetUpperBound(duration); | 510 interpolator_->SetUpperBound(duration); |
511 StartClockIfWaitingForTimeUpdate_Locked(); | 511 StartClockIfWaitingForTimeUpdate_Locked(); |
512 } | 512 } |
513 | 513 |
514 RunEndedCallbackIfNeeded(); | 514 RunEndedCallbackIfNeeded(); |
515 } | 515 } |
516 | 516 |
517 void RendererImpl::OnVideoRendererEnded() { | 517 void RendererImpl::OnVideoRendererEnded() { |
518 DVLOG(2) << __FUNCTION__; | 518 DVLOG(1) << __FUNCTION__; |
519 DCHECK(task_runner_->BelongsToCurrentThread()); | 519 DCHECK(task_runner_->BelongsToCurrentThread()); |
520 | 520 |
521 if (state_ != STATE_PLAYING) | 521 if (state_ != STATE_PLAYING) |
522 return; | 522 return; |
523 | 523 |
524 DCHECK(!video_ended_); | 524 DCHECK(!video_ended_); |
525 video_ended_ = true; | 525 video_ended_ = true; |
526 | 526 |
527 RunEndedCallbackIfNeeded(); | 527 RunEndedCallbackIfNeeded(); |
528 } | 528 } |
529 | 529 |
530 void RendererImpl::RunEndedCallbackIfNeeded() { | 530 void RendererImpl::RunEndedCallbackIfNeeded() { |
531 DVLOG(2) << __FUNCTION__; | 531 DVLOG(1) << __FUNCTION__; |
532 DCHECK(task_runner_->BelongsToCurrentThread()); | 532 DCHECK(task_runner_->BelongsToCurrentThread()); |
533 | 533 |
534 if (audio_renderer_ && !audio_ended_) | 534 if (audio_renderer_ && !audio_ended_) |
535 return; | 535 return; |
536 | 536 |
537 if (video_renderer_ && !video_ended_) | 537 if (video_renderer_ && !video_ended_) |
538 return; | 538 return; |
539 | 539 |
540 { | 540 { |
541 base::TimeDelta duration = get_duration_cb_.Run(); | 541 base::TimeDelta duration = get_duration_cb_.Run(); |
542 base::AutoLock auto_lock(interpolator_lock_); | 542 base::AutoLock auto_lock(interpolator_lock_); |
543 PauseClockAndStopTicking_Locked(); | 543 PauseClockAndStopTicking_Locked(); |
544 interpolator_->SetBounds(duration, duration); | 544 interpolator_->SetBounds(duration, duration); |
545 } | 545 } |
546 | 546 |
547 ended_cb_.Run(); | 547 ended_cb_.Run(); |
548 } | 548 } |
549 | 549 |
550 void RendererImpl::OnError(PipelineStatus error) { | 550 void RendererImpl::OnError(PipelineStatus error) { |
551 DVLOG(2) << __FUNCTION__; | 551 DVLOG(1) << __FUNCTION__ << "(" << error << ")"; |
552 DCHECK(task_runner_->BelongsToCurrentThread()); | 552 DCHECK(task_runner_->BelongsToCurrentThread()); |
553 DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!"; | 553 DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!"; |
554 | 554 |
555 state_ = STATE_ERROR; | 555 state_ = STATE_ERROR; |
556 | 556 |
557 // Pipeline will destroy |this| as the result of error. | 557 // Pipeline will destroy |this| as the result of error. |
558 base::ResetAndReturn(&error_cb_).Run(error); | 558 base::ResetAndReturn(&error_cb_).Run(error); |
559 | 559 |
560 FireAllPendingCallbacks(); | 560 FireAllPendingCallbacks(); |
561 } | 561 } |
562 | 562 |
563 void RendererImpl::FireAllPendingCallbacks() { | 563 void RendererImpl::FireAllPendingCallbacks() { |
564 DCHECK(task_runner_->BelongsToCurrentThread()); | 564 DCHECK(task_runner_->BelongsToCurrentThread()); |
565 | 565 |
566 if (!init_cb_.is_null()) | 566 if (!init_cb_.is_null()) |
567 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); | 567 base::ResetAndReturn(&init_cb_).Run(PIPELINE_ERROR_ABORT); |
568 | 568 |
569 if (!flush_cb_.is_null()) | 569 if (!flush_cb_.is_null()) |
570 base::ResetAndReturn(&flush_cb_).Run(); | 570 base::ResetAndReturn(&flush_cb_).Run(); |
571 } | 571 } |
572 | 572 |
573 } // namespace media | 573 } // namespace media |
OLD | NEW |