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

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: NON_EXPORTED_BASE. 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
« no previous file with comments | « content/renderer/media/renderer_webmediaplayer_delegate_browsertest.cc ('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 4f966ebf9b0d1678c71463ecea8b49666d1a02eb..71b21f4d3c934ce926141298bd92045441cdf93d 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -347,8 +347,15 @@ void WebMediaPlayerImpl::play() {
media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY));
- if (playback_rate_ > 0)
+ if (playback_rate_ > 0) {
+ // Resume the player if playback was initiated in the foreground.
+ if (suspended_ && !resuming_ && delegate_ && !delegate_->IsHidden()) {
+ Resume();
+ return;
+ }
+
NotifyPlaybackStarted();
+ }
}
void WebMediaPlayerImpl::pause() {
@@ -437,6 +444,11 @@ void WebMediaPlayerImpl::seek(double seconds) {
if (is_suspended) {
seeking_ = true;
seek_time_ = new_seek_time;
+
+ // Resume the pipeline if the seek is initiated in the foreground so that
+ // the correct frame is displayed.
+ if (delegate_ && !delegate_->IsHidden())
+ Resume();
}
return;
@@ -887,14 +899,15 @@ void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed,
return;
}
- // If we we're resuming into the playing state, notify the delegate.
- if (resuming_ && playback_rate_ > 0 && !paused_)
- NotifyPlaybackStarted();
-
// Whether or not the seek was caused by a resume, we're not suspended now.
+ const bool was_resuming = resuming_;
resuming_ = false;
suspended_ = false;
+ // If we we're resuming into the playing state, notify the delegate.
+ if (was_resuming && playback_rate_ > 0 && !paused_)
+ NotifyPlaybackStarted();
+
// If there is a pending suspend, the seek does not complete until after the
// next resume.
if (pending_suspend_) {
@@ -1151,7 +1164,8 @@ void WebMediaPlayerImpl::OnShown() {
return;
#endif
- ScheduleResume();
+ if (!ended_ && !paused_)
+ ScheduleResume();
}
void WebMediaPlayerImpl::ScheduleResume() {
@@ -1522,11 +1536,18 @@ void WebMediaPlayerImpl::UpdatePausedTime() {
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;
#endif
+
+ // Don't send delegate notifications when suspended; upon suspend we send
+ // PlayerGone() to the delegate -- no more notifications should be sent until
+ // after resume.
+ if (suspended_)
+ return;
+
if (delegate_) {
delegate_->DidPlay(delegate_id_, hasVideo(), hasAudio(), false,
pipeline_.GetMediaDuration());
@@ -1543,7 +1564,10 @@ void WebMediaPlayerImpl::NotifyPlaybackPaused() {
if (isRemote())
return;
#endif
- if (delegate_)
+ // Don't send delegate notifications when suspended; upon suspend we send
+ // PlayerGone() to the delegate -- no more notifications should be sent until
+ // after resume.
+ if (!suspended_ && delegate_)
delegate_->DidPause(delegate_id_, ended_);
memory_usage_reporting_timer_.Stop();
ReportMemoryUsage();
« no previous file with comments | « content/renderer/media/renderer_webmediaplayer_delegate_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698