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

Unified Diff: chrome/browser/chromeos/audio/audio_mixer_alsa.cc

Issue 10873085: Implement two new policies to control muting the audio I/O. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased to ToT. Created 8 years, 3 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 | « chrome/browser/chromeos/audio/audio_mixer_alsa.h ('k') | chrome/browser/chromeos/audio/audio_mixer_cras.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..464a4a01f4898bda9e6e82ddf6f1b27ac5703e34 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,13 @@ 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)));
+ }
+}
+
} // namespace chromeos
« no previous file with comments | « chrome/browser/chromeos/audio/audio_mixer_alsa.h ('k') | chrome/browser/chromeos/audio/audio_mixer_cras.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698