1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/shell/browser/shell_audio_controller_chromeos.h"
9 #include "chromeos/audio/audio_device.h"
11 namespace extensions {
15 // Default output and input volume.
16 const double kOutputVolumePercent = 100.0;
17 const double kInputGainPercent = 100.0;
19 // Returns a pointer to the device in |devices| with ID |node_id|, or NULL if it
21 const chromeos::AudioDevice* GetDevice(const chromeos::AudioDeviceList& devices,
23 for (chromeos::AudioDeviceList::const_iterator it = devices.begin();
24 it != devices.end(); ++it) {
25 if (it->id == node_id)
33 ShellAudioController::PrefHandler::PrefHandler() {}
35 double ShellAudioController::PrefHandler::GetOutputVolumeValue(
36 const chromeos::AudioDevice* device) {
37 return kOutputVolumePercent;
40 double ShellAudioController::PrefHandler::GetInputGainValue(
41 const chromeos::AudioDevice* device) {
42 return kInputGainPercent;
45 void ShellAudioController::PrefHandler::SetVolumeGainValue(
46 const chromeos::AudioDevice& device,
48 // TODO(derat): Shove volume and mute prefs into a map so we can at least
49 // honor changes that are made at runtime.
52 bool ShellAudioController::PrefHandler::GetMuteValue(
53 const chromeos::AudioDevice& device) {
57 void ShellAudioController::PrefHandler::SetMuteValue(
58 const chromeos::AudioDevice& device,
61 bool ShellAudioController::PrefHandler::GetAudioCaptureAllowedValue() {
65 bool ShellAudioController::PrefHandler::GetAudioOutputAllowedValue() {
69 void ShellAudioController::PrefHandler::AddAudioPrefObserver(
70 chromeos::AudioPrefObserver* observer) {}
72 void ShellAudioController::PrefHandler::RemoveAudioPrefObserver(
73 chromeos::AudioPrefObserver* observer) {}
75 ShellAudioController::PrefHandler::~PrefHandler() {}
77 ShellAudioController::ShellAudioController() {
78 chromeos::CrasAudioHandler::Get()->AddAudioObserver(this);
82 ShellAudioController::~ShellAudioController() {
83 chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this);
86 void ShellAudioController::OnOutputVolumeChanged() {}
88 void ShellAudioController::OnOutputMuteChanged() {}
90 void ShellAudioController::OnInputGainChanged() {}
92 void ShellAudioController::OnInputMuteChanged() {}
94 void ShellAudioController::OnAudioNodesChanged() {
95 VLOG(1) << "Audio nodes changed";
99 void ShellAudioController::OnActiveOutputNodeChanged() {}
101 void ShellAudioController::OnActiveInputNodeChanged() {}
103 void ShellAudioController::ActivateDevices() {
104 chromeos::CrasAudioHandler* handler = chromeos::CrasAudioHandler::Get();
105 chromeos::AudioDeviceList devices;
106 handler->GetAudioDevices(&devices);
107 sort(devices.begin(), devices.end(), chromeos::AudioDeviceCompare());
109 uint64 best_input = 0, best_output = 0;
110 for (chromeos::AudioDeviceList::const_reverse_iterator it = devices.rbegin();
111 it != devices.rend() && (!best_input || !best_output); ++it) {
112 // TODO(derat): Need to check |plugged_time|?
113 if (it->is_input && !best_input)
115 else if (!it->is_input && !best_output)
116 best_output = it->id;
119 if (best_input && best_input != handler->GetPrimaryActiveInputNode()) {
120 const chromeos::AudioDevice* device = GetDevice(devices, best_input);
122 VLOG(1) << "Activating input device: " << device->ToString();
123 handler->SwitchToDevice(*device);
125 if (best_output && best_output != handler->GetPrimaryActiveOutputNode()) {
126 const chromeos::AudioDevice* device = GetDevice(devices, best_output);
128 VLOG(1) << "Activating output device: " << device->ToString();
129 handler->SwitchToDevice(*device);
133 } // namespace extensions