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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
18 #include "base/time/default_tick_clock.h" | 18 #include "base/time/default_tick_clock.h" |
19 #include "base/time/time.h" | 19 #include "base/time/time.h" |
20 #include "cc/layers/video_frame_provider.h" | 20 #include "cc/layers/video_frame_provider.h" |
21 #include "content/public/renderer/render_frame_observer.h" | |
22 #include "content/renderer/media/android/media_info_loader.h" | 21 #include "content/renderer/media/android/media_info_loader.h" |
23 #include "content/renderer/media/android/media_source_delegate.h" | 22 #include "content/renderer/media/android/media_source_delegate.h" |
24 #include "content/renderer/media/android/renderer_media_player_manager.h" | 23 #include "content/renderer/media/android/renderer_media_player_manager.h" |
25 #include "content/renderer/media/android/stream_texture_factory.h" | 24 #include "content/renderer/media/android/stream_texture_factory.h" |
26 #include "gpu/command_buffer/common/mailbox.h" | 25 #include "gpu/command_buffer/common/mailbox.h" |
27 #include "media/base/android/media_player_android.h" | 26 #include "media/base/android/media_player_android.h" |
28 #include "media/base/cdm_context.h" | 27 #include "media/base/cdm_context.h" |
29 #include "media/base/demuxer_stream.h" | 28 #include "media/base/demuxer_stream.h" |
30 #include "media/base/media_keys.h" | 29 #include "media/base/media_keys.h" |
31 #include "media/base/time_delta_interpolator.h" | 30 #include "media/base/time_delta_interpolator.h" |
| 31 #include "media/blink/webmediaplayer_delegate.h" |
32 #include "media/blink/webmediaplayer_params.h" | 32 #include "media/blink/webmediaplayer_params.h" |
33 #include "media/cdm/proxy_decryptor.h" | 33 #include "media/cdm/proxy_decryptor.h" |
34 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" | 34 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" |
35 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 35 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
36 #include "third_party/WebKit/public/platform/WebSetSinkIdCallbacks.h" | 36 #include "third_party/WebKit/public/platform/WebSetSinkIdCallbacks.h" |
37 #include "third_party/WebKit/public/platform/WebSize.h" | 37 #include "third_party/WebKit/public/platform/WebSize.h" |
38 #include "third_party/WebKit/public/platform/WebURL.h" | 38 #include "third_party/WebKit/public/platform/WebURL.h" |
39 #include "third_party/skia/include/core/SkBitmap.h" | 39 #include "third_party/skia/include/core/SkBitmap.h" |
40 #include "ui/gfx/geometry/rect_f.h" | 40 #include "ui/gfx/geometry/rect_f.h" |
41 | 41 |
(...skipping 17 matching lines...) Expand all Loading... |
59 namespace gpu { | 59 namespace gpu { |
60 struct MailboxHolder; | 60 struct MailboxHolder; |
61 } | 61 } |
62 | 62 |
63 namespace media { | 63 namespace media { |
64 class CdmContext; | 64 class CdmContext; |
65 class CdmFactory; | 65 class CdmFactory; |
66 class MediaLog; | 66 class MediaLog; |
67 class MediaPermission; | 67 class MediaPermission; |
68 class WebContentDecryptionModuleImpl; | 68 class WebContentDecryptionModuleImpl; |
69 class WebMediaPlayerDelegate; | |
70 } | 69 } |
71 | 70 |
72 namespace content { | 71 namespace content { |
73 | 72 |
74 class RendererCdmManager; | 73 class RendererCdmManager; |
75 class RendererMediaPlayerManager; | 74 class RendererMediaPlayerManager; |
76 | 75 |
77 // This class implements blink::WebMediaPlayer by keeping the android | 76 // This class implements blink::WebMediaPlayer by keeping the android |
78 // media player in the browser process. It listens to all the status changes | 77 // media player in the browser process. It listens to all the status changes |
79 // sent from the browser process and sends playback controls to the media | 78 // sent from the browser process and sends playback controls to the media |
80 // player. | 79 // player. |
81 class WebMediaPlayerAndroid : public blink::WebMediaPlayer, | 80 class WebMediaPlayerAndroid |
82 public cc::VideoFrameProvider, | 81 : public blink::WebMediaPlayer, |
83 public RenderFrameObserver, | 82 public cc::VideoFrameProvider, |
84 public StreamTextureFactoryContextObserver, | 83 public StreamTextureFactoryContextObserver, |
85 public media::RendererMediaPlayerInterface { | 84 public media::RendererMediaPlayerInterface, |
| 85 public NON_EXPORTED_BASE(media::WebMediaPlayerDelegate::Observer) { |
86 public: | 86 public: |
87 // Construct a WebMediaPlayerAndroid object. This class communicates with the | 87 // Construct a WebMediaPlayerAndroid object. This class communicates with the |
88 // MediaPlayerAndroid object in the browser process through |proxy|. | 88 // MediaPlayerAndroid object in the browser process through |proxy|. |
89 // TODO(qinmin): |frame| argument is used to determine whether the current | 89 // TODO(qinmin): |frame| argument is used to determine whether the current |
90 // player can enter fullscreen. This logic should probably be moved into | 90 // player can enter fullscreen. This logic should probably be moved into |
91 // blink, so that enterFullscreen() will not be called if another video is | 91 // blink, so that enterFullscreen() will not be called if another video is |
92 // already in fullscreen. | 92 // already in fullscreen. |
93 WebMediaPlayerAndroid( | 93 WebMediaPlayerAndroid( |
94 blink::WebFrame* frame, | 94 blink::WebFrame* frame, |
95 blink::WebMediaPlayerClient* client, | 95 blink::WebMediaPlayerClient* client, |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 void ResetStreamTextureProxy() override; | 219 void ResetStreamTextureProxy() override; |
220 | 220 |
221 // Called when the player is released. | 221 // Called when the player is released. |
222 void OnPlayerReleased() override; | 222 void OnPlayerReleased() override; |
223 | 223 |
224 // This function is called by the RendererMediaPlayerManager to pause the | 224 // This function is called by the RendererMediaPlayerManager to pause the |
225 // video and release the media player and surface texture when we switch tabs. | 225 // video and release the media player and surface texture when we switch tabs. |
226 // However, the actual GlTexture is not released to keep the video screenshot. | 226 // However, the actual GlTexture is not released to keep the video screenshot. |
227 void SuspendAndReleaseResources() override; | 227 void SuspendAndReleaseResources() override; |
228 | 228 |
229 // RenderFrameObserver implementation. | |
230 void OnDestruct() override; | |
231 | |
232 #if defined(VIDEO_HOLE) | 229 #if defined(VIDEO_HOLE) |
233 // Calculate the boundary rectangle of the media player (i.e. location and | 230 // Calculate the boundary rectangle of the media player (i.e. location and |
234 // size of the video frame). | 231 // size of the video frame). |
235 // Returns true if the geometry has been changed since the last call. | 232 // Returns true if the geometry has been changed since the last call. |
236 bool UpdateBoundaryRectangle() override; | 233 bool UpdateBoundaryRectangle() override; |
237 | 234 |
238 const gfx::RectF GetBoundaryRectangle() override; | 235 const gfx::RectF GetBoundaryRectangle() override; |
239 #endif // defined(VIDEO_HOLE) | 236 #endif // defined(VIDEO_HOLE) |
240 | 237 |
241 MediaKeyException generateKeyRequest(const blink::WebString& key_system, | 238 MediaKeyException generateKeyRequest(const blink::WebString& key_system, |
(...skipping 23 matching lines...) Expand all Loading... |
265 | 262 |
266 void OnMediaSourceOpened(blink::WebMediaSource* web_media_source); | 263 void OnMediaSourceOpened(blink::WebMediaSource* web_media_source); |
267 | 264 |
268 void OnEncryptedMediaInitData(media::EmeInitDataType init_data_type, | 265 void OnEncryptedMediaInitData(media::EmeInitDataType init_data_type, |
269 const std::vector<uint8_t>& init_data); | 266 const std::vector<uint8_t>& init_data); |
270 | 267 |
271 // Called when a decoder detects that the key needed to decrypt the stream | 268 // Called when a decoder detects that the key needed to decrypt the stream |
272 // is not available. | 269 // is not available. |
273 void OnWaitingForDecryptionKey() override; | 270 void OnWaitingForDecryptionKey() override; |
274 | 271 |
| 272 // WebMediaPlayerDelegate::Observer implementation. |
| 273 void OnHidden() override; |
| 274 void OnShown() override; |
| 275 void OnPlay() override; |
| 276 void OnPause() override; |
| 277 void OnVolumeMultiplierUpdate(double multiplier) override; |
| 278 |
275 protected: | 279 protected: |
276 // Helper method to update the playing state. | 280 // Helper method to update the playing state. |
277 void UpdatePlayingState(bool is_playing_); | 281 void UpdatePlayingState(bool is_playing_); |
278 | 282 |
279 // Helper methods for posting task for setting states and update WebKit. | 283 // Helper methods for posting task for setting states and update WebKit. |
280 void UpdateNetworkState(blink::WebMediaPlayer::NetworkState state); | 284 void UpdateNetworkState(blink::WebMediaPlayer::NetworkState state); |
281 void UpdateReadyState(blink::WebMediaPlayer::ReadyState state); | 285 void UpdateReadyState(blink::WebMediaPlayer::ReadyState state); |
282 void TryCreateStreamTextureProxyIfNeeded(); | 286 void TryCreateStreamTextureProxyIfNeeded(); |
283 void DoCreateStreamTexture(); | 287 void DoCreateStreamTexture(); |
284 | 288 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 | 354 |
351 // Called after |defer_load_cb_| has decided to allow the load. If | 355 // Called after |defer_load_cb_| has decided to allow the load. If |
352 // |defer_load_cb_| is null this is called immediately. | 356 // |defer_load_cb_| is null this is called immediately. |
353 void DoLoad(LoadType load_type, const blink::WebURL& url, CORSMode cors_mode); | 357 void DoLoad(LoadType load_type, const blink::WebURL& url, CORSMode cors_mode); |
354 | 358 |
355 blink::WebFrame* const frame_; | 359 blink::WebFrame* const frame_; |
356 | 360 |
357 blink::WebMediaPlayerClient* const client_; | 361 blink::WebMediaPlayerClient* const client_; |
358 blink::WebMediaPlayerEncryptedMediaClient* const encrypted_client_; | 362 blink::WebMediaPlayerEncryptedMediaClient* const encrypted_client_; |
359 | 363 |
360 // |delegate_| is used to notify the browser process of the player status, so | 364 // WebMediaPlayer notifies the |delegate_| of playback state changes using |
361 // that the browser process can control screen locks. | 365 // |delegate_id_|; an id provided after registering with the delegate. The |
362 // TODO(qinmin): Currently android mediaplayer takes care of the screen | 366 // WebMediaPlayer may also receive directives (play, pause) from the delegate |
363 // lock. So this is only used for media source. Will apply this to regular | 367 // via the WebMediaPlayerDelegate::Observer interface after registration. |
364 // media tag once http://crbug.com/247892 is fixed. | |
365 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; | 368 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; |
| 369 int delegate_id_; |
366 | 370 |
367 // Callback responsible for determining if loading of media should be deferred | 371 // Callback responsible for determining if loading of media should be deferred |
368 // for external reasons; called during load(). | 372 // for external reasons; called during load(). |
369 media::WebMediaPlayerParams::DeferLoadCB defer_load_cb_; | 373 media::WebMediaPlayerParams::DeferLoadCB defer_load_cb_; |
370 | 374 |
371 // Save the list of buffered time ranges. | 375 // Save the list of buffered time ranges. |
372 blink::WebTimeRanges buffered_; | 376 blink::WebTimeRanges buffered_; |
373 | 377 |
374 // Size of the video. | 378 // Size of the video. |
375 blink::WebSize natural_size_; | 379 blink::WebSize natural_size_; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
537 | 541 |
538 int frame_id_; | 542 int frame_id_; |
539 | 543 |
540 // Whether to require that surface textures are copied in order to support | 544 // Whether to require that surface textures are copied in order to support |
541 // sharing between render and gpu threads in WebView. | 545 // sharing between render and gpu threads in WebView. |
542 bool enable_texture_copy_; | 546 bool enable_texture_copy_; |
543 | 547 |
544 // Whether to delete the existing texture and re-create it. | 548 // Whether to delete the existing texture and re-create it. |
545 bool suppress_deleting_texture_; | 549 bool suppress_deleting_texture_; |
546 | 550 |
| 551 // Whether OnPlaybackComplete() has been called since the last playback. |
| 552 bool playback_completed_; |
| 553 |
| 554 // The last volume received by setVolume() and the last volume multiplier from |
| 555 // OnVolumeMultiplierUpdate(). The multiplier is typical 1.0, but may be less |
| 556 // if the WebMediaPlayerDelegate has requested a volume reduction (ducking) |
| 557 // for a transient sound. Playout volume is derived by volume * multiplier. |
| 558 double volume_; |
| 559 double volume_multiplier_; |
| 560 |
547 // NOTE: Weak pointers must be invalidated before all other member variables. | 561 // NOTE: Weak pointers must be invalidated before all other member variables. |
548 base::WeakPtrFactory<WebMediaPlayerAndroid> weak_factory_; | 562 base::WeakPtrFactory<WebMediaPlayerAndroid> weak_factory_; |
549 | 563 |
550 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); | 564 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); |
551 }; | 565 }; |
552 | 566 |
553 } // namespace content | 567 } // namespace content |
554 | 568 |
555 #endif // CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 569 #endif // CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
OLD | NEW |