| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 InitializeAudioState(); | 587 InitializeAudioState(); |
| 588 } | 588 } |
| 589 | 589 |
| 590 void CrasAudioHandler::NodesChanged() { | 590 void CrasAudioHandler::NodesChanged() { |
| 591 if (cras_service_available_) | 591 if (cras_service_available_) |
| 592 GetNodes(); | 592 GetNodes(); |
| 593 } | 593 } |
| 594 | 594 |
| 595 void CrasAudioHandler::OutputNodeVolumeChanged(uint64_t node_id, int volume) { | 595 void CrasAudioHandler::OutputNodeVolumeChanged(uint64_t node_id, int volume) { |
| 596 const AudioDevice* device = this->GetDeviceFromId(node_id); | 596 const AudioDevice* device = this->GetDeviceFromId(node_id); |
| 597 int old_volume; | |
| 598 | 597 |
| 599 // If this is not an active output node, ignore this event. Because when this | 598 // If this is not an active output node, ignore this event. Because when this |
| 600 // node set to active, it will be applied with the volume value stored in | 599 // node set to active, it will be applied with the volume value stored in |
| 601 // preference. | 600 // preference. |
| 602 if (!device || !device->active || device->is_input) | 601 if (!device || !device->active || device->is_input) { |
| 602 LOG(ERROR) << "Unexpexted OutputNodeVolumeChanged received on node: 0x" |
| 603 << std::hex << node_id; |
| 603 return; | 604 return; |
| 605 } |
| 604 | 606 |
| 605 // If this callback is triggered by a response to previous set volume command, | 607 // Sync internal volume state and notify UI for the change. We trust cras |
| 606 // do nothing. | 608 // signal to report the volume state of the device, no matter which source |
| 607 old_volume = | 609 // set the volume, i.e., volume could be set from non-chrome source, like |
| 608 static_cast<int>(audio_pref_handler_->GetOutputVolumeValue(device)); | 610 // Bluetooth headset, etc. Assume all active output devices share a single |
| 609 if (old_volume == volume) | 611 // volume. |
| 610 return; | 612 output_volume_ = volume; |
| 611 | 613 audio_pref_handler_->SetVolumeGainValue(*device, volume); |
| 612 // Otherwise another app or the hardware itself just changed volume, update | 614 FOR_EACH_OBSERVER(AudioObserver, observers_, |
| 613 // the new volume value to all active output nodes. | 615 OnOutputNodeVolumeChanged(node_id, volume)); |
| 614 SetOutputVolumePercent(volume); | |
| 615 } | 616 } |
| 616 | 617 |
| 617 void CrasAudioHandler::ActiveOutputNodeChanged(uint64_t node_id) { | 618 void CrasAudioHandler::ActiveOutputNodeChanged(uint64_t node_id) { |
| 618 if (active_output_node_id_ == node_id) | 619 if (active_output_node_id_ == node_id) |
| 619 return; | 620 return; |
| 620 | 621 |
| 621 // Active audio output device should always be changed by chrome. | 622 // Active audio output device should always be changed by chrome. |
| 622 // During system boot, cras may change active input to unknown device 0x1, | 623 // During system boot, cras may change active input to unknown device 0x1, |
| 623 // we don't need to log it, since it is not an valid device. | 624 // we don't need to log it, since it is not an valid device. |
| 624 if (GetDeviceFromId(node_id)) { | 625 if (GetDeviceFromId(node_id)) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 // media system. | 783 // media system. |
| 783 } | 784 } |
| 784 | 785 |
| 785 void CrasAudioHandler::SetOutputNodeVolume(uint64_t node_id, int volume) { | 786 void CrasAudioHandler::SetOutputNodeVolume(uint64_t node_id, int volume) { |
| 786 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> | 787 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> |
| 787 SetOutputNodeVolume(node_id, volume); | 788 SetOutputNodeVolume(node_id, volume); |
| 788 } | 789 } |
| 789 | 790 |
| 790 void CrasAudioHandler::SetOutputNodeVolumePercent(uint64_t node_id, | 791 void CrasAudioHandler::SetOutputNodeVolumePercent(uint64_t node_id, |
| 791 int volume_percent) { | 792 int volume_percent) { |
| 792 const AudioDevice* device = this->GetDeviceFromId(node_id); | 793 const AudioDevice* device = GetDeviceFromId(node_id); |
| 793 if (!device || device->is_input) | 794 if (!device || device->is_input) |
| 794 return; | 795 return; |
| 795 | 796 |
| 796 volume_percent = min(max(volume_percent, 0), 100); | 797 volume_percent = min(max(volume_percent, 0), 100); |
| 797 if (volume_percent <= kMuteThresholdPercent) | 798 if (volume_percent <= kMuteThresholdPercent) |
| 798 volume_percent = 0; | 799 volume_percent = 0; |
| 799 if (node_id == active_output_node_id_) | |
| 800 output_volume_ = volume_percent; | |
| 801 | 800 |
| 801 // Save the volume setting in pref in case this is called on non-active |
| 802 // node for configuration. |
| 802 audio_pref_handler_->SetVolumeGainValue(*device, volume_percent); | 803 audio_pref_handler_->SetVolumeGainValue(*device, volume_percent); |
| 803 | 804 |
| 804 if (device->active) { | 805 if (device->active) |
| 805 SetOutputNodeVolume(node_id, volume_percent); | 806 SetOutputNodeVolume(node_id, volume_percent); |
| 806 FOR_EACH_OBSERVER(AudioObserver, observers_, | |
| 807 OnOutputNodeVolumeChanged(node_id, volume_percent)); | |
| 808 } | |
| 809 } | 807 } |
| 810 | 808 |
| 811 bool CrasAudioHandler::SetOutputMuteInternal(bool mute_on) { | 809 bool CrasAudioHandler::SetOutputMuteInternal(bool mute_on) { |
| 812 if (output_mute_locked_) | 810 if (output_mute_locked_) |
| 813 return false; | 811 return false; |
| 814 | 812 |
| 815 output_mute_on_ = mute_on; | 813 output_mute_on_ = mute_on; |
| 816 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> | 814 chromeos::DBusThreadManager::Get()->GetCrasAudioClient()-> |
| 817 SetOutputUserMute(mute_on); | 815 SetOutputUserMute(mute_on); |
| 818 return true; | 816 return true; |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1330 hdmi_rediscover_grace_period_duration_in_ms_), | 1328 hdmi_rediscover_grace_period_duration_in_ms_), |
| 1331 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod); | 1329 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod); |
| 1332 } | 1330 } |
| 1333 | 1331 |
| 1334 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting( | 1332 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting( |
| 1335 int duration_in_ms) { | 1333 int duration_in_ms) { |
| 1336 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms; | 1334 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms; |
| 1337 } | 1335 } |
| 1338 | 1336 |
| 1339 } // namespace chromeos | 1337 } // namespace chromeos |
| OLD | NEW |