| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 weak_ptr_factory_.GetWeakPtr())); | 250 weak_ptr_factory_.GetWeakPtr())); |
| 251 | 251 |
| 252 // Monitor the D-Bus signal for active input node change. | 252 // Monitor the D-Bus signal for active input node change. |
| 253 cras_proxy_->ConnectToSignal( | 253 cras_proxy_->ConnectToSignal( |
| 254 cras::kCrasControlInterface, | 254 cras::kCrasControlInterface, |
| 255 cras::kActiveInputNodeChanged, | 255 cras::kActiveInputNodeChanged, |
| 256 base::Bind(&CrasAudioClientImpl::ActiveInputNodeChangedReceived, | 256 base::Bind(&CrasAudioClientImpl::ActiveInputNodeChangedReceived, |
| 257 weak_ptr_factory_.GetWeakPtr()), | 257 weak_ptr_factory_.GetWeakPtr()), |
| 258 base::Bind(&CrasAudioClientImpl::SignalConnected, | 258 base::Bind(&CrasAudioClientImpl::SignalConnected, |
| 259 weak_ptr_factory_.GetWeakPtr())); | 259 weak_ptr_factory_.GetWeakPtr())); |
| 260 |
| 261 // Monitor the D-Bus signal for output node volume change. |
| 262 cras_proxy_->ConnectToSignal( |
| 263 cras::kCrasControlInterface, |
| 264 cras::kOutputNodeVolumeChanged, |
| 265 base::Bind(&CrasAudioClientImpl::OutputNodeVolumeChangedReceived, |
| 266 weak_ptr_factory_.GetWeakPtr()), |
| 267 base::Bind(&CrasAudioClientImpl::SignalConnected, |
| 268 weak_ptr_factory_.GetWeakPtr())); |
| 260 } | 269 } |
| 261 | 270 |
| 262 private: | 271 private: |
| 263 // Called when the cras signal is initially connected. | 272 // Called when the cras signal is initially connected. |
| 264 void SignalConnected(const std::string& interface_name, | 273 void SignalConnected(const std::string& interface_name, |
| 265 const std::string& signal_name, | 274 const std::string& signal_name, |
| 266 bool success) { | 275 bool success) { |
| 267 LOG_IF(ERROR, !success) | 276 LOG_IF(ERROR, !success) |
| 268 << "Failed to connect to cras signal:" << signal_name; | 277 << "Failed to connect to cras signal:" << signal_name; |
| 269 } | 278 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 void ActiveInputNodeChangedReceived(dbus::Signal* signal) { | 323 void ActiveInputNodeChangedReceived(dbus::Signal* signal) { |
| 315 dbus::MessageReader reader(signal); | 324 dbus::MessageReader reader(signal); |
| 316 uint64_t node_id; | 325 uint64_t node_id; |
| 317 if (!reader.PopUint64(&node_id)) { | 326 if (!reader.PopUint64(&node_id)) { |
| 318 LOG(ERROR) << "Error reading signal from cras:" | 327 LOG(ERROR) << "Error reading signal from cras:" |
| 319 << signal->ToString(); | 328 << signal->ToString(); |
| 320 } | 329 } |
| 321 FOR_EACH_OBSERVER(Observer, observers_, ActiveInputNodeChanged(node_id)); | 330 FOR_EACH_OBSERVER(Observer, observers_, ActiveInputNodeChanged(node_id)); |
| 322 } | 331 } |
| 323 | 332 |
| 333 void OutputNodeVolumeChangedReceived(dbus::Signal* signal) { |
| 334 dbus::MessageReader reader(signal); |
| 335 uint64_t node_id; |
| 336 int volume; |
| 337 |
| 338 if (!reader.PopUint64(&node_id)) { |
| 339 LOG(ERROR) << "Error eading signal from cras:" << signal->ToString(); |
| 340 } |
| 341 if (!reader.PopInt32(&volume)) { |
| 342 LOG(ERROR) << "Error eading signal from cras:" << signal->ToString(); |
| 343 } |
| 344 FOR_EACH_OBSERVER(Observer, observers_, |
| 345 OutputNodeVolumeChanged(node_id, volume)); |
| 346 } |
| 347 |
| 324 void OnGetVolumeState(const GetVolumeStateCallback& callback, | 348 void OnGetVolumeState(const GetVolumeStateCallback& callback, |
| 325 dbus::Response* response) { | 349 dbus::Response* response) { |
| 326 bool success = true; | 350 bool success = true; |
| 327 VolumeState volume_state; | 351 VolumeState volume_state; |
| 328 if (response) { | 352 if (response) { |
| 329 dbus::MessageReader reader(response); | 353 dbus::MessageReader reader(response); |
| 330 if (!reader.PopInt32(&volume_state.output_volume) || | 354 if (!reader.PopInt32(&volume_state.output_volume) || |
| 331 !reader.PopBool(&volume_state.output_system_mute) || | 355 !reader.PopBool(&volume_state.output_system_mute) || |
| 332 !reader.PopInt32(&volume_state.input_gain) || | 356 !reader.PopInt32(&volume_state.input_gain) || |
| 333 !reader.PopBool(&volume_state.input_mute) || | 357 !reader.PopBool(&volume_state.input_mute) || |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 void CrasAudioClient::Observer::InputMuteChanged(bool mute_on) { | 486 void CrasAudioClient::Observer::InputMuteChanged(bool mute_on) { |
| 463 } | 487 } |
| 464 | 488 |
| 465 void CrasAudioClient::Observer::NodesChanged() { | 489 void CrasAudioClient::Observer::NodesChanged() { |
| 466 } | 490 } |
| 467 | 491 |
| 468 void CrasAudioClient::Observer::ActiveOutputNodeChanged(uint64_t node_id) {} | 492 void CrasAudioClient::Observer::ActiveOutputNodeChanged(uint64_t node_id) {} |
| 469 | 493 |
| 470 void CrasAudioClient::Observer::ActiveInputNodeChanged(uint64_t node_id) {} | 494 void CrasAudioClient::Observer::ActiveInputNodeChanged(uint64_t node_id) {} |
| 471 | 495 |
| 496 void CrasAudioClient::Observer::OutputNodeVolumeChanged(uint64_t node_id, |
| 497 int volume) { |
| 498 } |
| 499 |
| 472 CrasAudioClient::CrasAudioClient() { | 500 CrasAudioClient::CrasAudioClient() { |
| 473 } | 501 } |
| 474 | 502 |
| 475 CrasAudioClient::~CrasAudioClient() { | 503 CrasAudioClient::~CrasAudioClient() { |
| 476 } | 504 } |
| 477 | 505 |
| 478 // static | 506 // static |
| 479 CrasAudioClient* CrasAudioClient::Create() { | 507 CrasAudioClient* CrasAudioClient::Create() { |
| 480 return new CrasAudioClientImpl(); | 508 return new CrasAudioClientImpl(); |
| 481 } | 509 } |
| 482 | 510 |
| 483 } // namespace chromeos | 511 } // namespace chromeos |
| OLD | NEW |