audio: drop audio driver registration
module_object_class_by_name() handles loading the module providing the requested object. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Reviewed-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
Marc-André Lureau committed
Oct 17, 2025 at 18:34 UTC
b16d03b5babd9f8d65b688a1256ce233df7017d6
15 files changed
+13
-45
audio/alsaaudio.c
-1
@@ -972,7 +972,6 @@ static const TypeInfo audio_alsa_info = {
972
973
static void register_audio_alsa(void)
974
{
975
- audio_driver_register(&alsa_audio_driver);
975
type_register_static(&audio_alsa_info);
976
}
977
type_init(register_audio_alsa);
audio/audio.c
+13
-30
@@ -68,40 +68,21 @@ const char *audio_prio_list[] = {
68
NULL
69
};
70
71
-static QLIST_HEAD(, audio_driver) audio_drivers;
71
static AudiodevListHead audiodevs =
72
QSIMPLEQ_HEAD_INITIALIZER(audiodevs);
73
static AudiodevListHead default_audiodevs =
74
QSIMPLEQ_HEAD_INITIALIZER(default_audiodevs);
75
77
-
78
-void audio_driver_register(audio_driver *drv)
79
-{
80
- QLIST_INSERT_HEAD(&audio_drivers, drv, next);
81
-}
82
-
83
-static audio_driver *audio_driver_lookup(const char *name)
76
+static AudioBackendClass *audio_be_class_by_name(const char *name)
77
{
85
- struct audio_driver *d;
86
- Error *local_err = NULL;
87
- int rv;
78
+ g_autofree char *tname = g_strconcat("audio-", name, NULL);
79
+ ObjectClass *oc = module_object_class_by_name(tname);
80
89
- QLIST_FOREACH(d, &audio_drivers, next) {
90
- if (strcmp(name, d->name) == 0) {
91
- return d;
92
- }
93
- }
94
- rv = audio_module_load(name, &local_err);
95
- if (rv > 0) {
96
- QLIST_FOREACH(d, &audio_drivers, next) {
97
- if (strcmp(name, d->name) == 0) {
98
- return d;
99
- }
100
- }
101
- } else if (rv < 0) {
102
- error_report_err(local_err);
81
+ if (!oc || !object_class_dynamic_cast(oc, TYPE_AUDIO_BACKEND)) {
82
+ return NULL;
83
}
104
- return NULL;
84
+
85
+ return AUDIO_BACKEND_CLASS(oc);
86
}
87
88
static AudioBackend *default_audio_be;
@@ -1764,7 +1745,7 @@ static const VMStateDescription vmstate_audio = {
1745
void audio_create_default_audiodevs(void)
1746
{
1747
for (int i = 0; audio_prio_list[i]; i++) {
1767
- if (audio_driver_lookup(audio_prio_list[i])) {
1748
+ if (audio_be_class_by_name(audio_prio_list[i]) != NULL) {
1749
QDict *dict = qdict_new();
1750
Audiodev *dev = NULL;
1751
Visitor *v;
@@ -2129,9 +2110,11 @@ void audio_help(void)
2110
printf("Available audio drivers:\n");
2111
2112
for (i = 0; i < AUDIODEV_DRIVER__MAX; i++) {
2132
- audio_driver *driver = audio_driver_lookup(AudiodevDriver_str(i));
2133
- if (driver) {
2134
- printf("%s\n", driver->name);
2113
+ const char *name = AudiodevDriver_str(i);
2114
+ AudioBackendClass *be = audio_be_class_by_name(name);
2115
+
2116
+ if (be) {
2117
+ printf("%s\n", name);
2118
}
2119
}
2120
}
audio/audio_int.h
-2
@@ -259,8 +259,6 @@ extern const struct mixeng_volume nominal_volume;
259
260
extern const char *audio_prio_list[];
261
262
-void audio_driver_register(audio_driver *drv);
263
-
262
void audio_pcm_init_info (struct audio_pcm_info *info, const struct audsettings *as);
263
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
264
audio/coreaudio.m
-1
@@ -699,7 +699,6 @@ static const TypeInfo audio_coreaudio_info = {
699
700
static void register_audio_coreaudio(void)
701
{
702
- audio_driver_register(&coreaudio_audio_driver);
702
type_register_static(&audio_coreaudio_info);
703
}
704
type_init(register_audio_coreaudio);
audio/dbusaudio.c
-1
@@ -738,7 +738,6 @@ static const TypeInfo audio_dbus_info = {
738
739
static void register_audio_dbus(void)
740
{
741
- audio_driver_register(&dbus_audio_driver);
741
type_register_static(&audio_dbus_info);
742
}
743
type_init(register_audio_dbus);
audio/dsoundaudio.c
-1
@@ -720,7 +720,6 @@ static const TypeInfo audio_dsound_info = {
720
721
static void register_audio_dsound(void)
722
{
723
- audio_driver_register(&dsound_audio_driver);
723
type_register_static(&audio_dsound_info);
724
}
725
type_init(register_audio_dsound);
audio/jackaudio.c
-1
@@ -718,7 +718,6 @@ static const TypeInfo audio_jack_info = {
718
static void register_audio_jack(void)
719
{
720
qemu_mutex_init(&qjack_shutdown_lock);
721
- audio_driver_register(&jack_driver);
721
type_register_static(&audio_jack_info);
722
#if !defined(WIN32) && defined(CONFIG_PTHREAD_SETNAME_NP_W_TID)
723
jack_set_thread_creator(qjack_thread_creator);
audio/noaudio.c
-1
@@ -164,7 +164,6 @@ static const TypeInfo audio_none_info = {
164
165
static void register_audio_none(void)
166
{
167
- audio_driver_register(&no_audio_driver);
167
type_register_static(&audio_none_info);
168
}
169
type_init(register_audio_none);
audio/ossaudio.c
-1
@@ -798,7 +798,6 @@ static const TypeInfo audio_oss_info = {
798
799
static void register_audio_oss(void)
800
{
801
- audio_driver_register(&oss_audio_driver);
801
type_register_static(&audio_oss_info);
802
}
803
type_init(register_audio_oss);
audio/paaudio.c
-1
@@ -957,7 +957,6 @@ static const TypeInfo audio_pa_info = {
957
958
static void register_audio_pa(void)
959
{
960
- audio_driver_register(&pa_audio_driver);
960
type_register_static(&audio_pa_info);
961
}
962
type_init(register_audio_pa);
audio/pwaudio.c
-1
@@ -874,7 +874,6 @@ static const TypeInfo audio_pw_info = {
874
static void
875
register_audio_pw(void)
876
{
877
- audio_driver_register(&pw_audio_driver);
877
type_register_static(&audio_pw_info);
878
}
879
audio/sdlaudio.c
-1
@@ -517,7 +517,6 @@ static const TypeInfo audio_sdl_info = {
517
518
static void register_audio_sdl(void)
519
{
520
- audio_driver_register(&sdl_audio_driver);
520
type_register_static(&audio_sdl_info);
521
}
522
type_init(register_audio_sdl);
audio/sndioaudio.c
-1
@@ -581,7 +581,6 @@ static const TypeInfo audio_sndio_info = {
581
582
static void register_audio_sndio(void)
583
{
584
- audio_driver_register(&sndio_audio_driver);
584
type_register_static(&audio_sndio_info);
585
}
586
audio/spiceaudio.c
-1
@@ -351,7 +351,6 @@ static const TypeInfo audio_spice_info = {
351
352
static void register_audio_spice(void)
353
{
354
- audio_driver_register(&spice_audio_driver);
354
type_register_static(&audio_spice_info);
355
}
356
type_init(register_audio_spice);
audio/wavaudio.c
-1
@@ -240,7 +240,6 @@ static const TypeInfo audio_wav_info = {
240
241
static void register_audio_wav(void)
242
{
243
- audio_driver_register(&wav_audio_driver);
243
type_register_static(&audio_wav_info);
244
}
245
type_init(register_audio_wav);