Chromium Code Reviews| Index: chrome/browser/chromeos/audio/audio_mixer_alsa.cc |
| diff --git a/chrome/browser/chromeos/audio/audio_mixer_alsa.cc b/chrome/browser/chromeos/audio/audio_mixer_alsa.cc |
| index c51cca8554cc0660791fb6a2041afdb495341b57..6527c9aabcf8d3dd1e363342bbbca84d608c83e2 100644 |
| --- a/chrome/browser/chromeos/audio/audio_mixer_alsa.cc |
| +++ b/chrome/browser/chromeos/audio/audio_mixer_alsa.cc |
| @@ -41,6 +41,9 @@ const char* const kMasterElementNames[] = { |
| }; |
| const char kPCMElementName[] = "PCM"; |
| +const char kMicElementName[] = "Mic"; |
| +const char kFrontMicElementName[] = "Front Mic"; |
| + |
| // Default minimum and maximum volume (before we've loaded the actual range from |
| // ALSA), in decibels. |
| const double kDefaultMinVolumeDb = -90.0; |
| @@ -76,6 +79,8 @@ AudioMixerAlsa::AudioMixerAlsa() |
| initial_volume_percent_(kDefaultVolumePercent), |
| alsa_mixer_(NULL), |
| pcm_element_(NULL), |
| + mic_element_(NULL), |
| + front_mic_element_(NULL), |
| disconnected_event_(true, false), |
| num_connection_attempts_(0) { |
| } |
| @@ -127,9 +132,7 @@ void AudioMixerAlsa::SetVolumePercent(double percent) { |
| initial_volume_percent_ = percent; |
| } else { |
| volume_db_ = PercentToDb(percent); |
| - if (!apply_is_pending_) |
| - thread_->message_loop()->PostTask(FROM_HERE, |
| - base::Bind(&AudioMixerAlsa::ApplyState, base::Unretained(this))); |
| + ApplyStateIfNeeded(); |
| } |
| } |
| @@ -138,13 +141,53 @@ bool AudioMixerAlsa::IsMuted() { |
| return is_muted_; |
| } |
| -void AudioMixerAlsa::SetMuted(bool muted) { |
| +void AudioMixerAlsa::SetMuted(bool mute) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| base::AutoLock lock(lock_); |
| - is_muted_ = muted; |
| - if (!apply_is_pending_) |
| - thread_->message_loop()->PostTask(FROM_HERE, |
| - base::Bind(&AudioMixerAlsa::ApplyState, base::Unretained(this))); |
| + if (is_mute_locked_) { |
| + NOTREACHED() << "Capture mute has been locked!"; |
| + return; |
| + } |
| + is_muted_ = mute; |
| + ApplyStateIfNeeded(); |
| +} |
| + |
| +bool AudioMixerAlsa::IsMuteLocked() { |
| + base::AutoLock lock(lock_); |
| + return is_mute_locked_; |
| +} |
| + |
| +void AudioMixerAlsa::SetMuteLocked(bool locked) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + base::AutoLock lock(lock_); |
| + is_mute_locked_ = locked; |
| +} |
| + |
| +bool AudioMixerAlsa::IsCaptureMuted() { |
| + base::AutoLock lock(lock_); |
| + return is_capture_muted_; |
| +} |
| + |
| +void AudioMixerAlsa::SetCaptureMuted(bool mute) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + base::AutoLock lock(lock_); |
| + if (is_capture_mute_locked_) { |
| + NOTREACHED() << "Capture mute has been locked!"; |
| + return; |
| + } |
| + is_capture_muted_ = mute; |
| + ApplyStateIfNeeded(); |
| +} |
| + |
| +bool AudioMixerAlsa::IsCaptureMuteLocked() { |
| + base::AutoLock lock(lock_); |
| + return is_capture_mute_locked_; |
| +} |
| + |
| +void AudioMixerAlsa::SetCaptureMuteLocked(bool locked) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + base::AutoLock lock(lock_); |
| + is_capture_mute_locked_ = locked; |
| } |
| void AudioMixerAlsa::Connect() { |
| @@ -266,11 +309,17 @@ bool AudioMixerAlsa::ConnectInternal() { |
| VLOG(1) << "Volume range is " << min_volume_db << " dB to " |
| << max_volume_db << " dB"; |
| + |
| + snd_mixer_elem_t* mic_element = FindElementWithName(handle, kMicElementName); |
| + snd_mixer_elem_t* front_mic_element = |
| + FindElementWithName(handle, kFrontMicElementName); |
| { |
| base::AutoLock lock(lock_); |
| alsa_mixer_ = handle; |
| master_element_ = master_element; |
| pcm_element_ = pcm_element; |
| + mic_element_ = mic_element; |
| + front_mic_element_ = front_mic_element; |
| min_volume_db_ = min_volume_db; |
| max_volume_db_ = max_volume_db; |
| volume_db_ = PercentToDb(initial_volume_percent_); |
| @@ -301,10 +350,12 @@ void AudioMixerAlsa::ApplyState() { |
| return; |
| bool should_mute = false; |
| + bool should_mute_capture = false; |
| double new_volume_db = 0; |
| { |
| base::AutoLock lock(lock_); |
| should_mute = is_muted_; |
| + should_mute_capture = is_capture_muted_; |
| new_volume_db = should_mute ? min_volume_db_ : volume_db_; |
| apply_is_pending_ = false; |
| } |
| @@ -325,6 +376,10 @@ void AudioMixerAlsa::ApplyState() { |
| } |
| SetElementMuted(master_element_, should_mute); |
| + if (mic_element_) |
| + SetElementMuted(mic_element_, should_mute_capture); |
| + if (front_mic_element_) |
| + SetElementMuted(front_mic_element_, should_mute_capture); |
| } |
| snd_mixer_elem_t* AudioMixerAlsa::FindElementWithName( |
| @@ -440,4 +495,12 @@ double AudioMixerAlsa::PercentToDb(double percent) const { |
| (max_volume_db_ - min_volume_db_) + min_volume_db_; |
| } |
| +void AudioMixerAlsa::ApplyStateIfNeeded() { |
| + lock_.AssertAcquired(); |
| + if (!apply_is_pending_) { |
| + thread_->message_loop()->PostTask(FROM_HERE, |
| + base::Bind(&AudioMixerAlsa::ApplyState, base::Unretained(this))); |
|
Mattias Nissler (ping if slow)
2012/08/30 11:51:26
indentation: PostTask arguments should be aligned.
pastarmovj
2012/08/31 07:28:24
Done.
|
| + } |
| +} |
| + |
| } // namespace chromeos |