Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #include "extensions/shell/browser/shell_audio_controller_chromeos.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "chromeos/audio/audio_device.h" | |
| 10 | |
| 11 namespace extensions { | |
| 12 | |
| 13 namespace { | |
| 14 | |
| 15 // Default output and input volume. | |
| 16 const double kOutputVolumePercent = 100.0; | |
| 17 const double kInputGainPercent = 100.0; | |
| 18 | |
| 19 // Returns a pointer to the device in |devices| with ID |node_id|, or NULL if it | |
| 20 // isn't present. | |
| 21 const chromeos::AudioDevice* GetDevice(const chromeos::AudioDeviceList& devices, | |
| 22 uint64 node_id) { | |
| 23 for (chromeos::AudioDeviceList::const_iterator it = devices.begin(); | |
| 24 it != devices.end(); ++it) { | |
| 25 if (it->id == node_id) | |
| 26 return &(*it); | |
| 27 } | |
| 28 return NULL; | |
| 29 } | |
| 30 | |
| 31 } // namespace | |
| 32 | |
| 33 ShellAudioController::PrefHandler::PrefHandler() {} | |
| 34 | |
| 35 double ShellAudioController::PrefHandler::GetOutputVolumeValue( | |
| 36 const chromeos::AudioDevice* device) { | |
| 37 return kOutputVolumePercent; | |
| 38 } | |
| 39 | |
| 40 double ShellAudioController::PrefHandler::GetInputGainValue( | |
| 41 const chromeos::AudioDevice* device) { | |
| 42 return kInputGainPercent; | |
| 43 } | |
| 44 | |
| 45 void ShellAudioController::PrefHandler::SetVolumeGainValue( | |
| 46 const chromeos::AudioDevice& device, | |
| 47 double value) {} | |
| 48 | |
| 49 bool ShellAudioController::PrefHandler::GetMuteValue( | |
| 50 const chromeos::AudioDevice& device) { | |
| 51 return false; | |
| 52 } | |
| 53 void ShellAudioController::PrefHandler::SetMuteValue( | |
| 54 const chromeos::AudioDevice& device, | |
| 55 bool mute_on) {} | |
| 56 | |
| 57 bool ShellAudioController::PrefHandler::GetAudioCaptureAllowedValue() { | |
| 58 return true; | |
| 59 } | |
| 60 | |
| 61 bool ShellAudioController::PrefHandler::GetAudioOutputAllowedValue() { | |
| 62 return true; | |
| 63 } | |
| 64 | |
| 65 void ShellAudioController::PrefHandler::AddAudioPrefObserver( | |
| 66 chromeos::AudioPrefObserver* observer) {} | |
| 67 | |
| 68 void ShellAudioController::PrefHandler::RemoveAudioPrefObserver( | |
| 69 chromeos::AudioPrefObserver* observer) {} | |
| 70 | |
| 71 ShellAudioController::PrefHandler::~PrefHandler() {} | |
| 72 | |
| 73 ShellAudioController::ShellAudioController() { | |
| 74 chromeos::CrasAudioHandler::Get()->AddAudioObserver(this); | |
| 75 ActivateDevices(); | |
| 76 } | |
| 77 | |
| 78 ShellAudioController::~ShellAudioController() { | |
| 79 chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this); | |
| 80 } | |
| 81 | |
| 82 void ShellAudioController::OnOutputVolumeChanged() {} | |
| 83 | |
| 84 void ShellAudioController::OnOutputMuteChanged() {} | |
| 85 | |
| 86 void ShellAudioController::OnInputGainChanged() {} | |
| 87 | |
| 88 void ShellAudioController::OnInputMuteChanged() {} | |
| 89 | |
| 90 void ShellAudioController::OnAudioNodesChanged() { | |
| 91 VLOG(1) << "Audio nodes changed"; | |
| 92 ActivateDevices(); | |
| 93 } | |
| 94 | |
| 95 void ShellAudioController::OnActiveOutputNodeChanged() {} | |
| 96 | |
| 97 void ShellAudioController::OnActiveInputNodeChanged() {} | |
| 98 | |
| 99 void ShellAudioController::ActivateDevices() { | |
| 100 chromeos::CrasAudioHandler* handler = chromeos::CrasAudioHandler::Get(); | |
| 101 chromeos::AudioDeviceList devices; | |
| 102 handler->GetAudioDevices(&devices); | |
| 103 sort(devices.begin(), devices.end(), chromeos::AudioDeviceCompare()); | |
| 104 | |
| 105 uint64 best_input = 0, best_output = 0; | |
| 106 for (chromeos::AudioDeviceList::const_reverse_iterator it = devices.rbegin(); | |
| 107 it != devices.rend() && (!best_input || !best_output); ++it) { | |
|
James Cook
2014/08/27 23:18:33
Would it be simpler to do two searches, one for be
Daniel Erat
2014/08/28 00:12:20
hmm, that seems like it'd still be more code overa
| |
| 108 if (it->is_input && !best_input) | |
| 109 best_input = it->id; | |
| 110 else if (!it->is_input && !best_output) | |
| 111 best_output = it->id; | |
| 112 } | |
| 113 | |
| 114 if (best_input && best_input != handler->GetActiveInputNode()) { | |
| 115 const chromeos::AudioDevice* device = GetDevice(devices, best_input); | |
| 116 DCHECK(device); | |
| 117 VLOG(1) << "Activating input device: " << device->ToString(); | |
| 118 handler->SwitchToDevice(*device); | |
| 119 } | |
| 120 if (best_output && best_output != handler->GetActiveOutputNode()) { | |
| 121 const chromeos::AudioDevice* device = GetDevice(devices, best_output); | |
| 122 DCHECK(device); | |
| 123 VLOG(1) << "Activating output device: " << device->ToString(); | |
| 124 handler->SwitchToDevice(*device); | |
| 125 } | |
| 126 } | |
|
James Cook
2014/08/27 23:18:33
How hard would it be to add a test for this class?
Daniel Erat
2014/08/28 00:12:20
probably not very; i'll do this.
| |
| 127 | |
| 128 } // namespace extensions | |
| OLD | NEW |