qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: mkletzan@redhat.com
Subject: [PATCH 1/9] audio: Add easy dummy audio initialiser
Date: Fri, 22 Sep 2023 11:44:51 +0200	[thread overview]
Message-ID: <20230922094459.265509-2-pbonzini@redhat.com> (raw)
In-Reply-To: <20230922094459.265509-1-pbonzini@redhat.com>

From: Martin Kletzander <mkletzan@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 <mkletzan@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@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;
+    }
+
+    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



  reply	other threads:[~2023-09-22  9:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-22  9:44 [PATCH 0/9] audio: make sound cards require the audiodev property Paolo Bonzini
2023-09-22  9:44 ` Paolo Bonzini [this message]
2023-09-22 11:45   ` [PATCH 1/9] audio: Add easy dummy audio initialiser Marc-André Lureau
2023-09-22  9:44 ` [PATCH 2/9] Introduce machine property "audiodev" Paolo Bonzini
2023-09-22  9:44 ` [PATCH 3/9] vl: support -audio BACKEND without model Paolo Bonzini
2023-09-22  9:44 ` [PATCH 4/9] hw/arm: Support machine-default audiodev with fallback Paolo Bonzini
2023-09-22  9:44 ` [PATCH 5/9] hw/ppc: " Paolo Bonzini
2023-09-22  9:44 ` [PATCH 6/9] vt82c686: " Paolo Bonzini
2023-09-22 12:16   ` BALATON Zoltan
2023-09-22 13:32     ` Paolo Bonzini
2023-09-22 23:54       ` BALATON Zoltan
2023-09-22  9:44 ` [PATCH 7/9] vl: recognize audiodev groups in configuration files Paolo Bonzini
2023-09-22  9:44 ` [PATCH 8/9] audio: Make AUD_register_card fallible and require audiodev= Paolo Bonzini
2023-09-22 11:17   ` Philippe Mathieu-Daudé
2023-09-22  9:44 ` [PATCH 9/9] audio: Be more strict during audio backend initialisation Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230922094459.265509-2-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=mkletzan@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).