Commit e7818501 authored by jennyz's avatar jennyz Committed by Commit bot

Count the SetOutputNodeVolume requests sent during the audio initialization...

Count the SetOutputNodeVolume requests sent during the audio initialization and track them with the OutputNodeVolumeChanged signals responding from cras, do not pop up the volume bar for such signals.

BUG=625222

Review-Url: https://codereview.chromium.org/2146313005
Cr-Commit-Position: refs/heads/master@{#406014}
parent cee3156d
...@@ -613,14 +613,22 @@ void CrasAudioHandler::OutputNodeVolumeChanged(uint64_t node_id, int volume) { ...@@ -613,14 +613,22 @@ void CrasAudioHandler::OutputNodeVolumeChanged(uint64_t node_id, int volume) {
audio_pref_handler_->SetVolumeGainValue(*device, volume); audio_pref_handler_->SetVolumeGainValue(*device, volume);
if (initializing_audio_state_) { if (initializing_audio_state_) {
// Reset the flag after the first OutputNodeVolumeChanged, just in case
// cras didn't respond to the initial SetOutputNodeVolume request.
initializing_audio_state_ = false;
// Do not notify the observers for volume changed event if CrasAudioHandler // Do not notify the observers for volume changed event if CrasAudioHandler
// is initializing its state, i.e., the volume change event is not from // is initializing its state, i.e., the volume change event is in responding
// user action, no need to notify UI to pop uo the volume slider bar. // to SetOutputNodeVolume request from intializaing audio state, not
if (init_node_id_ == node_id && init_volume_ == volume) // from user action, no need to notify UI to pop uo 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; return;
} 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;
init_volume_count_ = 0;
}
} }
FOR_EACH_OBSERVER(AudioObserver, observers_, FOR_EACH_OBSERVER(AudioObserver, observers_,
...@@ -730,6 +738,11 @@ void CrasAudioHandler::SetupAudioOutputState() { ...@@ -730,6 +738,11 @@ void CrasAudioHandler::SetupAudioOutputState() {
SetOutputMuteInternal(output_mute_on_); SetOutputMuteInternal(output_mute_on_);
if (initializing_audio_state_) { if (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
// OutputNodeVolumeChanged signals.
init_volume_count_++;
init_node_id_ = active_output_node_id_; init_node_id_ = active_output_node_id_;
init_volume_ = output_volume_; init_volume_ = output_volume_;
} }
......
...@@ -435,6 +435,7 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer, ...@@ -435,6 +435,7 @@ class CHROMEOS_EXPORT CrasAudioHandler : public CrasAudioClient::Observer,
bool initializing_audio_state_ = false; bool initializing_audio_state_ = false;
int init_volume_; int init_volume_;
uint64_t init_node_id_; uint64_t init_node_id_;
int init_volume_count_ = 0;
base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_; base::WeakPtrFactory<CrasAudioHandler> weak_ptr_factory_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment