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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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; |
| 121 void CleanAudioOutputImpl(AudioOutputImpl* audio_output_impl); |
108 | 122 |
109 private: | 123 private: |
| 124 friend class AudioEntry; |
| 125 friend class AudioOutputImplTest; |
110 friend class AudioRendererHostTest; | 126 friend class AudioRendererHostTest; |
111 friend class BrowserThread; | 127 friend class BrowserThread; |
112 friend class base::DeleteHelper<AudioRendererHost>; | 128 friend class base::DeleteHelper<AudioRendererHost>; |
113 friend class MockAudioRendererHost; | 129 friend class MockAudioRendererHost; |
| 130 friend class MockAudioOutputAudioRendererHost; |
| 131 friend class MockAudioOutputStreamAudioRendererHost; |
114 friend class TestAudioRendererHost; | 132 friend class TestAudioRendererHost; |
| 133 |
115 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); | 134 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); |
116 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); | 135 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); |
117 | 136 |
118 class AudioEntry; | 137 class AudioEntry; |
119 typedef std::map<int, AudioEntry*> AudioEntryMap; | 138 typedef std::map<int, AudioEntry*> AudioEntryMap; |
120 | 139 |
121 // Internal callback type for access requests to output devices. | 140 // Internal callback type for access requests to output devices. |
122 // |have_access| is true only if there is permission to access the device. | 141 // |have_access| is true only if there is permission to access the device. |
123 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB; | 142 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB; |
124 | 143 |
(...skipping 17 matching lines...) Expand all Loading... |
142 // |session_id| will be ignored and the given |device_id| and | 161 // |session_id| will be ignored and the given |device_id| and |
143 // |security_origin| will be used to select the output device. | 162 // |security_origin| will be used to select the output device. |
144 // Upon completion of the process, the peer is notified with the device output | 163 // Upon completion of the process, the peer is notified with the device output |
145 // parameters via the NotifyDeviceAuthorized message. | 164 // parameters via the NotifyDeviceAuthorized message. |
146 void OnRequestDeviceAuthorization(int stream_id, | 165 void OnRequestDeviceAuthorization(int stream_id, |
147 int render_frame_id, | 166 int render_frame_id, |
148 int session_id, | 167 int session_id, |
149 const std::string& device_id, | 168 const std::string& device_id, |
150 const url::Origin& security_origin); | 169 const url::Origin& security_origin); |
151 | 170 |
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|. | 171 // Play the audio stream referenced by |stream_id|. |
160 void OnPlayStream(int stream_id); | 172 void OnPlayStream(int stream_id); |
161 | 173 |
162 // Pause the audio stream referenced by |stream_id|. | 174 // Pause the audio stream referenced by |stream_id|. |
163 void OnPauseStream(int stream_id); | 175 void OnPauseStream(int stream_id); |
164 | 176 |
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|. | 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 url::Origin& security_origin, | 185 const url::Origin& 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 virtual void DoCreateStream(int stream_id, |
187 int render_frame_id, | 196 int render_frame_id, |
188 const media::AudioParameters& params, | 197 const media::AudioParameters& params, |
189 const std::string& device_unique_id); | 198 const std::string& device_unique_id, |
| 199 AudioOutputImpl* audio_output_impl); |
190 | 200 |
191 // Complete the process of creating an audio stream. This will set up the | 201 // 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 | 202 // shared memory or shared socket in low latency mode and send the |
193 // NotifyStreamCreated message to the peer. | 203 // NotifyStreamCreated message to the peer. |
194 void DoCompleteCreation(int stream_id); | 204 virtual void DoCompleteCreation(int stream_id); |
195 | 205 |
196 // Send playing/paused status to the renderer. | 206 // Send playing/paused status to the renderer. |
197 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); | 207 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); |
198 | 208 |
199 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; | 209 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; |
200 | 210 |
201 // Send an error message to the renderer. | 211 // Send an error message to the renderer. |
202 void SendErrorMessage(int stream_id); | 212 void SendErrorMessage(int stream_id); |
203 | 213 |
204 // Delete an audio entry, notifying observers first. This is called by | 214 // Delete an audio entry, notifying observers first. This is called by |
205 // AudioOutputController after it has closed. | 215 // AudioOutputController after it has closed. |
206 void DeleteEntry(std::unique_ptr<AudioEntry> entry); | 216 void DeleteEntry(std::unique_ptr<AudioEntry> entry); |
207 | 217 |
208 // Send an error message to the renderer, then close the stream. | 218 // Send an error message to the client, then close the stream. |
209 void ReportErrorAndClose(int stream_id); | 219 void ReportErrorAndClose(int stream_id); |
210 | 220 |
211 // A helper method to look up a AudioEntry identified by |stream_id|. | 221 // A helper method to look up a AudioEntry identified by |stream_id|. |
212 // Returns NULL if not found. | 222 // Returns NULL if not found. |
213 AudioEntry* LookupById(int stream_id); | 223 AudioEntry* LookupById(int stream_id); |
214 | 224 |
215 // A helper method to update the number of playing streams and alert the | 225 // A helper method to update the number of playing streams and alert the |
216 // ResourceScheduler when the renderer starts or stops playing an audiostream. | 226 // ResourceScheduler when the renderer starts or stops playing an audiostream. |
217 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); | 227 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); |
218 | 228 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_ |
OLD | NEW |