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/cras_audio_client_stub_impl.h"
9 CrasAudioClientStubImpl::CrasAudioClientStubImpl()
10 : active_input_node_id_(0),
11 active_output_node_id_(0) {
14 void CrasAudioClientStubImpl::Init(dbus::Bus
* bus
) {
15 VLOG(1) << "CrasAudioClientStubImpl is created";
17 // Fake audio output nodes.
19 node_1
.is_input
= false;
21 node_1
.device_name
= "Fake Speaker";
22 node_1
.type
= "INTERNAL_SPEAKER";
23 node_1
.name
= "Speaker";
24 node_list_
.push_back(node_1
);
27 node_2
.is_input
= false;
29 node_2
.device_name
= "Fake Headphone";
30 node_2
.type
= "HEADPHONE";
31 node_2
.name
= "Headphone";
32 node_list_
.push_back(node_2
);
35 node_3
.is_input
= false;
37 node_3
.device_name
= "Fake Bluetooth Headphone";
38 node_3
.type
= "BLUETOOTH";
39 node_3
.name
= "Headphone";
40 node_list_
.push_back(node_3
);
42 // Fake audio input ndoes
44 node_4
.is_input
= true;
46 node_4
.device_name
= "Fake Internal Mic";
47 node_4
.type
= "INTERNAL_MIC";
48 node_4
.name
= "Internal Mic";
49 node_list_
.push_back(node_4
);
52 node_5
.is_input
= true;
54 node_5
.device_name
= "Fake USB Mic";
57 node_list_
.push_back(node_5
);
60 CrasAudioClientStubImpl::~CrasAudioClientStubImpl() {
63 void CrasAudioClientStubImpl::AddObserver(Observer
* observer
) {
64 observers_
.AddObserver(observer
);
67 void CrasAudioClientStubImpl::RemoveObserver(Observer
* observer
) {
68 observers_
.RemoveObserver(observer
);
71 bool CrasAudioClientStubImpl::HasObserver(Observer
* observer
) {
72 return observers_
.HasObserver(observer
);
75 void CrasAudioClientStubImpl::GetVolumeState(
76 const GetVolumeStateCallback
& callback
) {
77 callback
.Run(volume_state_
, true);
80 void CrasAudioClientStubImpl::GetNodes(const GetNodesCallback
& callback
,
81 const ErrorCallback
& error_callback
) {
82 callback
.Run(node_list_
, true);
85 void CrasAudioClientStubImpl::SetOutputNodeVolume(uint64 node_id
,
89 void CrasAudioClientStubImpl::SetOutputUserMute(bool mute_on
) {
90 volume_state_
.output_user_mute
= mute_on
;
91 FOR_EACH_OBSERVER(Observer
,
93 OutputMuteChanged(volume_state_
.output_user_mute
));
96 void CrasAudioClientStubImpl::SetInputNodeGain(uint64 node_id
,
100 void CrasAudioClientStubImpl::SetInputMute(bool mute_on
) {
101 volume_state_
.input_mute
= mute_on
;
102 FOR_EACH_OBSERVER(Observer
,
104 InputMuteChanged(volume_state_
.input_mute
));
107 void CrasAudioClientStubImpl::SetActiveOutputNode(uint64 node_id
) {
108 if (active_output_node_id_
== node_id
)
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;
117 active_output_node_id_
= node_id
;
118 FOR_EACH_OBSERVER(Observer
,
120 ActiveOutputNodeChanged(node_id
));
123 void CrasAudioClientStubImpl::SetActiveInputNode(uint64 node_id
) {
124 if (active_input_node_id_
== node_id
)
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;
133 active_input_node_id_
= node_id
;
134 FOR_EACH_OBSERVER(Observer
,
136 ActiveInputNodeChanged(node_id
));
139 void CrasAudioClientStubImpl::SetAudioDevices(
140 const AudioNodeList
& audio_nodes
) {
142 for (size_t i
= 0; i
< audio_nodes
.size(); ++i
)
143 node_list_
.push_back(audio_nodes
[i
]);
146 void CrasAudioClientStubImpl::ChangeAudioNodes(const AudioNodeList
& new_nodes
) {
147 SetAudioDevices(new_nodes
);
148 FOR_EACH_OBSERVER(Observer
, observers_
, NodesChanged());
151 } // namespace chromeos