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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 #if defined(OS_ANDROID) // WMPI_CAST | 219 #if defined(OS_ANDROID) // WMPI_CAST |
| 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 client_playback_state_(PlaybackState::Paused) { | |
| 230 DCHECK(!adjust_allocated_memory_cb_.is_null()); | 231 DCHECK(!adjust_allocated_memory_cb_.is_null()); |
| 231 DCHECK(renderer_factory_); | 232 DCHECK(renderer_factory_); |
| 232 DCHECK(client_); | 233 DCHECK(client_); |
| 233 | 234 |
| 234 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 235 force_video_overlays_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 235 switches::kForceVideoOverlays); | 236 switches::kForceVideoOverlays); |
| 236 | 237 |
| 237 if (delegate_) | 238 if (delegate_) |
| 238 delegate_id_ = delegate_->AddObserver(this); | 239 delegate_id_ = delegate_->AddObserver(this); |
| 239 | 240 |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 buffering_strategy_ = MultibufferDataSource::BUFFERING_STRATEGY_NORMAL; | 582 buffering_strategy_ = MultibufferDataSource::BUFFERING_STRATEGY_NORMAL; |
| 582 #else | 583 #else |
| 583 buffering_strategy_ = | 584 buffering_strategy_ = |
| 584 static_cast<MultibufferDataSource::BufferingStrategy>(buffering_strategy); | 585 static_cast<MultibufferDataSource::BufferingStrategy>(buffering_strategy); |
| 585 #endif | 586 #endif |
| 586 | 587 |
| 587 if (data_source_) | 588 if (data_source_) |
| 588 data_source_->SetBufferingStrategy(buffering_strategy_); | 589 data_source_->SetBufferingStrategy(buffering_strategy_); |
| 589 } | 590 } |
| 590 | 591 |
| 592 void WebMediaPlayerImpl::setPlaybackState( | |
| 593 WebMediaPlayer::PlaybackState playback_state) { | |
| 594 client_playback_state_ = playback_state; | |
| 595 if (highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData) { | |
| 596 DCHECK_EQ(client_playback_state_ == WebMediaPlayer::PlaybackState::Paused, | |
| 597 paused_); | |
| 598 } | |
| 599 | |
| 600 UpdatePlayState(); | |
| 601 } | |
| 602 | |
| 591 bool WebMediaPlayerImpl::hasVideo() const { | 603 bool WebMediaPlayerImpl::hasVideo() const { |
| 592 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 604 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 593 | 605 |
| 594 return pipeline_metadata_.has_video; | 606 return pipeline_metadata_.has_video; |
| 595 } | 607 } |
| 596 | 608 |
| 597 bool WebMediaPlayerImpl::hasAudio() const { | 609 bool WebMediaPlayerImpl::hasAudio() const { |
| 598 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 610 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 599 | 611 |
| 600 return pipeline_metadata_.has_audio; | 612 return pipeline_metadata_.has_audio; |
| (...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1632 // errors. | 1644 // errors. |
| 1633 bool has_error = IsNetworkStateError(network_state_); | 1645 bool has_error = IsNetworkStateError(network_state_); |
| 1634 | 1646 |
| 1635 // After HaveMetadata, we know which tracks are present and the duration. | 1647 // After HaveMetadata, we know which tracks are present and the duration. |
| 1636 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata; | 1648 bool have_metadata = ready_state_ >= WebMediaPlayer::ReadyStateHaveMetadata; |
| 1637 | 1649 |
| 1638 // After HaveFutureData, Blink will call play() if the state is not paused. | 1650 // After HaveFutureData, Blink will call play() if the state is not paused. |
| 1639 bool have_future_data = | 1651 bool have_future_data = |
| 1640 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; | 1652 highest_ready_state_ >= WebMediaPlayer::ReadyStateHaveFutureData; |
| 1641 | 1653 |
| 1654 // Once we reach HaveFutureData, our internal paused state should be accurate, | |
| 1655 // due to ordering of calls we may temporarily be out of sync though. | |
|
sandersd (OOO until July 31)
2016/08/30 18:40:17
It's worth explicitly describing this as retaining
DaleCurtis
2016/08/30 21:56:04
This does happen, HTMLMediaElement::UpdatePlayStat
| |
| 1656 bool is_paused = | |
| 1657 have_future_data ? paused_ : client_playback_state_ == | |
| 1658 WebMediaPlayer::PlaybackState::Paused; | |
| 1659 | |
| 1642 // Background suspend is not enabled for audio-only players unless paused, | 1660 // Background suspend is not enabled for audio-only players unless paused, |
| 1643 // though in the case of audio-only the session should be kept. | 1661 // though in the case of audio-only the session should be kept. |
| 1644 // Videos are not suspended if the user resumed the playback via the remote | 1662 // Videos are not suspended if the user resumed the playback via the remote |
| 1645 // controls earlier and it's still playing. | 1663 // controls earlier and it's still playing. |
| 1646 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); | 1664 bool is_backgrounded_video = is_backgrounded && have_metadata && hasVideo(); |
| 1647 bool can_play_backgrounded = is_backgrounded_video && !is_remote && | 1665 bool can_play_backgrounded = is_backgrounded_video && !is_remote && |
| 1648 hasAudio() && IsResumeBackgroundVideosEnabled(); | 1666 hasAudio() && IsResumeBackgroundVideosEnabled(); |
| 1649 bool is_background_playing = | 1667 bool is_background_playing = |
| 1650 delegate_ && delegate_->IsPlayingBackgroundVideo(); | 1668 delegate_ && delegate_->IsPlayingBackgroundVideo(); |
| 1651 bool background_suspended = is_backgrounded_video && | 1669 bool background_suspended = is_backgrounded_video && |
| 1652 !(can_play_backgrounded && is_background_playing); | 1670 !(can_play_backgrounded && is_background_playing); |
| 1653 | 1671 bool background_pause_suspended = is_backgrounded && is_paused; |
| 1654 // The |paused_| state is not reliable until we |have_future_data|. | |
| 1655 bool background_pause_suspended = | |
| 1656 is_backgrounded && have_future_data && paused_; | |
| 1657 | 1672 |
| 1658 // Idle suspend is enabled once there is future data. We don't want to idle | 1673 // Idle suspend is enabled once there is future data. We don't want to idle |
| 1659 // suspend before that because play() may never be triggered to leave the idle | 1674 // suspend before that because play() may never be triggered to leave the idle |
| 1660 // state. There could be other theoretical problems if the page is waiting for | 1675 // state. There could be other theoretical problems if the page is waiting for |
| 1661 // other events before actually calling play(), but at least we don't break | 1676 // other events before actually calling play(), but at least we don't break |
| 1662 // Blink. | 1677 // Blink. |
| 1663 // | 1678 // |
| 1664 // TODO(sandersd): Make the delegate suspend idle players immediately when | 1679 // TODO(sandersd): Make the delegate suspend idle players immediately when |
| 1665 // hidden. | 1680 // hidden. |
| 1666 // TODO(sandersd): If Blink told us the paused state sooner, we could | 1681 bool idle_suspended = is_idle_ && is_paused; |
| 1667 // idle suspend sooner. | |
| 1668 bool idle_suspended = is_idle_ && have_future_data; | |
| 1669 | 1682 |
| 1670 // Combined suspend state. | 1683 // Combined suspend state. |
| 1671 result.is_suspended = | 1684 result.is_suspended = |
| 1672 is_remote || must_suspend_ || idle_suspended || background_suspended || | 1685 is_remote || must_suspend_ || idle_suspended || background_suspended || |
| 1673 background_pause_suspended || | 1686 background_pause_suspended || |
| 1674 // If we're already suspended, see if we can wait for user interaction. | 1687 // If we're already suspended, see if we can wait for user interaction. |
| 1675 (is_suspended && have_future_data && paused_ && !seeking_); | 1688 (is_suspended && is_paused && !seeking_); |
|
sandersd (OOO until July 31)
2016/08/30 18:40:18
While you're in here, can you pull this condition
DaleCurtis
2016/08/30 21:56:04
Done.
| |
| 1676 | 1689 |
| 1677 // We do not treat |playback_rate_| == 0 as paused. For the media session, | 1690 // We do not treat |playback_rate_| == 0 as paused. For the media session, |
| 1678 // being paused implies displaying a play button, which is incorrect in this | 1691 // being paused implies displaying a play button, which is incorrect in this |
| 1679 // case. For memory usage reporting, we just use the same definition (but we | 1692 // case. For memory usage reporting, we just use the same definition (but we |
| 1680 // don't have to). | 1693 // don't have to). |
| 1681 // | 1694 // |
| 1682 // Similarly, we don't consider |ended_| to be paused. Blink will immediately | 1695 // Similarly, we don't consider |ended_| to be paused. Blink will immediately |
| 1683 // call pause() or seek(), so |ended_| should not affect the computation. | 1696 // call pause() or seek(), so |ended_| should not affect the computation. |
| 1684 // Despite that, |ended_| does result in a separate paused state, to simplfy | 1697 // Despite that, |ended_| does result in a separate paused state, to simplfy |
| 1685 // the contract for SetDelegateState(). | 1698 // the contract for SetDelegateState(). |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1792 pipeline_metadata_.natural_size, | 1805 pipeline_metadata_.natural_size, |
| 1793 base::Bind(&GetCurrentTimeInternal, this))); | 1806 base::Bind(&GetCurrentTimeInternal, this))); |
| 1794 watch_time_reporter_->OnVolumeChange(volume_); | 1807 watch_time_reporter_->OnVolumeChange(volume_); |
| 1795 if (delegate_ && delegate_->IsHidden()) | 1808 if (delegate_ && delegate_->IsHidden()) |
| 1796 watch_time_reporter_->OnHidden(); | 1809 watch_time_reporter_->OnHidden(); |
| 1797 else | 1810 else |
| 1798 watch_time_reporter_->OnShown(); | 1811 watch_time_reporter_->OnShown(); |
| 1799 } | 1812 } |
| 1800 | 1813 |
| 1801 } // namespace media | 1814 } // namespace media |
| OLD | NEW |