| OLD | NEW |
| 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 1953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1964 // don't have to). | 1964 // don't have to). |
| 1965 // | 1965 // |
| 1966 // Similarly, we don't consider |ended_| to be paused. Blink will immediately | 1966 // Similarly, we don't consider |ended_| to be paused. Blink will immediately |
| 1967 // call pause() or seek(), so |ended_| should not affect the computation. | 1967 // call pause() or seek(), so |ended_| should not affect the computation. |
| 1968 // Despite that, |ended_| does result in a separate paused state, to simplfy | 1968 // Despite that, |ended_| does result in a separate paused state, to simplfy |
| 1969 // the contract for SetDelegateState(). | 1969 // the contract for SetDelegateState(). |
| 1970 // | 1970 // |
| 1971 // |has_remote_controls| indicates if the player can be controlled outside the | 1971 // |has_remote_controls| indicates if the player can be controlled outside the |
| 1972 // page (e.g. via the notification controls or by audio focus events). Idle | 1972 // page (e.g. via the notification controls or by audio focus events). Idle |
| 1973 // suspension does not destroy the media session, because we expect that the | 1973 // suspension does not destroy the media session, because we expect that the |
| 1974 // notification controls (and audio focus) remain. The following must be true | 1974 // notification controls (and audio focus) remain. With some exceptions for |
| 1975 // for the player to have remote controls: | 1975 // background videos, the player only needs to have audio to have controls |
| 1976 // (requires |have_future_data|). |
| 1977 // |
| 1978 // |alive| indicates if the player should be present (not |GONE|) to the |
| 1979 // delegate, either paused or playing. The following must be true for the |
| 1980 // player: |
| 1976 // - |have_future_data|, since we need to know whether we are paused to | 1981 // - |have_future_data|, since we need to know whether we are paused to |
| 1977 // correctly configure the session and also because the tracks and | 1982 // correctly configure the session and also because the tracks and |
| 1978 // duration are passed to DidPlay() | 1983 // duration are passed to DidPlay(), |
| 1979 // - |is_remote| is false as remote players have their own controls | 1984 // - |is_remote| is false as remote playback is not handled by the delegate, |
| 1980 // - |has_error| is false player should have no errors | 1985 // - |has_error| is false as player should have no errors, |
| 1981 // - hasAudio() (requires |have_future_data|) | 1986 // - |background_suspended| is false, otherwise |has_remote_controls| must |
| 1987 // be true. |
| 1982 // | 1988 // |
| 1983 // TODO(sandersd): If Blink told us the paused state sooner, we could detect | 1989 // TODO(sandersd): If Blink told us the paused state sooner, we could detect |
| 1984 // if the remote controls are available sooner. | 1990 // if the remote controls are available sooner. |
| 1985 | 1991 |
| 1986 // Background videos with audio don't have remote controls if background | 1992 // Background videos with audio don't have remote controls if background |
| 1987 // suspend is enabled and resuming background videos is not (original Android | 1993 // suspend is enabled and resuming background videos is not (original Android |
| 1988 // behavior). | 1994 // behavior). |
| 1989 bool backgrounded_video_has_no_remote_controls = | 1995 bool backgrounded_video_has_no_remote_controls = |
| 1990 IsBackgroundedSuspendEnabled() && !IsResumeBackgroundVideosEnabled() && | 1996 IsBackgroundedSuspendEnabled() && !IsResumeBackgroundVideosEnabled() && |
| 1991 is_backgrounded && hasVideo(); | 1997 is_backgrounded && hasVideo(); |
| 1992 bool can_play = !has_error && !is_remote && have_future_data; | 1998 bool can_play = !has_error && !is_remote && have_future_data; |
| 1993 bool has_remote_controls = can_play && !must_suspend && hasAudio() && | 1999 bool has_remote_controls = |
| 1994 !backgrounded_video_has_no_remote_controls; | 2000 hasAudio() && !backgrounded_video_has_no_remote_controls; |
| 1995 | 2001 bool alive = can_play && !must_suspend && |
| 1996 if (!has_remote_controls) { | 2002 (!background_suspended || has_remote_controls); |
| 2003 if (!alive) { |
| 1997 result.delegate_state = DelegateState::GONE; | 2004 result.delegate_state = DelegateState::GONE; |
| 1998 result.is_idle = delegate_ && delegate_->IsIdle(delegate_id_); | 2005 result.is_idle = delegate_ && delegate_->IsIdle(delegate_id_); |
| 1999 } else if (paused_) { | 2006 } else if (paused_) { |
| 2000 // TODO(sandersd): Is it possible to have a suspended session, be ended, | 2007 // TODO(sandersd): Is it possible to have a suspended session, be ended, |
| 2001 // and not be paused? If so we should be in a PLAYING state. | 2008 // and not be paused? If so we should be in a PLAYING state. |
| 2002 result.delegate_state = | 2009 result.delegate_state = |
| 2003 ended_ ? DelegateState::GONE : DelegateState::PAUSED; | 2010 ended_ ? DelegateState::GONE : DelegateState::PAUSED; |
| 2004 result.is_idle = !seeking_; | 2011 result.is_idle = !seeking_; |
| 2005 } else { | 2012 } else { |
| 2006 result.delegate_state = DelegateState::PLAYING; | 2013 result.delegate_state = DelegateState::PLAYING; |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2275 } | 2282 } |
| 2276 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { | 2283 void WebMediaPlayerImpl::RecordUnderflowDuration(base::TimeDelta duration) { |
| 2277 DCHECK(data_source_ || chunk_demuxer_); | 2284 DCHECK(data_source_ || chunk_demuxer_); |
| 2278 if (data_source_) | 2285 if (data_source_) |
| 2279 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); | 2286 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration", duration); |
| 2280 else | 2287 else |
| 2281 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); | 2288 UMA_HISTOGRAM_TIMES("Media.UnderflowDuration.MSE", duration); |
| 2282 } | 2289 } |
| 2283 | 2290 |
| 2284 } // namespace media | 2291 } // namespace media |
| OLD | NEW |