Index: chromeos/audio/cras_audio_handler.cc |
diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc |
index 3a86d8676ff483bb52be7955b979ba21ad5de1bf..db6f312236d2ce938be75aea122ee88fcffe9eb4 100644 |
--- a/chromeos/audio/cras_audio_handler.cc |
+++ b/chromeos/audio/cras_audio_handler.cc |
@@ -13,6 +13,7 @@ |
#include "chromeos/audio/audio_devices_pref_handler.h" |
#include "chromeos/audio/audio_devices_pref_handler_stub.h" |
#include "chromeos/dbus/dbus_thread_manager.h" |
+#include "media/audio/audio_manager.h" |
using std::max; |
using std::min; |
@@ -81,17 +82,41 @@ void CrasAudioHandler::AudioObserver::OnActiveOutputNodeChanged() { |
void CrasAudioHandler::AudioObserver::OnActiveInputNodeChanged() { |
} |
+CrasAudioHandler::AudioManagerWrapper::AudioManagerWrapper() { |
+} |
+CrasAudioHandler::AudioManagerWrapper::~AudioManagerWrapper() { |
+} |
+ |
+CrasAudioHandler::AudioManagerWrapperImpl::AudioManagerWrapperImpl() { |
+} |
+CrasAudioHandler::AudioManagerWrapperImpl::~AudioManagerWrapperImpl() { |
+} |
+ |
+void CrasAudioHandler::AudioManagerWrapperImpl::SetHasInputDevices( |
+ bool has_input_devices) { |
+ media::AudioManager::Get()->SetHasInputDevices(has_input_devices); |
+} |
+ |
// static |
void CrasAudioHandler::Initialize( |
- scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler) { |
+ scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler, |
+ scoped_ptr<AudioManagerWrapper> audio_manager) { |
CHECK(!g_cras_audio_handler); |
- g_cras_audio_handler = new CrasAudioHandler(audio_pref_handler); |
+ // Creates an AudioManagerWrapperImpl if audio_manager is not set by |
+ // caller. |
+ if (!audio_manager.get()) |
+ audio_manager.reset(new CrasAudioHandler::AudioManagerWrapperImpl()); |
+ g_cras_audio_handler = |
+ new CrasAudioHandler(audio_pref_handler, audio_manager.Pass()); |
} |
// static |
void CrasAudioHandler::InitializeForTesting() { |
CHECK(!g_cras_audio_handler); |
- CrasAudioHandler::Initialize(new AudioDevicesPrefHandlerStub()); |
+ scoped_ptr<AudioManagerWrapper> audio_manager( |
+ new CrasAudioHandler::AudioManagerWrapperImpl()); |
+ CrasAudioHandler::Initialize(new AudioDevicesPrefHandlerStub(), |
+ audio_manager.Pass()); |
} |
// static |
@@ -433,7 +458,8 @@ void CrasAudioHandler::LogErrors() { |
} |
CrasAudioHandler::CrasAudioHandler( |
- scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler) |
+ scoped_refptr<AudioDevicesPrefHandler> audio_pref_handler, |
+ scoped_ptr<AudioManagerWrapper> audio_manager) |
: audio_pref_handler_(audio_pref_handler), |
output_mute_on_(false), |
input_mute_on_(false), |
@@ -448,6 +474,7 @@ CrasAudioHandler::CrasAudioHandler( |
weak_ptr_factory_(this) { |
if (!audio_pref_handler.get()) |
Daniel Erat
2015/06/24 13:37:45
this isn't part of your change, but it seems stran
cychiang
2015/06/25 05:45:24
This was added long time ago in https://chromiumco
|
return; |
+ audio_manager_ = audio_manager.Pass(); |
// If the DBusThreadManager or the CrasAudioClient aren't available, there |
// isn't much we can do. This should only happen when running tests. |
if (!chromeos::DBusThreadManager::IsInitialized() || |
@@ -903,6 +930,18 @@ void CrasAudioHandler::UpdateDevicesAndSwitchActive( |
} |
} |
+void CrasAudioHandler::UpdateAudioManagerHasInputDevices() { |
+ AudioDeviceList devices; |
+ GetAudioDevices(&devices); |
+ for (size_t i = 0; i < devices.size(); ++i) { |
+ if (devices[i].is_input && devices[i].is_for_simple_usage()) { |
+ audio_manager_->SetHasInputDevices(true); |
+ return; |
+ } |
+ } |
+ audio_manager_->SetHasInputDevices(false); |
+} |
+ |
void CrasAudioHandler::HandleGetNodes(const chromeos::AudioNodeList& node_list, |
bool success) { |
if (!success) { |
@@ -911,6 +950,7 @@ void CrasAudioHandler::HandleGetNodes(const chromeos::AudioNodeList& node_list, |
} |
UpdateDevicesAndSwitchActive(node_list); |
+ UpdateAudioManagerHasInputDevices(); |
FOR_EACH_OBSERVER(AudioObserver, observers_, OnAudioNodesChanged()); |
} |