[libvirt PATCH 06/18] conf: refactor OSS audio backend specific options

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

 



To prepare for the introduction for more backend specific audio options,
move the OSS options into a dedicated struct and introduce separate
helper methods for parse/format/free.

Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx>
---
 docs/schemas/domaincommon.rng | 17 +++++---
 src/bhyve/bhyve_command.c     |  8 ++--
 src/conf/domain_conf.c        | 77 ++++++++++++++++++++++++++---------
 src/conf/domain_conf.h        |  9 +++-
 4 files changed, 79 insertions(+), 32 deletions(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index d73db65742..efa1806a3a 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -4513,6 +4513,15 @@
       </interleave>
     </element>
   </define>
+
+  <define name="audiooss">
+    <optional>
+      <attribute name="dev">
+        <ref name="filePath"/>
+      </attribute>
+    </optional>
+  </define>
+
   <define name="audio">
     <element name="audio">
       <attribute name="id">
@@ -4526,16 +4535,12 @@
       <interleave>
         <optional>
           <element name="input">
-            <attribute name="dev">
-              <ref name="deviceName"/>
-            </attribute>
+            <ref name="audiooss"/>
           </element>
         </optional>
         <optional>
           <element name="output">
-            <attribute name="dev">
-              <ref name="deviceName"/>
-            </attribute>
+            <ref name="audiooss"/>
           </element>
         </optional>
       </interleave>
diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c
index a963338654..e60a6bd393 100644
--- a/src/bhyve/bhyve_command.c
+++ b/src/bhyve/bhyve_command.c
@@ -514,13 +514,13 @@ bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED,
     if (audio) {
         switch ((virDomainAudioType) audio->type) {
         case  VIR_DOMAIN_AUDIO_TYPE_OSS:
-            if (audio->backend.oss.inputDev)
+            if (audio->backend.oss.input.dev)
                 virBufferAsprintf(&params, ",play=%s",
-                                  audio->backend.oss.inputDev);
+                                  audio->backend.oss.input.dev);
 
-            if (audio->backend.oss.outputDev)
+            if (audio->backend.oss.output.dev)
                 virBufferAsprintf(&params, ",rec=%s",
-                                  audio->backend.oss.outputDev);
+                                  audio->backend.oss.output.dev);
 
             break;
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 34d1673546..d5969c79a0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2889,15 +2889,22 @@ void virDomainSoundDefFree(virDomainSoundDefPtr def)
     g_free(def);
 }
 
