libvirt: Configure guest to share host audio

15

Solution 1

Okay, after a lot of trial and error I finally managed to get it working as it should, without any hiccups.

Some of the following steps might not be required in order to make it work, but it did work for me after making them. If someone wants to modify the answer and get rid of the unnecessary steps then please do it.

Besides what I said above when using VNC (changing the settings in qemu.conf & libvirt-bin and making sure my user was part of the required groups) I also made sure my user was part of the pulse & pulse-access groups.

I copied everything from /etc/pulse in .pulse my home directory:

cd ~
mkdir .pulse
cp /etc/pulse/* .pulse/

In ~/.pulse/client.conf I commented/modified the following lines:

enable-shm = yes
auto-connect-localhost = yes
auto-connect-display = yes

In ~/.pulse/daemon.conf

daemonize = yes
allow-module-loading = yes
use-pid-file = yes
enable-shm = yes

Also I installed paprefs (apt-get install paprefs) and checked:

  • Make discoverable PulseAudio network sound devices available locally
  • Enable network access to local sound devices
  • Don't require authnetication
  • Enable Multicast/RTP reciever
  • Add virtual output device for simultaneous output on all local sound cards

After you made all the changes you can reboot you computer or just logout/login and restart libvirt-bin and everything should work perfectly when you start a VM.

PS: If the audio from the VM is crackling then make sure the VM has the same sample rate and bit depth as the host and it should work.

Update: It became apparent to me that the audio can still have issues in the guest (carckling sound) because libvirt may not be able to load the pulse config, from what i saw in the domain logfile(/var/log/libvirt/qemu/yourdomain.log). You can disable the profile temporarily or just add:

@{HOME}/.pulse/** rw,

in /etc/apparmor.d/abstractions/libvirt-qemu and reload the apparmor profiles with:

sudo invoke-rc.d apparmor reload

Note: I configured libvirt to run as my current user in /etc/libvirt/qemu.conf for security reasons.

Solution 2

This is a bit old, but maybe will save time for somebody walking around this. What worked for me was to configure unix socket and use global pulseaudio config instead of TCP connection module-native-protocol-tcp specified for user as most of the online guides suggest.

I think the pulseaudio was not picking up the individual user, for whatever reason. So I ended up editing pulseaudio config in /etc.

I edited /etc/pulse/default.pa with line:

load-module module-native-protocol-unix auth-anonymous=1 socket=/tmp/system-pulseaudio.socket

In /etc/pulse/client.conf I added line:

default-server = unix:/tmp/system-pulseaudio.socket
Share:
15

Related videos on Youtube

Declan O'Hare
Author by

Declan O'Hare

Updated on September 18, 2022

Comments

  • Declan O'Hare
    Declan O'Hare over 1 year

    I am trying to create a simple sign up function for a website. I get the error above when I click enter after filling out the sign up form. I believe the error refers to the following lines of code, specifically filtering on the $_POST function. Any help would be appreciated. See code below:

    <?php 
     include("connection/conn.php");
     include("connection/showerrors.php");
     session_start();
    
     // initializing variables
     $StudentName = "";
     $StudentEmail = "";
     $errors = array(); 
    
     // REGISTER USER
     if (isset($_POST['reg_user'])) {
      // receive all input values from the form
     $StudentName = mysqli_real_escape_string ($conn, $_POST['StudentName']);
     $password_1 = mysqli_real_escape_string ($conn, $_POST['password_1']);
     $password_2 = mysqli_real_escape_string ($conn, $_POST['password_2']);
     $StudentEmail = mysqli_real_escape_string ($conn, $_POST['StudentEmail']);
    
  • Muhammad bin Yusrat
    Muhammad bin Yusrat over 4 years
    What was the sound device that you added to your VM's config?
  • MrWm
    MrWm almost 3 years
    What does auth-anonymous=1 do? Where can I find out more on this in the man pages?
  • Ludo
    Ludo over 2 years
    @MrWm i assume it turns off some kind of auth in pulseaudio, not much concern since i don't let it open any port to outside