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

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: 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 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 29 matching lines...) Expand all
78 if (client_connected_ && !apply_is_pending_) 81 if (client_connected_ && !apply_is_pending_)
79 thread_->message_loop()->PostTask(FROM_HERE, 82 thread_->message_loop()->PostTask(FROM_HERE,
80 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this))); 83 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this)));
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 mute) {
89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
90 base::AutoLock lock(lock_); 93 base::AutoLock lock(lock_);
91 is_muted_ = muted; 94 if (is_mute_locked_) {
92 if (client_connected_ && !apply_is_pending_) 95 NOTREACHED() << "Mute has been locked!";
93 thread_->message_loop()->PostTask(FROM_HERE, 96 return;
94 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this))); 97 }
98 is_muted_ = mute;
99 ApplyStateIfNeeded();
100 }
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 mute) {
120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
121 base::AutoLock lock(lock_);
122 if (is_capture_mute_locked_) {
123 NOTREACHED() << "Capture mute has been locked!";
124 return;
125 }
126 is_capture_muted_ = mute;
127 ApplyStateIfNeeded();
128 }
129
130 bool AudioMixerCras::IsCaptureMuteLocked() {
131 base::AutoLock lock(lock_);
132 return is_capture_mute_locked_;
133 }
134
135 void AudioMixerCras::SetCaptureMuteLocked(bool locked) {
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
137 base::AutoLock lock(lock_);
138 is_capture_mute_locked_ = locked;
139 ApplyStateIfNeeded();
95 } 140 }
96 141
97 void AudioMixerCras::Connect() { 142 void AudioMixerCras::Connect() {
98 DCHECK(MessageLoop::current() == thread_->message_loop()); 143 DCHECK(MessageLoop::current() == thread_->message_loop());
99 144
100 // Create the client structure. 145 // Create the client structure.
101 if (client_ == NULL && cras_client_create(&client_) < 0) { 146 if (client_ == NULL && cras_client_create(&client_) < 0) {
102 LOG(DFATAL) << "cras_client_create() failed"; 147 LOG(DFATAL) << "cras_client_create() failed";
103 return; // TODO(dgreid) change interface so this can return an error. 148 return; // TODO(dgreid) change interface so this can return an error.
104 } 149 }
(...skipping 14 matching lines...) Expand all
119 164
120 ApplyState(); 165 ApplyState();
121 } 166 }
122 167
123 void AudioMixerCras::ApplyState() { 168 void AudioMixerCras::ApplyState() {
124 DCHECK(MessageLoop::current() == thread_->message_loop()); 169 DCHECK(MessageLoop::current() == thread_->message_loop());
125 if (!client_connected_) 170 if (!client_connected_)
126 return; 171 return;
127 172
128 bool should_mute = false; 173 bool should_mute = false;
174 bool should_lock_mute = false;
175 bool should_mute_capture = false;
176 bool should_lock_capture_mute = false;
129 size_t new_volume = 0; 177 size_t new_volume = 0;
130 { 178 {
131 base::AutoLock lock(lock_); 179 base::AutoLock lock(lock_);
132 should_mute = is_muted_; 180 should_mute = is_muted_;
181 should_lock_mute = is_mute_locked_;
182 should_mute_capture = is_capture_muted_;
183 should_lock_capture_mute = is_capture_mute_locked_;
133 new_volume = floor(volume_percent_ + 0.5); 184 new_volume = floor(volume_percent_ + 0.5);
134 apply_is_pending_ = false; 185 apply_is_pending_ = false;
135 } 186 }
136 187
137 // If muting mute before setting volume, if un-muting set volume first. 188 // If muting mute before setting volume, if un-muting set volume first.
138 if (should_mute) { 189 if (should_mute) {
139 cras_client_set_system_mute(client_, should_mute); 190 cras_client_set_system_mute(client_, should_mute);
140 cras_client_set_system_volume(client_, new_volume); 191 cras_client_set_system_volume(client_, new_volume);
141 } else { 192 } else {
142 cras_client_set_system_volume(client_, new_volume); 193 cras_client_set_system_volume(client_, new_volume);
143 cras_client_set_system_mute(client_, should_mute); 194 cras_client_set_system_mute(client_, should_mute);
144 } 195 }
196 cras_client_set_system_mute_locked(client_, should_lock_mute);
197 cras_client_set_system_capture_mute(client_, should_mute_capture);
198 cras_client_set_system_capture_mute_locked(client_, should_lock_capture_mute);
199 }
200
201 void AudioMixerCras::ApplyStateIfNeeded() {
202 lock_.AssertAcquired();
203 if (client_connected_ && !apply_is_pending_) {
204 thread_->message_loop()->PostTask(
205 FROM_HERE,
206 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this)));
207 }
145 } 208 }
146 209
147 } // namespace chromeos 210 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/audio/audio_mixer_cras.h ('k') | chrome/browser/policy/configuration_policy_handler_list.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698