| 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 <set> |
| 11 |
| 10 #include "base/callback_list.h" | 12 #include "base/callback_list.h" |
| 11 #include "base/id_map.h" | 13 #include "base/id_map.h" |
| 12 #include "base/macros.h" | 14 #include "base/macros.h" |
| 13 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 14 #include "base/optional.h" | 16 #include "base/optional.h" |
| 15 #include "content/browser/media/session/audio_focus_manager.h" | 17 #include "content/browser/media/session/audio_focus_manager.h" |
| 16 #include "content/browser/media/session/media_session_uma_helper.h" | 18 #include "content/browser/media/session/media_session_uma_helper.h" |
| 17 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 18 #include "content/public/browser/media_session.h" | 20 #include "content/public/browser/media_session.h" |
| 19 #include "content/public/browser/media_session_observer.h" | 21 #include "content/public/browser/media_session_observer.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 32 } // namespace media | 34 } // namespace media |
| 33 | 35 |
| 34 namespace content { | 36 namespace content { |
| 35 | 37 |
| 36 class AudioFocusDelegate; | 38 class AudioFocusDelegate; |
| 37 class AudioFocusManagerTest; | 39 class AudioFocusManagerTest; |
| 38 class MediaSessionImplStateObserver; | 40 class MediaSessionImplStateObserver; |
| 39 class MediaSessionImplVisibilityBrowserTest; | 41 class MediaSessionImplVisibilityBrowserTest; |
| 40 class MediaSessionObserver; | 42 class MediaSessionObserver; |
| 41 class MediaSessionPlayerObserver; | 43 class MediaSessionPlayerObserver; |
| 42 class MediaSessionServiceImpl; | 44 class MediaSessionServiceRouter; |
| 43 | 45 |
| 44 #if defined(OS_ANDROID) | 46 #if defined(OS_ANDROID) |
| 45 class MediaSessionAndroid; | 47 class MediaSessionAndroid; |
| 46 #endif // defined(OS_ANDROID) | 48 #endif // defined(OS_ANDROID) |
| 47 | 49 |
| 48 // MediaSessionImpl is the implementation of MediaSession. It manages the media | 50 // MediaSessionImpl is the implementation of MediaSession. It manages the media |
| 49 // session and audio focus for a given WebContents. It is requesting the audio | 51 // session and audio focus for a given WebContents. It is requesting the audio |
| 50 // focus, pausing when requested by the system and dropping it on demand. The | 52 // focus, pausing when requested by the system and dropping it on demand. The |
| 51 // audio focus can be of two types: Transient or Content. A Transient audio | 53 // audio focus can be of two types: Transient or Content. A Transient audio |
| 52 // focus will allow other players to duck instead of pausing and will be | 54 // focus will allow other players to duck instead of pausing and will be |
| (...skipping 24 matching lines...) Expand all Loading... |
| 77 static MediaSession* FromJavaMediaSession( | 79 static MediaSession* FromJavaMediaSession( |
| 78 const base::android::JavaRef<jobject>& j_media_session); | 80 const base::android::JavaRef<jobject>& j_media_session); |
| 79 MediaSessionAndroid* session_android() const { | 81 MediaSessionAndroid* session_android() const { |
| 80 return session_android_.get(); | 82 return session_android_.get(); |
| 81 } | 83 } |
| 82 #endif // defined(OS_ANDROID) | 84 #endif // defined(OS_ANDROID) |
| 83 | 85 |
| 84 void AddObserver(MediaSessionObserver* observer); | 86 void AddObserver(MediaSessionObserver* observer); |
| 85 void RemoveObserver(MediaSessionObserver* observer); | 87 void RemoveObserver(MediaSessionObserver* observer); |
| 86 | 88 |
| 87 void SetMetadata(const base::Optional<MediaMetadata>& metadata); | 89 void NotifyMediaSessionMetadataChange( |
| 88 const base::Optional<MediaMetadata>& metadata() const { return metadata_; } | 90 const base::Optional<MediaMetadata>& metadata); |
| 91 void NotifyMediaSessionActionsChange( |
| 92 const std::set<blink::mojom::MediaSessionAction>& actions); |
| 89 | 93 |
| 90 // Adds the given player to the current media session. Returns whether the | 94 // Adds the given player to the current media session. Returns whether the |
| 91 // player was successfully added. If it returns false, AddPlayer() should be | 95 // player was successfully added. If it returns false, AddPlayer() should be |
| 92 // called again later. | 96 // called again later. |
| 93 CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer, | 97 CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer, |
| 94 int player_id, | 98 int player_id, |
| 95 media::MediaContentType media_content_type); | 99 media::MediaContentType media_content_type); |
| 96 | 100 |
| 97 // Removes the given player from the current media session. Abandons audio | 101 // Removes the given player from the current media session. Abandons audio |
| 98 // focus if that was the last player in the session. | 102 // focus if that was the last player in the session. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 120 // |type| represents the origin of the request. | 124 // |type| represents the origin of the request. |
| 121 CONTENT_EXPORT void Suspend(MediaSession::SuspendType suspend_type) override; | 125 CONTENT_EXPORT void Suspend(MediaSession::SuspendType suspend_type) override; |
| 122 | 126 |
| 123 // Stop the media session. | 127 // Stop the media session. |
| 124 // |type| represents the origin of the request. | 128 // |type| represents the origin of the request. |
| 125 CONTENT_EXPORT void Stop(MediaSession::SuspendType suspend_type) override; | 129 CONTENT_EXPORT void Stop(MediaSession::SuspendType suspend_type) override; |
| 126 | 130 |
| 127 // Received a media session action and forward to blink::MediaSession. | 131 // Received a media session action and forward to blink::MediaSession. |
| 128 void DidReceiveAction(blink::mojom::MediaSessionAction action) override; | 132 void DidReceiveAction(blink::mojom::MediaSessionAction action) override; |
| 129 | 133 |
| 130 // Called when an action is enabled in blink::MediaSession. This method will | 134 // Called when blink::MediaSession action list has changed. This method will |
| 131 // notify the observers that the action is enabled. | 135 // notify the observers of the change. |
| 132 void OnMediaSessionEnabledAction(blink::mojom::MediaSessionAction action); | 136 void OnMediaSessionActionsChanged( |
| 133 | 137 const std::set<blink::mojom::MediaSessionAction>& actions); |
| 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 |
| 138 // Let the media session start ducking such that the volume multiplier is | 139 // Let the media session start ducking such that the volume multiplier is |
| 139 // reduced. | 140 // reduced. |
| 140 CONTENT_EXPORT void StartDucking(); | 141 CONTENT_EXPORT void StartDucking(); |
| 141 | 142 |
| 142 // Let the media session stop ducking such that the volume multiplier is | 143 // Let the media session stop ducking such that the volume multiplier is |
| 143 // recovered. | 144 // recovered. |
| 144 CONTENT_EXPORT void StopDucking(); | 145 CONTENT_EXPORT void StopDucking(); |
| 145 | 146 |
| 146 // Returns if the session can be controlled by Resume() and Suspend calls | 147 // Returns if the session can be controlled by Resume() and Suspend calls |
| (...skipping 18 matching lines...) Expand all Loading... |
| 165 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type() const { | 166 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type() const { |
| 166 return audio_focus_type_; | 167 return audio_focus_type_; |
| 167 } | 168 } |
| 168 | 169 |
| 169 // Returns whether the session has Pepper instances. | 170 // Returns whether the session has Pepper instances. |
| 170 bool HasPepper() const; | 171 bool HasPepper() const; |
| 171 | 172 |
| 172 // WebContentsObserver implementation | 173 // WebContentsObserver implementation |
| 173 void WebContentsDestroyed() override; | 174 void WebContentsDestroyed() override; |
| 174 | 175 |
| 175 // Sets the associated MediaSessionService for communicating with | 176 // Getting the associated MediaSessionServiceRouter for communicating with |
| 176 // blink::MediaSession. | 177 // blink::MediaSession. |
| 177 MediaSessionServiceImpl* GetMediaSessionService() { return service_; } | 178 MediaSessionServiceRouter* GetMediaSessionServiceRouter() { |
| 178 void SetMediaSessionService(MediaSessionServiceImpl* service); | 179 return service_router_.get(); |
| 180 } |
| 181 |
| 182 MediaSessionPlayerObserver* GetMostMeaningfulPlayerObserver(); |
| 179 | 183 |
| 180 private: | 184 private: |
| 181 friend class content::WebContentsUserData<MediaSessionImpl>; | 185 friend class content::WebContentsUserData<MediaSessionImpl>; |
| 182 friend class ::MediaSessionImplBrowserTest; | 186 friend class ::MediaSessionImplBrowserTest; |
| 183 friend class content::MediaSessionImplVisibilityBrowserTest; | 187 friend class content::MediaSessionImplVisibilityBrowserTest; |
| 184 friend class content::AudioFocusManagerTest; | 188 friend class content::AudioFocusManagerTest; |
| 185 friend class content::MediaSessionImplStateObserver; | 189 friend class content::MediaSessionImplStateObserver; |
| 186 | 190 |
| 187 CONTENT_EXPORT void SetDelegateForTests( | 191 CONTENT_EXPORT void SetDelegateForTests( |
| 188 std::unique_ptr<AudioFocusDelegate> delegate); | 192 std::unique_ptr<AudioFocusDelegate> delegate); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 MediaSession::SuspendType suspend_type_; | 264 MediaSession::SuspendType suspend_type_; |
| 261 AudioFocusManager::AudioFocusType audio_focus_type_; | 265 AudioFocusManager::AudioFocusType audio_focus_type_; |
| 262 | 266 |
| 263 MediaSessionUmaHelper uma_helper_; | 267 MediaSessionUmaHelper uma_helper_; |
| 264 | 268 |
| 265 // The ducking state of this media session. The initial value is |false|, and | 269 // 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 | 270 // is set to |true| after StartDucking(), and will be set to |false| after |
| 267 // StopDucking(). | 271 // StopDucking(). |
| 268 bool is_ducking_; | 272 bool is_ducking_; |
| 269 | 273 |
| 270 base::Optional<MediaMetadata> metadata_; | |
| 271 base::CallbackList<void(State)> media_session_state_listeners_; | 274 base::CallbackList<void(State)> media_session_state_listeners_; |
| 272 | 275 |
| 273 base::ObserverList<MediaSessionObserver> observers_; | 276 base::ObserverList<MediaSessionObserver> observers_; |
| 274 | 277 |
| 275 #if defined(OS_ANDROID) | 278 #if defined(OS_ANDROID) |
| 276 std::unique_ptr<MediaSessionAndroid> session_android_; | 279 std::unique_ptr<MediaSessionAndroid> session_android_; |
| 277 #endif // defined(OS_ANDROID) | 280 #endif // defined(OS_ANDROID) |
| 278 | 281 |
| 279 // The MediaSessionService this session is associated with (the service of the | 282 // The MediaSessionService this session is associated with (the service of the |
| 280 // top-level frame). | 283 // top-level frame). |
| 281 MediaSessionServiceImpl* service_; | 284 std::unique_ptr<MediaSessionServiceRouter> service_router_; |
| 282 | 285 |
| 283 DISALLOW_COPY_AND_ASSIGN(MediaSessionImpl); | 286 DISALLOW_COPY_AND_ASSIGN(MediaSessionImpl); |
| 284 }; | 287 }; |
| 285 | 288 |
| 286 } // namespace content | 289 } // namespace content |
| 287 | 290 |
| 288 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ | 291 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ |
| OLD | NEW |