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

Side by Side Diff: media/audio/pulse/pulse_input.cc

Issue 645923002: Add support for audio input mute detection on all platforms (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added default implementation for cras Created 6 years, 2 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
« no previous file with comments | « media/audio/pulse/pulse_input.h ('k') | media/audio/virtual_audio_input_stream.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/audio/pulse/pulse_input.h" 5 #include "media/audio/pulse/pulse_input.h"
6 6
7 #include <pulse/pulseaudio.h> 7 #include <pulse/pulseaudio.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/audio/pulse/audio_manager_pulse.h" 10 #include "media/audio/pulse/audio_manager_pulse.h"
(...skipping 12 matching lines...) Expand all
23 const AudioParameters& params, 23 const AudioParameters& params,
24 pa_threaded_mainloop* mainloop, 24 pa_threaded_mainloop* mainloop,
25 pa_context* context) 25 pa_context* context)
26 : audio_manager_(audio_manager), 26 : audio_manager_(audio_manager),
27 callback_(NULL), 27 callback_(NULL),
28 device_name_(device_name), 28 device_name_(device_name),
29 params_(params), 29 params_(params),
30 channels_(0), 30 channels_(0),
31 volume_(0.0), 31 volume_(0.0),
32 stream_started_(false), 32 stream_started_(false),
33 muted_(false),
33 fifo_(params.channels(), 34 fifo_(params.channels(),
34 params.frames_per_buffer(), 35 params.frames_per_buffer(),
35 kNumberOfBlocksBufferInFifo), 36 kNumberOfBlocksBufferInFifo),
36 pa_mainloop_(mainloop), 37 pa_mainloop_(mainloop),
37 pa_context_(context), 38 pa_context_(context),
38 handle_(NULL), 39 handle_(NULL),
39 context_state_changed_(false) { 40 context_state_changed_(false) {
40 DCHECK(mainloop); 41 DCHECK(mainloop);
41 DCHECK(context); 42 DCHECK(context);
42 CHECK(params_.IsValid()); 43 CHECK(params_.IsValid());
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 193
193 size_t index = pa_stream_get_device_index(handle_); 194 size_t index = pa_stream_get_device_index(handle_);
194 pa_operation* operation = pa_context_get_source_info_by_index( 195 pa_operation* operation = pa_context_get_source_info_by_index(
195 pa_context_, index, &VolumeCallback, this); 196 pa_context_, index, &VolumeCallback, this);
196 WaitForOperationCompletion(pa_mainloop_, operation); 197 WaitForOperationCompletion(pa_mainloop_, operation);
197 198
198 return volume_; 199 return volume_;
199 } 200 }
200 } 201 }
201 202
203 bool PulseAudioInputStream::IsMuted() {
204 DCHECK(thread_checker_.CalledOnValidThread());
205 AutoPulseLock auto_lock(pa_mainloop_);
no longer working on chromium 2014/10/14 11:45:42 please extract these lines of code into a helper m
henrika (OOO until Aug 14) 2014/10/14 14:21:13 Done.
206 if (!handle_)
207 return false;
208
209 size_t index = pa_stream_get_device_index(handle_);
210 pa_operation* operation = pa_context_get_source_info_by_index(
211 pa_context_, index, &MuteCallback, this);
212 WaitForOperationCompletion(pa_mainloop_, operation);
213
214 return muted_;
215 }
216
202 // static, used by pa_stream_set_read_callback. 217 // static, used by pa_stream_set_read_callback.
203 void PulseAudioInputStream::ReadCallback(pa_stream* handle, 218 void PulseAudioInputStream::ReadCallback(pa_stream* handle,
204 size_t length, 219 size_t length,
205 void* user_data) { 220 void* user_data) {
206 PulseAudioInputStream* stream = 221 PulseAudioInputStream* stream =
207 reinterpret_cast<PulseAudioInputStream*>(user_data); 222 reinterpret_cast<PulseAudioInputStream*>(user_data);
208 223
209 stream->ReadData(); 224 stream->ReadData();
210 } 225 }
211 226
(...skipping 17 matching lines...) Expand all
229 for (int i = 0; i < stream->channels_; ++i) { 244 for (int i = 0; i < stream->channels_; ++i) {
230 if (volume < info->volume.values[i]) 245 if (volume < info->volume.values[i])
231 volume = info->volume.values[i]; 246 volume = info->volume.values[i];
232 } 247 }
233 248
234 // It is safe to access |volume_| here since VolumeCallback() is running 249 // It is safe to access |volume_| here since VolumeCallback() is running
235 // under PulseLock. 250 // under PulseLock.
236 stream->volume_ = static_cast<double>(volume); 251 stream->volume_ = static_cast<double>(volume);
237 } 252 }
238 253
254 // static, used by pa_context_get_source_info_by_index.
255 void PulseAudioInputStream::MuteCallback(pa_context* context,
256 const pa_source_info* info,
257 int error, void* user_data) {
258 PulseAudioInputStream* stream =
259 reinterpret_cast<PulseAudioInputStream*>(user_data);
260
261 if (error) {
262 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0);
263 return;
264 }
265
266 stream->muted_ = static_cast<bool>(info->mute);
267 }
268
239 // static, used by pa_stream_set_state_callback. 269 // static, used by pa_stream_set_state_callback.
240 void PulseAudioInputStream::StreamNotifyCallback(pa_stream* s, 270 void PulseAudioInputStream::StreamNotifyCallback(pa_stream* s,
241 void* user_data) { 271 void* user_data) {
242 PulseAudioInputStream* stream = 272 PulseAudioInputStream* stream =
243 reinterpret_cast<PulseAudioInputStream*>(user_data); 273 reinterpret_cast<PulseAudioInputStream*>(user_data);
244 if (s && stream->callback_ && 274 if (s && stream->callback_ &&
245 pa_stream_get_state(s) == PA_STREAM_FAILED) { 275 pa_stream_get_state(s) == PA_STREAM_FAILED) {
246 stream->callback_->OnError(stream); 276 stream->callback_->OnError(stream);
247 } 277 }
248 278
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // Sleep 5ms to wait until render consumes the data in order to avoid 325 // Sleep 5ms to wait until render consumes the data in order to avoid
296 // back to back OnData() method. 326 // back to back OnData() method.
297 if (fifo_.available_blocks()) 327 if (fifo_.available_blocks())
298 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); 328 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5));
299 } 329 }
300 330
301 pa_threaded_mainloop_signal(pa_mainloop_, 0); 331 pa_threaded_mainloop_signal(pa_mainloop_, 0);
302 } 332 }
303 333
304 } // namespace media 334 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/pulse/pulse_input.h ('k') | media/audio/virtual_audio_input_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698