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

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

Issue 2274873003: Letting Flash join MediaSession (stack implementaion) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@media_session_type
Patch Set: tuned some behavior details and addressed Anton's comments (Left some comments here) Created 4 years, 3 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"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // Suspended by the page via script or user interaction. 56 // Suspended by the page via script or user interaction.
57 CONTENT, 57 CONTENT,
58 }; 58 };
59 59
60 // Returns the MediaSession associated to this WebContents. Creates one if 60 // Returns the MediaSession associated to this WebContents. Creates one if
61 // none is currently available. 61 // none is currently available.
62 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents); 62 CONTENT_EXPORT static MediaSession* Get(WebContents* web_contents);
63 63
64 ~MediaSession() override; 64 ~MediaSession() override;
65 65
66 void WasShown() override;
67
66 void SetMetadata(const MediaMetadata& metadata); 68 void SetMetadata(const MediaMetadata& metadata);
67 const MediaMetadata& metadata() const { return metadata_; } 69 const MediaMetadata& metadata() const { return metadata_; }
68 70
69 // Adds the given player to the current media session. Returns whether the 71 // Adds the given player to the current media session. Returns whether the
70 // player was successfully added. If it returns false, AddPlayer() should be 72 // player was successfully added. If it returns false, AddPlayer() should be
71 // called again later. 73 // called again later.
72 CONTENT_EXPORT bool AddPlayer(MediaSessionObserver* observer, 74 CONTENT_EXPORT bool AddPlayer(MediaSessionObserver* observer,
73 int player_id, 75 int player_id,
74 media::MediaContentType media_content_type); 76 media::MediaContentType media_content_type);
75 77
(...skipping 28 matching lines...) Expand all
104 CONTENT_EXPORT void Stop(SuspendType suspend_type); 106 CONTENT_EXPORT void Stop(SuspendType suspend_type);
105 107
106 // Let the media session start ducking such that the volume multiplier is 108 // Let the media session start ducking such that the volume multiplier is
107 // reduced. 109 // reduced.
108 CONTENT_EXPORT void StartDucking(); 110 CONTENT_EXPORT void StartDucking();
109 111
110 // Let the media session stop ducking such that the volume multiplier is 112 // Let the media session stop ducking such that the volume multiplier is
111 // recovered. 113 // recovered.
112 CONTENT_EXPORT void StopDucking(); 114 CONTENT_EXPORT void StopDucking();
113 115
116 CONTENT_EXPORT bool IsDucking() { return is_ducking_; }
117
114 // Returns if the session can be controlled by Resume() and Suspend calls 118 // Returns if the session can be controlled by Resume() and Suspend calls
115 // above. 119 // above.
116 CONTENT_EXPORT bool IsControllable() const; 120 CONTENT_EXPORT bool IsControllable() const;
117 121
118 // Returns if the session is currently active. 122 // Returns if the session is currently active.
119 CONTENT_EXPORT bool IsActive() const; 123 CONTENT_EXPORT bool IsActive() const;
120 124
121 // Returns if the session is currently suspended. 125 // Returns if the session is currently suspended.
122 // TODO(mlamouri): IsSuspended() below checks if the state is not ACTIVE 126 // TODO(mlamouri): IsSuspended() below checks if the state is not ACTIVE
123 // instead of checking if the state is SUSPENDED. In order to not have to 127 // instead of checking if the state is SUSPENDED. In order to not have to
124 // change all the callers and make the current refactoring ridiculously huge, 128 // change all the callers and make the current refactoring ridiculously huge,
125 // this method is introduced temporarily and will be removed later. 129 // this method is introduced temporarily and will be removed later.
126 bool IsReallySuspended() const; 130 bool IsReallySuspended() const;
127 131
128 // Returns if the session is currently suspended or inactive. 132 // Returns if the session is currently suspended or inactive.
129 CONTENT_EXPORT bool IsSuspended() const; 133 CONTENT_EXPORT bool IsSuspended() const;
130 134
135 void AllowPepperOverrideDucking();
136 void DisallowPepperOverrideDucking();
137
138 bool HasPepper() const;
139
131 private: 140 private:
132 friend class content::WebContentsUserData<MediaSession>; 141 friend class content::WebContentsUserData<MediaSession>;
133 friend class ::MediaSessionBrowserTest; 142 friend class ::MediaSessionBrowserTest;
134 friend class content::MediaSessionVisibilityBrowserTest; 143 friend class content::MediaSessionVisibilityBrowserTest;
135 friend class content::AudioFocusManagerTest; 144 friend class content::AudioFocusManagerTest;
136 friend class content::MediaSessionStateObserver; 145 friend class content::MediaSessionStateObserver;
137 146
138 CONTENT_EXPORT void SetDelegateForTests( 147 CONTENT_EXPORT void SetDelegateForTests(
139 std::unique_ptr<MediaSessionDelegate> delegate); 148 std::unique_ptr<MediaSessionDelegate> delegate);
140 CONTENT_EXPORT bool IsActiveForTest() const; 149 CONTENT_EXPORT bool IsActiveForTest() const;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // Internal method that should be used instead of setting audio_focus_state_. 200 // Internal method that should be used instead of setting audio_focus_state_.
192 // It sets audio_focus_state_ and notifies observers about the state change. 201 // It sets audio_focus_state_ and notifies observers about the state change.
193 void SetAudioFocusState(State audio_focus_state); 202 void SetAudioFocusState(State audio_focus_state);
194 203
195 // Update the volume multiplier when ducking state changes. 204 // Update the volume multiplier when ducking state changes.
196 void UpdateVolumeMultiplier(); 205 void UpdateVolumeMultiplier();
197 206
198 // Get the volume multiplier, which depends on whether the media session is 207 // Get the volume multiplier, which depends on whether the media session is
199 // ducking. 208 // ducking.
200 double GetVolumeMultiplier() const; 209 double GetVolumeMultiplier() const;
210 double GetPepperVolumeMultiplier() const;
201 211
202 // Registers a MediaSession state change callback. 212 // Registers a MediaSession state change callback.
203 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription> 213 CONTENT_EXPORT std::unique_ptr<base::CallbackList<void(State)>::Subscription>
204 RegisterMediaSessionStateChangedCallbackForTest( 214 RegisterMediaSessionStateChangedCallbackForTest(
205 const StateChangedCallback& cb); 215 const StateChangedCallback& cb);
206 216
217 CONTENT_EXPORT bool AddPepperPlayer(MediaSessionObserver* observer,
218 int player_id);
219
207 std::unique_ptr<MediaSessionDelegate> delegate_; 220 std::unique_ptr<MediaSessionDelegate> delegate_;
208 PlayersMap players_; 221 PlayersMap players_;
222 PlayersMap pepper_players_;
209 223
210 State audio_focus_state_; 224 State audio_focus_state_;
211 SuspendType suspend_type_; 225 SuspendType suspend_type_;
212 AudioFocusManager::AudioFocusType audio_focus_type_; 226 AudioFocusManager::AudioFocusType audio_focus_type_;
213 227
214 MediaSessionUmaHelper uma_helper_; 228 MediaSessionUmaHelper uma_helper_;
215 229
216 // The ducking state of this media session. The initial value is |false|, and 230 // The ducking state of this media session. The initial value is |false|, and
217 // is set to |true| after StartDucking(), and will be set to |false| after 231 // is set to |true| after StartDucking(), and will be set to |false| after
218 // StopDucking(). 232 // StopDucking().
219 bool is_ducking_; 233 bool is_ducking_;
234 // Whether allow pepper to override ducking (play in full volume) when the
235 // session is not active.
236 bool allow_pepper_override_ducking_;
220 237
221 MediaMetadata metadata_; 238 MediaMetadata metadata_;
222 base::CallbackList<void(State)> media_session_state_listeners_; 239 base::CallbackList<void(State)> media_session_state_listeners_;
223 240
224 DISALLOW_COPY_AND_ASSIGN(MediaSession); 241 DISALLOW_COPY_AND_ASSIGN(MediaSession);
225 }; 242 };
226 243
227 } // namespace content 244 } // namespace content
228 245
229 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_ 246 #endif // CONTENT_BROWSER_MEDIA_SESSION_MEDIA_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698