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

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host.h

Issue 1856673002: Mojofication of the Chrome Audio Rendering Prototype Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 #include "base/atomic_ref_count.h" 49 #include "base/atomic_ref_count.h"
50 #include "base/gtest_prod_util.h" 50 #include "base/gtest_prod_util.h"
51 #include "base/macros.h" 51 #include "base/macros.h"
52 #include "base/memory/ref_counted.h" 52 #include "base/memory/ref_counted.h"
53 #include "base/memory/scoped_ptr.h" 53 #include "base/memory/scoped_ptr.h"
54 #include "base/process/process.h" 54 #include "base/process/process.h"
55 #include "base/sequenced_task_runner_helpers.h" 55 #include "base/sequenced_task_runner_helpers.h"
56 #include "content/browser/renderer_host/media/audio_output_device_enumerator.h" 56 #include "content/browser/renderer_host/media/audio_output_device_enumerator.h"
57 #include "content/common/content_export.h" 57 #include "content/common/content_export.h"
58 #include "content/common/media/audio_output.mojom.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"
66 #include "url/origin.h" 67 #include "url/origin.h"
67 68
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 bool OnMessageReceived(const IPC::Message& message) override; 100 bool OnMessageReceived(const IPC::Message& message) override;
100 101
101 // Returns true if any streams managed by this host are actively playing. Can 102 // Returns true if any streams managed by this host are actively playing. Can
102 // be called from any thread. 103 // be called from any thread.
103 bool HasActiveAudio(); 104 bool HasActiveAudio();
104 105
105 // Returns true if any streams managed by the RenderFrame identified by 106 // Returns true if any streams managed by the RenderFrame identified by
106 // |render_frame_id| are actively playing. Can be called from any thread. 107 // |render_frame_id| are actively playing. Can be called from any thread.
107 bool RenderFrameHasActiveAudio(int render_frame_id) const; 108 bool RenderFrameHasActiveAudio(int render_frame_id) const;
108 109
110 // Creates an audio output stream with the specified format.
111 // Upon success/failure, the peer is notified via the NotifyStreamCreated
112 // message.
113 void OnCreateStream(int stream_id,
114 int render_frame_id,
115 const media::AudioParameters& params);
116
117 // Creates an audio output stream with the specified format.
118 // Upon success/failure, the peer is notified via the NotifyStreamCreated
119 // message.
120 void OnCreateStreamMojo(int stream_id,
121 int render_frame_id,
122 const media::AudioParameters& params,
123 AudioOutputStreamPtr stream,
124 const AudioOutput::CreateStreamCallback& callback);
125
126 // Close the audio stream referenced by |stream_id|.
127 void OnCloseStream(int stream_id);
128
109 private: 129 private:
110 friend class AudioRendererHostTest; 130 friend class AudioRendererHostTest;
111 friend class BrowserThread; 131 friend class BrowserThread;
112 friend class base::DeleteHelper<AudioRendererHost>; 132 friend class base::DeleteHelper<AudioRendererHost>;
113 friend class MockAudioRendererHost; 133 friend class MockAudioRendererHost;
114 friend class TestAudioRendererHost; 134 friend class TestAudioRendererHost;
115 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream); 135 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, CreateMockStream);
116 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation); 136 FRIEND_TEST_ALL_PREFIXES(AudioRendererHostTest, MockStreamDataConversation);
117 137
118 class AudioEntry; 138 class AudioEntry;
(...skipping 23 matching lines...) Expand all
142 // |session_id| will be ignored and the given |device_id| and 162 // |session_id| will be ignored and the given |device_id| and
143 // |security_origin| will be used to select the output device. 163 // |security_origin| will be used to select the output device.
144 // Upon completion of the process, the peer is notified with the device output 164 // Upon completion of the process, the peer is notified with the device output
145 // parameters via the NotifyDeviceAuthorized message. 165 // parameters via the NotifyDeviceAuthorized message.
146 void OnRequestDeviceAuthorization(int stream_id, 166 void OnRequestDeviceAuthorization(int stream_id,
147 int render_frame_id, 167 int render_frame_id,
148 int session_id, 168 int session_id,
149 const std::string& device_id, 169 const std::string& device_id,
150 const url::Origin& gurl_security_origin); 170 const url::Origin& gurl_security_origin);
151 171
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 172
159 // Play the audio stream referenced by |stream_id|. 173 // Play the audio stream referenced by |stream_id|.
160 void OnPlayStream(int stream_id); 174 void OnPlayStream(int stream_id);
161 175
162 // Pause the audio stream referenced by |stream_id|. 176 // Pause the audio stream referenced by |stream_id|.
163 void OnPauseStream(int stream_id); 177 void OnPauseStream(int stream_id);
164 178
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|. 179 // Set the volume of the audio stream referenced by |stream_id|.
169 void OnSetVolume(int stream_id, double volume); 180 void OnSetVolume(int stream_id, double volume);
170 181
171 // Helper methods. 182 // Helper methods.
172 183
173 // Proceed with device authorization after checking permissions. 184 // Proceed with device authorization after checking permissions.
174 void OnDeviceAuthorized(int stream_id, 185 void OnDeviceAuthorized(int stream_id,
175 const std::string& device_id, 186 const std::string& device_id,
176 const GURL& security_origin, 187 const GURL& security_origin,
177 bool have_access); 188 bool have_access);
178 189
179 // Proceed with device authorization after translating device ID. 190 // Proceed with device authorization after translating device ID.
180 void OnDeviceIDTranslated(int stream_id, 191 void OnDeviceIDTranslated(int stream_id,
181 bool device_found, 192 bool device_found,
182 const AudioOutputDeviceInfo& device_info); 193 const AudioOutputDeviceInfo& device_info);
183 194
184 // Start the actual creation of an audio stream, after the device 195 // Start the actual creation of an audio stream, after the device
185 // authorization process is complete. 196 // authorization process is complete.
186 void DoCreateStream(int stream_id, 197 void DoCreateStream(int stream_id,
187 int render_frame_id, 198 int render_frame_id,
188 const media::AudioParameters& params, 199 const media::AudioParameters& params,
200 const std::string& device_unique_id,
201 AudioOutputStreamPtr stream,
202 const AudioOutput::CreateStreamCallback& callback);
203
204 // Start the actual creation of an audio stream, after the device
205 // authorization process is complete.
206 void DoCreateStream(int stream_id,
207 int render_frame_id,
208 const media::AudioParameters& params,
189 const std::string& device_unique_id); 209 const std::string& device_unique_id);
190 210
191 // Complete the process of creating an audio stream. This will set up the 211 // 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 212 // shared memory or shared socket in low latency mode and send the
193 // NotifyStreamCreated message to the peer. 213 // NotifyStreamCreated message to the peer.
194 void DoCompleteCreation(int stream_id); 214 void DoCompleteCreation(int stream_id);
195 215
216 // Complete the process of creating an audio stream. This will set up the
217 // shared memory or shared socket in low latency mode and send the
218 // NotifyStreamCreated message to the peer.
219 void DoCompleteCreationMojo(
220 int stream_id,
221 const AudioOutput::CreateStreamCallback& callback);
196 // Send playing/paused status to the renderer. 222 // Send playing/paused status to the renderer.
197 void DoNotifyStreamStateChanged(int stream_id, bool is_playing); 223 void DoNotifyStreamStateChanged(int stream_id, bool is_playing);
198 224
199 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const; 225 RenderProcessHost::AudioOutputControllerList DoGetOutputControllers() const;
200 226
201 // Send an error message to the renderer. 227 // Send an error message to the renderer.
202 void SendErrorMessage(int stream_id); 228 void SendErrorMessage(int stream_id);
203 229
204 // Delete an audio entry, notifying observers first. This is called by 230 // Delete an audio entry, notifying observers first. This is called by
205 // AudioOutputController after it has closed. 231 // AudioOutputController after it has closed.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 // Map of device authorizations for streams that are not yet created 286 // 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 287 // 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. 288 // is a bool that is true if the authorization process completes successfully.
263 // The second element contains the unique ID of the authorized device. 289 // The second element contains the unique ID of the authorized device.
264 std::map<int, std::pair<bool, std::string>> authorizations_; 290 std::map<int, std::pair<bool, std::string>> authorizations_;
265 291
266 // The maximum number of simultaneous streams during the lifetime of this 292 // The maximum number of simultaneous streams during the lifetime of this
267 // host. Reported as UMA stat at shutdown. 293 // host. Reported as UMA stat at shutdown.
268 size_t max_simultaneous_streams_; 294 size_t max_simultaneous_streams_;
269 295
296 AudioOutputStreamPtr stream_ptr_;
297
270 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost); 298 DISALLOW_COPY_AND_ASSIGN(AudioRendererHost);
271 }; 299 };
272 300
273 } // namespace content 301 } // namespace content
274 302
275 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_ 303 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_RENDERER_HOST_H_
OLDNEW
« no previous file with comments | « content/browser/media/audio_output_impl.cc ('k') | content/browser/renderer_host/media/audio_renderer_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698