audio/dbus: make "dbus" the default backend when using -display dbus
Set "using_dbus_display" during early_dbus_init(), so that we can try to create the "dbus" audio backend by default from audio_prio_list. This makes dbus audio work by default when using an audio device, without having to setup and wire up the -audiodev manually. The added FIXME is addressed in the following commits. Reviewed-by: Mark Cave-Ayland <mark.caveayland@nutanix.com> Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Marc-André Lureau committed
Oct 20, 2025 at 17:03 UTC
7c3f1bab7e79c5c514565fe6607d90129a3b549a
3 files changed
+27
-6
audio/audio.c
+3
@@ -58,6 +58,9 @@
58
that we generate the list.
59
*/
60
const char *audio_prio_list[] = {
61
+#ifdef CONFIG_GIO
62
+ "dbus",
63
+#endif
64
"spice",
65
CONFIG_AUDIO_DRIVERS
66
"none",
audio/dbusaudio.c
+7
-1
@@ -32,6 +32,7 @@
32
#endif
33
34
#include "ui/dbus.h"
35
+#include "ui/dbus-display.h"
36
#include "ui/dbus-display1.h"
37
38
#define AUDIO_CAP "dbus"
@@ -408,8 +409,13 @@ dbus_enable_in(HWVoiceIn *hw, bool enable)
409
static void *
410
dbus_audio_init(Audiodev *dev, Error **errp)
411
{
411
- DBusAudio *da = g_new0(DBusAudio, 1);
412
+ DBusAudio *da;
413
414
+ if (!qemu_using_dbus_display(errp)) {
415
+ return NULL;
416
+ }
417
+
418
+ da = g_new0(DBusAudio, 1);
419
da->dev = dev;
420
da->out_listeners = g_hash_table_new_full(g_str_hash, g_str_equal,
421
g_free, g_object_unref);
ui/dbus.c
+17
-5
@@ -35,6 +35,7 @@
35
#include "ui/egl-context.h"
36
#endif
37
#include "qemu/audio.h"
38
+#include "audio/audio_int.h" /* FIXME: use QOM dynamic cast instead of drv->name */
39
#include "qapi/error.h"
40
#include "trace.h"
41
@@ -218,9 +219,20 @@ dbus_display_complete(UserCreatable *uc, Error **errp)
219
return;
220
}
221
221
- if (dd->audiodev && *dd->audiodev) {
222
- AudioBackend *audio_be = audio_be_by_name(dd->audiodev, errp);
223
- if (!audio_be || !audio_be_set_dbus_server(audio_be, dd->server, dd->p2p, errp)) {
222
+ {
223
+ AudioBackend *audio_be = audio_get_default_audio_be(NULL);
224
+
225
+ if (audio_be && !g_str_equal(audio_be->drv->name, "dbus")) {
226
+ audio_be = NULL;
227
+ }
228
+ if (dd->audiodev && *dd->audiodev) {
229
+ audio_be = audio_be_by_name(dd->audiodev, errp);
230
+ if (!audio_be) {
231
+ return;
232
+ }
233
+ }
234
+ if (audio_be &&
235
+ !audio_be_set_dbus_server(audio_be, dd->server, dd->p2p, errp)) {
236
return;
237
}
238
}
@@ -475,6 +487,8 @@ early_dbus_init(DisplayOptions *opts)
487
#endif
488
}
489
490
+ using_dbus_display = 1;
491
+
492
type_register_static(&dbus_vc_type_info);
493
}
494
@@ -488,8 +502,6 @@ dbus_init(DisplayState *ds, DisplayOptions *opts)
502
exit(1);
503
}
504
491
- using_dbus_display = 1;
492
-
505
object_new_with_props(TYPE_DBUS_DISPLAY,
506
object_get_objects_root(),
507
"dbus-display", &error_fatal,