| 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 "base/callback_list.h" | 10 #include "base/callback_list.h" |
| 11 #include "base/id_map.h" | 11 #include "base/id_map.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/observer_list.h" | 13 #include "base/observer_list.h" |
| 14 #include "base/optional.h" | 14 #include "base/optional.h" |
| 15 #include "content/browser/media/session/audio_focus_manager.h" | 15 #include "content/browser/media/session/audio_focus_manager.h" |
| 16 #include "content/browser/media/session/media_session_uma_helper.h" | 16 #include "content/browser/media/session/media_session_uma_helper.h" |
| 17 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 18 #include "content/public/browser/media_session.h" | 18 #include "content/public/browser/media_session.h" |
| 19 #include "content/public/browser/media_session_observer.h" | 19 #include "content/public/browser/media_session_observer.h" |
| 20 #include "content/public/browser/web_contents_observer.h" | 20 #include "content/public/browser/web_contents_observer.h" |
| 21 #include "content/public/browser/web_contents_user_data.h" | 21 #include "content/public/browser/web_contents_user_data.h" |
| 22 #include "content/public/common/media_metadata.h" | 22 #include "content/public/common/media_metadata.h" |
| 23 | 23 |
| 24 #if defined(OS_ANDROID) |
| 25 #include "base/android/scoped_java_ref.h" |
| 26 #endif // defined(OS_ANDROID) |
| 27 |
| 24 class MediaSessionImplBrowserTest; | 28 class MediaSessionImplBrowserTest; |
| 25 | 29 |
| 26 namespace media { | 30 namespace media { |
| 27 enum class MediaContentType; | 31 enum class MediaContentType; |
| 28 } // namespace media | 32 } // namespace media |
| 29 | 33 |
| 30 namespace content { | 34 namespace content { |
| 31 | 35 |
| 32 class AudioFocusDelegate; | 36 class AudioFocusDelegate; |
| 33 class AudioFocusManagerTest; | 37 class AudioFocusManagerTest; |
| 34 class MediaSessionPlayerObserver; | |
| 35 class MediaSessionImplStateObserver; | 38 class MediaSessionImplStateObserver; |
| 36 class MediaSessionImplVisibilityBrowserTest; | 39 class MediaSessionImplVisibilityBrowserTest; |
| 37 class MediaSessionObserver; | 40 class MediaSessionObserver; |
| 41 class MediaSessionPlayerObserver; |
| 42 |
| 43 #if defined(OS_ANDROID) |
| 44 class MediaSessionAndroid; |
| 45 #endif // defined(OS_ANDROID) |
| 38 | 46 |
| 39 // MediaSessionImpl is the implementation of MediaSession. It manages the media | 47 // MediaSessionImpl is the implementation of MediaSession. It manages the media |
| 40 // session and audio focus for a given WebContents. It is requesting the audio | 48 // session and audio focus for a given WebContents. It is requesting the audio |
| 41 // focus, pausing when requested by the system and dropping it on demand. The | 49 // focus, pausing when requested by the system and dropping it on demand. The |
| 42 // audio focus can be of two types: Transient or Content. A Transient audio | 50 // audio focus can be of two types: Transient or Content. A Transient audio |
| 43 // focus will allow other players to duck instead of pausing and will be | 51 // focus will allow other players to duck instead of pausing and will be |
| 44 // declared as temporary to the system. A Content audio focus will not be | 52 // declared as temporary to the system. A Content audio focus will not be |
| 45 // declared as temporary and will not allow other players to duck. If a given | 53 // declared as temporary and will not allow other players to duck. If a given |
| 46 // WebContents can only have one audio focus at a time, it will be Content in | 54 // WebContents can only have one audio focus at a time, it will be Content in |
| 47 // case of Transient and Content audio focus are both requested. | 55 // case of Transient and Content audio focus are both requested. |
| 48 // TODO(thakis,mlamouri): MediaSessionImpl isn't CONTENT_EXPORT'd because it | 56 // TODO(thakis,mlamouri): MediaSessionImpl isn't CONTENT_EXPORT'd because it |
| 49 // creates complicated build issues with WebContentsUserData being a | 57 // creates complicated build issues with WebContentsUserData being a |
| 50 // non-exported template, see https://crbug.com/589840. As a result, the class | 58 // non-exported template, see https://crbug.com/589840. As a result, the class |
| 51 // uses CONTENT_EXPORT for methods that are being used from tests. | 59 // uses CONTENT_EXPORT for methods that are being used from tests. |
| 52 // CONTENT_EXPORT should be moved back to the class when the Windows build will | 60 // CONTENT_EXPORT should be moved back to the class when the Windows build will |
| 53 // work with it. | 61 // work with it. |
| 54 class MediaSessionImpl : public MediaSession, | 62 class MediaSessionImpl : public MediaSession, |
| 55 WebContentsObserver, | 63 WebContentsObserver, |
| 56 protected WebContentsUserData<MediaSessionImpl> { | 64 protected WebContentsUserData<MediaSessionImpl> { |
| 57 public: | 65 public: |
| 58 // Only visible to tests. | 66 // Only visible to tests. |
| 59 enum class State { ACTIVE, SUSPENDED, INACTIVE }; | 67 enum class State { ACTIVE, SUSPENDED, INACTIVE }; |
| 60 | 68 |
| 61 // Returns the MediaSessionImpl associated to this WebContents. Creates one if | 69 // Returns the MediaSessionImpl associated to this WebContents. Creates one if |
| 62 // none is currently available. | 70 // none is currently available. |
| 63 CONTENT_EXPORT static MediaSessionImpl* Get(WebContents* web_contents); | 71 CONTENT_EXPORT static MediaSessionImpl* Get(WebContents* web_contents); |
| 64 | 72 |
| 65 ~MediaSessionImpl() override; | 73 ~MediaSessionImpl() override; |
| 66 | 74 |
| 75 #if defined(OS_ANDROID) |
| 76 static MediaSession* FromJavaMediaSession( |
| 77 const base::android::JavaRef<jobject>& j_media_session); |
| 78 MediaSessionAndroid* session_android() const { |
| 79 return session_android_.get(); |
| 80 } |
| 81 #endif // defined(OS_ANDROID) |
| 82 |
| 67 void AddObserver(MediaSessionObserver* observer); | 83 void AddObserver(MediaSessionObserver* observer); |
| 68 void RemoveObserver(MediaSessionObserver* observer); | 84 void RemoveObserver(MediaSessionObserver* observer); |
| 69 | 85 |
| 70 void SetMetadata(const base::Optional<MediaMetadata>& metadata); | 86 void SetMetadata(const base::Optional<MediaMetadata>& metadata); |
| 71 const base::Optional<MediaMetadata>& metadata() const { return metadata_; } | 87 const base::Optional<MediaMetadata>& metadata() const { return metadata_; } |
| 72 | 88 |
| 73 // Adds the given player to the current media session. Returns whether the | 89 // Adds the given player to the current media session. Returns whether the |
| 74 // player was successfully added. If it returns false, AddPlayer() should be | 90 // player was successfully added. If it returns false, AddPlayer() should be |
| 75 // called again later. | 91 // called again later. |
| 76 CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer, | 92 CONTENT_EXPORT bool AddPlayer(MediaSessionPlayerObserver* observer, |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 // The ducking state of this media session. The initial value is |false|, and | 244 // The ducking state of this media session. The initial value is |false|, and |
| 229 // is set to |true| after StartDucking(), and will be set to |false| after | 245 // is set to |true| after StartDucking(), and will be set to |false| after |
| 230 // StopDucking(). | 246 // StopDucking(). |
| 231 bool is_ducking_; | 247 bool is_ducking_; |
| 232 | 248 |
| 233 base::Optional<MediaMetadata> metadata_; | 249 base::Optional<MediaMetadata> metadata_; |
| 234 base::CallbackList<void(State)> media_session_state_listeners_; | 250 base::CallbackList<void(State)> media_session_state_listeners_; |
| 235 | 251 |
| 236 base::ObserverList<MediaSessionObserver> observers_; | 252 base::ObserverList<MediaSessionObserver> observers_; |
| 237 | 253 |
| 254 #if defined(OS_ANDROID) |
| 255 std::unique_ptr<MediaSessionAndroid> session_android_; |
| 256 #endif // defined(OS_ANDROID) |
| 257 |
| 238 DISALLOW_COPY_AND_ASSIGN(MediaSessionImpl); | 258 DISALLOW_COPY_AND_ASSIGN(MediaSessionImpl); |
| 239 }; | 259 }; |
| 240 | 260 |
| 241 } // namespace content | 261 } // namespace content |
| 242 | 262 |
| 243 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ | 263 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_IMPL_H_ |
| OLD | NEW |