Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/audio_mixer_alsa.h" | 5 #include "chrome/browser/chromeos/audio_mixer_alsa.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include <alsa/asoundlib.h> | 9 #include <alsa/asoundlib.h> |
| 10 | 10 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 if (old_value != mute) { | 168 if (old_value != mute) { |
| 169 if (mute) { | 169 if (mute) { |
| 170 save_volume_ = DoGetVolumeDb_Locked(); | 170 save_volume_ = DoGetVolumeDb_Locked(); |
| 171 DoSetVolumeDb_Locked(min_volume_); | 171 DoSetVolumeDb_Locked(min_volume_); |
| 172 } else { | 172 } else { |
| 173 DoSetVolumeDb_Locked(save_volume_); | 173 DoSetVolumeDb_Locked(save_volume_); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 | 176 |
| 177 SetElementMuted_Locked(elem_master_, mute); | 177 SetElementMuted_Locked(elem_master_, mute); |
| 178 if (elem_pcm_) | |
| 179 SetElementMuted_Locked(elem_pcm_, mute); | |
|
davejcool
2011/03/03 20:05:02
It turns out the PCM mixer element does have a mut
| |
| 180 prefs_->SetInteger(prefs::kAudioMute, mute ? kPrefMuteOn : kPrefMuteOff); | 178 prefs_->SetInteger(prefs::kAudioMute, mute ? kPrefMuteOn : kPrefMuteOff); |
| 181 } | 179 } |
| 182 | 180 |
| 183 AudioMixer::State AudioMixerAlsa::GetState() const { | 181 AudioMixer::State AudioMixerAlsa::GetState() const { |
| 184 base::AutoLock lock(mixer_state_lock_); | 182 base::AutoLock lock(mixer_state_lock_); |
| 185 // If we think it's ready, verify it is actually so. | 183 // If we think it's ready, verify it is actually so. |
| 186 if ((mixer_state_ == READY) && (alsa_mixer_ == NULL)) | 184 if ((mixer_state_ == READY) && (alsa_mixer_ == NULL)) |
| 187 mixer_state_ = IN_ERROR; | 185 mixer_state_ = IN_ERROR; |
| 188 return mixer_state_; | 186 return mixer_state_; |
| 189 } | 187 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 | 237 |
| 240 bool AudioMixerAlsa::InitializeAlsaMixer() { | 238 bool AudioMixerAlsa::InitializeAlsaMixer() { |
| 241 base::AutoLock lock(mixer_state_lock_); | 239 base::AutoLock lock(mixer_state_lock_); |
| 242 if (mixer_state_ != INITIALIZING) | 240 if (mixer_state_ != INITIALIZING) |
| 243 return false; | 241 return false; |
| 244 | 242 |
| 245 int err; | 243 int err; |
| 246 snd_mixer_t* handle = NULL; | 244 snd_mixer_t* handle = NULL; |
| 247 const char* card = "default"; | 245 const char* card = "default"; |
| 248 | 246 |
| 247 // Verify PCM can be opened, which also instantiates the PCM mixer element | |
| 248 // which is needed for finer volume control and for muting by setting to zero. | |
| 249 // If it fails, we can still try to use the mixer as best we can. | |
| 250 snd_pcm_t* pcm_out_handle; | |
| 251 if ((err = snd_pcm_open(&pcm_out_handle, | |
| 252 "default", | |
| 253 SND_PCM_STREAM_PLAYBACK, | |
| 254 0)) >= 0) { | |
| 255 snd_pcm_close(pcm_out_handle); | |
| 256 } | |
| 257 else | |
| 258 { | |
| 259 LOG(WARNING) << "ALSA PCM open: " << snd_strerror(err); | |
| 260 } | |
| 261 | |
| 249 if ((err = snd_mixer_open(&handle, 0)) < 0) { | 262 if ((err = snd_mixer_open(&handle, 0)) < 0) { |
| 250 LOG(ERROR) << "ALSA mixer " << card << " open error: " << snd_strerror(err); | 263 LOG(ERROR) << "ALSA mixer " << card << " open error: " << snd_strerror(err); |
| 251 return false; | 264 return false; |
| 252 } | 265 } |
| 253 | 266 |
| 254 if ((err = snd_mixer_attach(handle, card)) < 0) { | 267 if ((err = snd_mixer_attach(handle, card)) < 0) { |
| 255 LOG(ERROR) << "ALSA Attach to card " << card << " failed: " | 268 LOG(ERROR) << "ALSA Attach to card " << card << " failed: " |
| 256 << snd_strerror(err); | 269 << snd_strerror(err); |
| 257 snd_mixer_close(handle); | 270 snd_mixer_close(handle); |
| 258 return false; | 271 return false; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 VLOG(1) << "Setting volume to " << pref_volume << " and mute to " << mute; | 354 VLOG(1) << "Setting volume to " << pref_volume << " and mute to " << mute; |
| 342 | 355 |
| 343 if (mute) { | 356 if (mute) { |
| 344 save_volume_ = pref_volume; | 357 save_volume_ = pref_volume; |
| 345 DoSetVolumeDb_Locked(min_volume_); | 358 DoSetVolumeDb_Locked(min_volume_); |
| 346 } else { | 359 } else { |
| 347 DoSetVolumeDb_Locked(pref_volume); | 360 DoSetVolumeDb_Locked(pref_volume); |
| 348 } | 361 } |
| 349 | 362 |
| 350 SetElementMuted_Locked(elem_master_, mute); | 363 SetElementMuted_Locked(elem_master_, mute); |
| 351 if (elem_pcm_) | |
| 352 SetElementMuted_Locked(elem_pcm_, mute); | |
| 353 } | 364 } |
| 354 | 365 |
| 355 void AudioMixerAlsa::RestoreVolumeMuteOnUIThread() { | 366 void AudioMixerAlsa::RestoreVolumeMuteOnUIThread() { |
| 356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 357 // This happens during init, so set the volume off the UI thread. | 368 // This happens during init, so set the volume off the UI thread. |
| 358 int mute = prefs_->GetInteger(prefs::kAudioMute); | 369 int mute = prefs_->GetInteger(prefs::kAudioMute); |
| 359 double vol = prefs_->GetDouble(prefs::kAudioVolume); | 370 double vol = prefs_->GetDouble(prefs::kAudioVolume); |
| 360 { | 371 { |
| 361 base::AutoLock lock(mixer_state_lock_); | 372 base::AutoLock lock(mixer_state_lock_); |
| 362 if (mixer_state_ == SHUTTING_DOWN) | 373 if (mixer_state_ == SHUTTING_DOWN) |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 513 if (alsa_result != 0) { | 524 if (alsa_result != 0) { |
| 514 LOG(WARNING) << "snd_mixer_selem_set_playback_switch_all() failed: " | 525 LOG(WARNING) << "snd_mixer_selem_set_playback_switch_all() failed: " |
| 515 << snd_strerror(alsa_result); | 526 << snd_strerror(alsa_result); |
| 516 } else { | 527 } else { |
| 517 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(elem) | 528 VLOG(1) << "Set playback switch " << snd_mixer_selem_get_name(elem) |
| 518 << " to " << enabled; | 529 << " to " << enabled; |
| 519 } | 530 } |
| 520 } | 531 } |
| 521 | 532 |
| 522 } // namespace chromeos | 533 } // namespace chromeos |
| OLD | NEW |