OLD | NEW |
---|---|
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 | 44 |
45 #include <map> | 45 #include <map> |
46 #include <memory> | 46 #include <memory> |
47 #include <string> | 47 #include <string> |
48 #include <utility> | 48 #include <utility> |
49 | 49 |
50 #include "base/atomic_ref_count.h" | 50 #include "base/atomic_ref_count.h" |
51 #include "base/gtest_prod_util.h" | 51 #include "base/gtest_prod_util.h" |
52 #include "base/macros.h" | 52 #include "base/macros.h" |
53 #include "base/memory/ref_counted.h" | 53 #include "base/memory/ref_counted.h" |
54 #include "base/memory/shared_memory.h" | |
54 #include "base/process/process.h" | 55 #include "base/process/process.h" |
55 #include "base/sequenced_task_runner_helpers.h" | 56 #include "base/sequenced_task_runner_helpers.h" |
56 #include "content/browser/renderer_host/media/audio_output_device_enumerator.h" | 57 #include "content/browser/renderer_host/media/audio_output_device_enumerator.h" |
57 #include "content/common/content_export.h" | 58 #include "content/common/content_export.h" |
58 #include "content/public/browser/browser_message_filter.h" | 59 #include "content/public/browser/browser_message_filter.h" |
59 #include "content/public/browser/browser_thread.h" | 60 #include "content/public/browser/browser_thread.h" |
60 #include "content/public/browser/render_process_host.h" | 61 #include "content/public/browser/render_process_host.h" |
61 #include "content/public/browser/resource_context.h" | 62 #include "content/public/browser/resource_context.h" |
62 #include "media/audio/audio_io.h" | 63 #include "media/audio/audio_io.h" |
63 #include "media/audio/audio_logging.h" | 64 #include "media/audio/audio_logging.h" |
64 #include "media/audio/audio_output_controller.h" | 65 #include "media/audio/audio_output_controller.h" |
65 #include "media/audio/simple_sources.h" | 66 #include "media/audio/simple_sources.h" |
67 #include "media/mojo/interfaces/audio_output.mojom.h" | |
66 #include "url/origin.h" | 68 #include "url/origin.h" |
67 | 69 |
68 namespace media { | 70 namespace media { |
69 class AudioManager; | 71 class AudioManager; |
70 class AudioParameters; | 72 class AudioParameters; |
71 } | 73 } |
72 | 74 |
73 namespace content { | 75 namespace content { |
74 | 76 |
75 class AudioMirroringManager; | 77 class AudioMirroringManager; |
78 class AudioOutputImpl; | |
79 class AudioOutputStreamImpl; | |
76 class MediaInternals; | 80 class MediaInternals; |
77 class MediaStreamManager; | 81 class MediaStreamManager; |
78 class MediaStreamUIProxy; | 82 class MediaStreamUIProxy; |
79 class ResourceContext; | 83 class ResourceContext; |
80 | 84 |
81 class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { | 85 class CONTENT_EXPORT AudioRendererHost : public BrowserMessageFilter { |
82 public: | 86 public: |
83 // Called from UI thread from the owner of this object. | 87 // Called from UI thread from the owner of this object. |
84 AudioRendererHost(int render_process_id, | 88 AudioRendererHost(int render_process_id, |
85 media::AudioManager* audio_manager, | 89 media::AudioManager* audio_manager, |
(...skipping 14 matching lines...) Expand all Loading... | |
100 | 104 |
101 // Returns true if any streams managed by this host are actively playing. Can | 105 // Returns true if any streams managed by this host are actively playing. Can |
102 // be called from any thread. | 106 // be called from any thread. |
103 bool HasActiveAudio(); | 107 bool HasActiveAudio(); |
104 | 108 |
105 // Returns true if any streams managed by the RenderFrame identified by | 109 // Returns true if any streams managed by the RenderFrame identified by |
106 // |render_frame_id| are actively playing. Can be called from any thread. | 110 // |render_frame_id| are actively playing. Can be called from any thread. |
107 bool RenderFrameHasActiveAudio(int render_frame_id) const; | 111 bool RenderFrameHasActiveAudio(int render_frame_id) const; |
108 | 112 |
109 private: | 113 private: |
114 friend class AudioEntry; | |
Henrik Grunell
2016/05/02 12:12:23
This should not be needed. Anything that needs to
rchtara
2016/05/23 16:38:17
Done.
| |
115 friend class AudioOutputImpl; | |
116 friend class AudioOutputStreamImpl; | |
110 friend class AudioRendererHostTest; | 117 friend class AudioRendererHostTest; |
111 friend class BrowserThread; | 118 friend class BrowserThread; |
112 friend class base::DeleteHelper<AudioRendererHost>; | 119 friend class base::DeleteHelper<AudioRendererHost>; |
113 friend class MockAudioRendererHost; | 120 friend class MockAudioRendererHost; |
114 friend class TestAudioRendererHost; | 121 friend class TestAudioRendererHost; |
115 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); | 122 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); |
116 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); | 123 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); |
117 | 124 |
118 class AudioEntry; | 125 class AudioEntry; |
119 typedef std::map<int, AudioEntry*> AudioEntryMap; | 126 typedef std::map<int, AudioEntry*> AudioEntryMap; |
(...skipping 25 matching lines...) Expand all Loading... | |
145 // parameters via the NotifyDeviceAuthorized message. | 152 // parameters via the NotifyDeviceAuthorized message. |
146 void OnRequestDeviceAuthorization(int stream_id, | 153 void OnRequestDeviceAuthorization(int stream_id, |
147 int render_frame_id, | 154 int render_frame_id, |
148 int session_id, | 155 int session_id, |
149 const std::string& device_id, | 156 const std::string& device_id, |
150 const url::Origin& gurl_security_origin); | 157 const url::Origin& gurl_security_origin); |
151 | 158 |
152 // Creates an audio output stream with the specified format. | 159 // Creates an audio output stream with the specified format. |
153 // Upon success/failure, the peer is notified via the NotifyStreamCreated | 160 // Upon success/failure, the peer is notified via the NotifyStreamCreated |
154 // message. | 161 // message. |
155 void OnCreateStream(int stream_id, | 162 void CreateStream( |
156 int render_frame_id, | 163 int stream_id, |
157 const media::AudioParameters& params); | 164 int render_frame_id, |
165 const media::AudioParameters& params, | |
166 const media::interfaces::AudioOutput::CreateStreamCallback& callback); | |
158 | 167 |
159 // Play the audio stream referenced by |stream_id|. | 168 // Play the audio stream referenced by |stream_id|. |
160 void OnPlayStream(int stream_id); | 169 void OnPlayStream(int stream_id); |
161 | 170 |
162 // Pause the audio stream referenced by |stream_id|. | 171 // Pause the audio stream referenced by |stream_id|. |
163 void OnPauseStream(int stream_id); | 172 void OnPauseStream(int stream_id); |
164 | 173 |
165 // Close the audio stream referenced by |stream_id|. | 174 // Close the audio stream referenced by |stream_id|. |
166 void OnCloseStream(int stream_id); | 175 void OnCloseStream(int stream_id); |
167 | 176 |
168 // Set the volume of the audio stream referenced by |stream_id|. | 177 // Set the volume of the audio stream referenced by |stream_id|. |
169 void OnSetVolume(int stream_id, double volume); | 178 void OnSetVolume(int stream_id, double volume); |
170 | 179 |
171 // Helper methods. | 180 // Helper methods. |
172 | 181 |
173 // Proceed with device authorization after checking permissions. | 182 // Proceed with device authorization after checking permissions. |
174 void OnDeviceAuthorized(int stream_id, | 183 void OnDeviceAuthorized(int stream_id, |
175 const std::string& device_id, | 184 const std::string& device_id, |
176 const GURL& security_origin, | 185 const GURL& security_origin, |
177 bool have_access); | 186 bool have_access); |
178 | 187 |
179 // Proceed with device authorization after translating device ID. | 188 // Proceed with device authorization after translating device ID. |
180 void OnDeviceIDTranslated(int stream_id, | 189 void OnDeviceIDTranslated(int stream_id, |
181 bool device_found, | 190 bool device_found, |
182 const AudioOutputDeviceInfo& device_info); | 191 const AudioOutputDeviceInfo& device_info); |
183 | 192 |
184 // Start the actual creation of an audio stream, after the device | 193 // Start the actual creation of an audio stream, after the device |
185 // authorization process is complete. | 194 // authorization process is complete. |
186 void DoCreateStream(int stream_id, | 195 void DoCreateStream( |
187 int render_frame_id, | 196 int stream_id, |
188 const media::AudioParameters& params, | 197 int render_frame_id, |
189 const std::string& device_unique_id); | 198 const media::AudioParameters& params, |
199 const std::string& device_unique_id, | |
200 const media::interfaces::AudioOutput::CreateStreamCallback& callback); | |
190 | 201 |
191 // Complete the process of creating an audio stream. This will set up the | 202 // 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 | 203 // shared memory or shared socket in low latency mode and send the |
193 // NotifyStreamCreated message to the peer. | 204 // NotifyStreamCreated message to the peer. |
194 void DoCompleteCreation(int stream_id); | 205 void DoCompleteCreation( |
206 int stream_id, | |
207 const media::interfaces::AudioOutput::CreateStreamCallback& callback); | |
195 | 208 |
196 // Send playing/paused status to the renderer. | 209 // Send playing/paused status to the renderer. |
197 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); | 210 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); |
198 | 211 |
199 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; | 212 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; |
200 | 213 |
201 // Send an error message to the renderer. | 214 // Send an error message to the renderer. |
202 void SendErrorMessage(int stream_id); | 215 void SendErrorMessage(int stream_id); |
203 | 216 |
204 // Delete an audio entry, notifying observers first. This is called by | 217 // Delete an audio entry, notifying observers first. This is called by |
205 // AudioOutputController after it has closed. | 218 // AudioOutputController after it has closed. |
206 void DeleteEntry(std::unique_ptr<AudioEntry> entry); | 219 void DeleteEntry(std::unique_ptr<AudioEntry> entry); |
207 | 220 |
208 // Send an error message to the renderer, then close the stream. | 221 // Send an error message to the renderer, then close the stream. |
209 void ReportErrorAndClose(int stream_id); | 222 void ReportErrorAndClose(int stream_id); |
210 | 223 |
224 // Send an error message to the renderer, then close the stream. | |
Henrik Grunell
2016/05/02 12:12:23
Change "renderer" to "client", it's more generic.
rchtara
2016/05/23 16:38:17
Done.
| |
225 void ReportErrorAndCloseStream( | |
226 int stream_id, | |
227 const media::interfaces::AudioOutput::CreateStreamCallback& callback); | |
228 | |
211 // A helper method to look up a AudioEntry identified by |stream_id|. | 229 // A helper method to look up a AudioEntry identified by |stream_id|. |
212 // Returns NULL if not found. | 230 // Returns NULL if not found. |
213 AudioEntry* LookupById(int stream_id); | 231 AudioEntry* LookupById(int stream_id); |
214 | 232 |
215 // A helper method to update the number of playing streams and alert the | 233 // A helper method to update the number of playing streams and alert the |
216 // ResourceScheduler when the renderer starts or stops playing an audiostream. | 234 // ResourceScheduler when the renderer starts or stops playing an audiostream. |
217 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); | 235 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); |
218 | 236 |
219 // Check if the renderer process has access to the requested output device. | 237 // Check if the renderer process has access to the requested output device. |
220 void CheckOutputDeviceAccess(int render_frame_id, | 238 void CheckOutputDeviceAccess(int render_frame_id, |
(...skipping 15 matching lines...) Expand all Loading... | |
236 // Helper method to check if the authorization procedure for stream | 254 // Helper method to check if the authorization procedure for stream |
237 // |stream_id| has started. | 255 // |stream_id| has started. |
238 bool IsAuthorizationStarted(int stream_id); | 256 bool IsAuthorizationStarted(int stream_id); |
239 | 257 |
240 // ID of the RenderProcessHost that owns this instance. | 258 // ID of the RenderProcessHost that owns this instance. |
241 const int render_process_id_; | 259 const int render_process_id_; |
242 | 260 |
243 media::AudioManager* const audio_manager_; | 261 media::AudioManager* const audio_manager_; |
244 AudioMirroringManager* const mirroring_manager_; | 262 AudioMirroringManager* const mirroring_manager_; |
245 std::unique_ptr<media::AudioLog> audio_log_; | 263 std::unique_ptr<media::AudioLog> audio_log_; |
264 AudioOutputImpl* audio_output_impl_; | |
Henrik Grunell
2016/05/02 12:12:23
Add a comment about this. In that also explain how
| |
246 | 265 |
247 // Used to access to AudioInputDeviceManager. | 266 // Used to access to AudioInputDeviceManager. |
248 MediaStreamManager* media_stream_manager_; | 267 MediaStreamManager* media_stream_manager_; |
249 | 268 |
250 // A map of stream IDs to audio sources. | 269 // A map of stream IDs to audio sources. |
251 AudioEntryMap audio_entries_; | 270 AudioEntryMap audio_entries_; |
252 | 271 |
253 // The number of streams in the playing state. Atomic read safe from any | 272 // The number of streams in the playing state. Atomic read safe from any |
254 // thread, but should only be updated from the IO thread. | 273 // thread, but should only be updated from the IO thread. |
255 base::AtomicRefCount num_playing_streams_; | 274 base::AtomicRefCount num_playing_streams_; |
256 | 275 |
257 // Salt required to translate renderer device IDs to raw device unique IDs | 276 // Salt required to translate renderer device IDs to raw device unique IDs |
258 ResourceContext::SaltCallback salt_callback_; | 277 ResourceContext::SaltCallback salt_callback_; |
259 | 278 |
260 // Map of device authorizations for streams that are not yet created | 279 // Map of device authorizations for streams that are not yet created |
261 // The key is the stream ID, and the value is a pair. The pair's first element | 280 // The key is the stream ID, and the value is a pair. The pair's first element |
262 // is a bool that is true if the authorization process completes successfully. | 281 // is a bool that is true if the authorization process completes successfully. |
263 // The second element contains the unique ID of the authorized device. | 282 // The second element contains the unique ID of the authorized device. |
264 std::map<int, std::pair<bool, std::string>> authorizations_; | 283 std::map<int, std::pair<bool, std::string>> authorizations_; |
265 | 284 |
266 // The maximum number of simultaneous streams during the lifetime of this | 285 // The maximum number of simultaneous streams during the lifetime of this |
267 // host. Reported as UMA stat at shutdown. | 286 // host. Reported as UMA stat at shutdown. |
268 size_t max_simultaneous_streams_; | 287 size_t max_simultaneous_streams_; |
269 | 288 |
289 media::interfaces::AudioOutputStreamPtr stream_ptr_; | |
Henrik Grunell
2016/05/02 12:12:23
Add comment.
rchtara
2016/05/23 16:38:17
Done.
| |
290 | |
270 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 291 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
271 }; | 292 }; |
272 | 293 |
273 } // namespace content | 294 } // namespace content |
274 | 295 |
275 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 296 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
OLD | NEW |