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

Unified Diff: chromeos/dbus/cras_audio_client.cc

Issue 14314002: Implement new audio handler which talks to the new audio dbus apis. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« chromeos/audio/cras_audio_handler.cc ('K') | « chromeos/dbus/cras_audio_client.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/dbus/cras_audio_client.cc
diff --git a/chromeos/dbus/cras_audio_client.cc b/chromeos/dbus/cras_audio_client.cc
index bffa4d40cecf2b7ded287bc0d988201662de2f23..5e6a377003306004fd14a69ee76cc4adfeeea40d 100644
--- a/chromeos/dbus/cras_audio_client.cc
+++ b/chromeos/dbus/cras_audio_client.cc
@@ -37,6 +37,11 @@ class CrasAudioClientImpl : public CrasAudioClient {
cras::kCrasServiceName,
dbus::ObjectPath(cras::kCrasServicePath));
+ // Monitor NameOwnerChanged signal.
+ cras_proxy_->SetNameOwnerChangedCallback(
+ base::Bind(&CrasAudioClientImpl::NameOwnerChangedReceived,
+ weak_ptr_factory_.GetWeakPtr()));
+
// Monitor the D-Bus signal for output volume change.
cras_proxy_->ConnectToSignal(
cras::kCrasControlInterface,
@@ -212,6 +217,10 @@ class CrasAudioClientImpl : public CrasAudioClient {
<< "Failed to connect to cras signal:" << signal_name;
}
+ void NameOwnerChangedReceived(dbus::Signal* signal) {
+ FOR_EACH_OBSERVER(Observer, observers_, AudioClientRestarted());
+ }
+
// Called when a OutputVolumeChanged signal is received.
void OutputVolumeChangedReceived(dbus::Signal* signal) {
dbus::MessageReader reader(signal);
@@ -309,7 +318,7 @@ class CrasAudioClientImpl : public CrasAudioClient {
if (response) {
dbus::MessageReader response_reader(response);
dbus::MessageReader array_reader(response);
- while(response_reader.HasMoreData()) {
+ while (response_reader.HasMoreData()) {
if (!response_reader.PopArray(&array_reader)) {
success = false;
LOG(ERROR) << "Error reading response from cras: "
@@ -388,32 +397,113 @@ class CrasAudioClientStubImpl : public CrasAudioClient {
public:
CrasAudioClientStubImpl() {
VLOG(1) << "CrasAudioClientStubImpl is created";
+
+ // Fake audio nodes.
+ AudioNode node_1;
+ node_1.is_input = false;
+ node_1.id = 10001;
+ node_1.device_name = "Fake Audio Output";
+ node_1.type = "INTERNAL_SPEAKER";
+ node_1.name = "Internal Speaker";
+ node_1.active = true;
+
+ AudioNode node_2;
+ node_2.is_input = true;
+ node_2.id = 10002;
+ node_2.device_name = "Fake Audio Input";
+ node_2.type = "INTERNAL_MIC";
+ node_2.name = "Internal Mic";
+ node_2.active = true;
+
+ node_list_.push_back(node_1);
+ node_list_.push_back(node_2);
+ }
+ virtual ~CrasAudioClientStubImpl() {
}
- virtual ~CrasAudioClientStubImpl() {}
// CrasAudioClient overrides:
// TODO(jennyz): Implement the observers and callbacks in the stub for UI
// testing.
- virtual void AddObserver(Observer* observer) OVERRIDE {}
- virtual void RemoveObserver(Observer* observer) OVERRIDE {}
- virtual bool HasObserver(Observer* observer) OVERRIDE { return false; }
+ virtual void AddObserver(Observer* observer) OVERRIDE {
+ observers_.AddObserver(observer);
+ }
+
+ virtual void RemoveObserver(Observer* observer) OVERRIDE {
+ observers_.RemoveObserver(observer);
+ }
+
+ virtual bool HasObserver(Observer* observer) OVERRIDE {
+ return observers_.HasObserver(observer);
+ }
+
virtual void GetVolumeState(const GetVolumeStateCallback& callback) OVERRIDE {
+ callback.Run(volume_state_, true);
+ }
+
+ virtual void GetNodes(const GetNodesCallback& callback)OVERRIDE {
+ callback.Run(node_list_, true);
+ }
+
+ virtual void SetOutputVolume(int32 volume) OVERRIDE {
+ LOG(ERROR) << "CrasAudioClientStubImpl::SetOutputVolume volume=" << volume;
stevenjb 2013/04/17 01:25:12 ->VLOG here and below
jennyz 2013/04/18 01:21:19 Done.
+ volume_state_.output_volume = volume;
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ OutputVolumeChanged(volume_state_.output_volume));
+ }
+
+ virtual void SetOutputMute(bool mute_on) OVERRIDE {
+ LOG(ERROR) << "CrasAudioClientStubImpl::SetOutputMute, mute_on=" << mute_on;
+ volume_state_.output_mute = mute_on;
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ OutputMuteChanged(volume_state_.output_mute));
+ }
+
+ virtual void SetInputGain(int32 input_gain) OVERRIDE {
+ volume_state_.input_gain = input_gain;
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ InputGainChanged(volume_state_.input_gain));
+ }
+
+ virtual void SetInputMute(bool mute_on) OVERRIDE {
+ volume_state_.input_mute = mute_on;
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ InputMuteChanged(volume_state_.input_mute));
+ }
+
+ virtual void SetActiveOutputNode(uint64 node_id) OVERRIDE {
+ active_output_node_id_ = node_id;
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ ActiveOutputNodeChanged(node_id));
+ }
+
+ virtual void SetActiveInputNode(uint64 node_id) OVERRIDE {
+ active_input_node_id_ = node_id;
+ FOR_EACH_OBSERVER(Observer,
+ observers_,
+ ActiveInputNodeChanged(node_id));
}
- virtual void GetNodes(const GetNodesCallback& callback)OVERRIDE {}
- virtual void SetOutputVolume(int32 volume) OVERRIDE {}
- virtual void SetOutputMute(bool mute_on) OVERRIDE {}
- virtual void SetInputGain(int32 input_gain) OVERRIDE {}
- virtual void SetInputMute(bool mute_on) OVERRIDE {}
- virtual void SetActiveOutputNode(uint64 node_id) OVERRIDE {}
- virtual void SetActiveInputNode(uint64 node_id) OVERRIDE {}
private:
+ VolumeState volume_state_;
+ AudioNodeList node_list_;
+ uint64 active_input_node_id_;
+ uint64 active_output_node_id_;
+ ObserverList<Observer> observers_;
+
DISALLOW_COPY_AND_ASSIGN(CrasAudioClientStubImpl);
};
CrasAudioClient::Observer::~Observer() {
}
+void CrasAudioClient::Observer::AudioClientRestarted() {
+}
+
void CrasAudioClient::Observer::OutputVolumeChanged(int32 volume) {
}
« chromeos/audio/cras_audio_handler.cc ('K') | « chromeos/dbus/cras_audio_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698