gst_device_monitor_start fails when no pulseaudio server is running
Summary
gst_device_monitor_start
is failing to start the device monitor, with no
obvious error being reported, if gst-plugins-good is compiled with pulseaudio
support but the sound server is not running. This is an issue on a system that
has libpulseaudio installed (pretty common) but only using ALSA.
Steps to reproduce
- Compile gst-plugins-good with alsa and pulseaudio support
- Stop the pulseaudio server (delete the socket in $XDG_RUNIME_DIR if necesssary)
- Run
gst-device-monitor-1.0
- Observer the
Failed to start device monitor!
error
Detailed description
I have a GStreamer-based VoIP application that can't detect any microphone on my system. The code is something like this:
monitor = gst_device_monitor_new();
GstCaps *caps = gst_caps_new_empty_simple("audio/x-raw");
gst_device_monitor_add_filter(monitor, "Audio/Source", caps);
gst_caps_unref(caps);
# and similar code for video
GstBus *bus = gst_device_monitor_get_bus(monitor);
gst_bus_add_watch(bus, newBusMessage, nullptr);
gst_object_unref(bus);
gst_device_monitor_start(monitor)
and the last call, gst_device_monitor_start
, is returning false.
Similarly, by running gst-device-monitor-1.0
(which uses the same function) I get:
Probing devices...
Failed to start device monitor!
By cranking up the logging using GST_DEBUG
, I can only see two warnings in between
the two messages printed by gst-device-monitor:
0x1ca5c00 WARN default gstdevicemonitor.c:458:gst_device_monitor_start:<devicemonitor0> No filters have been set, will expose all devices found
0x1ca5c00 WARN default gstdevicemonitor.c:466:gst_device_monitor_start:<devicemonitor0> No providers match the current filters
While device detection is not working, the ALSA plugins are being loaded:
$ gst-inspect-1.0 | grep alsa
alsa: alsasrc: Audio source (ALSA)
alsa: alsasink: Audio sink (ALSA)
alsa: alsamidisrc: AlsaMidi Source
and I can use the microphone just fine using this example command:
gst-launch-1.0 -v alsasrc ! queue ! audioconvert ! vorbisenc ! oggmux ! filesink location=alsasrc.ogg
I had an intuition so I run an strace and figured that gstreamer must be trying to connect to a pulseaudio server, but that fails because there simply isn't one:
openat(AT_FDCWD, "/home/rnhmjoj/.pulse/client.conf", O_RDONLY|O_CLOEXEC <unfinished ...>
openat(AT_FDCWD, "/home/rnhmjoj/.config/pulse/client.conf", O_RDONLY|O_CLOEXEC <unfinished ...>
openat(AT_FDCWD, "/etc/pulse/client.conf", O_RDONLY|O_CLOEXEC) = 14
openat(AT_FDCWD, "/etc/pulse/client.conf.d", O_RDONLY|O_NONBLOCK|O_CLOEXEC|O_DIRECTORY) = -1 ENOENT (No such file or directory)
memfd_create("pulseaudio", MFD_ALLOW_SEALING) = 14
mkdir("/run/user/1000/pulse", 0700) = -1 EEXIST (File exists)
openat(AT_FDCWD, "/run/user/1000/pulse", O_RDONLY|O_NOCTTY|O_NOFOLLOW|O_CLOEXEC) = 15
lstat("/run/user/1000/pulse", {st_mode=S_IFDIR|0700, st_size=40, ...}) = 0
connect(15, {sa_family=AF_UNIX, sun_path="/run/user/1000/pulse/native"}, 110) = -1 ENOENT (No such file or directory)
connect(15, {sa_family=AF_UNIX, sun_path="/var/run/pulse/native"}, 110) = -1 ENOENT (No such file or directory)
To confirm this is the cause of the failure, I compiled gst-plugins-good with
-Dpulse=disabled
and indeed gst-device-monitor-1.0
now starts and happily
reports my source devices.
As a final note, I tried to apply the patch from !679 (merged), which appeared closely related, but it didn't solve the problem.
Version information
- OS: Linux 5.10.18
- Sound system: ALSA + alsa-lib 1.2.4
- gstreamer: 1.18.2
- gst-plugins-base: 1.18.2