mk-fg / python-pulse-control

Python high-level interface and ctypes-based bindings for PulseAudio (libpulse)
https://pypi.org/project/pulsectl/
MIT License
170 stars 36 forks source link

Can't list ports of sinks/sources #51

Closed seevoid closed 3 years ago

seevoid commented 3 years ago

Hello,

I would like to list all the ports of a sink or a source but I didn't find anything to do this in your wrapper. Do you have any information about it ? Is it possible ?

Thanks, Seevoid

mk-fg commented 3 years ago

I would like to list all the ports of a sink or a source but I didn't find anything to do this in your wrapper. Do you have any information about it ? Is it possible ?

Yeah, should totally be doable already. I think port_list attribute should have these, you can use it like this:

with Pulse() as pulse:
  for sink in pulse.sink_list():
    print('Sink ::', sink)
    for port in sink.port_list: print('  Port ::', port)

Output might look something like this:

Sink :: description='Built-in Audio Analog Stereo', index=0, mute=0, name='alsa_output.pci-0000_00_14.2.analog-stereo', channels=2, volumes=[71% 71%]
  Port :: available=<EnumValue available=no>, description='Line Out', name='analog-output-lineout', priority=9000
  Port :: available=<EnumValue available=unknown>, description='Headphones', name='analog-output-headphones', priority=9900
Sink :: description='Baffin HDMI/DP Audio [Radeon RX 550 640SP / RX 560/560X] Digital Stereo (HDMI)', index=34, mute=0, name='alsa_output.pci-0000_04_00.1.hdmi-stereo', channels=2, volumes=[71% 71%]
  Port :: available=<EnumValue available=yes>, description='HDMI / DisplayPort', name='hdmi-output-0', priority=5900

Cheers!

mk-fg commented 3 years ago

Issue here seem to be that I never bothered to document all these attributes, and best way to discover them is probably running help(sink) and seeing if there's anything resembling what you're looking for.

Mostly they map closely to the corresponding libpulse concepts though, i.e. if sink_info struct in libpulse has "n_ports" + "ports" members, then in python wrapper that'd translate to a list of ports on the instance somewhere ("port_list" as it happens, following "_list" suffix convention used throughout this wrapper for consistency). So I'd generally suggest looking stuff up in e.g. libpulse doxygen docs or .h files there (which docs are generated from, but if you can read C, you can kinda use these as simplier greppable plaintext version), and then expect same attributes to be here as well, unless no one cared about them so far (yet) and there should just be a line or two added to parse them from struct.