mirror of https://gitee.com/openkylin/libvirt.git
conf: refactor OSS audio backend specific options
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. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
d0ae9b429a
commit
8149518ee1
|
@ -4518,6 +4518,15 @@
|
|||
</interleave>
|
||||
</element>
|
||||
</define>
|
||||
|
||||
<define name="audiooss">
|
||||
<optional>
|
||||
<attribute name="dev">
|
||||
<ref name="deviceName"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
</define>
|
||||
|
||||
<define name="audio">
|
||||
<element name="audio">
|
||||
<attribute name="id">
|
||||
|
@ -4531,16 +4540,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>
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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, "<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);
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue