]> git.proxmox.com Git - qemu-server.git/commitdiff
audio follouwp: pull out parsing into a conf_has_audio
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 23 Jul 2019 16:09:32 +0000 (18:09 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 23 Jul 2019 16:14:09 +0000 (18:14 +0200)
now that we finally now what the ID from the audiodev is for let's
factor some format string parsing out making a eventual future multi
audio device support with differen backends quite easy to support
here - once QEMU itself supports that fully.[0][1]

[0]: https://pve.proxmox.com/pipermail/pve-devel/2019-July/038400.html
[1]: https://lists.nongnu.org/archive/html/qemu-devel/2019-07/msg03583.html

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/QemuServer.pm

index 568dc5c6f1e9227a246dbd7a76343922f2a42fdd..c346af2cc1c5105d7288cca52acab0b0990dc898 100644 (file)
@@ -3413,6 +3413,24 @@ sub conf_has_serial {
     return 0;
 }
 
+sub conf_has_audio {
+    my ($conf, $id) = @_;
+
+    $id //= 0;
+    my $audio = $conf->{"audio$id"};
+    return undef if !defined($audio);
+
+    my $audioproperties = PVE::JSONSchema::parse_property_string($audio_fmt, $audio);
+    my $audiodriver = $audioproperties->{driver} // 'spice';
+
+    return {
+       dev => $audioproperties->{device},
+       dev_id => "audio$id",
+       backend => $audiodriver,
+       backend_id => "$audiodriver-backend${id}",
+    };
+}
+
 sub vga_conf_has_spice {
     my ($vga) = @_;
 
@@ -3801,23 +3819,22 @@ sub config_to_command {
        }
     }
 
-    if ($conf->{audio0}) {
-       my $audioproperties = PVE::JSONSchema::parse_property_string($audio_fmt, $conf->{audio0});
-       my $audiodevice = $audioproperties->{device};
-       my $audiodriver = $audioproperties->{driver} // 'spice';
+    if (my $audio = conf_has_audio($conf)) {
+
        my $audiopciaddr = print_pci_addr("audio0", $bridges, $arch, $machine_type);
 
-       if ($audiodevice eq 'AC97') {
-           push @$devices, '-device', "AC97,id=sound0${audiopciaddr}";
-       } elsif ($audiodevice =~ /intel\-hda$/) {
-           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 $id = $audio->{dev_id};
+       if ($audio->{dev} eq 'AC97') {
+           push @$devices, '-device', "AC97,id=${id}${audiopciaddr}";
+       } elsif ($audio->{dev} =~ /intel\-hda$/) {
+           push @$devices, '-device', "$audio->{dev},id=${id}${audiopciaddr}";
+           push @$devices, '-device', "hda-micro,id=${id}-codec0,bus=${id}.0,cad=0";
+           push @$devices, '-device', "hda-duplex,id=${id}-codec1,bus=${id}.0,cad=1";
        } else {
-           die "unkown audio device '$audiodevice', implement me!";
+           die "unkown audio device '$audio->{dev}', implement me!";
        }
 
-       push @$devices, '-audiodev', "${audiodriver},id=${audiodriver}-driver";
+       push @$devices, '-audiodev', "$audio->{backend},id=$audio->{backend_id}";
     }
 
     my $sockets = 1;