Hi On Fri, Sep 22, 2023 at 1:46 PM Paolo Bonzini <pbonz...@redhat.com> wrote: > > From: Martin Kletzander <mklet...@redhat.com> > > In case of sound devices which are created by default (some of them even with > -nodefaults) it would not be nice to users if qemu required explicit: > > -audiodev driver=none,id=audio0 -machine audiodev=audio0 > > when they just want to run a VM and not care about any audio output. Instead > this little helper makes it easy to create a dummy audiodev (driver=none) in > case there is no audiodev specified for the machine. To make sure users > are not surprised by no sound output a helping message is also printed out. > > Signed-off-by: Martin Kletzander <mklet...@redhat.com> > Signed-off-by: Paolo Bonzini <pbonz...@redhat.com> > --- > audio/audio.c | 34 ++++++++++++++++++++++++++++++++++ > audio/audio.h | 2 ++ > 2 files changed, 36 insertions(+) > > diff --git a/audio/audio.c b/audio/audio.c > index d72e7db7fb9..8c74bc6b88c 100644 > --- a/audio/audio.c > +++ b/audio/audio.c > @@ -41,6 +41,7 @@ > #include "sysemu/runstate.h" > #include "ui/qemu-spice.h" > #include "trace.h" > +#include "hw/boards.h" > > #define AUDIO_CAP "audio" > #include "audio_int.h" > @@ -2174,6 +2175,39 @@ bool audio_init_audiodevs(void) > return true; > } > > +static void audio_init_dummy(const char *id) > +{ > + Audiodev *dev = g_new0(Audiodev, 1); > + AudiodevListEntry *e = g_new0(AudiodevListEntry, 1); > + > + dev->driver = AUDIODEV_DRIVER_NONE; > + dev->id = g_strdup(id); > + > + audio_validate_opts(dev, &error_abort); > + audio_init(dev, NULL); > + > + e->dev = dev; > + QSIMPLEQ_INSERT_TAIL(&audiodevs, e, next); > +} > + > +const char *audio_maybe_init_dummy(const char *default_id) > +{ > + MachineState *ms = MACHINE(qdev_get_machine()); > + > + if (ms->default_audiodev) { > + return ms->default_audiodev; > + }
../audio/audio.c:2197:11: error: ‘MachineState’ {aka ‘struct MachineState’} has no member named ‘default_audiodev’ 2197 | if (ms->default_audiodev) { introduced in next patch > + > + dolog("warning: No audiodev specified for implicit machine devices, " > + "no audio output will be available for these. " > + "For setting a backend audiodev for such devices try using " > + "the audiodev machine option.\n"); > + > + audio_init_dummy(default_id); > + > + return default_id; > +} > + > audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo) > { > return (audsettings) { > diff --git a/audio/audio.h b/audio/audio.h > index a276ec13eba..81d39526625 100644 > --- a/audio/audio.h > +++ b/audio/audio.h > @@ -176,6 +176,8 @@ void audio_help(void); > AudioState *audio_state_by_name(const char *name); > const char *audio_get_id(QEMUSoundCard *card); > > +const char *audio_maybe_init_dummy(const char *default_id); > + > #define DEFINE_AUDIO_PROPERTIES(_s, _f) \ > DEFINE_PROP_AUDIODEV("audiodev", _s, _f) > > -- > 2.41.0 > > -- Marc-André Lureau