From 3a389133beee9ce172eb38914284595958f3a981 Mon Sep 17 00:00:00 2001
From: SimonFair <39065407+SimonFair@users.noreply.github.com>
Date: Sun, 13 Apr 2025 20:02:27 +0100
Subject: [PATCH] Initial Commit for Virtual sound cards.
Testing + Helptext still to be completed.
---
.../dynamix.vm.manager/include/libvirt.php | 53 ++++++++++++++-----
.../include/libvirt_helpers.php | 21 ++++++++
.../templates/Custom.form.php | 3 ++
3 files changed, 64 insertions(+), 13 deletions(-)
diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php
index 69f77f5c5..4f8714ed4 100644
--- a/emhttp/plugins/dynamix.vm.manager/include/libvirt.php
+++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt.php
@@ -839,6 +839,7 @@ class Libvirt {
}
}
$audiodevs_used=[];
+ $soundcards = "";
if (!empty($audios)) {
foreach ($audios as $i => $audio) {
$strSpecialAddressAudio = "";
@@ -847,21 +848,28 @@ class Libvirt {
continue;
}
[$audio_bus, $audio_slot, $audio_function] = my_explode(":", str_replace('.', ':', $audio['id']), 3);
- if ($audio_function != 0) {
- if (isset($multidevices[$audio_bus])) {
- $newaudio_bus = $multidevices[$audio_bus];
- if ($machine_type == "pc") $newaudio_slot = "0x01"; else $newaudio_slot = "0x00";
- $strSpecialAddressAudio = "
";
+ if ($audio_bus == "virtual")
+ {
+ $soundcards .= "
+
+ ";
+ } else {
+ if ($audio_function != 0) {
+ if (isset($multidevices[$audio_bus])) {
+ $newaudio_bus = $multidevices[$audio_bus];
+ if ($machine_type == "pc") $newaudio_slot = "0x01"; else $newaudio_slot = "0x00";
+ $strSpecialAddressAudio = "";
+ }
}
+ $pcidevs .= "
+
+
+
+
+ $strSpecialAddressAudio
+ ";
+ $audiodevs_used[] = $audio['id'];
}
- $pcidevs .= "
-
-
-
-
- $strSpecialAddressAudio
- ";
- $audiodevs_used[] = $audio['id'];
}
}
$pcidevs_used=[];
@@ -951,6 +959,7 @@ class Libvirt {
$vmrc
$scsicontroller
+ $soundcards
$pcidevs
$usbstr
@@ -2257,6 +2266,24 @@ class Libvirt {
return ['pci' => $devs_pci, 'usb' => $devs_usb];
}
+ function domain_get_sound_cards($domain) {
+ $soundcardslist = [];
+ $strDOMXML = $this->domain_get_xml($domain);
+ $xmldoc = new DOMDocument();
+ $xmldoc->loadXML($strDOMXML);
+ $xpath = new DOMXPath($xmldoc);
+ $objNodes = $xpath->query('//domain/devices/sound');
+ if ($objNodes->length > 0) {
+ foreach ($objNodes as $objNode) {
+ $soundcardslist[] = [
+ 'model' => $xpath->query('@model', $objNode)->Item(0)->nodeValue
+ ];
+ }
+ }
+ return $soundcardslist;
+ }
+
+
function get_nic_info($domain) {
$macs = $this->get_xpath($domain, "//domain/devices/interface/mac/@address", false);
if (!$macs) return $this->_set_last_error();
diff --git a/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php b/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php
index e5b7be2eb..35461b16a 100644
--- a/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php
+++ b/emhttp/plugins/dynamix.vm.manager/include/libvirt_helpers.php
@@ -971,6 +971,21 @@ class Array2XML {
return $arrValidAudioDevices;
}
+ function getValidSoundCards() {
+ $arrValidSoundCards = [
+ 'ich6' => ['name' => 'ich6','id' => 'virtual::ich6'],
+ 'ich7' => ['name' => 'ich7','id' => 'virtual::ich7'],
+ 'ich9' => ['name' => 'ich9','id' => 'virtual::ich9'],
+ 'ac97' => ['name' => 'ac97','id' => 'virtual::ac97'],
+ 'es1370' => ['name' => 'es1370','id' => 'virtual::es1370'],
+ 'pcspk' => ['name' => 'pcspk','id' => 'virtual::pcspk'],
+ 'sb16' => ['name' => 'sb16','id' => 'virtual::sb16'],
+ 'usb' => ['name' => 'usb','id' => 'virtual::usb'],
+ 'virtio' => ['name' => 'virtio','id' => 'virtual::virtio'],
+ ];
+ return $arrValidSoundCards;
+ }
+
function getValidOtherDevices() {
$arrValidPCIDevices = getValidPCIDevices();
@@ -1277,6 +1292,7 @@ class Array2XML {
$arrNICs = $lv->get_nic_info($res);
$arrHostDevs = $lv->domain_get_host_devices_pci($res);
$arrUSBDevs = $lv->domain_get_host_devices_usb($res);
+ $arrSoundCards = $lv->domain_get_sound_cards($res);
$getcopypaste=getcopypaste($res);
// Metadata Parsing
@@ -1348,6 +1364,10 @@ class Array2XML {
];
}
+ if (!empty($arrSoundCards)) {
+ foreach ($arrSoundCards as $sckey => $soundcard) $arrAudioDevices[] = ['id' => "virtual::".$soundcard['model']];
+ }
+
// Add claimed USB devices by this VM to the available USB devices
/*
foreach($arrUSBDevs as $arrUSB) {
@@ -1532,6 +1552,7 @@ class Array2XML {
unset($old['devices']['input']);
// preserve vnc/spice port settings
// unset($new['devices']['graphics']['@attributes']['port'],$new['devices']['graphics']['@attributes']['autoport']);
+ unset($old['devices']['sound']);
unset($old['devices']['graphics']);
if (!isset($new['devices']['graphics']['@attributes']['keymap']) && isset($old['devices']['graphics']['@attributes']['keymap'])) unset($old['devices']['graphics']['@attributes']['keymap']);
// update parent arrays
diff --git a/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php b/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php
index 432fbfa73..a86e500a6 100644
--- a/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php
+++ b/emhttp/plugins/dynamix.vm.manager/templates/Custom.form.php
@@ -27,6 +27,7 @@ $arrValidMachineTypes = getValidMachineTypes();
$arrValidPCIDevices = getValidPCIDevices();
$arrValidGPUDevices = getValidGPUDevices();
$arrValidAudioDevices = getValidAudioDevices();
+$arrValidSoundCards = getValidSoundCards();
$arrValidOtherDevices = getValidOtherDevices();
$arrValidUSBDevices = getValidUSBDevices();
$arrValidDiskDrivers = getValidDiskDrivers();
@@ -1441,6 +1442,7 @@ foreach ($arrConfig['shares'] as $i => $arrShare) {
echo mk_option($arrAudio['id'], '', _('None'));
foreach ($arrValidAudioDevices as $arrDev) echo mk_option($arrAudio['id'], $arrDev['id'], $arrDev['name'].' ('.$arrDev['id'].')');
+ foreach ($arrValidSoundCards as $arrSound) echo mk_option($arrAudio['id'], $arrSound['id'], $arrSound['name'].' ('._("Virtual").')');
?>
@@ -1466,6 +1468,7 @@ foreach ($arrConfig['shares'] as $i => $arrShare) {