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 <[email protected]>
---
 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


Reply via email to