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" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "media/base/audio_renderer.h" | 13 #include "media/base/audio_renderer.h" |
14 #include "media/base/bind_to_current_loop.h" | |
14 #include "media/base/demuxer_stream_provider.h" | 15 #include "media/base/demuxer_stream_provider.h" |
15 #include "media/base/time_source.h" | 16 #include "media/base/time_source.h" |
16 #include "media/base/video_renderer.h" | 17 #include "media/base/video_renderer.h" |
17 #include "media/base/wall_clock_time_source.h" | 18 #include "media/base/wall_clock_time_source.h" |
18 | 19 |
19 namespace media { | 20 namespace media { |
20 | 21 |
21 RendererImpl::RendererImpl( | 22 RendererImpl::RendererImpl( |
22 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 23 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
23 scoped_ptr<AudioRenderer> audio_renderer, | 24 scoped_ptr<AudioRenderer> audio_renderer, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 DCHECK(demuxer_stream_provider->GetStream(DemuxerStream::AUDIO) || | 72 DCHECK(demuxer_stream_provider->GetStream(DemuxerStream::AUDIO) || |
72 demuxer_stream_provider->GetStream(DemuxerStream::VIDEO)); | 73 demuxer_stream_provider->GetStream(DemuxerStream::VIDEO)); |
73 | 74 |
74 demuxer_stream_provider_ = demuxer_stream_provider; | 75 demuxer_stream_provider_ = demuxer_stream_provider; |
75 statistics_cb_ = statistics_cb; | 76 statistics_cb_ = statistics_cb; |
76 buffering_state_cb_ = buffering_state_cb; | 77 buffering_state_cb_ = buffering_state_cb; |
77 paint_cb_ = paint_cb; | 78 paint_cb_ = paint_cb; |
78 ended_cb_ = ended_cb; | 79 ended_cb_ = ended_cb; |
79 error_cb_ = error_cb; | 80 error_cb_ = error_cb; |
80 | 81 |
81 init_cb_ = init_cb; | 82 // Always post the callback because |this| could be destroyed upon failure. |
83 init_cb_ = BindToCurrentLoop(init_cb); | |
xhwang
2015/01/16 23:09:07
This is the tricky part of our rule that callee mu
DaleCurtis
2015/01/16 23:15:15
I realize we post below and init cb still runs asy
xhwang
2015/01/16 23:24:04
I am not too worried about long stack as long as w
DaleCurtis
2015/01/16 23:33:49
I think just adding a note to the demuxer and rend
DaleCurtis
2015/01/20 21:37:43
Done.
| |
84 | |
82 state_ = STATE_INITIALIZING; | 85 state_ = STATE_INITIALIZING; |
83 InitializeAudioRenderer(); | 86 InitializeAudioRenderer(); |
84 } | 87 } |
85 | 88 |
86 void RendererImpl::SetCdm(CdmContext* cdm_context, | 89 void RendererImpl::SetCdm(CdmContext* cdm_context, |
87 const CdmAttachedCB& cdm_attached_cb) { | 90 const CdmAttachedCB& cdm_attached_cb) { |
88 DVLOG(1) << __FUNCTION__; | 91 DVLOG(1) << __FUNCTION__; |
89 DCHECK(task_runner_->BelongsToCurrentThread()); | 92 DCHECK(task_runner_->BelongsToCurrentThread()); |
90 DCHECK(cdm_context); | 93 DCHECK(cdm_context); |
91 | 94 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 DVLOG(1) << __FUNCTION__; | 237 DVLOG(1) << __FUNCTION__; |
235 DCHECK(task_runner_->BelongsToCurrentThread()); | 238 DCHECK(task_runner_->BelongsToCurrentThread()); |
236 DCHECK_EQ(state_, STATE_INITIALIZING); | 239 DCHECK_EQ(state_, STATE_INITIALIZING); |
237 DCHECK(!init_cb_.is_null()); | 240 DCHECK(!init_cb_.is_null()); |
238 | 241 |
239 PipelineStatusCB done_cb = | 242 PipelineStatusCB done_cb = |
240 base::Bind(&RendererImpl::OnAudioRendererInitializeDone, weak_this_); | 243 base::Bind(&RendererImpl::OnAudioRendererInitializeDone, weak_this_); |
241 | 244 |
242 if (!demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO)) { | 245 if (!demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO)) { |
243 audio_renderer_.reset(); | 246 audio_renderer_.reset(); |
244 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); | 247 task_runner_->PostTask(FROM_HERE, base::Bind(done_cb, PIPELINE_OK)); |
xhwang
2015/01/16 23:09:07
See above: We post here; then audio_renderer_->Ini
| |
245 return; | 248 return; |
246 } | 249 } |
247 | 250 |
248 // Note: After the initialization of a renderer, error events from it may | 251 // Note: After the initialization of a renderer, error events from it may |
249 // happen at any time and all future calls must guard against STATE_ERROR. | 252 // happen at any time and all future calls must guard against STATE_ERROR. |
250 audio_renderer_->Initialize( | 253 audio_renderer_->Initialize( |
251 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO), done_cb, | 254 demuxer_stream_provider_->GetStream(DemuxerStream::AUDIO), done_cb, |
252 base::Bind(&RendererImpl::SetDecryptorReadyCallback, weak_this_), | 255 base::Bind(&RendererImpl::SetDecryptorReadyCallback, weak_this_), |
253 base::Bind(&RendererImpl::OnUpdateStatistics, weak_this_), | 256 base::Bind(&RendererImpl::OnUpdateStatistics, weak_this_), |
254 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, | 257 base::Bind(&RendererImpl::OnBufferingStateChanged, weak_this_, |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 DCHECK(task_runner_->BelongsToCurrentThread()); | 563 DCHECK(task_runner_->BelongsToCurrentThread()); |
561 | 564 |
562 if (!init_cb_.is_null()) | 565 if (!init_cb_.is_null()) |
563 base::ResetAndReturn(&init_cb_).Run(); | 566 base::ResetAndReturn(&init_cb_).Run(); |
564 | 567 |
565 if (!flush_cb_.is_null()) | 568 if (!flush_cb_.is_null()) |
566 base::ResetAndReturn(&flush_cb_).Run(); | 569 base::ResetAndReturn(&flush_cb_).Run(); |
567 } | 570 } |
568 | 571 |
569 } // namespace media | 572 } // namespace media |
OLD | NEW |