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 CrasAudioClientStubImpl::~CrasAudioClientStubImpl() {
17 void CrasAudioClientStubImpl::Init(dbus::Bus* bus) {
18 VLOG(1) << "CrasAudioClientStubImpl is created";
20 // Fake audio output nodes.
22 node_1.is_input = false;
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);
30 node_2.is_input = false;
32 node_2.device_name = "Fake Headphone";
33 node_2.type = "HEADPHONE";
34 node_2.name = "Headphone";
35 node_list_.push_back(node_2);
38 node_3.is_input = false;
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);
45 // Fake audio input ndoes
47 node_4.is_input = true;
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);
55 node_5.is_input = true;
57 node_5.device_name = "Fake USB Mic";
60 node_list_.push_back(node_5);
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::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;
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;
153 void CrasAudioClientStubImpl::AddActiveOutputNode(uint64 node_id) {
154 for (size_t i = 0; i < node_list_.size(); ++i) {
155 if (node_list_[i].id == node_id)
156 node_list_[i].active = true;
160 void CrasAudioClientStubImpl::RemoveActiveOutputNode(uint64 node_id) {
161 for (size_t i = 0; i < node_list_.size(); ++i) {
162 if (node_list_[i].id == node_id)
163 node_list_[i].active = false;
167 void CrasAudioClientStubImpl::SetAudioNodesForTesting(
168 const AudioNodeList& audio_nodes) {
169 node_list_ = audio_nodes;
172 void CrasAudioClientStubImpl::SetAudioNodesAndNotifyObserversForTesting(
173 const AudioNodeList& new_nodes) {
174 SetAudioNodesForTesting(new_nodes);
175 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
178 } // namespace chromeos