Bug 255348 - multimedia/pipewire: first take at alsa and media session
Summary: multimedia/pipewire: first take at alsa and media session
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Gleb Popov
Keywords: patch
Depends on: 245321
  Show dependency treegraph
Reported: 2021-04-23 16:11 UTC by Evgeniy Khramtsov
Modified: 2021-05-02 20:22 UTC (History)
1 user (show)

See Also:
arrowd: maintainer-feedback+

patch (11.17 KB, patch)
2021-04-23 16:11 UTC, Evgeniy Khramtsov
no flags Details | Diff
known good config for pw-play (5.56 KB, application/octet-stream)
2021-04-23 16:15 UTC, Evgeniy Khramtsov
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Evgeniy Khramtsov 2021-04-23 16:11:57 UTC
Created attachment 224380 [details]

There are patches to build alsa and media session. I plan on sending them upstream this week. This depends on 245321, media session requires alsa-lib >=1.1.7. Media session also has flatpak/xdg-portal related code, this might be useful for these.

PipeWire clients e.g. pw-cat pw-play can play sound via alsa backend with edited pipewire.conf to include alsa static sink adapter pointing to "pcm.default"  (see asound.conf & posted known working config next). Pulse clients do not work yet because the pipewire-pulse daemon gets wrong audio formats from pipewire.

PIPEWIRE_DEBUG=5 is too verbose, the only catch for now is pipewire-pulse reports sink-name "null", but it seems that "null" means to use the default sink from pipewire; pactl confirms that the default sink is used. I plan to continue debugging this next weekend, the PR is here to make sure that the progress does not block on me.

If sound does not work after configuration change that was faulty, make sure that ~/.config/pipewire is rm'ed. PipeWire restore-session wasted a lot of my time before this was found out.

If one wants to build jack, then version >=1.9.10 is needed (bug 251125).

SDL2 is disabled because it is needed only for tests and gets enabled if devel/sdl20 is installed. If one wants to build it anyway, then make sure to add localbase to USES.

TODO: find out where the LD_PRELOAD libs are and/or how to build them, check if static alsa source (microphone) can be configured, xdg-desktop-portal stuff, OSS backend.

FreeBSD 14 poudriere bulk && poudriere testport w/ all options sets: OK.
Comment 1 Evgeniy Khramtsov 2021-04-23 16:15:47 UTC
Created attachment 224382 [details]
known good config for pw-play
Comment 2 Gleb Popov freebsd_committer 2021-04-23 16:21:04 UTC
It is great that you're working on this!

I'm not using PipeWire for myself, so I can't test your changes, but the patch seems fine overall.

Please, make sure to submit these changes upstream, it is pretty responsive. Also note that GitHub mirror [1] has Cirrus CI set up for testing FreeBSD builds (which is failing ATM). It'd be awesome if you fix it up, enable alsa and make sure it passes.

I'm a bit reluctant to push patches to the Ports repo and usually wait for a release that contains these changes. However, if you wish, I can commit it right away. Let me know what you prefer.

And thanks again for working on this.

[1]: https://github.com/PipeWire/pipewire
Comment 3 Evgeniy Khramtsov 2021-04-23 16:27:37 UTC
(In reply to Gleb Popov from comment #2)


> Let me know what you prefer.

The latter (wait for a release that contains these changes).

> make sure to submit these changes upstream


> fix it up, enable alsa and make sure it passes.

I'll check this next week.
Comment 4 Gleb Popov freebsd_committer 2021-04-23 16:34:03 UTC
(In reply to Evgeniy Khramtsov from comment #3)

> The latter (wait for a release that contains these changes).

Great that we're agree on this. Feel free to get me on the hook when submitting a GitLab merge request.
Comment 5 Evgeniy Khramtsov 2021-04-23 20:21:25 UTC
(In reply to Gleb Popov from comment #4)
I've just built the master branch: https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/632
Comment 6 Gleb Popov freebsd_committer 2021-04-24 17:51:17 UTC
Nice. Can you also please fix GitHub CI? It should be as easy as adding gettext stuff to .cirrus.yml file.

It'd be also great if you enable alsa for CI.
Comment 7 Evgeniy Khramtsov 2021-04-24 19:39:33 UTC
(In reply to Gleb Popov from comment #6)

Sure, this is planned for the next week, currently away from the FreeBSD machine...

I’ll see next week if CI can build the new alsa before building the pipe. If it can’t, then the new alsa-lib has to hit the ports tree first before the CI changes.

I’ll add the alsa bug to the depends of this bug.
Comment 8 Evgeniy Khramtsov 2021-04-26 14:41:43 UTC
(In reply to Gleb Popov from comment #6)

See https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/637

To build with alsa, the CI has to build the new alsa-lib locally (waiting for 245321 to land into ports would be too long). I'll add alsa to the CI tomorrow.
Comment 9 Gleb Popov freebsd_committer 2021-04-26 14:55:20 UTC
(In reply to Evgeniy Khramtsov from comment #8)

I'd rather wait for alsa update to be committed, but if you have spare time - why not?
Comment 10 Evgeniy Khramtsov 2021-04-27 17:15:36 UTC
(In reply to Gleb Popov from comment #9)

See: https://gitlab.freedesktop.org/pipewire/pipewire/-/merge_requests/638

Building alsa-lib locally is PITA, even with 'make -d x' commands from the port build pasted directly.

I resolved this via minimal ports tree (e.g. audio/alsa-lib only and several Mk related dirs) in the compressed archive.

I'm kinda slow to reply/open pages/commit, nat64.net is overloaded for some reason today :D
Comment 11 Evgeniy Khramtsov 2021-05-02 20:22:46 UTC
Current progress:

1. Commenting 'restore-stream' in configuration files results in much improved debug information, and also gets rid of cached configuration and negotiations in ~/.config/pipewire.

2. ALSA OSS plugin abuse does not work with pipewire-pulse due to the default configured values (ex. default.clock.rate). Configuring audio.format for alsa sinks breaks format negotiation (audioadapter.c negotiate_format()) the same way for pw-play as with pipewire-pulse. The same applies to pipewire alsa, it gets configured by default, so aplay via pipewire does not work due to defaults.

3. Doxygen documentation seems to be misleading on format negotiation because it focuses on streams.

4. Continuing to abuse pcm.plug:oss is the wrong way, because PipeWire ALSA SPA plugin inserts a converter after format negotiation, which is an another can of worms if we abuse the oss plugin in alsa. No further progress in ALSA OSS abuse anymore.

To use pipewire as a pulseaudio replacement, one should write an OSS SPA plugin.

And also, this patch misses alsa-plugins, which has the required library for ALSA OSS abuse... This doesn't matter, because alsa-plugins is not needed for media session, so the patch is not updated.