| 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 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 return; | 604 return; |
| 605 } | 605 } |
| 606 | 606 |
| 607 // Sync internal volume state and notify UI for the change. We trust cras | 607 // Sync internal volume state and notify UI for the change. We trust cras |
| 608 // signal to report the volume state of the device, no matter which source | 608 // signal to report the volume state of the device, no matter which source |
| 609 // set the volume, i.e., volume could be set from non-chrome source, like | 609 // set the volume, i.e., volume could be set from non-chrome source, like |
| 610 // Bluetooth headset, etc. Assume all active output devices share a single | 610 // Bluetooth headset, etc. Assume all active output devices share a single |
| 611 // volume. | 611 // volume. |
| 612 output_volume_ = volume; | 612 output_volume_ = volume; |
| 613 audio_pref_handler_->SetVolumeGainValue(*device, volume); | 613 audio_pref_handler_->SetVolumeGainValue(*device, volume); |
| 614 |
| 615 if (initializing_audio_state_) { |
| 616 // Reset the flag after the first OutputNodeVolumeChanged, just in case |
| 617 // cras didn't respond to the initial SetOutputNodeVolume request. |
| 618 initializing_audio_state_ = false; |
| 619 // Do not notify the observers for volume changed event if CrasAudioHandler |
| 620 // is initializing its state, i.e., the volume change event is not from |
| 621 // user action, no need to notify UI to pop uo the volume slider bar. |
| 622 if (init_node_id_ == node_id && init_volume_ == volume) |
| 623 return; |
| 624 } |
| 625 |
| 614 FOR_EACH_OBSERVER(AudioObserver, observers_, | 626 FOR_EACH_OBSERVER(AudioObserver, observers_, |
| 615 OnOutputNodeVolumeChanged(node_id, volume)); | 627 OnOutputNodeVolumeChanged(node_id, volume)); |
| 616 } | 628 } |
| 617 | 629 |
| 618 void CrasAudioHandler::ActiveOutputNodeChanged(uint64_t node_id) { | 630 void CrasAudioHandler::ActiveOutputNodeChanged(uint64_t node_id) { |
| 619 if (active_output_node_id_ == node_id) | 631 if (active_output_node_id_ == node_id) |
| 620 return; | 632 return; |
| 621 | 633 |
| 622 // Active audio output device should always be changed by chrome. | 634 // Active audio output device should always be changed by chrome. |
| 623 // During system boot, cras may change active input to unknown device 0x1, | 635 // During system boot, cras may change active input to unknown device 0x1, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 // Mute the output during HDMI re-discovering grace period. | 721 // Mute the output during HDMI re-discovering grace period. |
| 710 if (hdmi_rediscovering_ && !IsHDMIPrimaryOutputDevice()) { | 722 if (hdmi_rediscovering_ && !IsHDMIPrimaryOutputDevice()) { |
| 711 VLOG(1) << "Mute the output during HDMI re-discovering grace period"; | 723 VLOG(1) << "Mute the output during HDMI re-discovering grace period"; |
| 712 output_mute_on_ = true; | 724 output_mute_on_ = true; |
| 713 } else { | 725 } else { |
| 714 output_mute_on_ = audio_pref_handler_->GetMuteValue(*device); | 726 output_mute_on_ = audio_pref_handler_->GetMuteValue(*device); |
| 715 } | 727 } |
| 716 output_volume_ = audio_pref_handler_->GetOutputVolumeValue(device); | 728 output_volume_ = audio_pref_handler_->GetOutputVolumeValue(device); |
| 717 | 729 |
| 718 SetOutputMuteInternal(output_mute_on_); | 730 SetOutputMuteInternal(output_mute_on_); |
| 731 |
| 732 if (initializing_audio_state_) { |
| 733 init_node_id_ = active_output_node_id_; |
| 734 init_volume_ = output_volume_; |
| 735 } |
| 719 SetOutputNodeVolume(active_output_node_id_, output_volume_); | 736 SetOutputNodeVolume(active_output_node_id_, output_volume_); |
| 720 } | 737 } |
| 721 | 738 |
| 722 // This sets up the state of an additional active node. | 739 // This sets up the state of an additional active node. |
| 723 void CrasAudioHandler::SetupAdditionalActiveAudioNodeState(uint64_t node_id) { | 740 void CrasAudioHandler::SetupAdditionalActiveAudioNodeState(uint64_t node_id) { |
| 724 const AudioDevice* device = GetDeviceFromId(node_id); | 741 const AudioDevice* device = GetDeviceFromId(node_id); |
| 725 if (!device) { | 742 if (!device) { |
| 726 VLOG(1) << "Can't set up audio state for unknown device id =" | 743 VLOG(1) << "Can't set up audio state for unknown device id =" |
| 727 << "0x" << std::hex << node_id; | 744 << "0x" << std::hex << node_id; |
| 728 return; | 745 return; |
| 729 } | 746 } |
| 730 | 747 |
| 731 DCHECK(node_id != active_output_node_id_ && node_id != active_input_node_id_); | 748 DCHECK(node_id != active_output_node_id_ && node_id != active_input_node_id_); |
| 732 | 749 |
| 733 // Note: The mute state is a system wide state, we don't set mute per device, | 750 // Note: The mute state is a system wide state, we don't set mute per device, |
| 734 // but just keep the mute state consistent for the active node in prefs. | 751 // but just keep the mute state consistent for the active node in prefs. |
| 735 // The output volume should be set to the same value for all active output | 752 // The output volume should be set to the same value for all active output |
| 736 // devices. For input devices, we don't restore their gain value so far. | 753 // devices. For input devices, we don't restore their gain value so far. |
| 737 // TODO(jennyz): crbug.com/417418, track the status for the decison if | 754 // TODO(jennyz): crbug.com/417418, track the status for the decison if |
| 738 // we should persist input gain value in prefs. | 755 // we should persist input gain value in prefs. |
| 739 if (!device->is_input) { | 756 if (!device->is_input) { |
| 740 audio_pref_handler_->SetMuteValue(*device, IsOutputMuted()); | 757 audio_pref_handler_->SetMuteValue(*device, IsOutputMuted()); |
| 741 SetOutputNodeVolumePercent(node_id, GetOutputVolumePercent()); | 758 SetOutputNodeVolumePercent(node_id, GetOutputVolumePercent()); |
| 742 } | 759 } |
| 743 } | 760 } |
| 744 | 761 |
| 745 void CrasAudioHandler::InitializeAudioState() { | 762 void CrasAudioHandler::InitializeAudioState() { |
| 763 initializing_audio_state_ = true; |
| 746 ApplyAudioPolicy(); | 764 ApplyAudioPolicy(); |
| 747 | 765 |
| 748 // Defer querying cras for GetNodes until cras service becomes available. | 766 // Defer querying cras for GetNodes until cras service becomes available. |
| 749 cras_service_available_ = false; | 767 cras_service_available_ = false; |
| 750 chromeos::DBusThreadManager::Get() | 768 chromeos::DBusThreadManager::Get() |
| 751 ->GetCrasAudioClient() | 769 ->GetCrasAudioClient() |
| 752 ->WaitForServiceToBeAvailable(base::Bind( | 770 ->WaitForServiceToBeAvailable(base::Bind( |
| 753 &CrasAudioHandler::InitializeAudioAfterCrasServiceAvailable, | 771 &CrasAudioHandler::InitializeAudioAfterCrasServiceAvailable, |
| 754 weak_ptr_factory_.GetWeakPtr())); | 772 weak_ptr_factory_.GetWeakPtr())); |
| 755 } | 773 } |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 hdmi_rediscover_grace_period_duration_in_ms_), | 1346 hdmi_rediscover_grace_period_duration_in_ms_), |
| 1329 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod); | 1347 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod); |
| 1330 } | 1348 } |
| 1331 | 1349 |
| 1332 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting( | 1350 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting( |
| 1333 int duration_in_ms) { | 1351 int duration_in_ms) { |
| 1334 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms; | 1352 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms; |
| 1335 } | 1353 } |
| 1336 | 1354 |
| 1337 } // namespace chromeos | 1355 } // namespace chromeos |
| OLD | NEW |