OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 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 "chromeos/dbus/cras_audio_client_stub_impl.h" | |
6 | |
7 namespace chromeos { | |
8 | |
9 CrasAudioClientStubImpl::CrasAudioClientStubImpl() | |
10 : active_input_node_id_(0), | |
11 active_output_node_id_(0) { | |
12 } | |
13 | |
14 CrasAudioClientStubImpl::~CrasAudioClientStubImpl() { | |
15 } | |
16 | |
17 void CrasAudioClientStubImpl::Init(dbus::Bus* bus) { | |
18 VLOG(1) << "CrasAudioClientStubImpl is created"; | |
19 | |
20 // Fake audio output nodes. | |
21 AudioNode node_1; | |
22 node_1.is_input = false; | |
23 node_1.id = 10001; | |
24 node_1.device_name = "Fake Speaker"; | |
25 node_1.type = "INTERNAL_SPEAKER"; | |
26 node_1.name = "Speaker"; | |
27 node_list_.push_back(node_1); | |
28 | |
29 AudioNode node_2; | |
30 node_2.is_input = false; | |
31 node_2.id = 10002; | |
32 node_2.device_name = "Fake Headphone"; | |
33 node_2.type = "HEADPHONE"; | |
34 node_2.name = "Headphone"; | |
35 node_list_.push_back(node_2); | |
36 | |
37 AudioNode node_3; | |
38 node_3.is_input = false; | |
39 node_3.id = 10003; | |
40 node_3.device_name = "Fake Bluetooth Headphone"; | |
41 node_3.type = "BLUETOOTH"; | |
42 node_3.name = "Headphone"; | |
43 node_list_.push_back(node_3); | |
44 | |
45 // Fake audio input ndoes | |
46 AudioNode node_4; | |
47 node_4.is_input = true; | |
48 node_4.id = 10004; | |
49 node_4.device_name = "Fake Internal Mic"; | |
50 node_4.type = "INTERNAL_MIC"; | |
51 node_4.name = "Internal Mic"; | |
52 node_list_.push_back(node_4); | |
53 | |
54 AudioNode node_5; | |
55 node_5.is_input = true; | |
56 node_5.id = 10005; | |
57 node_5.device_name = "Fake USB Mic"; | |
58 node_5.type = "USB"; | |
59 node_5.name = "Mic"; | |
60 node_list_.push_back(node_5); | |
61 } | |
62 | |
63 void CrasAudioClientStubImpl::AddObserver(Observer* observer) { | |
64 observers_.AddObserver(observer); | |
65 } | |
66 | |
67 void CrasAudioClientStubImpl::RemoveObserver(Observer* observer) { | |
68 observers_.RemoveObserver(observer); | |
69 } | |
70 | |
71 bool CrasAudioClientStubImpl::HasObserver(Observer* observer) { | |
72 return observers_.HasObserver(observer); | |
73 } | |
74 | |
75 void CrasAudioClientStubImpl::GetVolumeState( | |
76 const GetVolumeStateCallback& callback) { | |
77 callback.Run(volume_state_, true); | |
78 } | |
79 | |
80 void CrasAudioClientStubImpl::GetNodes(const GetNodesCallback& callback, | |
81 const ErrorCallback& error_callback) { | |
82 callback.Run(node_list_, true); | |
83 } | |
84 | |
85 void CrasAudioClientStubImpl::SetOutputNodeVolume(uint64 node_id, | |
86 int32 volume) { | |
87 } | |
88 | |
89 void CrasAudioClientStubImpl::SetOutputUserMute(bool mute_on) { | |
90 volume_state_.output_user_mute = mute_on; | |
91 FOR_EACH_OBSERVER(Observer, | |
92 observers_, | |
93 OutputMuteChanged(volume_state_.output_user_mute)); | |
94 } | |
95 | |
96 void CrasAudioClientStubImpl::SetInputNodeGain(uint64 node_id, | |
97 int32 input_gain) { | |
98 } | |
99 | |
100 void CrasAudioClientStubImpl::SetInputMute(bool mute_on) { | |
101 volume_state_.input_mute = mute_on; | |
102 FOR_EACH_OBSERVER(Observer, | |
103 observers_, | |
104 InputMuteChanged(volume_state_.input_mute)); | |
105 } | |
106 | |
107 void CrasAudioClientStubImpl::SetActiveOutputNode(uint64 node_id) { | |
108 if (active_output_node_id_ == node_id) | |
109 return; | |
110 | |
111 for (size_t i = 0; i < node_list_.size(); ++i) { | |
112 if (node_list_[i].id == active_output_node_id_) | |
113 node_list_[i].active = false; | |
114 else if (node_list_[i].id == node_id) | |
115 node_list_[i].active = true; | |
116 } | |
117 active_output_node_id_ = node_id; | |
118 FOR_EACH_OBSERVER(Observer, | |
119 observers_, | |
120 ActiveOutputNodeChanged(node_id)); | |
121 } | |
122 | |
123 void CrasAudioClientStubImpl::SetActiveInputNode(uint64 node_id) { | |
124 if (active_input_node_id_ == node_id) | |
125 return; | |
126 | |
127 for (size_t i = 0; i < node_list_.size(); ++i) { | |
128 if (node_list_[i].id == active_input_node_id_) | |
129 node_list_[i].active = false; | |
130 else if (node_list_[i].id == node_id) | |
131 node_list_[i].active = true; | |
132 } | |
133 active_input_node_id_ = node_id; | |
134 FOR_EACH_OBSERVER(Observer, | |
135 observers_, | |
136 ActiveInputNodeChanged(node_id)); | |
137 } | |
138 | |
139 void CrasAudioClientStubImpl::AddActiveInputNode(uint64 node_id) { | |
140 for (size_t i = 0; i < node_list_.size(); ++i) { | |
141 if (node_list_[i].id == node_id) | |
142 node_list_[i].active = true; | |
143 } | |
144 } | |
145 | |
146 void CrasAudioClientStubImpl::RemoveActiveInputNode(uint64 node_id) { | |
147 for (size_t i = 0; i < node_list_.size(); ++i) { | |
148 if (node_list_[i].id == node_id) | |
149 node_list_[i].active = false; | |
150 } | |
151 } | |
152 | |
153 void CrasAudioClientStubImpl::SwapLeftRight(uint64 node_id, bool swap) { | |
154 } | |
155 | |
156 void CrasAudioClientStubImpl::AddActiveOutputNode(uint64 node_id) { | |
157 for (size_t i = 0; i < node_list_.size(); ++i) { | |
158 if (node_list_[i].id == node_id) | |
159 node_list_[i].active = true; | |
160 } | |
161 } | |
162 | |
163 void CrasAudioClientStubImpl::RemoveActiveOutputNode(uint64 node_id) { | |
164 for (size_t i = 0; i < node_list_.size(); ++i) { | |
165 if (node_list_[i].id == node_id) | |
166 node_list_[i].active = false; | |
167 } | |
168 } | |
169 | |
170 void CrasAudioClientStubImpl::SetAudioNodesForTesting( | |
171 const AudioNodeList& audio_nodes) { | |
172 node_list_ = audio_nodes; | |
173 } | |
174 | |
175 void CrasAudioClientStubImpl::SetAudioNodesAndNotifyObserversForTesting( | |
176 const AudioNodeList& new_nodes) { | |
177 SetAudioNodesForTesting(new_nodes); | |
178 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged()); | |
179 } | |
180 | |
181 } // namespace chromeos | |
OLD | NEW |