cpal icon indicating copy to clipboard operation
cpal copied to clipboard

PipeWire backend: timeline for crates.io release?

Open silverstein opened this issue 7 months ago • 13 comments

Hi, we're using cpal's PipeWire backend in Minutes (conversation memory layer, ~900 stars). We're currently pinned to a git rev on master since the PipeWire feature isn't available in any crates.io release (latest is 0.17.3).

This blocks us from publishing our own crate to crates.io (cargo publish rejects git deps).

Is there a timeline for a release that includes the PipeWire backend? Happy to help test or contribute if that speeds things up.

silverstein avatar Apr 06 '26 03:04 silverstein

Glad to hear it's working well for you!

I've got two more design goals for the next release:

  • various correctness fixes to the hosts (PipeWire amongst them)
  • refactoring the various error types into a unified one, inspired by std::io::Error

Neither of them should take huge amounts of time; for the second one I've already got a local branch that needs rebasing.

As I'm volunteering this strictly in my free time, I can't make any promises but I'm thinking in less than a month. Understanding that sooner is better, I hope this somewhat accommodates your release schedule.

roderickvd avatar Apr 06 '26 17:04 roderickvd

@roderickvd That timeline works great for us, thanks! No rush on our account.

We're happy to test pre-release builds against our pipeline if that's useful. We have a contributor (@Dieterbe) running Arch/PipeWire who's been exercising the PipeWire backend on real recordings, so I think we can give it a solid workout before you cut the release.

Thanks for maintaining cpal, it's a cornerstone of what we're building.

silverstein avatar Apr 06 '26 17:04 silverstein

Great. I just pushed a significant update to the PipeWire backend, which should complete part of goal number one. Would be great if you could drop a note if everything's still OK.

roderickvd avatar Apr 06 '26 19:04 roderickvd

We have a contributor (@Dieterbe) running Arch/PipeWire who's been exercising the PipeWire backend on real recording

The only testing I've done this far is very crude: just calling the get devices() method. I'll need to figure out how to get the monitor pseudo-devices through the special port, then I can also try recording.

Dieterbe avatar Apr 06 '26 22:04 Dieterbe

@roderickvd Tested the latest master (8b152c3) against our pipeline on Linux today. Bumped from 63ea9ff to 8b152c3 (5 commits, including the PipeWire #1148 and ALSA #1149 fixes you just landed).

Result: clean build and clean runtime on every code path we exercised.

  • cargo build --release for our CLI completes successfully with the pipewire feature on
  • cpal::default_host().input_devices() enumerates without panicking
  • Our device categorization layer (capture vs loopback) handles the new metadata correctly
  • End-to-end pipeline (whisper transcription, diarization, markdown write on a WAV file) works exactly as before

Tested in a Linux Codespace (mcr.microsoft.com/devcontainers/rust:1-bookworm plus libpipewire-0.3-dev and libspa-0.2-dev). Codespaces don't have real audio hardware so I can't verify monitor pseudo-source enumeration directly. @Dieterbe's Arch box is the source of truth there. But the build, enumeration, and lifecycle paths all look good from our side.

Thanks for landing those fixes. No regressions on the paths we tested, and we're happy to keep pinning to your latest master revs until the crates.io release.

silverstein avatar Apr 07 '26 04:04 silverstein

Quick follow-up: dug into this today and turns out the "monitor sources missing" symptom in our downstream code was actually a bug on OUR side, not in cpal's PipeWire backend.

Walking through what cpal 8b152c3 actually does:

  • Audio/Sink nodes get direction = Duplex so they appear in host.input_devices() (src/host/pipewire/device.rs:657-663)
  • Recording from one transparently uses the sink's monitor port via STREAM_CAPTURE_SINK = "true" at stream creation (device.rs:133-135)

So there are no separate monitor pseudo-devices like PulseAudio has. The sink itself IS the monitor source. This is actually a cleaner model than PulseAudio, but anyone bringing a PulseAudio mental model (including us) will look for separate *.monitor entries and not find them.

Shipped a fix on our side: silverstein/minutes#85. The bug was in our device categorizer treating Linux sinks as "Microphone" because the only loopback hints we recognized were macOS-style names (BlackHole, Soundflower, etc.). Now it checks supports_input() && supports_output(), gated to the PipeWire host because both macOS and ALSA have legitimate Duplex devices that would false-positive.

The one thing that would have made this easier to discover from the cpal side: a doc comment near device.rs:657-663 or on the Class enum explaining the sinks-as-Duplex model and how STREAM_CAPTURE_SINK makes the monitor capture transparent. I'm happy to send that doc PR if it'd be useful, no pressure.

Thanks again for the recent fixes. Staying pinned to your master revs until the crates.io release.

silverstein avatar Apr 07 '26 05:04 silverstein

I'm happy to send that doc PR if it'd be useful, no pressure.

Contributions welcome!

Over at https://github.com/silverstein/minutes/pull/85 you mention that ALSA has a similar risk. It was a quick read but you mean in cpal or in Memory?

roderickvd avatar Apr 07 '26 06:04 roderickvd

To answer the question: I meant the risk in our categorizer in PR #85, not in cpal's ALSA backend.

We only apply that heuristic on PipeWire: discovered Audio/Sink nodes are surfaced as DeviceDirection::Duplex, and input streams opened on sink-role devices set STREAM_CAPTURE_SINK. On ALSA plenty of devices end up Duplex too (NULL IOID hints, genuinely duplex hardware), so unrelated ALSA devices reported as Duplex would trip the same check. We gate on host.id() == HostId::PipeWire to scope it.

Doc PR coming.

silverstein avatar Apr 07 '26 14:04 silverstein

Doc PR up: #1151. Single 6-line comment at the discovery match site, no behavior change.

silverstein avatar Apr 07 '26 14:04 silverstein

should pipewire be the default host for future releases ?

wiiznokes avatar Apr 23 '26 16:04 wiiznokes

Ticket about a potential platform which will know regression, I'm waiting for more info from the reporter (which initially reached me via SongRec's Matrix channel): https://github.com/marin-m/SongRec/issues/276

marin-m avatar Apr 23 '26 16:04 marin-m

Re: A second issue that reports the devel version of CPAL not working at all with FuriOS, precising that time that the defect is present only within Flatpak (edit: the non-Flatpak build uses the crates.io source distribution which still depends on CPAL stable so it shouldn't be taken in account I guess): https://github.com/marin-m/SongRec/issues/296

marin-m avatar May 08 '26 15:05 marin-m

Continuing at #1192.

roderickvd avatar May 09 '26 13:05 roderickvd