[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH v4 4/5] bhyve: allow to specify host sound device



Allow to map sound playback and recording devices to host devices
using "<audio type='oss'/>" OSS audio backend.

Signed-off-by: Roman Bogorodskiy <bogorodskiy gmail com>
---
 src/bhyve/bhyve_command.c                     | 35 +++++++++++++++++--
 src/conf/domain_conf.c                        | 13 +++++++
 src/conf/domain_conf.h                        |  4 +++
 src/libvirt_private.syms                      |  1 +
 .../bhyvexml2argv-sound.args                  |  2 +-
 .../bhyvexml2argvdata/bhyvexml2argv-sound.xml |  8 ++++-
 .../bhyvexml2xmlout-sound.xml                 |  5 +++
 7 files changed, 63 insertions(+), 5 deletions(-)

diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index 1f42f71347..5289e409fa 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -478,9 +478,12 @@ bhyveBuildGraphicsArgStr(const virDomainDef *def,
 static int
 bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED,
                       virDomainSoundDefPtr sound,
+                      virDomainAudioDefPtr audio,
                       bhyveConnPtr driver,
                       virCommandPtr cmd)
 {
+    g_auto(virBuffer) params = VIR_BUFFER_INITIALIZER;
+
     if (!(bhyveDriverGetBhyveCaps(driver) & BHYVE_CAP_SOUND_HDA)) {
         /* Currently, bhyve only supports "hda" sound devices, so
            if it's not supported, sound devices are not supported at all */
@@ -497,9 +500,33 @@ bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED,
     }
 
     virCommandAddArg(cmd, "-s");
-    virCommandAddArgFormat(cmd, "%d:%d,hda,play=/dev/dsp0",
+
+    if (audio) {
+        switch ((virDomainAudioType) audio->type) {
+        case  VIR_DOMAIN_AUDIO_TYPE_OSS:
+            if (audio->backend.oss.inputDev)
+                virBufferAsprintf(&params, ",play=%s",
+                                  audio->backend.oss.inputDev);
+
+            if (audio->backend.oss.outputDev)
+                virBufferAsprintf(&params, ",rec=%s",
+                                  audio->backend.oss.outputDev);
+
+            break;
+
+        case VIR_DOMAIN_AUDIO_TYPE_LAST:
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("unsupported audio backend '%s'"),
+                           virDomainAudioTypeTypeToString(audio->type));
+            return -1;
+        }
+    }
+
+    virCommandAddArgFormat(cmd, "%d:%d,hda%s",
                            sound->info.addr.pci.slot,
-                           sound->info.addr.pci.function);
+                           sound->info.addr.pci.function,
+                           virBufferCurrentContent(&params));
+
     return 0;
 }
 
@@ -648,7 +675,9 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, virDomainDefPtr def,
     }
 
     for (i = 0; i < def->nsounds; i++) {
-        if (bhyveBuildSoundArgStr(def, def->sounds[i], driver, cmd) < 0)
+        if (bhyveBuildSoundArgStr(def, def->sounds[i],
+                                  virDomainDefFindAudioForSound(def, def->sounds[i]),
+                                  driver, cmd) < 0)
             goto error;
     }
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9c05f301dd..921775edc4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31497,6 +31497,19 @@ virDomainDefFindDevice(virDomainDefPtr def,
 }
 
 
+virDomainAudioDefPtr
+virDomainDefFindAudioForSound(virDomainDefPtr def,
+                              virDomainSoundDefPtr sound)
+{
+    size_t i;
+    for (i = 0; i < def->naudios; i++)
+        if (def->audios[i]->id == sound->audioId)
+            return def->audios[i];
+
+    return NULL;
+}
+
+
 char *
 virDomainObjGetMetadata(virDomainObjPtr vm,
                         int type,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e0827fee74..8a0f26f5c0 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3712,6 +3712,10 @@ int virDomainDefFindDevice(virDomainDefPtr def,
                            virDomainDeviceDefPtr dev,
                            bool reportError);
 
+virDomainAudioDefPtr
+virDomainDefFindAudioForSound(virDomainDefPtr def,
+                              virDomainSoundDefPtr sound);
+
 const char *virDomainChrSourceDefGetPath(virDomainChrSourceDefPtr chr);
 
 void virDomainChrSourceDefClear(virDomainChrSourceDefPtr def);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 35bf9f08ef..f950a68179 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -298,6 +298,7 @@ virDomainDefCheckABIStability;
 virDomainDefCheckABIStabilityFlags;
 virDomainDefCompatibleDevice;
 virDomainDefCopy;
+virDomainDefFindAudioForSound;
 virDomainDefFindDevice;
 virDomainDefFormat;
 virDomainDefFormatConvertXMLFlags;
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-sound.args b/tests/bhyvexml2argvdata/bhyvexml2argv-sound.args
index c242708ff1..05ff4965dd 100644
--- a/tests/bhyvexml2argvdata/bhyvexml2argv-sound.args
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-sound.args
@@ -7,4 +7,4 @@
 -s 0:0,hostbridge \
 -s 2:0,ahci,hd:/tmp/freebsd.img \
 -s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
--s 4:0,hda,play=/dev/dsp0 bhyve
+-s 4:0,hda,play=/dev/dsp0,rec=/dev/dsp0 bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-sound.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-sound.xml
index 8e799301fb..831e8670e7 100644
--- a/tests/bhyvexml2argvdata/bhyvexml2argv-sound.xml
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-sound.xml
@@ -19,6 +19,12 @@
       <source bridge="virbr0"/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
     </interface>
-    <sound model='ich7'/>
+    <sound model='ich7'>
+      <audio id="1"/>
+    </sound>
+    <audio type="oss" id="1">
+      <input dev="/dev/dsp0"/>
+      <output dev="/dev/dsp0"/>
+    </audio>
   </devices>
 </domain>
diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-sound.xml b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-sound.xml
index a64c5da27a..c23892eec9 100644
--- a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-sound.xml
+++ b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-sound.xml
@@ -30,7 +30,12 @@
       <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
     </interface>
     <sound model='ich7'>
+      <audio id='1'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
     </sound>
+    <audio id='1' type='oss'>
+      <input dev='/dev/dsp0'/>
+      <output dev='/dev/dsp0'/>
+    </audio>
   </devices>
 </domain>
-- 
2.27.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]