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; | |
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(int stream_id, |
156 int render_frame_id, | 163 int render_frame_id, |
tommi (sloooow) - chröme
2016/04/26 15:29:53
fix indent
rchtara
2016/04/29 12:54:46
Done.
| |
157 const media::AudioParameters& params); | 164 const media::AudioParameters& params, |
165 const mojom::AudioOutput::CreateStreamCallback& callback); | |
158 | 166 |
159 // Play the audio stream referenced by |stream_id|. | 167 // Play the audio stream referenced by |stream_id|. |
160 void OnPlayStream(int stream_id); | 168 void OnPlayStream(int stream_id); |
161 | 169 |
162 // Pause the audio stream referenced by |stream_id|. | 170 // Pause the audio stream referenced by |stream_id|. |
163 void OnPauseStream(int stream_id); | 171 void OnPauseStream(int stream_id); |
164 | 172 |
165 // Close the audio stream referenced by |stream_id|. | 173 // Close the audio stream referenced by |stream_id|. |
166 void OnCloseStream(int stream_id); | 174 void OnCloseStream(int stream_id); |
167 | 175 |
(...skipping 11 matching lines...) Expand all Loading... | |
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 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 const mojom::AudioOutput::CreateStreamCallback& callback); | |
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 void DoCompleteCreation( |
204 int stream_id, | |
205 const mojom::AudioOutput::CreateStreamCallback& callback); | |
195 | 206 |
196 // Send playing/paused status to the renderer. | 207 // Send playing/paused status to the renderer. |
197 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); | 208 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); |
198 | 209 |
199 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; | 210 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; |
200 | 211 |
201 // Send an error message to the renderer. | 212 // Send an error message to the renderer. |
202 void SendErrorMessage(int stream_id); | 213 void SendErrorMessage(int stream_id); |
203 | 214 |
204 // Delete an audio entry, notifying observers first. This is called by | 215 // Delete an audio entry, notifying observers first. This is called by |
205 // AudioOutputController after it has closed. | 216 // AudioOutputController after it has closed. |
206 void DeleteEntry(std::unique_ptr<AudioEntry> entry); | 217 void DeleteEntry(std::unique_ptr<AudioEntry> entry); |
207 | 218 |
208 // Send an error message to the renderer, then close the stream. | 219 // Send an error message to the renderer, then close the stream. |
209 void ReportErrorAndClose(int stream_id); | 220 void ReportErrorAndClose(int stream_id); |
210 | 221 |
222 // Send an error message to the renderer, then close the stream. | |
223 void ReportErrorAndCloseStream( | |
224 int stream_id, | |
225 const mojom::AudioOutput::CreateStreamCallback& callback); | |
226 | |
211 // A helper method to look up a AudioEntry identified by |stream_id|. | 227 // A helper method to look up a AudioEntry identified by |stream_id|. |
212 // Returns NULL if not found. | 228 // Returns NULL if not found. |
213 AudioEntry* LookupById(int stream_id); | 229 AudioEntry* LookupById(int stream_id); |
214 | 230 |
215 // A helper method to update the number of playing streams and alert the | 231 // A helper method to update the number of playing streams and alert the |
216 // ResourceScheduler when the renderer starts or stops playing an audiostream. | 232 // ResourceScheduler when the renderer starts or stops playing an audiostream. |
217 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); | 233 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); |
218 | 234 |
219 // Check if the renderer process has access to the requested output device. | 235 // Check if the renderer process has access to the requested output device. |
220 void CheckOutputDeviceAccess(int render_frame_id, | 236 void CheckOutputDeviceAccess(int render_frame_id, |
(...skipping 15 matching lines...) Expand all Loading... | |
236 // Helper method to check if the authorization procedure for stream | 252 // Helper method to check if the authorization procedure for stream |
237 // |stream_id| has started. | 253 // |stream_id| has started. |
238 bool IsAuthorizationStarted(int stream_id); | 254 bool IsAuthorizationStarted(int stream_id); |
239 | 255 |
240 // ID of the RenderProcessHost that owns this instance. | 256 // ID of the RenderProcessHost that owns this instance. |
241 const int render_process_id_; | 257 const int render_process_id_; |
242 | 258 |
243 media::AudioManager* const audio_manager_; | 259 media::AudioManager* const audio_manager_; |
244 AudioMirroringManager* const mirroring_manager_; | 260 AudioMirroringManager* const mirroring_manager_; |
245 std::unique_ptr<media::AudioLog> audio_log_; | 261 std::unique_ptr<media::AudioLog> audio_log_; |
262 AudioOutputImpl* audio_output_impl_; | |
246 | 263 |
247 // Used to access to AudioInputDeviceManager. | 264 // Used to access to AudioInputDeviceManager. |
248 MediaStreamManager* media_stream_manager_; | 265 MediaStreamManager* media_stream_manager_; |
249 | 266 |
250 // A map of stream IDs to audio sources. | 267 // A map of stream IDs to audio sources. |
251 AudioEntryMap audio_entries_; | 268 AudioEntryMap audio_entries_; |
252 | 269 |
253 // The number of streams in the playing state. Atomic read safe from any | 270 // The number of streams in the playing state. Atomic read safe from any |
254 // thread, but should only be updated from the IO thread. | 271 // thread, but should only be updated from the IO thread. |
255 base::AtomicRefCount num_playing_streams_; | 272 base::AtomicRefCount num_playing_streams_; |
256 | 273 |
257 // Salt required to translate renderer device IDs to raw device unique IDs | 274 // Salt required to translate renderer device IDs to raw device unique IDs |
258 ResourceContext::SaltCallback salt_callback_; | 275 ResourceContext::SaltCallback salt_callback_; |
259 | 276 |
260 // Map of device authorizations for streams that are not yet created | 277 // 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 | 278 // 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. | 279 // is a bool that is true if the authorization process completes successfully. |
263 // The second element contains the unique ID of the authorized device. | 280 // The second element contains the unique ID of the authorized device. |
264 std::map<int, std::pair<bool, std::string>> authorizations_; | 281 std::map<int, std::pair<bool, std::string>> authorizations_; |
265 | 282 |
266 // The maximum number of simultaneous streams during the lifetime of this | 283 // The maximum number of simultaneous streams during the lifetime of this |
267 // host. Reported as UMA stat at shutdown. | 284 // host. Reported as UMA stat at shutdown. |
268 size_t max_simultaneous_streams_; | 285 size_t max_simultaneous_streams_; |
269 | 286 |
287 mojom::AudioOutputStreamPtr stream_ptr_; | |
288 | |
270 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); | 289 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); |
271 }; | 290 }; |
272 | 291 |
273 } // namespace content | 292 } // namespace content |
274 | 293 |
275 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ | 294 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ |
OLD | NEW |