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

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

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

Powered by Google App Engine
This is Rietveld 408576698