| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 return; | 469 return; |
| 454 | 470 |
| 455 if (!have_access) { | 471 if (!have_access) { |
| 456 authorizations_.erase(auth_data); | 472 authorizations_.erase(auth_data); |
| 457 Send(new AudioMsg_NotifyDeviceAuthorized( | 473 Send(new AudioMsg_NotifyDeviceAuthorized( |
| 458 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, | 474 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, |
| 459 DummyParams())); | 475 DummyParams())); |
| 460 return; | 476 return; |
| 461 } | 477 } |
| 462 | 478 |
| 463 media_stream_manager_->audio_output_device_enumerator()->Enumerate(base::Bind( | 479 // If enumerator caching is disabled, avoid the enumeration if the default |
| 464 &AudioRendererHost::TranslateDeviceID, this, device_id, | 480 // device is requested, since no device ID translation is needed. |
| 465 gurl_security_origin, | 481 // If enumerator caching is enabled, it is better to use its cache, even |
| 466 base::Bind(&AudioRendererHost::OnDeviceIDTranslated, this, stream_id))); | 482 // for the default device. |
| 483 if (IsDefaultDeviceId(device_id) && |
| 484 !media_stream_manager_->audio_output_device_enumerator() |
| 485 ->IsCacheEnabled()) { |
| 486 base::PostTaskAndReplyWithResult( |
| 487 audio_manager_->GetWorkerTaskRunner().get(), FROM_HERE, |
| 488 base::Bind(&GetDefaultDeviceInfoOnDeviceThread, audio_manager_), |
| 489 base::Bind(&AudioRendererHost::OnDeviceIDTranslated, this, stream_id, |
| 490 true)); |
| 491 } else { |
| 492 media_stream_manager_->audio_output_device_enumerator()->Enumerate( |
| 493 base::Bind(&AudioRendererHost::TranslateDeviceID, this, device_id, |
| 494 gurl_security_origin, |
| 495 base::Bind(&AudioRendererHost::OnDeviceIDTranslated, this, |
| 496 stream_id))); |
| 497 } |
| 467 } | 498 } |
| 468 | 499 |
| 469 void AudioRendererHost::OnDeviceIDTranslated( | 500 void AudioRendererHost::OnDeviceIDTranslated( |
| 470 int stream_id, | 501 int stream_id, |
| 471 bool device_found, | 502 bool device_found, |
| 472 const AudioOutputDeviceInfo& device_info) { | 503 const AudioOutputDeviceInfo& device_info) { |
| 473 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 504 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 474 const auto& auth_data = authorizations_.find(stream_id); | 505 const auto& auth_data = authorizations_.find(stream_id); |
| 475 | 506 |
| 476 // A close request was received while translation was in progress | 507 // A close request was received while translation was in progress |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 callback.Run(false, device_info); | 822 callback.Run(false, device_info); |
| 792 } | 823 } |
| 793 | 824 |
| 794 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 825 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
| 795 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 826 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 796 const auto& i = authorizations_.find(stream_id); | 827 const auto& i = authorizations_.find(stream_id); |
| 797 return i != authorizations_.end(); | 828 return i != authorizations_.end(); |
| 798 } | 829 } |
| 799 | 830 |
| 800 } // namespace content | 831 } // namespace content |
| OLD | NEW |