Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: media/mojo/clients/mojo_renderer.h

Issue 2491043003: MediaResource refactoring to support multiple streams (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_CLIENTS_MOJO_RENDERER_H_ 5 #ifndef MEDIA_MOJO_CLIENTS_MOJO_RENDERER_H_
6 #define MEDIA_MOJO_CLIENTS_MOJO_RENDERER_H_ 6 #define MEDIA_MOJO_CLIENTS_MOJO_RENDERER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/time/default_tick_clock.h" 14 #include "base/time/default_tick_clock.h"
15 #include "base/unguessable_token.h" 15 #include "base/unguessable_token.h"
16 #include "media/base/demuxer_stream.h" 16 #include "media/base/demuxer_stream.h"
17 #include "media/base/renderer.h" 17 #include "media/base/renderer.h"
18 #include "media/base/time_delta_interpolator.h" 18 #include "media/base/time_delta_interpolator.h"
19 #include "media/mojo/interfaces/renderer.mojom.h" 19 #include "media/mojo/interfaces/renderer.mojom.h"
20 #include "mojo/public/cpp/bindings/associated_binding.h" 20 #include "mojo/public/cpp/bindings/associated_binding.h"
21 21
22 namespace base { 22 namespace base {
23 class SingleThreadTaskRunner; 23 class SingleThreadTaskRunner;
24 } 24 }
25 25
26 namespace media { 26 namespace media {
27 27
28 class DemuxerStreamProvider; 28 class MediaResource;
29 class MojoDemuxerStreamImpl; 29 class MojoDemuxerStreamImpl;
30 class VideoOverlayFactory; 30 class VideoOverlayFactory;
31 class VideoRendererSink; 31 class VideoRendererSink;
32 32
33 // A media::Renderer that proxies to a mojom::Renderer. That 33 // A media::Renderer that proxies to a mojom::Renderer. That
34 // mojom::Renderer proxies back to the MojoRenderer via the 34 // mojom::Renderer proxies back to the MojoRenderer via the
35 // mojom::RendererClient interface. 35 // mojom::RendererClient interface.
36 // 36 //
37 // This class can be created on any thread, where the |remote_renderer| is 37 // This class can be created on any thread, where the |remote_renderer| is
38 // connected and passed in the constructor. Then Initialize() will be called on 38 // connected and passed in the constructor. Then Initialize() will be called on
39 // the |task_runner| and starting from that point this class is bound to the 39 // the |task_runner| and starting from that point this class is bound to the
40 // |task_runner|*. That means all Renderer and RendererClient methods will be 40 // |task_runner|*. That means all Renderer and RendererClient methods will be
41 // called/dispached on the |task_runner|. The only exception is GetMediaTime(), 41 // called/dispached on the |task_runner|. The only exception is GetMediaTime(),
42 // which can be called on any thread. 42 // which can be called on any thread.
43 class MojoRenderer : public Renderer, public mojom::RendererClient { 43 class MojoRenderer : public Renderer, public mojom::RendererClient {
44 public: 44 public:
45 MojoRenderer(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 45 MojoRenderer(const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
46 std::unique_ptr<VideoOverlayFactory> video_overlay_factory, 46 std::unique_ptr<VideoOverlayFactory> video_overlay_factory,
47 VideoRendererSink* video_renderer_sink, 47 VideoRendererSink* video_renderer_sink,
48 mojom::RendererPtr remote_renderer); 48 mojom::RendererPtr remote_renderer);
49 ~MojoRenderer() override; 49 ~MojoRenderer() override;
50 50
51 // Renderer implementation. 51 // Renderer implementation.
52 void Initialize(DemuxerStreamProvider* demuxer_stream_provider, 52 void Initialize(MediaResource* media_resource,
53 media::RendererClient* client, 53 media::RendererClient* client,
54 const PipelineStatusCB& init_cb) override; 54 const PipelineStatusCB& init_cb) override;
55 void SetCdm(CdmContext* cdm_context, 55 void SetCdm(CdmContext* cdm_context,
56 const CdmAttachedCB& cdm_attached_cb) override; 56 const CdmAttachedCB& cdm_attached_cb) override;
57 void Flush(const base::Closure& flush_cb) override; 57 void Flush(const base::Closure& flush_cb) override;
58 void StartPlayingFrom(base::TimeDelta time) override; 58 void StartPlayingFrom(base::TimeDelta time) override;
59 void SetPlaybackRate(double playback_rate) override; 59 void SetPlaybackRate(double playback_rate) override;
60 void SetVolume(float volume) override; 60 void SetVolume(float volume) override;
61 base::TimeDelta GetMediaTime() override; 61 base::TimeDelta GetMediaTime() override;
62 62
(...skipping 18 matching lines...) Expand all
81 void OnVideoOpacityChange(bool opaque) override; 81 void OnVideoOpacityChange(bool opaque) override;
82 void OnWaitingForDecryptionKey() override; 82 void OnWaitingForDecryptionKey() override;
83 void OnStatisticsUpdate(const PipelineStatistics& stats) override; 83 void OnStatisticsUpdate(const PipelineStatistics& stats) override;
84 void OnDurationChange(base::TimeDelta duration) override; 84 void OnDurationChange(base::TimeDelta duration) override;
85 85
86 // Binds |remote_renderer_| to the mojo message pipe. Can be called multiple 86 // Binds |remote_renderer_| to the mojo message pipe. Can be called multiple
87 // times. If an error occurs during connection, OnConnectionError will be 87 // times. If an error occurs during connection, OnConnectionError will be
88 // called asynchronously. 88 // called asynchronously.
89 void BindRemoteRendererIfNeeded(); 89 void BindRemoteRendererIfNeeded();
90 90
91 // Initialize the remote renderer when |demuxer_stream_provider| is of type 91 // Initialize the remote renderer when |media_resource| is of type
92 // DemuxerSteamProvider::Type::STREAM. 92 // MediaResource::Type::STREAM.
93 void InitializeRendererFromStreams(media::RendererClient* client); 93 void InitializeRendererFromStreams(media::RendererClient* client);
94 94
95 // Initialize the remote renderer when |demuxer_stream_provider| is of type 95 // Initialize the remote renderer when |media_resource| is of type
96 // DemuxerSteamProvider::Type::URL. 96 // MediaResource::Type::URL.
97 void InitializeRendererFromUrl(media::RendererClient* client); 97 void InitializeRendererFromUrl(media::RendererClient* client);
98 98
99 // Callback for connection error on |remote_renderer_|. 99 // Callback for connection error on |remote_renderer_|.
100 void OnConnectionError(); 100 void OnConnectionError();
101 101
102 // Callback for connection error on any of |streams_|. The |stream| parameter 102 // Callback for connection error on any of |streams_|. The |stream| parameter
103 // indicates which stream the error happened on. 103 // indicates which stream the error happened on.
104 void OnDemuxerStreamConnectionError(MojoDemuxerStreamImpl* stream); 104 void OnDemuxerStreamConnectionError(MojoDemuxerStreamImpl* stream);
105 105
106 // Callbacks for |remote_renderer_| methods. 106 // Callbacks for |remote_renderer_| methods.
(...skipping 10 matching lines...) Expand all
117 // Overlay factory used to create overlays for video frames rendered 117 // Overlay factory used to create overlays for video frames rendered
118 // by the remote renderer. 118 // by the remote renderer.
119 std::unique_ptr<VideoOverlayFactory> video_overlay_factory_; 119 std::unique_ptr<VideoOverlayFactory> video_overlay_factory_;
120 120
121 // Video frame overlays are rendered onto this sink. 121 // Video frame overlays are rendered onto this sink.
122 // Rendering of a new overlay is only needed when video natural size changes. 122 // Rendering of a new overlay is only needed when video natural size changes.
123 VideoRendererSink* video_renderer_sink_ = nullptr; 123 VideoRendererSink* video_renderer_sink_ = nullptr;
124 124
125 // Provider of audio/video DemuxerStreams. Must be valid throughout the 125 // Provider of audio/video DemuxerStreams. Must be valid throughout the
126 // lifetime of |this|. 126 // lifetime of |this|.
127 DemuxerStreamProvider* demuxer_stream_provider_ = nullptr; 127 MediaResource* media_resource_ = nullptr;
128 128
129 // Client of |this| renderer passed in Initialize. 129 // Client of |this| renderer passed in Initialize.
130 media::RendererClient* client_ = nullptr; 130 media::RendererClient* client_ = nullptr;
131 131
132 // Mojo demuxer streams. 132 // Mojo demuxer streams.
133 // Owned by MojoRenderer instead of remote mojom::Renderer 133 // Owned by MojoRenderer instead of remote mojom::Renderer
134 // becuase these demuxer streams need to be destroyed as soon as |this| is 134 // becuase these demuxer streams need to be destroyed as soon as |this| is
135 // destroyed. The local demuxer streams returned by DemuxerStreamProvider 135 // destroyed. The local demuxer streams returned by MediaResource
xhwang 2017/02/01 18:26:04 nit: reflow comments
servolk 2017/02/01 22:29:17 Done.
136 // cannot be used after |this| is destroyed. 136 // cannot be used after |this| is destroyed.
137 // TODO(alokp): Add tests for MojoDemuxerStreamImpl. 137 // TODO(alokp): Add tests for MojoDemuxerStreamImpl.
138 std::vector<std::unique_ptr<MojoDemuxerStreamImpl>> streams_; 138 std::vector<std::unique_ptr<MojoDemuxerStreamImpl>> streams_;
139 139
140 // This class is constructed on one thread and used exclusively on another 140 // This class is constructed on one thread and used exclusively on another
141 // thread. This member is used to safely pass the RendererPtr from one thread 141 // thread. This member is used to safely pass the RendererPtr from one thread
142 // to another. It is set in the constructor and is consumed in Initialize(). 142 // to another. It is set in the constructor and is consumed in Initialize().
143 mojom::RendererPtrInfo remote_renderer_info_; 143 mojom::RendererPtrInfo remote_renderer_info_;
144 144
145 // Remote Renderer, bound to |task_runner_| during Initialize(). 145 // Remote Renderer, bound to |task_runner_| during Initialize().
(...skipping 12 matching lines...) Expand all
158 mutable base::Lock lock_; 158 mutable base::Lock lock_;
159 base::DefaultTickClock media_clock_; 159 base::DefaultTickClock media_clock_;
160 media::TimeDeltaInterpolator media_time_interpolator_; 160 media::TimeDeltaInterpolator media_time_interpolator_;
161 161
162 DISALLOW_COPY_AND_ASSIGN(MojoRenderer); 162 DISALLOW_COPY_AND_ASSIGN(MojoRenderer);
163 }; 163 };
164 164
165 } // namespace media 165 } // namespace media
166 166
167 #endif // MEDIA_MOJO_CLIENTS_MOJO_RENDERER_H_ 167 #endif // MEDIA_MOJO_CLIENTS_MOJO_RENDERER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698