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

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: 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!";
96 return;
97 }
91 is_muted_ = muted; 98 is_muted_ = muted;
92 if (client_connected_ && !apply_is_pending_) 99 if (client_connected_ && !apply_is_pending_)
93 thread_->message_loop()->PostTask(FROM_HERE, 100 thread_->message_loop()->PostTask(FROM_HERE,
94 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this))); 101 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this)));
95 } 102 }
96 103
104 bool AudioMixerCras::IsMuteLocked() {
105 base::AutoLock lock(lock_);
106 return is_mute_locked_;
107 }
108
109 void AudioMixerCras::SetMuteLocked(bool locked) {
110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
111 base::AutoLock lock(lock_);
112 is_mute_locked_ = locked;
113 if (client_connected_ && !apply_is_pending_)
114 thread_->message_loop()->PostTask(FROM_HERE,
115 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this)));
116 }
117
118 bool AudioMixerCras::IsCaptureMuted() {
119 base::AutoLock lock(lock_);
120 return is_capture_muted_;
121 }
122
123 void AudioMixerCras::SetCaptureMuted(bool locked) {
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
125 base::AutoLock lock(lock_);
126 if (is_capture_mute_locked_){
127 NOTREACHED() << "Capture mute has been locked!";
128 return;
129 } is_capture_muted_ = locked;
130 if (client_connected_ && !apply_is_pending_)
131 thread_->message_loop()->PostTask(FROM_HERE,
132 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this)));
133 }
134
135 bool AudioMixerCras::IsCaptureMuteLocked() {
136 base::AutoLock lock(lock_);
137 return is_capture_mute_locked_;
138 }
139
140 void AudioMixerCras::SetCaptureMuteLocked(bool locked) {
141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
142 base::AutoLock lock(lock_);
143 is_capture_mute_locked_ = locked;
144 if (client_connected_ && !apply_is_pending_)
145 thread_->message_loop()->PostTask(FROM_HERE,
146 base::Bind(&AudioMixerCras::ApplyState, base::Unretained(this)));
Mattias Nissler (ping if slow) 2012/08/28 12:24:24 Curlies missing here and above, same comment appli
pastarmovj 2012/08/28 15:11:50 It is guaranteed that the lock is only held in the
147 }
148
97 void AudioMixerCras::Connect() { 149 void AudioMixerCras::Connect() {
98 DCHECK(MessageLoop::current() == thread_->message_loop()); 150 DCHECK(MessageLoop::current() == thread_->message_loop());
99 151
100 // Create the client structure. 152 // Create the client structure.
101 if (client_ == NULL && cras_client_create(&client_) < 0) { 153 if (client_ == NULL && cras_client_create(&client_) < 0) {
102 LOG(DFATAL) << "cras_client_create() failed"; 154 LOG(DFATAL) << "cras_client_create() failed";
103 return; // TODO(dgreid) change interface so this can return an error. 155 return; // TODO(dgreid) change interface so this can return an error.
104 } 156 }
105 157
106 if (cras_client_connect(client_) != 0) { 158 if (cras_client_connect(client_) != 0) {
(...skipping 12 matching lines...) Expand all
119 171
120 ApplyState(); 172 ApplyState();
121 } 173 }
122 174
123 void AudioMixerCras::ApplyState() { 175 void AudioMixerCras::ApplyState() {
124 DCHECK(MessageLoop::current() == thread_->message_loop()); 176 DCHECK(MessageLoop::current() == thread_->message_loop());
125 if (!client_connected_) 177 if (!client_connected_)
126 return; 178 return;
127 179
128 bool should_mute = false; 180 bool should_mute = false;
181 bool should_lock_mute = false;
182 bool should_mute_capture = false;
183 bool should_lock_capture_mute = false;
129 size_t new_volume = 0; 184 size_t new_volume = 0;
130 { 185 {
131 base::AutoLock lock(lock_); 186 base::AutoLock lock(lock_);
132 should_mute = is_muted_; 187 should_mute = is_muted_;
188 should_lock_mute = is_mute_locked_;
189 should_mute_capture = is_capture_muted_;
190 should_lock_capture_mute = is_capture_mute_locked_;
133 new_volume = floor(volume_percent_ + 0.5); 191 new_volume = floor(volume_percent_ + 0.5);
134 apply_is_pending_ = false; 192 apply_is_pending_ = false;
135 } 193 }
136 194
137 // If muting mute before setting volume, if un-muting set volume first. 195 // If muting mute before setting volume, if un-muting set volume first.
138 if (should_mute) { 196 if (should_mute) {
139 cras_client_set_system_mute(client_, should_mute); 197 cras_client_set_system_mute(client_, should_mute);
140 cras_client_set_system_volume(client_, new_volume); 198 cras_client_set_system_volume(client_, new_volume);
141 } else { 199 } else {
142 cras_client_set_system_volume(client_, new_volume); 200 cras_client_set_system_volume(client_, new_volume);
143 cras_client_set_system_mute(client_, should_mute); 201 cras_client_set_system_mute(client_, should_mute);
144 } 202 }
203 cras_client_set_system_mute_locked(client_, should_lock_mute);
204 cras_client_set_system_capture_mute(client_, should_mute_capture);
205 cras_client_set_system_capture_mute_locked(client_, should_lock_capture_mute);
145 } 206 }
146 207
147 } // namespace chromeos 208 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698