pulseaudio, in a KVM virtual machine (as root) and your desktop (not root) playing audio at the same time?
You have set probably right the enviroment variables for Qemu like:
QEMU_AUDIO_DRV=pa
but before you set your QEMU_PA_SINK it is neccessary to install package paprefs
this packace contains server-like settings for pulseaudio.
I've check everything on in PulseAudio Preferences but it maybe just the options:
- "Enable network access to local sound devices",
- "Allow other maschines on the LAN to discover local sound devices" and
- "Don't reguire authentication"
which after restart of pulseaudio made combined
source available. As your user then start:
pulseaudio -k
pactl list short sinks
if you are seeing source named combined
you can continue with setting other enviroment variables for Qemu like:
QEMU_PA_SINK=combined
QEMU_PA_SOURCE=input
As last step restart your VM
https://wiki.archlinux.org/index.php/QEMU <- see section Audio https://freedesktop.org/software/pulseaudio/paprefs/
EDIT: Now we have QEMU version 4.0
https://www.redhat.com/archives/libvir-list/2019-February/msg01305.html
then the usual changes in virtual machine xml definition look like
<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
...
<qemu:commandline>
<qemu:arg value='-audiodev'/>
<qemu:arg value='pa,id=pa1,out.name=combined,in.name=input'/>
</qemu:commandline>
</domain>
Related videos on Youtube
Peter
Updated on September 18, 2022Comments
-
Peter over 1 year
How do you get pulseaudio to play sound in a KVM virtual machine (running as root) and your desktop apps (not running as root) at the same time?
It seems that by default, it will only play sound for one user at a time, blocking all others.
For example,
I play some music:
mplayer ~/Music/*
my VM starts with:
kdesu qemu-system-x86_64 -enable-kvm [... disks, network, etc. ...] -soundhw hda
This runs the process as root, with the X display of the user that runs it. And sound doesn't work until mplayer stops.
If run in a root shell instead, I get:
pulseaudio: pa_context_connect() failed pulseaudio: Reason: Connection refused pulseaudio: Failed to initialize PA contextaudio: Could not init `pa' audio driver ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave alsa: Could not initialize DAC alsa: Failed to open `default': alsa: Reason: Device or resource busy ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave alsa: Could not initialize DAC alsa: Failed to open `default': alsa: Reason: Device or resource busy audio: Failed to create voice `dac'
And then the VM runs and its sound device looks like it works, but no sound is played.
Then I can stop mplayer, and then the sound can be played from the VM without restarting it.
Then if I start mplayer again, I get errors and no sound:
AO: [pulse] 44100Hz 2ch s16le (2 bytes per sample) Video: no video Starting playback... A: -0.0 (unknown) of 308.2 (05:08.2) ??,?% Audio device got stuck! A: -0.0 (unknown) of 308.2 (05:08.2) ??,?% Audio device got stuck! A: -0.0 (unknown) of 308.2 (05:08.2) ??,?% Audio device got stuck! A: -0.0 (unknown) of 308.2 (05:08.2) ??,?%
I believe I can solve this by uninstalling pulseaudio and using ALSA instead, but then I need to reconfigure qemu config and build it from source. I would like to do it by configuring pulseaudio instead, like with a software mixer in ALSA.