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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/pulse/pulse_input.cc
diff --git a/media/audio/pulse/pulse_input.cc b/media/audio/pulse/pulse_input.cc
index 8d4aeea2079d201a69e52fb48e4344680c467d70..6c5668becd9d69ab2c2d489d9f9644d961f2ed07 100644
--- a/media/audio/pulse/pulse_input.cc
+++ b/media/audio/pulse/pulse_input.cc
@@ -10,6 +10,22 @@
#include "media/audio/pulse/audio_manager_pulse.h"
#include "media/audio/pulse/pulse_util.h"
+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.
+
+// pa_context_get_server_info callback. It's used by
+// GetSystemDefaultInputDevice to set |default_system_device_name_| to the
+// default system input device.
+void GetSystemDefaultInputDeviceCallback(pa_context* context,
+ const pa_server_info* info,
+ void* user_data) {
+ media::PulseAudioInputStream* stream =
+ reinterpret_cast<media::PulseAudioInputStream*>(user_data);
+ stream->SetDefaultSystemDeviceName(info->default_source_name);
+ pa_threaded_mainloop* pa_mainloop = stream->GetPAMainloop();
+ pa_threaded_mainloop_signal(pa_mainloop, 0);
+}
+}
Henrik Grunell 2016/03/10 00:57:07 } } // namespace
rchtara 2016/03/10 13:20:34 Done.
+
namespace media {
using pulse::AutoPulseLock;
@@ -48,11 +64,26 @@ PulseAudioInputStream::~PulseAudioInputStream() {
DCHECK(!handle_);
}
+void PulseAudioInputStream::GetSystemDefaultInputDevice() {
+ DCHECK(pa_mainloop_);
+ DCHECK(pa_context_);
+ pa_operation* operation = pa_context_get_server_info(
+ pa_context_, GetSystemDefaultInputDeviceCallback, this);
+ WaitForOperationCompletion(pa_mainloop_, operation);
+}
+
bool PulseAudioInputStream::Open() {
DCHECK(thread_checker_.CalledOnValidThread());
AutoPulseLock auto_lock(pa_mainloop_);
+ std::string device_name_to_use = device_name_;
+ if (device_name_ == AudioManagerBase::kDefaultDeviceId) {
+ GetSystemDefaultInputDevice();
+ device_name_to_use = default_system_device_name_;
+ }
+
if (!pulse::CreateInputStream(pa_mainloop_, pa_context_, &handle_, params_,
- device_name_, &StreamNotifyCallback, this)) {
+ device_name_to_use, &StreamNotifyCallback,
+ this)) {
return false;
}
@@ -197,6 +228,15 @@ bool PulseAudioInputStream::IsMuted() {
return muted_;
}
+pa_threaded_mainloop* PulseAudioInputStream::GetPAMainloop() {
+ return pa_mainloop_;
+}
+
+void PulseAudioInputStream::SetDefaultSystemDeviceName(
+ const std::string& name) {
+ 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.
+}
+
// static, used by pa_stream_set_read_callback.
void PulseAudioInputStream::ReadCallback(pa_stream* handle,
size_t length,

Powered by Google App Engine
This is Rietveld 408576698