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

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

Issue 2979893002: media: Allow suspend on HTTP 200 videos (Closed)
Patch Set: layout test fix Created 3 years, 5 months 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
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 1802 matching lines...) Expand 10 before | Expand all | Expand 10 after
1813 if (!success) { 1813 if (!success) {
1814 SetNetworkState(WebMediaPlayer::kNetworkStateFormatError); 1814 SetNetworkState(WebMediaPlayer::kNetworkStateFormatError);
1815 1815
1816 // Not really necessary, since the pipeline was never started, but it at 1816 // Not really necessary, since the pipeline was never started, but it at
1817 // least this makes sure that the error handling code is in sync. 1817 // least this makes sure that the error handling code is in sync.
1818 UpdatePlayState(); 1818 UpdatePlayState();
1819 1819
1820 return; 1820 return;
1821 } 1821 }
1822 1822
1823 // No point in preloading data as we'll probably just throw it away anyways.
1824 if (IsStreaming() && preload_ > MultibufferDataSource::METADATA) {
1825 data_source_->SetPreload(MultibufferDataSource::METADATA);
1826 }
1827
1823 StartPipeline(); 1828 StartPipeline();
1824 } 1829 }
1825 1830
1826 void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) { 1831 void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) {
1827 DVLOG(1) << __func__ << "(" << is_downloading << ")"; 1832 DVLOG(1) << __func__ << "(" << is_downloading << ")";
1828 if (!is_downloading && network_state_ == WebMediaPlayer::kNetworkStateLoading) 1833 if (!is_downloading && network_state_ == WebMediaPlayer::kNetworkStateLoading)
1829 SetNetworkState(WebMediaPlayer::kNetworkStateIdle); 1834 SetNetworkState(WebMediaPlayer::kNetworkStateIdle);
1830 else if (is_downloading && 1835 else if (is_downloading &&
1831 network_state_ == WebMediaPlayer::kNetworkStateIdle) 1836 network_state_ == WebMediaPlayer::kNetworkStateIdle)
1832 SetNetworkState(WebMediaPlayer::kNetworkStateLoading); 1837 SetNetworkState(WebMediaPlayer::kNetworkStateLoading);
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 } 2098 }
2094 2099
2095 void WebMediaPlayerImpl::UpdatePlayState() { 2100 void WebMediaPlayerImpl::UpdatePlayState() {
2096 DCHECK(main_task_runner_->BelongsToCurrentThread()); 2101 DCHECK(main_task_runner_->BelongsToCurrentThread());
2097 2102
2098 #if defined(OS_ANDROID) // WMPI_CAST 2103 #if defined(OS_ANDROID) // WMPI_CAST
2099 bool is_remote = IsRemote(); 2104 bool is_remote = IsRemote();
2100 bool can_auto_suspend = true; 2105 bool can_auto_suspend = true;
2101 #else 2106 #else
2102 bool is_remote = false; 2107 bool is_remote = false;
2103 bool can_auto_suspend = !disable_pipeline_auto_suspend_ && !IsStreaming(); 2108 bool can_auto_suspend = !disable_pipeline_auto_suspend_;
2109 // For streaming videos, we only allow suspending at the very beginning of the
2110 // video, and only if we know the length of the video. (If we don't know
2111 // the length, it might be a dynamically generated video, and suspending
2112 // will not work at all.)
2113 if (IsStreaming()) {
2114 bool at_beginning =
2115 ready_state_ == WebMediaPlayer::kReadyStateHaveNothing ||
2116 CurrentTime() == 0.0;
2117 if (!at_beginning || GetPipelineMediaDuration() == kInfiniteDuration)
2118 can_auto_suspend = false;
2119 }
2104 #endif 2120 #endif
2105 2121
2106 bool is_suspended = pipeline_controller_.IsSuspended(); 2122 bool is_suspended = pipeline_controller_.IsSuspended();
2107 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden(); 2123 bool is_backgrounded = IsBackgroundedSuspendEnabled() && IsHidden();
2108 PlayState state = UpdatePlayState_ComputePlayState( 2124 PlayState state = UpdatePlayState_ComputePlayState(
2109 is_remote, can_auto_suspend, is_suspended, is_backgrounded); 2125 is_remote, can_auto_suspend, is_suspended, is_backgrounded);
2110 SetDelegateState(state.delegate_state, state.is_idle); 2126 SetDelegateState(state.delegate_state, state.is_idle);
2111 SetMemoryReportingState(state.is_memory_reporting_enabled); 2127 SetMemoryReportingState(state.is_memory_reporting_enabled);
2112 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_); 2128 SetSuspendState(state.is_suspended || pending_suspend_resume_cycle_);
2113 } 2129 }
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2655 } 2671 }
2656 2672
2657 #undef UMA_HISTOGRAM_VIDEO_HEIGHT 2673 #undef UMA_HISTOGRAM_VIDEO_HEIGHT
2658 2674
2659 void WebMediaPlayerImpl::SetTickClockForTest(base::TickClock* tick_clock) { 2675 void WebMediaPlayerImpl::SetTickClockForTest(base::TickClock* tick_clock) {
2660 tick_clock_.reset(tick_clock); 2676 tick_clock_.reset(tick_clock);
2661 buffered_data_source_host_.SetTickClockForTest(tick_clock); 2677 buffered_data_source_host_.SetTickClockForTest(tick_clock);
2662 } 2678 }
2663 2679
2664 } // namespace media 2680 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698