Chromium Code Reviews| Index: extensions/shell/browser/shell_audio_controller_chromeos.cc |
| diff --git a/extensions/shell/browser/shell_audio_controller_chromeos.cc b/extensions/shell/browser/shell_audio_controller_chromeos.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..02a537b0c136a18f4c89971b6292f305eb507db3 |
| --- /dev/null |
| +++ b/extensions/shell/browser/shell_audio_controller_chromeos.cc |
| @@ -0,0 +1,132 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "extensions/shell/browser/shell_audio_controller_chromeos.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "chromeos/audio/audio_device.h" |
| + |
| +namespace extensions { |
| + |
| +namespace { |
| + |
| +// Default output and input volume. |
| +const double kOutputVolumePercent = 100.0; |
| +const double kInputGainPercent = 100.0; |
| + |
| +// Returns a pointer to the device in |devices| with ID |node_id|, or NULL if it |
| +// isn't present. |
| +const chromeos::AudioDevice* GetDevice(const chromeos::AudioDeviceList& devices, |
| + uint64 node_id) { |
| + for (chromeos::AudioDeviceList::const_iterator it = devices.begin(); |
| + it != devices.end(); ++it) { |
| + if (it->id == node_id) |
| + return &(*it); |
| + } |
| + return NULL; |
| +} |
| + |
| +} // namespace |
| + |
| +ShellAudioController::PrefHandler::PrefHandler() {} |
| + |
| +double ShellAudioController::PrefHandler::GetOutputVolumeValue( |
| + const chromeos::AudioDevice* device) { |
| + return kOutputVolumePercent; |
| +} |
| + |
| +double ShellAudioController::PrefHandler::GetInputGainValue( |
| + const chromeos::AudioDevice* device) { |
| + return kInputGainPercent; |
| +} |
| + |
| +void ShellAudioController::PrefHandler::SetVolumeGainValue( |
| + const chromeos::AudioDevice& device, |
| + double value) { |
| + // TODO(derat): Shove volume and mute prefs into a map so we can at least |
| + // honor changes that are made at runtime. |
|
jennyz
2014/08/28 17:42:49
Do we have a plan to persist the volume/gain and m
Daniel Erat
2014/08/28 23:27:57
you mean across app_shell runs? we'll probably wan
|
| +} |
| + |
| +bool ShellAudioController::PrefHandler::GetMuteValue( |
| + const chromeos::AudioDevice& device) { |
| + return false; |
| +} |
| +void ShellAudioController::PrefHandler::SetMuteValue( |
|
James Cook
2014/08/28 18:48:37
nit: blank line above
Daniel Erat
2014/08/28 23:27:57
whoops, done
|
| + const chromeos::AudioDevice& device, |
| + bool mute_on) {} |
| + |
| +bool ShellAudioController::PrefHandler::GetAudioCaptureAllowedValue() { |
| + return true; |
| +} |
| + |
| +bool ShellAudioController::PrefHandler::GetAudioOutputAllowedValue() { |
| + return true; |
| +} |
| + |
| +void ShellAudioController::PrefHandler::AddAudioPrefObserver( |
| + chromeos::AudioPrefObserver* observer) {} |
| + |
| +void ShellAudioController::PrefHandler::RemoveAudioPrefObserver( |
| + chromeos::AudioPrefObserver* observer) {} |
| + |
| +ShellAudioController::PrefHandler::~PrefHandler() {} |
| + |
| +ShellAudioController::ShellAudioController() { |
| + chromeos::CrasAudioHandler::Get()->AddAudioObserver(this); |
| + ActivateDevices(); |
| +} |
| + |
| +ShellAudioController::~ShellAudioController() { |
| + chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this); |
| +} |
| + |
| +void ShellAudioController::OnOutputVolumeChanged() {} |
| + |
| +void ShellAudioController::OnOutputMuteChanged() {} |
| + |
| +void ShellAudioController::OnInputGainChanged() {} |
| + |
| +void ShellAudioController::OnInputMuteChanged() {} |
| + |
| +void ShellAudioController::OnAudioNodesChanged() { |
| + VLOG(1) << "Audio nodes changed"; |
| + ActivateDevices(); |
| +} |
| + |
| +void ShellAudioController::OnActiveOutputNodeChanged() {} |
| + |
| +void ShellAudioController::OnActiveInputNodeChanged() {} |
| + |
| +void ShellAudioController::ActivateDevices() { |
| + chromeos::CrasAudioHandler* handler = chromeos::CrasAudioHandler::Get(); |
| + chromeos::AudioDeviceList devices; |
| + handler->GetAudioDevices(&devices); |
| + sort(devices.begin(), devices.end(), chromeos::AudioDeviceCompare()); |
| + |
| + uint64 best_input = 0, best_output = 0; |
| + for (chromeos::AudioDeviceList::const_reverse_iterator it = devices.rbegin(); |
| + it != devices.rend() && (!best_input || !best_output); ++it) { |
|
James Cook
2014/08/28 18:48:37
optional: this loop might be clearer if the best_i
Daniel Erat
2014/08/28 23:27:57
i considered that, but it felt weird to me since i
|
| + // TODO(derat): Need to check |plugged_time|? |
|
Daniel Erat
2014/08/28 04:00:29
jenny, let me know if there's a danger of e.g. unp
jennyz
2014/08/28 17:42:49
If the headphone jack is unplugged, it should not
|
| + if (it->is_input && !best_input) |
| + best_input = it->id; |
| + else if (!it->is_input && !best_output) |
| + best_output = it->id; |
| + } |
| + |
| + if (best_input && best_input != handler->GetActiveInputNode()) { |
| + const chromeos::AudioDevice* device = GetDevice(devices, best_input); |
| + DCHECK(device); |
| + VLOG(1) << "Activating input device: " << device->ToString(); |
| + handler->SwitchToDevice(*device); |
| + } |
| + if (best_output && best_output != handler->GetActiveOutputNode()) { |
| + const chromeos::AudioDevice* device = GetDevice(devices, best_output); |
| + DCHECK(device); |
| + VLOG(1) << "Activating output device: " << device->ToString(); |
| + handler->SwitchToDevice(*device); |
| + } |
| +} |
| + |
| +} // namespace extensions |