| 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/audio/cras_audio_handler.h" | 5 #include "chromeos/audio/cras_audio_handler.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 | 359 |
| 360 void CrasAudioHandler::AdjustOutputVolumeToAudibleLevel() { | 360 void CrasAudioHandler::AdjustOutputVolumeToAudibleLevel() { |
| 361 if (output_volume_ <= kMuteThresholdPercent) { | 361 if (output_volume_ <= kMuteThresholdPercent) { |
| 362 // Avoid the situation when sound has been unmuted, but the volume | 362 // Avoid the situation when sound has been unmuted, but the volume |
| 363 // is set to a very low value, so user still can't hear any sound. | 363 // is set to a very low value, so user still can't hear any sound. |
| 364 SetOutputVolumePercent(kDefaultUnmuteVolumePercent); | 364 SetOutputVolumePercent(kDefaultUnmuteVolumePercent); |
| 365 } | 365 } |
| 366 } | 366 } |
| 367 | 367 |
| 368 void CrasAudioHandler::SetInputMute(bool mute_on) { | 368 void CrasAudioHandler::SetInputMute(bool mute_on) { |
| 369 if (!SetInputMuteInternal(mute_on)) | 369 SetInputMuteInternal(mute_on); |
| 370 return; | |
| 371 | |
| 372 FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputMuteChanged()); | 370 FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputMuteChanged()); |
| 373 } | 371 } |
| 374 | 372 |
| 375 void CrasAudioHandler::SetActiveOutputNode(uint64 node_id, bool notify) { | 373 void CrasAudioHandler::SetActiveOutputNode(uint64 node_id, bool notify) { |
| 376 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> | 374 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> |
| 377 SetActiveOutputNode(node_id); | 375 SetActiveOutputNode(node_id); |
| 378 if (notify) | 376 if (notify) |
| 379 NotifyActiveNodeChanged(false); | 377 NotifyActiveNodeChanged(false); |
| 380 } | 378 } |
| 381 | 379 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 : audio_pref_handler_(audio_pref_handler), | 422 : audio_pref_handler_(audio_pref_handler), |
| 425 output_mute_on_(false), | 423 output_mute_on_(false), |
| 426 input_mute_on_(false), | 424 input_mute_on_(false), |
| 427 output_volume_(0), | 425 output_volume_(0), |
| 428 input_gain_(0), | 426 input_gain_(0), |
| 429 active_output_node_id_(0), | 427 active_output_node_id_(0), |
| 430 active_input_node_id_(0), | 428 active_input_node_id_(0), |
| 431 has_alternative_input_(false), | 429 has_alternative_input_(false), |
| 432 has_alternative_output_(false), | 430 has_alternative_output_(false), |
| 433 output_mute_locked_(false), | 431 output_mute_locked_(false), |
| 434 input_mute_locked_(false), | |
| 435 log_errors_(false), | 432 log_errors_(false), |
| 436 weak_ptr_factory_(this) { | 433 weak_ptr_factory_(this) { |
| 437 if (!audio_pref_handler.get()) | 434 if (!audio_pref_handler.get()) |
| 438 return; | 435 return; |
| 439 // If the DBusThreadManager or the CrasAudioClient aren't available, there | 436 // If the DBusThreadManager or the CrasAudioClient aren't available, there |
| 440 // isn't much we can do. This should only happen when running tests. | 437 // isn't much we can do. This should only happen when running tests. |
| 441 if (!chromeos::DBusThreadManager::IsInitialized() || | 438 if (!chromeos::DBusThreadManager::IsInitialized() || |
| 442 !chromeos::DBusThreadManager::Get() || | 439 !chromeos::DBusThreadManager::Get() || |
| 443 !chromeos::DBusThreadManager::Get()->GetCrasAudioClient()) | 440 !chromeos::DBusThreadManager::Get()->GetCrasAudioClient()) |
| 444 return; | 441 return; |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 // Mute the device, but do not update the preference. | 596 // Mute the device, but do not update the preference. |
| 600 SetOutputMuteInternal(true); | 597 SetOutputMuteInternal(true); |
| 601 output_mute_locked_ = true; | 598 output_mute_locked_ = true; |
| 602 } else { | 599 } else { |
| 603 // Restore the mute state. | 600 // Restore the mute state. |
| 604 const AudioDevice* device = GetDeviceFromId(active_output_node_id_); | 601 const AudioDevice* device = GetDeviceFromId(active_output_node_id_); |
| 605 if (device) | 602 if (device) |
| 606 SetOutputMuteInternal(audio_pref_handler_->GetMuteValue(*device)); | 603 SetOutputMuteInternal(audio_pref_handler_->GetMuteValue(*device)); |
| 607 } | 604 } |
| 608 | 605 |
| 609 input_mute_locked_ = false; | 606 // Policy for audio input is handled by kAudioCaptureAllowed in the Chrome |
| 610 if (audio_pref_handler_->GetAudioCaptureAllowedValue()) { | 607 // media system. |
| 611 VLOG(1) << "Audio input allowed by policy, sets input id=" | |
| 612 << "0x" << std::hex << active_input_node_id_ << " mute=false"; | |
| 613 SetInputMuteInternal(false); | |
| 614 } else { | |
| 615 VLOG(0) << "Audio input NOT allowed by policy, sets input id=" | |
| 616 << "0x" << std::hex << active_input_node_id_ << " mute=true"; | |
| 617 SetInputMuteInternal(true); | |
| 618 input_mute_locked_ = true; | |
| 619 } | |
| 620 } | 608 } |
| 621 | 609 |
| 622 void CrasAudioHandler::SetOutputNodeVolume(uint64 node_id, int volume) { | 610 void CrasAudioHandler::SetOutputNodeVolume(uint64 node_id, int volume) { |
| 623 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> | 611 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> |
| 624 SetOutputNodeVolume(node_id, volume); | 612 SetOutputNodeVolume(node_id, volume); |
| 625 } | 613 } |
| 626 | 614 |
| 627 void CrasAudioHandler::SetOutputNodeVolumePercent(uint64 node_id, | 615 void CrasAudioHandler::SetOutputNodeVolumePercent(uint64 node_id, |
| 628 int volume_percent) { | 616 int volume_percent) { |
| 629 const AudioDevice* device = this->GetDeviceFromId(node_id); | 617 const AudioDevice* device = this->GetDeviceFromId(node_id); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 input_gain_ = gain_percent; | 659 input_gain_ = gain_percent; |
| 672 | 660 |
| 673 audio_pref_handler_->SetVolumeGainValue(*device, gain_percent); | 661 audio_pref_handler_->SetVolumeGainValue(*device, gain_percent); |
| 674 | 662 |
| 675 if (device->active) { | 663 if (device->active) { |
| 676 SetInputNodeGain(node_id, gain_percent); | 664 SetInputNodeGain(node_id, gain_percent); |
| 677 FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputGainChanged()); | 665 FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputGainChanged()); |
| 678 } | 666 } |
| 679 } | 667 } |
| 680 | 668 |
| 681 bool CrasAudioHandler::SetInputMuteInternal(bool mute_on) { | 669 void CrasAudioHandler::SetInputMuteInternal(bool mute_on) { |
| 682 if (input_mute_locked_) | |
| 683 return false; | |
| 684 | |
| 685 input_mute_on_ = mute_on; | 670 input_mute_on_ = mute_on; |
| 686 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> | 671 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> |
| 687 SetInputMute(mute_on); | 672 SetInputMute(mute_on); |
| 688 return true; | |
| 689 } | 673 } |
| 690 | 674 |
| 691 void CrasAudioHandler::GetNodes() { | 675 void CrasAudioHandler::GetNodes() { |
| 692 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->GetNodes( | 676 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->GetNodes( |
| 693 base::Bind(&CrasAudioHandler::HandleGetNodes, | 677 base::Bind(&CrasAudioHandler::HandleGetNodes, |
| 694 weak_ptr_factory_.GetWeakPtr()), | 678 weak_ptr_factory_.GetWeakPtr()), |
| 695 base::Bind(&CrasAudioHandler::HandleGetNodesError, | 679 base::Bind(&CrasAudioHandler::HandleGetNodesError, |
| 696 weak_ptr_factory_.GetWeakPtr())); | 680 weak_ptr_factory_.GetWeakPtr())); |
| 697 } | 681 } |
| 698 | 682 |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 active_output_node_id_ = 0; | 907 active_output_node_id_ = 0; |
| 924 chromeos::DBusThreadManager::Get() | 908 chromeos::DBusThreadManager::Get() |
| 925 ->GetCrasAudioClient() | 909 ->GetCrasAudioClient() |
| 926 ->RemoveActiveOutputNode(node_id); | 910 ->RemoveActiveOutputNode(node_id); |
| 927 if (notify) | 911 if (notify) |
| 928 NotifyActiveNodeChanged(false); | 912 NotifyActiveNodeChanged(false); |
| 929 } | 913 } |
| 930 } | 914 } |
| 931 | 915 |
| 932 } // namespace chromeos | 916 } // namespace chromeos |
| OLD | NEW |