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 #ifndef MEDIA_MOJO_SERVICES_MOJO_RENDERER_IMPL_H_ | 5 #ifndef MEDIA_MOJO_SERVICES_MOJO_RENDERER_IMPL_H_ |
| 6 #define MEDIA_MOJO_SERVICES_MOJO_RENDERER_IMPL_H_ | 6 #define MEDIA_MOJO_SERVICES_MOJO_RENDERER_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "media/base/renderer.h" | 11 #include "media/base/renderer.h" |
| 12 #include "media/mojo/interfaces/renderer.mojom.h" | 12 #include "media/mojo/interfaces/renderer.mojom.h" |
| 13 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 14 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 class SingleThreadTaskRunner; | 17 class SingleThreadTaskRunner; |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace media { | 20 namespace media { |
| 20 | 21 |
| 21 class DemuxerStreamProvider; | 22 class DemuxerStreamProvider; |
| 22 | 23 |
| 23 // A media::Renderer that proxies to a interfaces::Renderer. That | 24 // A media::Renderer that proxies to a interfaces::Renderer. That |
| 24 // interfaces::Renderer proxies back to the MojoRendererImpl via the | 25 // interfaces::Renderer proxies back to the MojoRendererImpl via the |
| 25 // interfaces::RendererClient interface. | 26 // interfaces::RendererClient interface. |
| 26 // | 27 // |
| 27 // This class can be created on any thread, where the |remote_renderer| is | 28 // This class can be created on any thread, where the |remote_renderer| is |
| 28 // connected and passed in the constructor. Then Initialize() will be called on | 29 // connected and passed in the constructor. Then Initialize() will be called on |
| 29 // the |task_runner| and starting from that point this class is bound to the | 30 // the |task_runner| and starting from that point this class is bound to the |
| 30 // |task_runner|*. That means all Renderer and RendererClient methods will be | 31 // |task_runner|*. That means all Renderer and RendererClient methods will be |
| 31 // called/dispached on the |task_runner|. The only exception is GetMediaTime(), | 32 // called/dispached on the |task_runner|. The only exception is GetMediaTime(), |
| 32 // which can be called on any thread. | 33 // which can be called on any thread. |
| 33 // | |
| 34 // * Threading details: | |
| 35 // mojo::GetProxy() doesn't bind an InterfacePtr to a thread. Then when | |
| 36 // InterfacePtr::operator->() or InterfacePtr::get() is called for the first | |
| 37 // time, e.g. to call remote_renderer->Initialize(), the InterfacePtr is bound | |
| 38 // the thread where the call is made. | |
| 39 | |
| 40 class MojoRendererImpl : public Renderer, public interfaces::RendererClient { | 34 class MojoRendererImpl : public Renderer, public interfaces::RendererClient { |
| 41 public: | 35 public: |
| 42 MojoRendererImpl( | 36 MojoRendererImpl( |
| 43 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 37 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 44 interfaces::RendererPtr remote_renderer); | 38 interfaces::RendererPtr remote_renderer); |
| 45 ~MojoRendererImpl() override; | 39 ~MojoRendererImpl() override; |
| 46 | 40 |
| 47 // Renderer implementation. | 41 // Renderer implementation. |
| 48 void Initialize(DemuxerStreamProvider* demuxer_stream_provider, | 42 void Initialize(DemuxerStreamProvider* demuxer_stream_provider, |
| 49 const PipelineStatusCB& init_cb, | 43 const PipelineStatusCB& init_cb, |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 77 void OnInitialized(bool success); | 71 void OnInitialized(bool success); |
| 78 | 72 |
| 79 // |task_runner| on which all methods are invoked, except for GetMediaTime(), | 73 // |task_runner| on which all methods are invoked, except for GetMediaTime(), |
| 80 // which can be called on any thread. | 74 // which can be called on any thread. |
| 81 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 75 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 82 | 76 |
| 83 // Provider of audio/video DemuxerStreams. Must be valid throughout the | 77 // Provider of audio/video DemuxerStreams. Must be valid throughout the |
| 84 // lifetime of |this|. | 78 // lifetime of |this|. |
| 85 DemuxerStreamProvider* demuxer_stream_provider_; | 79 DemuxerStreamProvider* demuxer_stream_provider_; |
| 86 | 80 |
| 87 // Remote Renderer, bound to |task_runner_|. | 81 // This class is constructed on one thread and used exclusively on another |
| 82 // thread. This member is used to safely pass the RendererPtr from one thread | |
| 83 // to another. It is set in the constructor and is consumed in Initialize(). | |
| 84 mojo::InterfacePtrInfo<interfaces::Renderer> remote_renderer_info_; | |
|
yzshen1
2016/03/22 19:15:04
optional: interfaces::RendererPtrInfo
xhwang
2016/03/22 19:45:26
Done.
| |
| 85 | |
| 86 // Remote Renderer, bound to |task_runner_| during Initialize(). | |
| 88 interfaces::RendererPtr remote_renderer_; | 87 interfaces::RendererPtr remote_renderer_; |
| 89 | 88 |
| 90 // Binding for RendererClient, bound to the |task_runner_|. | 89 // Binding for RendererClient, bound to the |task_runner_|. |
| 91 mojo::Binding<RendererClient> binding_; | 90 mojo::Binding<RendererClient> binding_; |
| 92 | 91 |
| 93 // Callbacks passed to Initialize() that we forward messages from | 92 // Callbacks passed to Initialize() that we forward messages from |
| 94 // |remote_renderer_| through. | 93 // |remote_renderer_| through. |
| 95 PipelineStatusCB init_cb_; | 94 PipelineStatusCB init_cb_; |
| 96 base::Closure ended_cb_; | 95 base::Closure ended_cb_; |
| 97 PipelineStatusCB error_cb_; | 96 PipelineStatusCB error_cb_; |
| 98 BufferingStateCB buffering_state_cb_; | 97 BufferingStateCB buffering_state_cb_; |
| 99 | 98 |
| 100 // Lock used to serialize access for |time_|. | 99 // Lock used to serialize access for |time_|. |
| 101 mutable base::Lock lock_; | 100 mutable base::Lock lock_; |
| 102 base::TimeDelta time_; | 101 base::TimeDelta time_; |
| 103 | 102 |
| 104 DISALLOW_COPY_AND_ASSIGN(MojoRendererImpl); | 103 DISALLOW_COPY_AND_ASSIGN(MojoRendererImpl); |
| 105 }; | 104 }; |
| 106 | 105 |
| 107 } // namespace media | 106 } // namespace media |
| 108 | 107 |
| 109 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_IMPL_H_ | 108 #endif // MEDIA_MOJO_SERVICES_MOJO_RENDERER_IMPL_H_ |
| OLD | NEW |