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

Unified Diff: media/blink/webmediaplayer_impl.cc

Issue 2289543005: Allow suspension prior to reaching kHaveFutureData. (Closed)
Patch Set: Rename to setPaused. Created 4 years, 4 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 cde7e38e0a693f2e56086525005bb4e2d23efc8e..d371b832bc066978e25ec26a040657e587e182e5 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -227,7 +227,8 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
suppress_destruction_errors_(false),
can_suspend_state_(CanSuspendState::UNKNOWN),
is_encrypted_(false),
- underflow_count_(0) {
+ underflow_count_(0),
+ is_client_paused_(true) {
DCHECK(!adjust_allocated_memory_cb_.is_null());
DCHECK(renderer_factory_);
DCHECK(client_);
@@ -589,6 +590,13 @@ void WebMediaPlayerImpl::setBufferingStrategy(
data_source_->SetBufferingStrategy(buffering_strategy_);
}
+void WebMediaPlayerImpl::setPaused(bool is_paused) {
+ is_client_paused_ = is_paused;
+ if (highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData)
+ DCHECK_EQ(is_paused, paused_);
+ UpdatePlayState();
+}
+
bool WebMediaPlayerImpl::hasVideo() const {
DCHECK(main_task_runner_->BelongsToCurrentThread());
@@ -1655,6 +1663,11 @@ WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote,
bool have_future_data =
highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData;
+ // Once we reach HaveFutureData, our internal paused state should be accurate,
+ // due to ordering of calls we may temporarily be out of sync though. During
+ // that period, we'll retain the most accurate |paused_| state.
sandersd (OOO until July 31) 2016/08/30 22:41:41 Is it actually 'most accurate'? It happens to be c
DaleCurtis 2016/08/30 22:59:43 Reworded.
+ bool is_paused = have_future_data ? paused_ : is_client_paused_;
+
// Background suspend is not enabled for audio-only players unless paused,
// though in the case of audio-only the session should be kept.
// Videos are not suspended if the user resumed the playback via the remote
@@ -1666,10 +1679,7 @@ WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote,
delegate_ && delegate_->IsPlayingBackgroundVideo();
bool background_suspended = is_backgrounded_video &&
!(can_play_backgrounded && is_background_playing);
-
- // The |paused_| state is not reliable until we |have_future_data|.
- bool background_pause_suspended =
- is_backgrounded && have_future_data && paused_;
+ bool background_pause_suspended = is_backgrounded && is_paused;
// Idle suspend is enabled once there is future data. We don't want to idle
// suspend before that because play() may never be triggered to leave the idle
@@ -1679,16 +1689,15 @@ WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote,
//
// TODO(sandersd): Make the delegate suspend idle players immediately when
// hidden.
- // TODO(sandersd): If Blink told us the paused state sooner, we could
- // idle suspend sooner.
- bool idle_suspended = is_idle_ && have_future_data;
+ bool idle_suspended = is_idle_ && is_paused;
+
+ // If we're already suspended, see if we can wait for user interaction.
+ bool can_stay_suspended = is_suspended && is_paused && !seeking_;
// Combined suspend state.
- result.is_suspended =
- is_remote || must_suspend_ || idle_suspended || background_suspended ||
- background_pause_suspended ||
- // If we're already suspended, see if we can wait for user interaction.
- (is_suspended && have_future_data && paused_ && !seeking_);
+ result.is_suspended = is_remote || must_suspend_ || idle_suspended ||
+ background_suspended || background_pause_suspended ||
+ can_stay_suspended;
// We do not treat |playback_rate_| == 0 as paused. For the media session,
// being paused implies displaying a play button, which is incorrect in this

Powered by Google App Engine
This is Rietveld 408576698