OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/media/session/media_session.h" | 5 #include "content/browser/media/session/media_session.h" |
6 | 6 |
7 #include "content/browser/media/session/media_session_delegate.h" | 7 #include "content/browser/media/session/media_session_delegate.h" |
8 #include "content/browser/media/session/media_session_observer.h" | 8 #include "content/browser/media/session/media_session_observer.h" |
9 #include "content/browser/web_contents/web_contents_impl.h" | 9 #include "content/browser/web_contents/web_contents_impl.h" |
10 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 metadata_ = metadata; | 63 metadata_ = metadata; |
64 // TODO(zqzhang): On Android, the metadata is sent though JNI everytime the | 64 // TODO(zqzhang): On Android, the metadata is sent though JNI everytime the |
65 // media session play/pause state changes. Need to find a way to seprate the | 65 // media session play/pause state changes. Need to find a way to seprate the |
66 // state change and Metadata update. See https://crbug.com/621855. | 66 // state change and Metadata update. See https://crbug.com/621855. |
67 static_cast<WebContentsImpl*>(web_contents())->OnMediaSessionStateChanged(); | 67 static_cast<WebContentsImpl*>(web_contents())->OnMediaSessionStateChanged(); |
68 } | 68 } |
69 | 69 |
70 bool MediaSession::AddPlayer(MediaSessionObserver* observer, | 70 bool MediaSession::AddPlayer(MediaSessionObserver* observer, |
71 int player_id, | 71 int player_id, |
72 media::MediaContentType media_content_type) { | 72 media::MediaContentType media_content_type) { |
| 73 if (media_content_type == media::MediaContentType::Pepper) |
| 74 return AddPepperPlayer(observer, player_id); |
| 75 |
73 observer->OnSetVolumeMultiplier(player_id, volume_multiplier_); | 76 observer->OnSetVolumeMultiplier(player_id, volume_multiplier_); |
74 | 77 |
75 // Determine the audio focus type required for playing the new player. | 78 // Determine the audio focus type required for playing the new player. |
76 // TODO(zqzhang): handle duckable and uncontrollable. | 79 // TODO(zqzhang): handle duckable and uncontrollable. |
77 // See https://crbug.com/639277. | 80 // See https://crbug.com/639277. |
78 AudioFocusManager::AudioFocusType required_audio_focus_type; | 81 AudioFocusManager::AudioFocusType required_audio_focus_type; |
79 if (media_content_type == media::MediaContentType::Persistent) { | 82 if (media_content_type == media::MediaContentType::Persistent) { |
80 required_audio_focus_type = AudioFocusManager::AudioFocusType::Gain; | 83 required_audio_focus_type = AudioFocusManager::AudioFocusType::Gain; |
81 } else { | 84 } else { |
82 required_audio_focus_type = | 85 required_audio_focus_type = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 117 |
115 return true; | 118 return true; |
116 } | 119 } |
117 | 120 |
118 void MediaSession::RemovePlayer(MediaSessionObserver* observer, | 121 void MediaSession::RemovePlayer(MediaSessionObserver* observer, |
119 int player_id) { | 122 int player_id) { |
120 auto it = players_.find(PlayerIdentifier(observer, player_id)); | 123 auto it = players_.find(PlayerIdentifier(observer, player_id)); |
121 if (it != players_.end()) | 124 if (it != players_.end()) |
122 players_.erase(it); | 125 players_.erase(it); |
123 | 126 |
| 127 auto it_pepper = pepper_players_.find(PlayerIdentifier(observer, player_id)); |
| 128 if (it != pepper_players_.end()) { |
| 129 pepper_players_.erase(it); |
| 130 if (pepper_players_.empty()) |
| 131 delegate_->AbandonPepperAudioFocus(); |
| 132 } |
| 133 |
124 AbandonSystemAudioFocusIfNeeded(); | 134 AbandonSystemAudioFocusIfNeeded(); |
125 } | 135 } |
126 | 136 |
127 void MediaSession::RemovePlayers(MediaSessionObserver* observer) { | 137 void MediaSession::RemovePlayers(MediaSessionObserver* observer) { |
128 for (auto it = players_.begin(); it != players_.end();) { | 138 for (auto it = players_.begin(); it != players_.end();) { |
129 if (it->observer == observer) | 139 if (it->observer == observer) |
130 players_.erase(it++); | 140 players_.erase(it++); |
131 else | 141 else |
132 ++it; | 142 ++it; |
133 } | 143 } |
134 | 144 |
| 145 for (auto it = pepper_players_.begin(); it != pepper_players_.end();) { |
| 146 if (it->observer == observer) |
| 147 pepper_players_.erase(it++); |
| 148 else |
| 149 ++it; |
| 150 if (pepper_players_.empty()) |
| 151 delegate_->AbandonPepperAudioFocus(); |
| 152 } |
| 153 |
135 AbandonSystemAudioFocusIfNeeded(); | 154 AbandonSystemAudioFocusIfNeeded(); |
136 } | 155 } |
137 | 156 |
138 void MediaSession::RecordSessionDuck() { | 157 void MediaSession::RecordSessionDuck() { |
139 uma_helper_.RecordSessionSuspended( | 158 uma_helper_.RecordSessionSuspended( |
140 MediaSessionSuspendedSource::SystemTransientDuck); | 159 MediaSessionSuspendedSource::SystemTransientDuck); |
141 } | 160 } |
142 | 161 |
143 void MediaSession::OnPlayerPaused(MediaSessionObserver* observer, | 162 void MediaSession::OnPlayerPaused(MediaSessionObserver* observer, |
144 int player_id) { | 163 int player_id) { |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 break; | 383 break; |
365 case State::SUSPENDED: | 384 case State::SUSPENDED: |
366 uma_helper_.OnSessionSuspended(); | 385 uma_helper_.OnSessionSuspended(); |
367 break; | 386 break; |
368 case State::INACTIVE: | 387 case State::INACTIVE: |
369 uma_helper_.OnSessionInactive(); | 388 uma_helper_.OnSessionInactive(); |
370 break; | 389 break; |
371 } | 390 } |
372 } | 391 } |
373 | 392 |
| 393 bool MediaSession::AddPepperPlayer( |
| 394 MediaSessionObserver* observer, int player_id) { |
| 395 pepper_players_.insert(PlayerIdentifier(observer, player_id)); |
| 396 return delegate_->RequestPepperAudioFocus(); |
| 397 } |
| 398 |
| 399 void MediaSession::SetPepperVolumeMultiplier(double volume_multiplier) { |
| 400 volume_multiplier_ = volume_multiplier; |
| 401 for (const auto& it : pepper_players_) |
| 402 it.observer->OnSetVolumeMultiplier(it.player_id, volume_multiplier_); |
| 403 } |
| 404 |
374 } // namespace content | 405 } // namespace content |
OLD | NEW |