Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: media/blink/webmediaplayer_impl.cc

Issue 2511573002: Media: Don't suspend streaming media on Desktop. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | media/blink/webmediaplayer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1589 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 } 1600 }
1601 1601
1602 // TODO(sandersd): FileSystem objects may also be non-static, but due to our 1602 // TODO(sandersd): FileSystem objects may also be non-static, but due to our
1603 // caching layer such situations are broken already. http://crbug.com/593159 1603 // caching layer such situations are broken already. http://crbug.com/593159
1604 bool is_static = !chunk_demuxer_; 1604 bool is_static = !chunk_demuxer_;
1605 1605
1606 // ... and we're ready to go! 1606 // ... and we're ready to go!
1607 seeking_ = true; 1607 seeking_ = true;
1608 1608
1609 // TODO(sandersd): On Android, defer Start() if the tab is not visible. 1609 // TODO(sandersd): On Android, defer Start() if the tab is not visible.
1610 bool is_streaming = (data_source_ && data_source_->IsStreaming()); 1610 bool is_streaming = data_source_ && data_source_->IsStreaming();
1611 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static); 1611 pipeline_controller_.Start(demuxer_.get(), this, is_streaming, is_static);
1612 } 1612 }
1613 1613
1614 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) { 1614 void WebMediaPlayerImpl::SetNetworkState(WebMediaPlayer::NetworkState state) {
1615 DVLOG(1) << __func__ << "(" << state << ")"; 1615 DVLOG(1) << __func__ << "(" << state << ")";
1616 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1616 DCHECK(main_task_runner_->BelongsToCurrentThread());
1617 network_state_ = state; 1617 network_state_ = state;
1618 // Always notify to ensure client has the latest value. 1618 // Always notify to ensure client has the latest value.
1619 client_->networkStateChanged(); 1619 client_->networkStateChanged();
1620 } 1620 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 &event)); 1681 &event));
1682 event.Wait(); 1682 event.Wait();
1683 return video_frame; 1683 return video_frame;
1684 } 1684 }
1685 1685
1686 void WebMediaPlayerImpl::UpdatePlayState() { 1686 void WebMediaPlayerImpl::UpdatePlayState() {
1687 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1687 DCHECK(main_task_runner_->BelongsToCurrentThread());
1688 1688
1689 #if defined(OS_ANDROID) // WMPI_CAST 1689 #if defined(OS_ANDROID) // WMPI_CAST
1690 bool is_remote = isRemote(); 1690 bool is_remote = isRemote();
1691 bool is_streaming = false;
1691 #else 1692 #else
1692 bool is_remote = false; 1693 bool is_remote = false;
1694 bool is_streaming = data_source_ && data_source_->IsStreaming();
1693 #endif 1695 #endif
1694 1696
1695 bool is_suspended = pipeline_controller_.IsSuspended(); 1697 bool is_suspended = pipeline_controller_.IsSuspended();
1696 bool is_backgrounded = 1698 bool is_backgrounded =
1697 IsBackgroundedSuspendEnabled() && delegate_ && delegate_->IsHidden(); 1699 IsBackgroundedSuspendEnabled() && delegate_ && delegate_->IsHidden();
1698 PlayState state = UpdatePlayState_ComputePlayState(is_remote, is_suspended, 1700 PlayState state = UpdatePlayState_ComputePlayState(
1699 is_backgrounded); 1701 is_remote, is_streaming, is_suspended, is_backgrounded);
1700 SetDelegateState(state.delegate_state); 1702 SetDelegateState(state.delegate_state);
1701 SetMemoryReportingState(state.is_memory_reporting_enabled); 1703 SetMemoryReportingState(state.is_memory_reporting_enabled);
1702 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); 1704 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_);
1703 } 1705 }
1704 1706
1705 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state) { 1707 void WebMediaPlayerImpl::SetDelegateState(DelegateState new_state) {
1706 if (!delegate_) 1708 if (!delegate_)
1707 return; 1709 return;
1708 1710
1709 if (delegate_state_ == new_state) { 1711 if (delegate_state_ == new_state) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1784 1786
1785 if (is_suspended) { 1787 if (is_suspended) {
1786 pipeline_controller_.Suspend(); 1788 pipeline_controller_.Suspend();
1787 } else { 1789 } else {
1788 pipeline_controller_.Resume(); 1790 pipeline_controller_.Resume();
1789 } 1791 }
1790 } 1792 }
1791 1793
1792 WebMediaPlayerImpl::PlayState 1794 WebMediaPlayerImpl::PlayState
1793 WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote, 1795 WebMediaPlayerImpl::UpdatePlayState_ComputePlayState(bool is_remote,
1796 bool is_streaming,
1794 bool is_suspended, 1797 bool is_suspended,
1795 bool is_backgrounded) { 1798 bool is_backgrounded) {
1796 PlayState result; 1799 PlayState result;
1797 1800
1798 // This includes both data source (before pipeline startup) and pipeline 1801 // This includes both data source (before pipeline startup) and pipeline
1799 // errors. 1802 // errors.
1800 bool has_error = IsNetworkStateError(network_state_); 1803 bool has_error = IsNetworkStateError(network_state_);
1801 1804
1802 // After HaveMetadata, we know which tracks are present and the duration. 1805 // After HaveMetadata, we know which tracks are present and the duration.
1803 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata; 1806 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata;
1804 1807
1805 // After HaveFutureData, Blink will call play() if the state is not paused; 1808 // After HaveFutureData, Blink will call play() if the state is not paused;
1806 // prior to this point |paused_| is not accurate. 1809 // prior to this point |paused_| is not accurate.
1807 bool have_future_data = 1810 bool have_future_data =
1808 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; 1811 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData;
1809 1812
1810 // Background suspend is not enabled for audio-only players unless paused, 1813 // Background suspend is not enabled for audio-only players unless paused,
1811 // though in the case of audio-only the session should be kept. 1814 // though in the case of audio-only the session should be kept.
1812 // Videos are not suspended if the user resumed the playback via the remote 1815 // Videos are not suspended if the user resumed the playback via the remote
1813 // controls earlier and it's still playing. 1816 // controls earlier and it's still playing.
1814 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); 1817 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo();
1815 bool can_play_backgrounded = is_backgrounded_video && !is_remote && 1818 bool can_play_backgrounded = is_backgrounded_video && !is_remote &&
1816 hasAudio() && IsResumeBackgroundVideosEnabled(); 1819 hasAudio() && IsResumeBackgroundVideosEnabled();
1817 bool is_background_playing = 1820 bool is_background_playing =
1818 delegate_ && delegate_->IsPlayingBackgroundVideo(); 1821 delegate_ && delegate_->IsPlayingBackgroundVideo();
1819 bool background_suspended = is_backgrounded_video && 1822 bool background_suspended = !is_streaming && is_backgrounded_video &&
1820 !(can_play_backgrounded && is_background_playing); 1823 !(can_play_backgrounded && is_background_playing);
1821 bool background_pause_suspended = 1824 bool background_pause_suspended =
1822 is_backgrounded && paused_ && have_future_data; 1825 !is_streaming && is_backgrounded && paused_ && have_future_data;
1823 1826
1824 // Idle suspension is allowed prior to have future data since there exist 1827 // Idle suspension is allowed prior to have future data since there exist
1825 // mechanisms to exit the idle state when the player is capable of reaching 1828 // mechanisms to exit the idle state when the player is capable of reaching
1826 // the have future data state; see didLoadingProgress(). 1829 // the have future data state; see didLoadingProgress().
1827 // 1830 //
1828 // TODO(sandersd): Make the delegate suspend idle players immediately when 1831 // TODO(sandersd): Make the delegate suspend idle players immediately when
1829 // hidden. 1832 // hidden.
1830 bool idle_suspended = is_idle_ && paused_ && !seeking_ && !overlay_enabled_; 1833 bool idle_suspended =
1834 !is_streaming && is_idle_ && paused_ && !seeking_ && !overlay_enabled_;
1831 1835
1832 // If we're already suspended, see if we can wait for user interaction. Prior 1836 // If we're already suspended, see if we can wait for user interaction. Prior
1833 // to HaveFutureData, we require |is_idle_| to remain suspended. |is_idle_| 1837 // to HaveFutureData, we require |is_idle_| to remain suspended. |is_idle_|
1834 // will be cleared when we receive data which may take us to HaveFutureData. 1838 // will be cleared when we receive data which may take us to HaveFutureData.
1835 bool can_stay_suspended = 1839 bool can_stay_suspended =
1836 (is_idle_ || have_future_data) && is_suspended && paused_ && !seeking_; 1840 (is_idle_ || have_future_data) && is_suspended && paused_ && !seeking_;
1837 1841
1838 // Combined suspend state. 1842 // Combined suspend state.
1839 result.is_suspended = is_remote || must_suspend_ || idle_suspended || 1843 result.is_suspended = is_remote || must_suspend_ || idle_suspended ||
1840 background_suspended || background_pause_suspended || 1844 background_suspended || background_pause_suspended ||
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 pipeline_metadata_.natural_size, 1955 pipeline_metadata_.natural_size,
1952 base::Bind(&GetCurrentTimeInternal, this))); 1956 base::Bind(&GetCurrentTimeInternal, this)));
1953 watch_time_reporter_->OnVolumeChange(volume_); 1957 watch_time_reporter_->OnVolumeChange(volume_);
1954 if (delegate_ && delegate_->IsHidden()) 1958 if (delegate_ && delegate_->IsHidden())
1955 watch_time_reporter_->OnHidden(); 1959 watch_time_reporter_->OnHidden();
1956 else 1960 else
1957 watch_time_reporter_->OnShown(); 1961 watch_time_reporter_->OnShown();
1958 } 1962 }
1959 1963
1960 } // namespace media 1964 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | media/blink/webmediaplayer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698