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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return natural_size; | 138 return natural_size; |
139 } | 139 } |
140 | 140 |
141 base::TimeDelta GetCurrentTimeInternal(WebMediaPlayerImpl* p_this) { | 141 base::TimeDelta GetCurrentTimeInternal(WebMediaPlayerImpl* p_this) { |
142 // We wrap currentTime() instead of using pipeline_.GetMediaTime() since there | 142 // We wrap currentTime() instead of using pipeline_.GetMediaTime() since there |
143 // are a variety of cases in which that time is not accurate; e.g., while | 143 // are a variety of cases in which that time is not accurate; e.g., while |
144 // remoting and during a pause or seek. | 144 // remoting and during a pause or seek. |
145 return base::TimeDelta::FromSecondsD(p_this->currentTime()); | 145 return base::TimeDelta::FromSecondsD(p_this->currentTime()); |
146 } | 146 } |
147 | 147 |
| 148 // How much time must have elapsed since loading last progressed before the |
| 149 // player is eligible for idle suspension. |
| 150 constexpr base::TimeDelta kLoadingToIdleTimeout = |
| 151 base::TimeDelta::FromSeconds(3); |
| 152 |
148 } // namespace | 153 } // namespace |
149 | 154 |
150 class BufferedDataSourceHostImpl; | 155 class BufferedDataSourceHostImpl; |
151 | 156 |
152 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUnspecified, | 157 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUnspecified, |
153 UrlData::CORS_UNSPECIFIED); | 158 UrlData::CORS_UNSPECIFIED); |
154 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeAnonymous, UrlData::CORS_ANONYMOUS); | 159 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeAnonymous, UrlData::CORS_ANONYMOUS); |
155 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUseCredentials, | 160 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUseCredentials, |
156 UrlData::CORS_USE_CREDENTIALS); | 161 UrlData::CORS_USE_CREDENTIALS); |
157 | 162 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 suppress_destruction_errors_(false), | 234 suppress_destruction_errors_(false), |
230 can_suspend_state_(CanSuspendState::UNKNOWN), | 235 can_suspend_state_(CanSuspendState::UNKNOWN), |
231 use_fallback_path_(false), | 236 use_fallback_path_(false), |
232 is_encrypted_(false), | 237 is_encrypted_(false), |
233 underflow_count_(0), | 238 underflow_count_(0), |
234 observer_(params.media_observer()) { | 239 observer_(params.media_observer()) { |
235 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 240 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
236 DCHECK(renderer_factory_); | 241 DCHECK(renderer_factory_); |
237 DCHECK(client_); | 242 DCHECK(client_); |
238 | 243 |
| 244 tick_clock_.reset(new base::DefaultTickClock()); |
| 245 |
239 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 246 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
240 switches::kForceVideoOverlays); | 247 switches::kForceVideoOverlays); |
241 | 248 |
242 disable_fullscreen_video_overlays_ = | 249 disable_fullscreen_video_overlays_ = |
243 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo); | 250 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo); |
244 | 251 |
245 if (delegate_) | 252 if (delegate_) |
246 delegate_id_ = delegate_->AddObserver(this); | 253 delegate_id_ = delegate_->AddObserver(this); |
247 | 254 |
248 media_log_->AddEvent( | 255 media_log_->AddEvent( |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 // If we've idle suspended before reaching kHaveFutureData and loading has | 786 // If we've idle suspended before reaching kHaveFutureData and loading has |
780 // progressed we need to spin up the renderer and figure out if we have enough | 787 // progressed we need to spin up the renderer and figure out if we have enough |
781 // data yet; |client_| may be waiting on this signal to trigger playback. The | 788 // data yet; |client_| may be waiting on this signal to trigger playback. The |
782 // idle timeout is long enough that this is a low-cost operation. | 789 // idle timeout is long enough that this is a low-cost operation. |
783 if (highest_ready_state_ < ReadyState::ReadyStateHaveFutureData && | 790 if (highest_ready_state_ < ReadyState::ReadyStateHaveFutureData && |
784 pipeline_controller_.IsSuspended() && did_loading_progress && is_idle_) { | 791 pipeline_controller_.IsSuspended() && did_loading_progress && is_idle_) { |
785 is_idle_ = false; | 792 is_idle_ = false; |
786 UpdatePlayState(); | 793 UpdatePlayState(); |
787 } | 794 } |
788 | 795 |
| 796 if (did_loading_progress) |
| 797 last_time_loading_progressed_ = tick_clock_->NowTicks(); |
| 798 |
789 return did_loading_progress; | 799 return did_loading_progress; |
790 } | 800 } |
791 | 801 |
792 void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas, | 802 void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas, |
793 const blink::WebRect& rect, | 803 const blink::WebRect& rect, |
794 SkPaint& paint) { | 804 SkPaint& paint) { |
795 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 805 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
796 TRACE_EVENT0("media", "WebMediaPlayerImpl:paint"); | 806 TRACE_EVENT0("media", "WebMediaPlayerImpl:paint"); |
797 | 807 |
798 // TODO(sandersd): Move this check into GetCurrentFrameFromCompositor() when | 808 // TODO(sandersd): Move this check into GetCurrentFrameFromCompositor() when |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1315 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1306 if (watch_time_reporter_) | 1316 if (watch_time_reporter_) |
1307 watch_time_reporter_->OnShown(); | 1317 watch_time_reporter_->OnShown(); |
1308 | 1318 |
1309 must_suspend_ = false; | 1319 must_suspend_ = false; |
1310 background_pause_timer_.Stop(); | 1320 background_pause_timer_.Stop(); |
1311 | 1321 |
1312 UpdatePlayState(); | 1322 UpdatePlayState(); |
1313 } | 1323 } |
1314 | 1324 |
1315 void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { | 1325 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { |
1316 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1326 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1317 | 1327 |
1318 if (must_suspend) | 1328 if (must_suspend) { |
1319 must_suspend_ = true; | 1329 must_suspend_ = true; |
1320 else | 1330 UpdatePlayState(); |
| 1331 return true; |
| 1332 } |
| 1333 |
| 1334 // If we're beyond HaveFutureData, we can safely suspend at any time. |
| 1335 if (highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData) { |
1321 is_idle_ = true; | 1336 is_idle_ = true; |
| 1337 UpdatePlayState(); |
| 1338 return true; |
| 1339 } |
1322 | 1340 |
1323 UpdatePlayState(); | 1341 // Before HaveFutureData blink will not call play(), so we must be careful to |
| 1342 // only suspend if we'll eventually receive an event that will trigger a |
| 1343 // resume. If the last time loading progressed was a while ago, and we still |
| 1344 // haven't reached HaveFutureData, we assume that we're waiting on more data |
| 1345 // to continue pre-rolling. When that data is loaded the pipeline will be |
| 1346 // resumed by didLoadingProgress(). |
| 1347 if (last_time_loading_progressed_.is_null() || |
| 1348 (tick_clock_->NowTicks() - last_time_loading_progressed_) > |
| 1349 kLoadingToIdleTimeout) { |
| 1350 is_idle_ = true; |
| 1351 UpdatePlayState(); |
| 1352 return true; |
| 1353 } |
| 1354 |
| 1355 return false; |
1324 } | 1356 } |
1325 | 1357 |
1326 void WebMediaPlayerImpl::OnPlay() { | 1358 void WebMediaPlayerImpl::OnPlay() { |
1327 play(); | 1359 play(); |
1328 client_->playbackStateChanged(); | 1360 client_->playbackStateChanged(); |
1329 } | 1361 } |
1330 | 1362 |
1331 void WebMediaPlayerImpl::OnPause() { | 1363 void WebMediaPlayerImpl::OnPause() { |
1332 pause(); | 1364 pause(); |
1333 client_->playbackStateChanged(); | 1365 client_->playbackStateChanged(); |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1907 pipeline_metadata_.natural_size, | 1939 pipeline_metadata_.natural_size, |
1908 base::Bind(&GetCurrentTimeInternal, this))); | 1940 base::Bind(&GetCurrentTimeInternal, this))); |
1909 watch_time_reporter_->OnVolumeChange(volume_); | 1941 watch_time_reporter_->OnVolumeChange(volume_); |
1910 if (delegate_ && delegate_->IsHidden()) | 1942 if (delegate_ && delegate_->IsHidden()) |
1911 watch_time_reporter_->OnHidden(); | 1943 watch_time_reporter_->OnHidden(); |
1912 else | 1944 else |
1913 watch_time_reporter_->OnShown(); | 1945 watch_time_reporter_->OnShown(); |
1914 } | 1946 } |
1915 | 1947 |
1916 } // namespace media | 1948 } // namespace media |
OLD | NEW |