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 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1707 | 1707 |
1708 #if defined(OS_ANDROID) // WMPI_CAST | 1708 #if defined(OS_ANDROID) // WMPI_CAST |
1709 bool is_remote = isRemote(); | 1709 bool is_remote = isRemote(); |
1710 bool is_streaming = false; | 1710 bool is_streaming = false; |
1711 #else | 1711 #else |
1712 bool is_remote = false; | 1712 bool is_remote = false; |
1713 bool is_streaming = data_source_ && data_source_->IsStreaming(); | 1713 bool is_streaming = data_source_ && data_source_->IsStreaming(); |
1714 #endif | 1714 #endif |
1715 | 1715 |
1716 bool is_suspended = pipeline_controller_.IsSuspended(); | 1716 bool is_suspended = pipeline_controller_.IsSuspended(); |
1717 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden(); | 1717 bool is_backgrounded = IsHidden(); |
1718 PlayState state = UpdatePlayState_ComputePlayState( | 1718 PlayState state = UpdatePlayState_ComputePlayState( |
1719 is_remote, is_streaming, is_suspended, is_backgrounded); | 1719 is_remote, is_streaming, is_suspended, is_backgrounded); |
1720 SetDelegateState(state.delegate_state); | 1720 SetDelegateState(state.delegate_state); |
1721 SetMemoryReportingState(state.is_memory_reporting_enabled); | 1721 SetMemoryReportingState(state.is_memory_reporting_enabled); |
1722 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); | 1722 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); |
1723 } | 1723 } |
1724 | 1724 |
1725 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state) { | 1725 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state) { |
1726 if (!delegate_) | 1726 if (!delegate_) |
1727 return; | 1727 return; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1830 | 1830 |
1831 // Background suspend is not enabled for audio-only players unless paused, | 1831 // Background suspend is not enabled for audio-only players unless paused, |
1832 // though in the case of audio-only the session should be kept. | 1832 // though in the case of audio-only the session should be kept. |
1833 // Videos are not suspended if the user resumed the playback via the remote | 1833 // Videos are not suspended if the user resumed the playback via the remote |
1834 // controls earlier and it's still playing. | 1834 // controls earlier and it's still playing. |
1835 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); | 1835 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); |
1836 bool can_play_backgrounded = is_backgrounded_video && !is_remote && | 1836 bool can_play_backgrounded = is_backgrounded_video && !is_remote && |
1837 hasAudio() && IsResumeBackgroundVideosEnabled(); | 1837 hasAudio() && IsResumeBackgroundVideosEnabled(); |
1838 bool is_background_playing = | 1838 bool is_background_playing = |
1839 delegate_ && delegate_->IsPlayingBackgroundVideo(); | 1839 delegate_ && delegate_->IsPlayingBackgroundVideo(); |
1840 bool background_suspended = !is_streaming && is_backgrounded_video && | 1840 // Video-only media should always be suspended when in background. |
1841 bool should_suspend_background_media = | |
1842 IsBackgroundedSuspendEnabled() || !hasAudio(); | |
1843 bool background_suspended = should_suspend_background_media && | |
1844 !is_streaming && is_backgrounded_video && | |
1841 !(can_play_backgrounded && is_background_playing); | 1845 !(can_play_backgrounded && is_background_playing); |
1842 bool background_pause_suspended = | 1846 bool background_pause_suspended = |
1843 !is_streaming && is_backgrounded && paused_ && have_future_data; | 1847 !is_streaming && is_backgrounded && paused_ && have_future_data; |
1844 | 1848 |
1845 // Idle suspension is allowed prior to have future data since there exist | 1849 // Idle suspension is allowed prior to have future data since there exist |
1846 // mechanisms to exit the idle state when the player is capable of reaching | 1850 // mechanisms to exit the idle state when the player is capable of reaching |
1847 // the have future data state; see didLoadingProgress(). | 1851 // the have future data state; see didLoadingProgress(). |
1848 // | 1852 // |
1849 // TODO(sandersd): Make the delegate suspend idle players immediately when | 1853 // TODO(sandersd): Make the delegate suspend idle players immediately when |
1850 // hidden. | 1854 // hidden. |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1944 << ", Video: " << stats.video_memory_usage << ", DataSource: " | 1948 << ", Video: " << stats.video_memory_usage << ", DataSource: " |
1945 << (data_source_ ? data_source_->GetMemoryUsage() : 0) | 1949 << (data_source_ ? data_source_->GetMemoryUsage() : 0) |
1946 << ", Demuxer: " << demuxer_memory_usage; | 1950 << ", Demuxer: " << demuxer_memory_usage; |
1947 | 1951 |
1948 const int64_t delta = current_memory_usage - last_reported_memory_usage_; | 1952 const int64_t delta = current_memory_usage - last_reported_memory_usage_; |
1949 last_reported_memory_usage_ = current_memory_usage; | 1953 last_reported_memory_usage_ = current_memory_usage; |
1950 adjust_allocated_memory_cb_.Run(delta); | 1954 adjust_allocated_memory_cb_.Run(delta); |
1951 } | 1955 } |
1952 | 1956 |
1953 void WebMediaPlayerImpl::ScheduleIdlePauseTimer() { | 1957 void WebMediaPlayerImpl::ScheduleIdlePauseTimer() { |
1954 // Only schedule the pause timer if we're playing and are suspended. | 1958 // Only schedule the pause timer if we're playing, are suspended and |
1955 if (paused_ || !pipeline_controller_.IsSuspended()) | 1959 // have audio. |
1960 if (paused_ || !pipeline_controller_.IsSuspended() || !hasAudio()) | |
sandersd (OOO until July 31)
2016/12/15 01:09:47
This doesn't look quite right to me. The purpose o
whywhat
2016/12/16 01:20:24
Well, it might be - AFAIK it only affects Android
whywhat
2016/12/16 20:09:37
Dan, am I correct that the timer would only trigge
| |
1956 return; | 1961 return; |
1957 | 1962 |
1958 #if defined(OS_ANDROID) | 1963 #if defined(OS_ANDROID) |
1959 // Remote players will be suspended and locally paused. | 1964 // Remote players will be suspended and locally paused. |
1960 if (isRemote()) | 1965 if (isRemote()) |
1961 return; | 1966 return; |
1962 #endif | 1967 #endif |
1963 | 1968 |
1964 // Idle timeout chosen arbitrarily. | 1969 // Idle timeout chosen arbitrarily. |
1965 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), | 1970 background_pause_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(5), |
(...skipping 13 matching lines...) Expand all Loading... | |
1979 watch_time_reporter_->OnShown(); | 1984 watch_time_reporter_->OnShown(); |
1980 } | 1985 } |
1981 | 1986 |
1982 bool WebMediaPlayerImpl::IsHidden() const { | 1987 bool WebMediaPlayerImpl::IsHidden() const { |
1983 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1988 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1984 | 1989 |
1985 return delegate_ && delegate_->IsHidden(); | 1990 return delegate_ && delegate_->IsHidden(); |
1986 } | 1991 } |
1987 | 1992 |
1988 } // namespace media | 1993 } // namespace media |
OLD | NEW |