| 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 1693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1704 bool is_backgrounded) { | 1704 bool is_backgrounded) { |
| 1705 PlayState result; | 1705 PlayState result; |
| 1706 | 1706 |
| 1707 // This includes both data source (before pipeline startup) and pipeline | 1707 // This includes both data source (before pipeline startup) and pipeline |
| 1708 // errors. | 1708 // errors. |
| 1709 bool has_error = IsNetworkStateError(network_state_); | 1709 bool has_error = IsNetworkStateError(network_state_); |
| 1710 | 1710 |
| 1711 // After HaveMetadata, we know which tracks are present and the duration. | 1711 // After HaveMetadata, we know which tracks are present and the duration. |
| 1712 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata; | 1712 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata; |
| 1713 | 1713 |
| 1714 // After HaveFutureData, Blink will call play() if the state is not paused. | 1714 // After HaveFutureData, Blink will call play() if the state is not paused; |
| 1715 // prior to this point |paused_| is not accurate. |
| 1715 bool have_future_data = | 1716 bool have_future_data = |
| 1716 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; | 1717 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; |
| 1717 | 1718 |
| 1718 // Background suspend is not enabled for audio-only players unless paused, | 1719 // Background suspend is not enabled for audio-only players unless paused, |
| 1719 // though in the case of audio-only the session should be kept. | 1720 // though in the case of audio-only the session should be kept. |
| 1720 // Videos are not suspended if the user resumed the playback via the remote | 1721 // Videos are not suspended if the user resumed the playback via the remote |
| 1721 // controls earlier and it's still playing. | 1722 // controls earlier and it's still playing. |
| 1722 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); | 1723 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); |
| 1723 bool can_play_backgrounded = is_backgrounded_video && !is_remote && | 1724 bool can_play_backgrounded = is_backgrounded_video && !is_remote && |
| 1724 hasAudio() && IsResumeBackgroundVideosEnabled(); | 1725 hasAudio() && IsResumeBackgroundVideosEnabled(); |
| 1725 bool is_background_playing = | 1726 bool is_background_playing = |
| 1726 delegate_ && delegate_->IsPlayingBackgroundVideo(); | 1727 delegate_ && delegate_->IsPlayingBackgroundVideo(); |
| 1727 bool background_suspended = is_backgrounded_video && | 1728 bool background_suspended = is_backgrounded_video && |
| 1728 !(can_play_backgrounded && is_background_playing); | 1729 !(can_play_backgrounded && is_background_playing); |
| 1729 bool background_pause_suspended = is_backgrounded && paused_; | 1730 bool background_pause_suspended = |
| 1731 is_backgrounded && paused_ && have_future_data; |
| 1730 | 1732 |
| 1733 // Idle suspension is allowed prior to have future data since there exist |
| 1734 // mechanisms to exit the idle state when the player is capable of reaching |
| 1735 // the have future data state; see didLoadingProgress(). |
| 1736 // |
| 1731 // TODO(sandersd): Make the delegate suspend idle players immediately when | 1737 // TODO(sandersd): Make the delegate suspend idle players immediately when |
| 1732 // hidden. | 1738 // hidden. |
| 1733 bool idle_suspended = is_idle_ && paused_ && !seeking_ && !overlay_enabled_; | 1739 bool idle_suspended = is_idle_ && paused_ && !seeking_ && !overlay_enabled_; |
| 1734 | 1740 |
| 1735 // If we're already suspended, see if we can wait for user interaction. Prior | 1741 // If we're already suspended, see if we can wait for user interaction. Prior |
| 1736 // to HaveFutureData, we require |is_idle_| to remain suspended. |is_idle_| | 1742 // to HaveFutureData, we require |is_idle_| to remain suspended. |is_idle_| |
| 1737 // will be cleared when we receive data which may take us to HaveFutureData. | 1743 // will be cleared when we receive data which may take us to HaveFutureData. |
| 1738 bool can_stay_suspended = | 1744 bool can_stay_suspended = |
| 1739 (is_idle_ || have_future_data) && is_suspended && paused_ && !seeking_; | 1745 (is_idle_ || have_future_data) && is_suspended && paused_ && !seeking_; |
| 1740 | 1746 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1854 pipeline_metadata_.natural_size, | 1860 pipeline_metadata_.natural_size, |
| 1855 base::Bind(&GetCurrentTimeInternal, this))); | 1861 base::Bind(&GetCurrentTimeInternal, this))); |
| 1856 watch_time_reporter_->OnVolumeChange(volume_); | 1862 watch_time_reporter_->OnVolumeChange(volume_); |
| 1857 if (delegate_ && delegate_->IsHidden()) | 1863 if (delegate_ && delegate_->IsHidden()) |
| 1858 watch_time_reporter_->OnHidden(); | 1864 watch_time_reporter_->OnHidden(); |
| 1859 else | 1865 else |
| 1860 watch_time_reporter_->OnShown(); | 1866 watch_time_reporter_->OnShown(); |
| 1861 } | 1867 } |
| 1862 | 1868 |
| 1863 } // namespace media | 1869 } // namespace media |
| OLD | NEW |