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

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

Issue 1711823004: Let default device in PulseAudio be the system default device (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: latest Created 4 years, 9 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
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 <stdint.h> 7 #include <stdint.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"
11 #include "media/audio/pulse/pulse_util.h" 11 #include "media/audio/pulse/pulse_util.h"
12 12
13 namespace {
Henrik Grunell 2016/03/10 00:57:07 Put the anonymous namespace inside the media names
rchtara 2016/03/10 13:20:34 Done.
14
15 // pa_context_get_server_info callback. It's used by
16 // GetSystemDefaultInputDevice to set |default_system_device_name_| to the
17 // default system input device.
18 void GetSystemDefaultInputDeviceCallback(pa_context* context,
19 const pa_server_info* info,
20 void* user_data) {
21 media::PulseAudioInputStream* stream =
22 reinterpret_cast<media::PulseAudioInputStream*>(user_data);
23 stream->SetDefaultSystemDeviceName(info->default_source_name);
24 pa_threaded_mainloop* pa_mainloop = stream->GetPAMainloop();
25 pa_threaded_mainloop_signal(pa_mainloop, 0);
26 }
27 }
Henrik Grunell 2016/03/10 00:57:07 } } // namespace
rchtara 2016/03/10 13:20:34 Done.
28
13 namespace media { 29 namespace media {
14 30
15 using pulse::AutoPulseLock; 31 using pulse::AutoPulseLock;
16 using pulse::WaitForOperationCompletion; 32 using pulse::WaitForOperationCompletion;
17 33
18 // Number of blocks of buffers used in the |fifo_|. 34 // Number of blocks of buffers used in the |fifo_|.
19 const int kNumberOfBlocksBufferInFifo = 2; 35 const int kNumberOfBlocksBufferInFifo = 2;
20 36
21 PulseAudioInputStream::PulseAudioInputStream(AudioManagerPulse* audio_manager, 37 PulseAudioInputStream::PulseAudioInputStream(AudioManagerPulse* audio_manager,
22 const std::string& device_name, 38 const std::string& device_name,
(...skipping 18 matching lines...) Expand all
41 DCHECK(context); 57 DCHECK(context);
42 CHECK(params_.IsValid()); 58 CHECK(params_.IsValid());
43 } 59 }
44 60
45 PulseAudioInputStream::~PulseAudioInputStream() { 61 PulseAudioInputStream::~PulseAudioInputStream() {
46 // All internal structures should already have been freed in Close(), 62 // All internal structures should already have been freed in Close(),
47 // which calls AudioManagerPulse::Release which deletes this object. 63 // which calls AudioManagerPulse::Release which deletes this object.
48 DCHECK(!handle_); 64 DCHECK(!handle_);
49 } 65 }
50 66
67 void PulseAudioInputStream::GetSystemDefaultInputDevice() {
68 DCHECK(pa_mainloop_);
69 DCHECK(pa_context_);
70 pa_operation* operation = pa_context_get_server_info(
71 pa_context_, GetSystemDefaultInputDeviceCallback, this);
72 WaitForOperationCompletion(pa_mainloop_, operation);
73 }
74
51 bool PulseAudioInputStream::Open() { 75 bool PulseAudioInputStream::Open() {
52 DCHECK(thread_checker_.CalledOnValidThread()); 76 DCHECK(thread_checker_.CalledOnValidThread());
53 AutoPulseLock auto_lock(pa_mainloop_); 77 AutoPulseLock auto_lock(pa_mainloop_);
78 std::string device_name_to_use = device_name_;
79 if (device_name_ == AudioManagerBase::kDefaultDeviceId) {
80 GetSystemDefaultInputDevice();
81 device_name_to_use = default_system_device_name_;
82 }
83
54 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_, 84 if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_,
55 device_name_, &StreamNotifyCallback, this)) { 85 device_name_to_use, &StreamNotifyCallback,
86 this)) {
56 return false; 87 return false;
57 } 88 }
58 89
59 DCHECK(handle_); 90 DCHECK(handle_);
60 91
61 return true; 92 return true;
62 } 93 }
63 94
64 void PulseAudioInputStream::Start(AudioInputCallback* callback) { 95 void PulseAudioInputStream::Start(AudioInputCallback* callback) {
65 DCHECK(thread_checker_.CalledOnValidThread()); 96 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 return volume_; 221 return volume_;
191 } 222 }
192 } 223 }
193 224
194 bool PulseAudioInputStream::IsMuted() { 225 bool PulseAudioInputStream::IsMuted() {
195 DCHECK(thread_checker_.CalledOnValidThread()); 226 DCHECK(thread_checker_.CalledOnValidThread());
196 GetSourceInformation(&MuteCallback); 227 GetSourceInformation(&MuteCallback);
197 return muted_; 228 return muted_;
198 } 229 }
199 230
231 pa_threaded_mainloop* PulseAudioInputStream::GetPAMainloop() {
232 return pa_mainloop_;
233 }
234
235 void PulseAudioInputStream::SetDefaultSystemDeviceName(
236 const std::string& name) {
237 default_system_device_name_ = name;
Henrik Grunell 2016/03/10 00:57:07 Either add a thread check or lock. Seems like we c
rchtara 2016/03/10 13:20:34 DCHECK(stream->thread_checker_.CalledOnValidThread
Henrik Grunell 2016/03/10 20:07:34 Seems you were using the pulse auto lock. Instead
rchtara 2016/03/11 10:13:09 Done.
238 }
239
200 // static, used by pa_stream_set_read_callback. 240 // static, used by pa_stream_set_read_callback.
201 void PulseAudioInputStream::ReadCallback(pa_stream* handle, 241 void PulseAudioInputStream::ReadCallback(pa_stream* handle,
202 size_t length, 242 size_t length,
203 void* user_data) { 243 void* user_data) {
204 PulseAudioInputStream* stream = 244 PulseAudioInputStream* stream =
205 reinterpret_cast<PulseAudioInputStream*>(user_data); 245 reinterpret_cast<PulseAudioInputStream*>(user_data);
206 246
207 stream->ReadData(); 247 stream->ReadData();
208 } 248 }
209 249
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 return false; 366 return false;
327 367
328 size_t index = pa_stream_get_device_index(handle_); 368 size_t index = pa_stream_get_device_index(handle_);
329 pa_operation* operation = 369 pa_operation* operation =
330 pa_context_get_source_info_by_index(pa_context_, index, callback, this); 370 pa_context_get_source_info_by_index(pa_context_, index, callback, this);
331 WaitForOperationCompletion(pa_mainloop_, operation); 371 WaitForOperationCompletion(pa_mainloop_, operation);
332 return true; 372 return true;
333 } 373 }
334 374
335 } // namespace media 375 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698