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

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..f8f69b0b82be2a597b16ea8484aba1206a5c3ce6 100644
--- a/media/audio/pulse/pulse_input.cc
+++ b/media/audio/pulse/pulse_input.cc
@@ -12,6 +12,22 @@
namespace media {
+namespace {
+
+// 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_signal(stream->GetPAMainloop(), 0);
+}
+
+} // namespace
+
using pulse::AutoPulseLock;
using pulse::WaitForOperationCompletion;
@@ -51,8 +67,15 @@ PulseAudioInputStream::~PulseAudioInputStream() {
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 +220,15 @@ bool PulseAudioInputStream::IsMuted() {
return muted_;
}
+pa_threaded_mainloop* PulseAudioInputStream::GetPAMainloop() {
+ return pa_mainloop_;
Henrik Grunell 2016/03/10 20:07:34 Could this function be called at the same time as
rchtara 2016/03/11 10:13:09 PulseAudioInputStream::Open is going to lock the m
Henrik Grunell 2016/03/11 18:54:41 Acknowledged.
rchtara 2016/03/13 15:12:00 Done.
+}
+
+void PulseAudioInputStream::SetDefaultSystemDeviceName(
+ const std::string& name) {
+ default_system_device_name_ = name;
+}
+
// static, used by pa_stream_set_read_callback.
void PulseAudioInputStream::ReadCallback(pa_stream* handle,
size_t length,
@@ -268,6 +300,14 @@ void PulseAudioInputStream::StreamNotifyCallback(pa_stream* s,
pa_threaded_mainloop_signal(stream->pa_mainloop_, 0);
}
+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);
+}
+
void PulseAudioInputStream::ReadData() {
uint32_t hardware_delay = pulse::GetHardwareLatencyInBytes(
handle_, params_.sample_rate(), params_.GetBytesPerFrame());

Powered by Google App Engine
This is Rietveld 408576698