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..c4e6cbef95d481fa75347f739a42c6af2389f675 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) { |
| } |
| @@ -141,12 +146,58 @@ bool AudioMixerAlsa::IsMuted() { |
| void AudioMixerAlsa::SetMuted(bool muted) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| base::AutoLock lock(lock_); |
| + if (is_mute_locked_) |
| + return; |
| is_muted_ = muted; |
| if (!apply_is_pending_) |
|
Daniel Erat
2012/08/27 17:38:35
nit: add curly braces since the statement doesn't
pastarmovj
2012/08/28 15:11:50
Done.
|
| thread_->message_loop()->PostTask(FROM_HERE, |
| base::Bind(&AudioMixerAlsa::ApplyState, base::Unretained(this))); |
| } |
| +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; |
| + if (!apply_is_pending_) |
|
Daniel Erat
2012/08/27 17:38:35
ditto
pastarmovj
2012/08/28 15:11:50
Done.
|
| + thread_->message_loop()->PostTask(FROM_HERE, |
| + base::Bind(&AudioMixerAlsa::ApplyState, base::Unretained(this))); |
| +} |
| + |
| +bool AudioMixerAlsa::IsCaptureMuted() { |
| + base::AutoLock lock(lock_); |
| + return is_capture_muted_; |
| +} |
| + |
| +void AudioMixerAlsa::SetCaptureMuted(bool muted) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + base::AutoLock lock(lock_); |
| + if (is_capture_mute_locked_) |
| + return; |
| + is_capture_muted_ = muted; |
| + if (!apply_is_pending_) |
|
Daniel Erat
2012/08/27 17:38:35
ditto
pastarmovj
2012/08/28 15:11:50
Done.
|
| + thread_->message_loop()->PostTask(FROM_HERE, |
| + base::Bind(&AudioMixerAlsa::ApplyState, base::Unretained(this))); |
| +} |
| + |
| +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; |
| + if (!apply_is_pending_) |
|
Daniel Erat
2012/08/27 17:38:35
mind fixing this one too?
pastarmovj
2012/08/28 15:11:50
Done.
|
| + thread_->message_loop()->PostTask(FROM_HERE, |
| + base::Bind(&AudioMixerAlsa::ApplyState, base::Unretained(this))); |
|
Mattias Nissler (ping if slow)
2012/08/28 12:24:24
Lots of code duplication here. Any chance to fix?
pastarmovj
2012/08/28 15:11:50
Done.
|
| +} |
| + |
| void AudioMixerAlsa::Connect() { |
| DCHECK(MessageLoop::current() == thread_->message_loop()); |
| DCHECK(!alsa_mixer_); |
| @@ -266,11 +317,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 +358,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 +384,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( |