diff options
author | xhwang <xhwang@chromium.org> | 2016-03-22 15:18:01 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-03-22 22:19:27 +0000 |
commit | ac9ee0c8ef4c20df609f7d34c068d9a97363160e (patch) | |
tree | fdf364e72834f14dc07ca7be4394f232c4249e46 /media | |
parent | 0a8aec1cd199c40f7840e3522f61642a743ca850 (diff) | |
download | chromium_src-ac9ee0c8ef4c20df609f7d34c068d9a97363160e.zip chromium_src-ac9ee0c8ef4c20df609f7d34c068d9a97363160e.tar.gz chromium_src-ac9ee0c8ef4c20df609f7d34c068d9a97363160e.tar.bz2 |
media: Use PassInterface() in mojo media classes
This is the preferred way to bind an InterfacePtr on one thread and then
use it on another thread.
BUG=596925
TEST=Manually tested.
Review URL: https://codereview.chromium.org/1821153004
Cr-Commit-Position: refs/heads/master@{#382708}
Diffstat (limited to 'media')
-rw-r--r-- | media/mojo/services/mojo_audio_decoder.cc | 5 | ||||
-rw-r--r-- | media/mojo/services/mojo_audio_decoder.h | 6 | ||||
-rw-r--r-- | media/mojo/services/mojo_renderer_impl.cc | 5 | ||||
-rw-r--r-- | media/mojo/services/mojo_renderer_impl.h | 14 |
4 files changed, 20 insertions, 10 deletions
diff --git a/media/mojo/services/mojo_audio_decoder.cc b/media/mojo/services/mojo_audio_decoder.cc index 0e9ea511..9a070bb 100644 --- a/media/mojo/services/mojo_audio_decoder.cc +++ b/media/mojo/services/mojo_audio_decoder.cc @@ -21,7 +21,7 @@ MojoAudioDecoder::MojoAudioDecoder( scoped_refptr<base::SingleThreadTaskRunner> task_runner, interfaces::AudioDecoderPtr remote_decoder) : task_runner_(task_runner), - remote_decoder_(std::move(remote_decoder)), + remote_decoder_info_(remote_decoder.PassInterface()), binding_(this), has_connection_error_(false), needs_bitstream_conversion_(false) { @@ -43,6 +43,9 @@ void MojoAudioDecoder::Initialize(const AudioDecoderConfig& config, DVLOG(1) << __FUNCTION__; DCHECK(task_runner_->BelongsToCurrentThread()); + // Bind |remote_decoder_| to the |task_runner_|. + remote_decoder_.Bind(std::move(remote_decoder_info_)); + // Fail immediately if the stream is encrypted but |cdm_context| is invalid. int cdm_id = (config.is_encrypted() && cdm_context) ? cdm_context->GetCdmId() diff --git a/media/mojo/services/mojo_audio_decoder.h b/media/mojo/services/mojo_audio_decoder.h index 3f0d58f..ae6097d 100644 --- a/media/mojo/services/mojo_audio_decoder.h +++ b/media/mojo/services/mojo_audio_decoder.h @@ -63,6 +63,12 @@ class MojoAudioDecoder : public AudioDecoder, scoped_refptr<base::SingleThreadTaskRunner> task_runner_; + // This class is constructed on one thread and used exclusively on another + // thread. This member is used to safely pass the AudioDecoderPtr from one + // thread to another. It is set in the constructor and is consumed in + // Initialize(). + interfaces::AudioDecoderPtrInfo remote_decoder_info_; + interfaces::AudioDecoderPtr remote_decoder_; // DataPipe for serializing the data section of DecoderBuffer. diff --git a/media/mojo/services/mojo_renderer_impl.cc b/media/mojo/services/mojo_renderer_impl.cc index ee4c908..e5a9433 100644 --- a/media/mojo/services/mojo_renderer_impl.cc +++ b/media/mojo/services/mojo_renderer_impl.cc @@ -19,7 +19,7 @@ MojoRendererImpl::MojoRendererImpl( const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, interfaces::RendererPtr remote_renderer) : task_runner_(task_runner), - remote_renderer_(std::move(remote_renderer)), + remote_renderer_info_(remote_renderer.PassInterface()), binding_(this) { DVLOG(1) << __FUNCTION__; } @@ -43,6 +43,9 @@ void MojoRendererImpl::Initialize( DCHECK(task_runner_->BelongsToCurrentThread()); DCHECK(demuxer_stream_provider); + // Bind |remote_renderer_| to the |task_runner_|. + remote_renderer_.Bind(std::move(remote_renderer_info_)); + // If connection error has happened, fail immediately. if (remote_renderer_.encountered_error()) { task_runner_->PostTask( diff --git a/media/mojo/services/mojo_renderer_impl.h b/media/mojo/services/mojo_renderer_impl.h index 85c47aa..9a7bb0f 100644 --- a/media/mojo/services/mojo_renderer_impl.h +++ b/media/mojo/services/mojo_renderer_impl.h @@ -30,13 +30,6 @@ class DemuxerStreamProvider; // |task_runner|*. That means all Renderer and RendererClient methods will be // called/dispached on the |task_runner|. The only exception is GetMediaTime(), // which can be called on any thread. -// -// * Threading details: -// mojo::GetProxy() doesn't bind an InterfacePtr to a thread. Then when -// InterfacePtr::operator->() or InterfacePtr::get() is called for the first -// time, e.g. to call remote_renderer->Initialize(), the InterfacePtr is bound -// the thread where the call is made. - class MojoRendererImpl : public Renderer, public interfaces::RendererClient { public: MojoRendererImpl( @@ -84,7 +77,12 @@ class MojoRendererImpl : public Renderer, public interfaces::RendererClient { // lifetime of |this|. DemuxerStreamProvider* demuxer_stream_provider_; - // Remote Renderer, bound to |task_runner_|. + // This class is constructed on one thread and used exclusively on another + // thread. This member is used to safely pass the RendererPtr from one thread + // to another. It is set in the constructor and is consumed in Initialize(). + interfaces::RendererPtrInfo remote_renderer_info_; + + // Remote Renderer, bound to |task_runner_| during Initialize(). interfaces::RendererPtr remote_renderer_; // Binding for RendererClient, bound to the |task_runner_|. |