summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordavej@chromium.org <davej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-04 19:04:12 +0000
committerdavej@chromium.org <davej@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-04 19:04:12 +0000
commita5d9581d9c3788c81e317414f58fbdee4e671724 (patch)
tree87fd7552dda1151b60bc8d2d1ab833a3b4676126
parent024bcff4e6d0927c19e4589153202b2f183c1875 (diff)
downloadchromium_src-a5d9581d9c3788c81e317414f58fbdee4e671724.zip
chromium_src-a5d9581d9c3788c81e317414f58fbdee4e671724.tar.gz
chromium_src-a5d9581d9c3788c81e317414f58fbdee4e671724.tar.bz2
Mute ALSA audio completely
The PCM control is needed to mute audio completely, but it is not available until at least one pcm stream is opened. This fix just opens and closes a pcm stream before gathering information about which mixer controls are available. BUG=chromium-os:12151 TEST=Manual, play audio then mute. No audio should be heard through headphones. Review URL: http://codereview.chromium.org/6591095 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76943 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/audio_mixer_alsa.cc19
1 files changed, 15 insertions, 4 deletions
diff --git a/chrome/browser/chromeos/audio_mixer_alsa.cc b/chrome/browser/chromeos/audio_mixer_alsa.cc
index 34fb722..ca99065 100644
--- a/chrome/browser/chromeos/audio_mixer_alsa.cc
+++ b/chrome/browser/chromeos/audio_mixer_alsa.cc
@@ -175,8 +175,6 @@ void AudioMixerAlsa::SetMute(bool mute) {
}
SetElementMuted_Locked(elem_master_, mute);
- if (elem_pcm_)
- SetElementMuted_Locked(elem_pcm_, mute);
prefs_->SetInteger(prefs::kAudioMute, mute ? kPrefMuteOn : kPrefMuteOff);
}
@@ -246,6 +244,21 @@ bool AudioMixerAlsa::InitializeAlsaMixer() {
snd_mixer_t* handle = NULL;
const char* card = "default";
+ // Verify PCM can be opened, which also instantiates the PCM mixer element
+ // which is needed for finer volume control and for muting by setting to zero.
+ // If it fails, we can still try to use the mixer as best we can.
+ snd_pcm_t* pcm_out_handle;
+ if ((err = snd_pcm_open(&pcm_out_handle,
+ "default",
+ SND_PCM_STREAM_PLAYBACK,
+ 0)) >= 0) {
+ snd_pcm_close(pcm_out_handle);
+ }
+ else
+ {
+ LOG(WARNING) << "ALSA PCM open: " << snd_strerror(err);
+ }
+
if ((err = snd_mixer_open(&handle, 0)) < 0) {
LOG(ERROR) << "ALSA mixer " << card << " open error: " << snd_strerror(err);
return false;
@@ -348,8 +361,6 @@ void AudioMixerAlsa::DoSetVolumeMute(double pref_volume, int pref_mute) {
}
SetElementMuted_Locked(elem_master_, mute);
- if (elem_pcm_)
- SetElementMuted_Locked(elem_pcm_, mute);
}
void AudioMixerAlsa::RestoreVolumeMuteOnUIThread() {