When QEMU is configured with `--disable-audio`, do not build any
audio-related sources.
- audio/meson.build and replay/meson.build:
Exclude audio-related sources when audio is disabled.
- audio/audio-stub.c:
Provide a minimal set of straightforward stubs.
- replay/replay-audio-stub.c:
Move the existing stubs from replay/stubs-system.c into a separate
file.
- qapi/audio.json:
Remove the QMP `query-audiodevs` command.
- audio/audio-hmp-cmds-stub.c:
Provide meaningful messages for audio-related HMP commands:
stopcapture, wavcapture, info capture.
Signed-off-by: Sergei Heifetz <heifetz@yandex-team.com>
---
audio/audio-hmp-cmds-stub.c | 28 ++++++++++++++++++++++++++++
audio/audio-stub.c | 35 +++++++++++++++++++++++++++++++++++
audio/meson.build | 5 +++++
qapi/audio.json | 3 ++-
replay/meson.build | 9 ++++++++-
replay/replay-audio-stub.c | 16 ++++++++++++++++
replay/stubs-system.c | 6 ------
7 files changed, 94 insertions(+), 8 deletions(-)
create mode 100644 audio/audio-hmp-cmds-stub.c
create mode 100644 audio/audio-stub.c
create mode 100644 replay/replay-audio-stub.c
diff --git a/audio/audio-hmp-cmds-stub.c b/audio/audio-hmp-cmds-stub.c
new file mode 100644
index 0000000000..2f94f1c8dd
--- /dev/null
+++ b/audio/audio-hmp-cmds-stub.c
@@ -0,0 +1,28 @@
+/*
+ * Stub for audio-hmp-cmds.c
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "audio_int.h"
+#include "monitor/hmp.h"
+#include "monitor/monitor.h"
+#include "qapi/error.h"
+#include "qobject/qdict.h"
+#include "qemu/error-report.h"
+
+void hmp_info_capture(Monitor *mon, const QDict *qdict)
+{
+ monitor_puts(mon, "audio subsystem is disabled at compile time");
+}
+
+void hmp_stopcapture(Monitor *mon, const QDict *qdict)
+{
+ monitor_puts(mon, "audio subsystem is disabled at compile time");
+}
+
+void hmp_wavcapture(Monitor *mon, const QDict *qdict)
+{
+ monitor_puts(mon, "audio subsystem is disabled at compile time");
+}
diff --git a/audio/audio-stub.c b/audio/audio-stub.c
new file mode 100644
index 0000000000..0c9e2446e0
--- /dev/null
+++ b/audio/audio-stub.c
@@ -0,0 +1,35 @@
+/*
+ * Stub for audio.c
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/qapi-commands-audio.h"
+#include "qemu/audio.h"
+#include "qapi/error.h"
+
+void audio_cleanup(void) {}
+
+AudioBackend *audio_be_by_name(const char *name, Error **errp)
+{
+ error_setg(
+ errp,
+ "trying to find audiodev '%s' by name with audio component disabled",
+ name);
+ return NULL;
+}
+
+const char *audio_be_get_id(AudioBackend *be) { return ""; }
+
+bool audio_be_set_dbus_server(AudioBackend *be,
+ GDBusObjectManagerServer *server, bool p2p,
+ Error **errp)
+{
+ error_setg(errp, "trying to set dbus server with audio component disabled");
+ return false;
+}
+
+void audio_init_audiodevs(void) {}
+
+void audio_create_default_audiodevs(void) {}
diff --git a/audio/meson.build b/audio/meson.build
index b2dca2c640..ea1f88fb6f 100644
--- a/audio/meson.build
+++ b/audio/meson.build
@@ -1,3 +1,8 @@
+if not audio_enabled
+ system_ss.add(files('audio-stub.c', 'audio-hmp-cmds-stub.c'))
+ subdir_done()
+endif
+
system_ss.add(files(
'audio.c',
'mixeng.c',
diff --git a/qapi/audio.json b/qapi/audio.json
index 2df87b9710..28fda7c8ac 100644
--- a/qapi/audio.json
+++ b/qapi/audio.json
@@ -540,4 +540,5 @@
# Since: 8.0
##
{ 'command': 'query-audiodevs',
- 'returns': ['Audiodev'] }
+ 'returns': ['Audiodev'],
+ 'if': 'CONFIG_AUDIO' }
diff --git a/replay/meson.build b/replay/meson.build
index 4b4175e8dd..7f8b5dca61 100644
--- a/replay/meson.build
+++ b/replay/meson.build
@@ -7,7 +7,14 @@ system_ss.add(when: 'CONFIG_TCG', if_true: files(
'replay-char.c',
'replay-snapshot.c',
'replay-net.c',
- 'replay-audio.c',
'replay-random.c',
'replay-debugging.c',
), if_false: files('stubs-system.c'))
+
+if audio_enabled
+ system_ss.add(when: 'CONFIG_TCG',
+ if_true: files('replay-audio.c'),
+ if_false: files('replay-audio-stub.c'))
+else
+ system_ss.add(files('replay-audio-stub.c'))
+endif
diff --git a/replay/replay-audio-stub.c b/replay/replay-audio-stub.c
new file mode 100644
index 0000000000..303e5075f4
--- /dev/null
+++ b/replay/replay-audio-stub.c
@@ -0,0 +1,16 @@
+/*
+ * Stub for replay-audio.c
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "system/replay.h"
+
+void replay_audio_in(size_t *recorded, st_sample *samples,
+ size_t *wpos, size_t size)
+{
+}
+void replay_audio_out(size_t *played)
+{
+}
diff --git a/replay/stubs-system.c b/replay/stubs-system.c
index 7f85764936..454415ae8e 100644
--- a/replay/stubs-system.c
+++ b/replay/stubs-system.c
@@ -15,12 +15,6 @@ void replay_input_sync_event(void)
void replay_add_blocker(const char *feature)
{
}
-void replay_audio_in(size_t *recorded, st_sample *samples, size_t *wpos, size_t size)
-{
-}
-void replay_audio_out(size_t *played)
-{
-}
void replay_breakpoint(void)
{
}
--
2.34.1
On 2/17/26 06:27, Sergei Heifetz wrote:
> When QEMU is configured with `--disable-audio`, do not build any
> audio-related sources.
>
> - audio/meson.build and replay/meson.build:
> Exclude audio-related sources when audio is disabled.
>
> - audio/audio-stub.c:
> Provide a minimal set of straightforward stubs.
>
> - replay/replay-audio-stub.c:
> Move the existing stubs from replay/stubs-system.c into a separate
> file.
>
> - qapi/audio.json:
> Remove the QMP `query-audiodevs` command.
>
> - audio/audio-hmp-cmds-stub.c:
> Provide meaningful messages for audio-related HMP commands:
> stopcapture, wavcapture, info capture.
>
> Signed-off-by: Sergei Heifetz <heifetz@yandex-team.com>
> ---
> audio/audio-hmp-cmds-stub.c | 28 ++++++++++++++++++++++++++++
Can you remove the commands instead?
> +AudioBackend *audio_be_by_name(const char *name, Error **errp)
> +{
> + error_setg(
> + errp,
> + "trying to find audiodev '%s' by name with audio component disabled",
This can be simplified to just 'audio disabled' or something like that.
> + name);
> + return NULL;
> +}
> +
> +const char *audio_be_get_id(AudioBackend *be) { return ""; }
Can you instead compile out qdev_prop_audiodev?
> +bool audio_be_set_dbus_server(AudioBackend *be,
> + GDBusObjectManagerServer *server, bool p2p,
> + Error **errp)
> +{
> + error_setg(errp, "trying to set dbus server with audio component disabled");
Since this requires an AudioBackend, which you cannot get with audio
disabled, it can be simply abort().
> +if audio_enabled
> + system_ss.add(when: 'CONFIG_TCG',
> + if_true: files('replay-audio.c'),
> + if_false: files('replay-audio-stub.c'))
> +else
> + system_ss.add(files('replay-audio-stub.c'))
> +endif
I think this can be simply
system_ss.add(when: ['CONFIG_TCG', 'CONFIG_AUDIO'],
if_true: files('replay-audio.c'),
if_false: files('replay-audio-stub.c'))
but I may be incorrect.
Paolo
On 2/17/26 14:49, Paolo Bonzini wrote:
> On 2/17/26 06:27, Sergei Heifetz wrote:
>> When QEMU is configured with `--disable-audio`, do not build any
>> audio-related sources.
>>
>> - audio/meson.build and replay/meson.build:
>> Exclude audio-related sources when audio is disabled.
>>
>> - audio/audio-stub.c:
>> Provide a minimal set of straightforward stubs.
>>
>> - replay/replay-audio-stub.c:
>> Move the existing stubs from replay/stubs-system.c into a separate
>> file.
>>
>> - qapi/audio.json:
>> Remove the QMP `query-audiodevs` command.
>>
>> - audio/audio-hmp-cmds-stub.c:
>> Provide meaningful messages for audio-related HMP commands:
>> stopcapture, wavcapture, info capture.
>>
>> Signed-off-by: Sergei Heifetz <heifetz@yandex-team.com>
>> ---
>> audio/audio-hmp-cmds-stub.c | 28 ++++++++++++++++++++++++++++
>
> Can you remove the commands instead?
>
Yes, sure.
>> +AudioBackend *audio_be_by_name(const char *name, Error **errp)
>> +{
>> + error_setg(
>> + errp,
>> + "trying to find audiodev '%s' by name with audio component
>> disabled",
>
> This can be simplified to just 'audio disabled' or something like that.
Ok.
>
>> + name);
>> + return NULL;
>> +}
>> +
>> +const char *audio_be_get_id(AudioBackend *be) { return ""; }
>
> Can you instead compile out qdev_prop_audiodev?
I think so. I'll try it.
>
>> +bool audio_be_set_dbus_server(AudioBackend *be,
>> + GDBusObjectManagerServer *server, bool
>> p2p,
>> + Error **errp)
>> +{
>> + error_setg(errp, "trying to set dbus server with audio component
>> disabled");
>
> Since this requires an AudioBackend, which you cannot get with audio
> disabled, it can be simply abort().
That's reasonable, I'll replace it with abort().
>
>> +if audio_enabled
>> + system_ss.add(when: 'CONFIG_TCG',
>> + if_true: files('replay-audio.c'),
>> + if_false: files('replay-audio-stub.c'))
>> +else
>> + system_ss.add(files('replay-audio-stub.c'))
>> +endif
>
> I think this can be simply
>
> system_ss.add(when: ['CONFIG_TCG', 'CONFIG_AUDIO'],
> if_true: files('replay-audio.c'),
> if_false: files('replay-audio-stub.c'))
>
> but I may be incorrect.
>
I’ve already tried it, and it doesn’t work for some reason.
> Paolo
>
Thank you for reviewing and for participating in the discussion about
the series. I probably wouldn’t have been able to summarise the points
as clearly myself.
© 2016 - 2026 Red Hat, Inc.