
On Wed, Mar 03, 2021 at 06:18:28PM +0000, Daniel P. Berrangé wrote:
Currently the QEMU driver secretly sets the QEMU_AUDIO_DRV env variable
- VNC - set to "none", unless passthrough of host env variable is set - SPICE - always set to "spice" - SDL - always passthrough host env - No graphics - set to "none", unless passthrough of host env variable is set
The setting of the QEMU_AUDIO_DRV env variable is done in the code which configures graphics.
If no <audio> element is present, we now auto-populate <audio> elements to reflect this historical default config. This avoids need to set audio env when processing graphics.
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index bb14fe2e33..59071068c3 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3573,9 +3573,112 @@ qemuDomainDefAddImplicitInputDevice(virDomainDef *def) return 0; }
+static int +qemuDomainDefAddDefaultAudioBackend(virQEMUDriverPtr driver, + virDomainDefPtr def) +{ + size_t i; + bool addAudio = false; + bool audioPassthrough = false; + virDomainAudioType audioBackend = VIR_DOMAIN_AUDIO_TYPE_NONE;
This var should be a plain 'int' otherwise the later....
+ g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver); + + if (def->naudios > 0) { + return 0; + } + + for (i = 0; i < def->ngraphics; i++) { + virDomainGraphicsDefPtr graph = def->graphics[i]; + + switch ((virDomainGraphicsType)graph->type) { + case VIR_DOMAIN_GRAPHICS_TYPE_VNC: + if (cfg->vncAllowHostAudio) { + audioPassthrough = true; + } else { + audioPassthrough = false; + audioBackend = VIR_DOMAIN_AUDIO_TYPE_NONE; + } + addAudio = true; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_SPICE: + audioPassthrough = false; + audioBackend = VIR_DOMAIN_AUDIO_TYPE_SPICE; + addAudio = true; + break; + case VIR_DOMAIN_GRAPHICS_TYPE_SDL: + audioPassthrough = true; + addAudio = true; + break; + + case VIR_DOMAIN_GRAPHICS_TYPE_RDP: + case VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP: + case VIR_DOMAIN_GRAPHICS_TYPE_EGL_HEADLESS: + break; + case VIR_DOMAIN_GRAPHICS_TYPE_LAST: + default: + virReportEnumRangeError(virDomainGraphicsType, graph->type); + return -1; + } + } + + if (!def->ngraphics) { + if (cfg->nogfxAllowHostAudio) { + audioPassthrough = true; + } else { + audioPassthrough = false; + audioBackend = VIR_DOMAIN_AUDIO_TYPE_NONE; + } + addAudio = true; + } + + if (addAudio && audioPassthrough) { + const char *audioenv = g_getenv("QEMU_AUDIO_DRV"); + if (audioenv == NULL) { + addAudio = false; + } else { + /* + * QEMU audio driver names are mostly the same as + * libvirt XML audio backend names + */ + if (STREQ(audioenv, "pa")) { + audioBackend = VIR_DOMAIN_AUDIO_TYPE_PULSEAUDIO; + } else { + if ((audioBackend = virDomainAudioTypeTypeFromString(audioenv)) < 0) {
...check here causes warning from clang about comparing an unsigned enum type to -1.
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown QEMU_AUDIO_DRV setting %s"), audioenv); + return -1; + } + } + } + }
Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|