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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "chromeos/dbus/cras_audio_client_stub_impl.h" |
10 #include "dbus/bus.h" | 11 #include "dbus/bus.h" |
11 #include "dbus/message.h" | 12 #include "dbus/message.h" |
12 #include "dbus/object_path.h" | 13 #include "dbus/object_path.h" |
13 #include "dbus/object_proxy.h" | 14 #include "dbus/object_proxy.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 15 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 16 |
16 namespace chromeos { | 17 namespace chromeos { |
17 | 18 |
18 // The CrasAudioClient implementation used in production. | 19 // The CrasAudioClient implementation used in production. |
19 class CrasAudioClientImpl : public CrasAudioClient { | 20 class CrasAudioClientImpl : public CrasAudioClient { |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 dbus::ObjectProxy* cras_proxy_; | 344 dbus::ObjectProxy* cras_proxy_; |
344 ObserverList<Observer> observers_; | 345 ObserverList<Observer> observers_; |
345 | 346 |
346 // Note: This should remain the last member so it'll be destroyed and | 347 // Note: This should remain the last member so it'll be destroyed and |
347 // invalidate its weak pointers before any other members are destroyed. | 348 // invalidate its weak pointers before any other members are destroyed. |
348 base::WeakPtrFactory<CrasAudioClientImpl> weak_ptr_factory_; | 349 base::WeakPtrFactory<CrasAudioClientImpl> weak_ptr_factory_; |
349 | 350 |
350 DISALLOW_COPY_AND_ASSIGN(CrasAudioClientImpl); | 351 DISALLOW_COPY_AND_ASSIGN(CrasAudioClientImpl); |
351 }; | 352 }; |
352 | 353 |
353 // The CrasAudioClient implementation used on Linux desktop, | |
354 // which does nothing. | |
355 class CrasAudioClientStubImpl : public CrasAudioClient { | |
356 public: | |
357 CrasAudioClientStubImpl() { | |
358 VLOG(1) << "CrasAudioClientStubImpl is created"; | |
359 | |
360 // Fake audio output nodes. | |
361 AudioNode node_1; | |
362 node_1.is_input = false; | |
363 node_1.id = 10001; | |
364 node_1.device_name = "Fake Speaker"; | |
365 node_1.type = "INTERNAL_SPEAKER"; | |
366 node_1.name = "Speaker"; | |
367 node_1.active = false; | |
368 node_list_.push_back(node_1); | |
369 | |
370 AudioNode node_2; | |
371 node_2.is_input = false; | |
372 node_2.id = 10002; | |
373 node_2.device_name = "Fake Headphone"; | |
374 node_2.type = "HEADPHONE"; | |
375 node_2.name = "Headphone"; | |
376 node_2.active = true; | |
377 node_list_.push_back(node_2); | |
378 active_output_node_id_ = node_2.id; | |
379 | |
380 AudioNode node_3; | |
381 node_3.is_input = false; | |
382 node_3.id = 10003; | |
383 node_3.device_name = "Fake Audio Output"; | |
384 node_3.type = "BLUETOOTH"; | |
385 node_3.name = "Bluetooth Headphone"; | |
386 node_3.active = false; | |
387 node_list_.push_back(node_3); | |
388 | |
389 // Fake audio input ndoes | |
390 AudioNode node_4; | |
391 node_4.is_input = true; | |
392 node_4.id = 10004; | |
393 node_4.device_name = "Fake Internal Mic"; | |
394 node_4.type = "INTERNAL_MIC"; | |
395 node_4.name = "Internal Mic"; | |
396 node_4.active = false; | |
397 node_list_.push_back(node_4); | |
398 | |
399 AudioNode node_5; | |
400 node_5.is_input = true; | |
401 node_5.id = 10005; | |
402 node_5.device_name = "Fake Internal Mic"; | |
403 node_5.type = "USB"; | |
404 node_5.name = "USB Mic"; | |
405 node_5.active = true; | |
406 node_list_.push_back(node_5); | |
407 active_input_node_id_ = node_5.id; | |
408 } | |
409 virtual ~CrasAudioClientStubImpl() { | |
410 } | |
411 | |
412 // CrasAudioClient overrides: | |
413 // TODO(jennyz): Implement the observers and callbacks in the stub for UI | |
414 // testing. | |
415 virtual void AddObserver(Observer* observer) OVERRIDE { | |
416 observers_.AddObserver(observer); | |
417 } | |
418 | |
419 virtual void RemoveObserver(Observer* observer) OVERRIDE { | |
420 observers_.RemoveObserver(observer); | |
421 } | |
422 | |
423 virtual bool HasObserver(Observer* observer) OVERRIDE { | |
424 return observers_.HasObserver(observer); | |
425 } | |
426 | |
427 virtual void GetVolumeState(const GetVolumeStateCallback& callback) OVERRIDE { | |
428 callback.Run(volume_state_, true); | |
429 } | |
430 | |
431 virtual void GetNodes(const GetNodesCallback& callback)OVERRIDE { | |
432 callback.Run(node_list_, true); | |
433 } | |
434 | |
435 virtual void SetOutputNodeVolume(uint64 node_id, int32 volume) OVERRIDE { | |
436 } | |
437 | |
438 virtual void SetOutputUserMute(bool mute_on) OVERRIDE { | |
439 volume_state_.output_user_mute = mute_on; | |
440 FOR_EACH_OBSERVER(Observer, | |
441 observers_, | |
442 OutputMuteChanged(volume_state_.output_user_mute)); | |
443 } | |
444 | |
445 virtual void SetInputNodeGain(uint64 node_id, int32 input_gain) OVERRIDE { | |
446 } | |
447 | |
448 virtual void SetInputMute(bool mute_on) OVERRIDE { | |
449 volume_state_.input_mute = mute_on; | |
450 FOR_EACH_OBSERVER(Observer, | |
451 observers_, | |
452 InputMuteChanged(volume_state_.input_mute)); | |
453 } | |
454 | |
455 virtual void SetActiveOutputNode(uint64 node_id) OVERRIDE { | |
456 if (active_output_node_id_ == node_id) | |
457 return; | |
458 | |
459 for (size_t i = 0; i < node_list_.size(); ++i) { | |
460 if (node_list_[i].id == active_output_node_id_) | |
461 node_list_[i].active = false; | |
462 else if (node_list_[i].id == node_id) | |
463 node_list_[i].active = true; | |
464 } | |
465 active_output_node_id_ = node_id; | |
466 FOR_EACH_OBSERVER(Observer, | |
467 observers_, | |
468 ActiveOutputNodeChanged(node_id)); | |
469 } | |
470 | |
471 virtual void SetActiveInputNode(uint64 node_id) OVERRIDE { | |
472 if (active_input_node_id_ == node_id) | |
473 return; | |
474 | |
475 for (size_t i = 0; i < node_list_.size(); ++i) { | |
476 if (node_list_[i].id == active_input_node_id_) | |
477 node_list_[i].active = false; | |
478 else if (node_list_[i].id == node_id) | |
479 node_list_[i].active = true; | |
480 } | |
481 active_input_node_id_ = node_id; | |
482 FOR_EACH_OBSERVER(Observer, | |
483 observers_, | |
484 ActiveInputNodeChanged(node_id)); | |
485 } | |
486 | |
487 private: | |
488 VolumeState volume_state_; | |
489 AudioNodeList node_list_; | |
490 uint64 active_input_node_id_; | |
491 uint64 active_output_node_id_; | |
492 ObserverList<Observer> observers_; | |
493 | |
494 DISALLOW_COPY_AND_ASSIGN(CrasAudioClientStubImpl); | |
495 }; | |
496 | |
497 CrasAudioClient::Observer::~Observer() { | 354 CrasAudioClient::Observer::~Observer() { |
498 } | 355 } |
499 | 356 |
500 void CrasAudioClient::Observer::AudioClientRestarted() { | 357 void CrasAudioClient::Observer::AudioClientRestarted() { |
501 } | 358 } |
502 | 359 |
503 void CrasAudioClient::Observer::OutputMuteChanged(bool mute_on) { | 360 void CrasAudioClient::Observer::OutputMuteChanged(bool mute_on) { |
504 } | 361 } |
505 | 362 |
506 void CrasAudioClient::Observer::InputMuteChanged(bool mute_on) { | 363 void CrasAudioClient::Observer::InputMuteChanged(bool mute_on) { |
(...skipping 19 matching lines...) Expand all Loading... |
526 DBusClientImplementationType type, | 383 DBusClientImplementationType type, |
527 dbus::Bus* bus) { | 384 dbus::Bus* bus) { |
528 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) { | 385 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) { |
529 return new CrasAudioClientImpl(bus); | 386 return new CrasAudioClientImpl(bus); |
530 } | 387 } |
531 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 388 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
532 return new CrasAudioClientStubImpl(); | 389 return new CrasAudioClientStubImpl(); |
533 } | 390 } |
534 | 391 |
535 } // namespace chromeos | 392 } // namespace chromeos |
OLD | NEW |