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" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 public: | 51 public: |
52 enum class SuspendType { | 52 enum class SuspendType { |
53 // Suspended by the system because a transient sound needs to be played. | 53 // Suspended by the system because a transient sound needs to be played. |
54 SYSTEM, | 54 SYSTEM, |
55 // Suspended by the UI. | 55 // Suspended by the UI. |
56 UI, | 56 UI, |
57 // Suspended by the page via script or user interaction. | 57 // Suspended by the page via script or user interaction. |
58 CONTENT, | 58 CONTENT, |
59 }; | 59 }; |
60 | 60 |
61 // Only visible to tests. | |
62 enum class State { | |
63 ACTIVE, | |
64 SUSPENDED, | |
65 INACTIVE | |
66 }; | |
67 | |
61 // Returns the MediaSession associated to this WebContents. Creates one if | 68 // Returns the MediaSession associated to this WebContents. Creates one if |
62 // none is currently available. | 69 // none is currently available. |
63 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); | 70 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); |
64 | 71 |
65 ~MediaSession() override; | 72 ~MediaSession() override; |
66 | 73 |
74 void WasShown() override; | |
whywhat
2016/09/13 00:16:17
nit: unused.
Zhiqiang Zhang (Slow)
2016/09/22 12:30:33
Done.
| |
75 | |
67 void SetMetadata(const base::Optional<MediaMetadata>& metadata); | 76 void SetMetadata(const base::Optional<MediaMetadata>& metadata); |
68 const base::Optional<MediaMetadata>& metadata() const { return metadata_; } | 77 const base::Optional<MediaMetadata>& metadata() const { return metadata_; } |
69 | 78 |
70 // Adds the given player to the current media session. Returns whether the | 79 // Adds the given player to the current media session. Returns whether the |
71 // player was successfully added. If it returns false, AddPlayer() should be | 80 // player was successfully added. If it returns false, AddPlayer() should be |
72 // called again later. | 81 // called again later. |
73 CONTENT_EXPORT bool AddPlayer(MediaSessionObserver* observer, | 82 CONTENT_EXPORT bool AddPlayer(MediaSessionObserver* observer, |
74 int player_id, | 83 int player_id, |
75 media::MediaContentType media_content_type); | 84 media::MediaContentType media_content_type); |
76 | 85 |
(...skipping 28 matching lines...) Expand all Loading... | |
105 CONTENT_EXPORT void Stop(SuspendType suspend_type); | 114 CONTENT_EXPORT void Stop(SuspendType suspend_type); |
106 | 115 |
107 // Let the media session start ducking such that the volume multiplier is | 116 // Let the media session start ducking such that the volume multiplier is |
108 // reduced. | 117 // reduced. |
109 CONTENT_EXPORT void StartDucking(); | 118 CONTENT_EXPORT void StartDucking(); |
110 | 119 |
111 // Let the media session stop ducking such that the volume multiplier is | 120 // Let the media session stop ducking such that the volume multiplier is |
112 // recovered. | 121 // recovered. |
113 CONTENT_EXPORT void StopDucking(); | 122 CONTENT_EXPORT void StopDucking(); |
114 | 123 |
124 CONTENT_EXPORT bool IsDucking() { return is_ducking_; } | |
whywhat
2016/09/13 00:16:17
nit: ditto
Zhiqiang Zhang (Slow)
2016/09/22 12:30:33
Done.
| |
125 | |
115 // Returns if the session can be controlled by Resume() and Suspend calls | 126 // Returns if the session can be controlled by Resume() and Suspend calls |
116 // above. | 127 // above. |
117 CONTENT_EXPORT bool IsControllable() const; | 128 CONTENT_EXPORT bool IsControllable() const; |
118 | 129 |
119 // Returns if the session is currently active. | 130 // Returns if the session is currently active. |
120 CONTENT_EXPORT bool IsActive() const; | 131 CONTENT_EXPORT bool IsActive() const; |
121 | 132 |
122 // Returns if the session is currently suspended. | 133 // Returns if the session is currently suspended. |
123 // TODO(mlamouri): IsSuspended() below checks if the state is not ACTIVE | 134 // TODO(mlamouri): IsSuspended() below checks if the state is not ACTIVE |
124 // instead of checking if the state is SUSPENDED. In order to not have to | 135 // instead of checking if the state is SUSPENDED. In order to not have to |
125 // change all the callers and make the current refactoring ridiculously huge, | 136 // change all the callers and make the current refactoring ridiculously huge, |
126 // this method is introduced temporarily and will be removed later. | 137 // this method is introduced temporarily and will be removed later. |
127 bool IsReallySuspended() const; | 138 bool IsReallySuspended() const; |
128 | 139 |
129 // Returns if the session is currently suspended or inactive. | 140 // Returns if the session is currently suspended or inactive. |
130 CONTENT_EXPORT bool IsSuspended() const; | 141 CONTENT_EXPORT bool IsSuspended() const; |
131 | 142 |
143 void AllowPepperOverrideDucking(); | |
144 void DisallowPepperOverrideDucking(); | |
145 | |
146 bool HasPepper() const; | |
147 | |
132 private: | 148 private: |
133 friend class content::WebContentsUserData<MediaSession>; | 149 friend class content::WebContentsUserData<MediaSession>; |
134 friend class ::MediaSessionBrowserTest; | 150 friend class ::MediaSessionBrowserTest; |
135 friend class content::MediaSessionVisibilityBrowserTest; | 151 friend class content::MediaSessionVisibilityBrowserTest; |
136 friend class content::AudioFocusManagerTest; | 152 friend class content::AudioFocusManagerTest; |
137 friend class content::MediaSessionStateObserver; | 153 friend class content::MediaSessionStateObserver; |
138 | 154 |
139 CONTENT_EXPORT void SetDelegateForTests( | 155 CONTENT_EXPORT void SetDelegateForTests( |
140 std::unique_ptr<MediaSessionDelegate> delegate); | 156 std::unique_ptr<MediaSessionDelegate> delegate); |
141 CONTENT_EXPORT bool IsActiveForTest() const; | 157 CONTENT_EXPORT bool IsActiveForTest() const; |
142 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type_for_test() | 158 CONTENT_EXPORT AudioFocusManager::AudioFocusType audio_focus_type_for_test() |
143 const; | 159 const; |
144 CONTENT_EXPORT void RemoveAllPlayersForTest(); | 160 CONTENT_EXPORT void RemoveAllPlayersForTest(); |
145 CONTENT_EXPORT MediaSessionUmaHelper* uma_helper_for_test(); | 161 CONTENT_EXPORT MediaSessionUmaHelper* uma_helper_for_test(); |
146 | 162 |
147 enum class State { | |
148 ACTIVE, | |
149 SUSPENDED, | |
150 INACTIVE | |
151 }; | |
152 | |
153 // Representation of a player for the MediaSession. | 163 // Representation of a player for the MediaSession. |
154 struct PlayerIdentifier { | 164 struct PlayerIdentifier { |
155 PlayerIdentifier(MediaSessionObserver* observer, int player_id); | 165 PlayerIdentifier(MediaSessionObserver* observer, int player_id); |
156 PlayerIdentifier(const PlayerIdentifier&) = default; | 166 PlayerIdentifier(const PlayerIdentifier&) = default; |
157 | 167 |
158 void operator=(const PlayerIdentifier&) = delete; | 168 void operator=(const PlayerIdentifier&) = delete; |
159 bool operator==(const PlayerIdentifier& player_identifier) const; | 169 bool operator==(const PlayerIdentifier& player_identifier) const; |
160 | 170 |
161 // Hash operator for base::hash_map<>. | 171 // Hash operator for base::hash_map<>. |
162 struct Hash { | 172 struct Hash { |
(...skipping 29 matching lines...) Expand all Loading... | |
192 // Internal method that should be used instead of setting audio_focus_state_. | 202 // Internal method that should be used instead of setting audio_focus_state_. |
193 // It sets audio_focus_state_ and notifies observers about the state change. | 203 // It sets audio_focus_state_ and notifies observers about the state change. |
194 void SetAudioFocusState(State audio_focus_state); | 204 void SetAudioFocusState(State audio_focus_state); |
195 | 205 |
196 // Update the volume multiplier when ducking state changes. | 206 // Update the volume multiplier when ducking state changes. |
197 void UpdateVolumeMultiplier(); | 207 void UpdateVolumeMultiplier(); |
198 | 208 |
199 // Get the volume multiplier, which depends on whether the media session is | 209 // Get the volume multiplier, which depends on whether the media session is |
200 // ducking. | 210 // ducking. |
201 double GetVolumeMultiplier() const; | 211 double GetVolumeMultiplier() const; |
212 double GetPepperVolumeMultiplier() const; | |
202 | 213 |
203 // Registers a MediaSession state change callback. | 214 // Registers a MediaSession state change callback. |
204 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription> | 215 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription> |
205 RegisterMediaSessionStateChangedCallbackForTest( | 216 RegisterMediaSessionStateChangedCallbackForTest( |
206 const StateChangedCallback& cb); | 217 const StateChangedCallback& cb); |
207 | 218 |
219 CONTENT_EXPORT bool AddPepperPlayer(MediaSessionObserver* observer, | |
220 int player_id); | |
221 | |
208 std::unique_ptr<MediaSessionDelegate> delegate_; | 222 std::unique_ptr<MediaSessionDelegate> delegate_; |
209 PlayersMap players_; | 223 PlayersMap players_; |
224 PlayersMap pepper_players_; | |
210 | 225 |
211 State audio_focus_state_; | 226 State audio_focus_state_; |
212 SuspendType suspend_type_; | 227 SuspendType suspend_type_; |
213 AudioFocusManager::AudioFocusType audio_focus_type_; | 228 AudioFocusManager::AudioFocusType audio_focus_type_; |
214 | 229 |
215 MediaSessionUmaHelper uma_helper_; | 230 MediaSessionUmaHelper uma_helper_; |
216 | 231 |
217 // The ducking state of this media session. The initial value is |false|, and | 232 // The ducking state of this media session. The initial value is |false|, and |
218 // is set to |true| after StartDucking(), and will be set to |false| after | 233 // is set to |true| after StartDucking(), and will be set to |false| after |
219 // StopDucking(). | 234 // StopDucking(). |
220 bool is_ducking_; | 235 bool is_ducking_; |
236 // Whether allow pepper to override ducking (play in full volume) when the | |
237 // session is not active. | |
238 bool allow_pepper_override_ducking_; | |
221 | 239 |
222 base::Optional<MediaMetadata> metadata_; | 240 base::Optional<MediaMetadata> metadata_; |
223 base::CallbackList<void(State)> media_session_state_listeners_; | 241 base::CallbackList<void(State)> media_session_state_listeners_; |
224 | 242 |
225 DISALLOW_COPY_AND_ASSIGN(MediaSession); | 243 DISALLOW_COPY_AND_ASSIGN(MediaSession); |
226 }; | 244 }; |
227 | 245 |
228 } // namespace content | 246 } // namespace content |
229 | 247 |
230 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ | 248 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ |
OLD | NEW |