| 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 #include "content/renderer/media/android/webmediaplayer_android.h" | 5 #include "content/renderer/media/android/webmediaplayer_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 blink::WebFrame* frame, | 177 blink::WebFrame* frame, |
| 178 blink::WebMediaPlayerClient* client, | 178 blink::WebMediaPlayerClient* client, |
| 179 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, | 179 blink::WebMediaPlayerEncryptedMediaClient* encrypted_client, |
| 180 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, | 180 base::WeakPtr<media::WebMediaPlayerDelegate> delegate, |
| 181 RendererMediaPlayerManager* player_manager, | 181 RendererMediaPlayerManager* player_manager, |
| 182 media::CdmFactory* cdm_factory, | 182 media::CdmFactory* cdm_factory, |
| 183 scoped_refptr<StreamTextureFactory> factory, | 183 scoped_refptr<StreamTextureFactory> factory, |
| 184 int frame_id, | 184 int frame_id, |
| 185 bool enable_texture_copy, | 185 bool enable_texture_copy, |
| 186 const media::WebMediaPlayerParams& params) | 186 const media::WebMediaPlayerParams& params) |
| 187 : RenderFrameObserver(RenderFrame::FromWebFrame(frame)), | 187 : frame_(frame), |
| 188 frame_(frame), | |
| 189 client_(client), | 188 client_(client), |
| 190 encrypted_client_(encrypted_client), | 189 encrypted_client_(encrypted_client), |
| 191 delegate_(delegate), | 190 delegate_(delegate), |
| 191 delegate_id_(0), |
| 192 defer_load_cb_(params.defer_load_cb()), | 192 defer_load_cb_(params.defer_load_cb()), |
| 193 buffered_(static_cast<size_t>(1)), | 193 buffered_(static_cast<size_t>(1)), |
| 194 media_task_runner_(params.media_task_runner()), | 194 media_task_runner_(params.media_task_runner()), |
| 195 ignore_metadata_duration_change_(false), | 195 ignore_metadata_duration_change_(false), |
| 196 pending_seek_(false), | 196 pending_seek_(false), |
| 197 seeking_(false), | 197 seeking_(false), |
| 198 did_loading_progress_(false), | 198 did_loading_progress_(false), |
| 199 player_manager_(player_manager), | 199 player_manager_(player_manager), |
| 200 cdm_factory_(cdm_factory), | 200 cdm_factory_(cdm_factory), |
| 201 media_permission_(params.media_permission()), | 201 media_permission_(params.media_permission()), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 219 is_remote_(false), | 219 is_remote_(false), |
| 220 media_log_(params.media_log()), | 220 media_log_(params.media_log()), |
| 221 init_data_type_(media::EmeInitDataType::UNKNOWN), | 221 init_data_type_(media::EmeInitDataType::UNKNOWN), |
| 222 cdm_context_(nullptr), | 222 cdm_context_(nullptr), |
| 223 allow_stored_credentials_(false), | 223 allow_stored_credentials_(false), |
| 224 is_local_resource_(false), | 224 is_local_resource_(false), |
| 225 interpolator_(&default_tick_clock_), | 225 interpolator_(&default_tick_clock_), |
| 226 frame_id_(frame_id), | 226 frame_id_(frame_id), |
| 227 enable_texture_copy_(enable_texture_copy), | 227 enable_texture_copy_(enable_texture_copy), |
| 228 suppress_deleting_texture_(false), | 228 suppress_deleting_texture_(false), |
| 229 playback_completed_(false), |
| 230 volume_(1.0), |
| 231 volume_multiplier_(1.0), |
| 229 weak_factory_(this) { | 232 weak_factory_(this) { |
| 230 DCHECK(player_manager_); | 233 DCHECK(player_manager_); |
| 231 DCHECK(cdm_factory_); | 234 DCHECK(cdm_factory_); |
| 232 | 235 |
| 233 DCHECK(main_thread_checker_.CalledOnValidThread()); | 236 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 234 stream_texture_factory_->AddObserver(this); | 237 stream_texture_factory_->AddObserver(this); |
| 235 | 238 |
| 239 if (delegate_) |
| 240 delegate_id_ = delegate_->AddObserver(this); |
| 241 |
| 236 player_id_ = player_manager_->RegisterMediaPlayer(this); | 242 player_id_ = player_manager_->RegisterMediaPlayer(this); |
| 237 | 243 |
| 238 #if defined(VIDEO_HOLE) | 244 #if defined(VIDEO_HOLE) |
| 239 const RendererPreferences& prefs = | 245 const RendererPreferences& prefs = RenderFrameImpl::FromRoutingID(frame_id) |
| 240 static_cast<RenderFrameImpl*>(render_frame()) | 246 ->render_view() |
| 241 ->render_view() | 247 ->renderer_preferences(); |
| 242 ->renderer_preferences(); | |
| 243 force_use_overlay_embedded_video_ = prefs.use_view_overlay_for_all_video; | 248 force_use_overlay_embedded_video_ = prefs.use_view_overlay_for_all_video; |
| 244 if (force_use_overlay_embedded_video_ || | 249 if (force_use_overlay_embedded_video_ || |
| 245 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { | 250 player_manager_->ShouldUseVideoOverlayForEmbeddedEncryptedVideo()) { |
| 246 // Defer stream texture creation until we are sure it's necessary. | 251 // Defer stream texture creation until we are sure it's necessary. |
| 247 needs_establish_peer_ = false; | 252 needs_establish_peer_ = false; |
| 248 current_frame_ = VideoFrame::CreateBlackFrame(gfx::Size(1, 1)); | 253 current_frame_ = VideoFrame::CreateBlackFrame(gfx::Size(1, 1)); |
| 249 } | 254 } |
| 250 #endif // defined(VIDEO_HOLE) | 255 #endif // defined(VIDEO_HOLE) |
| 251 TryCreateStreamTextureProxyIfNeeded(); | 256 TryCreateStreamTextureProxyIfNeeded(); |
| 252 interpolator_.SetUpperBound(base::TimeDelta()); | 257 interpolator_.SetUpperBound(base::TimeDelta()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 275 texture_id_ = 0; | 280 texture_id_ = 0; |
| 276 texture_mailbox_ = gpu::Mailbox(); | 281 texture_mailbox_ = gpu::Mailbox(); |
| 277 stream_id_ = 0; | 282 stream_id_ = 0; |
| 278 } | 283 } |
| 279 | 284 |
| 280 { | 285 { |
| 281 base::AutoLock auto_lock(current_frame_lock_); | 286 base::AutoLock auto_lock(current_frame_lock_); |
| 282 current_frame_ = NULL; | 287 current_frame_ = NULL; |
| 283 } | 288 } |
| 284 | 289 |
| 285 if (delegate_) | 290 if (delegate_) { |
| 286 delegate_->PlayerGone(this); | 291 delegate_->PlayerGone(delegate_id_); |
| 292 delegate_->RemoveObserver(delegate_id_); |
| 293 } |
| 287 | 294 |
| 288 stream_texture_factory_->RemoveObserver(this); | 295 stream_texture_factory_->RemoveObserver(this); |
| 289 | 296 |
| 290 if (media_source_delegate_) { | 297 if (media_source_delegate_) { |
| 291 // Part of |media_source_delegate_| needs to be stopped on the media thread. | 298 // Part of |media_source_delegate_| needs to be stopped on the media thread. |
| 292 // Wait until |media_source_delegate_| is fully stopped before tearing | 299 // Wait until |media_source_delegate_| is fully stopped before tearing |
| 293 // down other objects. | 300 // down other objects. |
| 294 base::WaitableEvent waiter(false, false); | 301 base::WaitableEvent waiter(false, false); |
| 295 media_source_delegate_->Stop( | 302 media_source_delegate_->Stop( |
| 296 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter))); | 303 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&waiter))); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 #endif // defined(VIDEO_HOLE) | 429 #endif // defined(VIDEO_HOLE) |
| 423 | 430 |
| 424 TryCreateStreamTextureProxyIfNeeded(); | 431 TryCreateStreamTextureProxyIfNeeded(); |
| 425 // There is no need to establish the surface texture peer for fullscreen | 432 // There is no need to establish the surface texture peer for fullscreen |
| 426 // video. | 433 // video. |
| 427 if ((hasVideo() || IsHLSStream()) && needs_establish_peer_ && | 434 if ((hasVideo() || IsHLSStream()) && needs_establish_peer_ && |
| 428 !is_fullscreen_) { | 435 !is_fullscreen_) { |
| 429 EstablishSurfaceTexturePeer(); | 436 EstablishSurfaceTexturePeer(); |
| 430 } | 437 } |
| 431 | 438 |
| 432 if (paused()) | 439 // UpdatePlayingState() must be run before calling Start() to ensure that the |
| 440 // browser side MediaPlayerAndroid values for hasAudio() and hasVideo() take |
| 441 // precedent over the guesses that we make based on mime type. |
| 442 const bool is_paused = paused(); |
| 443 UpdatePlayingState(true); |
| 444 if (is_paused) |
| 433 player_manager_->Start(player_id_); | 445 player_manager_->Start(player_id_); |
| 434 UpdatePlayingState(true); | |
| 435 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); | 446 UpdateNetworkState(WebMediaPlayer::NetworkStateLoading); |
| 436 } | 447 } |
| 437 | 448 |
| 438 void WebMediaPlayerAndroid::pause() { | 449 void WebMediaPlayerAndroid::pause() { |
| 439 DCHECK(main_thread_checker_.CalledOnValidThread()); | 450 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 440 Pause(true); | 451 Pause(true); |
| 441 } | 452 } |
| 442 | 453 |
| 443 void WebMediaPlayerAndroid::requestRemotePlayback() { | 454 void WebMediaPlayerAndroid::requestRemotePlayback() { |
| 444 player_manager_->RequestRemotePlayback(player_id_); | 455 player_manager_->RequestRemotePlayback(player_id_); |
| 445 } | 456 } |
| 446 | 457 |
| 447 void WebMediaPlayerAndroid::requestRemotePlaybackControl() { | 458 void WebMediaPlayerAndroid::requestRemotePlaybackControl() { |
| 448 player_manager_->RequestRemotePlaybackControl(player_id_); | 459 player_manager_->RequestRemotePlaybackControl(player_id_); |
| 449 } | 460 } |
| 450 | 461 |
| 451 void WebMediaPlayerAndroid::seek(double seconds) { | 462 void WebMediaPlayerAndroid::seek(double seconds) { |
| 452 DCHECK(main_thread_checker_.CalledOnValidThread()); | 463 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 453 DVLOG(1) << __FUNCTION__ << "(" << seconds << ")"; | 464 DVLOG(1) << __FUNCTION__ << "(" << seconds << ")"; |
| 454 | 465 |
| 466 playback_completed_ = false; |
| 455 base::TimeDelta new_seek_time = base::TimeDelta::FromSecondsD(seconds); | 467 base::TimeDelta new_seek_time = base::TimeDelta::FromSecondsD(seconds); |
| 456 | 468 |
| 457 if (seeking_) { | 469 if (seeking_) { |
| 458 if (new_seek_time == seek_time_) { | 470 if (new_seek_time == seek_time_) { |
| 459 if (media_source_delegate_) { | 471 if (media_source_delegate_) { |
| 460 // Don't suppress any redundant in-progress MSE seek. There could have | 472 // Don't suppress any redundant in-progress MSE seek. There could have |
| 461 // been changes to the underlying buffers after seeking the demuxer and | 473 // been changes to the underlying buffers after seeking the demuxer and |
| 462 // before receiving OnSeekComplete() for the currently in-progress seek. | 474 // before receiving OnSeekComplete() for the currently in-progress seek. |
| 463 MEDIA_LOG(DEBUG, media_log_) | 475 MEDIA_LOG(DEBUG, media_log_) |
| 464 << "Detected MediaSource seek to same time as in-progress seek to " | 476 << "Detected MediaSource seek to same time as in-progress seek to " |
| (...skipping 23 matching lines...) Expand all Loading... |
| 488 media_source_delegate_->StartWaitingForSeek(seek_time_); | 500 media_source_delegate_->StartWaitingForSeek(seek_time_); |
| 489 | 501 |
| 490 // Kick off the asynchronous seek! | 502 // Kick off the asynchronous seek! |
| 491 player_manager_->Seek(player_id_, seek_time_); | 503 player_manager_->Seek(player_id_, seek_time_); |
| 492 } | 504 } |
| 493 | 505 |
| 494 bool WebMediaPlayerAndroid::supportsSave() const { | 506 bool WebMediaPlayerAndroid::supportsSave() const { |
| 495 return false; | 507 return false; |
| 496 } | 508 } |
| 497 | 509 |
| 498 void WebMediaPlayerAndroid::setRate(double rate) { | 510 void WebMediaPlayerAndroid::setRate(double rate) {} |
| 499 NOTIMPLEMENTED(); | |
| 500 } | |
| 501 | 511 |
| 502 void WebMediaPlayerAndroid::setVolume(double volume) { | 512 void WebMediaPlayerAndroid::setVolume(double volume) { |
| 503 DCHECK(main_thread_checker_.CalledOnValidThread()); | 513 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 504 player_manager_->SetVolume(player_id_, volume); | 514 volume_ = volume; |
| 515 player_manager_->SetVolume(player_id_, volume_ * volume_multiplier_); |
| 505 } | 516 } |
| 506 | 517 |
| 507 void WebMediaPlayerAndroid::setSinkId( | 518 void WebMediaPlayerAndroid::setSinkId( |
| 508 const blink::WebString& sink_id, | 519 const blink::WebString& sink_id, |
| 509 const blink::WebSecurityOrigin& security_origin, | 520 const blink::WebSecurityOrigin& security_origin, |
| 510 blink::WebSetSinkIdCallbacks* web_callback) { | 521 blink::WebSetSinkIdCallbacks* web_callback) { |
| 511 DCHECK(main_thread_checker_.CalledOnValidThread()); | 522 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 512 scoped_ptr<blink::WebSetSinkIdCallbacks> callback(web_callback); | 523 scoped_ptr<blink::WebSetSinkIdCallbacks> callback(web_callback); |
| 513 callback->onError(blink::WebSetSinkIdError::NotSupported); | 524 callback->onError(blink::WebSetSinkIdError::NotSupported); |
| 514 } | 525 } |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 // know that the playback has finished. To solve this, we set the | 856 // know that the playback has finished. To solve this, we set the |
| 846 // current time to media duration when OnPlaybackComplete() get called. | 857 // current time to media duration when OnPlaybackComplete() get called. |
| 847 interpolator_.SetBounds(duration_, duration_); | 858 interpolator_.SetBounds(duration_, duration_); |
| 848 client_->timeChanged(); | 859 client_->timeChanged(); |
| 849 | 860 |
| 850 // If the loop attribute is set, timeChanged() will update the current time | 861 // If the loop attribute is set, timeChanged() will update the current time |
| 851 // to 0. It will perform a seek to 0. Issue a command to the player to start | 862 // to 0. It will perform a seek to 0. Issue a command to the player to start |
| 852 // playing after seek completes. | 863 // playing after seek completes. |
| 853 if (seeking_ && seek_time_ == base::TimeDelta()) | 864 if (seeking_ && seek_time_ == base::TimeDelta()) |
| 854 player_manager_->Start(player_id_); | 865 player_manager_->Start(player_id_); |
| 866 else |
| 867 playback_completed_ = true; |
| 855 } | 868 } |
| 856 | 869 |
| 857 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { | 870 void WebMediaPlayerAndroid::OnBufferingUpdate(int percentage) { |
| 858 buffered_[0].end = duration() * percentage / 100; | 871 buffered_[0].end = duration() * percentage / 100; |
| 859 did_loading_progress_ = true; | 872 did_loading_progress_ = true; |
| 860 | 873 |
| 861 if (percentage == 100 && network_state_ < WebMediaPlayer::NetworkStateLoaded) | 874 if (percentage == 100 && network_state_ < WebMediaPlayer::NetworkStateLoaded) |
| 862 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); | 875 UpdateNetworkState(WebMediaPlayer::NetworkStateLoaded); |
| 863 } | 876 } |
| 864 | 877 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 } | 1094 } |
| 1082 | 1095 |
| 1083 void WebMediaPlayerAndroid::OnPlayerReleased() { | 1096 void WebMediaPlayerAndroid::OnPlayerReleased() { |
| 1084 // |needs_external_surface_| is always false on non-TV devices. | 1097 // |needs_external_surface_| is always false on non-TV devices. |
| 1085 if (!needs_external_surface_) | 1098 if (!needs_external_surface_) |
| 1086 needs_establish_peer_ = true; | 1099 needs_establish_peer_ = true; |
| 1087 | 1100 |
| 1088 if (is_playing_) | 1101 if (is_playing_) |
| 1089 OnMediaPlayerPause(); | 1102 OnMediaPlayerPause(); |
| 1090 | 1103 |
| 1104 if (delegate_) |
| 1105 delegate_->PlayerGone(delegate_id_); |
| 1106 |
| 1091 #if defined(VIDEO_HOLE) | 1107 #if defined(VIDEO_HOLE) |
| 1092 last_computed_rect_ = gfx::RectF(); | 1108 last_computed_rect_ = gfx::RectF(); |
| 1093 #endif // defined(VIDEO_HOLE) | 1109 #endif // defined(VIDEO_HOLE) |
| 1094 } | 1110 } |
| 1095 | 1111 |
| 1096 void WebMediaPlayerAndroid::SuspendAndReleaseResources() { | 1112 void WebMediaPlayerAndroid::SuspendAndReleaseResources() { |
| 1097 switch (network_state_) { | 1113 switch (network_state_) { |
| 1098 // Pause the media player and inform WebKit if the player is in a good | 1114 // Pause the media player and inform WebKit if the player is in a good |
| 1099 // shape. | 1115 // shape. |
| 1100 case WebMediaPlayer::NetworkStateIdle: | 1116 case WebMediaPlayer::NetworkStateIdle: |
| 1101 case WebMediaPlayer::NetworkStateLoading: | 1117 case WebMediaPlayer::NetworkStateLoading: |
| 1102 case WebMediaPlayer::NetworkStateLoaded: | 1118 case WebMediaPlayer::NetworkStateLoaded: |
| 1103 Pause(false); | 1119 Pause(false); |
| 1104 client_->playbackStateChanged(); | 1120 client_->playbackStateChanged(); |
| 1121 if (delegate_) |
| 1122 delegate_->PlayerGone(delegate_id_); |
| 1105 break; | 1123 break; |
| 1106 // If a WebMediaPlayer instance has entered into one of these states, | 1124 // If a WebMediaPlayer instance has entered into one of these states, |
| 1107 // the internal network state in HTMLMediaElement could be set to empty. | 1125 // the internal network state in HTMLMediaElement could be set to empty. |
| 1108 // And calling playbackStateChanged() could get this object deleted. | 1126 // And calling playbackStateChanged() could get this object deleted. |
| 1109 case WebMediaPlayer::NetworkStateEmpty: | 1127 case WebMediaPlayer::NetworkStateEmpty: |
| 1110 case WebMediaPlayer::NetworkStateFormatError: | 1128 case WebMediaPlayer::NetworkStateFormatError: |
| 1111 case WebMediaPlayer::NetworkStateNetworkError: | 1129 case WebMediaPlayer::NetworkStateNetworkError: |
| 1112 case WebMediaPlayer::NetworkStateDecodeError: | 1130 case WebMediaPlayer::NetworkStateDecodeError: |
| 1113 break; | 1131 break; |
| 1114 } | 1132 } |
| 1115 player_manager_->SuspendAndReleaseResources(player_id_); | 1133 player_manager_->SuspendAndReleaseResources(player_id_); |
| 1116 if (!needs_external_surface_) | 1134 if (!needs_external_surface_) |
| 1117 SetNeedsEstablishPeer(true); | 1135 SetNeedsEstablishPeer(true); |
| 1118 } | 1136 } |
| 1119 | 1137 |
| 1120 void WebMediaPlayerAndroid::OnDestruct() { | |
| 1121 NOTREACHED() << "WebMediaPlayer should be destroyed before any " | |
| 1122 "RenderFrameObserver::OnDestruct() gets called when " | |
| 1123 "the RenderFrame goes away."; | |
| 1124 } | |
| 1125 | |
| 1126 void WebMediaPlayerAndroid::InitializePlayer( | 1138 void WebMediaPlayerAndroid::InitializePlayer( |
| 1127 const GURL& url, | 1139 const GURL& url, |
| 1128 const GURL& first_party_for_cookies, | 1140 const GURL& first_party_for_cookies, |
| 1129 bool allow_stored_credentials, | 1141 bool allow_stored_credentials, |
| 1130 int demuxer_client_id) { | 1142 int demuxer_client_id) { |
| 1131 ReportHLSMetrics(); | 1143 ReportHLSMetrics(); |
| 1132 | 1144 |
| 1133 allow_stored_credentials_ = allow_stored_credentials; | 1145 allow_stored_credentials_ = allow_stored_credentials; |
| 1134 player_manager_->Initialize( | 1146 player_manager_->Initialize( |
| 1135 player_type_, player_id_, url, first_party_for_cookies, demuxer_client_id, | 1147 player_type_, player_id_, url, first_party_for_cookies, demuxer_client_id, |
| 1136 frame_->document().url(), allow_stored_credentials); | 1148 frame_->document().url(), allow_stored_credentials, delegate_id_); |
| 1137 is_player_initialized_ = true; | 1149 is_player_initialized_ = true; |
| 1138 | 1150 |
| 1139 if (is_fullscreen_) | 1151 if (is_fullscreen_) |
| 1140 player_manager_->EnterFullscreen(player_id_); | 1152 player_manager_->EnterFullscreen(player_id_); |
| 1141 | 1153 |
| 1142 if (cdm_context_) | 1154 if (cdm_context_) |
| 1143 SetCdmInternal(base::Bind(&media::IgnoreCdmAttached)); | 1155 SetCdmInternal(base::Bind(&media::IgnoreCdmAttached)); |
| 1144 } | 1156 } |
| 1145 | 1157 |
| 1146 void WebMediaPlayerAndroid::Pause(bool is_media_related_action) { | 1158 void WebMediaPlayerAndroid::Pause(bool is_media_related_action) { |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 return; | 1378 return; |
| 1367 | 1379 |
| 1368 is_playing_ = is_playing; | 1380 is_playing_ = is_playing; |
| 1369 | 1381 |
| 1370 if (is_playing) | 1382 if (is_playing) |
| 1371 interpolator_.StartInterpolating(); | 1383 interpolator_.StartInterpolating(); |
| 1372 else | 1384 else |
| 1373 interpolator_.StopInterpolating(); | 1385 interpolator_.StopInterpolating(); |
| 1374 | 1386 |
| 1375 if (delegate_) { | 1387 if (delegate_) { |
| 1376 if (is_playing) | 1388 if (is_playing) { |
| 1377 delegate_->DidPlay(this); | 1389 // We must specify either video or audio to the delegate, but neither may |
| 1378 else | 1390 // be known at this point -- there are no video only containers, so only |
| 1379 delegate_->DidPause(this); | 1391 // send audio if we know for sure its audio. The browser side player will |
| 1392 // fill in the correct value later for media sessions. |
| 1393 delegate_->DidPlay(delegate_id_, hasVideo(), !hasVideo(), isRemote(), |
| 1394 duration_); |
| 1395 } else { |
| 1396 // Even if OnPlaybackComplete() has not been called yet, Blink may have |
| 1397 // already fired the ended event based on current time relative to |
| 1398 // duration -- so we need to check both possibilities here. |
| 1399 delegate_->DidPause(delegate_id_, |
| 1400 playback_completed_ || currentTime() >= duration()); |
| 1401 } |
| 1380 } | 1402 } |
| 1381 } | 1403 } |
| 1382 | 1404 |
| 1383 #if defined(VIDEO_HOLE) | 1405 #if defined(VIDEO_HOLE) |
| 1384 bool WebMediaPlayerAndroid::UpdateBoundaryRectangle() { | 1406 bool WebMediaPlayerAndroid::UpdateBoundaryRectangle() { |
| 1385 if (!video_weblayer_) | 1407 if (!video_weblayer_) |
| 1386 return false; | 1408 return false; |
| 1387 | 1409 |
| 1388 // Compute the geometry of video frame layer. | 1410 // Compute the geometry of video frame layer. |
| 1389 cc::Layer* layer = video_weblayer_->layer(); | 1411 cc::Layer* layer = video_weblayer_->layer(); |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1752 | 1774 |
| 1753 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { | 1775 void WebMediaPlayerAndroid::OnWaitingForDecryptionKey() { |
| 1754 encrypted_client_->didBlockPlaybackWaitingForKey(); | 1776 encrypted_client_->didBlockPlaybackWaitingForKey(); |
| 1755 | 1777 |
| 1756 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called | 1778 // TODO(jrummell): didResumePlaybackBlockedForKey() should only be called |
| 1757 // when a key has been successfully added (e.g. OnSessionKeysChange() with | 1779 // when a key has been successfully added (e.g. OnSessionKeysChange() with |
| 1758 // |has_additional_usable_key| = true). http://crbug.com/461903 | 1780 // |has_additional_usable_key| = true). http://crbug.com/461903 |
| 1759 encrypted_client_->didResumePlaybackBlockedForKey(); | 1781 encrypted_client_->didResumePlaybackBlockedForKey(); |
| 1760 } | 1782 } |
| 1761 | 1783 |
| 1784 void WebMediaPlayerAndroid::OnHidden() { |
| 1785 // RendererMediaPlayerManager will not call SuspendAndReleaseResources() if we |
| 1786 // were already in the paused state; thus notify the MediaWebContentsObserver |
| 1787 // that we've been hidden so any lingering MediaSessions are released. |
| 1788 if (delegate_) |
| 1789 delegate_->PlayerGone(delegate_id_); |
| 1790 } |
| 1791 |
| 1792 void WebMediaPlayerAndroid::OnShown() {} |
| 1793 |
| 1794 void WebMediaPlayerAndroid::OnPlay() { |
| 1795 play(); |
| 1796 client_->playbackStateChanged(); |
| 1797 } |
| 1798 |
| 1799 void WebMediaPlayerAndroid::OnPause() { |
| 1800 pause(); |
| 1801 client_->playbackStateChanged(); |
| 1802 } |
| 1803 |
| 1804 void WebMediaPlayerAndroid::OnVolumeMultiplierUpdate(double multiplier) { |
| 1805 volume_multiplier_ = multiplier; |
| 1806 setVolume(volume_); |
| 1807 } |
| 1808 |
| 1762 void WebMediaPlayerAndroid::OnCdmContextReady(media::CdmContext* cdm_context) { | 1809 void WebMediaPlayerAndroid::OnCdmContextReady(media::CdmContext* cdm_context) { |
| 1763 DCHECK(!cdm_context_); | 1810 DCHECK(!cdm_context_); |
| 1764 | 1811 |
| 1765 if (!cdm_context) { | 1812 if (!cdm_context) { |
| 1766 LOG(ERROR) << "CdmContext not available (e.g. CDM creation failed)."; | 1813 LOG(ERROR) << "CdmContext not available (e.g. CDM creation failed)."; |
| 1767 return; | 1814 return; |
| 1768 } | 1815 } |
| 1769 | 1816 |
| 1770 cdm_context_ = cdm_context; | 1817 cdm_context_ = cdm_context; |
| 1771 | 1818 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1878 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; | 1925 result = PREDICTION_RESULT_PATH_BASED_WAS_BETTER; |
| 1879 } else if (is_hls_url == is_hls) { | 1926 } else if (is_hls_url == is_hls) { |
| 1880 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; | 1927 result = PREDICTION_RESULT_URL_BASED_WAS_BETTER; |
| 1881 } | 1928 } |
| 1882 UMA_HISTOGRAM_ENUMERATION( | 1929 UMA_HISTOGRAM_ENUMERATION( |
| 1883 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", | 1930 "Media.Android.IsHttpLiveStreamingMediaPredictionResult", |
| 1884 result, PREDICTION_RESULT_MAX); | 1931 result, PREDICTION_RESULT_MAX); |
| 1885 } | 1932 } |
| 1886 | 1933 |
| 1887 } // namespace content | 1934 } // namespace content |
| OLD | NEW |