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

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

Issue 1892433002: Moving device description utils from AudioManager[Base] into AudioDeviceDescription; to be shared b… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 4 years, 7 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"
(...skipping 13 matching lines...) Expand all
24 #include "content/browser/renderer_host/media/audio_sync_reader.h" 24 #include "content/browser/renderer_host/media/audio_sync_reader.h"
25 #include "content/browser/renderer_host/media/media_stream_manager.h" 25 #include "content/browser/renderer_host/media/media_stream_manager.h"
26 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 26 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
27 #include "content/browser/renderer_host/render_widget_host_impl.h" 27 #include "content/browser/renderer_host/render_widget_host_impl.h"
28 #include "content/common/media/audio_messages.h" 28 #include "content/common/media/audio_messages.h"
29 #include "content/public/browser/content_browser_client.h" 29 #include "content/public/browser/content_browser_client.h"
30 #include "content/public/browser/media_device_id.h" 30 #include "content/public/browser/media_device_id.h"
31 #include "content/public/browser/media_observer.h" 31 #include "content/public/browser/media_observer.h"
32 #include "content/public/browser/render_frame_host.h" 32 #include "content/public/browser/render_frame_host.h"
33 #include "content/public/common/content_switches.h" 33 #include "content/public/common/content_switches.h"
34 #include "media/audio/audio_device_name.h" 34 #include "media/audio/audio_device_description.h"
35 #include "media/audio/audio_manager_base.h"
36 #include "media/audio/audio_streams_tracker.h" 35 #include "media/audio/audio_streams_tracker.h"
37 #include "media/base/audio_bus.h" 36 #include "media/base/audio_bus.h"
38 #include "media/base/limits.h" 37 #include "media/base/limits.h"
39 38
40 using media::AudioBus; 39 using media::AudioBus;
41 using media::AudioManager; 40 using media::AudioManager;
42 41
43 namespace content { 42 namespace content {
44 43
45 namespace { 44 namespace {
(...skipping 12 matching lines...) Expand all
58 } 57 }
59 58
60 GURL ConvertToGURL(const url::Origin& origin) { 59 GURL ConvertToGURL(const url::Origin& origin) {
61 return origin.unique() ? GURL() : GURL(origin.Serialize()); 60 return origin.unique() ? GURL() : GURL(origin.Serialize());
62 } 61 }
63 62
64 bool IsValidDeviceId(const std::string& device_id) { 63 bool IsValidDeviceId(const std::string& device_id) {
65 static const std::string::size_type kValidLength = 64; 64 static const std::string::size_type kValidLength = 64;
66 65
67 if (device_id.empty() || 66 if (device_id.empty() ||
68 device_id == media::AudioManagerBase::kDefaultDeviceId || 67 device_id == media::AudioDeviceDescription::kDefaultDeviceId ||
69 device_id == media::AudioManagerBase::kCommunicationsDeviceId) { 68 device_id == media::AudioDeviceDescription::kCommunicationsDeviceId) {
70 return true; 69 return true;
71 } 70 }
72 71
73 if (device_id.length() != kValidLength) 72 if (device_id.length() != kValidLength)
74 return false; 73 return false;
75 74
76 for (const char& c : device_id) { 75 for (const char& c : device_id) {
77 if ((c < 'a' || c > 'f') && (c < '0' || c > '9')) 76 if ((c < 'a' || c > 'f') && (c < '0' || c > '9'))
78 return false; 77 return false;
79 } 78 }
80 79
81 return true; 80 return true;
82 } 81 }
83 82
84 AudioOutputDeviceInfo GetDefaultDeviceInfoOnDeviceThread( 83 AudioOutputDeviceInfo GetDefaultDeviceInfoOnDeviceThread(
85 media::AudioManager* audio_manager) { 84 media::AudioManager* audio_manager) {
86 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread()); 85 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread());
87 AudioOutputDeviceInfo default_device_info = { 86 AudioOutputDeviceInfo default_device_info = {
88 media::AudioManagerBase::kDefaultDeviceId, 87 media::AudioDeviceDescription::kDefaultDeviceId,
89 audio_manager->GetDefaultDeviceName(), 88 media::AudioDeviceDescription::GetDefaultDeviceName(),
90 audio_manager->GetDefaultOutputStreamParameters()}; 89 audio_manager->GetDefaultOutputStreamParameters()};
91 90
92 return default_device_info; 91 return default_device_info;
93 } 92 }
94 93
95 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) { 94 void NotifyRenderProcessHostThatAudioStateChanged(int render_process_id) {
96 DCHECK_CURRENTLY_ON(BrowserThread::UI); 95 DCHECK_CURRENTLY_ON(BrowserThread::UI);
97 96
98 RenderProcessHost* render_process_host = 97 RenderProcessHost* render_process_host =
99 RenderProcessHost::FromID(render_process_id); 98 RenderProcessHost::FromID(render_process_id);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 414
416 if (!IsValidDeviceId(device_id)) { 415 if (!IsValidDeviceId(device_id)) {
417 Send(new AudioMsg_NotifyDeviceAuthorized( 416 Send(new AudioMsg_NotifyDeviceAuthorized(
418 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND, 417 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND,
419 media::AudioParameters::UnavailableDeviceParams(), std::string())); 418 media::AudioParameters::UnavailableDeviceParams(), std::string()));
420 return; 419 return;
421 } 420 }
422 421
423 // If |session_id should be used for output device selection and such output 422 // If |session_id should be used for output device selection and such output
424 // device is found, reuse the input device permissions. 423 // device is found, reuse the input device permissions.
425 if (media::AudioManagerBase::UseSessionIdToSelectDevice(session_id, 424 if (media::AudioDeviceDescription::UseSessionIdToSelectDevice(session_id,
426 device_id)) { 425 device_id)) {
427 const StreamDeviceInfo* info = 426 const StreamDeviceInfo* info =
428 media_stream_manager_->audio_input_device_manager() 427 media_stream_manager_->audio_input_device_manager()
429 ->GetOpenedDeviceInfoById(session_id); 428 ->GetOpenedDeviceInfoById(session_id);
430 if (info) { 429 if (info) {
431 media::AudioParameters output_params( 430 media::AudioParameters output_params(
432 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 431 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
433 static_cast<media::ChannelLayout>( 432 static_cast<media::ChannelLayout>(
434 info->device.matched_output.channel_layout), 433 info->device.matched_output.channel_layout),
435 info->device.matched_output.sample_rate, 16, 434 info->device.matched_output.sample_rate, 16,
436 info->device.matched_output.frames_per_buffer); 435 info->device.matched_output.frames_per_buffer);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 Send(new AudioMsg_NotifyDeviceAuthorized( 472 Send(new AudioMsg_NotifyDeviceAuthorized(
474 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED, 473 stream_id, media::OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED,
475 media::AudioParameters::UnavailableDeviceParams(), std::string())); 474 media::AudioParameters::UnavailableDeviceParams(), std::string()));
476 return; 475 return;
477 } 476 }
478 477
479 // If enumerator caching is disabled, avoid the enumeration if the default 478 // If enumerator caching is disabled, avoid the enumeration if the default
480 // device is requested, since no device ID translation is needed. 479 // device is requested, since no device ID translation is needed.
481 // If enumerator caching is enabled, it is better to use its cache, even 480 // If enumerator caching is enabled, it is better to use its cache, even
482 // for the default device. 481 // for the default device.
483 if (media::AudioManagerBase::IsDefaultDeviceId(device_id) && 482 if (media::AudioDeviceDescription::IsDefaultDevice(device_id) &&
484 !media_stream_manager_->audio_output_device_enumerator() 483 !media_stream_manager_->audio_output_device_enumerator()
485 ->IsCacheEnabled()) { 484 ->IsCacheEnabled()) {
486 base::PostTaskAndReplyWithResult( 485 base::PostTaskAndReplyWithResult(
487 audio_manager_->GetTaskRunner(), FROM_HERE, 486 audio_manager_->GetTaskRunner(), FROM_HERE,
488 base::Bind(&GetDefaultDeviceInfoOnDeviceThread, audio_manager_), 487 base::Bind(&GetDefaultDeviceInfoOnDeviceThread, audio_manager_),
489 base::Bind(&AudioRendererHost::OnDeviceIDTranslated, this, stream_id, 488 base::Bind(&AudioRendererHost::OnDeviceIDTranslated, this, stream_id,
490 true)); 489 true));
491 } else { 490 } else {
492 media_stream_manager_->audio_output_device_enumerator()->Enumerate( 491 media_stream_manager_->audio_output_device_enumerator()->Enumerate(
493 base::Bind(&AudioRendererHost::TranslateDeviceID, this, device_id, 492 base::Bind(&AudioRendererHost::TranslateDeviceID, this, device_id,
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 746
748 void AudioRendererHost::CheckOutputDeviceAccess( 747 void AudioRendererHost::CheckOutputDeviceAccess(
749 int render_frame_id, 748 int render_frame_id,
750 const std::string& device_id, 749 const std::string& device_id,
751 const GURL& gurl_security_origin, 750 const GURL& gurl_security_origin,
752 const OutputDeviceAccessCB& callback) { 751 const OutputDeviceAccessCB& callback) {
753 DCHECK_CURRENTLY_ON(BrowserThread::IO); 752 DCHECK_CURRENTLY_ON(BrowserThread::IO);
754 753
755 // Check security origin if nondefault device is requested. 754 // Check security origin if nondefault device is requested.
756 // Ignore check for default device, which is always authorized. 755 // Ignore check for default device, which is always authorized.
757 if (!media::AudioManagerBase::IsDefaultDeviceId(device_id) && 756 if (!media::AudioDeviceDescription::IsDefaultDevice(device_id) &&
758 !ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL( 757 !ChildProcessSecurityPolicyImpl::GetInstance()->CanRequestURL(
759 render_process_id_, gurl_security_origin)) { 758 render_process_id_, gurl_security_origin)) {
760 content::bad_message::ReceivedBadMessage(this, 759 content::bad_message::ReceivedBadMessage(this,
761 bad_message::ARH_UNAUTHORIZED_URL); 760 bad_message::ARH_UNAUTHORIZED_URL);
762 return; 761 return;
763 } 762 }
764 763
765 if (device_id.empty()) { 764 if (device_id.empty()) {
766 callback.Run(true); 765 callback.Run(true);
767 } else { 766 } else {
(...skipping 22 matching lines...) Expand all
790 } 789 }
791 790
792 void AudioRendererHost::TranslateDeviceID( 791 void AudioRendererHost::TranslateDeviceID(
793 const std::string& device_id, 792 const std::string& device_id,
794 const GURL& security_origin, 793 const GURL& security_origin,
795 const OutputDeviceInfoCB& callback, 794 const OutputDeviceInfoCB& callback,
796 const AudioOutputDeviceEnumeration& enumeration) { 795 const AudioOutputDeviceEnumeration& enumeration) {
797 DCHECK_CURRENTLY_ON(BrowserThread::IO); 796 DCHECK_CURRENTLY_ON(BrowserThread::IO);
798 for (const AudioOutputDeviceInfo& device_info : enumeration.devices) { 797 for (const AudioOutputDeviceInfo& device_info : enumeration.devices) {
799 if (device_id.empty()) { 798 if (device_id.empty()) {
800 if (device_info.unique_id == media::AudioManagerBase::kDefaultDeviceId) { 799 if (device_info.unique_id ==
800 media::AudioDeviceDescription::kDefaultDeviceId) {
801 callback.Run(true, device_info); 801 callback.Run(true, device_info);
802 return; 802 return;
803 } 803 }
804 } else if (content::DoesMediaDeviceIDMatchHMAC(salt_callback_, 804 } else if (content::DoesMediaDeviceIDMatchHMAC(salt_callback_,
805 security_origin, device_id, 805 security_origin, device_id,
806 device_info.unique_id)) { 806 device_info.unique_id)) {
807 callback.Run(true, device_info); 807 callback.Run(true, device_info);
808 return; 808 return;
809 } 809 }
810 } 810 }
811 DCHECK(!device_id.empty()); // Default device must always be found 811 DCHECK(!device_id.empty()); // Default device must always be found
812 AudioOutputDeviceInfo device_info = { 812 AudioOutputDeviceInfo device_info = {
813 std::string(), std::string(), 813 std::string(), std::string(),
814 media::AudioParameters::UnavailableDeviceParams()}; 814 media::AudioParameters::UnavailableDeviceParams()};
815 callback.Run(false, device_info); 815 callback.Run(false, device_info);
816 } 816 }
817 817
818 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { 818 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) {
819 DCHECK_CURRENTLY_ON(BrowserThread::IO); 819 DCHECK_CURRENTLY_ON(BrowserThread::IO);
820 const auto& i = authorizations_.find(stream_id); 820 const auto& i = authorizations_.find(stream_id);
821 return i != authorizations_.end(); 821 return i != authorizations_.end();
822 } 822 }
823 823
824 } // namespace content 824 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698