Chromium Code Reviews| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 | 43 |
| 44 RendererImpl::~RendererImpl() { | 44 RendererImpl::~RendererImpl() { |
| 45 DVLOG(1) << __FUNCTION__; | 45 DVLOG(1) << __FUNCTION__; |
| 46 DCHECK(task_runner_->BelongsToCurrentThread()); | 46 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 47 | 47 |
| 48 // Tear down in opposite order of construction as |video_renderer_| can still | 48 // Tear down in opposite order of construction as |video_renderer_| can still |
| 49 // need |time_source_| (which can be |audio_renderer_|) to be alive. | 49 // need |time_source_| (which can be |audio_renderer_|) to be alive. |
| 50 video_renderer_.reset(); | 50 video_renderer_.reset(); |
| 51 audio_renderer_.reset(); | 51 audio_renderer_.reset(); |
| 52 | 52 |
| 53 DCHECK(init_cb_.is_null()); | |
|
xhwang
2015/01/23 00:22:01
hmm, what if Pipeline::StopTask() is called during
DaleCurtis
2015/01/23 20:31:21
Right, this is possible. Changed this to run init_
| |
| 53 FireAllPendingCallbacks(); | 54 FireAllPendingCallbacks(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 void RendererImpl::Initialize(DemuxerStreamProvider* demuxer_stream_provider, | 57 void RendererImpl::Initialize(DemuxerStreamProvider* demuxer_stream_provider, |
| 57 const base::Closure& init_cb, | 58 const PipelineStatusCB& init_cb, |
| 58 const StatisticsCB& statistics_cb, | 59 const StatisticsCB& statistics_cb, |
| 59 const BufferingStateCB& buffering_state_cb, | 60 const BufferingStateCB& buffering_state_cb, |
| 60 const PaintCB& paint_cb, | 61 const PaintCB& paint_cb, |
| 61 const base::Closure& ended_cb, | 62 const base::Closure& ended_cb, |
| 62 const PipelineStatusCB& error_cb) { | 63 const PipelineStatusCB& error_cb) { |
| 63 DVLOG(1) << __FUNCTION__; | 64 DVLOG(1) << __FUNCTION__; |
| 64 DCHECK(task_runner_->BelongsToCurrentThread()); | 65 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 65 DCHECK_EQ(state_, STATE_UNINITIALIZED); | 66 DCHECK_EQ(state_, STATE_UNINITIALIZED); |
| 66 DCHECK(!init_cb.is_null()); | 67 DCHECK(!init_cb.is_null()); |
| 67 DCHECK(!statistics_cb.is_null()); | 68 DCHECK(!statistics_cb.is_null()); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, | 256 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, |
| 256 &audio_buffering_state_), | 257 &audio_buffering_state_), |
| 257 base::Bind(&RendererImpl::OnAudioRendererEnded, weak_this_), | 258 base::Bind(&RendererImpl::OnAudioRendererEnded, weak_this_), |
| 258 base::Bind(&RendererImpl::OnError, weak_this_)); | 259 base::Bind(&RendererImpl::OnError, weak_this_)); |
| 259 } | 260 } |
| 260 | 261 |
| 261 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) { | 262 void RendererImpl::OnAudioRendererInitializeDone(PipelineStatus status) { |
| 262 DVLOG(1) << __FUNCTION__ << ": " << status; | 263 DVLOG(1) << __FUNCTION__ << ": " << status; |
| 263 DCHECK(task_runner_->BelongsToCurrentThread()); | 264 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 264 | 265 |
| 265 if (status != PIPELINE_OK) | |
| 266 OnError(status); | |
|
xhwang
2015/01/23 00:22:01
I agree this is confusing! :)
| |
| 267 | |
| 268 // OnError() may be fired at any time by the renderers, even if they thought | 266 // OnError() may be fired at any time by the renderers, even if they thought |
| 269 // they initialized successfully (due to delayed output device setup). | 267 // they initialized successfully (due to delayed output device setup). |
|
xhwang
2015/01/23 00:22:01
Ouch, this is painful :(
| |
| 270 if (state_ != STATE_INITIALIZING) { | 268 if (state_ != STATE_INITIALIZING) { |
| 269 DCHECK(init_cb_.is_null()); | |
| 271 audio_renderer_.reset(); | 270 audio_renderer_.reset(); |
| 272 return; | 271 return; |
| 273 } | 272 } |
| 274 | 273 |
| 274 if (status != PIPELINE_OK) { | |
| 275 base::ResetAndReturn(&init_cb_).Run(status); | |
| 276 return; | |
| 277 } | |
| 278 | |
| 275 DCHECK(!init_cb_.is_null()); | 279 DCHECK(!init_cb_.is_null()); |
| 276 InitializeVideoRenderer(); | 280 InitializeVideoRenderer(); |
| 277 } | 281 } |
| 278 | 282 |
| 279 void RendererImpl::InitializeVideoRenderer() { | 283 void RendererImpl::InitializeVideoRenderer() { |
| 280 DVLOG(1) << __FUNCTION__; | 284 DVLOG(1) << __FUNCTION__; |
| 281 DCHECK(task_runner_->BelongsToCurrentThread()); | 285 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 282 DCHECK_EQ(state_, STATE_INITIALIZING); | 286 DCHECK_EQ(state_, STATE_INITIALIZING); |
| 283 DCHECK(!init_cb_.is_null()); | 287 DCHECK(!init_cb_.is_null()); |
| 284 | 288 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 301 base::Bind(&RendererImpl::OnVideoRendererEnded, weak_this_), | 305 base::Bind(&RendererImpl::OnVideoRendererEnded, weak_this_), |
| 302 base::Bind(&RendererImpl::OnError, weak_this_), | 306 base::Bind(&RendererImpl::OnError, weak_this_), |
| 303 base::Bind(&RendererImpl::GetMediaTimeForSyncingVideo, | 307 base::Bind(&RendererImpl::GetMediaTimeForSyncingVideo, |
| 304 base::Unretained(this))); | 308 base::Unretained(this))); |
| 305 } | 309 } |
| 306 | 310 |
| 307 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) { | 311 void RendererImpl::OnVideoRendererInitializeDone(PipelineStatus status) { |
| 308 DVLOG(1) << __FUNCTION__ << ": " << status; | 312 DVLOG(1) << __FUNCTION__ << ": " << status; |
| 309 DCHECK(task_runner_->BelongsToCurrentThread()); | 313 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 310 | 314 |
| 311 if (status != PIPELINE_OK) | |
| 312 OnError(status); | |
| 313 | |
| 314 // OnError() may be fired at any time by the renderers, even if they thought | 315 // OnError() may be fired at any time by the renderers, even if they thought |
| 315 // they initialized successfully (due to delayed output device setup). | 316 // they initialized successfully (due to delayed output device setup). |
| 316 if (state_ != STATE_INITIALIZING) { | 317 if (state_ != STATE_INITIALIZING) { |
| 318 DCHECK(init_cb_.is_null()); | |
| 317 audio_renderer_.reset(); | 319 audio_renderer_.reset(); |
| 318 video_renderer_.reset(); | 320 video_renderer_.reset(); |
| 319 return; | 321 return; |
| 320 } | 322 } |
| 321 | 323 |
| 322 DCHECK(!init_cb_.is_null()); | 324 DCHECK(!init_cb_.is_null()); |
| 323 | 325 |
| 326 if (status != PIPELINE_OK) { | |
| 327 base::ResetAndReturn(&init_cb_).Run(status); | |
| 328 return; | |
| 329 } | |
| 330 | |
| 324 if (audio_renderer_) { | 331 if (audio_renderer_) { |
| 325 time_source_ = audio_renderer_->GetTimeSource(); | 332 time_source_ = audio_renderer_->GetTimeSource(); |
| 326 } else { | 333 } else { |
| 327 wall_clock_time_source_.reset(new WallClockTimeSource()); | 334 wall_clock_time_source_.reset(new WallClockTimeSource()); |
| 328 time_source_ = wall_clock_time_source_.get(); | 335 time_source_ = wall_clock_time_source_.get(); |
| 329 } | 336 } |
| 330 | 337 |
| 331 state_ = STATE_PLAYING; | 338 state_ = STATE_PLAYING; |
| 332 DCHECK(time_source_); | 339 DCHECK(time_source_); |
| 333 DCHECK(audio_renderer_ || video_renderer_); | 340 DCHECK(audio_renderer_ || video_renderer_); |
| 334 base::ResetAndReturn(&init_cb_).Run(); | 341 base::ResetAndReturn(&init_cb_).Run(PIPELINE_OK); |
| 335 } | 342 } |
| 336 | 343 |
| 337 void RendererImpl::FlushAudioRenderer() { | 344 void RendererImpl::FlushAudioRenderer() { |
| 338 DVLOG(1) << __FUNCTION__; | 345 DVLOG(1) << __FUNCTION__; |
| 339 DCHECK(task_runner_->BelongsToCurrentThread()); | 346 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 340 DCHECK_EQ(state_, STATE_FLUSHING); | 347 DCHECK_EQ(state_, STATE_FLUSHING); |
| 341 DCHECK(!flush_cb_.is_null()); | 348 DCHECK(!flush_cb_.is_null()); |
| 342 | 349 |
| 343 if (!audio_renderer_) { | 350 if (!audio_renderer_) { |
| 344 OnAudioRendererFlushDone(); | 351 OnAudioRendererFlushDone(); |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 | 549 |
| 543 void RendererImpl::OnError(PipelineStatus error) { | 550 void RendererImpl::OnError(PipelineStatus error) { |
| 544 DVLOG(1) << __FUNCTION__ << "(" << error << ")"; | 551 DVLOG(1) << __FUNCTION__ << "(" << error << ")"; |
| 545 DCHECK(task_runner_->BelongsToCurrentThread()); | 552 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 546 DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!"; | 553 DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!"; |
| 547 | 554 |
| 548 // An error has already been delivered. | 555 // An error has already been delivered. |
| 549 if (state_ == STATE_ERROR) | 556 if (state_ == STATE_ERROR) |
| 550 return; | 557 return; |
| 551 | 558 |
| 559 const State old_state = state_; | |
| 552 state_ = STATE_ERROR; | 560 state_ = STATE_ERROR; |
| 553 | 561 |
| 562 if (old_state == STATE_INITIALIZING) { | |
| 563 base::ResetAndReturn(&init_cb_).Run(error); | |
| 564 return; | |
| 565 } | |
| 566 | |
| 554 // Pipeline will destroy |this| as the result of error. | 567 // Pipeline will destroy |this| as the result of error. |
| 555 base::ResetAndReturn(&error_cb_).Run(error); | 568 base::ResetAndReturn(&error_cb_).Run(error); |
| 556 | |
| 557 FireAllPendingCallbacks(); | 569 FireAllPendingCallbacks(); |
| 558 } | 570 } |
| 559 | 571 |
| 560 void RendererImpl::FireAllPendingCallbacks() { | 572 void RendererImpl::FireAllPendingCallbacks() { |
| 561 DCHECK(task_runner_->BelongsToCurrentThread()); | 573 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 562 | |
| 563 if (!init_cb_.is_null()) | |
| 564 base::ResetAndReturn(&init_cb_).Run(); | |
| 565 | |
| 566 if (!flush_cb_.is_null()) | 574 if (!flush_cb_.is_null()) |
| 567 base::ResetAndReturn(&flush_cb_).Run(); | 575 base::ResetAndReturn(&flush_cb_).Run(); |
| 568 } | 576 } |
| 569 | 577 |
| 570 } // namespace media | 578 } // namespace media |
| OLD | NEW |