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 CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_ | 6 #define CONTENT_RENDERER_MEDIA_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/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "content/renderer/media/buffered_data_source_host_impl.h" | 16 #include "content/renderer/media/buffered_data_source_host_impl.h" |
17 #include "content/renderer/media/crypto/proxy_decryptor.h" | |
18 #include "content/renderer/media/video_frame_compositor.h" | 17 #include "content/renderer/media/video_frame_compositor.h" |
19 #include "media/base/audio_renderer_sink.h" | 18 #include "media/base/audio_renderer_sink.h" |
20 #include "media/base/decryptor.h" | |
21 // TODO(xhwang): Remove when we remove prefixed EME implementation. | 19 // TODO(xhwang): Remove when we remove prefixed EME implementation. |
22 #include "media/base/media_keys.h" | 20 #include "media/base/media_keys.h" |
23 #include "media/base/pipeline.h" | 21 #include "media/base/pipeline.h" |
24 #include "media/base/text_track.h" | 22 #include "media/base/text_track.h" |
25 #include "media/filters/skcanvas_video_renderer.h" | 23 #include "media/filters/skcanvas_video_renderer.h" |
26 #include "skia/ext/platform_canvas.h" | 24 #include "skia/ext/platform_canvas.h" |
27 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" | 25 #include "third_party/WebKit/public/platform/WebAudioSourceProvider.h" |
| 26 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" |
28 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 27 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
29 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 28 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
30 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 29 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
31 #include "url/gurl.h" | 30 #include "url/gurl.h" |
32 | 31 |
33 class RenderAudioSourceProvider; | |
34 | |
35 namespace blink { | 32 namespace blink { |
36 class WebContentDecryptionModule; | |
37 class WebContentDecryptionModuleResult; | |
38 class WebLocalFrame; | 33 class WebLocalFrame; |
39 } | 34 } |
40 | 35 |
41 namespace base { | 36 namespace base { |
42 class MessageLoopProxy; | 37 class MessageLoopProxy; |
43 } | 38 } |
44 | 39 |
45 namespace cc_blink { | 40 namespace cc_blink { |
46 class WebLayerImpl; | 41 class WebLayerImpl; |
47 } | 42 } |
48 | 43 |
49 namespace media { | 44 namespace media { |
50 class ChunkDemuxer; | 45 class ChunkDemuxer; |
51 class GpuVideoAcceleratorFactories; | 46 class GpuVideoAcceleratorFactories; |
52 class MediaLog; | 47 class MediaLog; |
53 } | 48 } |
54 | 49 |
55 | 50 |
56 namespace content { | 51 namespace content { |
57 class BufferedDataSource; | 52 class BufferedDataSource; |
| 53 class EncryptedMediaPlayerSupport; |
58 class VideoFrameCompositor; | 54 class VideoFrameCompositor; |
59 class WebAudioSourceProviderImpl; | 55 class WebAudioSourceProviderImpl; |
60 class WebContentDecryptionModuleImpl; | |
61 class WebMediaPlayerDelegate; | 56 class WebMediaPlayerDelegate; |
62 class WebMediaPlayerParams; | 57 class WebMediaPlayerParams; |
63 class WebTextTrackImpl; | 58 class WebTextTrackImpl; |
64 | 59 |
65 // The canonical implementation of blink::WebMediaPlayer that's backed by | 60 // The canonical implementation of blink::WebMediaPlayer that's backed by |
66 // media::Pipeline. Handles normal resource loading, Media Source, and | 61 // media::Pipeline. Handles normal resource loading, Media Source, and |
67 // Encrypted Media. | 62 // Encrypted Media. |
68 class WebMediaPlayerImpl | 63 class WebMediaPlayerImpl |
69 : public blink::WebMediaPlayer, | 64 : public blink::WebMediaPlayer, |
70 public base::SupportsWeakPtr<WebMediaPlayerImpl> { | 65 public base::SupportsWeakPtr<WebMediaPlayerImpl> { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 blink::WebContentDecryptionModuleResult result); | 165 blink::WebContentDecryptionModuleResult result); |
171 virtual void setContentDecryptionModuleSync( | 166 virtual void setContentDecryptionModuleSync( |
172 blink::WebContentDecryptionModule* cdm); | 167 blink::WebContentDecryptionModule* cdm); |
173 | 168 |
174 void OnPipelineSeeked(bool time_changed, media::PipelineStatus status); | 169 void OnPipelineSeeked(bool time_changed, media::PipelineStatus status); |
175 void OnPipelineEnded(); | 170 void OnPipelineEnded(); |
176 void OnPipelineError(media::PipelineStatus error); | 171 void OnPipelineError(media::PipelineStatus error); |
177 void OnPipelineMetadata(media::PipelineMetadata metadata); | 172 void OnPipelineMetadata(media::PipelineMetadata metadata); |
178 void OnPipelineBufferingStateChanged(media::BufferingState buffering_state); | 173 void OnPipelineBufferingStateChanged(media::BufferingState buffering_state); |
179 void OnDemuxerOpened(); | 174 void OnDemuxerOpened(); |
180 void OnKeyAdded(const std::string& session_id); | |
181 void OnKeyError(const std::string& session_id, | |
182 media::MediaKeys::KeyError error_code, | |
183 uint32 system_code); | |
184 void OnKeyMessage(const std::string& session_id, | |
185 const std::vector<uint8>& message, | |
186 const GURL& destination_url); | |
187 void OnNeedKey(const std::string& type, | |
188 const std::vector<uint8>& init_data); | |
189 void OnAddTextTrack(const media::TextTrackConfig& config, | 175 void OnAddTextTrack(const media::TextTrackConfig& config, |
190 const media::AddTextTrackDoneCB& done_cb); | 176 const media::AddTextTrackDoneCB& done_cb); |
191 | 177 |
192 private: | 178 private: |
193 // Called after |defer_load_cb_| has decided to allow the load. If | 179 // Called after |defer_load_cb_| has decided to allow the load. If |
194 // |defer_load_cb_| is null this is called immediately. | 180 // |defer_load_cb_| is null this is called immediately. |
195 void DoLoad(LoadType load_type, | 181 void DoLoad(LoadType load_type, |
196 const blink::WebURL& url, | 182 const blink::WebURL& url, |
197 CORSMode cors_mode); | 183 CORSMode cors_mode); |
198 | 184 |
(...skipping 10 matching lines...) Expand all Loading... |
209 void StartPipeline(); | 195 void StartPipeline(); |
210 | 196 |
211 // Helpers that set the network/ready state and notifies the client if | 197 // Helpers that set the network/ready state and notifies the client if |
212 // they've changed. | 198 // they've changed. |
213 void SetNetworkState(blink::WebMediaPlayer::NetworkState state); | 199 void SetNetworkState(blink::WebMediaPlayer::NetworkState state); |
214 void SetReadyState(blink::WebMediaPlayer::ReadyState state); | 200 void SetReadyState(blink::WebMediaPlayer::ReadyState state); |
215 | 201 |
216 // Lets V8 know that player uses extra resources not managed by V8. | 202 // Lets V8 know that player uses extra resources not managed by V8. |
217 void IncrementExternallyAllocatedMemory(); | 203 void IncrementExternallyAllocatedMemory(); |
218 | 204 |
219 // Actually do the work for generateKeyRequest/addKey so they can easily | |
220 // report results to UMA. | |
221 MediaKeyException GenerateKeyRequestInternal(const std::string& key_system, | |
222 const unsigned char* init_data, | |
223 unsigned init_data_length); | |
224 MediaKeyException AddKeyInternal(const std::string& key_system, | |
225 const unsigned char* key, | |
226 unsigned key_length, | |
227 const unsigned char* init_data, | |
228 unsigned init_data_length, | |
229 const std::string& session_id); | |
230 MediaKeyException CancelKeyRequestInternal(const std::string& key_system, | |
231 const std::string& session_id); | |
232 | |
233 // Gets the duration value reported by the pipeline. | 205 // Gets the duration value reported by the pipeline. |
234 double GetPipelineDuration() const; | 206 double GetPipelineDuration() const; |
235 | 207 |
236 // Callbacks from |pipeline_| that are forwarded to |client_|. | 208 // Callbacks from |pipeline_| that are forwarded to |client_|. |
237 void OnDurationChanged(); | 209 void OnDurationChanged(); |
238 void OnNaturalSizeChanged(gfx::Size size); | 210 void OnNaturalSizeChanged(gfx::Size size); |
239 void OnOpacityChanged(bool opaque); | 211 void OnOpacityChanged(bool opaque); |
240 | 212 |
241 // Called by VideoRendererImpl on its internal thread with the new frame to be | 213 // Called by VideoRendererImpl on its internal thread with the new frame to be |
242 // painted. | 214 // painted. |
243 void FrameReady(const scoped_refptr<media::VideoFrame>& frame); | 215 void FrameReady(const scoped_refptr<media::VideoFrame>& frame); |
244 | 216 |
245 // Requests that this object notifies when a decryptor is ready through the | |
246 // |decryptor_ready_cb| provided. | |
247 // If |decryptor_ready_cb| is null, the existing callback will be fired with | |
248 // NULL immediately and reset. | |
249 void SetDecryptorReadyCB(const media::DecryptorReadyCB& decryptor_ready_cb); | |
250 | |
251 // Called when the ContentDecryptionModule has been attached to the | 217 // Called when the ContentDecryptionModule has been attached to the |
252 // pipeline/decoders. | 218 // pipeline/decoders. |
253 void ContentDecryptionModuleAttached( | 219 void ContentDecryptionModuleAttached( |
254 blink::WebContentDecryptionModuleResult result, | 220 blink::WebContentDecryptionModuleResult result, |
255 bool success); | 221 bool success); |
256 | 222 |
257 // Returns the current video frame from |compositor_|. Blocks until the | 223 // Returns the current video frame from |compositor_|. Blocks until the |
258 // compositor can return the frame. | 224 // compositor can return the frame. |
259 scoped_refptr<media::VideoFrame> GetCurrentFrameFromCompositor(); | 225 scoped_refptr<media::VideoFrame> GetCurrentFrameFromCompositor(); |
260 | 226 |
261 blink::WebLocalFrame* frame_; | 227 blink::WebLocalFrame* frame_; |
262 | 228 |
263 // TODO(hclam): get rid of these members and read from the pipeline directly. | 229 // TODO(hclam): get rid of these members and read from the pipeline directly. |
264 blink::WebMediaPlayer::NetworkState network_state_; | 230 blink::WebMediaPlayer::NetworkState network_state_; |
265 blink::WebMediaPlayer::ReadyState ready_state_; | 231 blink::WebMediaPlayer::ReadyState ready_state_; |
266 | 232 |
267 // Preload state for when |data_source_| is created after setPreload(). | 233 // Preload state for when |data_source_| is created after setPreload(). |
268 content::Preload preload_; | 234 content::Preload preload_; |
269 | 235 |
270 // Message loops for posting tasks on Chrome's main thread. Also used | 236 // Message loops for posting tasks on Chrome's main thread. Also used |
271 // for DCHECKs so methods calls won't execute in the wrong thread. | 237 // for DCHECKs so methods calls won't execute in the wrong thread. |
272 const scoped_refptr<base::MessageLoopProxy> main_loop_; | 238 const scoped_refptr<base::MessageLoopProxy> main_loop_; |
273 | 239 |
274 scoped_refptr<base::MessageLoopProxy> media_loop_; | 240 scoped_refptr<base::MessageLoopProxy> media_loop_; |
275 scoped_refptr<media::MediaLog> media_log_; | 241 scoped_refptr<media::MediaLog> media_log_; |
276 media::Pipeline pipeline_; | 242 media::Pipeline pipeline_; |
277 | 243 |
278 // The currently selected key system. Empty string means that no key system | |
279 // has been selected. | |
280 std::string current_key_system_; | |
281 | |
282 // The LoadType passed in the |load_type| parameter of the load() call. | 244 // The LoadType passed in the |load_type| parameter of the load() call. |
283 LoadType load_type_; | 245 LoadType load_type_; |
284 | 246 |
285 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize(). | 247 // Cache of metadata for answering hasAudio(), hasVideo(), and naturalSize(). |
286 media::PipelineMetadata pipeline_metadata_; | 248 media::PipelineMetadata pipeline_metadata_; |
287 | 249 |
288 // Whether the video is known to be opaque or not. | 250 // Whether the video is known to be opaque or not. |
289 bool opaque_; | 251 bool opaque_; |
290 | 252 |
291 // Playback state. | 253 // Playback state. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // |chunk_demuxer_| is used for Media Source resource loads. | 297 // |chunk_demuxer_| is used for Media Source resource loads. |
336 // | 298 // |
337 // |demuxer_| will contain the appropriate demuxer based on which resource | 299 // |demuxer_| will contain the appropriate demuxer based on which resource |
338 // load strategy we're using. | 300 // load strategy we're using. |
339 scoped_ptr<BufferedDataSource> data_source_; | 301 scoped_ptr<BufferedDataSource> data_source_; |
340 scoped_ptr<media::Demuxer> demuxer_; | 302 scoped_ptr<media::Demuxer> demuxer_; |
341 media::ChunkDemuxer* chunk_demuxer_; | 303 media::ChunkDemuxer* chunk_demuxer_; |
342 | 304 |
343 BufferedDataSourceHostImpl buffered_data_source_host_; | 305 BufferedDataSourceHostImpl buffered_data_source_host_; |
344 | 306 |
345 // Temporary for EME v0.1. In the future the init data type should be passed | |
346 // through GenerateKeyRequest() directly from WebKit. | |
347 std::string init_data_type_; | |
348 | |
349 // Video rendering members. | 307 // Video rendering members. |
350 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | 308 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
351 VideoFrameCompositor* compositor_; // Deleted on |compositor_task_runner_|. | 309 VideoFrameCompositor* compositor_; // Deleted on |compositor_task_runner_|. |
352 media::SkCanvasVideoRenderer skcanvas_video_renderer_; | 310 media::SkCanvasVideoRenderer skcanvas_video_renderer_; |
353 | 311 |
354 // The compositor layer for displaying the video content when using composited | 312 // The compositor layer for displaying the video content when using composited |
355 // playback. | 313 // playback. |
356 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; | 314 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; |
357 | 315 |
358 // Text track objects get a unique index value when they're created. | 316 // Text track objects get a unique index value when they're created. |
359 int text_track_index_; | 317 int text_track_index_; |
360 | 318 |
361 // Manages decryption keys and decrypts encrypted frames. | 319 scoped_ptr<EncryptedMediaPlayerSupport> encrypted_media_support_; |
362 scoped_ptr<ProxyDecryptor> proxy_decryptor_; | |
363 | |
364 // Non-owned pointer to the CDM. Updated via calls to | |
365 // setContentDecryptionModule(). | |
366 WebContentDecryptionModuleImpl* web_cdm_; | |
367 | |
368 media::DecryptorReadyCB decryptor_ready_cb_; | |
369 | 320 |
370 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); | 321 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerImpl); |
371 }; | 322 }; |
372 | 323 |
373 } // namespace content | 324 } // namespace content |
374 | 325 |
375 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_ | 326 #endif // CONTENT_RENDERER_MEDIA_WEBMEDIAPLAYER_IMPL_H_ |
OLD | NEW |