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

Unified Diff: media/blink/webmediaplayer_impl.cc

Issue 1739473003: Suspend idle WebMediaPlayer instances after some time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 10 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
Index: media/blink/webmediaplayer_impl.cc
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
index 986984dbcccfa5eb63212ecc399d087fab52c0bd..b1fefd2cc02a1adb48f40cda210fd302f3f4ebab 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -348,8 +348,19 @@ void WebMediaPlayerImpl::play() {
media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY));
- if (playback_rate_ > 0)
- NotifyPlaybackStarted();
+ if (playback_rate_ > 0) {
+ // Resume the player if playback was initiated in the foreground. Resume()
+ // will do nothing if the pipeline is not suspended state, but will clear
+ // some internal pending state, so it should always be called.
+ const bool was_suspended = pipeline_controller_.IsSuspended();
+ if (delegate_ && !delegate_->IsHidden())
+ pipeline_controller_.Resume();
+
+ // If we were in the suspended state, OnPipelineResumed() will take care of
+ // NotifyPlaybackStarted() when it finishes.
+ if (!was_suspended)
+ NotifyPlaybackStarted();
sandersd (OOO until July 31) 2016/02/27 00:22:20 If you swap the order, then no test is needed beca
DaleCurtis 2016/02/27 00:55:23 Done.
+ }
}
void WebMediaPlayerImpl::pause() {
@@ -435,6 +446,12 @@ void WebMediaPlayerImpl::DoSeek(base::TimeDelta time, bool time_updated) {
if (paused_)
paused_time_ = time;
pipeline_controller_.Seek(time, time_updated);
+
+ // Resume the pipeline if the seek is initiated in the foreground so that
+ // the correct frame is displayed. If the pipeline is not suspended, Resume()
+ // will do nothing but clear some pending state -- thus always call it.
+ if (delegate_ && !delegate_->IsHidden())
+ pipeline_controller_.Resume();
}
void WebMediaPlayerImpl::setRate(double rate) {
@@ -1327,7 +1344,7 @@ WebMediaPlayerImpl::GetCurrentFrameFromCompositor() {
void WebMediaPlayerImpl::NotifyPlaybackStarted() {
#if defined(OS_ANDROID) // WMPI_CAST
- // We do not tell our delegates about remote playback, becuase that would
+ // We do not tell our delegates about remote playback, because that would
// keep the device awake, which is not what we want.
if (isRemote())
return;

Powered by Google App Engine
This is Rietveld 408576698