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(); | |
1349 paused_when_hidden_ = true; | |
sandersd (OOO until July 31)
2017/01/06 01:44:15
Probably needs a comment to explain that the order
whywhat
2017/01/06 16:59:31
Done. Alternatively I could perhaps take the most
| |
1350 return; | |
1351 } | |
1352 | |
1353 selectedVideoTrackChanged(nullptr); | |
1354 } | |
1355 | |
1345 UpdatePlayState(); | 1356 UpdatePlayState(); |
1346 | 1357 |
1347 // Schedule suspended playing media to be paused if the user doesn't come back | 1358 // 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. | 1359 // to it within some timeout period to avoid any autoplay surprises. |
1349 ScheduleIdlePauseTimer(); | 1360 ScheduleIdlePauseTimer(); |
1350 } | 1361 } |
1351 | 1362 |
1352 void WebMediaPlayerImpl::OnShown() { | 1363 void WebMediaPlayerImpl::OnShown() { |
1353 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1364 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1354 if (watch_time_reporter_) | 1365 if (watch_time_reporter_) |
1355 watch_time_reporter_->OnShown(); | 1366 watch_time_reporter_->OnShown(); |
1356 | 1367 |
1357 if (IsBackgroundVideoTrackOptimizationEnabled() && | 1368 if (IsBackgroundVideoTrackOptimizationEnabled()) { |
1358 client_->hasSelectedVideoTrack()) { | 1369 if (paused_when_hidden_) { |
1359 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | 1370 paused_when_hidden_ = false; |
1360 selectedVideoTrackChanged(&trackId); | 1371 OnPlay(); |
1372 return; | |
1373 } | |
1374 | |
1375 if (client_->hasSelectedVideoTrack()) { | |
1376 WebMediaPlayer::TrackId trackId = client_->getSelectedVideoTrackId(); | |
1377 selectedVideoTrackChanged(&trackId); | |
1378 } | |
1361 } | 1379 } |
1362 | 1380 |
1363 must_suspend_ = false; | 1381 must_suspend_ = false; |
1364 background_pause_timer_.Stop(); | 1382 background_pause_timer_.Stop(); |
1365 | 1383 |
1366 UpdatePlayState(); | 1384 UpdatePlayState(); |
1367 } | 1385 } |
1368 | 1386 |
1369 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { | 1387 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { |
1370 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1388 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2033 bool WebMediaPlayerImpl::DoesOverlaySupportMetadata() const { | 2051 bool WebMediaPlayerImpl::DoesOverlaySupportMetadata() const { |
2034 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; | 2052 return pipeline_metadata_.video_rotation == VIDEO_ROTATION_0; |
2035 } | 2053 } |
2036 | 2054 |
2037 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { | 2055 void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) { |
2038 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 2056 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
2039 | 2057 |
2040 client_->activateViewportIntersectionMonitoring(activate); | 2058 client_->activateViewportIntersectionMonitoring(activate); |
2041 } | 2059 } |
2042 | 2060 |
2061 bool WebMediaPlayerImpl::ShouldPauseWhenHidden() const { | |
2062 #if defined(OS_ANDROID) // WMPI_CAST | |
2063 if (isRemote()) | |
2064 return false; | |
2065 #endif // defined(OS_ANDROID) // WMPI_CAST | |
2066 | |
2067 return hasVideo() && !hasAudio(); | |
2068 } | |
2069 | |
2043 } // namespace media | 2070 } // namespace media |
OLD | NEW |