diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 6dfd551e98..a2e2b1d9ea 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -4518,6 +4518,15 @@ + + + + + + + + + @@ -4531,16 +4540,12 @@ - - - + - - - + 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(¶ms, ",play=%s", - audio->backend.oss.inputDev); + audio->backend.oss.input.dev); - if (audio->backend.oss.outputDev) + if (audio->backend.oss.output.dev) virBufferAsprintf(¶ms, ",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 687f7069ae..feecd43c5a 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(virDomainAudioIOOSSPtr 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: @@ -13873,6 +13880,16 @@ virDomainSoundDefFind(const virDomainDef *def, } +static int +virDomainAudioOSSParse(virDomainAudioIOOSSPtr def, + xmlNodePtr node) +{ + def->dev = virXMLPropString(node, "dev"); + + return 0; +} + + static virDomainAudioDefPtr virDomainAudioDefParseXML(virDomainXMLOptionPtr xmlopt G_GNUC_UNUSED, xmlNodePtr node G_GNUC_UNUSED, @@ -13882,6 +13899,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; @@ -13912,19 +13930,16 @@ virDomainAudioDefParseXML(virDomainXMLOptionPtr xmlopt G_GNUC_UNUSED, goto error; } + inputNode = virXPathNode("./input", ctxt); + outputNode = virXPathNode("./output", ctxt); + switch ((virDomainAudioType) def->type) { - case VIR_DOMAIN_AUDIO_TYPE_OSS: { - xmlNodePtr inputDevNode, outputDevNode; - - inputDevNode = virXPathNode("./input", ctxt); - outputDevNode = virXPathNode("./output", ctxt); - - if (inputDevNode) - def->backend.oss.inputDev = virXMLPropString(inputDevNode, "dev"); - if (outputDevNode) - def->backend.oss.outputDev = virXMLPropString(outputDevNode, "dev"); + 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; @@ -26360,11 +26375,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(virDomainAudioIOOSSPtr 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) { @@ -26377,15 +26415,14 @@ virDomainAudioDefFormat(virBufferPtr buf, switch (def->type) { case VIR_DOMAIN_AUDIO_TYPE_OSS: - if (def->backend.oss.inputDev) - virBufferAsprintf(&childBuf, "\n", - def->backend.oss.inputDev); - if (def->backend.oss.outputDev) - virBufferAsprintf(&childBuf, "\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 d613d30495..bd8bd89a55 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1451,6 +1451,12 @@ typedef enum { VIR_DOMAIN_AUDIO_TYPE_LAST } virDomainAudioType; +typedef struct _virDomainAudioIOOSS virDomainAudioIOOSS; +typedef virDomainAudioIOOSS *virDomainAudioIOOSSPtr; +struct _virDomainAudioIOOSS { + char *dev; +}; + struct _virDomainAudioDef { int type; @@ -1458,8 +1464,8 @@ struct _virDomainAudioDef { union { struct { - char *inputDev; - char *outputDev; + virDomainAudioIOOSS input; + virDomainAudioIOOSS output; } oss; } backend; };