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

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

Issue 2767253002: Don't GONE the unsuspended video only players (Closed)
Patch Set: Fixed comments 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 1990 matching lines...) Expand 10 before | Expand all | Expand 10 after
2001 // don't have to). 2001 // don't have to).
2002 // 2002 //
2003 // Similarly, we don't consider |ended_| to be paused. Blink will immediately 2003 // Similarly, we don't consider |ended_| to be paused. Blink will immediately
2004 // call pause() or seek(), so |ended_| should not affect the computation. 2004 // call pause() or seek(), so |ended_| should not affect the computation.
2005 // Despite that, |ended_| does result in a separate paused state, to simplfy 2005 // Despite that, |ended_| does result in a separate paused state, to simplfy
2006 // the contract for SetDelegateState(). 2006 // the contract for SetDelegateState().
2007 // 2007 //
2008 // |has_remote_controls| indicates if the player can be controlled outside the 2008 // |has_remote_controls| indicates if the player can be controlled outside the
2009 // page (e.g. via the notification controls or by audio focus events). Idle 2009 // page (e.g. via the notification controls or by audio focus events). Idle
2010 // suspension does not destroy the media session, because we expect that the 2010 // suspension does not destroy the media session, because we expect that the
2011 // notification controls (and audio focus) remain. The following must be true 2011 // notification controls (and audio focus) remain. With some exceptions for
2012 // for the player to have remote controls: 2012 // background videos, the player only needs to have audio to have controls
2013 // (requires |have_future_data|).
2014 //
2015 // |alive| indicates if the player should be present (not |GONE|) to the
2016 // delegate, either paused or playing. The following must be true for the
2017 // player:
2013 // - |have_future_data|, since we need to know whether we are paused to 2018 // - |have_future_data|, since we need to know whether we are paused to
2014 // correctly configure the session and also because the tracks and 2019 // correctly configure the session and also because the tracks and
2015 // duration are passed to DidPlay() 2020 // duration are passed to DidPlay(),
2016 // - |is_remote| is false as remote players have their own controls 2021 // - |is_remote| is false as remote playback is not handled by the delegate,
2017 // - |has_error| is false player should have no errors 2022 // - |has_error| is false as player should have no errors,
2018 // - hasAudio() (requires |have_future_data|) 2023 // - |background_suspended| is false, otherwise |has_remote_controls| must
2024 // be true.
2019 // 2025 //
2020 // TODO(sandersd): If Blink told us the paused state sooner, we could detect 2026 // TODO(sandersd): If Blink told us the paused state sooner, we could detect
2021 // if the remote controls are available sooner. 2027 // if the remote controls are available sooner.
2022 2028
2023 // Background videos with audio don't have remote controls if background 2029 // Background videos with audio don't have remote controls if background
2024 // suspend is enabled and resuming background videos is not (original Android 2030 // suspend is enabled and resuming background videos is not (original Android
2025 // behavior). 2031 // behavior).
2026 bool backgrounded_video_has_no_remote_controls = 2032 bool backgrounded_video_has_no_remote_controls =
2027 IsBackgroundedSuspendEnabled() && !IsResumeBackgroundVideosEnabled() && 2033 IsBackgroundedSuspendEnabled() && !IsResumeBackgroundVideosEnabled() &&
2028 is_backgrounded && hasVideo(); 2034 is_backgrounded && hasVideo();
2029 bool can_play = !has_error && !is_remote && have_future_data; 2035 bool can_play = !has_error && !is_remote && have_future_data;
2030 bool has_remote_controls = can_play && !must_suspend && hasAudio() && 2036 bool has_remote_controls =
2031 !backgrounded_video_has_no_remote_controls; 2037 hasAudio() && !backgrounded_video_has_no_remote_controls;
2032 2038 bool alive = can_play && !must_suspend &&
2033 if (!has_remote_controls) { 2039 (!background_suspended || has_remote_controls);
2040 if (!alive) {
2034 result.delegate_state = DelegateState::GONE; 2041 result.delegate_state = DelegateState::GONE;
2035 result.is_idle = delegate_->IsIdle(delegate_id_); 2042 result.is_idle = delegate_->IsIdle(delegate_id_);
2036 } else if (paused_) { 2043 } else if (paused_) {
2037 // TODO(sandersd): Is it possible to have a suspended session, be ended, 2044 // TODO(sandersd): Is it possible to have a suspended session, be ended,
2038 // and not be paused? If so we should be in a PLAYING state. 2045 // and not be paused? If so we should be in a PLAYING state.
2039 result.delegate_state = 2046 result.delegate_state =
2040 ended_ ? DelegateState::GONE : DelegateState::PAUSED; 2047 ended_ ? DelegateState::GONE : DelegateState::PAUSED;
2041 result.is_idle = !seeking_; 2048 result.is_idle = !seeking_;
2042 } else { 2049 } else {
2043 result.delegate_state = DelegateState::PLAYING; 2050 result.delegate_state = DelegateState::PLAYING;
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
2325 2332
2326 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { 2333 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) {
2327 DCHECK(data_source_ || chunk_demuxer_); 2334 DCHECK(data_source_ || chunk_demuxer_);
2328 if (data_source_) 2335 if (data_source_)
2329 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); 2336 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration);
2330 else 2337 else
2331 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); 2338 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration);
2332 } 2339 }
2333 2340
2334 } // namespace media 2341 } // 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