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

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 of process_ instead of audio_renderer_host 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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"
59 #include "media/mojo/interfaces/audio_output.mojom.h"
Henrik Grunell 2016/05/20 13:35:40 Fix order.
rchtara 2016/05/27 15:24:37 Done.
58 #include "content/public/browser/browser_message_filter.h" 60 #include "content/public/browser/browser_message_filter.h"
59 #include "content/public/browser/browser_thread.h" 61 #include "content/public/browser/browser_thread.h"
60 #include "content/public/browser/render_process_host.h" 62 #include "content/public/browser/render_process_host.h"
61 #include "content/public/browser/resource_context.h" 63 #include "content/public/browser/resource_context.h"
62 #include "media/audio/audio_io.h" 64 #include "media/audio/audio_io.h"
63 #include "media/audio/audio_logging.h" 65 #include "media/audio/audio_logging.h"
64 #include "media/audio/audio_output_controller.h" 66 #include "media/audio/audio_output_controller.h"
65 #include "media/audio/simple_sources.h" 67 #include "media/audio/simple_sources.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,
86 AudioMirroringManager* mirroring_manager, 90 AudioMirroringManager* mirroring_manager,
87 MediaInternals* media_internals, 91 MediaInternals* media_internals,
88 MediaStreamManager* media_stream_manager, 92 MediaStreamManager* media_stream_manager,
89 const ResourceContext::SaltCallback& salt_callback); 93 const ResourceContext::SaltCallback& salt_callback);
90 94
95 // Creates an audio output stream with the specified format.
96 // Upon success/failure, the peer is notified via the NotifyStreamCreated
97 // message.
98 virtual void CreateStream(
99 int stream_id,
100 int render_frame_id,
101 const media::AudioParameters& params,
102 const media::mojom::AudioOutput::CreateStreamCallback& callback);
103
104 // Close the audio stream referenced by |stream_id|.
105 virtual void CloseStream(int stream_id);
106
91 // Calls |callback| with the list of AudioOutputControllers for this object. 107 // Calls |callback| with the list of AudioOutputControllers for this object.
92 void GetOutputControllers( 108 void GetOutputControllers(
93 const RenderProcessHost::GetAudioOutputControllersCallback& 109 const RenderProcessHost::GetAudioOutputControllersCallback&
94 callback) const; 110 callback) const;
95 111
96 // BrowserMessageFilter implementation. 112 // BrowserMessageFilter implementation.
97 void OnChannelClosing() override; 113 void OnChannelClosing() override;
98 void OnDestruct() const override; 114 void OnDestruct() const override;
99 bool OnMessageReceived(const IPC::Message& message) override; 115 bool OnMessageReceived(const IPC::Message& message) override;
100 116
101 // Returns true if any streams managed by this host are actively playing. Can 117 // Returns true if any streams managed by this host are actively playing. Can
102 // be called from any thread. 118 // be called from any thread.
103 bool HasActiveAudio(); 119 bool HasActiveAudio();
104 120
105 // Returns true if any streams managed by the RenderFrame identified by 121 // Returns true if any streams managed by the RenderFrame identified by
106 // |render_frame_id| are actively playing. Can be called from any thread. 122 // |render_frame_id| are actively playing. Can be called from any thread.
107 bool RenderFrameHasActiveAudio(int render_frame_id) const; 123 bool RenderFrameHasActiveAudio(int render_frame_id) const;
108 124
125 virtual AudioOutputImpl* get_audio_output_impl(int render_frame_id) const;
126
127 virtual void set_audio_output_impl(int render_frame_id,
128 AudioOutputImpl* audio_output_impl);
129
109 private: 130 private:
131 friend class AudioEntry;
132 friend class AudioOutputImplTest;
110 friend class AudioRendererHostTest; 133 friend class AudioRendererHostTest;
134 friend class base::DeleteHelper<AudioRendererHost>;
111 friend class BrowserThread; 135 friend class BrowserThread;
112 friend class base::DeleteHelper<AudioRendererHost>;
113 friend class MockAudioRendererHost; 136 friend class MockAudioRendererHost;
137 friend class MockAudioOutputAudioRendererHost;
138 friend class MockAudioOutputStreamAudioRendererHost;
114 friend class TestAudioRendererHost; 139 friend class TestAudioRendererHost;
140
115 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); 141 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream);
116 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); 142 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation);
117 143
118 class AudioEntry; 144 class AudioEntry;
119 typedef std::map<int, AudioEntry*> AudioEntryMap; 145 typedef std::map<int, AudioEntry*> AudioEntryMap;
120 146
121 // Internal callback type for access requests to output devices. 147 // Internal callback type for access requests to output devices.
122 // |have_access| is true only if there is permission to access the device. 148 // |have_access| is true only if there is permission to access the device.
123 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB; 149 typedef base::Callback<void(bool have_access)> OutputDeviceAccessCB;
124 150
(...skipping 17 matching lines...) Expand all
142 // |session_id| will be ignored and the given |device_id| and 168 // |session_id| will be ignored and the given |device_id| and
143 // |security_origin| will be used to select the output device. 169 // |security_origin| will be used to select the output device.
144 // Upon completion of the process, the peer is notified with the device output 170 // Upon completion of the process, the peer is notified with the device output
145 // parameters via the NotifyDeviceAuthorized message. 171 // parameters via the NotifyDeviceAuthorized message.
146 void OnRequestDeviceAuthorization(int stream_id, 172 void OnRequestDeviceAuthorization(int stream_id,
147 int render_frame_id, 173 int render_frame_id,
148 int session_id, 174 int session_id,
149 const std::string& device_id, 175 const std::string& device_id,
150 const url::Origin& security_origin); 176 const url::Origin& security_origin);
151 177
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|. 178 // Play the audio stream referenced by |stream_id|.
160 void OnPlayStream(int stream_id); 179 void OnPlayStream(int stream_id);
161 180
162 // Pause the audio stream referenced by |stream_id|. 181 // Pause the audio stream referenced by |stream_id|.
163 void OnPauseStream(int stream_id); 182 void OnPauseStream(int stream_id);
164 183
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|. 184 // Set the volume of the audio stream referenced by |stream_id|.
169 void OnSetVolume(int stream_id, double volume); 185 void OnSetVolume(int stream_id, double volume);
170 186
171 // Helper methods. 187 // Helper methods.
172 188
173 // Proceed with device authorization after checking permissions. 189 // Proceed with device authorization after checking permissions.
174 void OnDeviceAuthorized(int stream_id, 190 void OnDeviceAuthorized(int stream_id,
175 const std::string& device_id, 191 const std::string& device_id,
176 const url::Origin& security_origin, 192 const url::Origin& security_origin,
177 bool have_access); 193 bool have_access);
178 194
179 // Proceed with device authorization after translating device ID. 195 // Proceed with device authorization after translating device ID.
180 void OnDeviceIDTranslated(int stream_id, 196 void OnDeviceIDTranslated(int stream_id,
181 bool device_found, 197 bool device_found,
182 const AudioOutputDeviceInfo& device_info); 198 const AudioOutputDeviceInfo& device_info);
183 199
184 // Start the actual creation of an audio stream, after the device 200 // Start the actual creation of an audio stream, after the device
185 // authorization process is complete. 201 // authorization process is complete.
186 void DoCreateStream(int stream_id, 202 virtual void DoCreateStream(
187 int render_frame_id, 203 int stream_id,
188 const media::AudioParameters& params, 204 int render_frame_id,
189 const std::string& device_unique_id); 205 const media::AudioParameters& params,
206 const std::string& device_unique_id,
207 const media::mojom::AudioOutput::CreateStreamCallback&
208 create_stream_callback);
190 209
191 // Complete the process of creating an audio stream. This will set up the 210 // 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 211 // shared memory or shared socket in low latency mode and send the
193 // NotifyStreamCreated message to the peer. 212 // NotifyStreamCreated message to the peer.
194 void DoCompleteCreation(int stream_id); 213 virtual void DoCompleteCreation(
214 int stream_id,
215 const media::mojom::AudioOutput::CreateStreamCallback&
216 create_stream_callback);
195 217
196 // Send playing/paused status to the renderer. 218 // Send playing/paused status to the renderer.
197 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); 219 void DoNotifyStreamStateChanged(int stream_id, bool is_playing);
198 220
199 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; 221 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const;
200 222
201 // Send an error message to the renderer. 223 // Send an error message to the renderer.
202 void SendErrorMessage(int stream_id); 224 void SendErrorMessage(int stream_id);
203 225
204 // Delete an audio entry, notifying observers first. This is called by 226 // Delete an audio entry, notifying observers first. This is called by
205 // AudioOutputController after it has closed. 227 // AudioOutputController after it has closed.
206 void DeleteEntry(std::unique_ptr<AudioEntry> entry); 228 void DeleteEntry(std::unique_ptr<AudioEntry> entry);
207 229
230 // Send an error message to the client, then close the stream.
231 void ReportErrorAndClose(int stream_id);
232
208 // Send an error message to the renderer, then close the stream. 233 // Send an error message to the renderer, then close the stream.
209 void ReportErrorAndClose(int stream_id); 234 void ReportErrorAndCloseStream(
235 int stream_id,
236 const media::mojom::AudioOutput::CreateStreamCallback& callback);
210 237
211 // A helper method to look up a AudioEntry identified by |stream_id|. 238 // A helper method to look up a AudioEntry identified by |stream_id|.
212 // Returns NULL if not found. 239 // Returns NULL if not found.
213 AudioEntry* LookupById(int stream_id); 240 AudioEntry* LookupById(int stream_id);
214 241
215 // A helper method to update the number of playing streams and alert the 242 // A helper method to update the number of playing streams and alert the
216 // ResourceScheduler when the renderer starts or stops playing an audiostream. 243 // ResourceScheduler when the renderer starts or stops playing an audiostream.
217 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing); 244 void UpdateNumPlayingStreams(AudioEntry* entry, bool is_playing);
218 245
219 // Check if the renderer process has access to the requested output device. 246 // Check if the renderer process has access to the requested output device.
(...skipping 16 matching lines...) Expand all
236 // Helper method to check if the authorization procedure for stream 263 // Helper method to check if the authorization procedure for stream
237 // |stream_id| has started. 264 // |stream_id| has started.
238 bool IsAuthorizationStarted(int stream_id); 265 bool IsAuthorizationStarted(int stream_id);
239 266
240 // ID of the RenderProcessHost that owns this instance. 267 // ID of the RenderProcessHost that owns this instance.
241 const int render_process_id_; 268 const int render_process_id_;
242 269
243 media::AudioManager* const audio_manager_; 270 media::AudioManager* const audio_manager_;
244 AudioMirroringManager* const mirroring_manager_; 271 AudioMirroringManager* const mirroring_manager_;
245 std::unique_ptr<media::AudioLog> audio_log_; 272 std::unique_ptr<media::AudioLog> audio_log_;
273 std::map<int, AudioOutputImpl*> audio_output_impls_;
Henrik Grunell 2016/05/20 13:35:40 As we talked about offline, let the AudioRenderFra
rchtara 2016/05/27 15:24:37 Done.
274 std::map<int, int> renderer_frame_ids_;
Henrik Grunell 2016/05/20 13:35:40 What is this used for?
rchtara 2016/05/27 15:24:37 they are removed
246 275
247 // Used to access to AudioInputDeviceManager. 276 // Used to access to AudioInputDeviceManager.
248 MediaStreamManager* media_stream_manager_; 277 MediaStreamManager* media_stream_manager_;
249 278
250 // A map of stream IDs to audio sources. 279 // A map of stream IDs to audio sources.
251 AudioEntryMap audio_entries_; 280 AudioEntryMap audio_entries_;
252 281
253 // The number of streams in the playing state. Atomic read safe from any 282 // The number of streams in the playing state. Atomic read safe from any
254 // thread, but should only be updated from the IO thread. 283 // thread, but should only be updated from the IO thread.
255 base::AtomicRefCount num_playing_streams_; 284 base::AtomicRefCount num_playing_streams_;
(...skipping 10 matching lines...) Expand all
266 // The maximum number of simultaneous streams during the lifetime of this 295 // The maximum number of simultaneous streams during the lifetime of this
267 // host. Reported as UMA stat at shutdown. 296 // host. Reported as UMA stat at shutdown.
268 size_t max_simultaneous_streams_; 297 size_t max_simultaneous_streams_;
269 298
270 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); 299 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost);
271 }; 300 };
272 301
273 } // namespace content 302 } // namespace content
274 303
275 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ 304 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698