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 #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 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/shared_memory.h" | 14 #include "base/memory/shared_memory.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/process/process.h" | 16 #include "base/process/process.h" |
17 #include "content/browser/bad_message.h" | 17 #include "content/browser/bad_message.h" |
18 #include "content/browser/browser_main_loop.h" | 18 #include "content/browser/browser_main_loop.h" |
| 19 #include "content/browser/media/audio_output_impl.h" |
19 #include "content/browser/media/audio_stream_monitor.h" | 20 #include "content/browser/media/audio_stream_monitor.h" |
20 #include "content/browser/media/capture/audio_mirroring_manager.h" | 21 #include "content/browser/media/capture/audio_mirroring_manager.h" |
21 #include "content/browser/media/media_internals.h" | 22 #include "content/browser/media/media_internals.h" |
22 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 23 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
23 #include "content/browser/renderer_host/media/audio_sync_reader.h" | 24 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
24 #include "content/browser/renderer_host/media/media_stream_manager.h" | 25 #include "content/browser/renderer_host/media/media_stream_manager.h" |
25 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 26 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
26 #include "content/browser/renderer_host/render_widget_host_impl.h" | 27 #include "content/browser/renderer_host/render_widget_host_impl.h" |
27 #include "content/common/media/audio_messages.h" | 28 #include "content/common/media/audio_messages.h" |
28 #include "content/public/browser/content_browser_client.h" | 29 #include "content/public/browser/content_browser_client.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 114 |
114 class AudioRendererHost::AudioEntry | 115 class AudioRendererHost::AudioEntry |
115 : public media::AudioOutputController::EventHandler { | 116 : public media::AudioOutputController::EventHandler { |
116 public: | 117 public: |
117 AudioEntry(AudioRendererHost* host, | 118 AudioEntry(AudioRendererHost* host, |
118 int stream_id, | 119 int stream_id, |
119 int render_frame_id, | 120 int render_frame_id, |
120 const media::AudioParameters& params, | 121 const media::AudioParameters& params, |
121 const std::string& output_device_id, | 122 const std::string& output_device_id, |
122 std::unique_ptr<base::SharedMemory> shared_memory, | 123 std::unique_ptr<base::SharedMemory> shared_memory, |
123 std::unique_ptr<media::AudioOutputController::SyncReader> reader); | 124 std::unique_ptr<media::AudioOutputController::SyncReader> reader, |
| 125 AudioOutputImpl* audio_output_impl); |
124 ~AudioEntry() override; | 126 ~AudioEntry() override; |
125 | 127 |
126 int stream_id() const { | 128 int stream_id() const { |
127 return stream_id_; | 129 return stream_id_; |
128 } | 130 } |
129 | 131 |
130 int render_frame_id() const { return render_frame_id_; } | 132 int render_frame_id() const { return render_frame_id_; } |
131 | 133 |
132 media::AudioOutputController* controller() const { return controller_.get(); } | 134 media::AudioOutputController* controller() const { return controller_.get(); } |
133 | 135 |
134 base::SharedMemory* shared_memory() { | 136 base::SharedMemory* shared_memory() { |
135 return shared_memory_.get(); | 137 return shared_memory_.get(); |
136 } | 138 } |
137 | 139 |
138 media::AudioOutputController::SyncReader* reader() const { | 140 media::AudioOutputController::SyncReader* reader() const { |
139 return reader_.get(); | 141 return reader_.get(); |
140 } | 142 } |
141 | 143 |
142 bool playing() const { return playing_; } | 144 bool playing() const { return playing_; } |
143 void set_playing(bool playing) { playing_ = playing; } | 145 void set_playing(bool playing) { playing_ = playing; } |
144 | 146 |
| 147 AudioOutputImpl* audio_output_impl() { return audio_output_impl_; } |
| 148 |
145 private: | 149 private: |
146 // media::AudioOutputController::EventHandler implementation. | 150 // media::AudioOutputController::EventHandler implementation. |
147 void OnCreated() override; | 151 void OnCreated() override; |
148 void OnPlaying() override; | 152 void OnPlaying() override; |
149 void OnPaused() override; | 153 void OnPaused() override; |
150 void OnError() override; | 154 void OnError() override; |
151 | 155 |
152 AudioRendererHost* const host_; | 156 AudioRendererHost* const host_; |
153 const int stream_id_; | 157 const int stream_id_; |
154 | 158 |
155 // The routing ID of the source RenderFrame. | 159 // The routing ID of the source RenderFrame. |
156 const int render_frame_id_; | 160 const int render_frame_id_; |
157 | 161 |
158 // Shared memory for transmission of the audio data. Used by |reader_|. | 162 // Shared memory for transmission of the audio data. Used by |reader_|. |
159 const std::unique_ptr<base::SharedMemory> shared_memory_; | 163 const std::unique_ptr<base::SharedMemory> shared_memory_; |
160 | 164 |
161 // The synchronous reader to be used by |controller_|. | 165 // The synchronous reader to be used by |controller_|. |
162 const std::unique_ptr<media::AudioOutputController::SyncReader> reader_; | 166 const std::unique_ptr<media::AudioOutputController::SyncReader> reader_; |
163 | 167 |
164 // The AudioOutputController that manages the audio stream. | 168 // The AudioOutputController that manages the audio stream. |
165 const scoped_refptr<media::AudioOutputController> controller_; | 169 const scoped_refptr<media::AudioOutputController> controller_; |
166 | 170 |
| 171 AudioOutputImpl* audio_output_impl_; |
| 172 |
167 bool playing_; | 173 bool playing_; |
168 }; | 174 }; |
169 | 175 |
170 AudioRendererHost::AudioEntry::AudioEntry( | 176 AudioRendererHost::AudioEntry::AudioEntry( |
171 AudioRendererHost* host, | 177 AudioRendererHost* host, |
172 int stream_id, | 178 int stream_id, |
173 int render_frame_id, | 179 int render_frame_id, |
174 const media::AudioParameters& params, | 180 const media::AudioParameters& params, |
175 const std::string& output_device_id, | 181 const std::string& output_device_id, |
176 std::unique_ptr<base::SharedMemory> shared_memory, | 182 std::unique_ptr<base::SharedMemory> shared_memory, |
177 std::unique_ptr<media::AudioOutputController::SyncReader> reader) | 183 std::unique_ptr<media::AudioOutputController::SyncReader> reader, |
| 184 AudioOutputImpl* audio_output_impl) |
178 : host_(host), | 185 : host_(host), |
179 stream_id_(stream_id), | 186 stream_id_(stream_id), |
180 render_frame_id_(render_frame_id), | 187 render_frame_id_(render_frame_id), |
181 shared_memory_(std::move(shared_memory)), | 188 shared_memory_(std::move(shared_memory)), |
182 reader_(std::move(reader)), | 189 reader_(std::move(reader)), |
183 controller_(media::AudioOutputController::Create(host->audio_manager_, | 190 controller_(media::AudioOutputController::Create(host->audio_manager_, |
184 this, | 191 this, |
185 params, | 192 params, |
186 output_device_id, | 193 output_device_id, |
187 reader_.get())), | 194 reader_.get())), |
| 195 audio_output_impl_(audio_output_impl), |
188 playing_(false) { | 196 playing_(false) { |
189 DCHECK(controller_.get()); | 197 DCHECK(controller_.get()); |
190 } | 198 } |
191 | 199 |
192 AudioRendererHost::AudioEntry::~AudioEntry() {} | 200 AudioRendererHost::AudioEntry::~AudioEntry() {} |
193 | 201 |
194 /////////////////////////////////////////////////////////////////////////////// | 202 /////////////////////////////////////////////////////////////////////////////// |
195 // AudioRendererHost implementations. | 203 // AudioRendererHost implementations. |
196 | 204 |
197 AudioRendererHost::AudioRendererHost( | 205 AudioRendererHost::AudioRendererHost( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 callback) const { | 246 callback) const { |
239 BrowserThread::PostTaskAndReplyWithResult( | 247 BrowserThread::PostTaskAndReplyWithResult( |
240 BrowserThread::IO, FROM_HERE, | 248 BrowserThread::IO, FROM_HERE, |
241 base::Bind(&AudioRendererHost::DoGetOutputControllers, this), callback); | 249 base::Bind(&AudioRendererHost::DoGetOutputControllers, this), callback); |
242 } | 250 } |
243 | 251 |
244 void AudioRendererHost::OnChannelClosing() { | 252 void AudioRendererHost::OnChannelClosing() { |
245 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 253 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
246 // Since the IPC sender is gone, close all requested audio streams. | 254 // Since the IPC sender is gone, close all requested audio streams. |
247 while (!audio_entries_.empty()) { | 255 while (!audio_entries_.empty()) { |
248 // Note: OnCloseStream() removes the entries from audio_entries_. | 256 // Note: CloseStream() removes the entries from audio_entries_. |
249 OnCloseStream(audio_entries_.begin()->first); | 257 CloseStream(audio_entries_.begin()->first); |
250 } | 258 } |
251 | 259 |
252 // Remove any authorizations for streams that were not yet created | 260 // Remove any authorizations for streams that were not yet created |
253 authorizations_.clear(); | 261 authorizations_.clear(); |
254 } | 262 } |
255 | 263 |
256 void AudioRendererHost::OnDestruct() const { | 264 void AudioRendererHost::OnDestruct() const { |
257 BrowserThread::DeleteOnIOThread::Destruct(this); | 265 BrowserThread::DeleteOnIOThread::Destruct(this); |
258 } | 266 } |
259 | 267 |
260 void AudioRendererHost::AudioEntry::OnCreated() { | 268 void AudioRendererHost::AudioEntry::OnCreated() { |
261 BrowserThread::PostTask( | 269 BrowserThread::PostTask( |
262 BrowserThread::IO, | 270 BrowserThread::IO, FROM_HERE, |
263 FROM_HERE, | |
264 base::Bind(&AudioRendererHost::DoCompleteCreation, host_, stream_id_)); | 271 base::Bind(&AudioRendererHost::DoCompleteCreation, host_, stream_id_)); |
265 } | 272 } |
266 | 273 |
267 void AudioRendererHost::AudioEntry::OnPlaying() { | 274 void AudioRendererHost::AudioEntry::OnPlaying() { |
268 BrowserThread::PostTask( | 275 BrowserThread::PostTask( |
269 BrowserThread::IO, | 276 BrowserThread::IO, |
270 FROM_HERE, | 277 FROM_HERE, |
271 base::Bind(&AudioRendererHost::DoNotifyStreamStateChanged, | 278 base::Bind(&AudioRendererHost::DoNotifyStreamStateChanged, |
272 host_, | 279 host_, |
273 stream_id_, | 280 stream_id_, |
(...skipping 12 matching lines...) Expand all Loading... |
286 | 293 |
287 void AudioRendererHost::AudioEntry::OnError() { | 294 void AudioRendererHost::AudioEntry::OnError() { |
288 BrowserThread::PostTask( | 295 BrowserThread::PostTask( |
289 BrowserThread::IO, | 296 BrowserThread::IO, |
290 FROM_HERE, | 297 FROM_HERE, |
291 base::Bind(&AudioRendererHost::ReportErrorAndClose, host_, stream_id_)); | 298 base::Bind(&AudioRendererHost::ReportErrorAndClose, host_, stream_id_)); |
292 } | 299 } |
293 | 300 |
294 void AudioRendererHost::DoCompleteCreation(int stream_id) { | 301 void AudioRendererHost::DoCompleteCreation(int stream_id) { |
295 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 302 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 303 AudioEntry* entry = LookupById(stream_id); |
296 | 304 |
297 if (!PeerHandle()) { | 305 if (!PeerHandle()) { |
298 DLOG(WARNING) << "Renderer process handle is invalid."; | 306 DLOG(WARNING) << "Renderer process handle is invalid."; |
299 ReportErrorAndClose(stream_id); | 307 audio_log_->OnError(stream_id); |
| 308 CloseStream(stream_id); |
300 return; | 309 return; |
301 } | 310 } |
302 | 311 |
303 AudioEntry* const entry = LookupById(stream_id); | |
304 if (!entry) { | 312 if (!entry) { |
305 ReportErrorAndClose(stream_id); | 313 audio_log_->OnError(stream_id); |
| 314 CloseStream(stream_id); |
306 return; | 315 return; |
307 } | 316 } |
308 | 317 |
309 // Once the audio stream is created then complete the creation process by | |
310 // mapping shared memory and sharing with the renderer process. | |
311 base::SharedMemoryHandle foreign_memory_handle; | |
312 if (!entry->shared_memory()->ShareToProcess(PeerHandle(), | |
313 &foreign_memory_handle)) { | |
314 // If we failed to map and share the shared memory then close the audio | |
315 // stream and send an error message. | |
316 ReportErrorAndClose(entry->stream_id()); | |
317 return; | |
318 } | |
319 | |
320 AudioSyncReader* reader = static_cast<AudioSyncReader*>(entry->reader()); | 318 AudioSyncReader* reader = static_cast<AudioSyncReader*>(entry->reader()); |
321 | 319 |
322 base::SyncSocket::TransitDescriptor socket_descriptor; | 320 base::SyncSocket::TransitDescriptor socket_descriptor; |
323 | 321 |
324 // If we failed to prepare the sync socket for the renderer then we fail | 322 // If we failed to prepare the sync socket for the renderer then we fail |
325 // the construction of audio stream. | 323 // the construction of audio stream. |
326 if (!reader->PrepareForeignSocket(PeerHandle(), &socket_descriptor)) { | 324 if (!reader->PrepareForeignSocket(PeerHandle(), &socket_descriptor)) { |
327 ReportErrorAndClose(entry->stream_id()); | 325 entry->audio_output_impl()->ReportErrorAndCloseStream(entry->stream_id()); |
328 return; | 326 return; |
329 } | 327 } |
330 | 328 |
331 Send(new AudioMsg_NotifyStreamCreated( | 329 entry->audio_output_impl()->CreateStreamFactory( |
332 entry->stream_id(), foreign_memory_handle, socket_descriptor, | 330 stream_id, entry->shared_memory(), socket_descriptor); |
333 entry->shared_memory()->requested_size())); | |
334 } | 331 } |
335 | 332 |
336 void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id, | 333 void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id, |
337 bool is_playing) { | 334 bool is_playing) { |
338 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 335 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
339 | 336 |
340 AudioEntry* const entry = LookupById(stream_id); | 337 AudioEntry* const entry = LookupById(stream_id); |
341 if (!entry) | 338 if (!entry) |
342 return; | 339 return; |
343 | 340 |
(...skipping 30 matching lines...) Expand all Loading... |
374 return controllers; | 371 return controllers; |
375 } | 372 } |
376 | 373 |
377 /////////////////////////////////////////////////////////////////////////////// | 374 /////////////////////////////////////////////////////////////////////////////// |
378 // IPC Messages handler | 375 // IPC Messages handler |
379 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message) { | 376 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message) { |
380 bool handled = true; | 377 bool handled = true; |
381 IPC_BEGIN_MESSAGE_MAP(AudioRendererHost, message) | 378 IPC_BEGIN_MESSAGE_MAP(AudioRendererHost, message) |
382 IPC_MESSAGE_HANDLER(AudioHostMsg_RequestDeviceAuthorization, | 379 IPC_MESSAGE_HANDLER(AudioHostMsg_RequestDeviceAuthorization, |
383 OnRequestDeviceAuthorization) | 380 OnRequestDeviceAuthorization) |
384 IPC_MESSAGE_HANDLER(AudioHostMsg_CreateStream, OnCreateStream) | |
385 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream) | 381 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream) |
386 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream) | 382 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream) |
387 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream) | 383 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, CloseStream) |
388 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) | 384 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) |
389 IPC_MESSAGE_UNHANDLED(handled = false) | 385 IPC_MESSAGE_UNHANDLED(handled = false) |
390 IPC_END_MESSAGE_MAP() | 386 IPC_END_MESSAGE_MAP() |
391 | 387 |
392 return handled; | 388 return handled; |
393 } | 389 } |
394 | 390 |
395 void AudioRendererHost::OnRequestDeviceAuthorization( | 391 void AudioRendererHost::OnRequestDeviceAuthorization( |
396 int stream_id, | 392 int stream_id, |
397 int render_frame_id, | 393 int render_frame_id, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 | 507 |
512 auth_data->second.first = true; | 508 auth_data->second.first = true; |
513 auth_data->second.second = device_info.unique_id; | 509 auth_data->second.second = device_info.unique_id; |
514 | 510 |
515 media::AudioParameters output_params = device_info.output_params; | 511 media::AudioParameters output_params = device_info.output_params; |
516 MaybeFixAudioParameters(&output_params); | 512 MaybeFixAudioParameters(&output_params); |
517 Send(new AudioMsg_NotifyDeviceAuthorized( | 513 Send(new AudioMsg_NotifyDeviceAuthorized( |
518 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params, std::string())); | 514 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params, std::string())); |
519 } | 515 } |
520 | 516 |
521 void AudioRendererHost::OnCreateStream(int stream_id, | 517 void AudioRendererHost::CreateStream(int stream_id, |
522 int render_frame_id, | 518 int render_frame_id, |
523 const media::AudioParameters& params) { | 519 const media::AudioParameters& params, |
| 520 AudioOutputImpl* audio_output_impl) { |
524 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 521 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
525 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" | 522 DVLOG(1) << "AudioRendererHost@" << this << "::CreateStream" |
526 << "(stream_id=" << stream_id << ")"; | 523 << "(stream_id=" << stream_id << ")"; |
527 | 524 |
528 const auto& auth_data = authorizations_.find(stream_id); | 525 const auto& auth_data = authorizations_.find(stream_id); |
529 | 526 |
530 // If no previous authorization requested, assume default device | 527 // If no previous authorization requested, assume default device |
531 if (auth_data == authorizations_.end()) { | 528 if (auth_data == authorizations_.end()) { |
532 DoCreateStream(stream_id, render_frame_id, params, std::string()); | 529 DoCreateStream(stream_id, render_frame_id, params, std::string(), |
| 530 audio_output_impl); |
533 return; | 531 return; |
534 } | 532 } |
535 | 533 |
536 CHECK(auth_data->second.first); | 534 CHECK(auth_data->second.first); |
537 DoCreateStream(stream_id, render_frame_id, params, auth_data->second.second); | 535 DoCreateStream(stream_id, render_frame_id, params, auth_data->second.second, |
| 536 audio_output_impl); |
538 authorizations_.erase(auth_data); | 537 authorizations_.erase(auth_data); |
539 } | 538 } |
540 | 539 |
541 void AudioRendererHost::DoCreateStream(int stream_id, | 540 void AudioRendererHost::DoCreateStream(int stream_id, |
542 int render_frame_id, | 541 int render_frame_id, |
543 const media::AudioParameters& params, | 542 const media::AudioParameters& params, |
544 const std::string& device_unique_id) { | 543 const std::string& device_unique_id, |
| 544 AudioOutputImpl* audio_output_impl) { |
545 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 545 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
546 | 546 |
547 // media::AudioParameters is validated in the deserializer. | 547 // media::AudioParameters is validated in the deserializer. |
548 if (LookupById(stream_id) != NULL) { | 548 if (LookupById(stream_id) != NULL) { |
549 SendErrorMessage(stream_id); | 549 SendErrorMessage(stream_id); |
550 return; | 550 return; |
551 } | 551 } |
552 | 552 |
553 // Create the shared memory and share with the renderer process. | 553 // Create the shared memory and share with the renderer process. |
554 uint32_t shared_memory_size = sizeof(media::AudioOutputBufferParameters) + | 554 uint32_t shared_memory_size = sizeof(media::AudioOutputBufferParameters) + |
555 AudioBus::CalculateMemorySize(params); | 555 AudioBus::CalculateMemorySize(params); |
556 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); | 556 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); |
557 if (!shared_memory->CreateAndMapAnonymous(shared_memory_size)) { | 557 if (!shared_memory->CreateAndMapAnonymous(shared_memory_size)) { |
558 SendErrorMessage(stream_id); | 558 SendErrorMessage(stream_id); |
559 return; | 559 return; |
560 } | 560 } |
561 | 561 |
562 std::unique_ptr<AudioSyncReader> reader( | 562 std::unique_ptr<AudioSyncReader> reader( |
563 new AudioSyncReader(shared_memory.get(), params)); | 563 new AudioSyncReader(shared_memory.get(), params)); |
564 if (!reader->Init()) { | 564 if (!reader->Init()) { |
565 SendErrorMessage(stream_id); | 565 SendErrorMessage(stream_id); |
566 return; | 566 return; |
567 } | 567 } |
568 | 568 |
569 MediaObserver* const media_observer = | 569 MediaObserver* const media_observer = |
570 GetContentClient()->browser()->GetMediaObserver(); | 570 GetContentClient()->browser()->GetMediaObserver(); |
571 if (media_observer) | 571 if (media_observer) |
572 media_observer->OnCreatingAudioStream(render_process_id_, render_frame_id); | 572 media_observer->OnCreatingAudioStream(render_process_id_, render_frame_id); |
573 | 573 |
574 std::unique_ptr<AudioEntry> entry( | 574 std::unique_ptr<AudioEntry> entry(new AudioEntry( |
575 new AudioEntry(this, stream_id, render_frame_id, params, device_unique_id, | 575 this, stream_id, render_frame_id, params, device_unique_id, |
576 std::move(shared_memory), std::move(reader))); | 576 std::move(shared_memory), std::move(reader), audio_output_impl)); |
577 if (mirroring_manager_) { | 577 if (mirroring_manager_) { |
578 mirroring_manager_->AddDiverter( | 578 mirroring_manager_->AddDiverter( |
579 render_process_id_, entry->render_frame_id(), entry->controller()); | 579 render_process_id_, entry->render_frame_id(), entry->controller()); |
580 } | 580 } |
581 audio_entries_.insert(std::make_pair(stream_id, entry.release())); | 581 audio_entries_.insert(std::make_pair(stream_id, entry.release())); |
582 g_audio_streams_tracker.Get().IncreaseStreamCount(); | 582 g_audio_streams_tracker.Get().IncreaseStreamCount(); |
583 | 583 |
584 audio_log_->OnCreated(stream_id, params, device_unique_id); | 584 audio_log_->OnCreated(stream_id, params, device_unique_id); |
585 MediaInternals::GetInstance()->SetWebContentsTitleForAudioLogEntry( | 585 MediaInternals::GetInstance()->SetWebContentsTitleForAudioLogEntry( |
586 stream_id, render_process_id_, render_frame_id, audio_log_.get()); | 586 stream_id, render_process_id_, render_frame_id, audio_log_.get()); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 return; | 629 return; |
630 entry->controller()->SetVolume(volume); | 630 entry->controller()->SetVolume(volume); |
631 audio_log_->OnSetVolume(stream_id, volume); | 631 audio_log_->OnSetVolume(stream_id, volume); |
632 } | 632 } |
633 | 633 |
634 void AudioRendererHost::SendErrorMessage(int stream_id) { | 634 void AudioRendererHost::SendErrorMessage(int stream_id) { |
635 Send(new AudioMsg_NotifyStreamStateChanged( | 635 Send(new AudioMsg_NotifyStreamStateChanged( |
636 stream_id, media::AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR)); | 636 stream_id, media::AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR)); |
637 } | 637 } |
638 | 638 |
639 void AudioRendererHost::OnCloseStream(int stream_id) { | 639 void AudioRendererHost::CloseStream(int stream_id) { |
640 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 640 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
641 authorizations_.erase(stream_id); | 641 authorizations_.erase(stream_id); |
642 | 642 |
643 // Prevent oustanding callbacks from attempting to close/delete the same | 643 // Prevent oustanding callbacks from attempting to close/delete the same |
644 // AudioEntry twice. | 644 // AudioEntry twice. |
645 AudioEntryMap::iterator i = audio_entries_.find(stream_id); | 645 AudioEntryMap::iterator i = audio_entries_.find(stream_id); |
646 if (i == audio_entries_.end()) | 646 if (i == audio_entries_.end()) |
647 return; | 647 return; |
648 std::unique_ptr<AudioEntry> entry(i->second); | 648 std::unique_ptr<AudioEntry> entry(i->second); |
649 audio_entries_.erase(i); | 649 audio_entries_.erase(i); |
(...skipping 26 matching lines...) Expand all Loading... |
676 | 676 |
677 // Make sure this isn't a stray callback executing after the stream has been | 677 // Make sure this isn't a stray callback executing after the stream has been |
678 // closed, so error notifications aren't sent after clients believe the stream | 678 // closed, so error notifications aren't sent after clients believe the stream |
679 // is closed. | 679 // is closed. |
680 if (!LookupById(stream_id)) | 680 if (!LookupById(stream_id)) |
681 return; | 681 return; |
682 | 682 |
683 SendErrorMessage(stream_id); | 683 SendErrorMessage(stream_id); |
684 | 684 |
685 audio_log_->OnError(stream_id); | 685 audio_log_->OnError(stream_id); |
686 OnCloseStream(stream_id); | 686 CloseStream(stream_id); |
687 } | 687 } |
688 | 688 |
689 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { | 689 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { |
690 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 690 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
691 | 691 |
692 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); | 692 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); |
693 return i != audio_entries_.end() ? i->second : NULL; | 693 return i != audio_entries_.end() ? i->second : NULL; |
694 } | 694 } |
695 | 695 |
696 void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry, | 696 void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 callback.Run(false, device_info); | 809 callback.Run(false, device_info); |
810 } | 810 } |
811 | 811 |
812 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 812 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
813 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 813 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
814 const auto& i = authorizations_.find(stream_id); | 814 const auto& i = authorizations_.find(stream_id); |
815 return i != authorizations_.end(); | 815 return i != authorizations_.end(); |
816 } | 816 } |
817 | 817 |
818 } // namespace content | 818 } // namespace content |
OLD | NEW |