| Index: content/browser/media/session/media_session.cc
|
| diff --git a/content/browser/media/session/media_session.cc b/content/browser/media/session/media_session.cc
|
| index f76c5662bfe8b284464983690958753fba80458b..1c3af1ba6666a99a54f995b758bb918632e30029 100644
|
| --- a/content/browser/media/session/media_session.cc
|
| +++ b/content/browser/media/session/media_session.cc
|
| @@ -71,6 +71,9 @@ void MediaSession::SetMetadata(const base::Optional<MediaMetadata>& metadata) {
|
| bool MediaSession::AddPlayer(MediaSessionObserver* observer,
|
| int player_id,
|
| media::MediaContentType media_content_type) {
|
| + if (media_content_type == media::MediaContentType::Pepper)
|
| + return AddPepperPlayer(observer, player_id);
|
| +
|
| observer->OnSetVolumeMultiplier(player_id, GetVolumeMultiplier());
|
|
|
| // Determine the audio focus type required for playing the new player.
|
| @@ -122,17 +125,28 @@ void MediaSession::RemovePlayer(MediaSessionObserver* observer,
|
| if (it != players_.end())
|
| players_.erase(it);
|
|
|
| + it = pepper_players_.find(PlayerIdentifier(observer, player_id));
|
| + if (it != pepper_players_.end())
|
| + pepper_players_.erase(it);
|
| +
|
| AbandonSystemAudioFocusIfNeeded();
|
| }
|
|
|
| void MediaSession::RemovePlayers(MediaSessionObserver* observer) {
|
| - for (auto it = players_.begin(); it != players_.end();) {
|
| + for (auto it = players_.begin(); it != players_.end(); ) {
|
| if (it->observer == observer)
|
| players_.erase(it++);
|
| else
|
| ++it;
|
| }
|
|
|
| + for (auto it = pepper_players_.begin(); it != pepper_players_.end(); ) {
|
| + if (it->observer == observer)
|
| + pepper_players_.erase(it++);
|
| + else
|
| + ++it;
|
| + }
|
| +
|
| AbandonSystemAudioFocusIfNeeded();
|
| }
|
|
|
| @@ -190,8 +204,8 @@ void MediaSession::Suspend(SuspendType suspend_type) {
|
|
|
| void MediaSession::Stop(SuspendType suspend_type) {
|
| DCHECK(audio_focus_state_ != State::INACTIVE);
|
| -
|
| DCHECK(suspend_type != SuspendType::CONTENT);
|
| + DCHECK(!HasPepper());
|
|
|
| // TODO(mlamouri): merge the logic between UI and SYSTEM.
|
| if (suspend_type == SuspendType::SYSTEM) {
|
| @@ -204,6 +218,7 @@ void MediaSession::Stop(SuspendType suspend_type) {
|
|
|
| DCHECK(audio_focus_state_ == State::SUSPENDED);
|
| players_.clear();
|
| +
|
| AbandonSystemAudioFocusIfNeeded();
|
| }
|
|
|
| @@ -250,6 +265,10 @@ bool MediaSession::IsControllable() const {
|
| audio_focus_type_ == AudioFocusManager::AudioFocusType::Gain;
|
| }
|
|
|
| +bool MediaSession::HasPepper() const {
|
| + return !pepper_players_.empty();
|
| +}
|
| +
|
| std::unique_ptr<base::CallbackList<void(MediaSession::State)>::Subscription>
|
| MediaSession::RegisterMediaSessionStateChangedCallbackForTest(
|
| const StateChangedCallback& cb) {
|
| @@ -323,6 +342,9 @@ void MediaSession::OnSuspendInternal(SuspendType suspend_type,
|
| it.observer->OnSuspend(it.player_id);
|
| }
|
|
|
| + for (const auto& it : pepper_players_)
|
| + it.observer->OnSetVolumeMultiplier(it.player_id, kDuckingVolumeMultiplier);
|
| +
|
| UpdateWebContents();
|
| }
|
|
|
| @@ -335,6 +357,10 @@ void MediaSession::OnResumeInternal(SuspendType suspend_type) {
|
| for (const auto& it : players_)
|
| it.observer->OnResume(it.player_id);
|
|
|
| + for (const auto& it : pepper_players_)
|
| + it.observer->OnSetVolumeMultiplier(
|
| + it.player_id, GetVolumeMultiplier());
|
| +
|
| UpdateWebContents();
|
| }
|
|
|
| @@ -357,7 +383,8 @@ bool MediaSession::RequestSystemAudioFocus(
|
| }
|
|
|
| void MediaSession::AbandonSystemAudioFocusIfNeeded() {
|
| - if (audio_focus_state_ == State::INACTIVE || !players_.empty())
|
| + if (audio_focus_state_ == State::INACTIVE || !players_.empty() ||
|
| + !pepper_players_.empty())
|
| return;
|
|
|
| delegate_->AbandonAudioFocus();
|
| @@ -389,4 +416,19 @@ void MediaSession::SetAudioFocusState(State audio_focus_state) {
|
| }
|
| }
|
|
|
| +bool MediaSession::AddPepperPlayer(MediaSessionObserver* observer,
|
| + int player_id) {
|
| + AudioFocusManager::AudioFocusType focus_type =
|
| + AudioFocusManager::AudioFocusType::Gain;
|
| + State audio_focus_state =
|
| + RequestSystemAudioFocus(focus_type) ? State::ACTIVE : State::INACTIVE;
|
| + SetAudioFocusState(audio_focus_state);
|
| + audio_focus_type_ = focus_type;
|
| + pepper_players_.insert(PlayerIdentifier(observer, player_id));
|
| +
|
| + observer->OnSetVolumeMultiplier(player_id, GetVolumeMultiplier());
|
| +
|
| + return true;
|
| +}
|
| +
|
| } // namespace content
|
|
|