qemuBuildSoundCommandLine: Generate codecs via JSON

The codec devices have the following properties we control:
  cad=<uint32>           -  (default: 4294967295)
  audiodev=<str>         - ID of an audiodev to use as a backend

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2021-10-05 18:42:39 +02:00
parent e79e862a6c
commit 39f181dacc

View File

@ -4520,30 +4520,36 @@ qemuBuildSoundDevCmd(virCommand *cmd,
} }
static char * static int
qemuBuildSoundCodecStr(const virDomainDef *def, qemuBuildSoundCodecCmd(virCommand *cmd,
const virDomainDef *def,
virDomainSoundDef *sound, virDomainSoundDef *sound,
virDomainSoundCodecDef *codec, virDomainSoundCodecDef *codec,
virQEMUCaps *qemuCaps) virQEMUCaps *qemuCaps)
{ {
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autoptr(virJSONValue) props = NULL;
const char *stype; g_autofree char *audioid = NULL;
int type; g_autofree char *alias = g_strdup_printf("%s-codec%d", sound->info.alias, codec->cad);
g_autofree char *bus = g_strdup_printf("%s.0", sound->info.alias);
type = codec->type;
stype = qemuSoundCodecTypeToString(type);
virBufferAsprintf(&buf, "%s,id=%s-codec%d,bus=%s.0,cad=%d",
stype, sound->info.alias, codec->cad, sound->info.alias, codec->cad);
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_AUDIODEV)) { if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_AUDIODEV)) {
g_autofree char *audioid = qemuGetAudioIDString(def, sound->audioId); if (!(audioid = qemuGetAudioIDString(def, sound->audioId)))
if (!audioid) return -1;
return NULL;
virBufferAsprintf(&buf, ",audiodev=%s", audioid);
} }
return virBufferContentAndReset(&buf); if (virJSONValueObjectCreate(&props,
"s:driver", qemuSoundCodecTypeToString(codec->type),
"s:id", alias,
"s:bus", bus,
"i:cad", codec->cad,
"S:audiodev", audioid,
NULL) < 0)
return -1;
if (qemuBuildDeviceCommandlineFromJSON(cmd, props, qemuCaps) < 0)
return -1;
return 0;
} }
@ -4571,30 +4577,16 @@ qemuBuildSoundCommandLine(virCommand *cmd,
if (virDomainSoundModelSupportsCodecs(sound)) { if (virDomainSoundModelSupportsCodecs(sound)) {
for (j = 0; j < sound->ncodecs; j++) { for (j = 0; j < sound->ncodecs; j++) {
g_autofree char *codecstr = NULL; if (qemuBuildSoundCodecCmd(cmd, def, sound, sound->codecs[j],
virCommandAddArg(cmd, "-device"); qemuCaps) < 0)
if (!(codecstr =
qemuBuildSoundCodecStr(def, sound,
sound->codecs[j], qemuCaps))) {
return -1; return -1;
}
virCommandAddArg(cmd, codecstr);
} }
if (j == 0) {
g_autofree char *codecstr = NULL;
virDomainSoundCodecDef codec = {
VIR_DOMAIN_SOUND_CODEC_TYPE_DUPLEX,
0
};
virCommandAddArg(cmd, "-device");
if (!(codecstr =
qemuBuildSoundCodecStr(def, sound,
&codec, qemuCaps))) {
return -1;
} if (j == 0) {
virCommandAddArg(cmd, codecstr); virDomainSoundCodecDef codec = { VIR_DOMAIN_SOUND_CODEC_TYPE_DUPLEX, 0 };
if (qemuBuildSoundCodecCmd(cmd, def, sound, &codec, qemuCaps) < 0)
return -1;
} }
} }
} }