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

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: use wrap 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* get_audio_output_impl() { return audio_output_impl_; }
nasko 2016/05/25 20:50:42 No get_ prefix. The _impl suffix is also optional.
rchtara 2016/05/27 15:24:39 Done.
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
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
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->get_audio_output_impl()->ReportErrorAndCloseStream(
326 entry->stream_id());
328 return; 327 return;
329 } 328 }
330 329
331 Send(new AudioMsg_NotifyStreamCreated( 330 entry->get_audio_output_impl()->CreateStreamFactory(
332 entry->stream_id(), foreign_memory_handle, socket_descriptor, 331 stream_id, entry->shared_memory(), socket_descriptor);
333 entry->shared_memory()->requested_size()));
334 } 332 }
335 333
336 void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id, 334 void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id,
337 bool is_playing) { 335 bool is_playing) {
338 DCHECK_CURRENTLY_ON(BrowserThread::IO); 336 DCHECK_CURRENTLY_ON(BrowserThread::IO);
339 337
340 AudioEntry* const entry = LookupById(stream_id); 338 AudioEntry* const entry = LookupById(stream_id);
341 if (!entry) 339 if (!entry)
342 return; 340 return;
343 341
(...skipping 30 matching lines...) Expand all
374 return controllers; 372 return controllers;
375 } 373 }
376 374
377 /////////////////////////////////////////////////////////////////////////////// 375 ///////////////////////////////////////////////////////////////////////////////
378 // IPC Messages handler 376 // IPC Messages handler
379 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message) { 377 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message) {
380 bool handled = true; 378 bool handled = true;
381 IPC_BEGIN_MESSAGE_MAP(AudioRendererHost, message) 379 IPC_BEGIN_MESSAGE_MAP(AudioRendererHost, message)
382 IPC_MESSAGE_HANDLER(AudioHostMsg_RequestDeviceAuthorization, 380 IPC_MESSAGE_HANDLER(AudioHostMsg_RequestDeviceAuthorization,
383 OnRequestDeviceAuthorization) 381 OnRequestDeviceAuthorization)
384 IPC_MESSAGE_HANDLER(AudioHostMsg_CreateStream, OnCreateStream)
385 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream) 382 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream)
386 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream) 383 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream)
387 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream) 384 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, CloseStream)
388 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) 385 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume)
389 IPC_MESSAGE_UNHANDLED(handled = false) 386 IPC_MESSAGE_UNHANDLED(handled = false)
390 IPC_END_MESSAGE_MAP() 387 IPC_END_MESSAGE_MAP()
391 388
392 return handled; 389 return handled;
393 } 390 }
394 391
395 void AudioRendererHost::OnRequestDeviceAuthorization( 392 void AudioRendererHost::OnRequestDeviceAuthorization(
396 int stream_id, 393 int stream_id,
397 int render_frame_id, 394 int render_frame_id,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 508
512 auth_data->second.first = true; 509 auth_data->second.first = true;
513 auth_data->second.second = device_info.unique_id; 510 auth_data->second.second = device_info.unique_id;
514 511
515 media::AudioParameters output_params = device_info.output_params; 512 media::AudioParameters output_params = device_info.output_params;
516 MaybeFixAudioParameters(&output_params); 513 MaybeFixAudioParameters(&output_params);
517 Send(new AudioMsg_NotifyDeviceAuthorized( 514 Send(new AudioMsg_NotifyDeviceAuthorized(
518 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params, std::string())); 515 stream_id, media::OUTPUT_DEVICE_STATUS_OK, output_params, std::string()));
519 } 516 }
520 517
521 void AudioRendererHost::OnCreateStream(int stream_id, 518 void AudioRendererHost::CreateStream(int stream_id,
522 int render_frame_id, 519 int render_frame_id,
523 const media::AudioParameters& params) { 520 const media::AudioParameters& params,
521 AudioOutputImpl* audio_output_impl) {
524 DCHECK_CURRENTLY_ON(BrowserThread::IO); 522 DCHECK_CURRENTLY_ON(BrowserThread::IO);
525 DVLOG(1) << "AudioRendererHost@" << this << "::OnCreateStream" 523 DVLOG(1) << "AudioRendererHost@" << this << "::CreateStream"
526 << "(stream_id=" << stream_id << ")"; 524 << "(stream_id=" << stream_id << ")";
527 525
528 const auto& auth_data = authorizations_.find(stream_id); 526 const auto& auth_data = authorizations_.find(stream_id);
529 527
530 // If no previous authorization requested, assume default device 528 // If no previous authorization requested, assume default device
531 if (auth_data == authorizations_.end()) { 529 if (auth_data == authorizations_.end()) {
532 DoCreateStream(stream_id, render_frame_id, params, std::string()); 530 DoCreateStream(stream_id, render_frame_id, params, std::string(),
531 audio_output_impl);
533 return; 532 return;
534 } 533 }
535 534
536 CHECK(auth_data->second.first); 535 CHECK(auth_data->second.first);
537 DoCreateStream(stream_id, render_frame_id, params, auth_data->second.second); 536 DoCreateStream(stream_id, render_frame_id, params, auth_data->second.second,
537 audio_output_impl);
538 authorizations_.erase(auth_data); 538 authorizations_.erase(auth_data);
539 } 539 }
540 540
541 void AudioRendererHost::DoCreateStream(int stream_id, 541 void AudioRendererHost::DoCreateStream(int stream_id,
542 int render_frame_id, 542 int render_frame_id,
543 const media::AudioParameters& params, 543 const media::AudioParameters& params,
544 const std::string& device_unique_id) { 544 const std::string& device_unique_id,
545 AudioOutputImpl* audio_output_impl) {
545 DCHECK_CURRENTLY_ON(BrowserThread::IO); 546 DCHECK_CURRENTLY_ON(BrowserThread::IO);
546 547
547 // media::AudioParameters is validated in the deserializer. 548 // media::AudioParameters is validated in the deserializer.
548 if (LookupById(stream_id) != NULL) { 549 if (LookupById(stream_id) != NULL) {
549 SendErrorMessage(stream_id); 550 SendErrorMessage(stream_id);
550 return; 551 return;
551 } 552 }
552 553
553 // Create the shared memory and share with the renderer process. 554 // Create the shared memory and share with the renderer process.
554 uint32_t shared_memory_size = sizeof(media::AudioOutputBufferParameters) + 555 uint32_t shared_memory_size = sizeof(media::AudioOutputBufferParameters) +
555 AudioBus::CalculateMemorySize(params); 556 AudioBus::CalculateMemorySize(params);
556 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory()); 557 std::unique_ptr<base::SharedMemory> shared_memory(new base::SharedMemory());
557 if (!shared_memory->CreateAndMapAnonymous(shared_memory_size)) { 558 if (!shared_memory->CreateAndMapAnonymous(shared_memory_size)) {
558 SendErrorMessage(stream_id); 559 SendErrorMessage(stream_id);
559 return; 560 return;
560 } 561 }
561 562
562 std::unique_ptr<AudioSyncReader> reader( 563 std::unique_ptr<AudioSyncReader> reader(
563 new AudioSyncReader(shared_memory.get(), params)); 564 new AudioSyncReader(shared_memory.get(), params));
564 if (!reader->Init()) { 565 if (!reader->Init()) {
565 SendErrorMessage(stream_id); 566 SendErrorMessage(stream_id);
566 return; 567 return;
567 } 568 }
568 569
569 MediaObserver* const media_observer = 570 MediaObserver* const media_observer =
570 GetContentClient()->browser()->GetMediaObserver(); 571 GetContentClient()->browser()->GetMediaObserver();
571 if (media_observer) 572 if (media_observer)
572 media_observer->OnCreatingAudioStream(render_process_id_, render_frame_id); 573 media_observer->OnCreatingAudioStream(render_process_id_, render_frame_id);
573 574
574 std::unique_ptr<AudioEntry> entry( 575 std::unique_ptr<AudioEntry> entry(new AudioEntry(
575 new AudioEntry(this, stream_id, render_frame_id, params, device_unique_id, 576 this, stream_id, render_frame_id, params, device_unique_id,
576 std::move(shared_memory), std::move(reader))); 577 std::move(shared_memory), std::move(reader), audio_output_impl));
577 if (mirroring_manager_) { 578 if (mirroring_manager_) {
578 mirroring_manager_->AddDiverter( 579 mirroring_manager_->AddDiverter(
579 render_process_id_, entry->render_frame_id(), entry->controller()); 580 render_process_id_, entry->render_frame_id(), entry->controller());
580 } 581 }
581 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 582 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
582 g_audio_streams_tracker.Get().IncreaseStreamCount(); 583 g_audio_streams_tracker.Get().IncreaseStreamCount();
583 584
584 audio_log_->OnCreated(stream_id, params, device_unique_id); 585 audio_log_->OnCreated(stream_id, params, device_unique_id);
585 MediaInternals::GetInstance()->SetWebContentsTitleForAudioLogEntry( 586 MediaInternals::GetInstance()->SetWebContentsTitleForAudioLogEntry(
586 stream_id, render_process_id_, render_frame_id, audio_log_.get()); 587 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; 630 return;
630 entry->controller()->SetVolume(volume); 631 entry->controller()->SetVolume(volume);
631 audio_log_->OnSetVolume(stream_id, volume); 632 audio_log_->OnSetVolume(stream_id, volume);
632 } 633 }
633 634
634 void AudioRendererHost::SendErrorMessage(int stream_id) { 635 void AudioRendererHost::SendErrorMessage(int stream_id) {
635 Send(new AudioMsg_NotifyStreamStateChanged( 636 Send(new AudioMsg_NotifyStreamStateChanged(
636 stream_id, media::AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR)); 637 stream_id, media::AUDIO_OUTPUT_IPC_DELEGATE_STATE_ERROR));
637 } 638 }
638 639
639 void AudioRendererHost::OnCloseStream(int stream_id) { 640 void AudioRendererHost::CloseStream(int stream_id) {
640 DCHECK_CURRENTLY_ON(BrowserThread::IO); 641 DCHECK_CURRENTLY_ON(BrowserThread::IO);
641 authorizations_.erase(stream_id); 642 authorizations_.erase(stream_id);
642 643
643 // Prevent oustanding callbacks from attempting to close/delete the same 644 // Prevent oustanding callbacks from attempting to close/delete the same
644 // AudioEntry twice. 645 // AudioEntry twice.
645 AudioEntryMap::iterator i = audio_entries_.find(stream_id); 646 AudioEntryMap::iterator i = audio_entries_.find(stream_id);
646 if (i == audio_entries_.end()) 647 if (i == audio_entries_.end())
647 return; 648 return;
648 std::unique_ptr<AudioEntry> entry(i->second); 649 std::unique_ptr<AudioEntry> entry(i->second);
649 audio_entries_.erase(i); 650 audio_entries_.erase(i);
(...skipping 26 matching lines...) Expand all
676 677
677 // Make sure this isn't a stray callback executing after the stream has been 678 // 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 679 // closed, so error notifications aren't sent after clients believe the stream
679 // is closed. 680 // is closed.
680 if (!LookupById(stream_id)) 681 if (!LookupById(stream_id))
681 return; 682 return;
682 683
683 SendErrorMessage(stream_id); 684 SendErrorMessage(stream_id);
684 685
685 audio_log_->OnError(stream_id); 686 audio_log_->OnError(stream_id);
686 OnCloseStream(stream_id); 687 CloseStream(stream_id);
687 } 688 }
688 689
689 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { 690 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) {
690 DCHECK_CURRENTLY_ON(BrowserThread::IO); 691 DCHECK_CURRENTLY_ON(BrowserThread::IO);
691 692
692 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); 693 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id);
693 return i != audio_entries_.end() ? i->second : NULL; 694 return i != audio_entries_.end() ? i->second : NULL;
694 } 695 }
695 696
696 void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry, 697 void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 callback.Run(false, device_info); 810 callback.Run(false, device_info);
810 } 811 }
811 812
812 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { 813 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) {
813 DCHECK_CURRENTLY_ON(BrowserThread::IO); 814 DCHECK_CURRENTLY_ON(BrowserThread::IO);
814 const auto& i = authorizations_.find(stream_id); 815 const auto& i = authorizations_.find(stream_id);
815 return i != authorizations_.end(); 816 return i != authorizations_.end();
816 } 817 }
817 818
818 } // namespace content 819 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698