| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 return false; | 92 return false; |
| 93 | 93 |
| 94 for (const char& c : device_id) { | 94 for (const char& c : device_id) { |
| 95 if ((c < 'a' || c > 'f') && (c < '0' || c > '9')) | 95 if ((c < 'a' || c > 'f') && (c < '0' || c > '9')) |
| 96 return false; | 96 return false; |
| 97 } | 97 } |
| 98 | 98 |
| 99 return true; | 99 return true; |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool IsDefaultDeviceId(const std::string& device_id) { |
| 103 return device_id.empty() || |
| 104 device_id == media::AudioManagerBase::kDefaultDeviceId; |
| 105 } |
| 106 |
| 107 AudioOutputDeviceInfo GetDefaultDeviceInfoOnDeviceThread( |
| 108 media::AudioManager* audio_manager) { |
| 109 DCHECK(audio_manager->GetWorkerTaskRunner()->BelongsToCurrentThread()); |
| 110 AudioOutputDeviceInfo default_device_info = { |
| 111 media::AudioManagerBase::kDefaultDeviceId, |
| 112 audio_manager->GetDefaultDeviceName(), |
| 113 audio_manager->GetDefaultOutputStreamParameters()}; |
| 114 |
| 115 return default_device_info; |
| 116 } |
| 117 |
| 102 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { | 118 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { |
| 103 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 119 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 104 | 120 |
| 105 RenderProcessHost* render_process_host = | 121 RenderProcessHost* render_process_host = |
| 106 RenderProcessHost::FromID(render_process_id); | 122 RenderProcessHost::FromID(render_process_id); |
| 107 | 123 |
| 108 if (render_process_host) | 124 if (render_process_host) |
| 109 render_process_host->AudioStateChanged(); | 125 render_process_host->AudioStateChanged(); |
| 110 } | 126 } |
| 111 | 127 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 return; | 461 return; |
| 446 | 462 |
| 447 if (!have_access) { | 463 if (!have_access) { |
| 448 authorizations_.erase(auth_data); | 464 authorizations_.erase(auth_data); |
| 449 Send(new AudioMsg_NotifyDeviceAuthorized( | 465 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 450 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, | 466 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, |
| 451 DummyParams())); | 467 DummyParams())); |
| 452 return; | 468 return; |
| 453 } | 469 } |
| 454 | 470 |
| 455 media_stream_manager_->audio_output_device_enumerator()->Enumerate(base::Bind( | 471 // If enumerator caching is disabled, avoid the enumeration if the default |
| 456 &AudioRendererHost::TranslateDeviceID, this, device_id, | 472 // device is requested, since no device ID translation is needed. |
| 457 gurl_security_origin, | 473 // If enumerator caching is enabled, it is better to use its cache, even |
| 458 base::Bind(&AudioRendererHost::OnDeviceIDTranslated, this, stream_id))); | 474 // for the default device. |
| 475 if (IsDefaultDeviceId(device_id) && |
| 476 !media_stream_manager_->audio_output_device_enumerator() |
| 477 ->IsCacheEnabled()) { |
| 478 base::PostTaskAndReplyWithResult( |
| 479 audio_manager_->GetWorkerTaskRunner().get(), FROM_HERE, |
| 480 base::Bind(&GetDefaultDeviceInfoOnDeviceThread, audio_manager_), |
| 481 base::Bind(&AudioRendererHost::OnDeviceIDTranslated, this, stream_id, |
| 482 true)); |
| 483 } else { |
| 484 media_stream_manager_->audio_output_device_enumerator()->Enumerate( |
| 485 base::Bind(&AudioRendererHost::TranslateDeviceID, this, device_id, |
| 486 gurl_security_origin, |
| 487 base::Bind(&AudioRendererHost::OnDeviceIDTranslated, this, |
| 488 stream_id))); |
| 489 } |
| 459 } | 490 } |
| 460 | 491 |
| 461 void AudioRendererHost::OnDeviceIDTranslated( | 492 void AudioRendererHost::OnDeviceIDTranslated( |
| 462 int stream_id, | 493 int stream_id, |
| 463 bool device_found, | 494 bool device_found, |
| 464 const AudioOutputDeviceInfo& device_info) { | 495 const AudioOutputDeviceInfo& device_info) { |
| 465 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 496 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 466 const auto& auth_data = authorizations_.find(stream_id); | 497 const auto& auth_data = authorizations_.find(stream_id); |
| 467 | 498 |
| 468 // A close request was received while translation was in progress | 499 // A close request was received while translation was in progress |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 callback.Run(false, device_info); | 811 callback.Run(false, device_info); |
| 781 } | 812 } |
| 782 | 813 |
| 783 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 814 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
| 784 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 815 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 785 const auto& i = authorizations_.find(stream_id); | 816 const auto& i = authorizations_.find(stream_id); |
| 786 return i != authorizations_.end(); | 817 return i != authorizations_.end(); |
| 787 } | 818 } |
| 788 | 819 |
| 789 } // namespace content | 820 } // namespace content |
| OLD | NEW |