| Index: chromecast/media/cma/filters/cma_renderer.cc
|
| diff --git a/chromecast/media/cma/filters/cma_renderer.cc b/chromecast/media/cma/filters/cma_renderer.cc
|
| index 600ec5bae6eb48c6a5c96780438250522bcff8d6..d9266f8aeafbbe382311427a377f5b51dc97513b 100644
|
| --- a/chromecast/media/cma/filters/cma_renderer.cc
|
| +++ b/chromecast/media/cma/filters/cma_renderer.cc
|
| @@ -62,12 +62,15 @@ CmaRenderer::CmaRenderer(scoped_ptr<MediaPipeline> media_pipeline)
|
|
|
| CmaRenderer::~CmaRenderer() {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| - FireAllPendingCallbacks();
|
| + if (!init_cb_.is_null())
|
| + base::ResetAndReturn(&init_cb_).Run(::media::PIPELINE_ERROR_ABORT);
|
| + else if (!flush_cb_.is_null())
|
| + base::ResetAndReturn(&flush_cb_).Run();
|
| }
|
|
|
| void CmaRenderer::Initialize(
|
| ::media::DemuxerStreamProvider* demuxer_stream_provider,
|
| - const base::Closure& init_cb,
|
| + const ::media::PipelineStatusCB& init_cb,
|
| const ::media::StatisticsCB& statistics_cb,
|
| const ::media::BufferingStateCB& buffering_state_cb,
|
| const PaintCB& paint_cb,
|
| @@ -259,12 +262,16 @@ void CmaRenderer::InitializeAudioPipeline() {
|
| void CmaRenderer::OnAudioPipelineInitializeDone(
|
| ::media::PipelineStatus status) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| +
|
| + // OnError() may be fired at any time, even before initialization is complete.
|
| + if (state_ == kError)
|
| + return;
|
| +
|
| DCHECK_EQ(state_, kUninitialized) << state_;
|
| DCHECK(!init_cb_.is_null());
|
| -
|
| if (status != ::media::PIPELINE_OK) {
|
| has_audio_ = false;
|
| - OnError(status);
|
| + base::ResetAndReturn(&init_cb_).Run(status);
|
| return;
|
| }
|
|
|
| @@ -321,17 +328,21 @@ void CmaRenderer::InitializeVideoPipeline() {
|
| void CmaRenderer::OnVideoPipelineInitializeDone(
|
| ::media::PipelineStatus status) {
|
| DCHECK(thread_checker_.CalledOnValidThread());
|
| +
|
| + // OnError() may be fired at any time, even before initialization is complete.
|
| + if (state_ == kError)
|
| + return;
|
| +
|
| DCHECK_EQ(state_, kUninitialized) << state_;
|
| DCHECK(!init_cb_.is_null());
|
| -
|
| if (status != ::media::PIPELINE_OK) {
|
| has_video_ = false;
|
| - OnError(status);
|
| + base::ResetAndReturn(&init_cb_).Run(status);
|
| return;
|
| }
|
|
|
| CompleteStateTransition(kFlushed);
|
| - base::ResetAndReturn(&init_cb_).Run();
|
| + base::ResetAndReturn(&init_cb_).Run(::media::PIPELINE_OK);
|
| }
|
|
|
| void CmaRenderer::OnEosReached(bool is_audio) {
|
| @@ -423,18 +434,18 @@ void CmaRenderer::OnError(::media::PipelineStatus error) {
|
| DCHECK_NE(::media::PIPELINE_OK, error) << "PIPELINE_OK isn't an error!";
|
| LOG(ERROR) << "CMA error encountered: " << error;
|
|
|
| - // Pipeline will destroy |this| as the result of error.
|
| - if (state_ != kError)
|
| - error_cb_.Run(error);
|
| -
|
| + State old_state = state_;
|
| CompleteStateTransition(kError);
|
| - FireAllPendingCallbacks();
|
| -}
|
|
|
| -void CmaRenderer::FireAllPendingCallbacks() {
|
| - DCHECK(thread_checker_.CalledOnValidThread());
|
| - if (!init_cb_.is_null())
|
| - base::ResetAndReturn(&init_cb_).Run();
|
| + if (old_state != kError) {
|
| + if (!init_cb_.is_null()) {
|
| + base::ResetAndReturn(&init_cb_).Run(error);
|
| + return;
|
| + }
|
| + error_cb_.Run(error);
|
| + }
|
| +
|
| + // After OnError() returns, the pipeline may destroy |this|.
|
| if (!flush_cb_.is_null())
|
| base::ResetAndReturn(&flush_cb_).Run();
|
| }
|
|
|