-void virDomainAudioDefFree(virDomainAudioDefPtr def)
+static void
+virDomainAudioIOOSSFree(virDomainAudioIOOSS *def)
+{
+    g_free(def->dev);
+}
+
+void
+virDomainAudioDefFree(virDomainAudioDefPtr def)
 {
     if (!def)
         return;
 
     switch ((virDomainAudioType) def->type) {
     case VIR_DOMAIN_AUDIO_TYPE_OSS:
-        g_free(def->backend.oss.inputDev);
-        g_free(def->backend.oss.outputDev);
+        virDomainAudioIOOSSFree(&def->backend.oss.input);
+        virDomainAudioIOOSSFree(&def->backend.oss.output);
         break;
 
     case VIR_DOMAIN_AUDIO_TYPE_LAST:
@@ -13863,6 +13870,16 @@ virDomainSoundDefFind(const virDomainDef *def,
 }
 
 
+static int
+virDomainAudioOSSParse(virDomainAudioIOOSS *def,
+                       xmlNodePtr node)
+{
+    def->dev = virXMLPropString(node, "dev");
+
+    return 0;
+}
+
+
 static virDomainAudioDefPtr
 virDomainAudioDefParseXML(virDomainXMLOptionPtr xmlopt G_GNUC_UNUSED,
                           xmlNodePtr node G_GNUC_UNUSED,
@@ -13872,6 +13889,7 @@ virDomainAudioDefParseXML(virDomainXMLOptionPtr xmlopt G_GNUC_UNUSED,
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     g_autofree char *tmp = NULL;
     g_autofree char *type = NULL;
+    xmlNodePtr inputNode, outputNode;
 
     def = g_new0(virDomainAudioDef, 1);
     ctxt->node = node;
@@ -13902,19 +13920,16 @@ virDomainAudioDefParseXML(virDomainXMLOptionPtr xmlopt G_GNUC_UNUSED,
         goto error;
     }
 
-    switch ((virDomainAudioType) def->type) {
-    case VIR_DOMAIN_AUDIO_TYPE_OSS: {
-        xmlNodePtr inputDevNode, outputDevNode;
-
-        inputDevNode = virXPathNode("./input", ctxt);
-        outputDevNode = virXPathNode("./output", ctxt);
+    inputNode = virXPathNode("./input", ctxt);
+    outputNode = virXPathNode("./output", ctxt);
 
-        if (inputDevNode)
-            def->backend.oss.inputDev = virXMLPropString(inputDevNode, "dev");
-        if (outputDevNode)
-            def->backend.oss.outputDev = virXMLPropString(outputDevNode, "dev");
+    switch ((virDomainAudioType) def->type) {
+    case VIR_DOMAIN_AUDIO_TYPE_OSS:
+        if (inputNode)
+            virDomainAudioOSSParse(&def->backend.oss.input, inputNode);
+        if (outputNode)
+            virDomainAudioOSSParse(&def->backend.oss.output, outputNode);
         break;
-    }
 
     case VIR_DOMAIN_AUDIO_TYPE_LAST:
         break;
@@ -26381,11 +26396,34 @@ virDomainSoundDefFormat(virBufferPtr buf,
 }
 
 
+static void
+virDomainAudioCommonFormat(virBufferPtr childBuf,
+                           virBufferPtr backendAttrBuf,
+                           const char *direction)
+{
+    if (virBufferUse(backendAttrBuf)) {
+        virBufferAsprintf(childBuf, "<%s", direction);
+        virBufferAdd(childBuf, virBufferCurrentContent(backendAttrBuf), -1);
+        virBufferAddLit(childBuf, "/>\n");
+    }
+}
+
+
+static void
+virDomainAudioOSSFormat(virDomainAudioIOOSS *def,
+                        virBufferPtr buf)
+{
+    virBufferEscapeString(buf, " dev='%s'", def->dev);
+}
+
+
 static int
 virDomainAudioDefFormat(virBufferPtr buf,
                         virDomainAudioDefPtr def)
 {
     g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
+    g_auto(virBuffer) inputBuf = VIR_BUFFER_INITIALIZER;
+    g_auto(virBuffer) outputBuf = VIR_BUFFER_INITIALIZER;
     const char *type = virDomainAudioTypeTypeToString(def->type);
 
     if (!type) {
@@ -26398,15 +26436,14 @@ virDomainAudioDefFormat(virBufferPtr buf,
 
     switch (def->type) {
     case VIR_DOMAIN_AUDIO_TYPE_OSS:
-        if (def->backend.oss.inputDev)
-            virBufferAsprintf(&childBuf, "<input dev='%s'/>\n",
-                              def->backend.oss.inputDev);
-        if (def->backend.oss.outputDev)
-            virBufferAsprintf(&childBuf, "<output dev='%s'/>\n",
-                              def->backend.oss.outputDev);
+        virDomainAudioOSSFormat(&def->backend.oss.input, &inputBuf);
+        virDomainAudioOSSFormat(&def->backend.oss.output, &outputBuf);
         break;
     }
 
+    virDomainAudioCommonFormat(&childBuf, &inputBuf, "input");
+    virDomainAudioCommonFormat(&childBuf, &outputBuf, "output");
+
     if (virBufferUse(&childBuf)) {
         virBufferAddLit(buf, ">\n");
         virBufferAddBuffer(buf, &childBuf);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 8f2e559884..977dd48cc3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1451,6 +1451,11 @@ typedef enum {
     VIR_DOMAIN_AUDIO_TYPE_LAST
 } virDomainAudioType;
 
+typedef struct _virDomainAudioIOOSS virDomainAudioIOOSS;
+struct _virDomainAudioIOOSS {
+    char *dev;
+};
+
 struct _virDomainAudioDef {
     int type;
 
@@ -1458,8 +1463,8 @@ struct _virDomainAudioDef {
 
     union {
         struct {
-            char *inputDev;
-            char *outputDev;
+            virDomainAudioIOOSS input;
+            virDomainAudioIOOSS output;
         } oss;
     } backend;
 };
-- 
2.29.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux