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 // TODO(derat): Shove volume and mute prefs into a map so we can at least | |
49 // 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
| |
50 } | |
51 | |
52 bool ShellAudioController::PrefHandler::GetMuteValue( | |
53 const chromeos::AudioDevice& device) { | |
54 return false; | |
55 } | |
56 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
| |
57 const chromeos::AudioDevice& device, | |
58 bool mute_on) {} | |
59 | |
60 bool ShellAudioController::PrefHandler::GetAudioCaptureAllowedValue() { | |
61 return true; | |
62 } | |
63 | |
64 bool ShellAudioController::PrefHandler::GetAudioOutputAllowedValue() { | |
65 return true; | |
66 } | |
67 | |
68 void ShellAudioController::PrefHandler::AddAudioPrefObserver( | |
69 chromeos::AudioPrefObserver* observer) {} | |
70 | |
71 void ShellAudioController::PrefHandler::RemoveAudioPrefObserver( | |
72 chromeos::AudioPrefObserver* observer) {} | |
73 | |
74 ShellAudioController::PrefHandler::~PrefHandler() {} | |
75 | |
76 ShellAudioController::ShellAudioController() { | |
77 chromeos::CrasAudioHandler::Get()->AddAudioObserver(this); | |
78 ActivateDevices(); | |
79 } | |
80 | |
81 ShellAudioController::~ShellAudioController() { | |
82 chromeos::CrasAudioHandler::Get()->RemoveAudioObserver(this); | |
83 } | |
84 | |
85 void ShellAudioController::OnOutputVolumeChanged() {} | |
86 | |
87 void ShellAudioController::OnOutputMuteChanged() {} | |
88 | |
89 void ShellAudioController::OnInputGainChanged() {} | |
90 | |
91 void ShellAudioController::OnInputMuteChanged() {} | |
92 | |
93 void ShellAudioController::OnAudioNodesChanged() { | |
94 VLOG(1) << "Audio nodes changed"; | |
95 ActivateDevices(); | |
96 } | |
97 | |
98 void ShellAudioController::OnActiveOutputNodeChanged() {} | |
99 | |
100 void ShellAudioController::OnActiveInputNodeChanged() {} | |
101 | |
102 void ShellAudioController::ActivateDevices() { | |
103 chromeos::CrasAudioHandler* handler = chromeos::CrasAudioHandler::Get(); | |
104 chromeos::AudioDeviceList devices; | |
105 handler->GetAudioDevices(&devices); | |
106 sort(devices.begin(), devices.end(), chromeos::AudioDeviceCompare()); | |
107 | |
108 uint64 best_input = 0, best_output = 0; | |
109 for (chromeos::AudioDeviceList::const_reverse_iterator it = devices.rbegin(); | |
110 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
| |
111 // 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
| |
112 if (it->is_input && !best_input) | |
113 best_input = it->id; | |
114 else if (!it->is_input && !best_output) | |
115 best_output = it->id; | |
116 } | |
117 | |
118 if (best_input && best_input != handler->GetActiveInputNode()) { | |
119 const chromeos::AudioDevice* device = GetDevice(devices, best_input); | |
120 DCHECK(device); | |
121 VLOG(1) << "Activating input device: " << device->ToString(); | |
122 handler->SwitchToDevice(*device); | |
123 } | |
124 if (best_output && best_output != handler->GetActiveOutputNode()) { | |
125 const chromeos::AudioDevice* device = GetDevice(devices, best_output); | |
126 DCHECK(device); | |
127 VLOG(1) << "Activating output device: " << device->ToString(); | |
128 handler->SwitchToDevice(*device); | |
129 } | |
130 } | |
131 | |
132 } // namespace extensions | |
OLD | NEW |