summaryrefslogtreecommitdiffstats
path: root/chromeos
diff options
context:
space:
mode:
authormozartalouis <mozartalouis@google.com>2015-08-11 11:23:51 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-11 18:24:31 +0000
commita79e8ad477bb753fbed0bb2e00864419915b44e7 (patch)
tree89cbdba65226e38431c0bdab3f93a130cd649610 /chromeos
parent6a2d1066d7ab5bd4e6c1d3b5bf36a22c0aa95bfa (diff)
downloadchromium_src-a79e8ad477bb753fbed0bb2e00864419915b44e7.zip
chromium_src-a79e8ad477bb753fbed0bb2e00864419915b44e7.tar.gz
chromium_src-a79e8ad477bb753fbed0bb2e00864419915b44e7.tar.bz2
Implementation of Audio for the Chrome Os Device Emulator
BUG=516545 Review URL: https://codereview.chromium.org/1274403003 Cr-Commit-Position: refs/heads/master@{#342849}
Diffstat (limited to 'chromeos')
-rw-r--r--chromeos/dbus/fake_cras_audio_client.cc45
-rw-r--r--chromeos/dbus/fake_cras_audio_client.h15
2 files changed, 44 insertions, 16 deletions
diff --git a/chromeos/dbus/fake_cras_audio_client.cc b/chromeos/dbus/fake_cras_audio_client.cc
index c59b3e5..e28852b 100644
--- a/chromeos/dbus/fake_cras_audio_client.cc
+++ b/chromeos/dbus/fake_cras_audio_client.cc
@@ -98,25 +98,19 @@ void FakeCrasAudioClient::GetNodes(const GetNodesCallback& callback,
callback.Run(node_list_, true);
}
-void FakeCrasAudioClient::SetOutputNodeVolume(uint64 node_id,
- int32 volume) {
-}
+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_,
+ FOR_EACH_OBSERVER(Observer, observers_,
OutputMuteChanged(volume_state_.output_user_mute));
}
-void FakeCrasAudioClient::SetInputNodeGain(uint64 node_id,
- int32 input_gain) {
-}
+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_,
+ FOR_EACH_OBSERVER(Observer, observers_,
InputMuteChanged(volume_state_.input_mute));
}
@@ -131,9 +125,7 @@ void FakeCrasAudioClient::SetActiveOutputNode(uint64 node_id) {
node_list_[i].active = true;
}
active_output_node_id_ = node_id;
- FOR_EACH_OBSERVER(Observer,
- observers_,
- ActiveOutputNodeChanged(node_id));
+ FOR_EACH_OBSERVER(Observer, observers_, ActiveOutputNodeChanged(node_id));
}
void FakeCrasAudioClient::SetActiveInputNode(uint64 node_id) {
@@ -147,9 +139,7 @@ void FakeCrasAudioClient::SetActiveInputNode(uint64 node_id) {
node_list_[i].active = true;
}
active_input_node_id_ = node_id;
- FOR_EACH_OBSERVER(Observer,
- observers_,
- ActiveInputNodeChanged(node_id));
+ FOR_EACH_OBSERVER(Observer, observers_, ActiveInputNodeChanged(node_id));
}
void FakeCrasAudioClient::AddActiveInputNode(uint64 node_id) {
@@ -183,6 +173,23 @@ void FakeCrasAudioClient::RemoveActiveOutputNode(uint64 node_id) {
}
}
+void FakeCrasAudioClient::InsertAudioNodeToList(const AudioNode& audio_node) {
+ auto iter = FindNode(audio_node.id);
+ if (iter != node_list_.end())
+ (*iter) = audio_node;
+ else
+ node_list_.push_back(audio_node);
+ FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
+}
+
+void FakeCrasAudioClient::RemoveAudioNodeFromList(const uint64& node_id) {
+ auto iter = FindNode(node_id);
+ if (iter != node_list_.end()) {
+ node_list_.erase(iter);
+ FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
+ }
+}
+
void FakeCrasAudioClient::SetAudioNodesForTesting(
const AudioNodeList& audio_nodes) {
node_list_ = audio_nodes;
@@ -194,4 +201,10 @@ void FakeCrasAudioClient::SetAudioNodesAndNotifyObserversForTesting(
FOR_EACH_OBSERVER(Observer, observers_, NodesChanged());
}
+AudioNodeList::iterator FakeCrasAudioClient::FindNode(uint64 node_id) {
+ return std::find_if(
+ node_list_.begin(), node_list_.end(),
+ [node_id](const AudioNode& node) { return node_id == node.id; });
+}
+
} // namespace chromeos
diff --git a/chromeos/dbus/fake_cras_audio_client.h b/chromeos/dbus/fake_cras_audio_client.h
index ab5b9f7..cb15ab6 100644
--- a/chromeos/dbus/fake_cras_audio_client.h
+++ b/chromeos/dbus/fake_cras_audio_client.h
@@ -38,6 +38,14 @@ class CHROMEOS_EXPORT FakeCrasAudioClient : public CrasAudioClient {
void RemoveActiveOutputNode(uint64 node_id) override;
void SwapLeftRight(uint64 node_id, bool swap) override;
+ // Modifies an AudioNode from |node_list_| based on |audio_node.id|.
+ // if the |audio_node.id| cannot be found in list, Add an
+ // AudioNode to |node_list_|
+ void InsertAudioNodeToList(const AudioNode& audio_node);
+
+ // Removes an AudioNode from |node_list_| based on |node_id|.
+ void RemoveAudioNodeFromList(const uint64& node_id);
+
// Updates |node_list_| to contain |audio_nodes|.
void SetAudioNodesForTesting(const AudioNodeList& audio_nodes);
@@ -45,7 +53,14 @@ class CHROMEOS_EXPORT FakeCrasAudioClient : public CrasAudioClient {
void SetAudioNodesAndNotifyObserversForTesting(
const AudioNodeList& new_nodes);
+ const AudioNodeList& node_list() const { return node_list_; }
+ const uint64& active_input_node_id() const { return active_input_node_id_; }
+ const uint64& active_output_node_id() const { return active_output_node_id_; }
+
private:
+ // Find a node in the list based on the id.
+ AudioNodeList::iterator FindNode(uint64 node_id);
+
VolumeState volume_state_;
AudioNodeList node_list_;
uint64 active_input_node_id_;