I am working on a golang
software that aims at dealing (muting and unmuting) with the currently enabled microphone in a Linux system using pulseaudio.
My software is trying to use the DBUs
interface to interact with pulseaudio.
If the computer has more than one microphone connected to it, I need to find the enabled one by looking at the priority
property of my sources.
For example this is a trimmed output from the pacmd list-sources
command:
4 source(s) available.
index: 0
name: <alsa_output.pci-0000_00_1f.3.analog-stereo.monitor>
...
priority: 1030
...
index: 1
name: <alsa_input.pci-0000_00_1f.3.analog-stereo>
...
priority: 9039
...
index: 2
name: <combined.monitor>
...
priority: 1000
...
* index: 4
name: <alsa_input.usb-046d_0825_6C7C2E60-02.mono-fallback>
...
priority: 9040
...
In fact, in my system, the source with index 4 is the active one.
My problem: I can't find a way to get the priority
property out of the DBUs
interface.
According to the documentation, neither the Source
nor the Device
Objects expose a property named Priority
.
The only objects having a Priority
field are DevicePort
and CardProfile
. I got the value for those properties but their value doesn't match with the output of pacmd
.
Do you know if and where I can get the priority value?
At the time of writing getting the priority of sources is simply not possible.
There is an open merge request (by me) to add the support: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/531
In any case the subject is more complex than this.
In order to get the currently system-wide active microphone it's possible to use the FallbackSource
property, but the user might have customized the microphone to be used by a specific app so a one size fits all solution doesn't exist.