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_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ |
6 #define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ | 6 #define CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_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/optional.h" | 13 #include "base/optional.h" |
14 #include "content/browser/media/session/audio_focus_manager.h" | 14 #include "content/browser/media/session/audio_focus_manager.h" |
15 #include "content/browser/media/session/media_session_uma_helper.h" | 15 #include "content/browser/media/session/media_session_uma_helper.h" |
16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
17 #include "content/public/browser/web_contents_observer.h" | 17 #include "content/public/browser/web_contents_observer.h" |
18 #include "content/public/browser/web_contents_user_data.h" | 18 #include "content/public/browser/web_contents_user_data.h" |
19 #include "content/public/common/media_metadata.h" | 19 #include "content/public/common/media_metadata.h" |
20 | 20 |
21 class MediaSessionBrowserTest; | 21 class MediaSessionBrowserTest; |
22 | 22 |
23 namespace blink { | |
24 namespace mojom { | |
25 enum class MediaSessionAction; | |
26 } // namespace mojom | |
27 } // namespace blink | |
28 | |
23 namespace media { | 29 namespace media { |
24 enum class MediaContentType; | 30 enum class MediaContentType; |
25 } // namespace media | 31 } // namespace media |
26 | 32 |
27 namespace content { | 33 namespace content { |
28 | 34 |
29 class AudioFocusDelegate; | 35 class AudioFocusDelegate; |
30 class AudioFocusManagerTest; | 36 class AudioFocusManagerTest; |
31 class MediaSessionPlayerObserver; | 37 class MediaSessionPlayerObserver; |
38 class MediaSessionServiceImpl; | |
32 class MediaSessionStateObserver; | 39 class MediaSessionStateObserver; |
33 class MediaSessionVisibilityBrowserTest; | 40 class MediaSessionVisibilityBrowserTest; |
34 | 41 |
35 // MediaSession manages the media session and audio focus for a given | 42 // MediaSession manages the media session and audio focus for a given |
36 // WebContents. It is requesting the audio focus, pausing when requested by the | 43 // WebContents. It is requesting the audio focus, pausing when requested by the |
37 // system and dropping it on demand. | 44 // system and dropping it on demand. |
38 // The audio focus can be of two types: Transient or Content. A Transient audio | 45 // The audio focus can be of two types: Transient or Content. A Transient audio |
39 // focus will allow other players to duck instead of pausing and will be | 46 // focus will allow other players to duck instead of pausing and will be |
40 // declared as temporary to the system. A Content audio focus will not be | 47 // declared as temporary to the system. A Content audio focus will not be |
41 // declared as temporary and will not allow other players to duck. If a given | 48 // declared as temporary and will not allow other players to duck. If a given |
42 // WebContents can only have one audio focus at a time, it will be Content in | 49 // WebContents can only have one audio focus at a time, it will be Content in |
43 // case of Transient and Content audio focus are both requested. | 50 // case of Transient and Content audio focus are both requested. |
44 // TODO(thakis,mlamouri): MediaSession isn't CONTENT_EXPORT'd because it creates | 51 // TODO(thakis,mlamouri): MediaSession isn't CONTENT_EXPORT'd because it creates |
45 // complicated build issues with WebContentsUserData being a non-exported | 52 // complicated build issues with WebContentsUserData being a non-exported |
46 // template, see htttps://crbug.com/589840. As a result, the class uses | 53 // template, see htttps://crbug.com/589840. As a result, the class uses |
47 // CONTENT_EXPORT for methods that are being used from tests. CONTENT_EXPORT | 54 // CONTENT_EXPORT for methods that are being used from tests. CONTENT_EXPORT |
48 // should be moved back to the class when the Windows build will work with it. | 55 // should be moved back to the class when the Windows build will work with it. |
49 class MediaSession : public WebContentsObserver, | 56 class MediaSession : public WebContentsObserver, |
whywhat
2016/10/24 21:01:25
hm, how does this relate to the MediaSession to Me
Zhiqiang Zhang (Slow)
2016/10/25 10:46:55
It's totally separate. Depending on which one is l
| |
50 protected WebContentsUserData<MediaSession> { | 57 protected WebContentsUserData<MediaSession> { |
51 public: | 58 public: |
52 enum class SuspendType { | 59 enum class SuspendType { |
53 // Suspended by the system because a transient sound needs to be played. | 60 // Suspended by the system because a transient sound needs to be played. |
54 SYSTEM, | 61 SYSTEM, |
55 // Suspended by the UI. | 62 // Suspended by the UI. |
56 UI, | 63 UI, |
57 // Suspended by the page via script or user interaction. | 64 // Suspended by the page via script or user interaction. |
58 CONTENT, | 65 CONTENT, |
59 }; | 66 }; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 CONTENT_EXPORT void Resume(SuspendType suspend_type); | 111 CONTENT_EXPORT void Resume(SuspendType suspend_type); |
105 | 112 |
106 // Suspend the media session. | 113 // Suspend the media session. |
107 // |type| represents the origin of the request. | 114 // |type| represents the origin of the request. |
108 CONTENT_EXPORT void Suspend(SuspendType suspend_type); | 115 CONTENT_EXPORT void Suspend(SuspendType suspend_type); |
109 | 116 |
110 // Stop the media session. | 117 // Stop the media session. |
111 // |type| represents the origin of the request. | 118 // |type| represents the origin of the request. |
112 CONTENT_EXPORT void Stop(SuspendType suspend_type); | 119 CONTENT_EXPORT void Stop(SuspendType suspend_type); |
113 | 120 |
121 // Called when an action is enabled in blink::MediaSession and notify | |
whywhat
2016/10/24 21:01:26
nit: "Called ... and notify ..." is not a valid sy
Zhiqiang Zhang (Slow)
2016/10/25 10:46:55
Done.
| |
122 // observers. | |
123 void OnMediaSessionEnabledAction(blink::mojom::MediaSessionAction action); | |
124 | |
125 // Called when an action is disabled in blink::MediaSession and notify | |
whywhat
2016/10/24 21:01:26
ditto
Zhiqiang Zhang (Slow)
2016/10/25 10:46:55
Done.
| |
126 // observers. | |
127 void OnMediaSessionDisabledAction(blink::mojom::MediaSessionAction action); | |
128 | |
129 // Received a media session action and forward to blink::MediaSession. | |
130 void DidReceiveAction(blink::mojom::MediaSessionAction action); | |
131 | |
114 // 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 |
115 // reduced. | 133 // reduced. |
116 CONTENT_EXPORT void StartDucking(); | 134 CONTENT_EXPORT void StartDucking(); |
117 | 135 |
118 // 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 |
119 // recovered. | 137 // recovered. |
120 CONTENT_EXPORT void StopDucking(); | 138 CONTENT_EXPORT void StopDucking(); |
121 | 139 |
122 // 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 |
123 // above. | 141 // above. |
(...skipping 17 matching lines...) Expand all Loading... | |
141 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type() const { | 159 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type() const { |
142 return audio_focus_type_; | 160 return audio_focus_type_; |
143 } | 161 } |
144 | 162 |
145 // Returns whether the session has Pepper instances. | 163 // Returns whether the session has Pepper instances. |
146 bool HasPepper() const; | 164 bool HasPepper() const; |
147 | 165 |
148 // WebContentsObserver implementation | 166 // WebContentsObserver implementation |
149 void WebContentsDestroyed() override; | 167 void WebContentsDestroyed() override; |
150 | 168 |
169 void SetMediaSessionService(MediaSessionServiceImpl* service); | |
170 | |
151 private: | 171 private: |
152 friend class content::WebContentsUserData<MediaSession>; | 172 friend class content::WebContentsUserData<MediaSession>; |
153 friend class ::MediaSessionBrowserTest; | 173 friend class ::MediaSessionBrowserTest; |
154 friend class content::MediaSessionVisibilityBrowserTest; | 174 friend class content::MediaSessionVisibilityBrowserTest; |
155 friend class content::AudioFocusManagerTest; | 175 friend class content::AudioFocusManagerTest; |
156 friend class content::MediaSessionStateObserver; | 176 friend class content::MediaSessionStateObserver; |
157 | 177 |
158 CONTENT_EXPORT void SetDelegateForTests( | 178 CONTENT_EXPORT void SetDelegateForTests( |
159 std::unique_ptr<AudioFocusDelegate> delegate); | 179 std::unique_ptr<AudioFocusDelegate> delegate); |
160 CONTENT_EXPORT bool IsActiveForTest() const; | 180 CONTENT_EXPORT bool IsActiveForTest() const; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 MediaSessionUmaHelper uma_helper_; | 250 MediaSessionUmaHelper uma_helper_; |
231 | 251 |
232 // The ducking state of this media session. The initial value is |false|, and | 252 // The ducking state of this media session. The initial value is |false|, and |
233 // is set to |true| after StartDucking(), and will be set to |false| after | 253 // is set to |true| after StartDucking(), and will be set to |false| after |
234 // StopDucking(). | 254 // StopDucking(). |
235 bool is_ducking_; | 255 bool is_ducking_; |
236 | 256 |
237 base::Optional<MediaMetadata> metadata_; | 257 base::Optional<MediaMetadata> metadata_; |
238 base::CallbackList<void(State)> media_session_state_listeners_; | 258 base::CallbackList<void(State)> media_session_state_listeners_; |
239 | 259 |
260 // The MediaSessionService this session is associated with (the service of the | |
261 // top-level frame). | |
262 MediaSessionServiceImpl* service_; | |
263 | |
240 DISALLOW_COPY_AND_ASSIGN(MediaSession); | 264 DISALLOW_COPY_AND_ASSIGN(MediaSession); |
241 }; | 265 }; |
242 | 266 |
243 } // namespace content | 267 } // namespace content |
244 | 268 |
245 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ | 269 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ |
OLD | NEW |