| Index: media/blink/webmediaplayer_impl.cc
|
| diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
|
| index 0ab7b54d2cfdf4ee3dc09c257d782eea66e0c312..4f1d616976d4d705ff5075cb2d0d38a6d46b6158 100644
|
| --- a/media/blink/webmediaplayer_impl.cc
|
| +++ b/media/blink/webmediaplayer_impl.cc
|
| @@ -1405,10 +1405,8 @@ void WebMediaPlayerImpl::OnFrameHidden() {
|
| if (watch_time_reporter_)
|
| watch_time_reporter_->OnHidden();
|
|
|
| - // OnFrameHidden() can be called when frame is closed, then IsHidden() will
|
| - // return false, so check explicitly.
|
| - if (IsHidden()) {
|
| - if (ShouldPauseVideoWhenHidden()) {
|
| + if (IsBackground()) {
|
| + if (ShouldPauseVideoWhenBackground()) {
|
| PauseVideoIfNeeded();
|
| return;
|
| } else {
|
| @@ -1804,7 +1802,7 @@ void WebMediaPlayerImpl::UpdatePlayState() {
|
| #endif
|
|
|
| bool is_suspended = pipeline_controller_.IsSuspended();
|
| - bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden();
|
| + bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsBackground();
|
| PlayState state = UpdatePlayState_ComputePlayState(
|
| is_remote, is_streaming, is_suspended, is_backgrounded);
|
| SetDelegateState(state.delegate_state, state.is_idle);
|
| @@ -2103,9 +2101,12 @@ void WebMediaPlayerImpl::CreateWatchTimeReporter() {
|
| watch_time_reporter_->OnShown();
|
| }
|
|
|
| -bool WebMediaPlayerImpl::IsHidden() const {
|
| +bool WebMediaPlayerImpl::IsBackground() const {
|
| DCHECK(main_task_runner_->BelongsToCurrentThread());
|
|
|
| + // Nothing related to the media being in the background should matter if the
|
| + // frame is closed. However, the delegate might call OnFrameHidden() when
|
| + // closed so specifically exclude this case.
|
| return delegate_->IsFrameHidden() && !delegate_->IsFrameClosed();
|
| }
|
|
|
| @@ -2123,7 +2124,7 @@ void WebMediaPlayerImpl::ActivateViewportIntersectionMonitoring(bool activate) {
|
| client_->activateViewportIntersectionMonitoring(activate);
|
| }
|
|
|
| -bool WebMediaPlayerImpl::ShouldPauseVideoWhenHidden() const {
|
| +bool WebMediaPlayerImpl::ShouldPauseVideoWhenBackground() const {
|
| #if !defined(OS_ANDROID)
|
| // On desktop, this behavior is behind the feature flag.
|
| if (!IsBackgroundVideoTrackOptimizationEnabled())
|
| @@ -2134,7 +2135,7 @@ bool WebMediaPlayerImpl::ShouldPauseVideoWhenHidden() const {
|
| return !hasAudio() && IsBackgroundOptimizationCandidate();
|
| }
|
|
|
| -bool WebMediaPlayerImpl::ShouldDisableVideoWhenHidden() const {
|
| +bool WebMediaPlayerImpl::ShouldDisableVideoWhenBackground() const {
|
| // This optimization is behind the flag on all platforms.
|
| if (!IsBackgroundVideoTrackOptimizationEnabled())
|
| return false;
|
| @@ -2174,8 +2175,8 @@ bool WebMediaPlayerImpl::IsBackgroundOptimizationCandidate() const {
|
| }
|
|
|
| void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() {
|
| - if (IsHidden()) {
|
| - if (ShouldPauseVideoWhenHidden())
|
| + if (IsBackground()) {
|
| + if (ShouldPauseVideoWhenBackground())
|
| PauseVideoIfNeeded();
|
| else
|
| DisableVideoTrackIfNeeded();
|
| @@ -2185,7 +2186,7 @@ void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() {
|
| }
|
|
|
| void WebMediaPlayerImpl::PauseVideoIfNeeded() {
|
| - DCHECK(IsHidden());
|
| + DCHECK(IsBackground());
|
|
|
| // Don't pause video while the pipeline is stopped, resuming or seeking.
|
| // Also if the video is paused already.
|
| @@ -2214,13 +2215,13 @@ void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() {
|
| }
|
|
|
| void WebMediaPlayerImpl::DisableVideoTrackIfNeeded() {
|
| - DCHECK(IsHidden());
|
| + DCHECK(IsBackground());
|
|
|
| // Don't change video track while the pipeline is resuming or seeking.
|
| if (is_pipeline_resuming_ || seeking_)
|
| return;
|
|
|
| - if (!video_track_disabled_ && ShouldDisableVideoWhenHidden()) {
|
| + if (!video_track_disabled_ && ShouldDisableVideoWhenBackground()) {
|
| video_track_disabled_ = true;
|
| selectedVideoTrackChanged(nullptr);
|
| }
|
|
|