| Index: chromeos/audio/cras_audio_handler.cc
|
| diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc
|
| index a8f8036134ead71310d5a6748f4230045971f1f3..3ff5055ddb878c5f7f0ed3501cb073f4b63d8bb1 100644
|
| --- a/chromeos/audio/cras_audio_handler.cc
|
| +++ b/chromeos/audio/cras_audio_handler.cc
|
| @@ -25,6 +25,11 @@ namespace chromeos {
|
|
|
| namespace {
|
|
|
| +enum AutomatedVolumeChangeReason {
|
| + VOLUME_CHANGE_INITIALIZING_AUDIO_STATE = 1 << 0,
|
| + VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT = 1 << 1,
|
| +};
|
| +
|
| // Default value for unmuting, as a percent in the range [0, 100].
|
| // Used when sound is unmuted, but volume was less than kMuteThresholdPercent.
|
| const int kDefaultUnmuteVolumePercent = 4;
|
| @@ -376,6 +381,15 @@ void CrasAudioHandler::SetOutputVolumePercent(int volume_percent) {
|
| }
|
| }
|
|
|
| +void CrasAudioHandler::SetOutputVolumePercentWithoutNotifyingObservers(
|
| + int volume_percent) {
|
| + // Currently SetOutputVolumePercentWithoutNotifyingObservers is only called
|
| + // from maximize mode screenshot in PowerButtonController.
|
| + automated_volume_change_ |= VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT;
|
| + maximize_mode_screenshot_count_++;
|
| + SetOutputVolumePercent(volume_percent);
|
| +}
|
| +
|
| // TODO: Rename the 'Percent' to something more meaningful.
|
| void CrasAudioHandler::SetInputGainPercent(int gain_percent) {
|
| // TODO(jennyz): Should we set all input devices' gain to the same level?
|
| @@ -613,27 +627,43 @@ void CrasAudioHandler::OutputNodeVolumeChanged(uint64_t node_id, int volume) {
|
| output_volume_ = volume;
|
| audio_pref_handler_->SetVolumeGainValue(*device, volume);
|
|
|
| - if (initializing_audio_state_) {
|
| + bool should_not_notify_observers = false;
|
| + if (automated_volume_change_ & VOLUME_CHANGE_INITIALIZING_AUDIO_STATE) {
|
| // Do not notify the observers for volume changed event if CrasAudioHandler
|
| // is initializing its state, i.e., the volume change event is in responding
|
| - // to SetOutputNodeVolume request from intializaing audio state, not
|
| - // from user action, no need to notify UI to pop uo the volume slider bar.
|
| + // to SetOutputNodeVolume request from initializing audio state, not from
|
| + // user action, no need to notify UI to pop up the volume slider bar.
|
| if (init_node_id_ == node_id && init_volume_ == volume) {
|
| init_volume_count_--;
|
| if (!init_volume_count_)
|
| - initializing_audio_state_ = false;
|
| - return;
|
| + automated_volume_change_ ^= VOLUME_CHANGE_INITIALIZING_AUDIO_STATE;
|
| + should_not_notify_observers = true;
|
| } else {
|
| - // Reset the initializing_audio_state_ in case SetOutputNodeVolume request
|
| - // is lost by cras due to cras is not ready when CrasAudioHandler is being
|
| - // initialized.
|
| - initializing_audio_state_ = false;
|
| + // Reset the INITIALIZING_AUDIO_STATE in case SetOutputNodeVolume request
|
| + // is lost by cras due to cras is not ready when CrasAudioHandler is
|
| + // being initialized.
|
| + automated_volume_change_ ^= VOLUME_CHANGE_INITIALIZING_AUDIO_STATE;
|
| init_volume_count_ = 0;
|
| }
|
| }
|
|
|
| - FOR_EACH_OBSERVER(AudioObserver, observers_,
|
| - OnOutputNodeVolumeChanged(node_id, volume));
|
| + if (automated_volume_change_ & VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT) {
|
| + // Do not notify the observers for the volume changed event if that is
|
| + // coming from SetOutputVolumePercentWithoutNotifyingObservers, i.e., a
|
| + // restoring volume after a maximize mode screenshot is taken.
|
| + // Reset the MAXIMIZE_MODE_SCREENSHOT when there are no more
|
| + // OutputNodeVolumeChanged being fired.
|
| + DCHECK_GT(maximize_mode_screenshot_count_, 0);
|
| + maximize_mode_screenshot_count_--;
|
| + if (!maximize_mode_screenshot_count_)
|
| + automated_volume_change_ ^= VOLUME_CHANGE_MAXIMIZE_MODE_SCREENSHOT;
|
| + should_not_notify_observers = true;
|
| + }
|
| +
|
| + if (!should_not_notify_observers) {
|
| + FOR_EACH_OBSERVER(AudioObserver, observers_,
|
| + OnOutputNodeVolumeChanged(node_id, volume));
|
| + }
|
| }
|
|
|
| void CrasAudioHandler::ActiveOutputNodeChanged(uint64_t node_id) {
|
| @@ -738,7 +768,7 @@ void CrasAudioHandler::SetupAudioOutputState() {
|
|
|
| SetOutputMuteInternal(output_mute_on_);
|
|
|
| - if (initializing_audio_state_) {
|
| + if (automated_volume_change_ & VOLUME_CHANGE_INITIALIZING_AUDIO_STATE) {
|
| // During power up, InitializeAudioState() could be called twice, first
|
| // by CrasAudioHandler constructor, then by cras server restarting signal,
|
| // both sending SetOutputNodeVolume requests, and could lead to two
|
| @@ -774,7 +804,7 @@ void CrasAudioHandler::SetupAdditionalActiveAudioNodeState(uint64_t node_id) {
|
| }
|
|
|
| void CrasAudioHandler::InitializeAudioState() {
|
| - initializing_audio_state_ = true;
|
| + automated_volume_change_ |= VOLUME_CHANGE_INITIALIZING_AUDIO_STATE;
|
| ApplyAudioPolicy();
|
|
|
| // Defer querying cras for GetNodes until cras service becomes available.
|
|
|