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

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: fixwindows Created 4 years, 6 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
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // The maximum number of simultaneous streams during the lifetime of this 275 // The maximum number of simultaneous streams during the lifetime of this
267 // host. Reported as UMA stat at shutdown. 276 // host. Reported as UMA stat at shutdown.
268 size_t max_simultaneous_streams_; 277 size_t max_simultaneous_streams_;
269 278
270 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); 279 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost);
271 }; 280 };
272 281
273 } // namespace content 282 } // namespace content
274 283
275 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ 284 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698