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

Side by Side Diff: chromeos/audio/cras_audio_handler.cc

Issue 1186293003: Implement HasInputDevices in CrasAudioManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add SetHasInputDevice in FakeAudioManager Created 5 years, 5 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "chromeos/audio/cras_audio_handler.h" 5 #include "chromeos/audio/cras_audio_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
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/logging.h" 12 #include "base/logging.h"
13 #include "chromeos/audio/audio_devices_pref_handler.h" 13 #include "chromeos/audio/audio_devices_pref_handler.h"
14 #include "chromeos/audio/audio_devices_pref_handler_stub.h" 14 #include "chromeos/audio/audio_devices_pref_handler_stub.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "media/audio/audio_manager.h"
16 17
17 using std::max; 18 using std::max;
18 using std::min; 19 using std::min;
19 20
20 namespace chromeos { 21 namespace chromeos {
21 22
22 namespace { 23 namespace {
23 24
24 // Default value for unmuting, as a percent in the range [0, 100]. 25 // Default value for unmuting, as a percent in the range [0, 100].
25 // Used when sound is unmuted, but volume was less than kMuteThresholdPercent. 26 // Used when sound is unmuted, but volume was less than kMuteThresholdPercent.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 78
78 void CrasAudioHandler::AudioObserver::OnAudioNodesChanged() { 79 void CrasAudioHandler::AudioObserver::OnAudioNodesChanged() {
79 } 80 }
80 81
81 void CrasAudioHandler::AudioObserver::OnActiveOutputNodeChanged() { 82 void CrasAudioHandler::AudioObserver::OnActiveOutputNodeChanged() {
82 } 83 }
83 84
84 void CrasAudioHandler::AudioObserver::OnActiveInputNodeChanged() { 85 void CrasAudioHandler::AudioObserver::OnActiveInputNodeChanged() {
85 } 86 }
86 87
88 CrasAudioHandler::AudioManagerWrapper::AudioManagerWrapper() {
89 }
90 CrasAudioHandler::AudioManagerWrapper::~AudioManagerWrapper() {
91 }
92
93 CrasAudioHandler::AudioManagerWrapperImpl::AudioManagerWrapperImpl() {
94 }
95 CrasAudioHandler::AudioManagerWrapperImpl::~AudioManagerWrapperImpl() {
96 }
97
98 void CrasAudioHandler::AudioManagerWrapperImpl::SetHasInputDevices(
99 bool has_input_devices) {
100 media::AudioManager::Get()->SetHasInputDevices(has_input_devices);
101 }
102
103 CrasAudioHandler::AudioManagerWrapperForTesting::
104 AudioManagerWrapperForTesting() {
105 }
106 CrasAudioHandler::AudioManagerWrapperForTesting::
107 ~AudioManagerWrapperForTesting() {
108 }
109
110 void CrasAudioHandler::AudioManagerWrapperForTesting::SetHasInputDevices(
111 bool has_input_devices) {
112 }
113
87 // static 114 // static
88 void CrasAudioHandler::Initialize( 115 void CrasAudioHandler::Initialize(
89 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler) { 116 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler,
117 scoped_ptr<AudioManagerWrapper> audio_manager) {
90 CHECK(!g_cras_audio_handler); 118 CHECK(!g_cras_audio_handler);
91 g_cras_audio_handler = new CrasAudioHandler(audio_pref_handler); 119 g_cras_audio_handler =
120 new CrasAudioHandler(audio_pref_handler, audio_manager.Pass());
92 } 121 }
93 122
94 // static 123 // static
95 void CrasAudioHandler::InitializeForTesting() { 124 void CrasAudioHandler::InitializeForTesting() {
96 CHECK(!g_cras_audio_handler); 125 CHECK(!g_cras_audio_handler);
97 CrasAudioHandler::Initialize(new AudioDevicesPrefHandlerStub()); 126 scoped_ptr<AudioManagerWrapper> audio_manager(
127 new CrasAudioHandler::AudioManagerWrapperForTesting());
128 CrasAudioHandler::Initialize(new AudioDevicesPrefHandlerStub(),
129 audio_manager.Pass());
98 } 130 }
99 131
100 // static 132 // static
101 void CrasAudioHandler::Shutdown() { 133 void CrasAudioHandler::Shutdown() {
102 CHECK(g_cras_audio_handler); 134 CHECK(g_cras_audio_handler);
103 delete g_cras_audio_handler; 135 delete g_cras_audio_handler;
104 g_cras_audio_handler = NULL; 136 g_cras_audio_handler = NULL;
105 } 137 }
106 138
107 // static 139 // static
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 // Marks the start of the HDMI re-discovering grace period, during which we 481 // Marks the start of the HDMI re-discovering grace period, during which we
450 // will mute the audio output to prevent it to be be leaked to the 482 // will mute the audio output to prevent it to be be leaked to the
451 // alternative output device. 483 // alternative output device.
452 if ((hdmi_rediscovering_ && force_rediscovering) || 484 if ((hdmi_rediscovering_ && force_rediscovering) ||
453 (!hdmi_rediscovering_ && IsHDMIPrimaryOutputDevice())) { 485 (!hdmi_rediscovering_ && IsHDMIPrimaryOutputDevice())) {
454 StartHDMIRediscoverGracePeriod(); 486 StartHDMIRediscoverGracePeriod();
455 } 487 }
456 } 488 }
457 489
458 CrasAudioHandler::CrasAudioHandler( 490 CrasAudioHandler::CrasAudioHandler(
459 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler) 491 scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler,
492 scoped_ptr<AudioManagerWrapper> audio_manager)
460 : audio_pref_handler_(audio_pref_handler), 493 : audio_pref_handler_(audio_pref_handler),
461 output_mute_on_(false), 494 output_mute_on_(false),
462 input_mute_on_(false), 495 input_mute_on_(false),
463 output_volume_(0), 496 output_volume_(0),
464 input_gain_(0), 497 input_gain_(0),
465 active_output_node_id_(0), 498 active_output_node_id_(0),
466 active_input_node_id_(0), 499 active_input_node_id_(0),
467 has_alternative_input_(false), 500 has_alternative_input_(false),
468 has_alternative_output_(false), 501 has_alternative_output_(false),
469 output_mute_locked_(false), 502 output_mute_locked_(false),
470 log_errors_(false), 503 log_errors_(false),
471 hdmi_rediscover_grace_period_duration_in_ms_( 504 hdmi_rediscover_grace_period_duration_in_ms_(
472 kHDMIRediscoverGracePeriodDurationInMs), 505 kHDMIRediscoverGracePeriodDurationInMs),
473 hdmi_rediscovering_(false), 506 hdmi_rediscovering_(false),
474 weak_ptr_factory_(this) { 507 weak_ptr_factory_(this) {
475 if (!audio_pref_handler.get()) 508 if (!audio_pref_handler.get())
476 return; 509 return;
510 audio_manager_ = audio_manager.Pass();
477 // If the DBusThreadManager or the CrasAudioClient aren't available, there 511 // If the DBusThreadManager or the CrasAudioClient aren't available, there
478 // isn't much we can do. This should only happen when running tests. 512 // isn't much we can do. This should only happen when running tests.
479 if (!chromeos::DBusThreadManager::IsInitialized() || 513 if (!chromeos::DBusThreadManager::IsInitialized() ||
480 !chromeos::DBusThreadManager::Get() || 514 !chromeos::DBusThreadManager::Get() ||
481 !chromeos::DBusThreadManager::Get()->GetCrasAudioClient()) 515 !chromeos::DBusThreadManager::Get()->GetCrasAudioClient())
482 return; 516 return;
483 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->AddObserver(this); 517 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->AddObserver(this);
484 audio_pref_handler_->AddAudioPrefObserver(this); 518 audio_pref_handler_->AddAudioPrefObserver(this);
485 if (chromeos::DBusThreadManager::Get()->GetSessionManagerClient()) { 519 if (chromeos::DBusThreadManager::Get()->GetSessionManagerClient()) {
486 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()-> 520 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 } else { 963 } else {
930 // ditto input node case. 964 // ditto input node case.
931 if (!active_output_node_id_ || hotplug_output_nodes.empty() || 965 if (!active_output_node_id_ || hotplug_output_nodes.empty() ||
932 IsNodeInTheList(output_devices_pq_.top().id, hotplug_output_nodes)) { 966 IsNodeInTheList(output_devices_pq_.top().id, hotplug_output_nodes)) {
933 SwitchToDevice(output_devices_pq_.top(), true); 967 SwitchToDevice(output_devices_pq_.top(), true);
934 } 968 }
935 } 969 }
936 } 970 }
937 } 971 }
938 972
973 void CrasAudioHandler::UpdateAudioManagerHasInputDevices() {
974 AudioDeviceList devices;
975 GetAudioDevices(&devices);
976 for (size_t i = 0; i < devices.size(); ++i) {
977 if (devices[i].is_input && devices[i].is_for_simple_usage()) {
978 audio_manager_->SetHasInputDevices(true);
979 return;
980 }
981 }
982 audio_manager_->SetHasInputDevices(false);
983 }
984
939 void CrasAudioHandler::HandleGetNodes(const chromeos::AudioNodeList& node_list, 985 void CrasAudioHandler::HandleGetNodes(const chromeos::AudioNodeList& node_list,
940 bool success) { 986 bool success) {
941 if (!success) { 987 if (!success) {
942 LOG_IF(ERROR, log_errors_) << "Failed to retrieve audio nodes data"; 988 LOG_IF(ERROR, log_errors_) << "Failed to retrieve audio nodes data";
943 return; 989 return;
944 } 990 }
945 991
946 UpdateDevicesAndSwitchActive(node_list); 992 UpdateDevicesAndSwitchActive(node_list);
993 UpdateAudioManagerHasInputDevices();
947 FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); 994 FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged());
948 } 995 }
949 996
950 void CrasAudioHandler::HandleGetNodesError(const std::string& error_name, 997 void CrasAudioHandler::HandleGetNodesError(const std::string& error_name,
951 const std::string& error_msg) { 998 const std::string& error_msg) {
952 LOG_IF(ERROR, log_errors_) << "Failed to call GetNodes: " 999 LOG_IF(ERROR, log_errors_) << "Failed to call GetNodes: "
953 << error_name << ": " << error_msg; 1000 << error_name << ": " << error_msg;
954 } 1001 }
955 1002
956 void CrasAudioHandler::AddAdditionalActiveNode(uint64_t node_id, bool notify) { 1003 void CrasAudioHandler::AddAdditionalActiveNode(uint64_t node_id, bool notify) {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 hdmi_rediscover_grace_period_duration_in_ms_), 1080 hdmi_rediscover_grace_period_duration_in_ms_),
1034 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod); 1081 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod);
1035 } 1082 }
1036 1083
1037 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting( 1084 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting(
1038 int duration_in_ms) { 1085 int duration_in_ms) {
1039 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms; 1086 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms;
1040 } 1087 }
1041 1088
1042 } // namespace chromeos 1089 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698