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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 suppress_destruction_errors_(false), | 229 suppress_destruction_errors_(false), |
230 can_suspend_state_(CanSuspendState::UNKNOWN), | 230 can_suspend_state_(CanSuspendState::UNKNOWN), |
231 use_fallback_path_(false), | 231 use_fallback_path_(false), |
232 is_encrypted_(false), | 232 is_encrypted_(false), |
233 underflow_count_(0), | 233 underflow_count_(0), |
234 observer_(params.media_observer()) { | 234 observer_(params.media_observer()) { |
235 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 235 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
236 DCHECK(renderer_factory_); | 236 DCHECK(renderer_factory_); |
237 DCHECK(client_); | 237 DCHECK(client_); |
238 | 238 |
239 tick_clock_ = &default_tick_clock_; | |
240 | |
239 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 241 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
240 switches::kForceVideoOverlays); | 242 switches::kForceVideoOverlays); |
241 | 243 |
242 disable_fullscreen_video_overlays_ = | 244 disable_fullscreen_video_overlays_ = |
243 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo); | 245 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo); |
244 | 246 |
245 if (delegate_) | 247 if (delegate_) |
246 delegate_id_ = delegate_->AddObserver(this); | 248 delegate_id_ = delegate_->AddObserver(this); |
247 | 249 |
248 media_log_->AddEvent( | 250 media_log_->AddEvent( |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
775 // If we've idle suspended before reaching kHaveFutureData and loading has | 777 // If we've idle suspended before reaching kHaveFutureData and loading has |
776 // progressed we need to spin up the renderer and figure out if we have enough | 778 // progressed we need to spin up the renderer and figure out if we have enough |
777 // data yet; |client_| may be waiting on this signal to trigger playback. The | 779 // data yet; |client_| may be waiting on this signal to trigger playback. The |
778 // idle timeout is long enough that this is a low-cost operation. | 780 // idle timeout is long enough that this is a low-cost operation. |
779 if (highest_ready_state_ < ReadyState::ReadyStateHaveFutureData && | 781 if (highest_ready_state_ < ReadyState::ReadyStateHaveFutureData && |
780 pipeline_controller_.IsSuspended() && did_loading_progress && is_idle_) { | 782 pipeline_controller_.IsSuspended() && did_loading_progress && is_idle_) { |
781 is_idle_ = false; | 783 is_idle_ = false; |
782 UpdatePlayState(); | 784 UpdatePlayState(); |
783 } | 785 } |
784 | 786 |
787 if (did_loading_progress) | |
788 last_time_loading_progressed_ = tick_clock_->NowTicks(); | |
789 | |
785 return did_loading_progress; | 790 return did_loading_progress; |
786 } | 791 } |
787 | 792 |
788 void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas, | 793 void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas, |
789 const blink::WebRect& rect, | 794 const blink::WebRect& rect, |
790 SkPaint& paint) { | 795 SkPaint& paint) { |
791 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 796 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
792 TRACE_EVENT0("media", "WebMediaPlayerImpl:paint"); | 797 TRACE_EVENT0("media", "WebMediaPlayerImpl:paint"); |
793 | 798 |
794 // TODO(sandersd): Move this check into GetCurrentFrameFromCompositor() when | 799 // TODO(sandersd): Move this check into GetCurrentFrameFromCompositor() when |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1304 | 1309 |
1305 must_suspend_ = false; | 1310 must_suspend_ = false; |
1306 background_pause_timer_.Stop(); | 1311 background_pause_timer_.Stop(); |
1307 | 1312 |
1308 UpdatePlayState(); | 1313 UpdatePlayState(); |
1309 } | 1314 } |
1310 | 1315 |
1311 void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { | 1316 void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { |
1312 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 1317 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
1313 | 1318 |
1314 if (must_suspend) | 1319 if (must_suspend) { |
1315 must_suspend_ = true; | 1320 must_suspend_ = true; |
1316 else | 1321 UpdatePlayState(); |
1322 return; | |
1323 } | |
1324 | |
1325 // If we're beyond HaveFutureData, we can safely suspend at any time. | |
1326 if (highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData) { | |
1317 is_idle_ = true; | 1327 is_idle_ = true; |
1328 UpdatePlayState(); | |
1329 return; | |
1330 } | |
1318 | 1331 |
1319 UpdatePlayState(); | 1332 // Before HaveFutureData blink will not call play(), so we must be careful to |
DaleCurtis
2016/10/28 19:11:42
This will never be called again. So even after 3 s
watk
2016/10/28 20:03:22
What about calling delegate_->DidPause()? Then the
| |
1333 // only suspend if we'll eventually receive an event that will trigger a | |
1334 // resume. If the last time loading progressed was longer than 3 seconds ago, | |
1335 // and we still haven't reached HaveFutureData, assume that we're waiting on | |
1336 // more data to proceed. When that data is loaded the pipeline will be resumed | |
1337 // by didLoadingProgress(). | |
1338 if (last_time_loading_progressed_.is_null() || | |
1339 (tick_clock_->NowTicks() - last_time_loading_progressed_) > | |
1340 base::TimeDelta::FromSeconds(3)) { | |
1341 is_idle_ = true; | |
1342 UpdatePlayState(); | |
1343 } | |
1320 } | 1344 } |
1321 | 1345 |
1322 void WebMediaPlayerImpl::OnPlay() { | 1346 void WebMediaPlayerImpl::OnPlay() { |
1323 play(); | 1347 play(); |
1324 client_->playbackStateChanged(); | 1348 client_->playbackStateChanged(); |
1325 } | 1349 } |
1326 | 1350 |
1327 void WebMediaPlayerImpl::OnPause() { | 1351 void WebMediaPlayerImpl::OnPause() { |
1328 pause(); | 1352 pause(); |
1329 client_->playbackStateChanged(); | 1353 client_->playbackStateChanged(); |
(...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1893 pipeline_metadata_.natural_size, | 1917 pipeline_metadata_.natural_size, |
1894 base::Bind(&GetCurrentTimeInternal, this))); | 1918 base::Bind(&GetCurrentTimeInternal, this))); |
1895 watch_time_reporter_->OnVolumeChange(volume_); | 1919 watch_time_reporter_->OnVolumeChange(volume_); |
1896 if (delegate_ && delegate_->IsHidden()) | 1920 if (delegate_ && delegate_->IsHidden()) |
1897 watch_time_reporter_->OnHidden(); | 1921 watch_time_reporter_->OnHidden(); |
1898 else | 1922 else |
1899 watch_time_reporter_->OnShown(); | 1923 watch_time_reporter_->OnShown(); |
1900 } | 1924 } |
1901 | 1925 |
1902 } // namespace media | 1926 } // namespace media |
OLD | NEW |