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.
5 #include "chromeos/dbus/fake_cras_audio_client.h"
9 FakeCrasAudioClient::FakeCrasAudioClient()
10 : active_input_node_id_(0),
11 active_output_node_id_(0) {
14 FakeCrasAudioClient::~FakeCrasAudioClient() {
17 void FakeCrasAudioClient::Init(dbus::Bus
* bus
) {
18 VLOG(1) << "FakeCrasAudioClient is created";
20 // Fake audio output nodes.
22 output_1
.is_input
= false;
24 output_1
.device_name
= "Fake Speaker";
25 output_1
.type
= "INTERNAL_SPEAKER";
26 output_1
.name
= "Speaker";
27 node_list_
.push_back(output_1
);
30 output_2
.is_input
= false;
32 output_2
.device_name
= "Fake Headphone";
33 output_2
.type
= "HEADPHONE";
34 output_2
.name
= "Headphone";
35 node_list_
.push_back(output_2
);
38 output_3
.is_input
= false;
40 output_3
.device_name
= "Fake Bluetooth Headphone";
41 output_3
.type
= "BLUETOOTH";
42 output_3
.name
= "Headphone";
43 node_list_
.push_back(output_3
);
46 output_4
.is_input
= false;
48 output_4
.device_name
= "Fake HDMI Speaker";
49 output_4
.type
= "HDMI";
50 output_4
.name
= "HDMI Speaker";
51 node_list_
.push_back(output_4
);
53 // Fake audio input nodes
55 input_1
.is_input
= true;
57 input_1
.device_name
= "Fake Internal Mic";
58 input_1
.type
= "INTERNAL_MIC";
59 input_1
.name
= "Internal Mic";
60 node_list_
.push_back(input_1
);
63 input_2
.is_input
= true;
65 input_2
.device_name
= "Fake USB Mic";
68 node_list_
.push_back(input_2
);
71 input_3
.is_input
= true;
73 input_3
.device_name
= "Fake Mick Jack";
75 input_3
.name
= "Some type of Mic";
76 node_list_
.push_back(input_3
);
79 void FakeCrasAudioClient::AddObserver(Observer
* observer
) {
80 observers_
.AddObserver(observer
);
83 void FakeCrasAudioClient::RemoveObserver(Observer
* observer
) {
84 observers_
.RemoveObserver(observer
);
87 bool FakeCrasAudioClient::HasObserver(const Observer
* observer
) const {
88 return observers_
.HasObserver(observer
);
91 void FakeCrasAudioClient::GetVolumeState(
92 const GetVolumeStateCallback
& callback
) {
93 callback
.Run(volume_state_
, true);
96 void FakeCrasAudioClient::GetNodes(const GetNodesCallback
& callback
,
97 const ErrorCallback
& error_callback
) {
98 callback
.Run(node_list_
, true);
101 void FakeCrasAudioClient::SetOutputNodeVolume(uint64 node_id
,
105 void FakeCrasAudioClient::SetOutputUserMute(bool mute_on
) {
106 volume_state_
.output_user_mute
= mute_on
;
107 FOR_EACH_OBSERVER(Observer
,
109 OutputMuteChanged(volume_state_
.output_user_mute
));
112 void FakeCrasAudioClient::SetInputNodeGain(uint64 node_id
,
116 void FakeCrasAudioClient::SetInputMute(bool mute_on
) {
117 volume_state_
.input_mute
= mute_on
;
118 FOR_EACH_OBSERVER(Observer
,
120 InputMuteChanged(volume_state_
.input_mute
));
123 void FakeCrasAudioClient::SetActiveOutputNode(uint64 node_id
) {
124 if (active_output_node_id_
== node_id
)
127 for (size_t i
= 0; i
< node_list_
.size(); ++i
) {
128 if (node_list_
[i
].id
== active_output_node_id_
)
129 node_list_
[i
].active
= false;
130 else if (node_list_
[i
].id
== node_id
)
131 node_list_
[i
].active
= true;
133 active_output_node_id_
= node_id
;
134 FOR_EACH_OBSERVER(Observer
,
136 ActiveOutputNodeChanged(node_id
));
139 void FakeCrasAudioClient::SetActiveInputNode(uint64 node_id
) {
140 if (active_input_node_id_
== node_id
)
143 for (size_t i
= 0; i
< node_list_
.size(); ++i
) {
144 if (node_list_
[i
].id
== active_input_node_id_
)
145 node_list_
[i
].active
= false;
146 else if (node_list_
[i
].id
== node_id
)
147 node_list_
[i
].active
= true;
149 active_input_node_id_
= node_id
;
150 FOR_EACH_OBSERVER(Observer
,
152 ActiveInputNodeChanged(node_id
));
155 void FakeCrasAudioClient::AddActiveInputNode(uint64 node_id
) {
156 for (size_t i
= 0; i
< node_list_
.size(); ++i
) {
157 if (node_list_
[i
].id
== node_id
)
158 node_list_
[i
].active
= true;
162 void FakeCrasAudioClient::RemoveActiveInputNode(uint64 node_id
) {
163 for (size_t i
= 0; i
< node_list_
.size(); ++i
) {
164 if (node_list_
[i
].id
== node_id
)
165 node_list_
[i
].active
= false;
169 void FakeCrasAudioClient::SwapLeftRight(uint64 node_id
, bool swap
) {
172 void FakeCrasAudioClient::AddActiveOutputNode(uint64 node_id
) {
173 for (size_t i
= 0; i
< node_list_
.size(); ++i
) {
174 if (node_list_
[i
].id
== node_id
)
175 node_list_
[i
].active
= true;
179 void FakeCrasAudioClient::RemoveActiveOutputNode(uint64 node_id
) {
180 for (size_t i
= 0; i
< node_list_
.size(); ++i
) {
181 if (node_list_
[i
].id
== node_id
)
182 node_list_
[i
].active
= false;
186 void FakeCrasAudioClient::SetAudioNodesForTesting(
187 const AudioNodeList
& audio_nodes
) {
188 node_list_
= audio_nodes
;
191 void FakeCrasAudioClient::SetAudioNodesAndNotifyObserversForTesting(
192 const AudioNodeList
& new_nodes
) {
193 SetAudioNodesForTesting(new_nodes
);
194 FOR_EACH_OBSERVER(Observer
, observers_
, NodesChanged());
197 } // namespace chromeos