| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 media_log_->AddEvent( | 260 media_log_->AddEvent( |
| 261 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); | 261 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); |
| 262 | 262 |
| 263 if (params.initial_cdm()) | 263 if (params.initial_cdm()) |
| 264 SetCdm(params.initial_cdm()); | 264 SetCdm(params.initial_cdm()); |
| 265 | 265 |
| 266 // TODO(xhwang): When we use an external Renderer, many methods won't work, | 266 // TODO(xhwang): When we use an external Renderer, many methods won't work, |
| 267 // e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861 | 267 // e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861 |
| 268 audio_source_provider_ = | 268 audio_source_provider_ = |
| 269 new WebAudioSourceProviderImpl(params.audio_renderer_sink(), media_log_); | 269 new WebAudioSourceProviderImpl(params.audio_renderer_sink(), media_log_); |
| 270 |
| 271 if (observer_) |
| 272 observer_->SetClient(this); |
| 270 } | 273 } |
| 271 | 274 |
| 272 WebMediaPlayerImpl::~WebMediaPlayerImpl() { | 275 WebMediaPlayerImpl::~WebMediaPlayerImpl() { |
| 273 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 276 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 274 | 277 |
| 275 suppress_destruction_errors_ = true; | 278 suppress_destruction_errors_ = true; |
| 276 | 279 |
| 277 delegate_->PlayerGone(delegate_id_); | 280 delegate_->PlayerGone(delegate_id_); |
| 278 delegate_->RemoveObserver(delegate_id_); | 281 delegate_->RemoveObserver(delegate_id_); |
| 279 | 282 |
| (...skipping 1548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1828 &event)); | 1831 &event)); |
| 1829 event.Wait(); | 1832 event.Wait(); |
| 1830 return video_frame; | 1833 return video_frame; |
| 1831 } | 1834 } |
| 1832 | 1835 |
| 1833 void WebMediaPlayerImpl::UpdatePlayState() { | 1836 void WebMediaPlayerImpl::UpdatePlayState() { |
| 1834 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1837 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 1835 | 1838 |
| 1836 #if defined(OS_ANDROID) // WMPI_CAST | 1839 #if defined(OS_ANDROID) // WMPI_CAST |
| 1837 bool is_remote = isRemote(); | 1840 bool is_remote = isRemote(); |
| 1838 bool is_streaming = false; | 1841 bool can_auto_suspend = true; |
| 1839 #else | 1842 #else |
| 1840 bool is_remote = false; | 1843 bool is_remote = false; |
| 1841 bool is_streaming = IsStreaming(); | 1844 bool can_auto_suspend = !disable_pipeline_auto_suspend_ && !IsStreaming(); |
| 1842 #endif | 1845 #endif |
| 1843 | 1846 |
| 1844 bool is_suspended = pipeline_controller_.IsSuspended(); | 1847 bool is_suspended = pipeline_controller_.IsSuspended(); |
| 1845 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden(); | 1848 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden(); |
| 1846 PlayState state = UpdatePlayState_ComputePlayState( | 1849 PlayState state = UpdatePlayState_ComputePlayState( |
| 1847 is_remote, is_streaming, is_suspended, is_backgrounded); | 1850 is_remote, can_auto_suspend, is_suspended, is_backgrounded); |
| 1848 SetDelegateState(state.delegate_state, state.is_idle); | 1851 SetDelegateState(state.delegate_state, state.is_idle); |
| 1849 SetMemoryReportingState(state.is_memory_reporting_enabled); | 1852 SetMemoryReportingState(state.is_memory_reporting_enabled); |
| 1850 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); | 1853 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); |
| 1851 } | 1854 } |
| 1852 | 1855 |
| 1853 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state, | 1856 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state, |
| 1854 bool is_idle) { | 1857 bool is_idle) { |
| 1855 DCHECK(delegate_); | 1858 DCHECK(delegate_); |
| 1856 | 1859 |
| 1857 // Prevent duplicate delegate calls. | 1860 // Prevent duplicate delegate calls. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1928 if (preroll_attempt_pending_) { | 1931 if (preroll_attempt_pending_) { |
| 1929 preroll_attempt_pending_ = false; | 1932 preroll_attempt_pending_ = false; |
| 1930 preroll_attempt_start_time_ = tick_clock_->NowTicks(); | 1933 preroll_attempt_start_time_ = tick_clock_->NowTicks(); |
| 1931 } | 1934 } |
| 1932 pipeline_controller_.Resume(); | 1935 pipeline_controller_.Resume(); |
| 1933 } | 1936 } |
| 1934 } | 1937 } |
| 1935 | 1938 |
| 1936 WebMediaPlayerImpl::PlayState | 1939 WebMediaPlayerImpl::PlayState |
| 1937 WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote, | 1940 WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote, |
| 1938 bool is_streaming, | 1941 bool can_auto_suspend, |
| 1939 bool is_suspended, | 1942 bool is_suspended, |
| 1940 bool is_backgrounded) { | 1943 bool is_backgrounded) { |
| 1941 PlayState result; | 1944 PlayState result; |
| 1942 | 1945 |
| 1943 bool must_suspend = delegate_->IsFrameClosed(); | 1946 bool must_suspend = delegate_->IsFrameClosed(); |
| 1944 bool is_stale = delegate_->IsStale(delegate_id_); | 1947 bool is_stale = delegate_->IsStale(delegate_id_); |
| 1945 | 1948 |
| 1946 // This includes both data source (before pipeline startup) and pipeline | 1949 // This includes both data source (before pipeline startup) and pipeline |
| 1947 // errors. | 1950 // errors. |
| 1948 bool has_error = IsNetworkStateError(network_state_); | 1951 bool has_error = IsNetworkStateError(network_state_); |
| 1949 | 1952 |
| 1950 // After HaveMetadata, we know which tracks are present and the duration. | 1953 // After HaveMetadata, we know which tracks are present and the duration. |
| 1951 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata; | 1954 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata; |
| 1952 | 1955 |
| 1953 // After HaveFutureData, Blink will call play() if the state is not paused; | 1956 // After HaveFutureData, Blink will call play() if the state is not paused; |
| 1954 // prior to this point |paused_| is not accurate. | 1957 // prior to this point |paused_| is not accurate. |
| 1955 bool have_future_data = | 1958 bool have_future_data = |
| 1956 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; | 1959 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; |
| 1957 | 1960 |
| 1958 // Background suspend is not enabled for audio-only players unless paused, | 1961 // Background suspend is not enabled for audio-only players unless paused, |
| 1959 // though in the case of audio-only the session should be kept. | 1962 // though in the case of audio-only the session should be kept. |
| 1960 // Videos are not suspended if the user resumed the playback via the remote | 1963 // Videos are not suspended if the user resumed the playback via the remote |
| 1961 // controls earlier and it's still playing. | 1964 // controls earlier and it's still playing. |
| 1962 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); | 1965 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); |
| 1963 bool can_play_backgrounded = is_backgrounded_video && !is_remote && | 1966 bool can_play_backgrounded = is_backgrounded_video && !is_remote && |
| 1964 hasAudio() && IsResumeBackgroundVideosEnabled(); | 1967 hasAudio() && IsResumeBackgroundVideosEnabled(); |
| 1965 bool is_background_playing = delegate_->IsBackgroundVideoPlaybackUnlocked(); | 1968 bool is_background_playing = delegate_->IsBackgroundVideoPlaybackUnlocked(); |
| 1966 bool background_suspended = !is_streaming && is_backgrounded_video && | 1969 bool background_suspended = can_auto_suspend && is_backgrounded_video && |
| 1967 !(can_play_backgrounded && is_background_playing); | 1970 !(can_play_backgrounded && is_background_playing); |
| 1968 bool background_pause_suspended = | 1971 bool background_pause_suspended = |
| 1969 !is_streaming && is_backgrounded && paused_ && have_future_data; | 1972 can_auto_suspend && is_backgrounded && paused_ && have_future_data; |
| 1970 | 1973 |
| 1971 // Idle suspension is allowed prior to have future data since there exist | 1974 // Idle suspension is allowed prior to have future data since there exist |
| 1972 // mechanisms to exit the idle state when the player is capable of reaching | 1975 // mechanisms to exit the idle state when the player is capable of reaching |
| 1973 // the have future data state; see didLoadingProgress(). | 1976 // the have future data state; see didLoadingProgress(). |
| 1974 // | 1977 // |
| 1975 // TODO(sandersd): Make the delegate suspend idle players immediately when | 1978 // TODO(sandersd): Make the delegate suspend idle players immediately when |
| 1976 // hidden. | 1979 // hidden. |
| 1977 bool idle_suspended = | 1980 bool idle_suspended = |
| 1978 !is_streaming && is_stale && paused_ && !seeking_ && !overlay_enabled_; | 1981 can_auto_suspend && is_stale && paused_ && !seeking_ && !overlay_enabled_; |
| 1979 | 1982 |
| 1980 // If we're already suspended, see if we can wait for user interaction. Prior | 1983 // If we're already suspended, see if we can wait for user interaction. Prior |
| 1981 // to HaveFutureData, we require |is_stale| to remain suspended. |is_stale| | 1984 // to HaveFutureData, we require |is_stale| to remain suspended. |is_stale| |
| 1982 // will be cleared when we receive data which may take us to HaveFutureData. | 1985 // will be cleared when we receive data which may take us to HaveFutureData. |
| 1983 bool can_stay_suspended = | 1986 bool can_stay_suspended = |
| 1984 (is_stale || have_future_data) && is_suspended && paused_ && !seeking_; | 1987 (is_stale || have_future_data) && is_suspended && paused_ && !seeking_; |
| 1985 | 1988 |
| 1986 // Combined suspend state. | 1989 // Combined suspend state. |
| 1987 result.is_suspended = is_remote || must_suspend || idle_suspended || | 1990 result.is_suspended = is_remote || must_suspend || idle_suspended || |
| 1988 background_suspended || background_pause_suspended || | 1991 background_suspended || background_pause_suspended || |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2280 if (hasAudio()) { | 2283 if (hasAudio()) { |
| 2281 UMA_HISTOGRAM_TIMES( | 2284 UMA_HISTOGRAM_TIMES( |
| 2282 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", | 2285 "Media.Video.TimeFromForegroundToFirstFrame.DisableTrack", |
| 2283 time_to_first_frame); | 2286 time_to_first_frame); |
| 2284 } else { | 2287 } else { |
| 2285 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused", | 2288 UMA_HISTOGRAM_TIMES("Media.Video.TimeFromForegroundToFirstFrame.Paused", |
| 2286 time_to_first_frame); | 2289 time_to_first_frame); |
| 2287 } | 2290 } |
| 2288 } | 2291 } |
| 2289 | 2292 |
| 2293 void WebMediaPlayerImpl::SwitchRenderer(bool disable_pipeline_auto_suspend) { |
| 2294 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 2295 disable_pipeline_auto_suspend_ = disable_pipeline_auto_suspend; |
| 2296 ScheduleRestart(); |
| 2297 } |
| 2298 |
| 2290 } // namespace media | 2299 } // namespace media |
| OLD | NEW |