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

Unified Diff: chromeos/audio/cras_audio_handler.cc

Issue 15927004: Fix the audio mute button broken issue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nit. Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/audio/cras_audio_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/audio/cras_audio_handler.cc
diff --git a/chromeos/audio/cras_audio_handler.cc b/chromeos/audio/cras_audio_handler.cc
index 10883334013a90f56adc24937b7e9ef6e6bfd9e5..7ad5c844e1cb875646e0fd0fc2219ca9aad3f43f 100644
--- a/chromeos/audio/cras_audio_handler.cc
+++ b/chromeos/audio/cras_audio_handler.cc
@@ -104,10 +104,11 @@ bool CrasAudioHandler::IsOutputMuted() {
}
bool CrasAudioHandler::IsOutputMutedForDevice(uint64 device_id) {
- if (device_id == active_output_node_id_)
- return output_mute_on_;
- else
- return audio_pref_handler_->GetMuteValue(device_id);
+ return audio_pref_handler_->GetMuteValue(device_id);
+}
+
+bool CrasAudioHandler::IsOutputVolumeBelowDefaultMuteLvel() {
+ return output_volume_ <= kMuteThresholdPercent;
}
bool CrasAudioHandler::IsInputMuted() {
@@ -115,10 +116,7 @@ bool CrasAudioHandler::IsInputMuted() {
}
bool CrasAudioHandler::IsInputMutedForDevice(uint64 device_id) {
- if (device_id == active_input_node_id_)
- return input_mute_on_;
- else
- return audio_pref_handler_->GetMuteValue(device_id);
+ return audio_pref_handler_->GetMuteValue(device_id);
}
int CrasAudioHandler::GetOutputVolumePercent() {
@@ -178,14 +176,21 @@ void CrasAudioHandler::SetOutputVolumePercent(int volume_percent) {
volume_percent = min(max(volume_percent, 0), 100);
if (volume_percent <= kMuteThresholdPercent)
volume_percent = 0;
- SetOutputVolumeInternal(volume_percent);
+ output_volume_ = volume_percent;
+ audio_pref_handler_->SetVolumeGainValue(active_output_node_id_,
+ output_volume_);
+ SetOutputVolumeInternal(output_volume_);
+ FOR_EACH_OBSERVER(AudioObserver, observers_, OnOutputVolumeChanged());
}
void CrasAudioHandler::SetInputGainPercent(int gain_percent) {
gain_percent = min(max(gain_percent, 0), 100);
if (gain_percent <= kMuteThresholdPercent)
gain_percent = 0;
- SetInputGainInternal(gain_percent);
+ input_gain_ = gain_percent;
+ audio_pref_handler_->SetVolumeGainValue(active_input_node_id_, input_gain_);
+ SetInputGainInternal(input_gain_);
+ FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputGainChanged());
}
void CrasAudioHandler::AdjustOutputVolumeByPercent(int adjust_by_percent) {
@@ -196,37 +201,26 @@ void CrasAudioHandler::SetOutputMute(bool mute_on) {
if (!SetOutputMuteInternal(mute_on))
return;
- if (mute_on)
- return;
+ output_mute_on_ = mute_on;
+ audio_pref_handler_->SetMuteValue(active_output_node_id_, output_mute_on_);
+ FOR_EACH_OBSERVER(AudioObserver, observers_, OnOutputMuteChanged());
+}
- // Adjust volume level if user unmute the device and makes sure the volume
- // is set to a minimum audible level.
+void CrasAudioHandler::AdjustOutputVolumeToAudibleLevel() {
if (output_volume_ <= kMuteThresholdPercent) {
// Avoid the situation when sound has been unmuted, but the volume
// is set to a very low value, so user still can't hear any sound.
- SetOutputVolumeInternal(kDefaultUnmuteVolumePercent);
+ SetOutputVolumePercent(kDefaultUnmuteVolumePercent);
}
}
-bool CrasAudioHandler::SetOutputMuteInternal(bool mute_on) {
- if (output_mute_locked_)
- return false;
-
- output_mute_on_ = mute_on;
- audio_pref_handler_->SetMuteValue(active_output_node_id_, mute_on);
- chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->
- SetOutputMute(mute_on);
- return true;
-}
-
void CrasAudioHandler::SetInputMute(bool mute_on) {
- if (input_mute_locked_)
+ if (!SetInputMuteInternal(mute_on))
return;
input_mute_on_ = mute_on;
- audio_pref_handler_->SetMuteValue(active_input_node_id_, mute_on);
- chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->
- SetInputMute(mute_on);
+ audio_pref_handler_->SetMuteValue(active_input_node_id_, input_mute_on_);
+ FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputMuteChanged());
}
void CrasAudioHandler::SetActiveOutputNode(uint64 node_id) {
@@ -311,41 +305,32 @@ void CrasAudioHandler::AudioClientRestarted() {
}
void CrasAudioHandler::OutputVolumeChanged(int volume) {
- if (output_volume_ == volume)
+ if (output_volume_ != volume) {
+ LOG(WARNING) << "Output volume state inconsistent, internal volume="
+ << output_volume_ << ", dbus signal volume=" << volume;
return;
-
- output_volume_ = volume;
- audio_pref_handler_->SetVolumeGainValue(active_output_node_id_, volume);
- FOR_EACH_OBSERVER(AudioObserver, observers_, OnOutputVolumeChanged());
+ }
}
void CrasAudioHandler::InputGainChanged(int gain) {
- if (input_gain_ == gain)
- return;
-
- input_gain_ = gain;
- audio_pref_handler_->SetVolumeGainValue(active_input_node_id_, gain);
- FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputGainChanged());
+ if (input_gain_ != gain) {
+ LOG(WARNING) << "input gain state inconsistent, internal gain="
+ << input_gain_ << ", dbus signal gain=" << gain;
+ }
}
void CrasAudioHandler::OutputMuteChanged(bool mute_on) {
- if (output_mute_on_ == mute_on)
- return;
-
- output_mute_on_ = mute_on;
- // TODO(rkc,jennyz): We need to save the mute preferences here. See
- // crbug.com/239646.
- FOR_EACH_OBSERVER(AudioObserver, observers_, OnOutputMuteChanged());
+ if (output_mute_on_ != mute_on) {
+ LOG(WARNING) << "output mute state inconsistent, internal mute="
+ << output_mute_on_ << ", dbus signal mute=" << mute_on;
+ }
}
void CrasAudioHandler::InputMuteChanged(bool mute_on) {
- if (input_mute_on_ == mute_on)
- return;
-
- input_mute_on_ = mute_on;
- // TODO(rkc,jennyz): Fix this also when fixing the output mute. See
- // crbug.com/239646.
- FOR_EACH_OBSERVER(AudioObserver, observers_, OnInputMuteChanged());
+ if (input_mute_on_ != mute_on) {
+ LOG(WARNING) << "input mute state inconsistent, internal mute="
+ << input_mute_on_ << ", dbus signal mute=" << mute_on;
+ }
}
void CrasAudioHandler::NodesChanged() {
@@ -381,12 +366,13 @@ void CrasAudioHandler::SetupAudioInputState() {
input_mute_on_ = audio_pref_handler_->GetMuteValue(active_input_node_id_);
input_gain_ = audio_pref_handler_->GetVolumeGainValue(
active_input_node_id_);
- SetInputMute(input_mute_on_);
- SetInputGainInternal(input_gain_);
} else {
- SetInputMute(kPrefMuteOff);
- SetInputGainInternal(kDefaultVolumeGainPercent);
+ input_mute_on_ = kPrefMuteOff;
+ input_gain_ = kDefaultVolumeGainPercent;
}
+
+ SetInputMuteInternal(input_mute_on_);
+ SetInputGainInternal(input_gain_);
}
void CrasAudioHandler::SetupAudioOutputState() {
@@ -429,11 +415,29 @@ void CrasAudioHandler::SetOutputVolumeInternal(int volume) {
SetOutputVolume(volume);
}
+bool CrasAudioHandler::SetOutputMuteInternal(bool mute_on) {
+ if (output_mute_locked_)
+ return false;
+
+ chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->
+ SetOutputMute(mute_on);
+ return true;
+}
+
void CrasAudioHandler::SetInputGainInternal(int gain) {
chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->
SetInputGain(gain);
}
+bool CrasAudioHandler::SetInputMuteInternal(bool mute_on) {
+ if (input_mute_locked_)
+ return false;
+
+ chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->
+ SetInputMute(mute_on);
+ return true;
+}
+
void CrasAudioHandler::GetNodes() {
chromeos::DBusThreadManager::Get()->GetCrasAudioClient()->GetNodes(
base::Bind(&CrasAudioHandler::HandleGetNodes,
@@ -455,11 +459,11 @@ void CrasAudioHandler::SwitchToDevice(const AudioDevice& device) {
// to hear the wrong volume for a device.
LOG(INFO) << "Switching active device to: " << device.ToString();
if (device.is_input) {
- DBusThreadManager::Get()->GetCrasAudioClient()->SetInputMute(true);
+ SetInputMuteInternal(true);
DBusThreadManager::Get()->GetCrasAudioClient()->SetActiveInputNode(
device.id);
} else {
- DBusThreadManager::Get()->GetCrasAudioClient()->SetOutputMute(true);
+ SetOutputMuteInternal(true);
DBusThreadManager::Get()->GetCrasAudioClient()->SetActiveOutputNode(
device.id);
}
« no previous file with comments | « chromeos/audio/cras_audio_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698