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

Unified Diff: media/blink/webmediaplayer_impl.cc

Issue 2445533002: Don't suspend the pipeline before HaveFutureData while decoding progressing (Closed)
Patch Set: fix compiler error from rebase Created 4 years, 1 month 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') | media/blink/webmediaplayer_impl_unittest.cc » ('j') | 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 b45d08a3e70e8a85764e88f307f78508129f8021..394f5497aeba882cc51f856d4d2b01c476a87ec6 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -145,6 +145,11 @@ base::TimeDelta GetCurrentTimeInternal(WebMediaPlayerImpl* p_this) {
return base::TimeDelta::FromSecondsD(p_this->currentTime());
}
+// How much time must have elapsed since loading last progressed before the
+// player is eligible for idle suspension.
+constexpr base::TimeDelta kLoadingToIdleTimeout =
+ base::TimeDelta::FromSeconds(3);
+
} // namespace
class BufferedDataSourceHostImpl;
@@ -236,6 +241,8 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
DCHECK(renderer_factory_);
DCHECK(client_);
+ tick_clock_.reset(new base::DefaultTickClock());
+
force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kForceVideoOverlays);
@@ -786,6 +793,9 @@ bool WebMediaPlayerImpl::didLoadingProgress() {
UpdatePlayState();
}
+ if (did_loading_progress)
+ last_time_loading_progressed_ = tick_clock_->NowTicks();
+
return did_loading_progress;
}
@@ -1312,15 +1322,37 @@ void WebMediaPlayerImpl::OnShown() {
UpdatePlayState();
}
-void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) {
+bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) {
DCHECK(main_task_runner_->BelongsToCurrentThread());
- if (must_suspend)
+ if (must_suspend) {
must_suspend_ = true;
- else
+ UpdatePlayState();
+ return true;
+ }
+
+ // If we're beyond HaveFutureData, we can safely suspend at any time.
+ if (highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData) {
+ is_idle_ = true;
+ UpdatePlayState();
+ return true;
+ }
+
+ // Before HaveFutureData blink will not call play(), so we must be careful to
+ // only suspend if we'll eventually receive an event that will trigger a
+ // resume. If the last time loading progressed was a while ago, and we still
+ // haven't reached HaveFutureData, we assume that we're waiting on more data
+ // to continue pre-rolling. When that data is loaded the pipeline will be
+ // resumed by didLoadingProgress().
+ if (last_time_loading_progressed_.is_null() ||
+ (tick_clock_->NowTicks() - last_time_loading_progressed_) >
+ kLoadingToIdleTimeout) {
is_idle_ = true;
+ UpdatePlayState();
+ return true;
+ }
- UpdatePlayState();
+ return false;
}
void WebMediaPlayerImpl::OnPlay() {
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | media/blink/webmediaplayer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698