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

Side by Side Diff: media/blink/webmediaplayer_impl.cc

Issue 2763373003: Don't GONE the unsuspended video only players (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | media/blink/webmediaplayer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 1987 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 // don't have to). 1998 // don't have to).
1999 // 1999 //
2000 // Similarly, we don't consider |ended_| to be paused. Blink will immediately 2000 // Similarly, we don't consider |ended_| to be paused. Blink will immediately
2001 // call pause() or seek(), so |ended_| should not affect the computation. 2001 // call pause() or seek(), so |ended_| should not affect the computation.
2002 // Despite that, |ended_| does result in a separate paused state, to simplfy 2002 // Despite that, |ended_| does result in a separate paused state, to simplfy
2003 // the contract for SetDelegateState(). 2003 // the contract for SetDelegateState().
2004 // 2004 //
2005 // |has_remote_controls| indicates if the player can be controlled outside the 2005 // |has_remote_controls| indicates if the player can be controlled outside the
2006 // page (e.g. via the notification controls or by audio focus events). Idle 2006 // page (e.g. via the notification controls or by audio focus events). Idle
2007 // suspension does not destroy the media session, because we expect that the 2007 // suspension does not destroy the media session, because we expect that the
2008 // notification controls (and audio focus) remain. The following must be true 2008 // notification controls (and audio focus) remain. With some exceptions for
2009 // for the player to have remote controls: 2009 // background videos, the player only needs to have audio to have controls
2010 // (requires |have_future_data|).
2011 //
2012 // |alive| indicates if the player should be present (not |GONE|) to the
2013 // delegate, either paused or playing. The following must be true for the
2014 // player:
2010 // - |have_future_data|, since we need to know whether we are paused to 2015 // - |have_future_data|, since we need to know whether we are paused to
2011 // correctly configure the session and also because the tracks and 2016 // correctly configure the session and also because the tracks and
2012 // duration are passed to DidPlay() 2017 // duration are passed to DidPlay(),
2013 // - |is_remote| is false as remote players have their own controls 2018 // - |is_remote| is false as remote playback is not handled by the delegate,
2014 // - |has_error| is false player should have no errors 2019 // - |has_error| is false as player should have no errors,
2015 // - hasAudio() (requires |have_future_data|) 2020 // - |background_suspended| is false, otherwise |has_remote_controls| must
2021 // be true.
2016 // 2022 //
2017 // TODO(sandersd): If Blink told us the paused state sooner, we could detect 2023 // TODO(sandersd): If Blink told us the paused state sooner, we could detect
2018 // if the remote controls are available sooner. 2024 // if the remote controls are available sooner.
2019 2025
2020 // Background videos with audio don't have remote controls if background 2026 // Background videos with audio don't have remote controls if background
2021 // suspend is enabled and resuming background videos is not (original Android 2027 // suspend is enabled and resuming background videos is not (original Android
2022 // behavior). 2028 // behavior).
2023 bool backgrounded_video_has_no_remote_controls = 2029 bool backgrounded_video_has_no_remote_controls =
2024 IsBackgroundedSuspendEnabled() && !IsResumeBackgroundVideosEnabled() && 2030 IsBackgroundedSuspendEnabled() && !IsResumeBackgroundVideosEnabled() &&
2025 is_backgrounded && hasVideo(); 2031 is_backgrounded && hasVideo();
2026 bool can_play = !has_error && !is_remote && have_future_data; 2032 bool can_play = !has_error && !is_remote && have_future_data;
2027 bool has_remote_controls = can_play && !must_suspend && hasAudio() && 2033 bool has_remote_controls =
2028 !backgrounded_video_has_no_remote_controls; 2034 hasAudio() && !backgrounded_video_has_no_remote_controls;
2029 2035 bool alive = can_play && !must_suspend &&
2030 if (!has_remote_controls) { 2036 (!background_suspended || has_remote_controls);
2037 if (!alive) {
2031 result.delegate_state = DelegateState::GONE; 2038 result.delegate_state = DelegateState::GONE;
2032 result.is_idle = delegate_->IsIdle(delegate_id_); 2039 result.is_idle = delegate_->IsIdle(delegate_id_);
2033 } else if (paused_) { 2040 } else if (paused_) {
2034 // TODO(sandersd): Is it possible to have a suspended session, be ended, 2041 // TODO(sandersd): Is it possible to have a suspended session, be ended,
2035 // and not be paused? If so we should be in a PLAYING state. 2042 // and not be paused? If so we should be in a PLAYING state.
2036 result.delegate_state = 2043 result.delegate_state =
2037 ended_ ? DelegateState::GONE : DelegateState::PAUSED; 2044 ended_ ? DelegateState::GONE : DelegateState::PAUSED;
2038 result.is_idle = !seeking_; 2045 result.is_idle = !seeking_;
2039 } else { 2046 } else {
2040 result.delegate_state = DelegateState::PLAYING; 2047 result.delegate_state = DelegateState::PLAYING;
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
2331 2338
2332 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { 2339 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) {
2333 DCHECK(data_source_ || chunk_demuxer_); 2340 DCHECK(data_source_ || chunk_demuxer_);
2334 if (data_source_) 2341 if (data_source_)
2335 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); 2342 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration);
2336 else 2343 else
2337 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); 2344 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration);
2338 } 2345 }
2339 2346
2340 } // namespace media 2347 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/blink/webmediaplayer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698