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

Side by Side Diff: chrome/browser/chromeos/audio/audio_mixer_cras.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: Addressed comments. 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/audio_mixer_cras.h" 5 #include "chrome/browser/chromeos/audio/audio_mixer_cras.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <cras_client.h> 8 #include <cras_client.h>
9 #include <unistd.h> 9 #include <unistd.h>
10 10
(...skipping 18 matching lines...) Expand all
29 // Number of seconds that we'll sleep between each connection attempt. 29 // Number of seconds that we'll sleep between each connection attempt.
30 const int kConnectionRetrySleepSec = 1; 30 const int kConnectionRetrySleepSec = 1;
31 31
32 } // namespace 32 } // namespace
33 33
34 AudioMixerCras::AudioMixerCras() 34 AudioMixerCras::AudioMixerCras()
35 : client_(NULL), 35 : client_(NULL),
36 client_connected_(false), 36 client_connected_(false),
37 volume_percent_(kDefaultVolumePercent), 37 volume_percent_(kDefaultVolumePercent),
38 is_muted_(false), 38 is_muted_(false),
39 is_mute_locked_(false),
40 is_capture_muted_(false),
41 is_capture_mute_locked_(false),
39 apply_is_pending_(true) { 42 apply_is_pending_(true) {
40 } 43 }
41 44
42 AudioMixerCras::~AudioMixerCras() { 45 AudioMixerCras::~AudioMixerCras() {
43 if (!thread_.get()) 46 if (!thread_.get())
44 return; 47 return;
45 DCHECK(MessageLoop::current() != thread_->message_loop()); 48 DCHECK(MessageLoop::current() != thread_->message_loop());
46 49
47 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join; 50 base::ThreadRestrictions::ScopedAllowIO allow_io_for_thread_join;
48 thread_->Stop(); 51 thread_->Stop();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 84 }
82 85
83 bool AudioMixerCras::IsMuted() { 86 bool AudioMixerCras::IsMuted() {
84 base::AutoLock lock(lock_); 87 base::AutoLock lock(lock_);
85 return is_muted_; 88 return is_muted_;
86 } 89 }
87 90
88 void AudioMixerCras::SetMuted(bool muted) { 91 void AudioMixerCras::SetMuted(bool muted) {
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
90 base::AutoLock lock(lock_); 93 base::AutoLock lock(lock_);
94 if (is_mute_locked_) {
95 NOTREACHED() << "Mute has been locked!";
Daniel Erat 2012/08/28 20:40:51 This is why I suggested documenting that callers m
pastarmovj 2012/08/29 08:45:05 Done.
96 return;
97 }
91 is_muted_ = muted; 98 is_muted_ = muted;
92 if (client_connected_ && !apply_is_pending_) 99 ApplyStateIfNeeded();
93 thread_->message_loop()->PostTask(FROM_HERE, 100 }
94 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this))); 101
102 bool AudioMixerCras::IsMuteLocked() {
103 base::AutoLock lock(lock_);
104 return is_mute_locked_;
105 }
106
107 void AudioMixerCras::SetMuteLocked(bool locked) {
108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
109 base::AutoLock lock(lock_);
110 is_mute_locked_ = locked;
111 ApplyStateIfNeeded();
112 }
113
114 bool AudioMixerCras::IsCaptureMuted() {
115 base::AutoLock lock(lock_);
116 return is_capture_muted_;
117 }
118
119 void AudioMixerCras::SetCaptureMuted(bool locked) {
120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
121 base::AutoLock lock(lock_);
122 if (is_capture_mute_locked_){
123 NOTREACHED() << "Capture mute has been locked!";
Daniel Erat 2012/08/28 20:40:51 nit: indent two spaces, not three
pastarmovj 2012/08/29 08:45:05 Grrr don't know why this screwed up here so badly.
124 return;
125 } is_capture_muted_ = locked;
Daniel Erat 2012/08/28 20:40:51 nit: fix formatting
pastarmovj 2012/08/29 08:45:05 Ditto.
126 ApplyStateIfNeeded();
127 }
128
129 bool AudioMixerCras::IsCaptureMuteLocked() {
130 base::AutoLock lock(lock_);
131 return is_capture_mute_locked_;
132 }
133
134 void AudioMixerCras::SetCaptureMuteLocked(bool locked) {
135 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
136 base::AutoLock lock(lock_);
137 is_capture_mute_locked_ = locked;
138 ApplyStateIfNeeded();
95 } 139 }
96 140
97 void AudioMixerCras::Connect() { 141 void AudioMixerCras::Connect() {
98 DCHECK(MessageLoop::current() == thread_->message_loop()); 142 DCHECK(MessageLoop::current() == thread_->message_loop());
99 143
100 // Create the client structure. 144 // Create the client structure.
101 if (client_ == NULL && cras_client_create(&client_) < 0) { 145 if (client_ == NULL && cras_client_create(&client_) < 0) {
102 LOG(DFATAL) << "cras_client_create() failed"; 146 LOG(DFATAL) << "cras_client_create() failed";
103 return; // TODO(dgreid) change interface so this can return an error. 147 return; // TODO(dgreid) change interface so this can return an error.
104 } 148 }
(...skipping 14 matching lines...) Expand all
119 163
120 ApplyState(); 164 ApplyState();
121 } 165 }
122 166
123 void AudioMixerCras::ApplyState() { 167 void AudioMixerCras::ApplyState() {
124 DCHECK(MessageLoop::current() == thread_->message_loop()); 168 DCHECK(MessageLoop::current() == thread_->message_loop());
125 if (!client_connected_) 169 if (!client_connected_)
126 return; 170 return;
127 171
128 bool should_mute = false; 172 bool should_mute = false;
173 bool should_lock_mute = false;
174 bool should_mute_capture = false;
175 bool should_lock_capture_mute = false;
129 size_t new_volume = 0; 176 size_t new_volume = 0;
130 { 177 {
131 base::AutoLock lock(lock_); 178 base::AutoLock lock(lock_);
132 should_mute = is_muted_; 179 should_mute = is_muted_;
180 should_lock_mute = is_mute_locked_;
181 should_mute_capture = is_capture_muted_;
182 should_lock_capture_mute = is_capture_mute_locked_;
133 new_volume = floor(volume_percent_ + 0.5); 183 new_volume = floor(volume_percent_ + 0.5);
134 apply_is_pending_ = false; 184 apply_is_pending_ = false;
135 } 185 }
136 186
137 // If muting mute before setting volume, if un-muting set volume first. 187 // If muting mute before setting volume, if un-muting set volume first.
138 if (should_mute) { 188 if (should_mute) {
139 cras_client_set_system_mute(client_, should_mute); 189 cras_client_set_system_mute(client_, should_mute);
140 cras_client_set_system_volume(client_, new_volume); 190 cras_client_set_system_volume(client_, new_volume);
141 } else { 191 } else {
142 cras_client_set_system_volume(client_, new_volume); 192 cras_client_set_system_volume(client_, new_volume);
143 cras_client_set_system_mute(client_, should_mute); 193 cras_client_set_system_mute(client_, should_mute);
144 } 194 }
195 cras_client_set_system_mute_locked(client_, should_lock_mute);
196 cras_client_set_system_capture_mute(client_, should_mute_capture);
197 cras_client_set_system_capture_mute_locked(client_, should_lock_capture_mute);
198 }
199
200 void AudioMixerCras::ApplyStateIfNeeded() {
Daniel Erat 2012/08/28 20:40:51 nit: check that the lock is held here
pastarmovj 2012/08/29 08:45:05 Done.
201 if (client_connected_ && !apply_is_pending_) {
202 thread_->message_loop()->PostTask(FROM_HERE,
203 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this)));
204 }
145 } 205 }
146 206
147 } // namespace chromeos 207 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698