Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Side by Side Diff: content/browser/media/session/media_session.h

Issue 1996043002: Split MediaContentType and AudioFocusType (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed desktop build & tests Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/browser/media/session/media_session_uma_helper.h" 13 #include "content/browser/media/session/media_session_uma_helper.h"
14 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
15 #include "content/public/browser/web_contents_observer.h" 15 #include "content/public/browser/web_contents_observer.h"
16 #include "content/public/browser/web_contents_user_data.h" 16 #include "content/public/browser/web_contents_user_data.h"
17 #include "content/public/common/media_metadata.h" 17 #include "content/public/common/media_metadata.h"
18 18
19 class MediaSessionBrowserTest; 19 class MediaSessionBrowserTest;
20 20
21 namespace media {
22
23 enum class MediaContentType;
24
25 }
26
21 namespace content { 27 namespace content {
22 28
23 class MediaSessionDelegate; 29 class MediaSessionDelegate;
24 class MediaSessionObserver; 30 class MediaSessionObserver;
25 class MediaSessionStateObserver; 31 class MediaSessionStateObserver;
26 class MediaSessionVisibilityBrowserTest; 32 class MediaSessionVisibilityBrowserTest;
27 33
28 // MediaSession manages the media session and audio focus for a given 34 // MediaSession manages the media session and audio focus for a given
29 // WebContents. It is requesting the audio focus, pausing when requested by the 35 // WebContents. It is requesting the audio focus, pausing when requested by the
30 // system and dropping it on demand. 36 // system and dropping it on demand.
31 // The audio focus can be of two types: Transient or Content. A Transient audio 37 // The audio focus can be of two types: Transient or Content. A Transient audio
32 // focus will allow other players to duck instead of pausing and will be 38 // focus will allow other players to duck instead of pausing and will be
33 // declared as temporary to the system. A Content audio focus will not be 39 // declared as temporary to the system. A Content audio focus will not be
34 // declared as temporary and will not allow other players to duck. If a given 40 // declared as temporary and will not allow other players to duck. If a given
35 // WebContents can only have one audio focus at a time, it will be Content in 41 // WebContents can only have one audio focus at a time, it will be Content in
36 // case of Transient and Content audio focus are both requested. 42 // case of Transient and Content audio focus are both requested.
37 // TODO(thakis,mlamouri): MediaSession isn't CONTENT_EXPORT'd because it creates 43 // TODO(thakis,mlamouri): MediaSession isn't CONTENT_EXPORT'd because it creates
38 // complicated build issues with WebContentsUserData being a non-exported 44 // complicated build issues with WebContentsUserData being a non-exported
39 // template, see htttps://crbug.com/589840. As a result, the class uses 45 // template, see htttps://crbug.com/589840. As a result, the class uses
40 // CONTENT_EXPORT for methods that are being used from tests. CONTENT_EXPORT 46 // CONTENT_EXPORT for methods that are being used from tests. CONTENT_EXPORT
41 // should be moved back to the class when the Windows build will work with it. 47 // should be moved back to the class when the Windows build will work with it.
42 class MediaSession : public WebContentsObserver, 48 class MediaSession : public WebContentsObserver,
43 protected WebContentsUserData<MediaSession> { 49 protected WebContentsUserData<MediaSession> {
44 public: 50 public:
45 enum class Type {
46 Content,
47 Transient
48 };
49
50 enum class SuspendType { 51 enum class SuspendType {
51 // Suspended by the system because a transient sound needs to be played. 52 // Suspended by the system because a transient sound needs to be played.
52 SYSTEM, 53 SYSTEM,
53 // Suspended by the UI. 54 // Suspended by the UI.
54 UI, 55 UI,
55 // Suspended by the page via script or user interaction. 56 // Suspended by the page via script or user interaction.
56 CONTENT, 57 CONTENT,
57 }; 58 };
58 59
60 enum class AudioFocusType {
61 Content,
62 Transient
63 };
mlamouri (slow - plz ping) 2016/08/18 14:33:15 Maybe re-use AudioFocusType from audio_focus_manag
Zhiqiang Zhang (Slow) 2016/08/18 17:31:45 This is also my idea when you were preparing Audio
64
59 // Returns the MediaSession associated to this WebContents. Creates one if 65 // Returns the MediaSession associated to this WebContents. Creates one if
60 // none is currently available. 66 // none is currently available.
61 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); 67 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents);
62 68
63 ~MediaSession() override; 69 ~MediaSession() override;
64 70
65 void SetMetadata(const MediaMetadata& metadata); 71 void SetMetadata(const MediaMetadata& metadata);
66 const MediaMetadata& metadata() const { return metadata_; } 72 const MediaMetadata& metadata() const { return metadata_; }
67 73
68 // Adds the given player to the current media session. Returns whether the 74 // Adds the given player to the current media session. Returns whether the
69 // player was successfully added. If it returns false, AddPlayer() should be 75 // player was successfully added. If it returns false, AddPlayer() should be
70 // called again later. 76 // called again later.
71 CONTENT_EXPORT bool AddPlayer(MediaSessionObserver* observer, 77 CONTENT_EXPORT bool AddPlayer(MediaSessionObserver* observer,
72 int player_id, Type type); 78 int player_id, media::MediaContentType type);
73 79
74 // Removes the given player from the current media session. Abandons audio 80 // Removes the given player from the current media session. Abandons audio
75 // focus if that was the last player in the session. 81 // focus if that was the last player in the session.
76 CONTENT_EXPORT void RemovePlayer(MediaSessionObserver* observer, 82 CONTENT_EXPORT void RemovePlayer(MediaSessionObserver* observer,
77 int player_id); 83 int player_id);
78 84
79 // Removes all the players associated with |observer|. Abandons audio focus if 85 // Removes all the players associated with |observer|. Abandons audio focus if
80 // these were the last players in the session. 86 // these were the last players in the session.
81 CONTENT_EXPORT void RemovePlayers(MediaSessionObserver* observer); 87 CONTENT_EXPORT void RemovePlayers(MediaSessionObserver* observer);
82 88
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 129
124 private: 130 private:
125 friend class content::WebContentsUserData<MediaSession>; 131 friend class content::WebContentsUserData<MediaSession>;
126 friend class ::MediaSessionBrowserTest; 132 friend class ::MediaSessionBrowserTest;
127 friend class content::MediaSessionVisibilityBrowserTest; 133 friend class content::MediaSessionVisibilityBrowserTest;
128 friend class content::MediaSessionStateObserver; 134 friend class content::MediaSessionStateObserver;
129 135
130 CONTENT_EXPORT void SetDelegateForTests( 136 CONTENT_EXPORT void SetDelegateForTests(
131 std::unique_ptr<MediaSessionDelegate> delegate); 137 std::unique_ptr<MediaSessionDelegate> delegate);
132 CONTENT_EXPORT bool IsActiveForTest() const; 138 CONTENT_EXPORT bool IsActiveForTest() const;
133 CONTENT_EXPORT Type audio_focus_type_for_test() const; 139 CONTENT_EXPORT AudioFocusType audio_focus_type_for_test() const;
134 CONTENT_EXPORT void RemoveAllPlayersForTest(); 140 CONTENT_EXPORT void RemoveAllPlayersForTest();
135 CONTENT_EXPORT MediaSessionUmaHelper* uma_helper_for_test(); 141 CONTENT_EXPORT MediaSessionUmaHelper* uma_helper_for_test();
136 142
137 enum class State { 143 enum class State {
138 ACTIVE, 144 ACTIVE,
139 SUSPENDED, 145 SUSPENDED,
140 INACTIVE 146 INACTIVE
141 }; 147 };
142 148
143 // Representation of a player for the MediaSession. 149 // Representation of a player for the MediaSession.
(...skipping 17 matching lines...) Expand all
161 167
162 CONTENT_EXPORT explicit MediaSession(WebContents* web_contents); 168 CONTENT_EXPORT explicit MediaSession(WebContents* web_contents);
163 169
164 void Initialize(); 170 void Initialize();
165 171
166 CONTENT_EXPORT void OnSuspendInternal(SuspendType type, State new_state); 172 CONTENT_EXPORT void OnSuspendInternal(SuspendType type, State new_state);
167 CONTENT_EXPORT void OnResumeInternal(SuspendType type); 173 CONTENT_EXPORT void OnResumeInternal(SuspendType type);
168 174
169 // Requests audio focus to the MediaSessionDelegate. 175 // Requests audio focus to the MediaSessionDelegate.
170 // Returns whether the request was granted. 176 // Returns whether the request was granted.
171 bool RequestSystemAudioFocus(Type type); 177 bool RequestSystemAudioFocus(AudioFocusType type);
172 178
173 // To be called after a call to AbandonAudioFocus() in order request the 179 // To be called after a call to AbandonAudioFocus() in order request the
174 // delegate to abandon the audio focus. 180 // delegate to abandon the audio focus.
175 void AbandonSystemAudioFocusIfNeeded(); 181 void AbandonSystemAudioFocusIfNeeded();
176 182
177 // Notifies WebContents about the state change of the media session. 183 // Notifies WebContents about the state change of the media session.
178 void UpdateWebContents(); 184 void UpdateWebContents();
179 185
180 // Internal method that should be used instead of setting audio_focus_state_. 186 // Internal method that should be used instead of setting audio_focus_state_.
181 // It sets audio_focus_state_ and notifies observers about the state change. 187 // It sets audio_focus_state_ and notifies observers about the state change.
182 void SetAudioFocusState(State audio_focus_state); 188 void SetAudioFocusState(State audio_focus_state);
183 189
184 // Registers a MediaSession state change callback. 190 // Registers a MediaSession state change callback.
185 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription> 191 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription>
186 RegisterMediaSessionStateChangedCallbackForTest( 192 RegisterMediaSessionStateChangedCallbackForTest(
187 const StateChangedCallback& cb); 193 const StateChangedCallback& cb);
188 194
189 std::unique_ptr<MediaSessionDelegate> delegate_; 195 std::unique_ptr<MediaSessionDelegate> delegate_;
190 PlayersMap players_; 196 PlayersMap players_;
191 197
192 State audio_focus_state_; 198 State audio_focus_state_;
193 SuspendType suspend_type_; 199 SuspendType suspend_type_;
194 Type audio_focus_type_; 200 AudioFocusType audio_focus_type_;
195 201
196 MediaSessionUmaHelper uma_helper_; 202 MediaSessionUmaHelper uma_helper_;
197 203
198 // The volume multiplier of this session. All players in this session should 204 // The volume multiplier of this session. All players in this session should
199 // multiply their volume with this multiplier to get the effective volume. 205 // multiply their volume with this multiplier to get the effective volume.
200 double volume_multiplier_; 206 double volume_multiplier_;
201 207
202 MediaMetadata metadata_; 208 MediaMetadata metadata_;
203 base::CallbackList<void(State)> media_session_state_listeners_; 209 base::CallbackList<void(State)> media_session_state_listeners_;
204 210
205 DISALLOW_COPY_AND_ASSIGN(MediaSession); 211 DISALLOW_COPY_AND_ASSIGN(MediaSession);
206 }; 212 };
207 213
208 } // namespace content 214 } // namespace content
209 215
210 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ 216 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698