cpal icon indicating copy to clipboard operation
cpal copied to clipboard

Allow to read devices names directly from audio server (Pipewire, Pulseaudio etc. instead of backend-ALSA)

Open SimonDevStack opened this issue 8 months ago • 2 comments

use cpal::traits::{DeviceTrait, HostTrait};
fn main() {
    let host = cpal::default_host();
    match host.input_devices() {
        Ok(devices) => {
            for x in devices {
                println!("{}", x.description().unwrap());
            }
        }
        Err(_) => println!("No devices were found"),
    }
}

The following code prints this garbage data:

Rate Converter Plugin Using Libav/FFmpeg Library
Rate Converter Plugin Using Samplerate Library
Rate Converter Plugin Using Speex Resampler
JACK Audio Connection Kit
Open Sound System
PipeWire Sound Server
PulseAudio Sound Server
Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
Plugin for channel upmix (4,6,8)
Plugin for channel downmix (stereo) with a simple spacialization
Default ALSA Output (currently PipeWire Media Server)
HDA ATI HDMI
HD-Audio Generic
HD-Audio Generic, ALC897 Analog
HD-Audio Generic, ALC897 Analog
HD-Audio Generic
HD-Audio Generic, ALC897 Analog
HD-Audio Generic, ALC897 Analog
HD-Audio Generic, ALC897 Alt Analog
HD-Audio Generic, ALC897 Alt Analog

I'm looking for a way to get meaningful data like with the pactl list sources short commend which provides useful output:

118	bluez_input.00:02:3C:AC:F5:B9	PipeWire	float32le 1ch 48000Hz	SUSPENDED
121	bluez_output.00:02:3C:AC:F5:B9.monitor	PipeWire	float32le 2ch 48000Hz	SUSPENDED```

specifically the `bluez_output.00:02:3C:AC:F5:B9.monitor`, `bluez_input.00:02:3C:AC:F5:B9	PipeWire` format 

SimonDevStack avatar Mar 08 '26 11:03 SimonDevStack

ALSA's enumeration is designed to mirror the contents of aplay -l and aplay -L. bluealsa does not register per-device hints, and so individual Bluetooth devices don't appear.

If you look at the enumerate example then that gives the following output as intended:

1. alsa:null (Discard all samples (playback) or generate zero samples (capture))
2. alsa:sysdefault (Default Audio Device)
3. alsa:bluealsa (Bluetooth Audio)
4. alsa:pipewire (PipeWire Sound Server)
5. alsa:default (Default ALSA Output (currently PipeWire Media Server))
6. alsa:hw:CARD=vc4hdmi0,DEV=0 (vc4-hdmi-0, MAI PCM i2s-hifi-0)
7. alsa:plughw:CARD=vc4hdmi0,DEV=0 (vc4-hdmi-0, MAI PCM i2s-hifi-0)
8. alsa:sysdefault:CARD=vc4hdmi0 (vc4-hdmi-0, MAI PCM i2s-hifi-0)
9. alsa:hdmi:CARD=vc4hdmi0,DEV=0 (vc4-hdmi-0, MAI PCM i2s-hifi-0)
10. alsa:dmix:CARD=vc4hdmi0,DEV=0 (vc4-hdmi-0, MAI PCM i2s-hifi-0)

Note that this has Bluetooth headphones connected, but like aplay you can't see that.

On this same system with --features pipewire you get:

1. pipewire:sink_default (sink_default)
2. pipewire:input_default (input_default)
3. pipewire:output_default (output_default)
4. pipewire:alsa_output.usb-C-Media_Electronics_Inc._USB_Audio_Device-00.analog-stereo (USB Audio Device)
5. pipewire:alsa_input.usb-SunplusIT_Inc_PC_Camera_JV0-02.analog-stereo (PC Camera)
6. pipewire:bluez_input.00_22_BB_77_05_69.0 (Blue Byrd ANC (2nd gen.) via Bluetooth)
7. pipewire:bluez_output.00_22_BB_77_05_69.1 (Blue Byrd ANC (2nd gen.) via Bluetooth)

Note the last two entries, which should be what you're after.

roderickvd avatar Mar 26 '26 21:03 roderickvd

Thanks, solved my issue

SimonDevStack avatar Mar 28 '26 11:03 SimonDevStack