Bug 1788807 - [RFE] Add qemu -audiodev support to libvirt
Summary: [RFE] Add qemu -audiodev support to libvirt
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: libvirt
Version: ---
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: 8.0
Assignee: Daniel Berrangé
QA Contact: Lili Zhu
URL:
Whiteboard:
Depends On: 1983493
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-01-08 07:15 UTC by Gerd Hoffmann
Modified: 2021-11-16 07:52 UTC (History)
12 users (show)

Fixed In Version: libvirt-7.3.0-1.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-11-16 07:49:56 UTC
Type: Feature Request
Target Upstream Version: 7.2.0
Embargoed:


Attachments (Terms of Use)

Description Gerd Hoffmann 2020-01-08 07:15:56 UTC
Background:
https://www.kraxel.org/blog/2020/01/qemu-sound-audiodev/

First chunk of patches has been merged for qemu 4.0.
Full support has been merged for 4.2.
I'd suggest to bother with 4.2+ only.

Feature detection:  Full -audiodev support is visible via qapi inspection as all sound devices all got a new audiodev property.

Comment 2 Peter Krempa 2021-04-09 11:26:19 UTC
Implemented upstream by:

16634feb1d qemu: wire up support for backend specific audio settings
3e97d81a81 conf: add support for audio backend specific settings
c99e72d18d qemu: wire up support for common audio backend settings
46b77b3e6a conf: introduce support for common audio settings
d96fb5cb31 qemu: add support for generating -audiodev arguments
e07994aade qemu: probe for -vnc audiodev property
e88367095f qemu: populate <audio> element with default config
6be99c99c5 qemu: support use of <audio> elements
efdab67f44 conf: rename and improve virDomainDefFindAudioForSound
562a495b92 conf: add validation of audio backend IDs
cf1c5c6344 conf: add support for audio backend for the VNC server
915b637257 conf: add coverage for all QEMU audio backend types
8149518ee1 conf: refactor OSS audio backend specific options
d0ae9b429a conf: add missing iteration over audio backends
657999b04f conf: add helper to test for sound device codec support
fe304b02f0 conf: don't force existance of audio child elements
d6b79a64e6 conf: stronger error reporting when parsing audio related params

v7.1.0-167-g16634feb1d

Comment 5 Lili Zhu 2021-06-22 03:51:17 UTC
Tested with:
libvirt-daemon-7.4.0-1.module+el8.5.0+11218+83343022.x86_64
qemu-kvm-6.0.0-19.module+el8.5.0+11385+6e7d542e.x86_64

1. prepare a guest with the following xml
...
  <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <audio id='1' type='pulseaudio'>
      <input mixingEngine='yes' fixedSettings='yes' voices='1' bufferLength='100'>
        <settings frequency='44100' channels='2' format='s16'/>
      </input>
      <output mixingEngine='yes' fixedSettings='yes' voices='2' bufferLength='100'>
        <settings frequency='22050' channels='4' format='f32'/>
      </output>
    </audio>
...

2. start the guest
# virsh start avocado-vt-vm1
Domain 'avocado-vt-vm1' started

3. check the qemu cmd line
...
-audiodev id=audio1,driver=pa,in.mixing-engine=on,in.fixed-settings=on,in.voices=1,in.buffer-length=100,in.frequency=44100,in.channels=2,in.format=s16,out.mixing-engine=on,out.fixed-settings=on,out.voices=2,out.buffer-length=100,out.frequency=22050,out.channels=4,out.format=f32 -vnc 0.0.0.0:1,audiodev=audio1
...

4. login into the guest, play a audio file
Can not hear any sound

Comment 6 Lili Zhu 2021-06-28 03:09:09 UTC
Tested again with:
libvirt-daemon-7.4.0-1.module+el8.5.0+11218+83343022.x86_64
qemu-kvm-6.0.0-21.module+el8.5.0+11555+e0ab0d09.x86_64

1. prepare a guest using non-root account with the following xml
...
  <graphics type='vnc' port='-1' autoport='yes' listen='0.0.0.0'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <audio id='1' type='pulseaudio'>
      <input mixingEngine='yes' fixedSettings='yes' voices='1' bufferLength='100'>
        <settings frequency='44100' channels='2' format='s16'/>
      </input>
      <output mixingEngine='yes' fixedSettings='yes' voices='2' bufferLength='100'>
        <settings frequency='22050' channels='4' format='f32'/>
      </output>
    </audio>
...

2. start the guest
$ virsh start avocado-vt-vm1
Domain 'avocado-vt-vm1' started

