Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(995)

Side by Side Diff: chromeos/audio/cras_audio_handler.cc

Issue 2190773002: Fix Volume slider is captured in screenshot done in touchview mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: several updates included Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 // Set all active devices to the same volume. 369 // Set all active devices to the same volume.
370 for (AudioDeviceMap::const_iterator it = audio_devices_.begin(); 370 for (AudioDeviceMap::const_iterator it = audio_devices_.begin();
371 it != audio_devices_.end(); 371 it != audio_devices_.end();
372 it++) { 372 it++) {
373 const AudioDevice& device = it->second; 373 const AudioDevice& device = it->second;
374 if (!device.is_input && device.active) 374 if (!device.is_input && device.active)
375 SetOutputNodeVolumePercent(device.id, volume_percent); 375 SetOutputNodeVolumePercent(device.id, volume_percent);
376 } 376 }
377 } 377 }
378 378
379 void CrasAudioHandler::SetOutputVolumePercentWithoutNotifyingObservers(
380 int volume_percent,
381 AutomatedVolumeChangeReason reason) {
382 automated_volume_change_reasons_.push_back(reason);
383 SetOutputVolumePercent(volume_percent);
384 }
385
379 // TODO: Rename the 'Percent' to something more meaningful. 386 // TODO: Rename the 'Percent' to something more meaningful.
380 void CrasAudioHandler::SetInputGainPercent(int gain_percent) { 387 void CrasAudioHandler::SetInputGainPercent(int gain_percent) {
381 // TODO(jennyz): Should we set all input devices' gain to the same level? 388 // TODO(jennyz): Should we set all input devices' gain to the same level?
382 for (AudioDeviceMap::const_iterator it = audio_devices_.begin(); 389 for (AudioDeviceMap::const_iterator it = audio_devices_.begin();
383 it != audio_devices_.end(); 390 it != audio_devices_.end();
384 it++) { 391 it++) {
385 const AudioDevice& device = it->second; 392 const AudioDevice& device = it->second;
386 if (device.is_input && device.active) 393 if (device.is_input && device.active)
387 SetInputNodeGainPercent(active_input_node_id_, gain_percent); 394 SetInputNodeGainPercent(active_input_node_id_, gain_percent);
388 } 395 }
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 } 613 }
607 614
608 // Sync internal volume state and notify UI for the change. We trust cras 615 // Sync internal volume state and notify UI for the change. We trust cras
609 // signal to report the volume state of the device, no matter which source 616 // signal to report the volume state of the device, no matter which source
610 // set the volume, i.e., volume could be set from non-chrome source, like 617 // set the volume, i.e., volume could be set from non-chrome source, like
611 // Bluetooth headset, etc. Assume all active output devices share a single 618 // Bluetooth headset, etc. Assume all active output devices share a single
612 // volume. 619 // volume.
613 output_volume_ = volume; 620 output_volume_ = volume;
614 audio_pref_handler_->SetVolumeGainValue(*device, volume); 621 audio_pref_handler_->SetVolumeGainValue(*device, volume);
615 622
616 if (initializing_audio_state_) { 623 bool should_not_notify_observers = false;
Daniel Erat 2016/08/01 21:10:07 i'd invert this to make it easier to read: bool
Qiang(Joe) Xu 2016/08/01 22:56:48 I think I do change the previous logic by mistake.
617 // Do not notify the observers for volume changed event if CrasAudioHandler 624 if (!automated_volume_change_reasons_.empty()) {
618 // is initializing its state, i.e., the volume change event is in responding 625 should_not_notify_observers = true;
619 // to SetOutputNodeVolume request from intializaing audio state, not 626 AutomatedVolumeChangeReason reason =
620 // from user action, no need to notify UI to pop uo the volume slider bar. 627 automated_volume_change_reasons_.front();
621 if (init_node_id_ == node_id && init_volume_ == volume) { 628 if (reason == VOLUME_CHANGE_INITIALIZING_AUDIO_STATE &&
622 init_volume_count_--; 629 (init_node_id_ != node_id || init_volume_ != volume)) {
623 if (!init_volume_count_) 630 // SetOutputNodeVolume request may lose by cras due to cras is not ready
624 initializing_audio_state_ = false; 631 // when CrasAudioHandler is being initialized.
625 return; 632 should_not_notify_observers = false;
626 } else {
627 // Reset the initializing_audio_state_ in case SetOutputNodeVolume request
628 // is lost by cras due to cras is not ready when CrasAudioHandler is being
629 // initialized.
630 initializing_audio_state_ = false;
631 init_volume_count_ = 0;
632 } 633 }
634 automated_volume_change_reasons_.pop_front();
633 } 635 }
634 636
635 FOR_EACH_OBSERVER(AudioObserver, observers_, 637 if (!should_not_notify_observers) {
636 OnOutputNodeVolumeChanged(node_id, volume)); 638 FOR_EACH_OBSERVER(AudioObserver, observers_,
639 OnOutputNodeVolumeChanged(node_id, volume));
640 }
637 } 641 }
638 642
639 void CrasAudioHandler::ActiveOutputNodeChanged(uint64_t node_id) { 643 void CrasAudioHandler::ActiveOutputNodeChanged(uint64_t node_id) {
640 if (active_output_node_id_ == node_id) 644 if (active_output_node_id_ == node_id)
641 return; 645 return;
642 646
643 // Active audio output device should always be changed by chrome. 647 // Active audio output device should always be changed by chrome.
644 // During system boot, cras may change active input to unknown device 0x1, 648 // During system boot, cras may change active input to unknown device 0x1,
645 // we don't need to log it, since it is not an valid device. 649 // we don't need to log it, since it is not an valid device.
646 if (GetDeviceFromId(node_id)) { 650 if (GetDeviceFromId(node_id)) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 if (hdmi_rediscovering_ && !IsHDMIPrimaryOutputDevice()) { 735 if (hdmi_rediscovering_ && !IsHDMIPrimaryOutputDevice()) {
732 VLOG(1) << "Mute the output during HDMI re-discovering grace period"; 736 VLOG(1) << "Mute the output during HDMI re-discovering grace period";
733 output_mute_on_ = true; 737 output_mute_on_ = true;
734 } else { 738 } else {
735 output_mute_on_ = audio_pref_handler_->GetMuteValue(*device); 739 output_mute_on_ = audio_pref_handler_->GetMuteValue(*device);
736 } 740 }
737 output_volume_ = audio_pref_handler_->GetOutputVolumeValue(device); 741 output_volume_ = audio_pref_handler_->GetOutputVolumeValue(device);
738 742
739 SetOutputMuteInternal(output_mute_on_); 743 SetOutputMuteInternal(output_mute_on_);
740 744
741 if (initializing_audio_state_) { 745 if (!automated_volume_change_reasons_.empty() &&
746 automated_volume_change_reasons_.front() ==
747 VOLUME_CHANGE_INITIALIZING_AUDIO_STATE) {
742 // During power up, InitializeAudioState() could be called twice, first 748 // During power up, InitializeAudioState() could be called twice, first
743 // by CrasAudioHandler constructor, then by cras server restarting signal, 749 // by CrasAudioHandler constructor, then by cras server restarting signal,
744 // both sending SetOutputNodeVolume requests, and could lead to two 750 // both sending SetOutputNodeVolume requests, and could lead to two
745 // OutputNodeVolumeChanged signals. 751 // OutputNodeVolumeChanged signals.
Daniel Erat 2016/08/01 21:10:07 the old code was incrementing a counter here that
Qiang(Joe) Xu 2016/08/01 22:56:48 I am not quite understanding the comments here. Bu
746 init_volume_count_++;
747 init_node_id_ = active_output_node_id_; 752 init_node_id_ = active_output_node_id_;
748 init_volume_ = output_volume_; 753 init_volume_ = output_volume_;
749 } 754 }
750 SetOutputNodeVolume(active_output_node_id_, output_volume_); 755 SetOutputNodeVolume(active_output_node_id_, output_volume_);
751 } 756 }
752 757
753 // This sets up the state of an additional active node. 758 // This sets up the state of an additional active node.
754 void CrasAudioHandler::SetupAdditionalActiveAudioNodeState(uint64_t node_id) { 759 void CrasAudioHandler::SetupAdditionalActiveAudioNodeState(uint64_t node_id) {
755 const AudioDevice* device = GetDeviceFromId(node_id); 760 const AudioDevice* device = GetDeviceFromId(node_id);
756 if (!device) { 761 if (!device) {
(...skipping 10 matching lines...) Expand all
767 // devices. For input devices, we don't restore their gain value so far. 772 // devices. For input devices, we don't restore their gain value so far.
768 // TODO(jennyz): crbug.com/417418, track the status for the decison if 773 // TODO(jennyz): crbug.com/417418, track the status for the decison if
769 // we should persist input gain value in prefs. 774 // we should persist input gain value in prefs.
770 if (!device->is_input) { 775 if (!device->is_input) {
771 audio_pref_handler_->SetMuteValue(*device, IsOutputMuted()); 776 audio_pref_handler_->SetMuteValue(*device, IsOutputMuted());
772 SetOutputNodeVolumePercent(node_id, GetOutputVolumePercent()); 777 SetOutputNodeVolumePercent(node_id, GetOutputVolumePercent());
773 } 778 }
774 } 779 }
775 780
776 void CrasAudioHandler::InitializeAudioState() { 781 void CrasAudioHandler::InitializeAudioState() {
777 initializing_audio_state_ = true; 782 automated_volume_change_reasons_.push_back(
783 VOLUME_CHANGE_INITIALIZING_AUDIO_STATE);
778 ApplyAudioPolicy(); 784 ApplyAudioPolicy();
779 785
780 // Defer querying cras for GetNodes until cras service becomes available. 786 // Defer querying cras for GetNodes until cras service becomes available.
781 cras_service_available_ = false; 787 cras_service_available_ = false;
782 chromeos::DBusThreadManager::Get() 788 chromeos::DBusThreadManager::Get()
783 ->GetCrasAudioClient() 789 ->GetCrasAudioClient()
784 ->WaitForServiceToBeAvailable(base::Bind( 790 ->WaitForServiceToBeAvailable(base::Bind(
785 &CrasAudioHandler::InitializeAudioAfterCrasServiceAvailable, 791 &CrasAudioHandler::InitializeAudioAfterCrasServiceAvailable,
786 weak_ptr_factory_.GetWeakPtr())); 792 weak_ptr_factory_.GetWeakPtr()));
787 } 793 }
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 hdmi_rediscover_grace_period_duration_in_ms_), 1378 hdmi_rediscover_grace_period_duration_in_ms_),
1373 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod); 1379 this, &CrasAudioHandler::UpdateAudioAfterHDMIRediscoverGracePeriod);
1374 } 1380 }
1375 1381
1376 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting( 1382 void CrasAudioHandler::SetHDMIRediscoverGracePeriodForTesting(
1377 int duration_in_ms) { 1383 int duration_in_ms) {
1378 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms; 1384 hdmi_rediscover_grace_period_duration_in_ms_ = duration_in_ms;
1379 } 1385 }
1380 1386
1381 } // namespace chromeos 1387 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698