Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: chromeos/dbus/fake_cras_audio_client.cc

Issue 1274403003: Full Implementation of Audio for the Chrome Os Device Emulator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromeos/dbus/fake_cras_audio_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chromeos/dbus/fake_cras_audio_client.h" 5 #include "chromeos/dbus/fake_cras_audio_client.h"
6 6
7 namespace chromeos { 7 namespace chromeos {
8 8
9 FakeCrasAudioClient::FakeCrasAudioClient() 9 FakeCrasAudioClient::FakeCrasAudioClient()
10 : active_input_node_id_(0), 10 : active_input_node_id_(0),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void FakeCrasAudioClient::GetVolumeState( 91 void FakeCrasAudioClient::GetVolumeState(
92 const GetVolumeStateCallback& callback) { 92 const GetVolumeStateCallback& callback) {
93 callback.Run(volume_state_, true); 93 callback.Run(volume_state_, true);
94 } 94 }
95 95
96 void FakeCrasAudioClient::GetNodes(const GetNodesCallback& callback, 96 void FakeCrasAudioClient::GetNodes(const GetNodesCallback& callback,
97 const ErrorCallback& error_callback) { 97 const ErrorCallback& error_callback) {
98 callback.Run(node_list_, true); 98 callback.Run(node_list_, true);
99 } 99 }
100 100
101 void FakeCrasAudioClient::SetOutputNodeVolume(uint64 node_id, 101 void FakeCrasAudioClient::SetOutputNodeVolume(uint64 node_id, int32 volume) {}
102 int32 volume) {
103 }
104 102
105 void FakeCrasAudioClient::SetOutputUserMute(bool mute_on) { 103 void FakeCrasAudioClient::SetOutputUserMute(bool mute_on) {
106 volume_state_.output_user_mute = mute_on; 104 volume_state_.output_user_mute = mute_on;
107 FOR_EACH_OBSERVER(Observer, 105 FOR_EACH_OBSERVER(Observer, observers_,
108 observers_,
109 OutputMuteChanged(volume_state_.output_user_mute)); 106 OutputMuteChanged(volume_state_.output_user_mute));
110 } 107 }
111 108
112 void FakeCrasAudioClient::SetInputNodeGain(uint64 node_id, 109 void FakeCrasAudioClient::SetInputNodeGain(uint64 node_id, int32 input_gain) {}
113 int32 input_gain) {
114 }
115 110
116 void FakeCrasAudioClient::SetInputMute(bool mute_on) { 111 void FakeCrasAudioClient::SetInputMute(bool mute_on) {
117 volume_state_.input_mute = mute_on; 112 volume_state_.input_mute = mute_on;
118 FOR_EACH_OBSERVER(Observer, 113 FOR_EACH_OBSERVER(Observer, observers_,
119 observers_,
120 InputMuteChanged(volume_state_.input_mute)); 114 InputMuteChanged(volume_state_.input_mute));
121 } 115 }
122 116
123 void FakeCrasAudioClient::SetActiveOutputNode(uint64 node_id) { 117 void FakeCrasAudioClient::SetActiveOutputNode(uint64 node_id) {
124 if (active_output_node_id_ == node_id) 118 if (active_output_node_id_ == node_id)
125 return; 119 return;
126 120
127 for (size_t i = 0; i < node_list_.size(); ++i) { 121 for (size_t i = 0; i < node_list_.size(); ++i) {
128 if (node_list_[i].id == active_output_node_id_) 122 if (node_list_[i].id == active_output_node_id_)
129 node_list_[i].active = false; 123 node_list_[i].active = false;
130 else if (node_list_[i].id == node_id) 124 else if (node_list_[i].id == node_id)
131 node_list_[i].active = true; 125 node_list_[i].active = true;
132 } 126 }
133 active_output_node_id_ = node_id; 127 active_output_node_id_ = node_id;
134 FOR_EACH_OBSERVER(Observer, 128 FOR_EACH_OBSERVER(Observer, observers_, ActiveOutputNodeChanged(node_id));
135 observers_,
136 ActiveOutputNodeChanged(node_id));
137 } 129 }
138 130
139 void FakeCrasAudioClient::SetActiveInputNode(uint64 node_id) { 131 void FakeCrasAudioClient::SetActiveInputNode(uint64 node_id) {
140 if (active_input_node_id_ == node_id) 132 if (active_input_node_id_ == node_id)
141 return; 133 return;
142 134
143 for (size_t i = 0; i < node_list_.size(); ++i) { 135 for (size_t i = 0; i < node_list_.size(); ++i) {
144 if (node_list_[i].id == active_input_node_id_) 136 if (node_list_[i].id == active_input_node_id_)
145 node_list_[i].active = false; 137 node_list_[i].active = false;
146 else if (node_list_[i].id == node_id) 138 else if (node_list_[i].id == node_id)
147 node_list_[i].active = true; 139 node_list_[i].active = true;
148 } 140 }
149 active_input_node_id_ = node_id; 141 active_input_node_id_ = node_id;
150 FOR_EACH_OBSERVER(Observer, 142 FOR_EACH_OBSERVER(Observer, observers_, ActiveInputNodeChanged(node_id));
151 observers_,
152 ActiveInputNodeChanged(node_id));
153 } 143 }
154 144
155 void FakeCrasAudioClient::AddActiveInputNode(uint64 node_id) { 145 void FakeCrasAudioClient::AddActiveInputNode(uint64 node_id) {
156 for (size_t i = 0; i < node_list_.size(); ++i) { 146 for (size_t i = 0; i < node_list_.size(); ++i) {
157 if (node_list_[i].id == node_id) 147 if (node_list_[i].id == node_id)
158 node_list_[i].active = true; 148 node_list_[i].active = true;
159 } 149 }
160 } 150 }
161 151
162 void FakeCrasAudioClient::RemoveActiveInputNode(uint64 node_id) { 152 void FakeCrasAudioClient::RemoveActiveInputNode(uint64 node_id) {
(...skipping 13 matching lines...) Expand all
176 } 166 }
177 } 167 }
178 168
179 void FakeCrasAudioClient::RemoveActiveOutputNode(uint64 node_id) { 169 void FakeCrasAudioClient::RemoveActiveOutputNode(uint64 node_id) {
180 for (size_t i = 0; i < node_list_.size(); ++i) { 170 for (size_t i = 0; i < node_list_.size(); ++i) {
181 if (node_list_[i].id == node_id) 171 if (node_list_[i].id == node_id)
182 node_list_[i].active = false; 172 node_list_[i].active = false;
183 } 173 }
184 } 174 }
185 175
176 void FakeCrasAudioClient::InsertAudioNodeToList(const AudioNode& audio_node) {
177 auto iter = FindNode(audio_node.id);
178 if (iter != node_list_.end())
179 (*iter) = audio_node;
180 else
181 node_list_.push_back(audio_node);
182 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
183 }
184
185 void FakeCrasAudioClient::RemoveAudioNodeFromList(const uint64& node_id) {
186 auto iter = FindNode(node_id);
187 if (iter != node_list_.end()) {
188 node_list_.erase(iter);
189 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
190 }
191 }
192
186 void FakeCrasAudioClient::SetAudioNodesForTesting( 193 void FakeCrasAudioClient::SetAudioNodesForTesting(
187 const AudioNodeList& audio_nodes) { 194 const AudioNodeList& audio_nodes) {
188 node_list_ = audio_nodes; 195 node_list_ = audio_nodes;
189 } 196 }
190 197
191 void FakeCrasAudioClient::SetAudioNodesAndNotifyObserversForTesting( 198 void FakeCrasAudioClient::SetAudioNodesAndNotifyObserversForTesting(
192 const AudioNodeList& new_nodes) { 199 const AudioNodeList& new_nodes) {
193 SetAudioNodesForTesting(new_nodes); 200 SetAudioNodesForTesting(new_nodes);
194 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged()); 201 FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
195 } 202 }
196 203
204 AudioNodeList::iterator FakeCrasAudioClient::FindNode(uint64 node_id) {
205 return std::find_if(
206 node_list_.begin(), node_list_.end(),
207 [node_id](const AudioNode& node) { return node_id == node.id; });
208 }
209
197 } // namespace chromeos 210 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_cras_audio_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698