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

Unified Diff: extensions/shell/browser/shell_audio_controller_chromeos.cc

Issue 515573003: app_shell: Do simple audio initialization. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: wrap line Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
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..0ee6150a3420a4aec0e98261d7e3191a4d7be30a
--- /dev/null
+++ b/extensions/shell/browser/shell_audio_controller_chromeos.cc
@@ -0,0 +1,133 @@
+// 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.
+}
+
+bool ShellAudioController::PrefHandler::GetMuteValue(
+ const chromeos::AudioDevice& device) {
+ return false;
+}
+
+void ShellAudioController::PrefHandler::SetMuteValue(
+ 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) {
+ // TODO(derat): Need to check |plugged_time|?
+ 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

Powered by Google App Engine
This is Rietveld 408576698