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

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host.h

Issue 2578983003: Add AudioStreamRegistry. Move stream counting logic (Closed)
Patch Set: Thread checking. Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // AudioRendererHost serves audio related requests from AudioRenderer which 5 // AudioRendererHost serves audio related requests from AudioRenderer which
6 // lives inside the render process and provide access to audio hardware. 6 // lives inside the render process and provide access to audio hardware.
7 // 7 //
8 // This class is owned by RenderProcessHostImpl, and instantiated on UI 8 // This class is owned by RenderProcessHostImpl, and instantiated on UI
9 // thread, but all other operations and method calls happen on IO thread, so we 9 // thread, but all other operations and method calls happen on IO thread, so we
10 // need to be extra careful about the lifetime of this object. AudioManager is a 10 // need to be extra careful about the lifetime of this object. AudioManager is a
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 59
60 namespace media { 60 namespace media {
61 class AudioManager; 61 class AudioManager;
62 class AudioParameters; 62 class AudioParameters;
63 } 63 }
64 64
65 namespace content { 65 namespace content {
66 66
67 class AudioMirroringManager; 67 class AudioMirroringManager;
68 class AudioStreamRegistry;
68 class MediaStreamManager; 69 class MediaStreamManager;
69 70
70 class CONTENT_EXPORT AudioRendererHost 71 class CONTENT_EXPORT AudioRendererHost
71 : public BrowserMessageFilter, 72 : public BrowserMessageFilter,
72 public AudioOutputDelegate::EventHandler { 73 public AudioOutputDelegate::EventHandler {
73 public: 74 public:
74 // Called from UI thread from the owner of this object. 75 // Called from UI thread from the owner of this object.
75 AudioRendererHost(int render_process_id, 76 AudioRendererHost(int render_process_id,
77 AudioStreamRegistry* stream_registry,
76 media::AudioManager* audio_manager, 78 media::AudioManager* audio_manager,
77 AudioMirroringManager* mirroring_manager, 79 AudioMirroringManager* mirroring_manager,
78 MediaStreamManager* media_stream_manager, 80 MediaStreamManager* media_stream_manager,
79 const std::string& salt); 81 const std::string& salt);
80 82
81 // Calls |callback| with the list of AudioOutputControllers for this object. 83 // Calls |callback| with the list of AudioOutputControllers for this object.
82 void GetOutputControllers( 84 void GetOutputControllers(
83 const RenderProcessHost::GetAudioOutputControllersCallback& 85 const RenderProcessHost::GetAudioOutputControllersCallback&
84 callback) const; 86 callback) const;
85 87
86 // BrowserMessageFilter implementation. 88 // BrowserMessageFilter implementation.
87 void OnChannelClosing() override; 89 void OnChannelClosing() override;
88 void OnDestruct() const override; 90 void OnDestruct() const override;
89 bool OnMessageReceived(const IPC::Message& message) override; 91 bool OnMessageReceived(const IPC::Message& message) override;
90 92
91 // AudioOutputDelegate::EventHandler implementation 93 // AudioOutputDelegate::EventHandler implementation
92 void OnStreamCreated(int stream_id, 94 void OnStreamCreated(int stream_id,
93 base::SharedMemory* shared_memory, 95 base::SharedMemory* shared_memory,
94 base::CancelableSyncSocket* foreign_socket) override; 96 base::CancelableSyncSocket* foreign_socket) override;
95 void OnStreamError(int stream_id) override; 97 void OnStreamError(int stream_id) override;
96 void OnStreamStateChanged(bool is_playing) override;
97 98
98 // Returns true if any streams managed by this host are actively playing. Can 99 // Returns true if any streams managed by this host are actively playing. Can
99 // be called from any thread. 100 // be called from any thread.
100 bool HasActiveAudio(); 101 bool HasActiveAudio();
101 102
102 void OverrideDevicePermissionsForTesting(bool has_access); 103 void OverrideDevicePermissionsForTesting(bool has_access);
103 104
104 private: 105 private:
105 friend class AudioRendererHostTest; 106 friend class AudioRendererHostTest;
106 friend class BrowserThread; 107 friend class BrowserThread;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 171
171 // Set the volume of the audio stream referenced by |stream_id|. 172 // Set the volume of the audio stream referenced by |stream_id|.
172 void OnSetVolume(int stream_id, double volume); 173 void OnSetVolume(int stream_id, double volume);
173 174
174 // Helper methods. 175 // Helper methods.
175 176
176 // Called after the |render_frame_id| provided to OnCreateStream() was 177 // Called after the |render_frame_id| provided to OnCreateStream() was
177 // validated. When |is_valid| is false, this calls OnStreamError(). 178 // validated. When |is_valid| is false, this calls OnStreamError().
178 void DidValidateRenderFrame(int stream_id, bool is_valid); 179 void DidValidateRenderFrame(int stream_id, bool is_valid);
179 180
180 // Updates status of stream for AudioStreamMonitor and updates
181 // the number of playing streams.
182 void StreamStateChanged(int stream_id, bool is_playing);
183
184 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; 181 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const;
185 182
186 // Send an error message to the renderer. 183 // Send an error message to the renderer.
187 void SendErrorMessage(int stream_id); 184 void SendErrorMessage(int stream_id);
188 185
189 // Helper methods to look up a AudioOutputDelegate identified by |stream_id|. 186 // Helper methods to look up a AudioOutputDelegate identified by |stream_id|.
190 // Returns delegates_.end() if not found. 187 // Returns delegates_.end() if not found.
191 AudioOutputDelegateVector::iterator LookupIteratorById(int stream_id); 188 AudioOutputDelegateVector::iterator LookupIteratorById(int stream_id);
192 // Returns nullptr if not found. 189 // Returns nullptr if not found.
193 AudioOutputDelegate* LookupById(int stream_id); 190 AudioOutputDelegate* LookupById(int stream_id);
194 191
195 // Helper method to check if the authorization procedure for stream 192 // Helper method to check if the authorization procedure for stream
196 // |stream_id| has started. 193 // |stream_id| has started.
197 bool IsAuthorizationStarted(int stream_id); 194 bool IsAuthorizationStarted(int stream_id);
198 195
199 // Called from AudioRendererHostTest to override the function that checks for 196 // Called from AudioRendererHostTest to override the function that checks for
200 // the existence of the RenderFrameHost at stream creation time. 197 // the existence of the RenderFrameHost at stream creation time.
201 void set_render_frame_id_validate_function_for_testing( 198 void set_render_frame_id_validate_function_for_testing(
202 ValidateRenderFrameIdFunction function) { 199 ValidateRenderFrameIdFunction function) {
203 validate_render_frame_id_function_ = function; 200 validate_render_frame_id_function_ = function;
204 } 201 }
205 202
206 // ID of the RenderProcessHost that owns this instance. 203 // ID of the RenderProcessHost that owns this instance.
207 const int render_process_id_; 204 const int render_process_id_;
208 205
206 AudioStreamRegistry* stream_registry_;
209 media::AudioManager* const audio_manager_; 207 media::AudioManager* const audio_manager_;
210 AudioMirroringManager* const mirroring_manager_; 208 AudioMirroringManager* const mirroring_manager_;
211 209
212 // Used to access to AudioInputDeviceManager. 210 // Used to access to AudioInputDeviceManager.
213 MediaStreamManager* media_stream_manager_; 211 MediaStreamManager* media_stream_manager_;
214 212
215 // A list of the current open streams. 213 // A list of the current open streams.
216 AudioOutputDelegateVector delegates_; 214 AudioOutputDelegateVector delegates_;
217 215
218 // The number of streams in the playing state. Atomic read safe from any
219 // thread, but should only be updated from the IO thread.
220 base::AtomicRefCount num_playing_streams_;
221
222 // Salt required to translate renderer device IDs to raw device unique IDs 216 // Salt required to translate renderer device IDs to raw device unique IDs
223 std::string salt_; 217 std::string salt_;
224 218
225 // Map of device authorizations for streams that are not yet created 219 // Map of device authorizations for streams that are not yet created
226 // The key is the stream ID, and the value is a pair. The pair's first element 220 // The key is the stream ID, and the value is a pair. The pair's first element
227 // is a bool that is true if the authorization process completes successfully. 221 // is a bool that is true if the authorization process completes successfully.
228 // The second element contains the unique ID of the authorized device. 222 // The second element contains the unique ID of the authorized device.
229 std::map<int, std::pair<bool, std::string>> authorizations_; 223 std::map<int, std::pair<bool, std::string>> authorizations_;
230 224
231 // At stream creation time, AudioRendererHost will call this function on the 225 // At stream creation time, AudioRendererHost will call this function on the
232 // UI thread to validate render frame IDs. A default is set by the 226 // UI thread to validate render frame IDs. A default is set by the
233 // constructor, but this can be overridden by unit tests. 227 // constructor, but this can be overridden by unit tests.
234 ValidateRenderFrameIdFunction validate_render_frame_id_function_; 228 ValidateRenderFrameIdFunction validate_render_frame_id_function_;
235 229
236 // The maximum number of simultaneous streams during the lifetime of this
237 // host. Reported as UMA stat at shutdown.
238 size_t max_simultaneous_streams_;
239
240 AudioOutputAuthorizationHandler authorization_handler_; 230 AudioOutputAuthorizationHandler authorization_handler_;
241 231
242 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); 232 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost);
243 }; 233 };
244 234
245 } // namespace content 235 } // namespace content
246 236
247 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ 237 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698