| Index: media/blink/webmediaplayer_impl.cc
|
| diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
|
| index 3e1500e121bab874f209093e74cb36922672fd20..85485c4f1cd07d47c4999863cc06c309f1d4e882 100644
|
| --- a/media/blink/webmediaplayer_impl.cc
|
| +++ b/media/blink/webmediaplayer_impl.cc
|
| @@ -236,6 +236,8 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
|
| DCHECK(renderer_factory_);
|
| DCHECK(client_);
|
|
|
| + tick_clock_ = &default_tick_clock_;
|
| +
|
| force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| switches::kForceVideoOverlays);
|
|
|
| @@ -782,6 +784,9 @@ bool WebMediaPlayerImpl::didLoadingProgress() {
|
| UpdatePlayState();
|
| }
|
|
|
| + if (did_loading_progress)
|
| + last_time_loading_progressed_ = tick_clock_->NowTicks();
|
| +
|
| return did_loading_progress;
|
| }
|
|
|
| @@ -1308,15 +1313,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 longer than 3 seconds ago,
|
| + // and we still haven't reached HaveFutureData, assume that we're waiting on
|
| + // more data to proceed. 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_) >
|
| + base::TimeDelta::FromSeconds(3)) {
|
| is_idle_ = true;
|
| + UpdatePlayState();
|
| + return true;
|
| + }
|
|
|
| - UpdatePlayState();
|
| + return false;
|
| }
|
|
|
| void WebMediaPlayerImpl::OnPlay() {
|
|
|