OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_ | 5 #ifndef MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_ | 6 #define MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
16 #include "content/renderer/media/buffered_data_source_host_impl.h" | |
17 #include "content/renderer/media/video_frame_compositor.h" | |
18 #include "media/base/audio_renderer_sink.h" | 17 #include "media/base/audio_renderer_sink.h" |
18 #include "media/base/media_export.h" | |
19 // TODO(xhwang): Remove when we remove prefixed EME implementation. | 19 // TODO(xhwang): Remove when we remove prefixed EME implementation. |
20 #include "media/base/media_keys.h" | 20 #include "media/base/media_keys.h" |
21 #include "media/base/pipeline.h" | 21 #include "media/base/pipeline.h" |
22 #include "media/base/text_track.h" | 22 #include "media/base/text_track.h" |
23 #include "media/blink/buffered_data_source.h" | |
24 #include "media/blink/buffered_data_source_host_impl.h" | |
25 #include "media/blink/video_frame_compositor.h" | |
23 #include "media/filters/skcanvas_video_renderer.h" | 26 #include "media/filters/skcanvas_video_renderer.h" |
24 #include "skia/ext/platform_canvas.h" | |
25 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" | 27 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" |
26 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | 28 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
27 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 29 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
28 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 30 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
29 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 31 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
30 #include "url/gurl.h" | 32 #include "url/gurl.h" |
31 | 33 |
32 namespace blink { | 34 namespace blink { |
33 class WebLocalFrame; | 35 class WebLocalFrame; |
34 } | 36 } |
35 | 37 |
36 namespace base { | 38 namespace base { |
37 class SingleThreadTaskRunner; | 39 class SingleThreadTaskRunner; |
38 } | 40 } |
39 | 41 |
40 namespace cc_blink { | 42 namespace cc_blink { |
41 class WebLayerImpl; | 43 class WebLayerImpl; |
42 } | 44 } |
43 | 45 |
44 namespace media { | 46 namespace media { |
45 class AudioHardwareConfig; | 47 class AudioHardwareConfig; |
46 class ChunkDemuxer; | 48 class ChunkDemuxer; |
49 class EncryptedMediaPlayerSupport; | |
47 class GpuVideoAcceleratorFactories; | 50 class GpuVideoAcceleratorFactories; |
48 class MediaLog; | 51 class MediaLog; |
49 } | |
50 | |
51 | |
52 namespace content { | |
53 class BufferedDataSource; | |
54 class EncryptedMediaPlayerSupport; | |
55 class VideoFrameCompositor; | 52 class VideoFrameCompositor; |
56 class WebAudioSourceProviderImpl; | 53 class WebAudioSourceProviderImpl; |
57 class WebMediaPlayerDelegate; | 54 class WebMediaPlayerDelegate; |
58 class WebMediaPlayerParams; | 55 class WebMediaPlayerParams; |
59 class WebTextTrackImpl; | 56 class WebTextTrackImpl; |
60 | 57 |
61 // The canonical implementation of blink::WebMediaPlayer that's backed by | 58 // The canonical implementation of blink::WebMediaPlayer that's backed by |
62 // media::Pipeline. Handles normal resource loading, Media Source, and | 59 // Pipeline. Handles normal resource loading, Media Source, and |
63 // Encrypted Media. | 60 // Encrypted Media. |
64 class WebMediaPlayerImpl | 61 class MEDIA_EXPORT WebMediaPlayerImpl |
65 : public blink::WebMediaPlayer, | 62 : public NON_EXPORTED_BASE(blink::WebMediaPlayer), |
66 public base::SupportsWeakPtr<WebMediaPlayerImpl> { | 63 public base::SupportsWeakPtr<WebMediaPlayerImpl> { |
67 public: | 64 public: |
68 // Constructs a WebMediaPlayer implementation using Chromium's media stack. | 65 // Constructs a WebMediaPlayer implementation using Chromium's media stack. |
69 // |delegate| may be null. | 66 // |delegate| may be null. |
70 WebMediaPlayerImpl(blink::WebLocalFrame* frame, | 67 WebMediaPlayerImpl(blink::WebLocalFrame* frame, |
71 blink::WebMediaPlayerClient* client, | 68 blink::WebMediaPlayerClient* client, |
72 base::WeakPtr<WebMediaPlayerDelegate> delegate, | 69 base::WeakPtr<WebMediaPlayerDelegate> delegate, |
73 const WebMediaPlayerParams& params); | 70 const WebMediaPlayerParams& params); |
74 virtual ~WebMediaPlayerImpl(); | 71 virtual ~WebMediaPlayerImpl(); |
75 | 72 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 // TODO(jrummell): Remove this method once Blink updated to use the other | 157 // TODO(jrummell): Remove this method once Blink updated to use the other |
161 // two methods. | 158 // two methods. |
162 virtual void setContentDecryptionModule( | 159 virtual void setContentDecryptionModule( |
163 blink::WebContentDecryptionModule* cdm); | 160 blink::WebContentDecryptionModule* cdm); |
164 virtual void setContentDecryptionModule( | 161 virtual void setContentDecryptionModule( |
165 blink::WebContentDecryptionModule* cdm, | 162 blink::WebContentDecryptionModule* cdm, |
166 blink::WebContentDecryptionModuleResult result); | 163 blink::WebContentDecryptionModuleResult result); |
167 virtual void setContentDecryptionModuleSync( | 164 virtual void setContentDecryptionModuleSync( |
168 blink::WebContentDecryptionModule* cdm); | 165 blink::WebContentDecryptionModule* cdm); |
169 | 166 |
170 void OnPipelineSeeked(bool time_changed, media::PipelineStatus status); | 167 void OnPipelineSeeked(bool time_changed, PipelineStatus status); |
171 void OnPipelineEnded(); | 168 void OnPipelineEnded(); |
172 void OnPipelineError(media::PipelineStatus error); | 169 void OnPipelineError(PipelineStatus error); |
173 void OnPipelineMetadata(media::PipelineMetadata metadata); | 170 void OnPipelineMetadata(PipelineMetadata metadata); |
174 void OnPipelineBufferingStateChanged(media::BufferingState buffering_state); | 171 void OnPipelineBufferingStateChanged(BufferingState buffering_state); |
175 void OnDemuxerOpened(); | 172 void OnDemuxerOpened(); |
176 void OnAddTextTrack(const media::TextTrackConfig& config, | 173 void OnAddTextTrack(const TextTrackConfig& config, |
177 const media::AddTextTrackDoneCB& done_cb); | 174 const AddTextTrackDoneCB& done_cb); |
178 | 175 |
179 private: | 176 private: |
180 // Called after |defer_load_cb_| has decided to allow the load. If | 177 // Called after |defer_load_cb_| has decided to allow the load. If |
181 // |defer_load_cb_| is null this is called immediately. | 178 // |defer_load_cb_| is null this is called immediately. |
182 void DoLoad(LoadType load_type, | 179 void DoLoad(LoadType load_type, |
183 const blink::WebURL& url, | 180 const blink::WebURL& url, |
184 CORSMode cors_mode); | 181 CORSMode cors_mode); |
185 | 182 |
186 // Called after asynchronous initialization of a data source completed. | 183 // Called after asynchronous initialization of a data source completed. |
187 void DataSourceInitialized(bool success); | 184 void DataSourceInitialized(bool success); |
188 | 185 |
189 // Called when the data source is downloading or paused. | 186 // Called when the data source is downloading or paused. |
190 void NotifyDownloading(bool is_downloading); | 187 void NotifyDownloading(bool is_downloading); |
191 | 188 |
192 // Creates a media::Renderer that will be used by the |pipeline_|. | 189 // Creates a Renderer that will be used by the |pipeline_|. |
193 scoped_ptr<media::Renderer> CreateRenderer(); | 190 scoped_ptr<Renderer> CreateRenderer(); |
194 | 191 |
195 // Finishes starting the pipeline due to a call to load(). | 192 // Finishes starting the pipeline due to a call to load(). |
196 void StartPipeline(); | 193 void StartPipeline(); |
197 | 194 |
198 // Helpers that set the network/ready state and notifies the client if | 195 // Helpers that set the network/ready state and notifies the client if |
199 // they've changed. | 196 // they've changed. |
200 void SetNetworkState(blink::WebMediaPlayer::NetworkState state); | 197 void SetNetworkState(blink::WebMediaPlayer::NetworkState state); |
201 void SetReadyState(blink::WebMediaPlayer::ReadyState state); | 198 void SetReadyState(blink::WebMediaPlayer::ReadyState state); |
202 | 199 |
203 // Gets the duration value reported by the pipeline. | 200 // Gets the duration value reported by the pipeline. |
204 double GetPipelineDuration() const; | 201 double GetPipelineDuration() const; |
205 | 202 |
206 // Callbacks from |pipeline_| that are forwarded to |client_|. | 203 // Callbacks from |pipeline_| that are forwarded to |client_|. |
207 void OnDurationChanged(); | 204 void OnDurationChanged(); |
208 void OnNaturalSizeChanged(gfx::Size size); | 205 void OnNaturalSizeChanged(gfx::Size size); |
209 void OnOpacityChanged(bool opaque); | 206 void OnOpacityChanged(bool opaque); |
210 | 207 |
211 // Called by VideoRendererImpl on its internal thread with the new frame to be | 208 // Called by VideoRendererImpl on its internal thread with the new frame to be |
212 // painted. | 209 // painted. |
213 void FrameReady(const scoped_refptr<media::VideoFrame>& frame); | 210 void FrameReady(const scoped_refptr<VideoFrame>& frame); |
214 | 211 |
215 // Returns the current video frame from |compositor_|. Blocks until the | 212 // Returns the current video frame from |compositor_|. Blocks until the |
216 // compositor can return the frame. | 213 // compositor can return the frame. |
217 scoped_refptr<media::VideoFrame> GetCurrentFrameFromCompositor(); | 214 scoped_refptr<VideoFrame> GetCurrentFrameFromCompositor(); |
218 | 215 |
219 blink::WebLocalFrame* frame_; | 216 blink::WebLocalFrame* frame_; |
220 | 217 |
221 // TODO(hclam): get rid of these members and read from the pipeline directly. | 218 // TODO(hclam): get rid of these members and read from the pipeline directly. |
222 blink::WebMediaPlayer::NetworkState network_state_; | 219 blink::WebMediaPlayer::NetworkState network_state_; |
223 blink::WebMediaPlayer::ReadyState ready_state_; | 220 blink::WebMediaPlayer::ReadyState ready_state_; |
224 | 221 |
225 // Preload state for when |data_source_| is created after setPreload(). | 222 // Preload state for when |data_source_| is created after setPreload(). |
226 BufferedDataSource::Preload preload_; | 223 BufferedDataSource::Preload preload_; |
227 | 224 |
228 // Task runner for posting tasks on Chrome's main thread. Also used | 225 // Task runner for posting tasks on Chrome's main thread. Also used |
229 // for DCHECKs so methods calls won't execute in the wrong thread. | 226 // for DCHECKs so methods calls won't execute in the wrong thread. |
230 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 227 const scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
231 | 228 |
232 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; | 229 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner_; |
233 scoped_refptr<media::MediaLog> media_log_; | 230 scoped_refptr<MediaLog> media_log_; |
234 media::Pipeline pipeline_; | 231 Pipeline pipeline_; |
235 | 232 |
236 // The LoadType passed in the |load_type| parameter of the load() call. | 233 // The LoadType passed in the |load_type| parameter of the load() call. |
237 LoadType load_type_; | 234 LoadType load_type_; |
238 | 235 |
239 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize(). | 236 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize(). |
240 media::PipelineMetadata pipeline_metadata_; | 237 PipelineMetadata pipeline_metadata_; |
241 | 238 |
242 // Whether the video is known to be opaque or not. | 239 // Whether the video is known to be opaque or not. |
243 bool opaque_; | 240 bool opaque_; |
244 | 241 |
245 // Playback state. | 242 // Playback state. |
246 // | 243 // |
247 // TODO(scherkus): we have these because Pipeline favours the simplicity of a | 244 // TODO(scherkus): we have these because Pipeline favours the simplicity of a |
248 // single "playback rate" over worrying about paused/stopped etc... It forces | 245 // single "playback rate" over worrying about paused/stopped etc... It forces |
249 // all clients to manage the pause+playback rate externally, but is that | 246 // all clients to manage the pause+playback rate externally, but is that |
250 // really a bad thing? | 247 // really a bad thing? |
(...skipping 21 matching lines...) Expand all Loading... | |
272 // changes. | 269 // changes. |
273 bool should_notify_time_changed_; | 270 bool should_notify_time_changed_; |
274 | 271 |
275 blink::WebMediaPlayerClient* client_; | 272 blink::WebMediaPlayerClient* client_; |
276 | 273 |
277 base::WeakPtr<WebMediaPlayerDelegate> delegate_; | 274 base::WeakPtr<WebMediaPlayerDelegate> delegate_; |
278 | 275 |
279 base::Callback<void(const base::Closure&)> defer_load_cb_; | 276 base::Callback<void(const base::Closure&)> defer_load_cb_; |
280 | 277 |
281 // Factories for supporting video accelerators. May be null. | 278 // Factories for supporting video accelerators. May be null. |
282 scoped_refptr<media::GpuVideoAcceleratorFactories> gpu_factories_; | 279 scoped_refptr<GpuVideoAcceleratorFactories> gpu_factories_; |
283 | 280 |
284 // Routes audio playback to either AudioRendererSink or WebAudio. | 281 // Routes audio playback to either AudioRendererSink or WebAudio. |
285 scoped_refptr<WebAudioSourceProviderImpl> audio_source_provider_; | 282 scoped_refptr<WebAudioSourceProviderImpl> audio_source_provider_; |
286 | 283 |
287 bool supports_save_; | 284 bool supports_save_; |
288 | 285 |
289 // These two are mutually exclusive: | 286 // These two are mutually exclusive: |
290 // |data_source_| is used for regular resource loads. | 287 // |data_source_| is used for regular resource loads. |
291 // |chunk_demuxer_| is used for Media Source resource loads. | 288 // |chunk_demuxer_| is used for Media Source resource loads. |
292 // | 289 // |
293 // |demuxer_| will contain the appropriate demuxer based on which resource | 290 // |demuxer_| will contain the appropriate demuxer based on which resource |
294 // load strategy we're using. | 291 // load strategy we're using. |
295 scoped_ptr<BufferedDataSource> data_source_; | 292 scoped_ptr<BufferedDataSource> data_source_; |
296 scoped_ptr<media::Demuxer> demuxer_; | 293 scoped_ptr<Demuxer> demuxer_; |
297 media::ChunkDemuxer* chunk_demuxer_; | 294 ChunkDemuxer* chunk_demuxer_; |
298 | 295 |
299 BufferedDataSourceHostImpl buffered_data_source_host_; | 296 BufferedDataSourceHostImpl buffered_data_source_host_; |
300 | 297 |
301 // Video rendering members. | 298 // Video rendering members. |
302 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 299 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
303 VideoFrameCompositor* compositor_; // Deleted on |compositor_task_runner_|. | 300 VideoFrameCompositor* compositor_; // Deleted on |compositor_task_runner_|. |
304 media::SkCanvasVideoRenderer skcanvas_video_renderer_; | 301 SkCanvasVideoRenderer skcanvas_video_renderer_; |
305 | 302 |
306 // The compositor layer for displaying the video content when using composited | 303 // The compositor layer for displaying the video content when using composited |
307 // playback. | 304 // playback. |
308 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; | 305 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; |
309 | 306 |
310 // Text track objects get a unique index value when they're created. | 307 // Text track objects get a unique index value when they're created. |
311 int text_track_index_; | 308 int text_track_index_; |
312 | 309 |
313 scoped_ptr<EncryptedMediaPlayerSupport> encrypted_media_support_; | 310 scoped_ptr<EncryptedMediaPlayerSupport> encrypted_media_support_; |
314 | 311 |
315 const media::AudioHardwareConfig& audio_hardware_config_; | 312 const media::AudioHardwareConfig& audio_hardware_config_; |
scherkus (not reviewing)
2014/09/04 23:00:36
remove media::
acolwell GONE FROM CHROMIUM
2014/09/05 00:23:44
Done.
| |
316 | 313 |
317 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); | 314 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); |
318 }; | 315 }; |
319 | 316 |
320 } // namespace content | 317 } // namespace media |
321 | 318 |
322 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_ | 319 #endif // MEDIA_BLINK_WEBMEDIAPLAYER_IMPL_H_ |
OLD | NEW |