Chromium Code Reviews| 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 "media/blink/webmediaplayer_impl.h" | 5 #include "media/blink/webmediaplayer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 &pipeline_, | 198 &pipeline_, |
| 199 base::Bind(&WebMediaPlayerImpl::CreateRenderer, | 199 base::Bind(&WebMediaPlayerImpl::CreateRenderer, |
| 200 base::Unretained(this)), | 200 base::Unretained(this)), |
| 201 base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()), | 201 base::Bind(&WebMediaPlayerImpl::OnPipelineSeeked, AsWeakPtr()), |
| 202 base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()), | 202 base::Bind(&WebMediaPlayerImpl::OnPipelineSuspended, AsWeakPtr()), |
| 203 base::Bind(&WebMediaPlayerImpl::OnError, AsWeakPtr())), | 203 base::Bind(&WebMediaPlayerImpl::OnError, AsWeakPtr())), |
| 204 load_type_(LoadTypeURL), | 204 load_type_(LoadTypeURL), |
| 205 opaque_(false), | 205 opaque_(false), |
| 206 playback_rate_(0.0), | 206 playback_rate_(0.0), |
| 207 paused_(true), | 207 paused_(true), |
| 208 paused_when_hidden_(false), | |
| 208 seeking_(false), | 209 seeking_(false), |
| 209 pending_suspend_resume_cycle_(false), | 210 pending_suspend_resume_cycle_(false), |
| 210 ended_(false), | 211 ended_(false), |
| 211 should_notify_time_changed_(false), | 212 should_notify_time_changed_(false), |
| 212 overlay_enabled_(false), | 213 overlay_enabled_(false), |
| 213 decoder_requires_restart_for_overlay_(false), | 214 decoder_requires_restart_for_overlay_(false), |
| 214 client_(client), | 215 client_(client), |
| 215 encrypted_client_(encrypted_client), | 216 encrypted_client_(encrypted_client), |
| 216 delegate_(delegate), | 217 delegate_(delegate), |
| 217 delegate_id_(0), | 218 delegate_id_(0), |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 | 442 |
| 442 void WebMediaPlayerImpl::pause() { | 443 void WebMediaPlayerImpl::pause() { |
| 443 DVLOG(1) << __func__; | 444 DVLOG(1) << __func__; |
| 444 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 445 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 445 | 446 |
| 446 // We update the paused state even when casting, since we expect pause() to be | 447 // We update the paused state even when casting, since we expect pause() to be |
| 447 // called when casting begins, and when we exit casting we should end up in a | 448 // called when casting begins, and when we exit casting we should end up in a |
| 448 // paused state. | 449 // paused state. |
| 449 paused_ = true; | 450 paused_ = true; |
| 450 | 451 |
| 452 // No longer paused because it was hidden. | |
| 453 paused_when_hidden_ = false; | |
| 454 | |
| 451 #if defined(OS_ANDROID) // WMPI_CAST | 455 #if defined(OS_ANDROID) // WMPI_CAST |
| 452 if (isRemote()) { | 456 if (isRemote()) { |
| 453 cast_impl_.pause(); | 457 cast_impl_.pause(); |
| 454 return; | 458 return; |
| 455 } | 459 } |
| 456 #endif | 460 #endif |
| 457 | 461 |
| 458 pipeline_.SetPlaybackRate(0.0); | 462 pipeline_.SetPlaybackRate(0.0); |
| 459 | 463 |
| 460 // pause() may be called after playback has ended and the HTMLMediaElement | 464 // pause() may be called after playback has ended and the HTMLMediaElement |
| (...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1329 opaque_ = opaque; | 1333 opaque_ = opaque; |
| 1330 // Modify content opaqueness of cc::Layer directly so that | 1334 // Modify content opaqueness of cc::Layer directly so that |
| 1331 // SetContentsOpaqueIsFixed is ignored. | 1335 // SetContentsOpaqueIsFixed is ignored. |
| 1332 if (video_weblayer_) | 1336 if (video_weblayer_) |
| 1333 video_weblayer_->layer()->SetContentsOpaque(opaque_); | 1337 video_weblayer_->layer()->SetContentsOpaque(opaque_); |
| 1334 } | 1338 } |
| 1335 | 1339 |
| 1336 void WebMediaPlayerImpl::OnHidden() { | 1340 void WebMediaPlayerImpl::OnHidden() { |
| 1337 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1341 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1338 | 1342 |
| 1339 if (IsBackgroundVideoTrackOptimizationEnabled()) | |
| 1340 selectedVideoTrackChanged(nullptr); | |
| 1341 | |
| 1342 if (watch_time_reporter_) | 1343 if (watch_time_reporter_) |
| 1343 watch_time_reporter_->OnHidden(); | 1344 watch_time_reporter_->OnHidden(); |
| 1344 | 1345 |
| 1346 if (IsBackgroundVideoTrackOptimizationEnabled()) { | |
| 1347 if (ShouldPauseWhenHidden()) { | |
| 1348 // OnPause() will set |paused_when_hidden_| to false and call | |
| 1349 // UpdatePlayState(), so set the flag to true after and then return. | |
| 1350 OnPause(); | |
| 1351 paused_when_hidden_ = true; | |
| 1352 return; | |
| 1353 } | |
| 1354 | |
| 1355 selectedVideoTrackChanged(nullptr); | |
| 1356 } | |
| 1357 | |
| 1345 UpdatePlayState(); | 1358 UpdatePlayState(); |
| 1346 | 1359 |
| 1347 // Schedule suspended playing media to be paused if the user doesn't come back | 1360 // Schedule suspended playing media to be paused if the user doesn't come back |
| 1348 // to it within some timeout period to avoid any autoplay surprises. | 1361 // to it within some timeout period to avoid any autoplay surprises. |
| 1349 ScheduleIdlePauseTimer(); | 1362 ScheduleIdlePauseTimer(); |
| 1350 } | 1363 } |
| 1351 | 1364 |
| 1352 void WebMediaPlayerImpl::OnShown() { | 1365 void WebMediaPlayerImpl::OnShown() { |
| 1353 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1366 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1354 if (watch_time_reporter_) | 1367 if (watch_time_reporter_) |
| 1355 watch_time_reporter_->OnShown(); | 1368 watch_time_reporter_->OnShown(); |
| 1356 | 1369 |
| 1357 compositor_task_runner_->PostTask( | 1370 compositor_task_runner_->PostTask( |
| 1358 FROM_HERE, | 1371 FROM_HERE, |
| 1359 base::Bind(&VideoFrameCompositor::SetForegroundTime, | 1372 base::Bind(&VideoFrameCompositor::SetForegroundTime, |
| 1360 base::Unretained(compositor_), base::TimeTicks::Now())); | 1373 base::Unretained(compositor_), base::TimeTicks::Now())); |
| 1361 | 1374 |
| 1362 if (IsBackgroundVideoTrackOptimizationEnabled() && | 1375 if (IsBackgroundVideoTrackOptimizationEnabled()) { |
| 1363 client_->hasSelectedVideoTrack()) { | 1376 if (paused_when_hidden_) { |
| 1364 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | 1377 paused_when_hidden_ = false; |
| 1365 selectedVideoTrackChanged(&trackId); | 1378 OnPlay(); // Calls UpdatePlayState() so return afterwards. |
| 1379 return; | |
| 1380 } | |
| 1381 | |
| 1382 if (client_->hasSelectedVideoTrack()) { | |
| 1383 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | |
| 1384 selectedVideoTrackChanged(&trackId); | |
| 1385 } | |
| 1366 } | 1386 } |
| 1367 | 1387 |
| 1368 must_suspend_ = false; | 1388 must_suspend_ = false; |
| 1369 background_pause_timer_.Stop(); | 1389 background_pause_timer_.Stop(); |
| 1370 | 1390 |
| 1371 UpdatePlayState(); | 1391 UpdatePlayState(); |
| 1372 } | 1392 } |
| 1373 | 1393 |
| 1374 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { | 1394 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { |
| 1375 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1395 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| (...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2038 bool WebMediaPlayerImpl::DoesOverlaySupportMetadata() const { | 2058 bool WebMediaPlayerImpl::DoesOverlaySupportMetadata() const { |
| 2039 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; | 2059 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; |
| 2040 } | 2060 } |
| 2041 | 2061 |
| 2042 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { | 2062 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { |
| 2043 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 2063 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 2044 | 2064 |
| 2045 client_->activateViewportIntersectionMonitoring(activate); | 2065 client_->activateViewportIntersectionMonitoring(activate); |
| 2046 } | 2066 } |
| 2047 | 2067 |
| 2068 bool WebMediaPlayerImpl::ShouldPauseWhenHidden() const { | |
| 2069 #if defined(OS_ANDROID) // WMPI_CAST | |
| 2070 if (isRemote()) | |
| 2071 return false; | |
| 2072 #endif // defined(OS_ANDROID) // WMPI_CAST | |
| 2073 | |
| 2074 return hasVideo() && !hasAudio(); | |
|
whywhat
2017/01/06 22:23:48
Mounir - should we add autoplay_muted() for this m
| |
| 2075 } | |
| 2076 | |
| 2048 } // namespace media | 2077 } // namespace media |
| OLD | NEW |