3. check the qemu cmd line
...
-audiodev id=audio1,driver=pa,in.mixing-engine=on,in.fixed-settings=on,in.voices=1,in.buffer-length=100,in.frequency=44100,in.channels=2,in.format=s16,out.mixing-engine=on,out.fixed-settings=on,out.voices=2,out.buffer-length=100,out.frequency=22050,out.channels=4,out.format=f32 -vnc 0.0.0.0:1,audiodev=audio1
...

4. check the pulseaudio daemon
$ systemctl --user status pulseaudio
● pulseaudio.service - Sound Service
   Loaded: loaded (/usr/lib/systemd/user/pulseaudio.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2021-06-28 10:23:05 CST; 42min ago
 Main PID: 2290 (pulseaudio)
   CGroup: /user.slice/user-1000.slice/user/pulseaudio.service
           └─2290 /usr/bin/pulseaudio --daemonize=no --log-target=journal

Jun 28 10:23:05 192.168.122.1 systemd[2269]: Starting Sound Service...
Jun 28 10:23:05 192.168.122.1 systemd[2269]: Started Sound Service.

5. login the guest, using vlc to play some audio file
(can not hear any sound)

Comment 7 Lili Zhu 2021-06-28 03:30:08 UTC
Hi, 

Additional Info:
1. $ lspci |grep -i audio
00:1f.3 Audio device: Intel Corporation Sunrise Point-LP HD Audio (rev 21)

2. I used the no-root account for starting the guest, since
# pulseaudio 
W: [pulseaudio] main.c: This program is not intended to be run as root (unless --system is specified).
W: [pulseaudio] authkey.c: Failed to open cookie file '/root/.config/pulse/cookie': No such file or directory
...

3. I checked the build file of qemu-kvm-6.0.0-21.module+el8.5.0+11555+e0ab0d09.x86_64
....
qemu 6.0.0
  Directories
                   Install prefix: /usr
                   BIOS directory: share/qemu-kvm
                    firmware path: /usr/share/qemu-firmware
                 binary directory: bin
                library directory: lib64
                 module directory: lib64/qemu-kvm
                libexec directory: libexec
                include directory: include
                 config directory: /etc
            local state directory: /var
                 Manual directory: share/man
                    Doc directory: /usr/share/doc
                  Build directory: /builddir/build/BUILD/qemu-6.0.0/qemu_kvm_build
                      Source path: /builddir/build/BUILD/qemu-6.0.0
                   GIT submodules: 
  Host binaries
                              git: git
                             make: make
                           python: /usr/libexec/platform-python (version: 3.6)
                     sphinx-build: YES
                      genisoimage: 
                             smbd: "/usr/sbin/smbd"
  Configurable features
                    Documentation: YES
            system-mode emulation: YES
              user-mode emulation: NO

                      block layer: YES
                    Install blobs: YES
                   module support: YES
          alternative module path: NO
                   plugin support: NO
                  fuzzing support: NO
                    Audio drivers:
                   Trace backends: dtrace
                    QOM debugging: NO

There is no Audio drivers here. I do not know whether this is reason that I can not hear any sound in Comment 6.
If it is not the case, please help to check whether there is some problem with the configuration in Comment 6.
Thanks very much.

Comment 8 Jaroslav Suchanek 2021-07-12 07:52:42 UTC
Gerd, can you please check the config in comment 6? Do you see any issues there? Can you please suggest steps, how this feature can be verified? Thanks a lot.

Comment 9 Daniel Berrangé 2021-07-12 12:33:06 UTC
(In reply to Lili Zhu from comment #7)
> 3. I checked the build file of
> qemu-kvm-6.0.0-21.module+el8.5.0+11555+e0ab0d09.x86_64
> ....
> qemu 6.0.0
>   Directories
>                    Install prefix: /usr
>                    BIOS directory: share/qemu-kvm
>                     firmware path: /usr/share/qemu-firmware
>                  binary directory: bin
>                 library directory: lib64
>                  module directory: lib64/qemu-kvm
>                 libexec directory: libexec
>                 include directory: include
>                  config directory: /etc
>             local state directory: /var
>                  Manual directory: share/man
>                     Doc directory: /usr/share/doc
>                   Build directory:
> /builddir/build/BUILD/qemu-6.0.0/qemu_kvm_build
>                       Source path: /builddir/build/BUILD/qemu-6.0.0
>                    GIT submodules: 
>   Host binaries
>                               git: git
>                              make: make
>                            python: /usr/libexec/platform-python (version:
> 3.6)
>                      sphinx-build: YES
>                       genisoimage: 
>                              smbd: "/usr/sbin/smbd"
>   Configurable features
>                     Documentation: YES
>             system-mode emulation: YES
>               user-mode emulation: NO
> 
>                       block layer: YES
>                     Install blobs: YES
>                    module support: YES
>           alternative module path: NO
>                    plugin support: NO
>                   fuzzing support: NO
>                     Audio drivers:
>                    Trace backends: dtrace
>                     QOM debugging: NO
> 
> There is no Audio drivers here. I do not know whether this is reason that I
> can not hear any sound in Comment 6.

Yes, RHEL builds with

  --audio-drv-list= \

which removes all the optional audio drivers.

IIUC, that means only the basic "none", and "spice" audio drivers will remain.

If you look at the libvirt logfile for the VM you launched, I expect you'll see a line like

audio: Unknown audio driver `pa'
audio: warning: Using timer based audio emulation


Can you confirm this.  If so, then I'd argue this is a QEMU bug. If the request audio can't be configure it should be a fatal error

Comment 10 Lili Zhu 2021-07-13 06:49:26 UTC
(In reply to Daniel Berrangé from comment #9)
> (In reply to Lili Zhu from comment #7)
> > 3. I checked the build file of
> > qemu-kvm-6.0.0-21.module+el8.5.0+11555+e0ab0d09.x86_64
> > ....
> > qemu 6.0.0
> >   Directories
> >                    Install prefix: /usr
> >                    BIOS directory: share/qemu-kvm
> >                     firmware path: /usr/share/qemu-firmware
> >                  binary directory: bin
> >                 library directory: lib64
> >                  module directory: lib64/qemu-kvm
> >                 libexec directory: libexec
> >                 include directory: include
> >                  config directory: /etc
> >             local state directory: /var
> >                  Manual directory: share/man
> >                     Doc directory: /usr/share/doc
> >                   Build directory:
> > /builddir/build/BUILD/qemu-6.0.0/qemu_kvm_build
> >                       Source path: /builddir/build/BUILD/qemu-6.0.0
> >                    GIT submodules: 
> >   Host binaries
> >                               git: git
> >                              make: make
> >                            python: /usr/libexec/platform-python (version:
> > 3.6)
> >                      sphinx-build: YES
> >                       genisoimage: 
> >                              smbd: "/usr/sbin/smbd"
> >   Configurable features
> >                     Documentation: YES
> >             system-mode emulation: YES
> >               user-mode emulation: NO
> > 
> >                       block layer: YES
> >                     Install blobs: YES
> >                    module support: YES
> >           alternative module path: NO
> >                    plugin support: NO
> >                   fuzzing support: NO
> >                     Audio drivers:
> >                    Trace backends: dtrace
> >                     QOM debugging: NO
> > 
> > There is no Audio drivers here. I do not know whether this is reason that I
> > can not hear any sound in Comment 6.
> 
> Yes, RHEL builds with
> 
>   --audio-drv-list= \
> 
> which removes all the optional audio drivers.
> 
> IIUC, that means only the basic "none", and "spice" audio drivers will
> remain.
> 
> If you look at the libvirt logfile for the VM you launched, I expect you'll
> see a line like
> 
> audio: Unknown audio driver `pa'
> audio: warning: Using timer based audio emulation
> 
> 
> Can you confirm this.  If so, then I'd argue this is a QEMU bug. If the
> request audio can't be configure it should be a fatal error

Yes, you are right.
check the log
$ cat /home/lizhu/.cache/libvirt/qemu/log/avocado-vt-vm1.log
...
audio: Unknown audio driver `pa'
audio: warning: Using timer based audio emulation
...
Filed a qemu-kvm Bug #1981663

Comment 11 Guo, Zhiyi 2021-07-14 15:03:35 UTC
I'm able to enable the audio drivers using upstream qemu on via "./configure --target-list=x86_64-softmmu --audio-drv-list='oss alsa pa'" on my rhel8.5 machine. Now I'm experiencing the audio backends, will give a summary about my test tomorrow.

Zhiyi

Comment 18 Lili Zhu 2021-07-28 07:29:32 UTC
Thanks very much for Zhiyi and Daniel's clarification, verify this bug with:
libvirt-daemon-7.5.0-1.module+el8.5.0+11664+59f87560.x86_64
qemu-kvm-6.0.0-24.module+el8.5.0+11844+1e3017bd.x86_64

A. spice audio driver
1. Prepare a guest with following xml
...
 <graphics type='spice' port='5900' autoport='yes' listen='0.0.0.0'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <sound model='ich9'>
      <audio id='2'/>
      <alias name='sound0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </sound>
    <audio id='2' type='spice' timerPeriod='40'>
      <input mixingEngine='yes' fixedSettings='yes' voices='1' bufferLength='100'>
        <settings frequency='44100' channels='2' format='s16'/>
      </input>
      <output mixingEngine='yes' fixedSettings='yes' voices='1' bufferLength='100'>
        <settings frequency='22050' channels='4' format='f32'/>
      </output>
    </audio>
...

2. Start the guest( with graphical desktop installed)
# virsh start avocado-vt-vm1
Domain 'avocado-vt-vm1' started

3. Check the qemu cmd line
# ps aux |grep audio
qemu      268704  5.8 14.4 2890928 1067572 ?     Sl   10:28   0:37 /usr/libexec/qemu-kvm -name guest=avocado-vt-vm1
...
-audiodev id=audio2,driver=spice,timer-period=40,in.mixing-engine=on,in.fixed-settings=on,in.voices=1,in.buffer-length=100,in.frequency=44100,in.channels=2,in.format=s16,out.mixing-engine=on,out.fixed-settings=on,out.voices=1,out.buffer-length=100,out.frequency=22050,out.channels=4,out.format=f32 
-spice port=5900,addr=0.0.0.0,disable-ticketing=on,seamless-migration=on
-device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0,audiodev=audio2
...

4. Login the guest with remote-viewer, play an audio file, can hear the audio

B. none audio driver
1. Prepare a guest with following xml
...
   <graphics type='vnc' port='5900' autoport='yes' listen='0.0.0.0'>
      <listen type='address' address='0.0.0.0'/>
    </graphics>
    <sound model='ich9'>
      <audio id='1'/>
      <alias name='sound0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </sound>
    <audio id='1' type='none' timerPeriod='40'>
      <output mixingEngine='yes' fixedSettings='yes' voices='2' bufferLength='100'>
        <settings frequency='22050' channels='4' format='f32'/>
      </output>
    </audio>
...

2. Start the guest, check the guest
# virsh list --all
 Id   Name             State
--------------------------------
 1    avocado-vt-vm1   running

3. Check qemu cmd line
# ps aux |grep audio
qemu      276303  160 13.5 2304132 1001912 ?     Sl   15:09   0:27 /usr/libexec/qemu-kvm -name guest=avocado-vt-vm1
...
-audiodev id=audio2,driver=none,timer-period=40,out.mixing-engine=on,out.fixed-settings=on,out.voices=1,out.buffer-length=100,out.frequency=22050,out.channels=4,out.format=f32 
-vnc 0.0.0.0:0,audiodev=audio2 -device virtio-vga,id=video0,max_outputs=1,bus=pci.0,addr=0x2 
-device ich9-intel-hda,id=sound0,bus=pci.0,addr=0x9 
-device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0,audiodev=audio2
...

C. For other audio drivers, as this qemu-kvm only support:
# /usr/libexec/qemu-kvm -audio-help
Environment variable based configuration deprecated.
Please use the new -audiodev option.

Equivalent -audiodev to your current environment variables:
(Since you didn't specify QEMU_AUDIO_DRV, I'll list all possibilities)
-audiodev id=none,driver=none

When configure guest with other audio drivers,
<audio id='2' type='pulseaudio' timerPeriod='40'>
      <output mixingEngine='yes' fixedSettings='yes' voices='1' bufferLength='100'>
        <settings frequency='22050' channels='4' format='f32'/>
      </output>
    </audio>

Then start the guest, check the qemu log
$ cat /var/log/libvirt/qemu/avocado-vt-vm1.log
...
audio: Unknown audio driver `pa'
audio: warning: Using timer based audio emulation
...

For this issue, please refer to Bug #1983493

As now the testing result shows, -audiodev is supported in libvirt, mark the bug as verified.

Comment 19 Klaus Heinrich Kiwi 2021-08-25 17:29:18 UTC
(In reply to Lili Zhu from comment #18)
> When configure guest with other audio drivers,
> <audio id='2' type='pulseaudio' timerPeriod='40'>
>       <output mixingEngine='yes' fixedSettings='yes' voices='1'
> bufferLength='100'>
>         <settings frequency='22050' channels='4' format='f32'/>
>       </output>
>     </audio>
> 
> Then start the guest, check the qemu log
> $ cat /var/log/libvirt/qemu/avocado-vt-vm1.log
> ...
> audio: Unknown audio driver `pa'
> audio: warning: Using timer based audio emulation
> ...
> 


Based on the above, I created an RFE to actually enable pulseaudio: Bug 1997725

Comment 21 errata-xmlrpc 2021-11-16 07:49:56 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (virt:av bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:4684


Note You need to log in before you can comment on or make changes to this bug.