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

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

Issue 2477323003: Stop suspending the pipeline before HaveFutureData while decoding (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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 return natural_size; 136 return natural_size;
137 } 137 }
138 138
139 base::TimeDelta GetCurrentTimeInternal(WebMediaPlayerImpl* p_this) { 139 base::TimeDelta GetCurrentTimeInternal(WebMediaPlayerImpl* p_this) {
140 // We wrap currentTime() instead of using pipeline_.GetMediaTime() since there 140 // We wrap currentTime() instead of using pipeline_.GetMediaTime() since there
141 // are a variety of cases in which that time is not accurate; e.g., while 141 // are a variety of cases in which that time is not accurate; e.g., while
142 // remoting and during a pause or seek. 142 // remoting and during a pause or seek.
143 return base::TimeDelta::FromSecondsD(p_this->currentTime()); 143 return base::TimeDelta::FromSecondsD(p_this->currentTime());
144 } 144 }
145 145
146 // How much time must have elapsed since loading last progressed before the
147 // player is eligible for idle suspension.
148 constexpr base::TimeDelta kLoadingToIdleTimeout =
149 base::TimeDelta::FromSeconds(3);
150
146 } // namespace 151 } // namespace
147 152
148 class BufferedDataSourceHostImpl; 153 class BufferedDataSourceHostImpl;
149 154
150 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUnspecified, 155 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUnspecified,
151 UrlData::CORS_UNSPECIFIED); 156 UrlData::CORS_UNSPECIFIED);
152 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeAnonymous, UrlData::CORS_ANONYMOUS); 157 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeAnonymous, UrlData::CORS_ANONYMOUS);
153 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUseCredentials, 158 STATIC_ASSERT_ENUM(WebMediaPlayer::CORSModeUseCredentials,
154 UrlData::CORS_USE_CREDENTIALS); 159 UrlData::CORS_USE_CREDENTIALS);
155 160
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 surface_manager_(params.surface_manager()), 230 surface_manager_(params.surface_manager()),
226 overlay_surface_id_(SurfaceManager::kNoSurfaceID), 231 overlay_surface_id_(SurfaceManager::kNoSurfaceID),
227 suppress_destruction_errors_(false), 232 suppress_destruction_errors_(false),
228 can_suspend_state_(CanSuspendState::UNKNOWN), 233 can_suspend_state_(CanSuspendState::UNKNOWN),
229 is_encrypted_(false), 234 is_encrypted_(false),
230 underflow_count_(0) { 235 underflow_count_(0) {
231 DCHECK(!adjust_allocated_memory_cb_.is_null()); 236 DCHECK(!adjust_allocated_memory_cb_.is_null());
232 DCHECK(renderer_factory_); 237 DCHECK(renderer_factory_);
233 DCHECK(client_); 238 DCHECK(client_);
234 239
240 tick_clock_.reset(new base::DefaultTickClock());
241
235 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( 242 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch(
236 switches::kForceVideoOverlays); 243 switches::kForceVideoOverlays);
237 244
238 disable_fullscreen_video_overlays_ = 245 disable_fullscreen_video_overlays_ =
239 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo); 246 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo);
240 247
241 if (delegate_) 248 if (delegate_)
242 delegate_id_ = delegate_->AddObserver(this); 249 delegate_id_ = delegate_->AddObserver(this);
243 250
244 media_log_->AddEvent( 251 media_log_->AddEvent(
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 // If we've idle suspended before reaching kHaveFutureData and loading has 772 // If we've idle suspended before reaching kHaveFutureData and loading has
766 // progressed we need to spin up the renderer and figure out if we have enough 773 // progressed we need to spin up the renderer and figure out if we have enough
767 // data yet; |client_| may be waiting on this signal to trigger playback. The 774 // data yet; |client_| may be waiting on this signal to trigger playback. The
768 // idle timeout is long enough that this is a low-cost operation. 775 // idle timeout is long enough that this is a low-cost operation.
769 if (highest_ready_state_ < ReadyState::ReadyStateHaveFutureData && 776 if (highest_ready_state_ < ReadyState::ReadyStateHaveFutureData &&
770 pipeline_controller_.IsSuspended() && did_loading_progress && is_idle_) { 777 pipeline_controller_.IsSuspended() && did_loading_progress && is_idle_) {
771 is_idle_ = false; 778 is_idle_ = false;
772 UpdatePlayState(); 779 UpdatePlayState();
773 } 780 }
774 781
782 if (did_loading_progress)
783 last_time_loading_progressed_ = tick_clock_->NowTicks();
784
775 return did_loading_progress; 785 return did_loading_progress;
776 } 786 }
777 787
778 void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas, 788 void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas,
779 const blink::WebRect& rect, 789 const blink::WebRect& rect,
780 SkPaint& paint) { 790 SkPaint& paint) {
781 DCHECK(main_task_runner_->BelongsToCurrentThread()); 791 DCHECK(main_task_runner_->BelongsToCurrentThread());
782 TRACE_EVENT0("media", "WebMediaPlayerImpl:paint"); 792 TRACE_EVENT0("media", "WebMediaPlayerImpl:paint");
783 793
784 // TODO(sandersd): Move this check into GetCurrentFrameFromCompositor() when 794 // TODO(sandersd): Move this check into GetCurrentFrameFromCompositor() when
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1295 DCHECK(main_task_runner_->BelongsToCurrentThread());
1286 if (watch_time_reporter_) 1296 if (watch_time_reporter_)
1287 watch_time_reporter_->OnShown(); 1297 watch_time_reporter_->OnShown();
1288 1298
1289 must_suspend_ = false; 1299 must_suspend_ = false;
1290 background_pause_timer_.Stop(); 1300 background_pause_timer_.Stop();
1291 1301
1292 UpdatePlayState(); 1302 UpdatePlayState();
1293 } 1303 }
1294 1304
1295 void WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) { 1305 bool WebMediaPlayerImpl::OnSuspendRequested(bool must_suspend) {
1296 DCHECK(main_task_runner_->BelongsToCurrentThread()); 1306 DCHECK(main_task_runner_->BelongsToCurrentThread());
1297 1307
1298 if (must_suspend) 1308 if (must_suspend) {
1299 must_suspend_ = true; 1309 must_suspend_ = true;
1300 else 1310 UpdatePlayState();
1311 return true;
1312 }
1313
1314 // If we're beyond HaveFutureData, we can safely suspend at any time.
1315 if (highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData) {
1301 is_idle_ = true; 1316 is_idle_ = true;
1317 UpdatePlayState();
1318 return true;
1319 }
1302 1320
1303 UpdatePlayState(); 1321 // Before HaveFutureData blink will not call play(), so we must be careful to
1322 // only suspend if we'll eventually receive an event that will trigger a
1323 // resume. If the last time loading progressed was a while ago, and we still
1324 // haven't reached HaveFutureData, we assume that we're waiting on more data
1325 // to continue pre-rolling. When that data is loaded the pipeline will be
1326 // resumed by didLoadingProgress().
1327 if (last_time_loading_progressed_.is_null() ||
1328 (tick_clock_->NowTicks() - last_time_loading_progressed_) >
1329 kLoadingToIdleTimeout) {
1330 is_idle_ = true;
1331 UpdatePlayState();
1332 return true;
1333 }
1334
1335 return false;
1304 } 1336 }
1305 1337
1306 void WebMediaPlayerImpl::OnPlay() { 1338 void WebMediaPlayerImpl::OnPlay() {
1307 play(); 1339 play();
1308 client_->playbackStateChanged(); 1340 client_->playbackStateChanged();
1309 } 1341 }
1310 1342
1311 void WebMediaPlayerImpl::OnPause() { 1343 void WebMediaPlayerImpl::OnPause() {
1312 pause(); 1344 pause();
1313 client_->playbackStateChanged(); 1345 client_->playbackStateChanged();
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 pipeline_metadata_.natural_size, 1906 pipeline_metadata_.natural_size,
1875 base::Bind(&GetCurrentTimeInternal, this))); 1907 base::Bind(&GetCurrentTimeInternal, this)));
1876 watch_time_reporter_->OnVolumeChange(volume_); 1908 watch_time_reporter_->OnVolumeChange(volume_);
1877 if (delegate_ && delegate_->IsHidden()) 1909 if (delegate_ && delegate_->IsHidden())
1878 watch_time_reporter_->OnHidden(); 1910 watch_time_reporter_->OnHidden();
1879 else 1911 else
1880 watch_time_reporter_->OnShown(); 1912 watch_time_reporter_->OnShown();
1881 } 1913 }
1882 1914
1883 } // namespace media 1915 } // 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