]> git.proxmox.com Git - qemu-server.git/commitdiff
Add audio device support
authorAaron Lauterer <a.lauterer@proxmox.com>
Wed, 17 Jul 2019 13:58:57 +0000 (15:58 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 18 Jul 2019 06:24:39 +0000 (08:24 +0200)
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@proxmox.com>
PVE/QemuServer.pm

index 9f29927ffa20d907bf4cdb26a736966019893391..72641162f694526999a5eaed3e4e2f4d7b27c0d1 100644 (file)
@@ -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);