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

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

Issue 1896883002: Mojo interfaces needed for switching audio rendering stream creation and closing from IPC to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: All grunell comments resolved 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 #include "content/browser/renderer_host/media/audio_renderer_host.h" 5 #include "content/browser/renderer_host/media/audio_renderer_host.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 #if defined(OS_WIN)
10 #include <windows.h>
11 #endif
9 12
10 #include "base/bind.h" 13 #include "base/bind.h"
11 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
12 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
13 #include "base/logging.h" 16 #include "base/logging.h"
14 #include "base/memory/shared_memory.h" 17 #include "base/memory/shared_memory.h"
15 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
16 #include "base/process/process.h" 19 #include "base/process/process.h"
17 #include "content/browser/bad_message.h" 20 #include "content/browser/bad_message.h"
18 #include "content/browser/browser_main_loop.h" 21 #include "content/browser/browser_main_loop.h"
19 #include "content/browser/child_process_security_policy_impl.h" 22 #include "content/browser/child_process_security_policy_impl.h"
23 #include "content/browser/media/audio_output_impl.h"
20 #include "content/browser/media/audio_stream_monitor.h" 24 #include "content/browser/media/audio_stream_monitor.h"
21 #include "content/browser/media/capture/audio_mirroring_manager.h" 25 #include "content/browser/media/capture/audio_mirroring_manager.h"
22 #include "content/browser/media/media_internals.h" 26 #include "content/browser/media/media_internals.h"
23 #include "content/browser/renderer_host/media/audio_input_device_manager.h" 27 #include "content/browser/renderer_host/media/audio_input_device_manager.h"
24 #include "content/browser/renderer_host/media/audio_sync_reader.h" 28 #include "content/browser/renderer_host/media/audio_sync_reader.h"
25 #include "content/browser/renderer_host/media/media_stream_manager.h" 29 #include "content/browser/renderer_host/media/media_stream_manager.h"
26 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 30 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
27 #include "content/browser/renderer_host/render_widget_host_impl.h" 31 #include "content/browser/renderer_host/render_widget_host_impl.h"
28 #include "content/common/media/audio_messages.h" 32 #include "content/common/media/audio_messages.h"
29 #include "content/public/browser/content_browser_client.h" 33 #include "content/public/browser/content_browser_client.h"
30 #include "content/public/browser/media_device_id.h" 34 #include "content/public/browser/media_device_id.h"
31 #include "content/public/browser/media_observer.h" 35 #include "content/public/browser/media_observer.h"
32 #include "content/public/browser/render_frame_host.h" 36 #include "content/public/browser/render_frame_host.h"
33 #include "content/public/common/content_switches.h" 37 #include "content/public/common/content_switches.h"
34 #include "media/audio/audio_device_name.h" 38 #include "media/audio/audio_device_name.h"
35 #include "media/audio/audio_manager_base.h" 39 #include "media/audio/audio_manager_base.h"
36 #include "media/audio/audio_streams_tracker.h" 40 #include "media/audio/audio_streams_tracker.h"
37 #include "media/base/audio_bus.h" 41 #include "media/base/audio_bus.h"
38 #include "media/base/limits.h" 42 #include "media/base/limits.h"
43 #include "mojo/edk/embedder/embedder.h"
44 #include "mojo/public/cpp/system/handle.h"
39 45
40 using media::AudioBus; 46 using media::AudioBus;
41 using media::AudioManager; 47 using media::AudioManager;
42 48
43 namespace content { 49 namespace content {
44 50
45 namespace { 51 namespace {
46 52
47 // Tracks the maximum number of simultaneous output streams browser-wide. 53 // Tracks the maximum number of simultaneous output streams browser-wide.
48 // Accessed on IO thread. 54 // Accessed on IO thread.
49 base::LazyInstance<media::AudioStreamsTracker> g_audio_streams_tracker = 55 base::LazyInstance<media::AudioStreamsTracker> g_audio_streams_tracker =
50 LAZY_INSTANCE_INITIALIZER; 56 LAZY_INSTANCE_INITIALIZER;
51 57
52 std::pair<int, std::pair<bool, std::string>> MakeAuthorizationData( 58 std::pair<int, std::pair<bool, std::string>> MakeAuthorizationData(
53 int stream_id, 59 int stream_id,
54 bool authorized, 60 bool authorized,
55 const std::string& device_unique_id) { 61 const std::string& device_unique_id) {
56 return std::make_pair(stream_id, 62 return std::make_pair(stream_id,
57 std::make_pair(authorized, device_unique_id)); 63 std::make_pair(authorized, device_unique_id));
58 } 64 }
59 65
60 GURL ConvertToGURL(const url::Origin& origin) { 66 GURL ConvertToGURL(const url::Origin& origin) {
61 return origin.unique() ? GURL() : GURL(origin.Serialize()); 67 return origin.unique() ? GURL() : GURL(origin.Serialize());
62 } 68 }
63 69
70 base::SyncSocket::TransitDescriptor DuplicateSocket(
71 base::SyncSocket::TransitDescriptor socket_descriptor) {
72 base::SyncSocket::TransitDescriptor socket_descriptor_dup;
tommi (sloooow) - chröme 2016/04/26 15:29:53 Initialize please. As is, you might be returning a
rchtara 2016/04/29 12:54:46 Done.
73
74 #if defined(OS_WIN)
75 ::DuplicateHandle(GetCurrentProcess(), // hSourceProcessHandle
tommi (sloooow) - chröme 2016/04/26 15:29:53 check the return value?
rchtara 2016/04/29 12:54:46 Done.
76 socket_descriptor,
77 GetCurrentProcess(), // hTargetProcessHandle
78 &socket_descriptor_dup,
79 0, // dwDesiredAccess ignored due to SAME_ACCESS
80 FALSE, // !bInheritHandle
81 DUPLICATE_SAME_ACCESS);
82
83 #else
84 socket_descriptor_dup.fd = dup(socket_descriptor.fd);
85 #endif
86 return socket_descriptor_dup;
87 }
88
64 bool IsValidDeviceId(const std::string& device_id) { 89 bool IsValidDeviceId(const std::string& device_id) {
65 static const std::string::size_type kValidLength = 64; 90 static const std::string::size_type kValidLength = 64;
66 91
67 if (device_id.empty() || 92 if (device_id.empty() ||
68 device_id == media::AudioManagerBase::kDefaultDeviceId || 93 device_id == media::AudioManagerBase::kDefaultDeviceId ||
69 device_id == media::AudioManagerBase::kCommunicationsDeviceId) { 94 device_id == media::AudioManagerBase::kCommunicationsDeviceId) {
70 return true; 95 return true;
71 } 96 }
72 97
73 if (device_id.length() != kValidLength) 98 if (device_id.length() != kValidLength)
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 144
120 class AudioRendererHost::AudioEntry 145 class AudioRendererHost::AudioEntry
121 : public media::AudioOutputController::EventHandler { 146 : public media::AudioOutputController::EventHandler {
122 public: 147 public:
123 AudioEntry(AudioRendererHost* host, 148 AudioEntry(AudioRendererHost* host,
124 int stream_id, 149 int stream_id,
125 int render_frame_id, 150 int render_frame_id,
126 const media::AudioParameters& params, 151 const media::AudioParameters& params,
127 const std::string& output_device_id, 152 const std::string& output_device_id,
128 std::unique_ptr<base::SharedMemory> shared_memory, 153 std::unique_ptr<base::SharedMemory> shared_memory,
129 std::unique_ptr<media::AudioOutputController::SyncReader> reader); 154 std::unique_ptr<media::AudioOutputController::SyncReader> reader,
155 const mojom::AudioOutput::CreateStreamCallback& callback);
130 ~AudioEntry() override; 156 ~AudioEntry() override;
131 157
132 int stream_id() const { 158 int stream_id() const {
133 return stream_id_; 159 return stream_id_;
134 } 160 }
135 161
136 int render_frame_id() const { return render_frame_id_; } 162 int render_frame_id() const { return render_frame_id_; }
137 163
138 media::AudioOutputController* controller() const { return controller_.get(); } 164 media::AudioOutputController* controller() const { return controller_.get(); }
139 165
140 base::SharedMemory* shared_memory() { 166 base::SharedMemory* shared_memory() {
141 return shared_memory_.get(); 167 return shared_memory_.get();
142 } 168 }
143 169
144 media::AudioOutputController::SyncReader* reader() const { 170 media::AudioOutputController::SyncReader* reader() const {
145 return reader_.get(); 171 return reader_.get();
146 } 172 }
147 173
148 bool playing() const { return playing_; } 174 bool playing() const { return playing_; }
149 void set_playing(bool playing) { playing_ = playing; } 175 void set_playing(bool playing) { playing_ = playing; }
150 176
151 private: 177 private:
152 // media::AudioOutputController::EventHandler implementation. 178 // media::AudioOutputController::EventHandler implementation.
153 void OnCreated() override; 179 void OnCreated(
180 const mojom::AudioOutput::CreateStreamCallback& callback) override;
154 void OnPlaying() override; 181 void OnPlaying() override;
155 void OnPaused() override; 182 void OnPaused() override;
156 void OnError() override; 183 void OnError() override;
157 184
158 AudioRendererHost* const host_; 185 AudioRendererHost* const host_;
159 const int stream_id_; 186 const int stream_id_;
160 187
161 // The routing ID of the source RenderFrame. 188 // The routing ID of the source RenderFrame.
162 const int render_frame_id_; 189 const int render_frame_id_;
163 190
164 // Shared memory for transmission of the audio data. Used by |reader_|. 191 // Shared memory for transmission of the audio data. Used by |reader_|.
165 const std::unique_ptr<base::SharedMemory> shared_memory_; 192 const std::unique_ptr<base::SharedMemory> shared_memory_;
166 193
167 // The synchronous reader to be used by |controller_|. 194 // The synchronous reader to be used by |controller_|.
168 const std::unique_ptr<media::AudioOutputController::SyncReader> reader_; 195 const std::unique_ptr<media::AudioOutputController::SyncReader> reader_;
169 196
170 // The AudioOutputController that manages the audio stream. 197 // The AudioOutputController that manages the audio stream.
171 const scoped_refptr<media::AudioOutputController> controller_; 198 const scoped_refptr<media::AudioOutputController> controller_;
172 199
173 bool playing_; 200 bool playing_;
174 }; 201 };
175 202
176 AudioRendererHost::AudioEntry::AudioEntry( 203 AudioRendererHost::AudioEntry::AudioEntry(
177 AudioRendererHost* host, 204 AudioRendererHost* host,
178 int stream_id, 205 int stream_id,
179 int render_frame_id, 206 int render_frame_id,
180 const media::AudioParameters& params, 207 const media::AudioParameters& params,
181 const std::string& output_device_id, 208 const std::string& output_device_id,
182 std::unique_ptr<base::SharedMemory> shared_memory, 209 std::unique_ptr<base::SharedMemory> shared_memory,
183 std::unique_ptr<media::AudioOutputController::SyncReader> reader) 210 std::unique_ptr<media::AudioOutputController::SyncReader> reader,
211 const mojom::AudioOutput::CreateStreamCallback& callback)
184 : host_(host), 212 : host_(host),
185 stream_id_(stream_id), 213 stream_id_(stream_id),
186 render_frame_id_(render_frame_id), 214 render_frame_id_(render_frame_id),
187 shared_memory_(std::move(shared_memory)), 215 shared_memory_(std::move(shared_memory)),
188 reader_(std::move(reader)), 216 reader_(std::move(reader)),
189 controller_(media::AudioOutputController::Create(host->audio_manager_, 217 controller_(media::AudioOutputController::Create(host->audio_manager_,
190 this, 218 this,
191 params, 219 params,
192 output_device_id, 220 output_device_id,
193 reader_.get())), 221 reader_.get(),
222 callback)),
194 playing_(false) { 223 playing_(false) {
195 DCHECK(controller_.get()); 224 DCHECK(controller_.get());
196 } 225 }
197 226
198 AudioRendererHost::AudioEntry::~AudioEntry() {} 227 AudioRendererHost::AudioEntry::~AudioEntry() {}
199 228
200 /////////////////////////////////////////////////////////////////////////////// 229 ///////////////////////////////////////////////////////////////////////////////
201 // AudioRendererHost implementations. 230 // AudioRendererHost implementations.
202 231
203 AudioRendererHost::AudioRendererHost( 232 AudioRendererHost::AudioRendererHost(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 } 284 }
256 285
257 // Remove any authorizations for streams that were not yet created 286 // Remove any authorizations for streams that were not yet created
258 authorizations_.clear(); 287 authorizations_.clear();
259 } 288 }
260 289
261 void AudioRendererHost::OnDestruct() const { 290 void AudioRendererHost::OnDestruct() const {
262 BrowserThread::DeleteOnIOThread::Destruct(this); 291 BrowserThread::DeleteOnIOThread::Destruct(this);
263 } 292 }
264 293
265 void AudioRendererHost::AudioEntry::OnCreated() { 294 void AudioRendererHost::AudioEntry::OnCreated(
266 BrowserThread::PostTask( 295 const mojom::AudioOutput::CreateStreamCallback& callback) {
267 BrowserThread::IO, 296 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
268 FROM_HERE, 297 base::Bind(&AudioRendererHost::DoCompleteCreation,
269 base::Bind(&AudioRendererHost::DoCompleteCreation, host_, stream_id_)); 298 host_, stream_id_, callback));
270 } 299 }
271 300
272 void AudioRendererHost::AudioEntry::OnPlaying() { 301 void AudioRendererHost::AudioEntry::OnPlaying() {
273 BrowserThread::PostTask( 302 BrowserThread::PostTask(
274 BrowserThread::IO, 303 BrowserThread::IO,
275 FROM_HERE, 304 FROM_HERE,
276 base::Bind(&AudioRendererHost::DoNotifyStreamStateChanged, 305 base::Bind(&AudioRendererHost::DoNotifyStreamStateChanged,
277 host_, 306 host_,
278 stream_id_, 307 stream_id_,
279 true)); 308 true));
280 } 309 }
281 310
282 void AudioRendererHost::AudioEntry::OnPaused() { 311 void AudioRendererHost::AudioEntry::OnPaused() {
283 BrowserThread::PostTask( 312 BrowserThread::PostTask(
284 BrowserThread::IO, 313 BrowserThread::IO,
285 FROM_HERE, 314 FROM_HERE,
286 base::Bind(&AudioRendererHost::DoNotifyStreamStateChanged, 315 base::Bind(&AudioRendererHost::DoNotifyStreamStateChanged,
287 host_, 316 host_,
288 stream_id_, 317 stream_id_,
289 false)); 318 false));
290 } 319 }
291 320
292 void AudioRendererHost::AudioEntry::OnError() { 321 void AudioRendererHost::AudioEntry::OnError() {
293 BrowserThread::PostTask( 322 BrowserThread::PostTask(
294 BrowserThread::IO, 323 BrowserThread::IO,
295 FROM_HERE, 324 FROM_HERE,
296 base::Bind(&AudioRendererHost::ReportErrorAndClose, host_, stream_id_)); 325 base::Bind(&AudioRendererHost::ReportErrorAndClose, host_, stream_id_));
297 } 326 }
298 327
299 void AudioRendererHost::DoCompleteCreation(int stream_id) { 328 void AudioRendererHost::DoCompleteCreation(
329 int stream_id,
330 const mojom::AudioOutput::CreateStreamCallback& callback) {
300 DCHECK_CURRENTLY_ON(BrowserThread::IO); 331 DCHECK_CURRENTLY_ON(BrowserThread::IO);
301 332
302 if (!PeerHandle()) { 333 if (!PeerHandle()) {
303 DLOG(WARNING) << "Renderer process handle is invalid."; 334 DLOG(WARNING) << "Renderer process handle is invalid.";
304 ReportErrorAndClose(stream_id); 335 ReportErrorAndCloseStream(stream_id, callback);
305 return; 336 return;
306 } 337 }
307 338
308 AudioEntry* const entry = LookupById(stream_id); 339 AudioEntry* const entry = LookupById(stream_id);
309 if (!entry) { 340 if (!entry) {
310 ReportErrorAndClose(stream_id); 341 ReportErrorAndCloseStream(stream_id, callback);
311 return; 342 return;
312 } 343 }
313 344
314 // Once the audio stream is created then complete the creation process by 345 std::unique_ptr<mojom::AudioOutputStreamPtr> stream_ptr(
xhwang 2016/04/26 22:54:42 AudioOutputStreamPtr is an InterfacePtr which is a
rchtara 2016/04/29 12:54:46 Done.
315 // mapping shared memory and sharing with the renderer process. 346 audio_output_impl_->StreamFactory(stream_id, this));
316 base::SharedMemoryHandle foreign_memory_handle; 347
317 if (!entry->shared_memory()->ShareToProcess(PeerHandle(), 348 base::SharedMemoryHandle shared_memory_handle =
318 &foreign_memory_handle)) { 349 base::SharedMemory::DuplicateHandle(entry->shared_memory()->handle());
319 // If we failed to map and share the shared memory then close the audio 350
320 // stream and send an error message. 351 MojoHandle mojo_foreign_memory_handle;
321 ReportErrorAndClose(entry->stream_id()); 352
353 MojoResult shared_buffer_result = mojo::edk::CreateSharedBufferWrapper(
354 shared_memory_handle, entry->shared_memory()->requested_size(), false,
355 &mojo_foreign_memory_handle);
356
357 if (shared_buffer_result != MOJO_RESULT_OK) {
358 DLOG(WARNING) << "Failed to wrap transit descriptor. Closing: "
359 << shared_buffer_result;
360 ReportErrorAndCloseStream(entry->stream_id(), callback);
322 return; 361 return;
323 } 362 }
324 363
325 AudioSyncReader* reader = static_cast<AudioSyncReader*>(entry->reader()); 364 AudioSyncReader* reader = static_cast<AudioSyncReader*>(entry->reader());
326 365
327 base::SyncSocket::TransitDescriptor socket_descriptor; 366 base::SyncSocket::TransitDescriptor socket_descriptor;
328 367
329 // If we failed to prepare the sync socket for the renderer then we fail 368 // If we failed to prepare the sync socket for the renderer then we fail
330 // the construction of audio stream. 369 // the construction of audio stream.
331 if (!reader->PrepareForeignSocket(PeerHandle(), &socket_descriptor)) { 370 if (!reader->PrepareForeignSocket(PeerHandle(), &socket_descriptor)) {
332 ReportErrorAndClose(entry->stream_id()); 371 ReportErrorAndCloseStream(entry->stream_id(), callback);
372 return;
373 }
374 mojo::ScopedSharedBufferHandle shared_buffer_handle =
375 mojo::ScopedSharedBufferHandle(
376 mojo::SharedBufferHandle(mojo_foreign_memory_handle));
377
378 MojoHandle socket_descriptor_handle;
379 MojoResult platform_handle_result;
380
381 // The socket handle is going to be closed when |mojo_application_host_| is
Henrik Grunell 2016/04/22 08:23:04 Why do we need two handles actually? Only one is u
rchtara 2016/04/29 12:54:46 yes.
382 // reset. AudioOutputIPCDelegate is going to need to close the socket handle
383 // too when the steam it controls is closed. This is going to cause an issue
384 // because both of them are going to close the same socket handle.
385 // This is why a duplicate of the socket handler is going to be created,
386 // stored in |socket_descriptor_dup| and sent through Mojo to the renderer so
387 // it can be used by AudioOutputIPCDelegate.
388
389 base::SyncSocket::TransitDescriptor socket_descriptor_dup =
390 DuplicateSocket(socket_descriptor);
391 #if defined(OS_WIN)
392 platform_handle_result = mojo::edk::CreatePlatformHandleWrapper(
393 mojo::edk::ScopedPlatformHandle(
394 mojo::edk::PlatformHandle(socket_descriptor_dup),
395 &socket_descriptor_handle);
396 #else
397 platform_handle_result = mojo::edk::CreatePlatformHandleWrapper(
398 mojo::edk::ScopedPlatformHandle(
399 mojo::edk::PlatformHandle(socket_descriptor_dup.fd)),
400 &socket_descriptor_handle);
401 #endif
402
403 if (platform_handle_result != MOJO_RESULT_OK) {
404 DLOG(WARNING) << "Failed to wrap platform handle. Closing: "
405 << platform_handle_result;
406 ReportErrorAndCloseStream(stream_id, callback);
333 return; 407 return;
334 } 408 }
335 409
336 Send(new AudioMsg_NotifyStreamCreated( 410 mojo::ScopedHandle socket_handle =
337 entry->stream_id(), foreign_memory_handle, socket_descriptor, 411 mojo::ScopedHandle(mojo::Handle(socket_descriptor_handle));
338 entry->shared_memory()->requested_size())); 412 callback.Run(stream_id, std::move(*stream_ptr),
413 std::move(shared_buffer_handle), std::move(socket_handle));
414
339 } 415 }
340 416
341 void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id, 417 void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id,
342 bool is_playing) { 418 bool is_playing) {
343 DCHECK_CURRENTLY_ON(BrowserThread::IO); 419 DCHECK_CURRENTLY_ON(BrowserThread::IO);
344 420
345 AudioEntry* const entry = LookupById(stream_id); 421 AudioEntry* const entry = LookupById(stream_id);
346 if (!entry) 422 if (!entry)
347 return; 423 return;
348 424
(...skipping 30 matching lines...) Expand all
379 return controllers; 455 return controllers;
380 } 456 }
381 457
382 /////////////////////////////////////////////////////////////////////////////// 458 ///////////////////////////////////////////////////////////////////////////////
383 // IPC Messages handler 459 // IPC Messages handler
384 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message) { 460 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message) {
385 bool handled = true; 461 bool handled = true;
386 IPC_BEGIN_MESSAGE_MAP(AudioRendererHost, message) 462 IPC_BEGIN_MESSAGE_MAP(AudioRendererHost, message)
387 IPC_MESSAGE_HANDLER(AudioHostMsg_RequestDeviceAuthorization, 463 IPC_MESSAGE_HANDLER(AudioHostMsg_RequestDeviceAuthorization,
388 OnRequestDeviceAuthorization) 464 OnRequestDeviceAuthorization)
389 IPC_MESSAGE_HANDLER(AudioHostMsg_CreateStream, OnCreateStream)
390 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream) 465 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream)
391 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream) 466 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream)
392 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream) 467 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream)
393 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) 468 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume)
394 IPC_MESSAGE_UNHANDLED(handled = false) 469 IPC_MESSAGE_UNHANDLED(handled = false)
395 IPC_END_MESSAGE_MAP() 470 IPC_END_MESSAGE_MAP()
396 471
397 return handled; 472 return handled;
398 } 473 }
399 474
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 593
519 auth_data->second.first = true; 594 auth_data->second.first = true;
520 auth_data->second.second = device_info.unique_id; 595 auth_data->second.second = device_info.unique_id;
521 596
522 media::AudioParameters output_params = device_info.output_params; 597 media::AudioParameters output_params = device_info.output_params;
523 MaybeFixAudioParameters(&output_params); 598 MaybeFixAudioParameters(&output_params);
524 Send(new AudioMsg_NotifyDeviceAuthorized( 599 Send(new AudioMsg_NotifyDeviceAuthorized(
525 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params, std::string())); 600 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params, std::string()));
526 } 601 }
527 602
528 void AudioRendererHost::OnCreateStream(int stream_id, 603 void AudioRendererHost::CreateStream(
529 int render_frame_id, 604 int stream_id,
530 const media::AudioParameters& params) { 605 int render_frame_id,
606 const media::AudioParameters& params,
607 const mojom::AudioOutput::CreateStreamCallback& callback) {
531 DCHECK_CURRENTLY_ON(BrowserThread::IO); 608 DCHECK_CURRENTLY_ON(BrowserThread::IO);
532 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" 609 DVLOG(1) << "AudioRendererHost@" << this << "::CreateStream"
533 << "(stream_id=" << stream_id << ")"; 610 << "(stream_id=" << stream_id << ")";
534 611
535 const auto& auth_data = authorizations_.find(stream_id); 612 const auto& auth_data = authorizations_.find(stream_id);
536 613
537 // If no previous authorization requested, assume default device 614 // If no previous authorization requested, assume default device
538 if (auth_data == authorizations_.end()) { 615 if (auth_data == authorizations_.end()) {
539 DoCreateStream(stream_id, render_frame_id, params, std::string()); 616 DoCreateStream(stream_id, render_frame_id, params, std::string(), callback);
540 return; 617 return;
541 } 618 }
542 619
543 CHECK(auth_data->second.first); 620 CHECK(auth_data->second.first);
544 DoCreateStream(stream_id, render_frame_id, params, auth_data->second.second); 621 DoCreateStream(stream_id, render_frame_id, params, auth_data->second.second,
622 callback);
545 authorizations_.erase(auth_data); 623 authorizations_.erase(auth_data);
546 } 624 }
547 625
548 void AudioRendererHost::DoCreateStream(int stream_id, 626 void AudioRendererHost::DoCreateStream(
549 int render_frame_id, 627 int stream_id,
550 const media::AudioParameters& params, 628 int render_frame_id,
551 const std::string& device_unique_id) { 629 const media::AudioParameters& params,
630 const std::string& device_unique_id,
631 const mojom::AudioOutput::CreateStreamCallback& callback) {
552 DCHECK_CURRENTLY_ON(BrowserThread::IO); 632 DCHECK_CURRENTLY_ON(BrowserThread::IO);
553 633
554 // media::AudioParameters is validated in the deserializer. 634 // media::AudioParameters is validated in the deserializer.
555 if (LookupById(stream_id) != NULL) { 635 if (LookupById(stream_id) != NULL) {
556 SendErrorMessage(stream_id); 636 SendErrorMessage(stream_id);
557 return; 637 return;
558 } 638 }
559 639
560 // Create the shared memory and share with the renderer process. 640 // Create the shared memory and share with the renderer process.
561 uint32_t shared_memory_size = sizeof(media::AudioOutputBufferParameters) + 641 uint32_t shared_memory_size = sizeof(media::AudioOutputBufferParameters) +
(...skipping 11 matching lines...) Expand all
573 return; 653 return;
574 } 654 }
575 655
576 MediaObserver* const media_observer = 656 MediaObserver* const media_observer =
577 GetContentClient()->browser()->GetMediaObserver(); 657 GetContentClient()->browser()->GetMediaObserver();
578 if (media_observer) 658 if (media_observer)
579 media_observer->OnCreatingAudioStream(render_process_id_, render_frame_id); 659 media_observer->OnCreatingAudioStream(render_process_id_, render_frame_id);
580 660
581 std::unique_ptr<AudioEntry> entry( 661 std::unique_ptr<AudioEntry> entry(
582 new AudioEntry(this, stream_id, render_frame_id, params, device_unique_id, 662 new AudioEntry(this, stream_id, render_frame_id, params, device_unique_id,
583 std::move(shared_memory), std::move(reader))); 663 std::move(shared_memory), std::move(reader), callback));
584 if (mirroring_manager_) { 664 if (mirroring_manager_) {
585 mirroring_manager_->AddDiverter( 665 mirroring_manager_->AddDiverter(
586 render_process_id_, entry->render_frame_id(), entry->controller()); 666 render_process_id_, entry->render_frame_id(), entry->controller());
587 } 667 }
588 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 668 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
589 g_audio_streams_tracker.Get().IncreaseStreamCount(); 669 g_audio_streams_tracker.Get().IncreaseStreamCount();
590 670
591 audio_log_->OnCreated(stream_id, params, device_unique_id); 671 audio_log_->OnCreated(stream_id, params, device_unique_id);
592 MediaInternals::GetInstance()->SetWebContentsTitleForAudioLogEntry( 672 MediaInternals::GetInstance()->SetWebContentsTitleForAudioLogEntry(
593 stream_id, render_process_id_, render_frame_id, audio_log_.get()); 673 stream_id, render_process_id_, render_frame_id, audio_log_.get());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 // is closed. 766 // is closed.
687 if (!LookupById(stream_id)) 767 if (!LookupById(stream_id))
688 return; 768 return;
689 769
690 SendErrorMessage(stream_id); 770 SendErrorMessage(stream_id);
691 771
692 audio_log_->OnError(stream_id); 772 audio_log_->OnError(stream_id);
693 OnCloseStream(stream_id); 773 OnCloseStream(stream_id);
694 } 774 }
695 775
776 void AudioRendererHost::ReportErrorAndCloseStream(
777 int stream_id,
778 const mojom::AudioOutput::CreateStreamCallback& callback) {
779 DCHECK_CURRENTLY_ON(BrowserThread::IO);
780
781 // Make sure this isn't a stray callback executing after the stream has been
782 // closed, so error notifications aren't sent after clients believe the stream
783 // is closed.
784 if (!LookupById(stream_id))
785 return;
786 mojo::ScopedSharedBufferHandle shared_buffer_handle =
787 mojo::ScopedSharedBufferHandle(mojo::SharedBufferHandle());
788
789 mojo::ScopedHandle socket_handle = mojo::ScopedHandle(mojo::Handle());
790
791 callback.Run(stream_id, mojom::AudioOutputStreamPtr(),
792 std::move(shared_buffer_handle), std::move(socket_handle));
793
794 audio_log_->OnError(stream_id);
795 OnCloseStream(stream_id);
796 }
797
696 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { 798 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) {
697 DCHECK_CURRENTLY_ON(BrowserThread::IO); 799 DCHECK_CURRENTLY_ON(BrowserThread::IO);
698 800
699 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); 801 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id);
700 return i != audio_entries_.end() ? i->second : NULL; 802 return i != audio_entries_.end() ? i->second : NULL;
701 } 803 }
702 804
703 void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry, 805 void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry,
704 bool is_playing) { 806 bool is_playing) {
705 DCHECK_CURRENTLY_ON(BrowserThread::IO); 807 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 callback.Run(false, device_info); 917 callback.Run(false, device_info);
816 } 918 }
817 919
818 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { 920 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) {
819 DCHECK_CURRENTLY_ON(BrowserThread::IO); 921 DCHECK_CURRENTLY_ON(BrowserThread::IO);
820 const auto& i = authorizations_.find(stream_id); 922 const auto& i = authorizations_.find(stream_id);
821 return i != authorizations_.end(); 923 return i != authorizations_.end();
822 } 924 }
823 925
824 } // namespace content 926 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698