]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: add support for audio backend for the VNC server
authorDaniel P. Berrangé <berrange@redhat.com>
Wed, 24 Feb 2021 17:19:55 +0000 (17:19 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Tue, 9 Mar 2021 22:58:18 +0000 (22:58 +0000)
When there are multiple <audio> backends specified, it is possible to
assign a specific one to the VNC server using

  <graphics type='vnc'...>
    <audio id='1'/>
  </graphics>

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
docs/formatdomain.rst
docs/schemas/domaincommon.rng
src/conf/domain_conf.c
src/conf/domain_conf.h

index e9d51e46898912fb15b80c4ac1c4d5b24884ed51..cecb27e744ac197a7f23510687cb26f0371ef80a 100644 (file)
@@ -5800,6 +5800,19 @@ interaction with the admin.
       graphics type ``egl-headless`` (see below) which will instruct QEMU to
       open and use drm nodes for OpenGL rendering.
 
+      A VNC server could be optionally mapped to the specific host audio
+      backend using the ``<audio>`` sub-element:
+
+      ::
+
+         <graphics type='vnc' ...>
+           <audio id='1'>
+         </graphics>
+
+      Where ``1`` is an id of the `audio device <#elementsAudio>`__. If no
+      ID is specified, then the default audio backend will be used.
+      :since:`Since 7.2.0, qemu`.
+
    ``spice`` :since:`Since 0.8.6`
       Starts a SPICE server. The ``port`` attribute specifies the TCP port
       number (with -1 as legacy syntax indicating that it should be
@@ -6805,8 +6818,8 @@ Valid values are:
 Each ``sound`` element has an optional sub-element ``<address>`` which can tie
 the device to a particular PCI slot, `documented above <#elementsAddress>`__.
 
-:since:`Since 6.7.0`, a sound device could be optionally mapped to the specific
-host audio backend using the ``<audio>`` sub-element:
+A sound device could be optionally mapped to the specific host audio
+backend using the ``<audio>`` sub-element:
 
 ::
 
@@ -6818,8 +6831,9 @@ host audio backend using the ``<audio>`` sub-element:
    </devices>
    ...
 
-Where ``1`` is an id of the `audio device <#elementsAudio>`__.
-This is supported for bhyve only.
+Where ``1`` is an id of the `audio device <#elementsAudio>`__. If no
+ID is specified, then the default audio backend will be used.
+:since:`Since 6.7.0, bhyve; Since 7.2.0, qemu`.
 
 :anchor:`<a id="elementsAudio"/>`
 
index b1032292c18cd52a7d78745917a423fa669f30ea..4729590871241370a9d1c733ebfd93c5fac540e1 100644 (file)
               <value>keep</value>
             </attribute>
           </optional>
-          <ref name="listenElements"/>
+          <interleave>
+            <optional>
+              <element name="audio">
+                <attribute name="id">
+                  <ref name="uint8"/>
+                </attribute>
+              </element>
+            </optional>
+            <ref name="listenElements"/>
+          </interleave>
         </group>
         <group>
           <attribute name="type">
index b84008ce94530e8baa7320dabbe985521394c645..15f439d21c02a2378b4741f27becc612ef28aac6 100644 (file)
@@ -13204,6 +13204,8 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def,
     g_autofree char *sharePolicy = virXMLPropString(node, "sharePolicy");
     g_autofree char *autoport = virXMLPropString(node, "autoport");
     g_autofree char *powerControl = virXMLPropString(node, "powerControl");
+    xmlNodePtr audioNode;
+    VIR_XPATH_NODE_AUTORESTORE(ctxt)
 
     if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0)
         return -1;
@@ -13272,6 +13274,24 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDefPtr def,
 
     def->data.vnc.keymap = virXMLPropString(node, "keymap");
 
+    ctxt->node = node;
+    audioNode = virXPathNode("./audio", ctxt);
+    if (audioNode) {
+        g_autofree char *tmp = NULL;
+        tmp = virXMLPropString(audioNode, "id");
+        if (!tmp) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("missing audio 'id' attribute"));
+            return -1;
+        }
+        if (virStrToLong_ui(tmp, NULL, 10, &def->data.vnc.audioId) < 0 ||
+            def->data.vnc.audioId == 0) {
+            virReportError(VIR_ERR_XML_ERROR,
+                           _("Invalid audio 'id' value '%s'"), tmp);
+            return -1;
+        }
+    }
+
     if (virDomainGraphicsAuthDefParseXML(node, &def->data.vnc.auth,
                                          def->type) < 0)
         return -1;
@@ -27512,6 +27532,18 @@ virDomainGraphicsDefFormat(virBufferPtr buf,
         virDomainSpiceGLDefFormat(buf, def);
     }
 
+    if (def->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) {
+        if (!children) {
+            virBufferAddLit(buf, ">\n");
+            virBufferAdjustIndent(buf, 2);
+            children = true;
+        }
+
+        if (def->data.vnc.audioId > 0)
+            virBufferAsprintf(buf, "<audio id='%d'/>\n",
+                              def->data.vnc.audioId);
+    }
+
     if (children) {
         virBufferAdjustIndent(buf, -2);
         virBufferAddLit(buf, "</graphics>\n");
index 4da68dbebcf2f786ece0c0d78e677ee027a106e3..216d097f5ec6e01da3a79aee21aa43926ab359a2 100644 (file)
@@ -1740,6 +1740,7 @@ struct _virDomainGraphicsDef {
             virDomainGraphicsAuthDef auth;
             int sharePolicy;
             virTristateBool powerControl;
+            unsigned int audioId;
         } vnc;
         struct {
             char *display;