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

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

Issue 1930393002: Switch stream creation and closing in Chrome audio rendering from IPC to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use wrap Created 4 years, 7 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 (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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "url/origin.h" 66 #include "url/origin.h"
67 67
68 namespace media { 68 namespace media {
69 class AudioManager; 69 class AudioManager;
70 class AudioParameters; 70 class AudioParameters;
71 } 71 }
72 72
73 namespace content { 73 namespace content {
74 74
75 class AudioMirroringManager; 75 class AudioMirroringManager;
76 class AudioOutputImpl;
76 class MediaInternals; 77 class MediaInternals;
77 class MediaStreamManager; 78 class MediaStreamManager;
78 class MediaStreamUIProxy; 79 class MediaStreamUIProxy;
79 class ResourceContext; 80 class ResourceContext;
80 81
81 class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { 82 class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter {
82 public: 83 public:
83 // Called from UI thread from the owner of this object. 84 // Called from UI thread from the owner of this object.
84 AudioRendererHost(int render_process_id, 85 AudioRendererHost(int render_process_id,
85 media::AudioManager* audio_manager, 86 media::AudioManager* audio_manager,
86 AudioMirroringManager* mirroring_manager, 87 AudioMirroringManager* mirroring_manager,
87 MediaInternals* media_internals, 88 MediaInternals* media_internals,
88 MediaStreamManager* media_stream_manager, 89 MediaStreamManager* media_stream_manager,
89 const ResourceContext::SaltCallback& salt_callback); 90 const ResourceContext::SaltCallback& salt_callback);
90 91
92 // Creates an audio output stream with the specified format.
93 // Upon success/failure, the peer is notified via the NotifyStreamCreated
94 // message.
95 virtual void CreateStream(int stream_id,
96 int render_frame_id,
97 const media::AudioParameters& params,
98 AudioOutputImpl* audio_output_impl);
99
100 // Close the audio stream referenced by |stream_id|.
101 virtual void CloseStream(int stream_id);
102
91 // Calls |callback| with the list of AudioOutputControllers for this object. 103 // Calls |callback| with the list of AudioOutputControllers for this object.
92 void GetOutputControllers( 104 void GetOutputControllers(
93 const RenderProcessHost::GetAudioOutputControllersCallback& 105 const RenderProcessHost::GetAudioOutputControllersCallback&
94 callback) const; 106 callback) const;
107 media::AudioLog* get_audio_log() { return audio_log_.get(); }
95 108
96 // BrowserMessageFilter implementation. 109 // BrowserMessageFilter implementation.
97 void OnChannelClosing() override; 110 void OnChannelClosing() override;
98 void OnDestruct() const override; 111 void OnDestruct() const override;
99 bool OnMessageReceived(const IPC::Message& message) override; 112 bool OnMessageReceived(const IPC::Message& message) override;
100 113
101 // Returns true if any streams managed by this host are actively playing. Can 114 // Returns true if any streams managed by this host are actively playing. Can
102 // be called from any thread. 115 // be called from any thread.
103 bool HasActiveAudio(); 116 bool HasActiveAudio();
104 117
105 // Returns true if any streams managed by the RenderFrame identified by 118 // Returns true if any streams managed by the RenderFrame identified by
106 // |render_frame_id| are actively playing. Can be called from any thread. 119 // |render_frame_id| are actively playing. Can be called from any thread.
107 bool RenderFrameHasActiveAudio(int render_frame_id) const; 120 bool RenderFrameHasActiveAudio(int render_frame_id) const;
108 121
109 private: 122 private:
123 friend class AudioEntry;
124 friend class AudioOutputImplTest;
110 friend class AudioRendererHostTest; 125 friend class AudioRendererHostTest;
111 friend class BrowserThread; 126 friend class BrowserThread;
112 friend class base::DeleteHelper<AudioRendererHost>; 127 friend class base::DeleteHelper<AudioRendererHost>;
113 friend class MockAudioRendererHost; 128 friend class MockAudioRendererHost;
129 friend class MockAudioOutputAudioRendererHost;
130 friend class MockAudioOutputStreamAudioRendererHost;
114 friend class TestAudioRendererHost; 131 friend class TestAudioRendererHost;
132
115 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); 133 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream);
116 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); 134 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation);
117 135
118 class AudioEntry; 136 class AudioEntry;
119 typedef std::map<int, AudioEntry*> AudioEntryMap; 137 typedef std::map<int, AudioEntry*> AudioEntryMap;
120 138
121 // Internal callback type for access requests to output devices. 139 // Internal callback type for access requests to output devices.
122 // |have_access| is true only if there is permission to access the device. 140 // |have_access| is true only if there is permission to access the device.
123 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB; 141 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB;
124 142
(...skipping 17 matching lines...) Expand all
142 // |session_id| will be ignored and the given |device_id| and 160 // |session_id| will be ignored and the given |device_id| and
143 // |security_origin| will be used to select the output device. 161 // |security_origin| will be used to select the output device.
144 // Upon completion of the process, the peer is notified with the device output 162 // Upon completion of the process, the peer is notified with the device output
145 // parameters via the NotifyDeviceAuthorized message. 163 // parameters via the NotifyDeviceAuthorized message.
146 void OnRequestDeviceAuthorization(int stream_id, 164 void OnRequestDeviceAuthorization(int stream_id,
147 int render_frame_id, 165 int render_frame_id,
148 int session_id, 166 int session_id,
149 const std::string& device_id, 167 const std::string& device_id,
150 const url::Origin& security_origin); 168 const url::Origin& security_origin);
151 169
152 // Creates an audio output stream with the specified format.
153 // Upon success/failure, the peer is notified via the NotifyStreamCreated
154 // message.
155 void OnCreateStream(int stream_id,
156 int render_frame_id,
157 const media::AudioParameters& params);
158
159 // Play the audio stream referenced by |stream_id|. 170 // Play the audio stream referenced by |stream_id|.
160 void OnPlayStream(int stream_id); 171 void OnPlayStream(int stream_id);
161 172
162 // Pause the audio stream referenced by |stream_id|. 173 // Pause the audio stream referenced by |stream_id|.
163 void OnPauseStream(int stream_id); 174 void OnPauseStream(int stream_id);
164 175
165 // Close the audio stream referenced by |stream_id|.
166 void OnCloseStream(int stream_id);
167
168 // Set the volume of the audio stream referenced by |stream_id|. 176 // Set the volume of the audio stream referenced by |stream_id|.
169 void OnSetVolume(int stream_id, double volume); 177 void OnSetVolume(int stream_id, double volume);
170 178
171 // Helper methods. 179 // Helper methods.
172 180
173 // Proceed with device authorization after checking permissions. 181 // Proceed with device authorization after checking permissions.
174 void OnDeviceAuthorized(int stream_id, 182 void OnDeviceAuthorized(int stream_id,
175 const std::string& device_id, 183 const std::string& device_id,
176 const url::Origin& security_origin, 184 const url::Origin& security_origin,
177 bool have_access); 185 bool have_access);
178 186
179 // Proceed with device authorization after translating device ID. 187 // Proceed with device authorization after translating device ID.
180 void OnDeviceIDTranslated(int stream_id, 188 void OnDeviceIDTranslated(int stream_id,
181 bool device_found, 189 bool device_found,
182 const AudioOutputDeviceInfo& device_info); 190 const AudioOutputDeviceInfo& device_info);
183 191
184 // Start the actual creation of an audio stream, after the device 192 // Start the actual creation of an audio stream, after the device
185 // authorization process is complete. 193 // authorization process is complete.
186 void DoCreateStream(int stream_id, 194 virtual void DoCreateStream(int stream_id,
187 int render_frame_id, 195 int render_frame_id,
188 const media::AudioParameters& params, 196 const media::AudioParameters& params,
189 const std::string& device_unique_id); 197 const std::string& device_unique_id,
198 AudioOutputImpl* audio_output_impl);
190 199
191 // Complete the process of creating an audio stream. This will set up the 200 // Complete the process of creating an audio stream. This will set up the
192 // shared memory or shared socket in low latency mode and send the 201 // shared memory or shared socket in low latency mode and send the
193 // NotifyStreamCreated message to the peer. 202 // NotifyStreamCreated message to the peer.
194 void DoCompleteCreation(int stream_id); 203 virtual void DoCompleteCreation(int stream_id);
195 204
196 // Send playing/paused status to the renderer. 205 // Send playing/paused status to the renderer.
197 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); 206 void DoNotifyStreamStateChanged(int stream_id, bool is_playing);
198 207
199 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; 208 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const;
200 209
201 // Send an error message to the renderer. 210 // Send an error message to the renderer.
202 void SendErrorMessage(int stream_id); 211 void SendErrorMessage(int stream_id);
203 212
204 // Delete an audio entry, notifying observers first. This is called by 213 // Delete an audio entry, notifying observers first. This is called by
205 // AudioOutputController after it has closed. 214 // AudioOutputController after it has closed.
206 void DeleteEntry(std::unique_ptr<AudioEntry> entry); 215 void DeleteEntry(std::unique_ptr<AudioEntry> entry);
207 216
208 // Send an error message to the renderer, then close the stream. 217 // Send an error message to the client, then close the stream.
209 void ReportErrorAndClose(int stream_id); 218 void ReportErrorAndClose(int stream_id);
210 219
211 // A helper method to look up a AudioEntry identified by |stream_id|. 220 // A helper method to look up a AudioEntry identified by |stream_id|.
212 // Returns NULL if not found. 221 // Returns NULL if not found.
213 AudioEntry* LookupById(int stream_id); 222 AudioEntry* LookupById(int stream_id);
214 223
215 // A helper method to update the number of playing streams and alert the 224 // A helper method to update the number of playing streams and alert the
216 // ResourceScheduler when the renderer starts or stops playing an audiostream. 225 // ResourceScheduler when the renderer starts or stops playing an audiostream.
217 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); 226 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing);
218 227
219 // Check if the renderer process has access to the requested output device. 228 // Check if the renderer process has access to the requested output device.
220 void CheckOutputDeviceAccess(int render_frame_id, 229 void CheckOutputDeviceAccess(int render_frame_id,
221 const std::string& device_id, 230 const std::string& device_id,
222 const url::Origin& security_origin, 231 const url::Origin& security_origin,
223 const OutputDeviceAccessCB& callback); 232 const OutputDeviceAccessCB& callback);
224 233
225 // Invoke |callback| after permission to use a device has been checked. 234 // Invoke |callback| after permission to use a device has been checked.
226 void AccessChecked(std::unique_ptr<MediaStreamUIProxy> ui_proxy, 235 void AccessChecked(std::unique_ptr<MediaStreamUIProxy> ui_proxy,
227 const OutputDeviceAccessCB& callback, 236 const OutputDeviceAccessCB& callback,
228 bool have_access); 237 bool have_access);
229 238
230 // Translate the hashed |device_id| to a unique device ID. 239 // Translate the hashed |device_id| to a unique device ID.
231 void TranslateDeviceID(const std::string& device_id, 240 void TranslateDeviceID(const std::string& device_id,
232 const url::Origin& security_origin, 241 const url::Origin& security_origin,
233 const OutputDeviceInfoCB& callback, 242 const OutputDeviceInfoCB& callback,
234 const AudioOutputDeviceEnumeration& enumeration); 243 const AudioOutputDeviceEnumeration& enumeration);
235 244
236 // Helper method to check if the authorization procedure for stream 245 // Helper method to check if the authorization procedure for stream
237 // |stream_id| has started. 246 // |streaa_id| has started.
nasko 2016/05/25 20:50:42 stream?
rchtara 2016/05/27 15:24:39 Done.
238 bool IsAuthorizationStarted(int stream_id); 247 bool IsAuthorizationStarted(int stream_id);
239 248
240 // ID of the RenderProcessHost that owns this instance. 249 // ID of the RenderProcessHost that owns this instance.
241 const int render_process_id_; 250 const int render_process_id_;
242 251
243 media::AudioManager* const audio_manager_; 252 media::AudioManager* const audio_manager_;
244 AudioMirroringManager* const mirroring_manager_; 253 AudioMirroringManager* const mirroring_manager_;
245 std::unique_ptr<media::AudioLog> audio_log_; 254 std::unique_ptr<media::AudioLog> audio_log_;
255 std::map<int, int> renderer_frame_ids_;
nasko 2016/05/25 20:50:42 This is never used.
rchtara 2016/05/27 15:24:39 Done.
246 256
247 // Used to access to AudioInputDeviceManager. 257 // Used to access to AudioInputDeviceManager.
248 MediaStreamManager* media_stream_manager_; 258 MediaStreamManager* media_stream_manager_;
249 259
250 // A map of stream IDs to audio sources. 260 // A map of stream IDs to audio sources.
251 AudioEntryMap audio_entries_; 261 AudioEntryMap audio_entries_;
252 262
253 // The number of streams in the playing state. Atomic read safe from any 263 // The number of streams in the playing state. Atomic read safe from any
254 // thread, but should only be updated from the IO thread. 264 // thread, but should only be updated from the IO thread.
255 base::AtomicRefCount num_playing_streams_; 265 base::AtomicRefCount num_playing_streams_;
(...skipping 10 matching lines...) Expand all
266 // The maximum number of simultaneous streams during the lifetime of this 276 // The maximum number of simultaneous streams during the lifetime of this
267 // host. Reported as UMA stat at shutdown. 277 // host. Reported as UMA stat at shutdown.
268 size_t max_simultaneous_streams_; 278 size_t max_simultaneous_streams_;
269 279
270 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); 280 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost);
271 }; 281 };
272 282
273 } // namespace content 283 } // namespace content
274 284
275 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ 285 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698