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