| OLD | NEW |
| 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/cras_audio_client.h" | 5 #include "chromeos/dbus/cras_audio_client.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 weak_ptr_factory_.GetWeakPtr())); | 238 weak_ptr_factory_.GetWeakPtr())); |
| 239 | 239 |
| 240 // Monitor the D-Bus signal for active input node change. | 240 // Monitor the D-Bus signal for active input node change. |
| 241 cras_proxy_->ConnectToSignal( | 241 cras_proxy_->ConnectToSignal( |
| 242 cras::kCrasControlInterface, | 242 cras::kCrasControlInterface, |
| 243 cras::kActiveInputNodeChanged, | 243 cras::kActiveInputNodeChanged, |
| 244 base::Bind(&CrasAudioClientImpl::ActiveInputNodeChangedReceived, | 244 base::Bind(&CrasAudioClientImpl::ActiveInputNodeChangedReceived, |
| 245 weak_ptr_factory_.GetWeakPtr()), | 245 weak_ptr_factory_.GetWeakPtr()), |
| 246 base::Bind(&CrasAudioClientImpl::SignalConnected, | 246 base::Bind(&CrasAudioClientImpl::SignalConnected, |
| 247 weak_ptr_factory_.GetWeakPtr())); | 247 weak_ptr_factory_.GetWeakPtr())); |
| 248 |
| 249 // |
| 250 cras_proxy_->ConnectToSignal( |
| 251 cras::kCrasControlInterface, "OutputNodeVolumeChanged", |
| 252 base::Bind(&CrasAudioClientImpl::OutputNodeVolumeChangedReceived, |
| 253 weak_ptr_factory_.GetWeakPtr()), |
| 254 base::Bind(&CrasAudioClientImpl::SignalConnected, |
| 255 weak_ptr_factory_.GetWeakPtr())); |
| 248 } | 256 } |
| 249 | 257 |
| 250 private: | 258 private: |
| 251 // Called when the cras signal is initially connected. | 259 // Called when the cras signal is initially connected. |
| 252 void SignalConnected(const std::string& interface_name, | 260 void SignalConnected(const std::string& interface_name, |
| 253 const std::string& signal_name, | 261 const std::string& signal_name, |
| 254 bool success) { | 262 bool success) { |
| 255 LOG_IF(ERROR, !success) | 263 LOG_IF(ERROR, !success) |
| 256 << "Failed to connect to cras signal:" << signal_name; | 264 << "Failed to connect to cras signal:" << signal_name; |
| 257 } | 265 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 void ActiveInputNodeChangedReceived(dbus::Signal* signal) { | 310 void ActiveInputNodeChangedReceived(dbus::Signal* signal) { |
| 303 dbus::MessageReader reader(signal); | 311 dbus::MessageReader reader(signal); |
| 304 uint64_t node_id; | 312 uint64_t node_id; |
| 305 if (!reader.PopUint64(&node_id)) { | 313 if (!reader.PopUint64(&node_id)) { |
| 306 LOG(ERROR) << "Error reading signal from cras:" | 314 LOG(ERROR) << "Error reading signal from cras:" |
| 307 << signal->ToString(); | 315 << signal->ToString(); |
| 308 } | 316 } |
| 309 FOR_EACH_OBSERVER(Observer, observers_, ActiveInputNodeChanged(node_id)); | 317 FOR_EACH_OBSERVER(Observer, observers_, ActiveInputNodeChanged(node_id)); |
| 310 } | 318 } |
| 311 | 319 |
| 320 void OutputNodeVolumeChangedReceived(dbus::Signal* signal) { |
| 321 dbus::MessageReader reader(signal); |
| 322 uint64_t node_id; |
| 323 int volume; |
| 324 |
| 325 if (!reader.PopUint64(&node_id)) { |
| 326 LOG(ERROR) << "Error eading signal from cras:" << signal->ToString(); |
| 327 } |
| 328 if (!reader.PopInt32(&volume)) { |
| 329 LOG(ERROR) << "Error eading signal from cras:" << signal->ToString(); |
| 330 } |
| 331 FOR_EACH_OBSERVER(Observer, observers_, |
| 332 OutputNodeVolumeChanged(node_id, volume)); |
| 333 } |
| 334 |
| 312 void OnGetVolumeState(const GetVolumeStateCallback& callback, | 335 void OnGetVolumeState(const GetVolumeStateCallback& callback, |
| 313 dbus::Response* response) { | 336 dbus::Response* response) { |
| 314 bool success = true; | 337 bool success = true; |
| 315 VolumeState volume_state; | 338 VolumeState volume_state; |
| 316 if (response) { | 339 if (response) { |
| 317 dbus::MessageReader reader(response); | 340 dbus::MessageReader reader(response); |
| 318 if (!reader.PopInt32(&volume_state.output_volume) || | 341 if (!reader.PopInt32(&volume_state.output_volume) || |
| 319 !reader.PopBool(&volume_state.output_system_mute) || | 342 !reader.PopBool(&volume_state.output_system_mute) || |
| 320 !reader.PopInt32(&volume_state.input_gain) || | 343 !reader.PopInt32(&volume_state.input_gain) || |
| 321 !reader.PopBool(&volume_state.input_mute) || | 344 !reader.PopBool(&volume_state.input_mute) || |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 | 485 |
| 463 CrasAudioClient::~CrasAudioClient() { | 486 CrasAudioClient::~CrasAudioClient() { |
| 464 } | 487 } |
| 465 | 488 |
| 466 // static | 489 // static |
| 467 CrasAudioClient* CrasAudioClient::Create() { | 490 CrasAudioClient* CrasAudioClient::Create() { |
| 468 return new CrasAudioClientImpl(); | 491 return new CrasAudioClientImpl(); |
| 469 } | 492 } |
| 470 | 493 |
| 471 } // namespace chromeos | 494 } // namespace chromeos |
| OLD | NEW |