Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Unified Diff: media/blink/webmediaplayer_impl.cc

Issue 2644723004: [Video] Don't pause video-only elements if they're already paused... (Closed)
Patch Set: Improved comments, extracted method Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/webmediaplayer_impl.cc
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
index d1f0b448102d3dcb861b90c76ab7e71195487153..fb081b50fae8f5ee7647a5be2c40ce74934f92d5 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -1121,6 +1121,10 @@ void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) {
// Reset underflow count upon seek; this prevents looping videos and user
// actions from artificially inflating the underflow count.
underflow_count_ = 0;
+
+ // Background video optimizations are delayed when shown/hidden if pipeline
+ // is seeking.
+ UpdateBackgroundVideoOptimizationState();
}
void WebMediaPlayerImpl::OnPipelineSuspended() {
@@ -1160,11 +1164,7 @@ void WebMediaPlayerImpl::OnBeforePipelineResume() {
void WebMediaPlayerImpl::OnPipelineResumed() {
is_pipeline_resuming_ = false;
- if (IsHidden()) {
- DisableVideoTrackIfNeeded();
- } else {
- EnableVideoTrackIfNeeded();
- }
+ UpdateBackgroundVideoOptimizationState();
}
void WebMediaPlayerImpl::OnDemuxerOpened() {
@@ -1411,13 +1411,8 @@ void WebMediaPlayerImpl::OnFrameHidden() {
watch_time_reporter_->OnHidden();
if (ShouldPauseVideoWhenHidden()) {
sandersd (OOO until July 31) 2017/01/20 22:57:00 Should just call UpdateBackgroundVideoOptimization
whywhat 2017/01/20 23:24:45 Hm, here we already know we're hidden. We also wan
sandersd (OOO until July 31) 2017/01/20 23:29:42 Ah I see, I missed the early return when comparing
- if (!paused_when_hidden_) {
- // OnPause() will set |paused_when_hidden_| to false and call
- // UpdatePlayState(), so set the flag to true after and then return.
- OnPause();
- paused_when_hidden_ = true;
- return;
- }
+ PauseVideoIfNeeded();
+ return;
} else {
DisableVideoTrackIfNeeded();
}
@@ -2182,9 +2177,35 @@ bool WebMediaPlayerImpl::IsBackgroundOptimizationCandidate() const {
max_keyframe_distance_to_disable_background_video_;
}
+void WebMediaPlayerImpl::UpdateBackgroundVideoOptimizationState() {
+ if (IsHidden()) {
+ if (ShouldPauseVideoWhenHidden())
+ PauseVideoIfNeeded();
+ else
+ DisableVideoTrackIfNeeded();
+ } else {
+ EnableVideoTrackIfNeeded();
+ }
+}
+
+void WebMediaPlayerImpl::PauseVideoIfNeeded() {
+ DCHECK(IsHidden());
+
+ // Don't pause video while the pipeline is stopped, resuming or seeking.
+ // Also if the video is paused already.
+ if (!pipeline_.IsRunning() || is_pipeline_resuming_ || seeking_ || paused_)
+ return;
+
+ // OnPause() will set |paused_when_hidden_| to false and call
+ // UpdatePlayState(), so set the flag to true after and then return.
+ OnPause();
+ paused_when_hidden_ = true;
+}
+
void WebMediaPlayerImpl::EnableVideoTrackIfNeeded() {
- // Don't change video track while the pipeline is resuming or seeking.
- if (is_pipeline_resuming_ || seeking_)
+ // Don't change video track while the pipeline is stopped, resuming or
+ // seeking.
+ if (!pipeline_.IsRunning() || is_pipeline_resuming_ || seeking_)
return;
if (video_track_disabled_) {
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698