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

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

Issue 1739473003: Suspend idle WebMediaPlayer instances after some time. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 10 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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 #endif 341 #endif
342 342
343 paused_ = false; 343 paused_ = false;
344 pipeline_.SetPlaybackRate(playback_rate_); 344 pipeline_.SetPlaybackRate(playback_rate_);
345 345
346 if (data_source_) 346 if (data_source_)
347 data_source_->MediaIsPlaying(); 347 data_source_->MediaIsPlaying();
348 348
349 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY)); 349 media_log_->AddEvent(media_log_->CreateEvent(MediaLogEvent::PLAY));
350 350
351 if (playback_rate_ > 0) 351 if (playback_rate_ > 0) {
352 NotifyPlaybackStarted(); 352 // Resume the player if playback was initiated in the foreground. Resume()
353 // will do nothing if the pipeline is not suspended state, but will clear
354 // some internal pending state, so it should always be called.
355 const bool was_suspended = pipeline_controller_.IsSuspended();
356 if (delegate_ && !delegate_->IsHidden())
357 pipeline_controller_.Resume();
358
359 // If we were in the suspended state, OnPipelineResumed() will take care of
360 // NotifyPlaybackStarted() when it finishes.
361 if (!was_suspended)
362 NotifyPlaybackStarted();
sandersd (OOO until July 31) 2016/02/27 00:22:20 If you swap the order, then no test is needed beca
DaleCurtis 2016/02/27 00:55:23 Done.
363 }
353 } 364 }
354 365
355 void WebMediaPlayerImpl::pause() { 366 void WebMediaPlayerImpl::pause() {
356 DVLOG(1) << __FUNCTION__; 367 DVLOG(1) << __FUNCTION__;
357 DCHECK(main_task_runner_->BelongsToCurrentThread()); 368 DCHECK(main_task_runner_->BelongsToCurrentThread());
358 369
359 const bool was_already_paused = paused_ || playback_rate_ == 0; 370 const bool was_already_paused = paused_ || playback_rate_ == 0;
360 paused_ = true; 371 paused_ = true;
361 372
362 #if defined(OS_ANDROID) // WMPI_CAST 373 #if defined(OS_ANDROID) // WMPI_CAST
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 AsWeakPtr(), BUFFERING_HAVE_ENOUGH)); 439 AsWeakPtr(), BUFFERING_HAVE_ENOUGH));
429 } 440 }
430 return; 441 return;
431 } 442 }
432 443
433 seeking_ = true; 444 seeking_ = true;
434 seek_time_ = time; 445 seek_time_ = time;
435 if (paused_) 446 if (paused_)
436 paused_time_ = time; 447 paused_time_ = time;
437 pipeline_controller_.Seek(time, time_updated); 448 pipeline_controller_.Seek(time, time_updated);
449
450 // Resume the pipeline if the seek is initiated in the foreground so that
451 // the correct frame is displayed. If the pipeline is not suspended, Resume()
452 // will do nothing but clear some pending state -- thus always call it.
453 if (delegate_ && !delegate_->IsHidden())
454 pipeline_controller_.Resume();
438 } 455 }
439 456
440 void WebMediaPlayerImpl::setRate(double rate) { 457 void WebMediaPlayerImpl::setRate(double rate) {
441 DVLOG(1) << __FUNCTION__ << "(" << rate << ")"; 458 DVLOG(1) << __FUNCTION__ << "(" << rate << ")";
442 DCHECK(main_task_runner_->BelongsToCurrentThread()); 459 DCHECK(main_task_runner_->BelongsToCurrentThread());
443 460
444 // TODO(kylep): Remove when support for negatives is added. Also, modify the 461 // TODO(kylep): Remove when support for negatives is added. Also, modify the
445 // following checks so rewind uses reasonable values also. 462 // following checks so rewind uses reasonable values also.
446 if (rate < 0.0) 463 if (rate < 0.0)
447 return; 464 return;
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 base::Bind(&GetCurrentFrameAndSignal, 1337 base::Bind(&GetCurrentFrameAndSignal,
1321 base::Unretained(compositor_), 1338 base::Unretained(compositor_),
1322 &video_frame, 1339 &video_frame,
1323 &event)); 1340 &event));
1324 event.Wait(); 1341 event.Wait();
1325 return video_frame; 1342 return video_frame;
1326 } 1343 }
1327 1344
1328 void WebMediaPlayerImpl::NotifyPlaybackStarted() { 1345 void WebMediaPlayerImpl::NotifyPlaybackStarted() {
1329 #if defined(OS_ANDROID) // WMPI_CAST 1346 #if defined(OS_ANDROID) // WMPI_CAST
1330 // We do not tell our delegates about remote playback, becuase that would 1347 // We do not tell our delegates about remote playback, because that would
1331 // keep the device awake, which is not what we want. 1348 // keep the device awake, which is not what we want.
1332 if (isRemote()) 1349 if (isRemote())
1333 return; 1350 return;
1334 #endif 1351 #endif
1335 1352
1336 // NotifyPlaybackStarted() may be called by interactions while suspended, 1353 // NotifyPlaybackStarted() may be called by interactions while suspended,
1337 // (play/pause in particular). Those actions won't have any effect until the 1354 // (play/pause in particular). Those actions won't have any effect until the
1338 // pipeline is resumed. 1355 // pipeline is resumed.
1339 // TODO(dalecurtis): Should these be dropped at the call sites instead? 1356 // TODO(dalecurtis): Should these be dropped at the call sites instead?
1340 // Alternatively, rename this method to include Maybe or Changed, and handle 1357 // Alternatively, rename this method to include Maybe or Changed, and handle
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1402 << ", Video: " << stats.video_memory_usage << ", DataSource: " 1419 << ", Video: " << stats.video_memory_usage << ", DataSource: "
1403 << (data_source_ ? data_source_->GetMemoryUsage() : 0) 1420 << (data_source_ ? data_source_->GetMemoryUsage() : 0)
1404 << ", Demuxer: " << demuxer_memory_usage; 1421 << ", Demuxer: " << demuxer_memory_usage;
1405 1422
1406 const int64_t delta = current_memory_usage - last_reported_memory_usage_; 1423 const int64_t delta = current_memory_usage - last_reported_memory_usage_;
1407 last_reported_memory_usage_ = current_memory_usage; 1424 last_reported_memory_usage_ = current_memory_usage;
1408 adjust_allocated_memory_cb_.Run(delta); 1425 adjust_allocated_memory_cb_.Run(delta);
1409 } 1426 }
1410 1427
1411 } // namespace media 1428 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698