Commit e7813971 authored by Yuchen Liu's avatar Yuchen Liu Committed by Commit Bot

Do not pause audio only stream when video background play is disabled

For audio only stream, we should let it play even video backgroud play
is disabled.

Bug: internal b/129859403
Test: Move audio only page to background, stream is still playing.
Change-Id: If82d6c0cbc21b71d3da3c8dd70e344b08bdb55f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1552164
Commit-Queue: Yuchen Liu <yucliu@chromium.org>
Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#650487}
parent b369e2e6
...@@ -3184,16 +3184,19 @@ base::Optional<viz::SurfaceId> WebMediaPlayerImpl::GetSurfaceId() { ...@@ -3184,16 +3184,19 @@ base::Optional<viz::SurfaceId> WebMediaPlayerImpl::GetSurfaceId() {
return bridge_->GetSurfaceId(); return bridge_->GetSurfaceId();
} }
bool WebMediaPlayerImpl::ShouldPauseVideoWhenHidden() const { bool WebMediaPlayerImpl::ShouldPausePlaybackWhenHidden() const {
// Audio only stream is allowed to play when in background.
// TODO: We should check IsBackgroundOptimizationCandidate here. But we need
// to move the logic of checking video frames out of that function.
if (!HasVideo())
return false;
if (!is_background_video_playback_enabled_) if (!is_background_video_playback_enabled_)
return true; return true;
// If suspending background video, pause any video that's not remoted or // If suspending background video, pause any video that's not remoted or
// not unlocked to play in the background. // not unlocked to play in the background.
if (IsBackgroundSuspendEnabled(this)) { if (IsBackgroundSuspendEnabled(this)) {
if (!HasVideo())
return false;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
if (is_flinging_) if (is_flinging_)
return false; return false;
...@@ -3262,7 +3265,7 @@ bool WebMediaPlayerImpl::IsBackgroundOptimizationCandidate() const { ...@@ -3262,7 +3265,7 @@ bool WebMediaPlayerImpl::IsBackgroundOptimizationCandidate() const {
void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() { void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() {
if (IsHidden()) { if (IsHidden()) {
if (ShouldPauseVideoWhenHidden()) { if (ShouldPausePlaybackWhenHidden()) {
PauseVideoIfNeeded(); PauseVideoIfNeeded();
} else if (update_background_status_cb_.IsCancelled()) { } else if (update_background_status_cb_.IsCancelled()) {
// Only trigger updates when we don't have one already scheduled. // Only trigger updates when we don't have one already scheduled.
......
...@@ -461,11 +461,11 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl ...@@ -461,11 +461,11 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
// is intended for android. // is intended for android.
bool DoesOverlaySupportMetadata() const; bool DoesOverlaySupportMetadata() const;
// Whether the video should be paused when hidden. Uses metadata so has // Whether the playback should be paused when hidden. Uses metadata so has
// meaning only after the pipeline has started, otherwise returns false. // meaning only after the pipeline has started, otherwise returns false.
// Doesn't check if the video can actually be paused depending on the // Doesn't check if the playback can actually be paused depending on the
// pipeline's state. // pipeline's state.
bool ShouldPauseVideoWhenHidden() const; bool ShouldPausePlaybackWhenHidden() const;
// Whether the video track should be disabled when hidden. Uses metadata so // Whether the video track should be disabled when hidden. Uses metadata so
// has meaning only after the pipeline has started, otherwise returns false. // has meaning only after the pipeline has started, otherwise returns false.
...@@ -894,7 +894,7 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl ...@@ -894,7 +894,7 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
base::Optional<base::TimeDelta> pipeline_media_duration_for_test_; base::Optional<base::TimeDelta> pipeline_media_duration_for_test_;
// Whether the video requires a user gesture to resume after it was paused in // Whether the video requires a user gesture to resume after it was paused in
// the background. Affects the value of ShouldPauseVideoWhenHidden(). // the background. Affects the value of ShouldPausePlaybackWhenHidden().
bool video_locked_when_paused_when_hidden_ = false; bool video_locked_when_paused_when_hidden_ = false;
// Whether embedded media experience is currently enabled. // Whether embedded media experience is currently enabled.
...@@ -964,7 +964,7 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl ...@@ -964,7 +964,7 @@ class MEDIA_BLINK_EXPORT WebMediaPlayerImpl
bool is_background_suspend_enabled_ = false; bool is_background_suspend_enabled_ = false;
// If disabled, video will be auto paused when in background. Affects the // If disabled, video will be auto paused when in background. Affects the
// value of ShouldPauseVideoWhenHidden(). // value of ShouldPausePlaybackWhenHidden().
bool is_background_video_playback_enabled_ = true; bool is_background_video_playback_enabled_ = true;
// Whether background video optimization is supported on current platform. // Whether background video optimization is supported on current platform.
......
...@@ -1821,8 +1821,8 @@ class WebMediaPlayerImplBackgroundBehaviorTest ...@@ -1821,8 +1821,8 @@ class WebMediaPlayerImplBackgroundBehaviorTest
return wmpi_->ShouldDisableVideoWhenHidden(); return wmpi_->ShouldDisableVideoWhenHidden();
} }
bool ShouldPauseVideoWhenHidden() const { bool ShouldPausePlaybackWhenHidden() const {
return wmpi_->ShouldPauseVideoWhenHidden(); return wmpi_->ShouldPausePlaybackWhenHidden();
} }
bool IsBackgroundOptimizationCandidate() const { bool IsBackgroundOptimizationCandidate() const {
...@@ -1837,8 +1837,7 @@ TEST_P(WebMediaPlayerImplBackgroundBehaviorTest, AudioOnly) { ...@@ -1837,8 +1837,7 @@ TEST_P(WebMediaPlayerImplBackgroundBehaviorTest, AudioOnly) {
// Never optimize or pause an audio-only player. // Never optimize or pause an audio-only player.
SetMetadata(true, false); SetMetadata(true, false);
EXPECT_FALSE(IsBackgroundOptimizationCandidate()); EXPECT_FALSE(IsBackgroundOptimizationCandidate());
EXPECT_FALSE(IsBackgroundVideoPlaybackEnabled() && EXPECT_FALSE(ShouldPausePlaybackWhenHidden());
ShouldPauseVideoWhenHidden());
EXPECT_FALSE(ShouldDisableVideoWhenHidden()); EXPECT_FALSE(ShouldDisableVideoWhenHidden());
} }
...@@ -1858,7 +1857,7 @@ TEST_P(WebMediaPlayerImplBackgroundBehaviorTest, VideoOnly) { ...@@ -1858,7 +1857,7 @@ TEST_P(WebMediaPlayerImplBackgroundBehaviorTest, VideoOnly) {
bool should_pause = !IsBackgroundVideoPlaybackEnabled() || bool should_pause = !IsBackgroundVideoPlaybackEnabled() ||
IsMediaSuspendOn() || IsMediaSuspendOn() ||
(IsBackgroundPauseOn() && matches_requirements); (IsBackgroundPauseOn() && matches_requirements);
EXPECT_EQ(should_pause, ShouldPauseVideoWhenHidden()); EXPECT_EQ(should_pause, ShouldPausePlaybackWhenHidden());
} }
TEST_P(WebMediaPlayerImplBackgroundBehaviorTest, AudioVideo) { TEST_P(WebMediaPlayerImplBackgroundBehaviorTest, AudioVideo) {
...@@ -1880,7 +1879,7 @@ TEST_P(WebMediaPlayerImplBackgroundBehaviorTest, AudioVideo) { ...@@ -1880,7 +1879,7 @@ TEST_P(WebMediaPlayerImplBackgroundBehaviorTest, AudioVideo) {
// videos are on by default on Android and off on desktop. // videos are on by default on Android and off on desktop.
EXPECT_EQ(!IsBackgroundVideoPlaybackEnabled() || EXPECT_EQ(!IsBackgroundVideoPlaybackEnabled() ||
(IsMediaSuspendOn() && IsResumeBackgroundVideoEnabled()), (IsMediaSuspendOn() && IsResumeBackgroundVideoEnabled()),
ShouldPauseVideoWhenHidden()); ShouldPausePlaybackWhenHidden());
if (!IsBackgroundOptimizationOn() || !matches_requirements || if (!IsBackgroundOptimizationOn() || !matches_requirements ||
!ShouldDisableVideoWhenHidden() || IsMediaSuspendOn()) { !ShouldDisableVideoWhenHidden() || IsMediaSuspendOn()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment