[PATCH v3 09/11] audio: do not build audio-related sources with --disable-audio

Sergei Heifetz posted 11 patches 3 weeks, 1 day ago
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Gerd Hoffmann <kraxel@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Dr. David Alan Gilbert" <dave@treblig.org>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Michael S. Tsirkin" <mst@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>
[PATCH v3 09/11] audio: do not build audio-related sources with --disable-audio
Posted by Sergei Heifetz 3 weeks, 1 day ago
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.

- 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.

- hmp-commands*.hx:
  Remove the HMP `info capture`, `stopcapture` and `wavcapture`
  commands.

- Other source files:
  Wrap audio-related code in ifdefs.

Signed-off-by: Sergei Heifetz <heifetz@yandex-team.com>
---
 audio/meson.build                |  4 ++++
 hmp-commands-info.hx             |  2 ++
 hmp-commands.hx                  |  2 ++
 hw/core/machine.c                |  6 ++++++
 hw/core/qdev-properties-system.c |  2 ++
 qapi/audio.json                  |  3 ++-
 replay/meson.build               |  9 ++++++++-
 replay/replay-audio-stub.c       | 21 +++++++++++++++++++++
 replay/stubs-system.c            | 12 ------------
 system/runstate.c                |  2 ++
 system/vl.c                      |  2 ++
 11 files changed, 51 insertions(+), 14 deletions(-)
 create mode 100644 replay/replay-audio-stub.c

diff --git a/audio/meson.build b/audio/meson.build
index 0e33b6f9836..4cd855d2b9a 100644
--- a/audio/meson.build
+++ b/audio/meson.build
@@ -1,4 +1,8 @@
 audio_ss = ss.source_set()
+if not have_audio
+  subdir_done()
+endif
+
 audio_ss.add(files(
   'audio.c',
   'audio-be.c',
diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx
index 74c741f80e2..a959479024a 100644
--- a/hmp-commands-info.hx
+++ b/hmp-commands-info.hx
@@ -364,6 +364,7 @@ SRST
 ERST
 
 /* BEGIN deprecated */
+#ifdef CONFIG_AUDIO
     {
         .name       = "capture",
         .args_type  = "",
@@ -376,6 +377,7 @@ SRST
   ``info capture``
     Show capture information (deprecated).
 ERST
+#endif
 /* END deprecated */
 
     {
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 5cc4788f12d..e8b8175bb94 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -765,6 +765,7 @@ SRST
 ERST
 
 /* BEGIN deprecated */
+#ifdef CONFIG_AUDIO
     {
         .name       = "wavcapture",
         .args_type  = "path:F,audiodev:s,freq:i?,bits:i?,nchannels:i?",
@@ -802,6 +803,7 @@ SRST
 
   Deprecated.
 ERST
+#endif
 /* END deprecated */
 
     {
diff --git a/hw/core/machine.c b/hw/core/machine.c
index a14ad05b9a6..920a74b3aef 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -678,6 +678,7 @@ bool device_type_is_dynamic_sysbus(MachineClass *mc, const char *type)
     return allowed;
 }
 
+#ifdef CONFIG_AUDIO
 static char *machine_get_audiodev(Object *obj, Error **errp)
 {
     MachineState *ms = MACHINE(obj);
@@ -697,6 +698,7 @@ static void machine_set_audiodev(Object *obj, const char *value,
     g_free(ms->audiodev);
     ms->audiodev = g_strdup(value);
 }
+#endif
 
 HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine)
 {
@@ -990,6 +992,7 @@ out_free:
     qapi_free_BootConfiguration(config);
 }
 
+#ifdef CONFIG_AUDIO
 void machine_add_audiodev_property(MachineClass *mc)
 {
     ObjectClass *oc = OBJECT_CLASS(mc);
@@ -1000,6 +1003,7 @@ void machine_add_audiodev_property(MachineClass *mc)
     object_class_property_set_description(oc, "audiodev",
                                           "Audiodev to use for default machine devices");
 }
+#endif
 
 static bool create_default_memdev(MachineState *ms, const char *path,
                                   Error **errp)
@@ -1286,7 +1290,9 @@ static void machine_finalize(Object *obj)
     g_free(ms->device_memory);
     g_free(ms->nvdimms_state);
     g_free(ms->numa_state);
+#ifdef CONFIG_AUDIO
     g_free(ms->audiodev);
+#endif
 }
 
 bool machine_usb(MachineState *machine)
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index a402321f42c..8679a71b538 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -483,6 +483,7 @@ const PropertyInfo qdev_prop_netdev = {
 };
 
 
+#ifdef CONFIG_AUDIO
 /* --- audiodev --- */
 static void get_audiodev(Object *obj, Visitor *v, const char* name,
                          void *opaque, Error **errp)
@@ -519,6 +520,7 @@ const PropertyInfo qdev_prop_audiodev = {
     .get = get_audiodev,
     .set = set_audiodev,
 };
+#endif
 
 bool qdev_prop_set_drive_err(DeviceState *dev, const char *name,
                              BlockBackend *value, Error **errp)
diff --git a/qapi/audio.json b/qapi/audio.json
index 2df87b97101..28fda7c8ac3 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 4b4175e8dd4..dc2e94e8975 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 have_audio
+  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 00000000000..b3da8e15583
--- /dev/null
+++ b/replay/replay-audio-stub.c
@@ -0,0 +1,21 @@
+/*
+ * 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_start(size_t *nsamples)
+{
+}
+void replay_audio_in_sample_lr(uint64_t *left, uint64_t *right)
+{
+}
+void replay_audio_in_finish(void)
+{
+}
+void replay_audio_out(size_t *played)
+{
+}
diff --git a/replay/stubs-system.c b/replay/stubs-system.c
index b2c52bc4043..454415ae8e4 100644
--- a/replay/stubs-system.c
+++ b/replay/stubs-system.c
@@ -15,18 +15,6 @@ void replay_input_sync_event(void)
 void replay_add_blocker(const char *feature)
 {
 }
-void replay_audio_in_start(size_t *nsamples)
-{
-}
-void replay_audio_in_sample_lr(uint64_t *left, uint64_t *right)
-{
-}
-void replay_audio_in_finish(void)
-{
-}
-void replay_audio_out(size_t *played)
-{
-}
 void replay_breakpoint(void)
 {
 }
diff --git a/system/runstate.c b/system/runstate.c
index eca722b43c6..7fb104f6515 100644
--- a/system/runstate.c
+++ b/system/runstate.c
@@ -1035,7 +1035,9 @@ void qemu_cleanup(int status)
     /* vhost-user must be cleaned up before chardevs.  */
     tpm_cleanup();
     net_cleanup();
+#ifdef CONFIG_AUDIO
     audio_cleanup();
+#endif
     monitor_cleanup();
     qemu_chr_cleanup();
     user_creatable_cleanup();
diff --git a/system/vl.c b/system/vl.c
index 9ed0285c47a..bd2b6439f00 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -2069,10 +2069,12 @@ static void qemu_create_early_backends(void)
      * setting machine properties, so they can be referred to.
      */
     configure_blockdev(&bdo_queue, machine_class, snapshot);
+#ifdef CONFIG_AUDIO
     audio_init_audiodevs();
     if (default_audio) {
         audio_create_default_audiodevs();
     }
+#endif
 }
 
 
-- 
2.34.1
Re: [PATCH v3 09/11] audio: do not build audio-related sources with --disable-audio
Posted by Markus Armbruster 2 weeks, 4 days ago
Sergei Heifetz <heifetz@yandex-team.com> writes:

> 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.
>
> - 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.
>
> - hmp-commands*.hx:
>   Remove the HMP `info capture`, `stopcapture` and `wavcapture`
>   commands.
>
> - Other source files:
>   Wrap audio-related code in ifdefs.
>
> Signed-off-by: Sergei Heifetz <heifetz@yandex-team.com>

[...]

> diff --git a/qapi/audio.json b/qapi/audio.json
> index 2df87b97101..28fda7c8ac3 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' }

Could we disable all the audio stuff here?

I tried, patch appended.  What do you think?

> diff --git a/replay/meson.build b/replay/meson.build
> index 4b4175e8dd4..dc2e94e8975 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 have_audio
> +  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 00000000000..b3da8e15583
> --- /dev/null
> +++ b/replay/replay-audio-stub.c
> @@ -0,0 +1,21 @@
> +/*
> + * 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_start(size_t *nsamples)
> +{
> +}
> +void replay_audio_in_sample_lr(uint64_t *left, uint64_t *right)
> +{
> +}
> +void replay_audio_in_finish(void)
> +{
> +}
> +void replay_audio_out(size_t *played)
> +{
> +}

Should this go into stubs/ instead?  Genuine question!  I can't tell
when we use stubs/foo*.c and when we use foo/*stub.c.

> diff --git a/replay/stubs-system.c b/replay/stubs-system.c
> index b2c52bc4043..454415ae8e4 100644
> --- a/replay/stubs-system.c
> +++ b/replay/stubs-system.c
> @@ -15,18 +15,6 @@ void replay_input_sync_event(void)
>  void replay_add_blocker(const char *feature)
>  {
>  }
> -void replay_audio_in_start(size_t *nsamples)
> -{
> -}
> -void replay_audio_in_sample_lr(uint64_t *left, uint64_t *right)
> -{
> -}
> -void replay_audio_in_finish(void)
> -{
> -}
> -void replay_audio_out(size_t *played)
> -{
> -}
>  void replay_breakpoint(void)
>  {
>  }

[...]

Note on the appended patch: the change to ui/dbus.c should be a separate
cleanup patch.


diff --git a/qapi/audio.json b/qapi/audio.json
index 28fda7c8ac..4f5f5dd988 100644
--- a/qapi/audio.json
+++ b/qapi/audio.json
@@ -49,7 +49,8 @@
     '*channels':       'uint32',
     '*voices':         'uint32',
     '*format':         'AudioFormat',
-    '*buffer-length':  'uint32' } }
+    '*buffer-length':  'uint32' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevGenericOptions:
@@ -65,7 +66,8 @@
 { 'struct': 'AudiodevGenericOptions',
   'data': {
     '*in':  'AudiodevPerDirectionOptions',
-    '*out': 'AudiodevPerDirectionOptions' } }
+    '*out': 'AudiodevPerDirectionOptions' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevDBusOptions:
@@ -85,7 +87,8 @@
   'data': {
     '*in':  'AudiodevPerDirectionOptions',
     '*out': 'AudiodevPerDirectionOptions',
-    '*nsamples': 'uint32'} }
+    '*nsamples': 'uint32'},
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevAlsaPerDirectionOptions:
@@ -107,7 +110,8 @@
   'data': {
     '*dev':           'str',
     '*period-length': 'uint32',
-    '*try-poll':      'bool' } }
+    '*try-poll':      'bool' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevAlsaOptions:
@@ -126,7 +130,8 @@
   'data': {
     '*in':        'AudiodevAlsaPerDirectionOptions',
     '*out':       'AudiodevAlsaPerDirectionOptions',
-    '*threshold': 'uint32' } }
+    '*threshold': 'uint32' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevSndioOptions:
@@ -148,7 +153,8 @@
     '*in':        'AudiodevPerDirectionOptions',
     '*out':       'AudiodevPerDirectionOptions',
     '*dev':       'str',
-    '*latency':   'uint32'} }
+    '*latency':   'uint32'},
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevCoreaudioPerDirectionOptions:
@@ -163,7 +169,8 @@
 { 'struct': 'AudiodevCoreaudioPerDirectionOptions',
   'base': 'AudiodevPerDirectionOptions',
   'data': {
-    '*buffer-count': 'uint32' } }
+      '*buffer-count': 'uint32' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevCoreaudioOptions:
@@ -179,7 +186,8 @@
 { 'struct': 'AudiodevCoreaudioOptions',
   'data': {
     '*in':  'AudiodevCoreaudioPerDirectionOptions',
-    '*out': 'AudiodevCoreaudioPerDirectionOptions' } }
+    '*out': 'AudiodevCoreaudioPerDirectionOptions' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevDsoundOptions:
@@ -199,7 +207,8 @@
   'data': {
     '*in':      'AudiodevPerDirectionOptions',
     '*out':     'AudiodevPerDirectionOptions',
-    '*latency': 'uint32' } }
+    '*latency': 'uint32' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevJackPerDirectionOptions:
@@ -233,7 +242,8 @@
     '*client-name':   'str',
     '*connect-ports': 'str',
     '*start-server':  'bool',
-    '*exact-name':    'bool' } }
+    '*exact-name':    'bool' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevJackOptions:
@@ -249,7 +259,8 @@
 { 'struct': 'AudiodevJackOptions',
   'data': {
     '*in':  'AudiodevJackPerDirectionOptions',
-    '*out': 'AudiodevJackPerDirectionOptions' } }
+    '*out': 'AudiodevJackPerDirectionOptions' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevOssPerDirectionOptions:
@@ -271,7 +282,8 @@
   'data': {
     '*dev':          'str',
     '*buffer-count': 'uint32',
-    '*try-poll':     'bool' } }
+    '*try-poll':     'bool' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevOssOptions:
@@ -301,7 +313,8 @@
     '*out':        'AudiodevOssPerDirectionOptions',
     '*try-mmap':   'bool',
     '*exclusive':  'bool',
-    '*dsp-policy': 'uint32' } }
+    '*dsp-policy': 'uint32' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevPaPerDirectionOptions:
@@ -326,7 +339,8 @@
   'data': {
     '*name': 'str',
     '*stream-name': 'str',
-    '*latency': 'uint32' } }
+    '*latency': 'uint32' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevPaOptions:
@@ -345,7 +359,8 @@
   'data': {
     '*in':     'AudiodevPaPerDirectionOptions',
     '*out':    'AudiodevPaPerDirectionOptions',
-    '*server': 'str' } }
+    '*server': 'str' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevPipewirePerDirectionOptions:
@@ -370,7 +385,8 @@
   'data': {
     '*name': 'str',
     '*stream-name': 'str',
-    '*latency': 'uint32' } }
+    '*latency': 'uint32' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevPipewireOptions:
@@ -386,7 +402,8 @@
 { 'struct': 'AudiodevPipewireOptions',
   'data': {
     '*in':     'AudiodevPipewirePerDirectionOptions',
-    '*out':    'AudiodevPipewirePerDirectionOptions' } }
+    '*out':    'AudiodevPipewirePerDirectionOptions' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevSdlPerDirectionOptions:
@@ -401,7 +418,8 @@
 { 'struct': 'AudiodevSdlPerDirectionOptions',
   'base': 'AudiodevPerDirectionOptions',
   'data': {
-    '*buffer-count': 'uint32' } }
+    '*buffer-count': 'uint32' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevSdlOptions:
@@ -417,7 +435,8 @@
 { 'struct': 'AudiodevSdlOptions',
   'data': {
     '*in':  'AudiodevSdlPerDirectionOptions',
-    '*out': 'AudiodevSdlPerDirectionOptions' } }
+    '*out': 'AudiodevSdlPerDirectionOptions' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevWavOptions:
@@ -436,7 +455,8 @@
   'data': {
     '*in':   'AudiodevPerDirectionOptions',
     '*out':  'AudiodevPerDirectionOptions',
-    '*path': 'str' } }
+    '*path': 'str' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudioFormat:
@@ -460,7 +480,8 @@
 # Since: 4.0
 ##
 { 'enum': 'AudioFormat',
-  'data': [ 'u8', 's8', 'u16', 's16', 'u32', 's32', 'f32' ] }
+  'data': [ 'u8', 's8', 'u16', 's16', 'u32', 's32', 'f32' ],
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @AudiodevDriver:
@@ -484,7 +505,8 @@
             { 'name': 'sdl', 'if': 'CONFIG_AUDIO_SDL' },
             { 'name': 'sndio', 'if': 'CONFIG_AUDIO_SNDIO' },
             { 'name': 'spice', 'if': 'CONFIG_SPICE' },
-            'wav' ] }
+            'wav' ],
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @Audiodev:
@@ -530,7 +552,8 @@
                    'if': 'CONFIG_AUDIO_SNDIO' },
     'spice':     { 'type': 'AudiodevGenericOptions',
                    'if': 'CONFIG_SPICE' },
-    'wav':       'AudiodevWavOptions' } }
+    'wav':       'AudiodevWavOptions' },
+  'if': 'CONFIG_AUDIO' }
 
 ##
 # @query-audiodevs:
diff --git a/audio/mixeng.h b/audio/mixeng.h
index f63283f408..0dfd5204a6 100644
--- a/audio/mixeng.h
+++ b/audio/mixeng.h
@@ -25,6 +25,8 @@
 #ifndef QEMU_MIXENG_H
 #define QEMU_MIXENG_H
 
+#ifdef CONFIG_AUDIO
+
 #ifdef FLOAT_MIXENG
 typedef float mixeng_real;
 struct mixeng_volume { int mute; mixeng_real r; mixeng_real l; };
@@ -56,4 +58,5 @@ uint32_t st_rate_frames_in(void *opaque, uint32_t frames_out);
 void mixeng_clear (struct st_sample *buf, int len);
 void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volume *vol);
 
+#endif
 #endif /* QEMU_MIXENG_H */
diff --git a/include/qemu/audio-capture.h b/include/qemu/audio-capture.h
index f1319c9002..5774967c0e 100644
--- a/include/qemu/audio-capture.h
+++ b/include/qemu/audio-capture.h
@@ -8,6 +8,8 @@
 
 #include "audio.h"
 
+#ifdef CONFIG_AUDIO
+
 struct capture_ops {
     void (*info) (void *opaque);
     void (*destroy) (void *opaque);
@@ -30,4 +32,5 @@ void audio_be_del_capture(
     CaptureVoiceOut *cap,
     void *cb_opaque);
 
+#endif
 #endif /* QEMU_AUDIO_CAPTURE_H */
diff --git a/include/qemu/audio.h b/include/qemu/audio.h
index cff8a334f3..1788a54877 100644
--- a/include/qemu/audio.h
+++ b/include/qemu/audio.h
@@ -32,6 +32,8 @@
 #include "gio/gio.h"
 #endif
 
+#ifdef CONFIG_AUDIO
+
 typedef void (*audio_callback_fn) (void *opaque, int avail);
 
 typedef struct audsettings {
@@ -240,4 +242,7 @@ static inline bool audio_format_is_signed(AudioFormat fmt)
 #define TYPE_AUDIO_BACKEND "audio-backend"
 OBJECT_DECLARE_TYPE(AudioBackend, AudioBackendClass, AUDIO_BACKEND)
 
+#else
+//#define audio_cleanup() ((void)0)
+#endif
 #endif /* QEMU_AUDIO_H */
diff --git a/ui/vnc.h b/ui/vnc.h
index ec8d0c91b5..89e0199be1 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -184,7 +184,9 @@ struct VncDisplay
     VncDisplaySASL sasl;
 #endif
 
+#ifdef CONFIG_AUDIO
     AudioBackend *audio_be;
+#endif
 
     VMChangeStateEntry *vmstate_handler_entry;
 };
@@ -325,8 +327,10 @@ struct VncState
     pixman_format_code_t client_format;
     int client_endian; /* G_LITTLE_ENDIAN or G_BIG_ENDIAN */
 
+#ifdef CONFIG_AUDIO
     CaptureVoiceOut *audio_cap;
     struct audsettings as;
+#endif
 
     VncReadEvent *read_handler;
     size_t read_handler_expect;
diff --git a/ui/dbus.c b/ui/dbus.c
index 99dac3e7fe..6086efd017 100644
--- a/ui/dbus.c
+++ b/ui/dbus.c
@@ -35,7 +35,6 @@
 #include "ui/egl-context.h"
 #endif
 #include "qemu/audio.h"
-#include "audio/audio_int.h" /* FIXME: use QOM dynamic cast instead of drv->name */
 #include "qapi/error.h"
 #include "trace.h"
 
diff --git a/ui/vnc.c b/ui/vnc.c
index 0ee5502d1e..7004c875a1 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1103,7 +1103,13 @@ static void vnc_update_throttle_offset(VncState *vs)
     if (vs->throttle_output_offset != offset) {
         trace_vnc_client_throttle_threshold(
             vs, vs->ioc, vs->throttle_output_offset, offset, vs->client_width,
-            vs->client_height, vs->client_pf.bytes_per_pixel, vs->audio_cap);
+            vs->client_height, vs->client_pf.bytes_per_pixel,
+#ifdef CONFIG_AUDIO
+            vs->audio_cap
+#else
+            NULL
+#endif
+            );
     }
 
     vs->throttle_output_offset = offset;
Re: [PATCH v3 09/11] audio: do not build audio-related sources with --disable-audio
Posted by Sergei Heifetz 6 days, 2 hours ago
On Thu Mar 19, 2026 at 1:36 PM +05, Markus Armbruster wrote:
> [...]
>> index 2df87b97101..28fda7c8ac3 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' }
>
> Could we disable all the audio stuff here?
>
> I tried, patch appended.  What do you think?

For some reason, I thought it was undesirable to alter the header files.
That's what I had in mind while working on the series.

In particular, when you previously suggested emptying out audio.json,
I used that idea to find other parts of the source code we can compile
out, but I thought that was it, and that there is no real reason to
actually remove the QAPI definitions.

I don't have any strong arguments against it. If we are okay with
changing the headers, what you suggest makes perfect sense.

>> [...]
>>
>> +#include "qemu/osdep.h"
>> +#include "system/replay.h"
>> +
>> +void replay_audio_in_start(size_t *nsamples)
>> +{
>> +}
>> +void replay_audio_in_sample_lr(uint64_t *left, uint64_t *right)
>> +{
>> +}
>> +void replay_audio_in_finish(void)
>> +{
>> +}
>> +void replay_audio_out(size_t *played)
>> +{
>> +}
>
> Should this go into stubs/ instead?  Genuine question!  I can't tell
> when we use stubs/foo*.c and when we use foo/*stub.c.

I don't think we should move this to stubs/ unless we also move 
replay/stubs-system.c there. I put the new file in replay/ because 
that's where these stubs originally came from.

Also, here is a quote from stubs/meson.build: 'If possible, add new
files to other directories, by using "if_false"'.

> [...]

P.S. Thank you for the review and for your suggestions. I'm really
grateful for them. I'm still interested in working on this, and I'm very
sorry it took so long to respond. 
Re: [PATCH v3 09/11] audio: do not build audio-related sources with --disable-audio
Posted by Markus Armbruster 5 days, 22 hours ago
"Sergei Heifetz" <heifetz@yandex-team.com> writes:

> On Thu Mar 19, 2026 at 1:36 PM +05, Markus Armbruster wrote:
>> [...]
>>> index 2df87b97101..28fda7c8ac3 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' }
>>
>> Could we disable all the audio stuff here?
>>
>> I tried, patch appended.  What do you think?
>
> For some reason, I thought it was undesirable to alter the header files.
> That's what I had in mind while working on the series.
>
> In particular, when you previously suggested emptying out audio.json,
> I used that idea to find other parts of the source code we can compile
> out, but I thought that was it, and that there is no real reason to
> actually remove the QAPI definitions.
>
> I don't have any strong arguments against it. If we are okay with
> changing the headers, what you suggest makes perfect sense.

We'd add a bunch of #if defined(CONFIG_AUDIO) to generated
qapi-*-audio.h.

If these were handwritten, would we do the same?

I figure we would, because that way we get compile errors instead of
link errors.  Likely one big #ifdef to guard everything but #include.

>>> [...]
>>>
>>> +#include "qemu/osdep.h"
>>> +#include "system/replay.h"
>>> +
>>> +void replay_audio_in_start(size_t *nsamples)
>>> +{
>>> +}
>>> +void replay_audio_in_sample_lr(uint64_t *left, uint64_t *right)
>>> +{
>>> +}
>>> +void replay_audio_in_finish(void)
>>> +{
>>> +}
>>> +void replay_audio_out(size_t *played)
>>> +{
>>> +}
>>
>> Should this go into stubs/ instead?  Genuine question!  I can't tell
>> when we use stubs/foo*.c and when we use foo/*stub.c.
>
> I don't think we should move this to stubs/ unless we also move 
> replay/stubs-system.c there. I put the new file in replay/ because 
> that's where these stubs originally came from.
>
> Also, here is a quote from stubs/meson.build: 'If possible, add new
> files to other directories, by using "if_false"'.

Alright, I learned something :)

>> [...]
>
> P.S. Thank you for the review and for your suggestions. I'm really
> grateful for them. I'm still interested in working on this, and I'm very
> sorry it took so long to respond. 

No worries!