Chromium Code Reviews| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 220 cast_impl_(this, client_, params.context_3d_cb()), | 220 cast_impl_(this, client_, params.context_3d_cb()), |
| 221 #endif | 221 #endif |
| 222 volume_(1.0), | 222 volume_(1.0), |
| 223 volume_multiplier_(1.0), | 223 volume_multiplier_(1.0), |
| 224 renderer_factory_(std::move(renderer_factory)), | 224 renderer_factory_(std::move(renderer_factory)), |
| 225 surface_manager_(params.surface_manager()), | 225 surface_manager_(params.surface_manager()), |
| 226 overlay_surface_id_(SurfaceManager::kNoSurfaceID), | 226 overlay_surface_id_(SurfaceManager::kNoSurfaceID), |
| 227 suppress_destruction_errors_(false), | 227 suppress_destruction_errors_(false), |
| 228 can_suspend_state_(CanSuspendState::UNKNOWN), | 228 can_suspend_state_(CanSuspendState::UNKNOWN), |
| 229 is_encrypted_(false), | 229 is_encrypted_(false), |
| 230 underflow_count_(0) { | 230 underflow_count_(0), |
| 231 is_client_paused_(true) { | |
| 231 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 232 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 232 DCHECK(renderer_factory_); | 233 DCHECK(renderer_factory_); |
| 233 DCHECK(client_); | 234 DCHECK(client_); |
| 234 | 235 |
| 235 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 236 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 236 switches::kForceVideoOverlays); | 237 switches::kForceVideoOverlays); |
| 237 | 238 |
| 238 if (delegate_) | 239 if (delegate_) |
| 239 delegate_id_ = delegate_->AddObserver(this); | 240 delegate_id_ = delegate_->AddObserver(this); |
| 240 | 241 |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 buffering_strategy_ = MultibufferDataSource::BUFFERING_STRATEGY_NORMAL; | 583 buffering_strategy_ = MultibufferDataSource::BUFFERING_STRATEGY_NORMAL; |
| 583 #else | 584 #else |
| 584 buffering_strategy_ = | 585 buffering_strategy_ = |
| 585 static_cast<MultibufferDataSource::BufferingStrategy>(buffering_strategy); | 586 static_cast<MultibufferDataSource::BufferingStrategy>(buffering_strategy); |
| 586 #endif | 587 #endif |
| 587 | 588 |
| 588 if (data_source_) | 589 if (data_source_) |
| 589 data_source_->SetBufferingStrategy(buffering_strategy_); | 590 data_source_->SetBufferingStrategy(buffering_strategy_); |
| 590 } | 591 } |
| 591 | 592 |
| 593 void WebMediaPlayerImpl::setPaused(bool is_paused) { | |
| 594 is_client_paused_ = is_paused; | |
| 595 if (highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData) | |
| 596 DCHECK_EQ(is_paused, paused_); | |
| 597 UpdatePlayState(); | |
| 598 } | |
| 599 | |
| 592 bool WebMediaPlayerImpl::hasVideo() const { | 600 bool WebMediaPlayerImpl::hasVideo() const { |
| 593 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 601 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 594 | 602 |
| 595 return pipeline_metadata_.has_video; | 603 return pipeline_metadata_.has_video; |
| 596 } | 604 } |
| 597 | 605 |
| 598 bool WebMediaPlayerImpl::hasAudio() const { | 606 bool WebMediaPlayerImpl::hasAudio() const { |
| 599 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 607 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 600 | 608 |
| 601 return pipeline_metadata_.has_audio; | 609 return pipeline_metadata_.has_audio; |
| (...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1648 // errors. | 1656 // errors. |
| 1649 bool has_error = IsNetworkStateError(network_state_); | 1657 bool has_error = IsNetworkStateError(network_state_); |
| 1650 | 1658 |
| 1651 // After HaveMetadata, we know which tracks are present and the duration. | 1659 // After HaveMetadata, we know which tracks are present and the duration. |
| 1652 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata; | 1660 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata; |
| 1653 | 1661 |
| 1654 // After HaveFutureData, Blink will call play() if the state is not paused. | 1662 // After HaveFutureData, Blink will call play() if the state is not paused. |
| 1655 bool have_future_data = | 1663 bool have_future_data = |
| 1656 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; | 1664 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; |
| 1657 | 1665 |
| 1666 // Once we reach HaveFutureData, our internal paused state should be accurate, | |
| 1667 // due to ordering of calls we may temporarily be out of sync though. During | |
| 1668 // that period, we'll retain the most accurate |paused_| state. | |
|
sandersd (OOO until July 31)
2016/08/30 22:41:41
Is it actually 'most accurate'? It happens to be c
DaleCurtis
2016/08/30 22:59:43
Reworded.
| |
| 1669 bool is_paused = have_future_data ? paused_ : is_client_paused_; | |
| 1670 | |
| 1658 // Background suspend is not enabled for audio-only players unless paused, | 1671 // Background suspend is not enabled for audio-only players unless paused, |
| 1659 // though in the case of audio-only the session should be kept. | 1672 // though in the case of audio-only the session should be kept. |
| 1660 // Videos are not suspended if the user resumed the playback via the remote | 1673 // Videos are not suspended if the user resumed the playback via the remote |
| 1661 // controls earlier and it's still playing. | 1674 // controls earlier and it's still playing. |
| 1662 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); | 1675 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); |
| 1663 bool can_play_backgrounded = is_backgrounded_video && !is_remote && | 1676 bool can_play_backgrounded = is_backgrounded_video && !is_remote && |
| 1664 hasAudio() && IsResumeBackgroundVideosEnabled(); | 1677 hasAudio() && IsResumeBackgroundVideosEnabled(); |
| 1665 bool is_background_playing = | 1678 bool is_background_playing = |
| 1666 delegate_ && delegate_->IsPlayingBackgroundVideo(); | 1679 delegate_ && delegate_->IsPlayingBackgroundVideo(); |
| 1667 bool background_suspended = is_backgrounded_video && | 1680 bool background_suspended = is_backgrounded_video && |
| 1668 !(can_play_backgrounded && is_background_playing); | 1681 !(can_play_backgrounded && is_background_playing); |
| 1669 | 1682 bool background_pause_suspended = is_backgrounded && is_paused; |
| 1670 // The |paused_| state is not reliable until we |have_future_data|. | |
| 1671 bool background_pause_suspended = | |
| 1672 is_backgrounded && have_future_data && paused_; | |
| 1673 | 1683 |
| 1674 // Idle suspend is enabled once there is future data. We don't want to idle | 1684 // Idle suspend is enabled once there is future data. We don't want to idle |
| 1675 // suspend before that because play() may never be triggered to leave the idle | 1685 // suspend before that because play() may never be triggered to leave the idle |
| 1676 // state. There could be other theoretical problems if the page is waiting for | 1686 // state. There could be other theoretical problems if the page is waiting for |
| 1677 // other events before actually calling play(), but at least we don't break | 1687 // other events before actually calling play(), but at least we don't break |
| 1678 // Blink. | 1688 // Blink. |
| 1679 // | 1689 // |
| 1680 // TODO(sandersd): Make the delegate suspend idle players immediately when | 1690 // TODO(sandersd): Make the delegate suspend idle players immediately when |
| 1681 // hidden. | 1691 // hidden. |
| 1682 // TODO(sandersd): If Blink told us the paused state sooner, we could | 1692 bool idle_suspended = is_idle_ && is_paused; |
| 1683 // idle suspend sooner. | 1693 |
| 1684 bool idle_suspended = is_idle_ && have_future_data; | 1694 // If we're already suspended, see if we can wait for user interaction. |
| 1695 bool can_stay_suspended = is_suspended && is_paused && !seeking_; | |
| 1685 | 1696 |
| 1686 // Combined suspend state. | 1697 // Combined suspend state. |
| 1687 result.is_suspended = | 1698 result.is_suspended = is_remote || must_suspend_ || idle_suspended || |
| 1688 is_remote || must_suspend_ || idle_suspended || background_suspended || | 1699 background_suspended || background_pause_suspended || |
| 1689 background_pause_suspended || | 1700 can_stay_suspended; |
| 1690 // If we're already suspended, see if we can wait for user interaction. | |
| 1691 (is_suspended && have_future_data && paused_ && !seeking_); | |
| 1692 | 1701 |
| 1693 // We do not treat |playback_rate_| == 0 as paused. For the media session, | 1702 // We do not treat |playback_rate_| == 0 as paused. For the media session, |
| 1694 // being paused implies displaying a play button, which is incorrect in this | 1703 // being paused implies displaying a play button, which is incorrect in this |
| 1695 // case. For memory usage reporting, we just use the same definition (but we | 1704 // case. For memory usage reporting, we just use the same definition (but we |
| 1696 // don't have to). | 1705 // don't have to). |
| 1697 // | 1706 // |
| 1698 // Similarly, we don't consider |ended_| to be paused. Blink will immediately | 1707 // Similarly, we don't consider |ended_| to be paused. Blink will immediately |
| 1699 // call pause() or seek(), so |ended_| should not affect the computation. | 1708 // call pause() or seek(), so |ended_| should not affect the computation. |
| 1700 // Despite that, |ended_| does result in a separate paused state, to simplfy | 1709 // Despite that, |ended_| does result in a separate paused state, to simplfy |
| 1701 // the contract for SetDelegateState(). | 1710 // the contract for SetDelegateState(). |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1808 pipeline_metadata_.natural_size, | 1817 pipeline_metadata_.natural_size, |
| 1809 base::Bind(&GetCurrentTimeInternal, this))); | 1818 base::Bind(&GetCurrentTimeInternal, this))); |
| 1810 watch_time_reporter_->OnVolumeChange(volume_); | 1819 watch_time_reporter_->OnVolumeChange(volume_); |
| 1811 if (delegate_ && delegate_->IsHidden()) | 1820 if (delegate_ && delegate_->IsHidden()) |
| 1812 watch_time_reporter_->OnHidden(); | 1821 watch_time_reporter_->OnHidden(); |
| 1813 else | 1822 else |
| 1814 watch_time_reporter_->OnShown(); | 1823 watch_time_reporter_->OnShown(); |
| 1815 } | 1824 } |
| 1816 | 1825 |
| 1817 } // namespace media | 1826 } // namespace media |
| OLD | NEW |