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_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
6 #define CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 6 #define CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/synchronization/waitable_event.h" |
16 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
18 #include "cc/layers/video_frame_provider.h" | 19 #include "cc/layers/video_frame_provider.h" |
19 #include "content/common/media/media_player_messages_enums_android.h" | 20 #include "content/common/media/media_player_messages_enums_android.h" |
20 #include "content/public/renderer/render_frame_observer.h" | 21 #include "content/public/renderer/render_frame_observer.h" |
21 #include "content/renderer/media/android/media_info_loader.h" | 22 #include "content/renderer/media/android/media_info_loader.h" |
22 #include "content/renderer/media/android/media_source_delegate.h" | 23 #include "content/renderer/media/android/media_source_delegate.h" |
23 #include "content/renderer/media/android/stream_texture_factory.h" | 24 #include "content/renderer/media/android/stream_texture_factory.h" |
24 #include "content/renderer/media/crypto/proxy_decryptor.h" | 25 #include "content/renderer/media/crypto/proxy_decryptor.h" |
25 #include "gpu/command_buffer/common/mailbox.h" | 26 #include "gpu/command_buffer/common/mailbox.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 class RendererCdmManager; | 64 class RendererCdmManager; |
64 class RendererMediaPlayerManager; | 65 class RendererMediaPlayerManager; |
65 class WebContentDecryptionModuleImpl; | 66 class WebContentDecryptionModuleImpl; |
66 | 67 |
67 // This class implements blink::WebMediaPlayer by keeping the android | 68 // This class implements blink::WebMediaPlayer by keeping the android |
68 // media player in the browser process. It listens to all the status changes | 69 // media player in the browser process. It listens to all the status changes |
69 // sent from the browser process and sends playback controls to the media | 70 // sent from the browser process and sends playback controls to the media |
70 // player. | 71 // player. |
71 class WebMediaPlayerAndroid : public blink::WebMediaPlayer, | 72 class WebMediaPlayerAndroid : public blink::WebMediaPlayer, |
72 public cc::VideoFrameProvider, | 73 public cc::VideoFrameProvider, |
73 public RenderFrameObserver { | 74 public RenderFrameObserver, |
| 75 public StreamTextureFactoryContextObserver { |
74 public: | 76 public: |
75 // Construct a WebMediaPlayerAndroid object. This class communicates with the | 77 // Construct a WebMediaPlayerAndroid object. This class communicates with the |
76 // MediaPlayerAndroid object in the browser process through |proxy|. | 78 // MediaPlayerAndroid object in the browser process through |proxy|. |
77 // TODO(qinmin): |frame| argument is used to determine whether the current | 79 // TODO(qinmin): |frame| argument is used to determine whether the current |
78 // player can enter fullscreen. This logic should probably be moved into | 80 // player can enter fullscreen. This logic should probably be moved into |
79 // blink, so that enterFullscreen() will not be called if another video is | 81 // blink, so that enterFullscreen() will not be called if another video is |
80 // already in fullscreen. | 82 // already in fullscreen. |
81 WebMediaPlayerAndroid( | 83 WebMediaPlayerAndroid( |
82 blink::WebFrame* frame, | 84 blink::WebFrame* frame, |
83 blink::WebMediaPlayerClient* client, | 85 blink::WebMediaPlayerClient* client, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 | 191 |
190 // Functions called when media player status changes. | 192 // Functions called when media player status changes. |
191 void OnConnectedToRemoteDevice(const std::string& remote_playback_message); | 193 void OnConnectedToRemoteDevice(const std::string& remote_playback_message); |
192 void OnDisconnectedFromRemoteDevice(); | 194 void OnDisconnectedFromRemoteDevice(); |
193 void OnDidEnterFullscreen(); | 195 void OnDidEnterFullscreen(); |
194 void OnDidExitFullscreen(); | 196 void OnDidExitFullscreen(); |
195 void OnMediaPlayerPlay(); | 197 void OnMediaPlayerPlay(); |
196 void OnMediaPlayerPause(); | 198 void OnMediaPlayerPause(); |
197 void OnRequestFullscreen(); | 199 void OnRequestFullscreen(); |
198 | 200 |
| 201 // StreamTextureFactoryContextObserver implementation. |
| 202 virtual void ResetStreamTextureProxy() OVERRIDE; |
| 203 |
199 // Called when the player is released. | 204 // Called when the player is released. |
200 virtual void OnPlayerReleased(); | 205 virtual void OnPlayerReleased(); |
201 | 206 |
202 // This function is called by the RendererMediaPlayerManager to pause the | 207 // This function is called by the RendererMediaPlayerManager to pause the |
203 // video and release the media player and surface texture when we switch tabs. | 208 // video and release the media player and surface texture when we switch tabs. |
204 // However, the actual GlTexture is not released to keep the video screenshot. | 209 // However, the actual GlTexture is not released to keep the video screenshot. |
205 virtual void ReleaseMediaResources(); | 210 virtual void ReleaseMediaResources(); |
206 | 211 |
207 // RenderFrameObserver implementation. | 212 // RenderFrameObserver implementation. |
208 virtual void OnDestruct() OVERRIDE; | 213 virtual void OnDestruct() OVERRIDE; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 | 280 |
276 private: | 281 private: |
277 void InitializePlayer(const GURL& url, | 282 void InitializePlayer(const GURL& url, |
278 const GURL& first_party_for_cookies, | 283 const GURL& first_party_for_cookies, |
279 bool allowed_stored_credentials, | 284 bool allowed_stored_credentials, |
280 int demuxer_client_id); | 285 int demuxer_client_id); |
281 void Pause(bool is_media_related_action); | 286 void Pause(bool is_media_related_action); |
282 void DrawRemotePlaybackText(const std::string& remote_playback_message); | 287 void DrawRemotePlaybackText(const std::string& remote_playback_message); |
283 void ReallocateVideoFrame(); | 288 void ReallocateVideoFrame(); |
284 void SetCurrentFrameInternal(scoped_refptr<media::VideoFrame>& frame); | 289 void SetCurrentFrameInternal(scoped_refptr<media::VideoFrame>& frame); |
| 290 void BindStreamTextureProxyOnCompositorThread( |
| 291 base::WaitableEvent* completion); |
285 void DidLoadMediaInfo(MediaInfoLoader::Status status, | 292 void DidLoadMediaInfo(MediaInfoLoader::Status status, |
286 const GURL& redirected_url, | 293 const GURL& redirected_url, |
287 const GURL& first_party_for_cookies, | 294 const GURL& first_party_for_cookies, |
288 bool allow_stored_credentials); | 295 bool allow_stored_credentials); |
289 bool IsKeySystemSupported(const std::string& key_system); | 296 bool IsKeySystemSupported(const std::string& key_system); |
290 bool IsLocalResource(); | 297 bool IsLocalResource(); |
291 | 298 |
292 // Actually do the work for generateKeyRequest/addKey so they can easily | 299 // Actually do the work for generateKeyRequest/addKey so they can easily |
293 // report results to UMA. | 300 // report results to UMA. |
294 MediaKeyException GenerateKeyRequestInternal(const std::string& key_system, | 301 MediaKeyException GenerateKeyRequestInternal(const std::string& key_system, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 // Stream texture ID allocated to the video. | 411 // Stream texture ID allocated to the video. |
405 unsigned int stream_id_; | 412 unsigned int stream_id_; |
406 | 413 |
407 // Whether the mediaplayer is playing. | 414 // Whether the mediaplayer is playing. |
408 bool is_playing_; | 415 bool is_playing_; |
409 | 416 |
410 // Whether media player needs to re-establish the surface texture peer. | 417 // Whether media player needs to re-establish the surface texture peer. |
411 bool needs_establish_peer_; | 418 bool needs_establish_peer_; |
412 | 419 |
413 // Whether |stream_texture_proxy_| is initialized. | 420 // Whether |stream_texture_proxy_| is initialized. |
| 421 // Accessed on main thread and on compositor thread when main thread is |
| 422 // blocked. |
414 bool stream_texture_proxy_initialized_; | 423 bool stream_texture_proxy_initialized_; |
415 | 424 |
416 // Whether the video size info is available. | 425 // Whether the video size info is available. |
417 bool has_size_info_; | 426 bool has_size_info_; |
418 | 427 |
419 // Object for allocating stream textures. | 428 // Object for allocating stream textures. |
420 scoped_refptr<StreamTextureFactory> stream_texture_factory_; | 429 scoped_refptr<StreamTextureFactory> stream_texture_factory_; |
421 | 430 |
422 // Object for calling back the compositor thread to repaint the video when a | 431 // Object for calling back the compositor thread to repaint the video when a |
423 // frame available. It should be initialized on the compositor thread. | 432 // frame available. It should be initialized on the compositor thread. |
| 433 // Accessed on main thread and on compositor thread when main thread is |
| 434 // blocked. |
424 ScopedStreamTextureProxy stream_texture_proxy_; | 435 ScopedStreamTextureProxy stream_texture_proxy_; |
425 | 436 |
426 // Whether media player needs external surface. | 437 // Whether media player needs external surface. |
427 // Only used for the VIDEO_HOLE logic. | 438 // Only used for the VIDEO_HOLE logic. |
428 bool needs_external_surface_; | 439 bool needs_external_surface_; |
429 | 440 |
430 // Whether valid metadata are available | 441 // Whether valid metadata are available |
431 bool has_valid_metadata_; | 442 bool has_valid_metadata_; |
432 | 443 |
433 // A pointer back to the compositor to inform it about state changes. This is | 444 // A pointer back to the compositor to inform it about state changes. This is |
434 // not NULL while the compositor is actively using this webmediaplayer. | 445 // not NULL while the compositor is actively using this webmediaplayer. |
| 446 // Accessed on main thread and on compositor thread when main thread is |
| 447 // blocked. |
435 cc::VideoFrameProvider::Client* video_frame_provider_client_; | 448 cc::VideoFrameProvider::Client* video_frame_provider_client_; |
436 | 449 |
437 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; | 450 scoped_ptr<cc_blink::WebLayerImpl> video_weblayer_; |
438 | 451 |
439 #if defined(VIDEO_HOLE) | 452 #if defined(VIDEO_HOLE) |
440 // A rectangle represents the geometry of video frame, when computed last | 453 // A rectangle represents the geometry of video frame, when computed last |
441 // time. | 454 // time. |
442 gfx::RectF last_computed_rect_; | 455 gfx::RectF last_computed_rect_; |
443 | 456 |
444 // Whether to use the video overlay for all embedded video. | 457 // Whether to use the video overlay for all embedded video. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 511 |
499 // NOTE: Weak pointers must be invalidated before all other member variables. | 512 // NOTE: Weak pointers must be invalidated before all other member variables. |
500 base::WeakPtrFactory<WebMediaPlayerAndroid> weak_factory_; | 513 base::WeakPtrFactory<WebMediaPlayerAndroid> weak_factory_; |
501 | 514 |
502 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); | 515 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); |
503 }; | 516 }; |
504 | 517 |
505 } // namespace content | 518 } // namespace content |
506 | 519 |
507 #endif // CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 520 #endif // CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
OLD | NEW |