[pve-devel] [PATCH qemu-server 1/3] Add audio device support

Aaron Lauterer a.lauterer at proxmox.com
Wed Jul 17 15:58:57 CEST 2019


Until now audio devices had to be added manually with the `args` option
in the VMs config file. This adds a new config option to define an audio
device. It is called `audio0` with the extra `0` to be prepared should
we ever implement support for more than one audio device.

Supported devices are:

* ich9-intel-hda: Intel HD Audio Controller, emulates ICH9
* intel-hda: Intel HD Audio Controller, emulates ICH6
* AC97: useful for older OSs like Win XP

If any of the `intel-hda`s is selected two additional devices will be
created: hda-micro and hda-duplex. The `*intel-hda` controllers need at
least one of them as they emulate microphones and speakers (hda-micro)
or line in and out devices (hda-duplex).

Having both is deemed best practice to avoid problems if some software
needs one of the other kind of output/input ports.

I also cleaned up some old, commented out, code regarding audio devices.

Signed-off-by: Aaron Lauterer <a.lauterer at proxmox.com>
---
 PVE/QemuServer.pm | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 9f29927..7264116 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -637,7 +637,13 @@ EODESCR
 	format => $ivshmem_fmt,
 	description => "Inter-VM shared memory. Useful for direct communication between VMs, or to the host.",
 	optional => 1,
-    }
+    },
+    audio0 => {
+	type => 'string',
+	enum => [qw(ich9-intel-hda intel-hda AC97)],
+	description => "Configure a audio device.",
+	optional => 1
+    },
 };
 
 my $cicustom_fmt = {
@@ -3780,6 +3786,18 @@ sub config_to_command {
 	}
     }
 
+    if ($conf->{"audio0"}) {
+	my $audiodevice = $conf->{audio0};
+	my $audiopciaddr = print_pci_addr("audio0", $bridges, $arch, $machine_type);
+
+	if ($audiodevice eq 'AC97') {
+	    push @$devices, '-device', "AC97,id=sound0${audiopciaddr}";
+	} else {
+	    push @$devices, '-device', "${audiodevice},id=sound5${audiopciaddr}";
+	    push @$devices, '-device', "hda-micro,id=sound5-codec0,bus=sound5.0,cad=0";
+	    push @$devices, '-device', "hda-duplex,id=sound5-codec1,bus=sound5.0,cad=1";
+	}
+    }
 
     my $sockets = 1;
     $sockets = $conf->{smp} if $conf->{smp}; # old style - no longer iused
@@ -3877,11 +3895,6 @@ sub config_to_command {
 
     push @$cmd, '-k', $conf->{keyboard} if defined($conf->{keyboard});
 
-    # enable sound
-    #my $soundhw = $conf->{soundhw} || $defaults->{soundhw};
-    #push @$cmd, '-soundhw', 'es1370';
-    #push @$cmd, '-soundhw', $soundhw if $soundhw;
-
     if (parse_guest_agent($conf)->{enabled}) {
 	my $qgasocket = qmp_socket($vmid, 1);
 	my $pciaddr = print_pci_addr("qga0", $bridges, $arch, $machine_type);
-- 
2.20.1





More information about the pve-devel mailing list