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 #ifndef CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ |
6 #define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ | 6 #define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | |
11 #include <set> | |
12 | |
10 #include "base/callback_list.h" | 13 #include "base/callback_list.h" |
11 #include "base/id_map.h" | 14 #include "base/id_map.h" |
12 #include "base/macros.h" | 15 #include "base/macros.h" |
13 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
14 #include "base/optional.h" | 17 #include "base/optional.h" |
15 #include "content/browser/media/session/audio_focus_manager.h" | 18 #include "content/browser/media/session/audio_focus_manager.h" |
16 #include "content/browser/media/session/media_session_uma_helper.h" | 19 #include "content/browser/media/session/media_session_uma_helper.h" |
17 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
18 #include "content/public/browser/media_session.h" | 21 #include "content/public/browser/media_session.h" |
19 #include "content/public/browser/media_session_observer.h" | 22 #include "content/public/browser/media_session_observer.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 static MediaSession* FromJavaMediaSession( | 80 static MediaSession* FromJavaMediaSession( |
78 const base::android::JavaRef<jobject>& j_media_session); | 81 const base::android::JavaRef<jobject>& j_media_session); |
79 MediaSessionAndroid* session_android() const { | 82 MediaSessionAndroid* session_android() const { |
80 return session_android_.get(); | 83 return session_android_.get(); |
81 } | 84 } |
82 #endif // defined(OS_ANDROID) | 85 #endif // defined(OS_ANDROID) |
83 | 86 |
84 void AddObserver(MediaSessionObserver* observer); | 87 void AddObserver(MediaSessionObserver* observer); |
85 void RemoveObserver(MediaSessionObserver* observer); | 88 void RemoveObserver(MediaSessionObserver* observer); |
86 | 89 |
87 void SetMetadata(const base::Optional<MediaMetadata>& metadata); | 90 void NotifyMediaSessionMetadataChange( |
88 const base::Optional<MediaMetadata>& metadata() const { return metadata_; } | 91 const base::Optional<MediaMetadata>& metadata); |
92 void NotifyMediaSessionActionsChange( | |
93 const std::set<blink::mojom::MediaSessionAction>& actions); | |
89 | 94 |
90 // Adds the given player to the current media session. Returns whether the | 95 // Adds the given player to the current media session. Returns whether the |
91 // player was successfully added. If it returns false, AddPlayer() should be | 96 // player was successfully added. If it returns false, AddPlayer() should be |
92 // called again later. | 97 // called again later. |
93 CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer, | 98 CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer, |
94 int player_id, | 99 int player_id, |
95 media::MediaContentType media_content_type); | 100 media::MediaContentType media_content_type); |
96 | 101 |
97 // Removes the given player from the current media session. Abandons audio | 102 // Removes the given player from the current media session. Abandons audio |
98 // focus if that was the last player in the session. | 103 // focus if that was the last player in the session. |
(...skipping 18 matching lines...) Expand all Loading... | |
117 CONTENT_EXPORT void Resume(MediaSession::SuspendType suspend_type) override; | 122 CONTENT_EXPORT void Resume(MediaSession::SuspendType suspend_type) override; |
118 | 123 |
119 // Suspend the media session. | 124 // Suspend the media session. |
120 // |type| represents the origin of the request. | 125 // |type| represents the origin of the request. |
121 CONTENT_EXPORT void Suspend(MediaSession::SuspendType suspend_type) override; | 126 CONTENT_EXPORT void Suspend(MediaSession::SuspendType suspend_type) override; |
122 | 127 |
123 // Stop the media session. | 128 // Stop the media session. |
124 // |type| represents the origin of the request. | 129 // |type| represents the origin of the request. |
125 CONTENT_EXPORT void Stop(MediaSession::SuspendType suspend_type) override; | 130 CONTENT_EXPORT void Stop(MediaSession::SuspendType suspend_type) override; |
126 | 131 |
127 // Received a media session action and forward to blink::MediaSession. | |
128 void DidReceiveAction(blink::mojom::MediaSessionAction action) override; | |
129 | |
130 // Called when an action is enabled in blink::MediaSession. This method will | |
131 // notify the observers that the action is enabled. | |
132 void OnMediaSessionEnabledAction(blink::mojom::MediaSessionAction action); | |
133 | |
134 // Called when an action is disabled in blink::MediaSession. This method will | |
135 // notify the observers that the action is disabled. | |
136 void OnMediaSessionDisabledAction(blink::mojom::MediaSessionAction action); | |
137 | |
138 // Let the media session start ducking such that the volume multiplier is | 132 // Let the media session start ducking such that the volume multiplier is |
139 // reduced. | 133 // reduced. |
140 CONTENT_EXPORT void StartDucking(); | 134 CONTENT_EXPORT void StartDucking(); |
141 | 135 |
142 // Let the media session stop ducking such that the volume multiplier is | 136 // Let the media session stop ducking such that the volume multiplier is |
143 // recovered. | 137 // recovered. |
144 CONTENT_EXPORT void StopDucking(); | 138 CONTENT_EXPORT void StopDucking(); |
145 | 139 |
146 // Returns if the session can be controlled by Resume() and Suspend calls | 140 // Returns if the session can be controlled by Resume() and Suspend calls |
147 // above. | 141 // above. |
(...skipping 17 matching lines...) Expand all Loading... | |
165 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type() const { | 159 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type() const { |
166 return audio_focus_type_; | 160 return audio_focus_type_; |
167 } | 161 } |
168 | 162 |
169 // Returns whether the session has Pepper instances. | 163 // Returns whether the session has Pepper instances. |
170 bool HasPepper() const; | 164 bool HasPepper() const; |
171 | 165 |
172 // WebContentsObserver implementation | 166 // WebContentsObserver implementation |
173 void WebContentsDestroyed() override; | 167 void WebContentsDestroyed() override; |
174 | 168 |
175 // Sets the associated MediaSessionService for communicating with | 169 // MediaSessionService-related methods |
176 // blink::MediaSession. | 170 |
177 MediaSessionServiceImpl* GetMediaSessionService() { return service_; } | 171 // Called when a MediaSessionService is created, which registers itself to |
178 void SetMediaSessionService(MediaSessionServiceImpl* service); | 172 // this session. |
173 void OnServiceCreated(MediaSessionServiceImpl* service); | |
174 // Called when a MediaSessionService is destroyed, which unregisters itself | |
175 // from this session. | |
176 void OnServiceDestroyed(MediaSessionServiceImpl* service); | |
177 | |
178 // Called when the metadata of a MediaSessionService has changed. Will notify | |
179 // observers if the service is currently routed. | |
180 void OnMediaSessionMetadataChanged(MediaSessionServiceImpl* service); | |
181 // Called when the actions of a MediaSessionService has changed. Will notify | |
182 // observers if the service is currently routed. | |
183 void OnMediaSessionActionsChanged(MediaSessionServiceImpl* service); | |
184 | |
185 // Called when a MediaSessionAction is received. The action will be forwarded | |
186 // to blink::MediaSession corresponding to the current routed service. | |
187 void DidReceiveAction(blink::mojom::MediaSessionAction action) override; | |
179 | 188 |
180 private: | 189 private: |
181 friend class content::WebContentsUserData<MediaSessionImpl>; | 190 friend class content::WebContentsUserData<MediaSessionImpl>; |
182 friend class ::MediaSessionImplBrowserTest; | 191 friend class ::MediaSessionImplBrowserTest; |
183 friend class content::MediaSessionImplVisibilityBrowserTest; | 192 friend class content::MediaSessionImplVisibilityBrowserTest; |
184 friend class content::AudioFocusManagerTest; | 193 friend class content::AudioFocusManagerTest; |
185 friend class content::MediaSessionImplStateObserver; | 194 friend class content::MediaSessionImplStateObserver; |
186 | 195 |
187 CONTENT_EXPORT void SetDelegateForTests( | 196 CONTENT_EXPORT void SetDelegateForTests( |
188 std::unique_ptr<AudioFocusDelegate> delegate); | 197 std::unique_ptr<AudioFocusDelegate> delegate); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
244 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription> | 253 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription> |
245 RegisterMediaSessionStateChangedCallbackForTest( | 254 RegisterMediaSessionStateChangedCallbackForTest( |
246 const StateChangedCallback& cb); | 255 const StateChangedCallback& cb); |
247 | 256 |
248 CONTENT_EXPORT bool AddPepperPlayer(MediaSessionPlayerObserver* observer, | 257 CONTENT_EXPORT bool AddPepperPlayer(MediaSessionPlayerObserver* observer, |
249 int player_id); | 258 int player_id); |
250 | 259 |
251 CONTENT_EXPORT bool AddOneShotPlayer(MediaSessionPlayerObserver* observer, | 260 CONTENT_EXPORT bool AddOneShotPlayer(MediaSessionPlayerObserver* observer, |
252 int player_id); | 261 int player_id); |
253 | 262 |
263 // MediaSessionService-related methods | |
264 | |
265 // Called when the routed service may have changed. | |
266 void UpdateRoutedService(); | |
267 // Returns whether the frame |rfh| uses MediaSession API. | |
268 bool IsServiceActiveForRenderFrameHost(RenderFrameHost* rfh); | |
269 // Returns the most-meaningful audio producing frame for deciding which | |
270 // MediaSessionService should be routed. | |
271 RenderFrameHost* GetMostMeaningfulAudioProducingFrame(); | |
whywhat
2016/11/28 19:59:14
nit: most-meaningful doesn't tell much to the read
Zhiqiang Zhang (Slow)
2016/11/30 16:40:59
Done.
| |
272 | |
254 std::unique_ptr<AudioFocusDelegate> delegate_; | 273 std::unique_ptr<AudioFocusDelegate> delegate_; |
255 PlayersMap normal_players_; | 274 PlayersMap normal_players_; |
256 PlayersMap pepper_players_; | 275 PlayersMap pepper_players_; |
257 PlayersMap one_shot_players_; | 276 PlayersMap one_shot_players_; |
258 | 277 |
259 State audio_focus_state_; | 278 State audio_focus_state_; |
260 MediaSession::SuspendType suspend_type_; | 279 MediaSession::SuspendType suspend_type_; |
261 AudioFocusManager::AudioFocusType audio_focus_type_; | 280 AudioFocusManager::AudioFocusType audio_focus_type_; |
262 | 281 |
263 MediaSessionUmaHelper uma_helper_; | 282 MediaSessionUmaHelper uma_helper_; |
264 | 283 |
265 // The ducking state of this media session. The initial value is |false|, and | 284 // The ducking state of this media session. The initial value is |false|, and |
266 // is set to |true| after StartDucking(), and will be set to |false| after | 285 // is set to |true| after StartDucking(), and will be set to |false| after |
267 // StopDucking(). | 286 // StopDucking(). |
268 bool is_ducking_; | 287 bool is_ducking_; |
269 | 288 |
270 base::Optional<MediaMetadata> metadata_; | |
271 base::CallbackList<void(State)> media_session_state_listeners_; | 289 base::CallbackList<void(State)> media_session_state_listeners_; |
272 | 290 |
273 base::ObserverList<MediaSessionObserver> observers_; | 291 base::ObserverList<MediaSessionObserver> observers_; |
274 | 292 |
275 #if defined(OS_ANDROID) | 293 #if defined(OS_ANDROID) |
276 std::unique_ptr<MediaSessionAndroid> session_android_; | 294 std::unique_ptr<MediaSessionAndroid> session_android_; |
277 #endif // defined(OS_ANDROID) | 295 #endif // defined(OS_ANDROID) |
278 | 296 |
279 // The MediaSessionService this session is associated with (the service of the | 297 // MediaSessionService-related fields |
280 // top-level frame). | 298 using ServicesMap = std::map<RenderFrameHost*, MediaSessionServiceImpl*>; |
281 MediaSessionServiceImpl* service_; | 299 |
300 // The collection of all managed services (non-owned pointers). The services | |
301 // are owned by RenderFrameHost and should be registered on creation and | |
302 // unregistered on destroy. | |
303 ServicesMap services_; | |
304 // The currently routed service (non-owned pointer). | |
305 MediaSessionServiceImpl* routed_service_; | |
282 | 306 |
283 DISALLOW_COPY_AND_ASSIGN(MediaSessionImpl); | 307 DISALLOW_COPY_AND_ASSIGN(MediaSessionImpl); |
284 }; | 308 }; |
285 | 309 |
286 } // namespace content | 310 } // namespace content |
287 | 311 |
288 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ | 312 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ |
OLD | NEW |