| 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 1723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1734 bool is_backgrounded) { | 1734 bool is_backgrounded) { |
| 1735 PlayState result; | 1735 PlayState result; |
| 1736 | 1736 |
| 1737 // This includes both data source (before pipeline startup) and pipeline | 1737 // This includes both data source (before pipeline startup) and pipeline |
| 1738 // errors. | 1738 // errors. |
| 1739 bool has_error = IsNetworkStateError(network_state_); | 1739 bool has_error = IsNetworkStateError(network_state_); |
| 1740 | 1740 |
| 1741 // After HaveMetadata, we know which tracks are present and the duration. | 1741 // After HaveMetadata, we know which tracks are present and the duration. |
| 1742 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata; | 1742 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata; |
| 1743 | 1743 |
| 1744 // After HaveFutureData, Blink will call play() if the state is not paused. | 1744 // After HaveFutureData, Blink will call play() if the state is not paused; |
| 1745 // prior to this point |paused_| is not accurate. |
| 1745 bool have_future_data = | 1746 bool have_future_data = |
| 1746 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; | 1747 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; |
| 1747 | 1748 |
| 1748 // Background suspend is not enabled for audio-only players unless paused, | 1749 // Background suspend is not enabled for audio-only players unless paused, |
| 1749 // though in the case of audio-only the session should be kept. | 1750 // though in the case of audio-only the session should be kept. |
| 1750 // Videos are not suspended if the user resumed the playback via the remote | 1751 // Videos are not suspended if the user resumed the playback via the remote |
| 1751 // controls earlier and it's still playing. | 1752 // controls earlier and it's still playing. |
| 1752 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); | 1753 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); |
| 1753 bool can_play_backgrounded = is_backgrounded_video && !is_remote && | 1754 bool can_play_backgrounded = is_backgrounded_video && !is_remote && |
| 1754 hasAudio() && IsResumeBackgroundVideosEnabled(); | 1755 hasAudio() && IsResumeBackgroundVideosEnabled(); |
| 1755 bool is_background_playing = | 1756 bool is_background_playing = |
| 1756 delegate_ && delegate_->IsPlayingBackgroundVideo(); | 1757 delegate_ && delegate_->IsPlayingBackgroundVideo(); |
| 1757 bool background_suspended = is_backgrounded_video && | 1758 bool background_suspended = is_backgrounded_video && |
| 1758 !(can_play_backgrounded && is_background_playing); | 1759 !(can_play_backgrounded && is_background_playing); |
| 1759 bool background_pause_suspended = is_backgrounded && paused_; | 1760 bool background_pause_suspended = |
| 1761 is_backgrounded && paused_ && have_future_data; |
| 1760 | 1762 |
| 1763 // Idle suspension is allowed prior to have future data since there exist |
| 1764 // mechanisms to exit the idle state when the player is capable of reaching |
| 1765 // the have future data state; see didLoadingProgress(). |
| 1766 // |
| 1761 // TODO(sandersd): Make the delegate suspend idle players immediately when | 1767 // TODO(sandersd): Make the delegate suspend idle players immediately when |
| 1762 // hidden. | 1768 // hidden. |
| 1763 bool idle_suspended = is_idle_ && paused_ && !seeking_ && !overlay_enabled_; | 1769 bool idle_suspended = is_idle_ && paused_ && !seeking_ && !overlay_enabled_; |
| 1764 | 1770 |
| 1765 // If we're already suspended, see if we can wait for user interaction. Prior | 1771 // If we're already suspended, see if we can wait for user interaction. Prior |
| 1766 // to HaveFutureData, we require |is_idle_| to remain suspended. |is_idle_| | 1772 // to HaveFutureData, we require |is_idle_| to remain suspended. |is_idle_| |
| 1767 // will be cleared when we receive data which may take us to HaveFutureData. | 1773 // will be cleared when we receive data which may take us to HaveFutureData. |
| 1768 bool can_stay_suspended = | 1774 bool can_stay_suspended = |
| 1769 (is_idle_ || have_future_data) && is_suspended && paused_ && !seeking_; | 1775 (is_idle_ || have_future_data) && is_suspended && paused_ && !seeking_; |
| 1770 | 1776 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 pipeline_metadata_.natural_size, | 1890 pipeline_metadata_.natural_size, |
| 1885 base::Bind(&GetCurrentTimeInternal, this))); | 1891 base::Bind(&GetCurrentTimeInternal, this))); |
| 1886 watch_time_reporter_->OnVolumeChange(volume_); | 1892 watch_time_reporter_->OnVolumeChange(volume_); |
| 1887 if (delegate_ && delegate_->IsHidden()) | 1893 if (delegate_ && delegate_->IsHidden()) |
| 1888 watch_time_reporter_->OnHidden(); | 1894 watch_time_reporter_->OnHidden(); |
| 1889 else | 1895 else |
| 1890 watch_time_reporter_->OnShown(); | 1896 watch_time_reporter_->OnShown(); |
| 1891 } | 1897 } |
| 1892 | 1898 |
| 1893 } // namespace media | 1899 } // namespace media |
| OLD | NEW |