Closed teohhanhui closed 1 month ago
This is tricky because the pulseaudio
daemon insists on re-executing itself: https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/blob/v17.0/src/daemon/main.c#L592
And we cannot install pulseaudio
on the host since the package would conflict.
We can use user namespace with uid remapping for the current user, right? :thinking:
cf. https://github.com/containers/krunvm/commit/da0a1c482484d6abec5c42f8f330a47bd175c4af
Yes, we'll need to re-package pulseaudio in a way that doesn't conflict with pipewire, so we can install in on the host and execute it from the VM. I had plans to work on this next week.
Do we basically just set PA_BINARY
to /usr/bin/krun-pulseaudio
/usr/libexec/krun/pulseaudio
and call it a day?
https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/blob/v17.0/src/daemon/main.c#L575
We'll probably also need to override the system's alsa & pipewire config (alsa is instructed to redirect output to pipewire) by mounting tmpfs
on top of them and writing a custom config for the VM.
Another working alternative is to run it inside of a container. Haha...
At least it's working inside krun
, but I haven't got it working inside FEXBash
yet... :thinking:
https://gist.github.com/teohhanhui/042a395010d9946ceee14768736e3780
EDIT: Never mind. I don't think this approach works because virtio-snd uses PipeWire backend, and we don't have access to that from within a container?
Weird... Actually, we do have access to /dev/snd/*
from within a distrobox
container, but not from within the krun
VM. Maybe I messed up my rebase of the libkrun
patch?
We'll probably also need to override the system's alsa & pipewire config (alsa is instructed to redirect output to pipewire)
I'm not familiar with any of this, but from what I can see:
/etc/alsa/conf.d/99-pulseaudio-default.conf
provided by alsa-plugins-pulseaudio
package/usr/bin/pulseaudio
provided by pulseudio
package/usr/bin/pipewire-pulse
provided by pipewire-pulseaudio
packageSo I don't think there's anything to do. There's pipewire-alsa
which replaces alsa-plugins-pulseaudio
. And then there's user config in HOME
...
Maybe I messed up my rebase of the
libkrun
patch?
Okay, getting somewhere with PIPEWIRE_DEBUG=4 krun bash
:
[D][02601.369493] pw.thread-loop | [ thread-loop.c: 146 loop_new()] 0xfffc08007e50: new name:Pipewire thread loopfailed to create contextFailed to connect to coresync failedpipewire backend runningStream Audioaudio-outputcould not create new streamcould not connect to the streamInvalid direction prepare could not disconnect stream release pipewire startcould not start stream start pipewire stopcould not stop stream stop State changed: could not update paramsNo buffer recievedassertion failed: bytes_read == to_readdevices::virtio::snd::audio_backendssrc/devices/src/virtio/snd/audio_backends.rsallocating audio backend devices::virtio::snd::devicesrc/devices/src/virtio/snd/device.rsa PCM_INFO request should have a writeable descriptor for the info payload response after the header status responsea PCM_INFO request should have three descriptors total.returned for ctrl msg BAD_MSGOKsnd: process_control()Error processing control message: index= head_index=snd: process_txq_queue()snd: p... (truncated)
Hmm... This seems like just all the messages. Never mind.
https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/issues/3816
Running pactl load-module module-alsa-card device_id=0
manually gets it working.
We aren't running udev in the VM. We can simply ship a default.pa
that configures the alsa devices on start. It's working here for me, both with native and x86 (w/fex) binaries. It's now just a matter of getting pulseaudio packaged in a decent shape.
We can simply ship a default.pa that configures the alsa devices on start.
We can add a config file in /etc/pulse/default.pa.d
, but I don't see a mechanism to only do load-module module-alsa-card device_id=0
when we're running inside krun
VM.
Found a solution: pulseaudio -D --load="module-alsa-card device_id=0" --exit-idle-time=-1
We aren't running udev in the VM. We can simply ship a
default.pa
that configures the alsa devices on start. It's working here for me, both with native and x86 (w/fex) binaries. It's now just a matter of getting pulseaudio packaged in a decent shape.
Is this why controllers don’t work?
@teohhanhui I've created a pulseaudio-krun
package that can be installed side-by-side with pipewire: https://copr.fedorainfracloud.org/coprs/slp/pulseaudio-krun/
Using it with your command line works nicely. We should probably update krun-guest
to launch it if present.
We aren't running udev in the VM. We can simply ship a
default.pa
that configures the alsa devices on start. It's working here for me, both with native and x86 (w/fex) binaries. It's now just a matter of getting pulseaudio packaged in a decent shape.Is this why controllers don’t work?
If by controllers you mean gamepads, no. The problem with gamepads is that there's not Wayland extension to transport that kind of input device, so sommelier
can't translate them from the host to the VM.
A possible solution for this is implementing a virtio-input device that would detect and read the events from /dev/input/eventX
.
I've created a
pulseaudio-krun
package that can be installed side-by-side with pipewire: https://copr.fedorainfracloud.org/coprs/slp/pulseaudio-krun/
A few suggestions:
krun-pulseaudio
(pulseaudio-krun
gives the impression that it's a pulseaudio
subpackage / plugin or something...)pulseaudio
in /usr/libexec/krun/pulseaudio
, and configure the meson build to only build a few selected targets. This is just perfect for our needs:
I wouldn't mind working on this.
2. I thought about it long and hard, and I think this approach is mistaken. We should rather install
pulseaudio
in/usr/libexec/krun/pulseaudio
, and configure the meson build to only build a few selected targets. This is just perfect for our needs:* https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/blob/v17.0/meson_options.txt#L1-3 * https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/blob/v17.0/src/meson.build#L222-226
I wouldn't mind working on this.
Sounds good to me.
Sound should be working after #9.
Sound doesn't seem to be working even when
libkrun
is built withvirtio-snd
support, e.g.: https://github.com/teohhanhui/libkrun/tree/virtio-snd (patch adapted from @slp but updated for latestlibkrun
)I think we're missing this: https://github.com/teohhanhui/asahi-krun-container/blob/799243343a4546be9e464f9a64d7326d3655e294/entrypoint-user.sh#L7-L9 (again, adapted from @slp's container image)
Should we do this in
krun-guest
?