| 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 <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.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/renderer/media/android/media_info_loader.h" | 21 #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/renderer_media_player_manager.h" | 22 #include "content/renderer/media/android/renderer_media_player_manager.h" |
| 24 #include "content/renderer/media/android/stream_texture_factory.h" | 23 #include "content/renderer/media/android/stream_texture_factory.h" |
| 25 #include "gpu/command_buffer/common/mailbox.h" | 24 #include "gpu/command_buffer/common/mailbox.h" |
| 26 #include "media/base/android/media_player_android.h" | 25 #include "media/base/android/media_player_android.h" |
| 27 #include "media/base/cdm_context.h" | |
| 28 #include "media/base/demuxer_stream.h" | |
| 29 #include "media/base/eme_constants.h" | |
| 30 #include "media/base/media_keys.h" | |
| 31 #include "media/base/time_delta_interpolator.h" | 26 #include "media/base/time_delta_interpolator.h" |
| 32 #include "media/blink/webmediaplayer_delegate.h" | 27 #include "media/blink/webmediaplayer_delegate.h" |
| 33 #include "media/blink/webmediaplayer_params.h" | 28 #include "media/blink/webmediaplayer_params.h" |
| 34 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" | 29 #include "third_party/WebKit/public/platform/WebMediaPlayer.h" |
| 35 #include "third_party/WebKit/public/platform/WebSetSinkIdCallbacks.h" | 30 #include "third_party/WebKit/public/platform/WebSetSinkIdCallbacks.h" |
| 36 #include "third_party/WebKit/public/platform/WebSize.h" | 31 #include "third_party/WebKit/public/platform/WebSize.h" |
| 37 #include "third_party/WebKit/public/platform/WebURL.h" | 32 #include "third_party/WebKit/public/platform/WebURL.h" |
| 38 #include "ui/gfx/geometry/rect_f.h" | 33 #include "ui/gfx/geometry/rect_f.h" |
| 39 | 34 |
| 40 namespace base { | 35 namespace base { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 184 |
| 190 // Media player callback handlers. | 185 // Media player callback handlers. |
| 191 void OnMediaMetadataChanged(base::TimeDelta duration, int width, | 186 void OnMediaMetadataChanged(base::TimeDelta duration, int width, |
| 192 int height, bool success) override; | 187 int height, bool success) override; |
| 193 void OnPlaybackComplete() override; | 188 void OnPlaybackComplete() override; |
| 194 void OnBufferingUpdate(int percentage) override; | 189 void OnBufferingUpdate(int percentage) override; |
| 195 void OnSeekRequest(const base::TimeDelta& time_to_seek) override; | 190 void OnSeekRequest(const base::TimeDelta& time_to_seek) override; |
| 196 void OnSeekComplete(const base::TimeDelta& current_time) override; | 191 void OnSeekComplete(const base::TimeDelta& current_time) override; |
| 197 void OnMediaError(int error_type) override; | 192 void OnMediaError(int error_type) override; |
| 198 void OnVideoSizeChanged(int width, int height) override; | 193 void OnVideoSizeChanged(int width, int height) override; |
| 199 void OnDurationChanged(const base::TimeDelta& duration); | |
| 200 | 194 |
| 201 // Called to update the current time. | 195 // Called to update the current time. |
| 202 void OnTimeUpdate(base::TimeDelta current_timestamp, | 196 void OnTimeUpdate(base::TimeDelta current_timestamp, |
| 203 base::TimeTicks current_time_ticks) override; | 197 base::TimeTicks current_time_ticks) override; |
| 204 | 198 |
| 205 // Functions called when media player status changes. | 199 // Functions called when media player status changes. |
| 206 void OnConnectedToRemoteDevice(const std::string& remote_playback_message) | 200 void OnConnectedToRemoteDevice(const std::string& remote_playback_message) |
| 207 override; | 201 override; |
| 208 void OnDisconnectedFromRemoteDevice() override; | 202 void OnDisconnectedFromRemoteDevice() override; |
| 209 void OnCancelledRemotePlaybackRequest() override; | 203 void OnCancelledRemotePlaybackRequest() override; |
| 210 void OnDidExitFullscreen() override; | 204 void OnDidExitFullscreen() override; |
| 211 void OnMediaPlayerPlay() override; | 205 void OnMediaPlayerPlay() override; |
| 212 void OnMediaPlayerPause() override; | 206 void OnMediaPlayerPause() override; |
| 213 void OnRemoteRouteAvailabilityChanged(bool routes_available) override; | 207 void OnRemoteRouteAvailabilityChanged(bool routes_available) override; |
| 214 | 208 |
| 215 // Called when the player is released. | 209 // Called when the player is released. |
| 216 void OnPlayerReleased() override; | 210 void OnPlayerReleased() override; |
| 217 | 211 |
| 218 // This function is called by the RendererMediaPlayerManager to pause the | 212 // This function is called by the RendererMediaPlayerManager to pause the |
| 219 // video and release the media player and surface texture when we switch tabs. | 213 // video and release the media player and surface texture when we switch tabs. |
| 220 // However, the actual GlTexture is not released to keep the video screenshot. | 214 // However, the actual GlTexture is not released to keep the video screenshot. |
| 221 void SuspendAndReleaseResources() override; | 215 void SuspendAndReleaseResources() override; |
| 222 | 216 |
| 223 void setContentDecryptionModule( | 217 void setContentDecryptionModule( |
| 224 blink::WebContentDecryptionModule* cdm, | 218 blink::WebContentDecryptionModule* cdm, |
| 225 blink::WebContentDecryptionModuleResult result) override; | 219 blink::WebContentDecryptionModuleResult result) override; |
| 226 | 220 |
| 227 void OnMediaSourceOpened(blink::WebMediaSource* web_media_source); | |
| 228 | |
| 229 void OnEncryptedMediaInitData(media::EmeInitDataType init_data_type, | |
| 230 const std::vector<uint8_t>& init_data); | |
| 231 | |
| 232 // Called when a decoder detects that the key needed to decrypt the stream | |
| 233 // is not available. | |
| 234 void OnWaitingForDecryptionKey() override; | |
| 235 | |
| 236 // WebMediaPlayerDelegate::Observer implementation. | 221 // WebMediaPlayerDelegate::Observer implementation. |
| 237 void OnHidden() override; | 222 void OnHidden() override; |
| 238 void OnShown() override; | 223 void OnShown() override; |
| 239 void OnSuspendRequested(bool must_suspend) override; | 224 void OnSuspendRequested(bool must_suspend) override; |
| 240 void OnPlay() override; | 225 void OnPlay() override; |
| 241 void OnPause() override; | 226 void OnPause() override; |
| 242 void OnVolumeMultiplierUpdate(double multiplier) override; | 227 void OnVolumeMultiplierUpdate(double multiplier) override; |
| 243 | 228 |
| 244 protected: | 229 protected: |
| 245 // Helper method to update the playing state. | 230 // Helper method to update the playing state. |
| 246 void UpdatePlayingState(bool is_playing_); | 231 void UpdatePlayingState(bool is_playing_); |
| 247 | 232 |
| 248 // Helper methods for posting task for setting states and update WebKit. | 233 // Helper methods for posting task for setting states and update WebKit. |
| 249 void UpdateNetworkState(blink::WebMediaPlayer::NetworkState state); | 234 void UpdateNetworkState(blink::WebMediaPlayer::NetworkState state); |
| 250 void UpdateReadyState(blink::WebMediaPlayer::ReadyState state); | 235 void UpdateReadyState(blink::WebMediaPlayer::ReadyState state); |
| 251 void TryCreateStreamTextureProxyIfNeeded(); | 236 void TryCreateStreamTextureProxyIfNeeded(); |
| 252 void DoCreateStreamTexture(); | 237 void DoCreateStreamTexture(); |
| 253 | 238 |
| 254 // Helper method to reestablish the surface texture peer for android | 239 // Helper method to reestablish the surface texture peer for android |
| 255 // media player. | 240 // media player. |
| 256 void EstablishSurfaceTexturePeer(); | 241 void EstablishSurfaceTexturePeer(); |
| 257 | 242 |
| 258 // Requesting whether the surface texture peer needs to be reestablished. | 243 // Requesting whether the surface texture peer needs to be reestablished. |
| 259 void SetNeedsEstablishPeer(bool needs_establish_peer); | 244 void SetNeedsEstablishPeer(bool needs_establish_peer); |
| 260 | 245 |
| 261 private: | 246 private: |
| 262 void InitializePlayer(const GURL& url, | 247 void InitializePlayer(const GURL& url, |
| 263 const GURL& first_party_for_cookies, | 248 const GURL& first_party_for_cookies, |
| 264 bool allowed_stored_credentials, | 249 bool allowed_stored_credentials); |
| 265 int demuxer_client_id); | |
| 266 void Pause(bool is_media_related_action); | 250 void Pause(bool is_media_related_action); |
| 267 void DrawRemotePlaybackText(const std::string& remote_playback_message); | 251 void DrawRemotePlaybackText(const std::string& remote_playback_message); |
| 268 void ReallocateVideoFrame(); | 252 void ReallocateVideoFrame(); |
| 269 void SetCurrentFrameInternal(scoped_refptr<media::VideoFrame>& frame); | 253 void SetCurrentFrameInternal(scoped_refptr<media::VideoFrame>& frame); |
| 270 void RemoveSurfaceTextureAndProxy(); | 254 void RemoveSurfaceTextureAndProxy(); |
| 271 void DidLoadMediaInfo(MediaInfoLoader::Status status, | 255 void DidLoadMediaInfo(MediaInfoLoader::Status status, |
| 272 const GURL& redirected_url, | 256 const GURL& redirected_url, |
| 273 const GURL& first_party_for_cookies, | 257 const GURL& first_party_for_cookies, |
| 274 bool allow_stored_credentials); | 258 bool allow_stored_credentials); |
| 275 bool IsKeySystemSupported(const std::string& key_system); | |
| 276 bool IsLocalResource(); | 259 bool IsLocalResource(); |
| 277 | 260 |
| 278 // Called whenever we create a new StreamTextureProxy and had a VFP::Client, | 261 // Called whenever we create a new StreamTextureProxy and had a VFP::Client, |
| 279 // or when we get a new VFP::Client and had a StreamTextureProxy. | 262 // or when we get a new VFP::Client and had a StreamTextureProxy. |
| 280 // Sets |stream_texture_proxy_|'s OnFrameAvailable() to call |client|'s | 263 // Sets |stream_texture_proxy_|'s OnFrameAvailable() to call |client|'s |
| 281 // DidReceiveFrame(). | 264 // DidReceiveFrame(). |
| 282 // Passing nullptr to this method will clear the previous callback. | 265 // Passing nullptr to this method will clear the previous callback. |
| 283 void UpdateStreamTextureProxyCallback(cc::VideoFrameProvider::Client* client); | 266 void UpdateStreamTextureProxyCallback(cc::VideoFrameProvider::Client* client); |
| 284 | 267 |
| 285 // Called when |cdm_context| is ready. | |
| 286 void OnCdmContextReady(media::CdmContext* cdm_context); | |
| 287 | |
| 288 // Sets the CDM. Should only be called when |is_player_initialized_| is true | |
| 289 // and a new non-null |cdm_context_| is available. Fires |cdm_attached_cb_| on | |
| 290 // the main thread with the result after the CDM is attached. | |
| 291 void SetCdmInternal(const media::CdmAttachedCB& cdm_attached_cb); | |
| 292 | |
| 293 // Called when the CDM is attached. | |
| 294 void OnCdmAttached(const media::CdmAttachedCB& cdm_attached_cb, bool success); | |
| 295 | |
| 296 // Requests that this object notifies when a CDM is ready through the | |
| 297 // |cdm_ready_cb| provided. | |
| 298 // If |cdm_ready_cb| is null, the existing callback will be fired with | |
| 299 // NULL immediately and reset. | |
| 300 void SetCdmReadyCB(const MediaSourceDelegate::CdmReadyCB& cdm_ready_cb); | |
| 301 | |
| 302 // Called when the ContentDecryptionModule has been attached to the | |
| 303 // pipeline/decoders. | |
| 304 void ContentDecryptionModuleAttached( | |
| 305 blink::WebContentDecryptionModuleResult result, | |
| 306 bool success); | |
| 307 | |
| 308 bool IsHLSStream() const; | 268 bool IsHLSStream() const; |
| 309 // Report whether the loaded url, after following redirects, points to a HLS | 269 // Report whether the loaded url, after following redirects, points to a HLS |
| 310 // playlist, and record the origin of the player. | 270 // playlist, and record the origin of the player. |
| 311 void ReportHLSMetrics() const; | 271 void ReportHLSMetrics() const; |
| 312 | 272 |
| 313 // Called after |defer_load_cb_| has decided to allow the load. If | 273 // Called after |defer_load_cb_| has decided to allow the load. If |
| 314 // |defer_load_cb_| is null this is called immediately. | 274 // |defer_load_cb_| is null this is called immediately. |
| 315 void DoLoad(LoadType load_type, const blink::WebURL& url, CORSMode cors_mode); | 275 void DoLoad(LoadType load_type, const blink::WebURL& url, CORSMode cors_mode); |
| 316 | 276 |
| 317 // Returns if this video can be resumed in the background. | 277 // Returns if this video can be resumed in the background. |
| 318 bool IsBackgroundVideoCandidate() const; | 278 bool IsBackgroundVideoCandidate() const; |
| 319 | 279 |
| 320 blink::WebFrame* const frame_; | 280 blink::WebFrame* const frame_; |
| 321 | 281 |
| 322 blink::WebMediaPlayerClient* const client_; | 282 blink::WebMediaPlayerClient* const client_; |
| 323 blink::WebMediaPlayerEncryptedMediaClient* const encrypted_client_; | |
| 324 | 283 |
| 325 // WebMediaPlayer notifies the |delegate_| of playback state changes using | 284 // WebMediaPlayer notifies the |delegate_| of playback state changes using |
| 326 // |delegate_id_|; an id provided after registering with the delegate. The | 285 // |delegate_id_|; an id provided after registering with the delegate. The |
| 327 // WebMediaPlayer may also receive directives (play, pause) from the delegate | 286 // WebMediaPlayer may also receive directives (play, pause) from the delegate |
| 328 // via the WebMediaPlayerDelegate::Observer interface after registration. | 287 // via the WebMediaPlayerDelegate::Observer interface after registration. |
| 329 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; | 288 base::WeakPtr<media::WebMediaPlayerDelegate> delegate_; |
| 330 int delegate_id_; | 289 int delegate_id_; |
| 331 | 290 |
| 332 // Callback responsible for determining if loading of media should be deferred | 291 // Callback responsible for determining if loading of media should be deferred |
| 333 // for external reasons; called during load(). | 292 // for external reasons; called during load(). |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 400 |
| 442 MediaPlayerHostMsg_Initialize_Type player_type_; | 401 MediaPlayerHostMsg_Initialize_Type player_type_; |
| 443 | 402 |
| 444 // Whether the browser is currently connected to a remote media player. | 403 // Whether the browser is currently connected to a remote media player. |
| 445 bool is_remote_; | 404 bool is_remote_; |
| 446 | 405 |
| 447 scoped_refptr<media::MediaLog> media_log_; | 406 scoped_refptr<media::MediaLog> media_log_; |
| 448 | 407 |
| 449 std::unique_ptr<MediaInfoLoader> info_loader_; | 408 std::unique_ptr<MediaInfoLoader> info_loader_; |
| 450 | 409 |
| 451 // Non-owned pointer to the CdmContext. Updated in the constructor, | |
| 452 // generateKeyRequest() or setContentDecryptionModule(). | |
| 453 media::CdmContext* cdm_context_; | |
| 454 | |
| 455 // This is only Used by Clear Key key system implementation, where a renderer | |
| 456 // side CDM will be used. This is similar to WebMediaPlayerImpl. For other key | |
| 457 // systems, a browser side CDM will be used and we set CDM by calling | |
| 458 // player_manager_->SetCdm() directly. | |
| 459 MediaSourceDelegate::CdmReadyCB cdm_ready_cb_; | |
| 460 | |
| 461 // Whether stored credentials are allowed to be passed to the server. | 410 // Whether stored credentials are allowed to be passed to the server. |
| 462 bool allow_stored_credentials_; | 411 bool allow_stored_credentials_; |
| 463 | 412 |
| 464 // Whether the resource is local. | 413 // Whether the resource is local. |
| 465 bool is_local_resource_; | 414 bool is_local_resource_; |
| 466 | 415 |
| 467 // base::TickClock used by |interpolator_|. | 416 // base::TickClock used by |interpolator_|. |
| 468 base::DefaultTickClock default_tick_clock_; | 417 base::DefaultTickClock default_tick_clock_; |
| 469 | 418 |
| 470 // Tracks the most recent media time update and provides interpolated values | 419 // Tracks the most recent media time update and provides interpolated values |
| 471 // as playback progresses. | 420 // as playback progresses. |
| 472 media::TimeDeltaInterpolator interpolator_; | 421 media::TimeDeltaInterpolator interpolator_; |
| 473 | 422 |
| 474 std::unique_ptr<MediaSourceDelegate> media_source_delegate_; | |
| 475 | |
| 476 int frame_id_; | 423 int frame_id_; |
| 477 | 424 |
| 478 // Whether to require that surface textures are copied in order to support | 425 // Whether to require that surface textures are copied in order to support |
| 479 // sharing between render and gpu threads in WebView. | 426 // sharing between render and gpu threads in WebView. |
| 480 bool enable_texture_copy_; | 427 bool enable_texture_copy_; |
| 481 | 428 |
| 482 // Whether to delete the existing texture and re-create it. | 429 // Whether to delete the existing texture and re-create it. |
| 483 bool suppress_deleting_texture_; | 430 bool suppress_deleting_texture_; |
| 484 | 431 |
| 485 // Whether OnPlaybackComplete() has been called since the last playback. | 432 // Whether OnPlaybackComplete() has been called since the last playback. |
| 486 bool playback_completed_; | 433 bool playback_completed_; |
| 487 | 434 |
| 488 // The last volume received by setVolume() and the last volume multiplier from | 435 // The last volume received by setVolume() and the last volume multiplier from |
| 489 // OnVolumeMultiplierUpdate(). The multiplier is typical 1.0, but may be less | 436 // OnVolumeMultiplierUpdate(). The multiplier is typical 1.0, but may be less |
| 490 // if the WebMediaPlayerDelegate has requested a volume reduction (ducking) | 437 // if the WebMediaPlayerDelegate has requested a volume reduction (ducking) |
| 491 // for a transient sound. Playout volume is derived by volume * multiplier. | 438 // for a transient sound. Playout volume is derived by volume * multiplier. |
| 492 double volume_; | 439 double volume_; |
| 493 double volume_multiplier_; | 440 double volume_multiplier_; |
| 494 | 441 |
| 495 // NOTE: Weak pointers must be invalidated before all other member variables. | 442 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 496 base::WeakPtrFactory<WebMediaPlayerAndroid> weak_factory_; | 443 base::WeakPtrFactory<WebMediaPlayerAndroid> weak_factory_; |
| 497 | 444 |
| 498 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); | 445 DISALLOW_COPY_AND_ASSIGN(WebMediaPlayerAndroid); |
| 499 }; | 446 }; |
| 500 | 447 |
| 501 } // namespace content | 448 } // namespace content |
| 502 | 449 |
| 503 #endif // CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ | 450 #endif // CONTENT_RENDERER_MEDIA_ANDROID_WEBMEDIAPLAYER_ANDROID_H_ |
| OLD | NEW |