| 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 c95ab3b5784069a8ab41a26600c3c976d7751188..7b15068feaab66f00204630f6d133ac2b313cb14 100644
|
| --- a/content/browser/media/session/media_session.cc
|
| +++ b/content/browser/media/session/media_session.cc
|
| @@ -60,6 +60,11 @@ MediaSession::~MediaSession() {
|
| DCHECK(audio_focus_state_ == State::INACTIVE);
|
| }
|
|
|
| +void MediaSession::WasShown() {
|
| + if (IsSuspended())
|
| + RequestSystemAudioFocus(audio_focus_type_);
|
| +}
|
| +
|
| void MediaSession::SetMetadata(const MediaMetadata& metadata) {
|
| metadata_ = metadata;
|
| // TODO(zqzhang): On Android, the metadata is sent though JNI everytime the
|
| @@ -71,6 +76,9 @@ void MediaSession::SetMetadata(const 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 +130,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_player_.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();
|
| }
|
|
|
| @@ -204,6 +223,12 @@ void MediaSession::Stop(SuspendType suspend_type) {
|
|
|
| DCHECK(audio_focus_state_ == State::SUSPENDED);
|
| players_.clear();
|
| +
|
| + for (const auto& it : pepper_players_) {
|
| + it.observer->OnSetVolumeMultiplier(
|
| + it.player_id, GetPepperVolumeMultiplier());
|
| + }
|
| +
|
| AbandonSystemAudioFocusIfNeeded();
|
| }
|
|
|
| @@ -230,6 +255,14 @@ double MediaSession::GetVolumeMultiplier() const {
|
| return is_ducking_ ? kDuckingVolumeMultiplier : kDefaultVolumeMultiplier;
|
| }
|
|
|
| +double MediaSession::GetPepperVolumeMultiplier() const {
|
| + if (is_ducking_)
|
| + return kDuckingVolumeMultiplier;
|
| + if (!IsActive() && !allow_pepper_override_ducking_)
|
| + return kDuckingVolumeMultiplier;
|
| + return kDefaultVolumeMultiplier;
|
| +}
|
| +
|
| bool MediaSession::IsActive() const {
|
| return audio_focus_state_ == State::ACTIVE;
|
| }
|
| @@ -250,6 +283,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 +360,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 +375,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, GetPepperVolumeMultiplier());
|
| +
|
| UpdateWebContents();
|
| }
|
|
|
| @@ -343,7 +387,8 @@ MediaSession::MediaSession(WebContents* web_contents)
|
| audio_focus_state_(State::INACTIVE),
|
| audio_focus_type_(
|
| AudioFocusManager::AudioFocusType::GainTransientMayDuck),
|
| - is_ducking_(false) {}
|
| + is_ducking_(false),
|
| + allow_pepper_override_ducking_(false) {}
|
|
|
| void MediaSession::Initialize() {
|
| delegate_ = MediaSessionDelegate::Create(this);
|
| @@ -357,7 +402,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 +435,41 @@ 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, GetPepperVolumeMultiplier());
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void MediaSession::AllowPepperOverrideDucking() {
|
| + if (allow_pepper_override_ducking_)
|
| + return;
|
| +
|
| + allow_pepper_override_ducking_ = true;
|
| + for (const auto& it : pepper_players_) {
|
| + it.observer->OnSetVolumeMultiplier(
|
| + it.player_id, GetPepperVolumeMultiplier());
|
| + }
|
| +}
|
| +
|
| +void MediaSession::DisallowPepperOverrideDucking() {
|
| + if (!allow_pepper_override_ducking_)
|
| + return;
|
| +
|
| + allow_pepper_override_ducking_ = false;
|
| + for (const auto& it : pepper_players_) {
|
| + it.observer->OnSetVolumeMultiplier(
|
| + it.player_id, GetPepperVolumeMultiplier());
|
| + }
|
| +}
|
| +
|
| } // namespace content
|
|
|