[PATCH 34/43] audio: rename AudioState -> AudioBE

marcandre.lureau@redhat.com posted 43 patches 1 week, 2 days ago
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, Christian Schoenebeck <qemu_oss@crudebyte.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Thomas Huth <huth@tuxfamily.org>, Alexandre Ratchov <alex@caoua.org>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Peter Maydell <peter.maydell@linaro.org>, Jan Kiszka <jan.kiszka@web.de>, Alistair Francis <alistair@alistair23.me>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Laurent Vivier <laurent@vivier.eu>, "Michael S. Tsirkin" <mst@redhat.com>, Manos Pitsidianakis <manos.pitsidianakis@linaro.org>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Zhao Liu <zhao1.liu@intel.com>, "Hervé Poussineau" <hpoussin@reactos.org>, BALATON Zoltan <balaton@eik.bme.hu>, Jiaxun Yang <jiaxun.yang@flygoat.com>, "Alex Bennée" <alex.bennee@linaro.org>
There is a newer version of this series
[PATCH 34/43] audio: rename AudioState -> AudioBE
Posted by marcandre.lureau@redhat.com 1 week, 2 days ago
From: Marc-André Lureau <marcandre.lureau@redhat.com>

Naming is hard. But in general in QEMU, a host "backend" is the term
used to fullfill the request made by the device "frontend".

Note that "audiodev" is the corresponding QAPI type name (or configuration).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 audio/audio.h                    | 18 +++----
 audio/audio_int.h                | 20 +++----
 audio/audio_template.h           | 20 +++----
 ui/vnc.h                         |  2 +-
 audio/alsaaudio.c                |  2 +-
 audio/audio-hmp-cmds.c           |  2 +-
 audio/audio.c                    | 90 ++++++++++++++++----------------
 audio/dbusaudio.c                |  8 +--
 audio/ossaudio.c                 |  4 +-
 audio/wavcapture.c               |  2 +-
 hw/audio/pcspk.c                 |  2 +-
 hw/core/machine.c                |  2 +-
 hw/core/qdev-properties-system.c |  6 +--
 ui/dbus.c                        |  8 +--
 ui/vnc.c                         | 10 ++--
 15 files changed, 98 insertions(+), 98 deletions(-)

diff --git a/audio/audio.h b/audio/audio.h
index 1858b930ca..845e078169 100644
--- a/audio/audio.h
+++ b/audio/audio.h
@@ -64,15 +64,15 @@ typedef struct SWVoiceOut SWVoiceOut;
 typedef struct CaptureVoiceOut CaptureVoiceOut;
 typedef struct SWVoiceIn SWVoiceIn;
 
-typedef struct AudioStateClass AudioStateClass;
-struct AudioStateClass {
+typedef struct AudioBEClass AudioBEClass;
+struct AudioBEClass {
     ObjectClass parent_class;
 };
 
-typedef struct AudioState AudioState;
+typedef struct AudioBE AudioBE;
 typedef struct QEMUSoundCard {
     char *name;
-    AudioState *state;
+    AudioBE *be;
     QLIST_ENTRY (QEMUSoundCard) entries;
 } QEMUSoundCard;
 
@@ -83,7 +83,7 @@ typedef struct QEMUAudioTimeStamp {
 bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp);
 void AUD_remove_card (QEMUSoundCard *card);
 CaptureVoiceOut *AUD_add_capture(
-    AudioState *s,
+    AudioBE *s,
     struct audsettings *as,
     struct audio_capture_ops *ops,
     void *opaque
@@ -154,14 +154,14 @@ void audio_create_default_audiodevs(void);
 void audio_init_audiodevs(void);
 void audio_help(void);
 
-AudioState *audio_state_by_name(const char *name, Error **errp);
-AudioState *audio_get_default_audio_state(Error **errp);
+AudioBE *audio_be_by_name(const char *name, Error **errp);
+AudioBE *audio_get_default_audio_be(Error **errp);
 const char *audio_get_id(QEMUSoundCard *card);
 
 #define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
     DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
 
-#define TYPE_AUDIO_STATE "audio-state"
-OBJECT_DECLARE_TYPE(AudioState, AudioStateClass, AUDIO_STATE)
+#define TYPE_AUDIO_BE "audio-be"
+OBJECT_DECLARE_TYPE(AudioBE, AudioBEClass, AUDIO_BE)
 
 #endif /* QEMU_AUDIO_H */
diff --git a/audio/audio_int.h b/audio/audio_int.h
index cc7a6fe087..d7e24ec089 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -57,7 +57,7 @@ struct audio_pcm_info {
     int swap_endianness;
 };
 
-typedef struct AudioState AudioState;
+typedef struct AudioBE AudioBE;
 typedef struct SWVoiceCap SWVoiceCap;
 
 typedef struct STSampleBuffer {
@@ -66,7 +66,7 @@ typedef struct STSampleBuffer {
 } STSampleBuffer;
 
 typedef struct HWVoiceOut {
-    AudioState *s;
+    AudioBE *s;
     int enabled;
     int poll_mode;
     int pending_disable;
@@ -87,7 +87,7 @@ typedef struct HWVoiceOut {
 } HWVoiceOut;
 
 typedef struct HWVoiceIn {
-    AudioState *s;
+    AudioBE *s;
     int enabled;
     int poll_mode;
     struct audio_pcm_info info;
@@ -109,7 +109,7 @@ typedef struct HWVoiceIn {
 
 struct SWVoiceOut {
     QEMUSoundCard *card;
-    AudioState *s;
+    AudioBE *s;
     struct audio_pcm_info info;
     t_sample *conv;
     STSampleBuffer resample_buf;
@@ -126,7 +126,7 @@ struct SWVoiceOut {
 
 struct SWVoiceIn {
     QEMUSoundCard *card;
-    AudioState *s;
+    AudioBE *s;
     int active;
     struct audio_pcm_info info;
     void *rate;
@@ -147,7 +147,7 @@ struct audio_driver {
     void *(*init) (Audiodev *, Error **);
     void (*fini) (void *);
 #ifdef CONFIG_GIO
-    void (*set_dbus_server) (AudioState *s, GDBusObjectManagerServer *manager, bool p2p);
+    void (*set_dbus_server) (AudioBE *s, GDBusObjectManagerServer *manager, bool p2p);
 #endif
     struct audio_pcm_ops *pcm_ops;
     int max_voices_out;
@@ -206,7 +206,7 @@ static inline void *advance (void *p, int incr)
     return (d + incr);
 }
 
-int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
+int wav_start_capture(AudioBE *state, CaptureState *s, const char *path,
                       int freq, int bits, int nchannels);
 
 void audio_generic_run_buffer_in(HWVoiceIn *hw);
@@ -238,7 +238,7 @@ struct SWVoiceCap {
     QLIST_ENTRY (SWVoiceCap) entries;
 };
 
-typedef struct AudioState {
+typedef struct AudioBE {
     Object parent;
 
     struct audio_driver *drv;
@@ -258,7 +258,7 @@ typedef struct AudioState {
     bool timer_running;
     uint64_t timer_last;
     VMChangeStateEntry *vmse;
-} AudioState;
+} AudioBE;
 
 extern const struct mixeng_volume nominal_volume;
 
@@ -271,7 +271,7 @@ void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
 
 int audio_bug (const char *funcname, int cond);
 
-void audio_run(AudioState *s, const char *msg);
+void audio_run(AudioBE *s, const char *msg);
 
 const char *audio_application_name(void);
 
diff --git a/audio/audio_template.h b/audio/audio_template.h
index c29d79c443..c8f3e9dc93 100644
--- a/audio/audio_template.h
+++ b/audio/audio_template.h
@@ -36,7 +36,7 @@
 #define HWBUF hw->conv_buf
 #endif
 
-static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,
+static void glue(audio_init_nb_voices_, TYPE)(AudioBE *s,
                                               struct audio_driver *drv, int min_voices)
 {
     int max_voices = glue (drv->max_voices_, TYPE);
@@ -221,7 +221,7 @@ static void glue (audio_pcm_hw_del_sw_, TYPE) (SW *sw)
 static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
 {
     HW *hw = *hwp;
-    AudioState *s = hw->s;
+    AudioBE *s = hw->s;
 
     if (!hw->sw_head.lh_first) {
 #ifdef DAC
@@ -236,12 +236,12 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
     }
 }
 
-static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioState *s, HW *hw)
+static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioBE *s, HW *hw)
 {
     return hw ? hw->entries.le_next : glue (s->hw_head_, TYPE).lh_first;
 }
 
-static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioState *s, HW *hw)
+static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioBE *s, HW *hw)
 {
     while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
         if (hw->enabled) {
@@ -251,7 +251,7 @@ static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioState *s, HW *hw)
     return NULL;
 }
 
-static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioState *s, HW *hw,
+static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioBE *s, HW *hw,
                                                    struct audsettings *as)
 {
     while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
@@ -262,7 +262,7 @@ static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioState *s, HW *hw,
     return NULL;
 }
 
-static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
+static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioBE *s,
                                              struct audsettings *as)
 {
     HW *hw;
@@ -398,7 +398,7 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
     abort();
 }
 
-static HW *glue(audio_pcm_hw_add_, TYPE)(AudioState *s, struct audsettings *as)
+static HW *glue(audio_pcm_hw_add_, TYPE)(AudioBE *s, struct audsettings *as)
 {
     HW *hw;
     AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s->dev);
@@ -424,7 +424,7 @@ static HW *glue(audio_pcm_hw_add_, TYPE)(AudioState *s, struct audsettings *as)
 }
 
 static SW *glue(audio_pcm_create_voice_pair_, TYPE)(
-    AudioState *s,
+    AudioBE *s,
     const char *sw_name,
     struct audsettings *as
     )
@@ -494,7 +494,7 @@ SW *glue (AUD_open_, TYPE) (
     struct audsettings *as
     )
 {
-    AudioState *s;
+    AudioBE *s;
     AudiodevPerDirectionOptions *pdo;
 
     if (audio_bug(__func__, !card || !name || !callback_fn || !as)) {
@@ -503,7 +503,7 @@ SW *glue (AUD_open_, TYPE) (
         goto fail;
     }
 
-    s = card->state;
+    s = card->be;
     pdo = glue(audio_get_pdo_, TYPE)(s->dev);
 
     ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
diff --git a/ui/vnc.h b/ui/vnc.h
index f2dab2f4d9..a6aac50ec3 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -184,7 +184,7 @@ struct VncDisplay
     VncDisplaySASL sasl;
 #endif
 
-    AudioState *audio_state;
+    AudioBE *audio_be;
 
     VMChangeStateEntry *vmstate_handler_entry;
 };
diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
index 9b6c01c0ef..1c762e0e24 100644
--- a/audio/alsaaudio.c
+++ b/audio/alsaaudio.c
@@ -41,7 +41,7 @@ struct pollhlp {
     struct pollfd *pfds;
     int count;
     int mask;
-    AudioState *s;
+    AudioBE *s;
 };
 
 typedef struct ALSAVoiceOut {
diff --git a/audio/audio-hmp-cmds.c b/audio/audio-hmp-cmds.c
index 819f8fa9d8..f7a7d0c947 100644
--- a/audio/audio-hmp-cmds.c
+++ b/audio/audio-hmp-cmds.c
@@ -67,7 +67,7 @@ void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     const char *audiodev = qdict_get_str(qdict, "audiodev");
     CaptureState *s;
     Error *local_err = NULL;
-    AudioState *as = audio_state_by_name(audiodev, &local_err);
+    AudioBE *as = audio_be_by_name(audiodev, &local_err);
 
     if (!as) {
         error_report_err(local_err);
diff --git a/audio/audio.c b/audio/audio.c
index 9e6d79b4e3..66a2e86f13 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -99,7 +99,7 @@ static audio_driver *audio_driver_lookup(const char *name)
     return NULL;
 }
 
-static AudioState *default_audio_state;
+static AudioBE *default_audio_be;
 
 const struct mixeng_volume nominal_volume = {
     .mute = 0,
@@ -380,7 +380,7 @@ void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len)
 /*
  * Capture
  */
-static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioState *s,
+static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioBE *s,
                                                         struct audsettings *as)
 {
     CaptureVoiceOut *cap;
@@ -460,7 +460,7 @@ static void audio_detach_capture (HWVoiceOut *hw)
 
 static int audio_attach_capture (HWVoiceOut *hw)
 {
-    AudioState *s = hw->s;
+    AudioBE *s = hw->s;
     CaptureVoiceOut *cap;
 
     audio_detach_capture (hw);
@@ -798,7 +798,7 @@ static void audio_pcm_print_info (const char *cap, struct audio_pcm_info *info)
 /*
  * Timer
  */
-static int audio_is_timer_needed(AudioState *s)
+static int audio_is_timer_needed(AudioBE *s)
 {
     HWVoiceIn *hwi = NULL;
     HWVoiceOut *hwo = NULL;
@@ -816,7 +816,7 @@ static int audio_is_timer_needed(AudioState *s)
     return 0;
 }
 
-static void audio_reset_timer (AudioState *s)
+static void audio_reset_timer (AudioBE *s)
 {
     if (audio_is_timer_needed(s)) {
         timer_mod_anticipate_ns(s->ts,
@@ -838,7 +838,7 @@ static void audio_reset_timer (AudioState *s)
 static void audio_timer (void *opaque)
 {
     int64_t now, diff;
-    AudioState *s = opaque;
+    AudioBE *s = opaque;
 
     now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
     diff = now - s->timer_last;
@@ -921,7 +921,7 @@ void AUD_set_active_out (SWVoiceOut *sw, int on)
 
     hw = sw->hw;
     if (sw->active != on) {
-        AudioState *s = sw->s;
+        AudioBE *s = sw->s;
         SWVoiceOut *temp_sw;
         SWVoiceCap *sc;
 
@@ -969,7 +969,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on)
 
     hw = sw->hw;
     if (sw->active != on) {
-        AudioState *s = sw->s;
+        AudioBE *s = sw->s;
         SWVoiceIn *temp_sw;
 
         if (on) {
@@ -1137,7 +1137,7 @@ static size_t audio_pcm_hw_run_out(HWVoiceOut *hw, size_t live)
     return clipped;
 }
 
-static void audio_run_out (AudioState *s)
+static void audio_run_out (AudioBE *s)
 {
     HWVoiceOut *hw = NULL;
     SWVoiceOut *sw;
@@ -1291,7 +1291,7 @@ static size_t audio_pcm_hw_run_in(HWVoiceIn *hw, size_t samples)
     return conv;
 }
 
-static void audio_run_in (AudioState *s)
+static void audio_run_in (AudioBE *s)
 {
     HWVoiceIn *hw = NULL;
 
@@ -1339,7 +1339,7 @@ static void audio_run_in (AudioState *s)
     }
 }
 
-static void audio_run_capture (AudioState *s)
+static void audio_run_capture (AudioBE *s)
 {
     CaptureVoiceOut *cap;
 
@@ -1386,7 +1386,7 @@ static void audio_run_capture (AudioState *s)
     }
 }
 
-void audio_run(AudioState *s, const char *msg)
+void audio_run(AudioBE *s, const char *msg)
 {
     audio_run_out(s);
     audio_run_in(s);
@@ -1559,7 +1559,7 @@ size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size)
     return total;
 }
 
-static bool audio_driver_init(AudioState *s, struct audio_driver *drv,
+static bool audio_driver_init(AudioBE *s, struct audio_driver *drv,
                               Audiodev *dev, Error **errp)
 {
     s->drv_opaque = drv->init(dev, errp);
@@ -1592,7 +1592,7 @@ static bool audio_driver_init(AudioState *s, struct audio_driver *drv,
 static void audio_vm_change_state_handler (void *opaque, bool running,
                                            RunState state)
 {
-    AudioState *s = opaque;
+    AudioBE *s = opaque;
     HWVoiceOut *hwo = NULL;
     HWVoiceIn *hwi = NULL;
 
@@ -1613,9 +1613,9 @@ static void audio_vm_change_state_handler (void *opaque, bool running,
 
 static const VMStateDescription vmstate_audio;
 
-static void audio_state_init(Object *obj)
+static void audio_be_init(Object *obj)
 {
-    AudioState *s = AUDIO_STATE(obj);
+    AudioBE *s = AUDIO_BE(obj);
 
     QLIST_INIT (&s->hw_head_out);
     QLIST_INIT (&s->hw_head_in);
@@ -1629,9 +1629,9 @@ static void audio_state_init(Object *obj)
     vmstate_register_any(NULL, &vmstate_audio, s);
 }
 
-static void audio_state_finalize(Object *obj)
+static void audio_be_finalize(Object *obj)
 {
-    AudioState *s = AUDIO_STATE(obj);
+    AudioBE *s = AUDIO_BE(obj);
     HWVoiceOut *hwo, *hwon;
     HWVoiceIn *hwi, *hwin;
 
@@ -1692,7 +1692,7 @@ static Object *get_audiodevs_root(void)
 
 void audio_cleanup(void)
 {
-    default_audio_state = NULL;
+    default_audio_be = NULL;
 
     object_unparent(get_audiodevs_root());
 }
@@ -1743,14 +1743,14 @@ void audio_create_default_audiodevs(void)
  * if dev == NULL => legacy implicit initialization, return the already created
  *   state or create a new one
  */
-static AudioState *audio_init(Audiodev *dev, Error **errp)
+static AudioBE *audio_init(Audiodev *dev, Error **errp)
 {
     int done = 0;
     const char *drvname;
-    AudioState *s;
+    AudioBE *s;
     struct audio_driver *driver;
 
-    s = AUDIO_STATE(object_new(TYPE_AUDIO_STATE));
+    s = AUDIO_BE(object_new(TYPE_AUDIO_BE));
 
     if (dev) {
         /* -audiodev option */
@@ -1766,7 +1766,7 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
             goto out;
         }
     } else {
-        assert(!default_audio_state);
+        assert(!default_audio_be);
         for (;;) {
             AudiodevListEntry *e = QSIMPLEQ_FIRST(&default_audiodevs);
             if (!e) {
@@ -1797,11 +1797,11 @@ out:
     return NULL;
 }
 
-AudioState *audio_get_default_audio_state(Error **errp)
+AudioBE *audio_get_default_audio_be(Error **errp)
 {
-    if (!default_audio_state) {
-        default_audio_state = audio_init(NULL, errp);
-        if (!default_audio_state) {
+    if (!default_audio_be) {
+        default_audio_be = audio_init(NULL, errp);
+        if (!default_audio_be) {
             if (!QSIMPLEQ_EMPTY(&audiodevs)) {
                 error_append_hint(errp, "Perhaps you wanted to use -audio or set audiodev=%s?\n",
                                   QSIMPLEQ_FIRST(&audiodevs)->dev->id);
@@ -1809,21 +1809,21 @@ AudioState *audio_get_default_audio_state(Error **errp)
         }
     }
 
-    return default_audio_state;
+    return default_audio_be;
 }
 
 bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp)
 {
-    if (!card->state) {
-        card->state = audio_get_default_audio_state(errp);
-        if (!card->state) {
+    if (!card->be) {
+        card->be = audio_get_default_audio_be(errp);
+        if (!card->be) {
             return false;
         }
     }
 
     card->name = g_strdup (name);
     memset (&card->entries, 0, sizeof (card->entries));
-    QLIST_INSERT_HEAD(&card->state->card_head, card, entries);
+    QLIST_INSERT_HEAD(&card->be->card_head, card, entries);
 
     return true;
 }
@@ -1837,7 +1837,7 @@ void AUD_remove_card (QEMUSoundCard *card)
 static struct audio_pcm_ops capture_pcm_ops;
 
 CaptureVoiceOut *AUD_add_capture(
-    AudioState *s,
+    AudioBE *s,
     struct audsettings *as,
     struct audio_capture_ops *ops,
     void *cb_opaque
@@ -2220,7 +2220,7 @@ int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
         audioformat_bytes_per_sample(as->fmt);
 }
 
-AudioState *audio_state_by_name(const char *name, Error **errp)
+AudioBE *audio_be_by_name(const char *name, Error **errp)
 {
     Object *obj = object_resolve_path_component(get_audiodevs_root(), name);
 
@@ -2228,15 +2228,15 @@ AudioState *audio_state_by_name(const char *name, Error **errp)
         error_setg(errp, "audiodev '%s' not found", name);
         return NULL;
     } else {
-        return AUDIO_STATE(obj);
+        return AUDIO_BE(obj);
     }
 }
 
 const char *audio_get_id(QEMUSoundCard *card)
 {
-    if (card->state) {
-        assert(card->state->dev);
-        return card->state->dev->id;
+    if (card->be) {
+        assert(card->be->dev);
+        return card->be->dev->id;
     } else {
         return "";
     }
@@ -2305,19 +2305,19 @@ AudiodevList *qmp_query_audiodevs(Error **errp)
     return ret;
 }
 
-static const TypeInfo audio_state_info = {
-    .name = TYPE_AUDIO_STATE,
+static const TypeInfo audio_be_info = {
+    .name = TYPE_AUDIO_BE,
     .parent = TYPE_OBJECT,
-    .instance_size = sizeof(AudioState),
-    .instance_init = audio_state_init,
-    .instance_finalize = audio_state_finalize,
+    .instance_size = sizeof(AudioBE),
+    .instance_init = audio_be_init,
+    .instance_finalize = audio_be_finalize,
     .abstract = false, // todo, subclass and make it abstract
-    .class_size = sizeof(AudioStateClass),
+    .class_size = sizeof(AudioBEClass),
 };
 
 static void register_types(void)
 {
-    type_register_static(&audio_state_info);
+    type_register_static(&audio_be_info);
 }
 
 type_init(register_types);
diff --git a/audio/dbusaudio.c b/audio/dbusaudio.c
index 908214a170..873f76a89e 100644
--- a/audio/dbusaudio.c
+++ b/audio/dbusaudio.c
@@ -458,7 +458,7 @@ listener_in_vanished_cb(GDBusConnection *connection,
 }
 
 static gboolean
-dbus_audio_register_listener(AudioState *s,
+dbus_audio_register_listener(AudioBE *s,
                              GDBusMethodInvocation *invocation,
 #ifdef G_OS_UNIX
                              GUnixFDList *fd_list,
@@ -615,7 +615,7 @@ dbus_audio_register_listener(AudioState *s,
 }
 
 static gboolean
-dbus_audio_register_out_listener(AudioState *s,
+dbus_audio_register_out_listener(AudioBE *s,
                                  GDBusMethodInvocation *invocation,
 #ifdef G_OS_UNIX
                                  GUnixFDList *fd_list,
@@ -631,7 +631,7 @@ dbus_audio_register_out_listener(AudioState *s,
 }
 
 static gboolean
-dbus_audio_register_in_listener(AudioState *s,
+dbus_audio_register_in_listener(AudioBE *s,
                                 GDBusMethodInvocation *invocation,
 #ifdef G_OS_UNIX
                                 GUnixFDList *fd_list,
@@ -646,7 +646,7 @@ dbus_audio_register_in_listener(AudioState *s,
 }
 
 static void
-dbus_audio_set_server(AudioState *s, GDBusObjectManagerServer *server, bool p2p)
+dbus_audio_set_server(AudioBE *s, GDBusObjectManagerServer *server, bool p2p)
 {
     DBusAudio *da = s->drv_opaque;
 
diff --git a/audio/ossaudio.c b/audio/ossaudio.c
index c5858284a1..f202e743ff 100644
--- a/audio/ossaudio.c
+++ b/audio/ossaudio.c
@@ -107,13 +107,13 @@ static void oss_anal_close (int *fdp)
 
 static void oss_helper_poll_out (void *opaque)
 {
-    AudioState *s = opaque;
+    AudioBE *s = opaque;
     audio_run(s, "oss_poll_out");
 }
 
 static void oss_helper_poll_in (void *opaque)
 {
-    AudioState *s = opaque;
+    AudioBE *s = opaque;
     audio_run(s, "oss_poll_in");
 }
 
diff --git a/audio/wavcapture.c b/audio/wavcapture.c
index 0fbc695d23..55ba0906a2 100644
--- a/audio/wavcapture.c
+++ b/audio/wavcapture.c
@@ -103,7 +103,7 @@ static struct capture_ops wav_capture_ops = {
     .info = wav_capture_info
 };
 
-int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
+int wav_start_capture(AudioBE *state, CaptureState *s, const char *path,
                       int freq, int bits, int nchannels)
 {
     WAVState *wav;
diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
index c8c63b7915..e9ab5ac41b 100644
--- a/hw/audio/pcspk.c
+++ b/hw/audio/pcspk.c
@@ -188,7 +188,7 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
 
     isa_register_ioport(isadev, &s->ioport, s->iobase);
 
-    if (s->card.state && AUD_register_card(s_spk, &s->card, errp)) {
+    if (s->card.be && AUD_register_card(s_spk, &s->card, errp)) {
         pcspk_audio_init(s);
     }
 }
diff --git a/hw/core/machine.c b/hw/core/machine.c
index 681adbb7ac..2de8b89606 100644
--- a/hw/core/machine.c
+++ b/hw/core/machine.c
@@ -763,7 +763,7 @@ static void machine_set_audiodev(Object *obj, const char *value,
 {
     MachineState *ms = MACHINE(obj);
 
-    if (!audio_state_by_name(value, errp)) {
+    if (!audio_be_by_name(value, errp)) {
         return;
     }
 
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index 1f810b7ddf..be682895f7 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -499,16 +499,16 @@ static void set_audiodev(Object *obj, Visitor *v, const char* name,
 {
     const Property *prop = opaque;
     QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
-    AudioState *state;
+    AudioBE *state;
     g_autofree char *str = NULL;
 
     if (!visit_type_str(v, name, &str, errp)) {
         return;
     }
 
-    state = audio_state_by_name(str, errp);
+    state = audio_be_by_name(str, errp);
     if (state) {
-        card->state = state;
+        card->be = state;
     }
 }
 
diff --git a/ui/dbus.c b/ui/dbus.c
index dd0336702d..962b4a8c1e 100644
--- a/ui/dbus.c
+++ b/ui/dbus.c
@@ -220,16 +220,16 @@ dbus_display_complete(UserCreatable *uc, Error **errp)
     }
 
     if (dd->audiodev && *dd->audiodev) {
-        AudioState *audio_state = audio_state_by_name(dd->audiodev, errp);
-        if (!audio_state) {
+        AudioBE *audio_be = audio_be_by_name(dd->audiodev, errp);
+        if (!audio_be) {
             return;
         }
-        if (!g_str_equal(audio_state->drv->name, "dbus")) {
+        if (!g_str_equal(audio_be->drv->name, "dbus")) {
             error_setg(errp, "Audiodev '%s' is not compatible with DBus",
                        dd->audiodev);
             return;
         }
-        audio_state->drv->set_dbus_server(audio_state, dd->server, dd->p2p);
+        audio_be->drv->set_dbus_server(audio_be, dd->server, dd->p2p);
     }
 
     consoles = g_array_new(FALSE, FALSE, sizeof(guint32));
diff --git a/ui/vnc.c b/ui/vnc.c
index 77c823bf2e..0094ec680c 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1276,7 +1276,7 @@ static void audio_add(VncState *vs)
     ops.destroy = audio_capture_destroy;
     ops.capture = audio_capture;
 
-    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, &ops, vs);
+    vs->audio_cap = AUD_add_capture(vs->vd->audio_be, &vs->as, &ops, vs);
     if (!vs->audio_cap) {
         error_report("Failed to add audio capture");
     }
@@ -2193,7 +2193,7 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
             send_ext_key_event_ack(vs);
             break;
         case VNC_ENCODING_AUDIO:
-            if (vs->vd->audio_state) {
+            if (vs->vd->audio_be) {
                 vnc_set_feature(vs, VNC_FEATURE_AUDIO);
                 send_ext_audio_ack(vs);
             }
@@ -4236,12 +4236,12 @@ void vnc_display_open(const char *id, Error **errp)
 
     audiodev = qemu_opt_get(opts, "audiodev");
     if (audiodev) {
-        vd->audio_state = audio_state_by_name(audiodev, errp);
-        if (!vd->audio_state) {
+        vd->audio_be = audio_be_by_name(audiodev, errp);
+        if (!vd->audio_be) {
             goto fail;
         }
     } else {
-        vd->audio_state = audio_get_default_audio_state(NULL);
+        vd->audio_be = audio_get_default_audio_be(NULL);
     }
 
     device_id = qemu_opt_get(opts, "display");
-- 
2.51.0


Re: [PATCH 34/43] audio: rename AudioState -> AudioBE
Posted by Paolo Bonzini 1 week, 2 days ago
On 10/21/25 11:03, marcandre.lureau@redhat.com wrote:
> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> 
> Naming is hard. But in general in QEMU, a host "backend" is the term
> used to fullfill the request made by the device "frontend".
> 
> Note that "audiodev" is the corresponding QAPI type name (or configuration).

BE and FE aren't used in existing code though.  Looking at current use:

- BlockDriverState*/BlockBackend*

- Chardev*/CharBackend

- NetClientState*/NICState*

... it's actually quite common for the *frontend* to have a pointer or 
object of type FooBackend; that would give Audiodev* and AudioBackend*.

Paolo

> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>   audio/audio.h                    | 18 +++----
>   audio/audio_int.h                | 20 +++----
>   audio/audio_template.h           | 20 +++----
>   ui/vnc.h                         |  2 +-
>   audio/alsaaudio.c                |  2 +-
>   audio/audio-hmp-cmds.c           |  2 +-
>   audio/audio.c                    | 90 ++++++++++++++++----------------
>   audio/dbusaudio.c                |  8 +--
>   audio/ossaudio.c                 |  4 +-
>   audio/wavcapture.c               |  2 +-
>   hw/audio/pcspk.c                 |  2 +-
>   hw/core/machine.c                |  2 +-
>   hw/core/qdev-properties-system.c |  6 +--
>   ui/dbus.c                        |  8 +--
>   ui/vnc.c                         | 10 ++--
>   15 files changed, 98 insertions(+), 98 deletions(-)
> 
> diff --git a/audio/audio.h b/audio/audio.h
> index 1858b930ca..845e078169 100644
> --- a/audio/audio.h
> +++ b/audio/audio.h
> @@ -64,15 +64,15 @@ typedef struct SWVoiceOut SWVoiceOut;
>   typedef struct CaptureVoiceOut CaptureVoiceOut;
>   typedef struct SWVoiceIn SWVoiceIn;
>   
> -typedef struct AudioStateClass AudioStateClass;
> -struct AudioStateClass {
> +typedef struct AudioBEClass AudioBEClass;
> +struct AudioBEClass {
>       ObjectClass parent_class;
>   };
>   
> -typedef struct AudioState AudioState;
> +typedef struct AudioBE AudioBE;
>   typedef struct QEMUSoundCard {
>       char *name;
> -    AudioState *state;
> +    AudioBE *be;
>       QLIST_ENTRY (QEMUSoundCard) entries;
>   } QEMUSoundCard;
>   
> @@ -83,7 +83,7 @@ typedef struct QEMUAudioTimeStamp {
>   bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp);
>   void AUD_remove_card (QEMUSoundCard *card);
>   CaptureVoiceOut *AUD_add_capture(
> -    AudioState *s,
> +    AudioBE *s,
>       struct audsettings *as,
>       struct audio_capture_ops *ops,
>       void *opaque
> @@ -154,14 +154,14 @@ void audio_create_default_audiodevs(void);
>   void audio_init_audiodevs(void);
>   void audio_help(void);
>   
> -AudioState *audio_state_by_name(const char *name, Error **errp);
> -AudioState *audio_get_default_audio_state(Error **errp);
> +AudioBE *audio_be_by_name(const char *name, Error **errp);
> +AudioBE *audio_get_default_audio_be(Error **errp);
>   const char *audio_get_id(QEMUSoundCard *card);
>   
>   #define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
>       DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
>   
> -#define TYPE_AUDIO_STATE "audio-state"
> -OBJECT_DECLARE_TYPE(AudioState, AudioStateClass, AUDIO_STATE)
> +#define TYPE_AUDIO_BE "audio-be"
> +OBJECT_DECLARE_TYPE(AudioBE, AudioBEClass, AUDIO_BE)
>   
>   #endif /* QEMU_AUDIO_H */
> diff --git a/audio/audio_int.h b/audio/audio_int.h
> index cc7a6fe087..d7e24ec089 100644
> --- a/audio/audio_int.h
> +++ b/audio/audio_int.h
> @@ -57,7 +57,7 @@ struct audio_pcm_info {
>       int swap_endianness;
>   };
>   
> -typedef struct AudioState AudioState;
> +typedef struct AudioBE AudioBE;
>   typedef struct SWVoiceCap SWVoiceCap;
>   
>   typedef struct STSampleBuffer {
> @@ -66,7 +66,7 @@ typedef struct STSampleBuffer {
>   } STSampleBuffer;
>   
>   typedef struct HWVoiceOut {
> -    AudioState *s;
> +    AudioBE *s;
>       int enabled;
>       int poll_mode;
>       int pending_disable;
> @@ -87,7 +87,7 @@ typedef struct HWVoiceOut {
>   } HWVoiceOut;
>   
>   typedef struct HWVoiceIn {
> -    AudioState *s;
> +    AudioBE *s;
>       int enabled;
>       int poll_mode;
>       struct audio_pcm_info info;
> @@ -109,7 +109,7 @@ typedef struct HWVoiceIn {
>   
>   struct SWVoiceOut {
>       QEMUSoundCard *card;
> -    AudioState *s;
> +    AudioBE *s;
>       struct audio_pcm_info info;
>       t_sample *conv;
>       STSampleBuffer resample_buf;
> @@ -126,7 +126,7 @@ struct SWVoiceOut {
>   
>   struct SWVoiceIn {
>       QEMUSoundCard *card;
> -    AudioState *s;
> +    AudioBE *s;
>       int active;
>       struct audio_pcm_info info;
>       void *rate;
> @@ -147,7 +147,7 @@ struct audio_driver {
>       void *(*init) (Audiodev *, Error **);
>       void (*fini) (void *);
>   #ifdef CONFIG_GIO
> -    void (*set_dbus_server) (AudioState *s, GDBusObjectManagerServer *manager, bool p2p);
> +    void (*set_dbus_server) (AudioBE *s, GDBusObjectManagerServer *manager, bool p2p);
>   #endif
>       struct audio_pcm_ops *pcm_ops;
>       int max_voices_out;
> @@ -206,7 +206,7 @@ static inline void *advance (void *p, int incr)
>       return (d + incr);
>   }
>   
> -int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
> +int wav_start_capture(AudioBE *state, CaptureState *s, const char *path,
>                         int freq, int bits, int nchannels);
>   
>   void audio_generic_run_buffer_in(HWVoiceIn *hw);
> @@ -238,7 +238,7 @@ struct SWVoiceCap {
>       QLIST_ENTRY (SWVoiceCap) entries;
>   };
>   
> -typedef struct AudioState {
> +typedef struct AudioBE {
>       Object parent;
>   
>       struct audio_driver *drv;
> @@ -258,7 +258,7 @@ typedef struct AudioState {
>       bool timer_running;
>       uint64_t timer_last;
>       VMChangeStateEntry *vmse;
> -} AudioState;
> +} AudioBE;
>   
>   extern const struct mixeng_volume nominal_volume;
>   
> @@ -271,7 +271,7 @@ void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
>   
>   int audio_bug (const char *funcname, int cond);
>   
> -void audio_run(AudioState *s, const char *msg);
> +void audio_run(AudioBE *s, const char *msg);
>   
>   const char *audio_application_name(void);
>   
> diff --git a/audio/audio_template.h b/audio/audio_template.h
> index c29d79c443..c8f3e9dc93 100644
> --- a/audio/audio_template.h
> +++ b/audio/audio_template.h
> @@ -36,7 +36,7 @@
>   #define HWBUF hw->conv_buf
>   #endif
>   
> -static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,
> +static void glue(audio_init_nb_voices_, TYPE)(AudioBE *s,
>                                                 struct audio_driver *drv, int min_voices)
>   {
>       int max_voices = glue (drv->max_voices_, TYPE);
> @@ -221,7 +221,7 @@ static void glue (audio_pcm_hw_del_sw_, TYPE) (SW *sw)
>   static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
>   {
>       HW *hw = *hwp;
> -    AudioState *s = hw->s;
> +    AudioBE *s = hw->s;
>   
>       if (!hw->sw_head.lh_first) {
>   #ifdef DAC
> @@ -236,12 +236,12 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
>       }
>   }
>   
> -static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioState *s, HW *hw)
> +static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioBE *s, HW *hw)
>   {
>       return hw ? hw->entries.le_next : glue (s->hw_head_, TYPE).lh_first;
>   }
>   
> -static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioState *s, HW *hw)
> +static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioBE *s, HW *hw)
>   {
>       while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
>           if (hw->enabled) {
> @@ -251,7 +251,7 @@ static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioState *s, HW *hw)
>       return NULL;
>   }
>   
> -static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioState *s, HW *hw,
> +static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioBE *s, HW *hw,
>                                                      struct audsettings *as)
>   {
>       while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
> @@ -262,7 +262,7 @@ static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioState *s, HW *hw,
>       return NULL;
>   }
>   
> -static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
> +static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioBE *s,
>                                                struct audsettings *as)
>   {
>       HW *hw;
> @@ -398,7 +398,7 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
>       abort();
>   }
>   
> -static HW *glue(audio_pcm_hw_add_, TYPE)(AudioState *s, struct audsettings *as)
> +static HW *glue(audio_pcm_hw_add_, TYPE)(AudioBE *s, struct audsettings *as)
>   {
>       HW *hw;
>       AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s->dev);
> @@ -424,7 +424,7 @@ static HW *glue(audio_pcm_hw_add_, TYPE)(AudioState *s, struct audsettings *as)
>   }
>   
>   static SW *glue(audio_pcm_create_voice_pair_, TYPE)(
> -    AudioState *s,
> +    AudioBE *s,
>       const char *sw_name,
>       struct audsettings *as
>       )
> @@ -494,7 +494,7 @@ SW *glue (AUD_open_, TYPE) (
>       struct audsettings *as
>       )
>   {
> -    AudioState *s;
> +    AudioBE *s;
>       AudiodevPerDirectionOptions *pdo;
>   
>       if (audio_bug(__func__, !card || !name || !callback_fn || !as)) {
> @@ -503,7 +503,7 @@ SW *glue (AUD_open_, TYPE) (
>           goto fail;
>       }
>   
> -    s = card->state;
> +    s = card->be;
>       pdo = glue(audio_get_pdo_, TYPE)(s->dev);
>   
>       ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
> diff --git a/ui/vnc.h b/ui/vnc.h
> index f2dab2f4d9..a6aac50ec3 100644
> --- a/ui/vnc.h
> +++ b/ui/vnc.h
> @@ -184,7 +184,7 @@ struct VncDisplay
>       VncDisplaySASL sasl;
>   #endif
>   
> -    AudioState *audio_state;
> +    AudioBE *audio_be;
>   
>       VMChangeStateEntry *vmstate_handler_entry;
>   };
> diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
> index 9b6c01c0ef..1c762e0e24 100644
> --- a/audio/alsaaudio.c
> +++ b/audio/alsaaudio.c
> @@ -41,7 +41,7 @@ struct pollhlp {
>       struct pollfd *pfds;
>       int count;
>       int mask;
> -    AudioState *s;
> +    AudioBE *s;
>   };
>   
>   typedef struct ALSAVoiceOut {
> diff --git a/audio/audio-hmp-cmds.c b/audio/audio-hmp-cmds.c
> index 819f8fa9d8..f7a7d0c947 100644
> --- a/audio/audio-hmp-cmds.c
> +++ b/audio/audio-hmp-cmds.c
> @@ -67,7 +67,7 @@ void hmp_wavcapture(Monitor *mon, const QDict *qdict)
>       const char *audiodev = qdict_get_str(qdict, "audiodev");
>       CaptureState *s;
>       Error *local_err = NULL;
> -    AudioState *as = audio_state_by_name(audiodev, &local_err);
> +    AudioBE *as = audio_be_by_name(audiodev, &local_err);
>   
>       if (!as) {
>           error_report_err(local_err);
> diff --git a/audio/audio.c b/audio/audio.c
> index 9e6d79b4e3..66a2e86f13 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
> @@ -99,7 +99,7 @@ static audio_driver *audio_driver_lookup(const char *name)
>       return NULL;
>   }
>   
> -static AudioState *default_audio_state;
> +static AudioBE *default_audio_be;
>   
>   const struct mixeng_volume nominal_volume = {
>       .mute = 0,
> @@ -380,7 +380,7 @@ void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len)
>   /*
>    * Capture
>    */
> -static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioState *s,
> +static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioBE *s,
>                                                           struct audsettings *as)
>   {
>       CaptureVoiceOut *cap;
> @@ -460,7 +460,7 @@ static void audio_detach_capture (HWVoiceOut *hw)
>   
>   static int audio_attach_capture (HWVoiceOut *hw)
>   {
> -    AudioState *s = hw->s;
> +    AudioBE *s = hw->s;
>       CaptureVoiceOut *cap;
>   
>       audio_detach_capture (hw);
> @@ -798,7 +798,7 @@ static void audio_pcm_print_info (const char *cap, struct audio_pcm_info *info)
>   /*
>    * Timer
>    */
> -static int audio_is_timer_needed(AudioState *s)
> +static int audio_is_timer_needed(AudioBE *s)
>   {
>       HWVoiceIn *hwi = NULL;
>       HWVoiceOut *hwo = NULL;
> @@ -816,7 +816,7 @@ static int audio_is_timer_needed(AudioState *s)
>       return 0;
>   }
>   
> -static void audio_reset_timer (AudioState *s)
> +static void audio_reset_timer (AudioBE *s)
>   {
>       if (audio_is_timer_needed(s)) {
>           timer_mod_anticipate_ns(s->ts,
> @@ -838,7 +838,7 @@ static void audio_reset_timer (AudioState *s)
>   static void audio_timer (void *opaque)
>   {
>       int64_t now, diff;
> -    AudioState *s = opaque;
> +    AudioBE *s = opaque;
>   
>       now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>       diff = now - s->timer_last;
> @@ -921,7 +921,7 @@ void AUD_set_active_out (SWVoiceOut *sw, int on)
>   
>       hw = sw->hw;
>       if (sw->active != on) {
> -        AudioState *s = sw->s;
> +        AudioBE *s = sw->s;
>           SWVoiceOut *temp_sw;
>           SWVoiceCap *sc;
>   
> @@ -969,7 +969,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on)
>   
>       hw = sw->hw;
>       if (sw->active != on) {
> -        AudioState *s = sw->s;
> +        AudioBE *s = sw->s;
>           SWVoiceIn *temp_sw;
>   
>           if (on) {
> @@ -1137,7 +1137,7 @@ static size_t audio_pcm_hw_run_out(HWVoiceOut *hw, size_t live)
>       return clipped;
>   }
>   
> -static void audio_run_out (AudioState *s)
> +static void audio_run_out (AudioBE *s)
>   {
>       HWVoiceOut *hw = NULL;
>       SWVoiceOut *sw;
> @@ -1291,7 +1291,7 @@ static size_t audio_pcm_hw_run_in(HWVoiceIn *hw, size_t samples)
>       return conv;
>   }
>   
> -static void audio_run_in (AudioState *s)
> +static void audio_run_in (AudioBE *s)
>   {
>       HWVoiceIn *hw = NULL;
>   
> @@ -1339,7 +1339,7 @@ static void audio_run_in (AudioState *s)
>       }
>   }
>   
> -static void audio_run_capture (AudioState *s)
> +static void audio_run_capture (AudioBE *s)
>   {
>       CaptureVoiceOut *cap;
>   
> @@ -1386,7 +1386,7 @@ static void audio_run_capture (AudioState *s)
>       }
>   }
>   
> -void audio_run(AudioState *s, const char *msg)
> +void audio_run(AudioBE *s, const char *msg)
>   {
>       audio_run_out(s);
>       audio_run_in(s);
> @@ -1559,7 +1559,7 @@ size_t audio_generic_read(HWVoiceIn *hw, void *buf, size_t size)
>       return total;
>   }
>   
> -static bool audio_driver_init(AudioState *s, struct audio_driver *drv,
> +static bool audio_driver_init(AudioBE *s, struct audio_driver *drv,
>                                 Audiodev *dev, Error **errp)
>   {
>       s->drv_opaque = drv->init(dev, errp);
> @@ -1592,7 +1592,7 @@ static bool audio_driver_init(AudioState *s, struct audio_driver *drv,
>   static void audio_vm_change_state_handler (void *opaque, bool running,
>                                              RunState state)
>   {
> -    AudioState *s = opaque;
> +    AudioBE *s = opaque;
>       HWVoiceOut *hwo = NULL;
>       HWVoiceIn *hwi = NULL;
>   
> @@ -1613,9 +1613,9 @@ static void audio_vm_change_state_handler (void *opaque, bool running,
>   
>   static const VMStateDescription vmstate_audio;
>   
> -static void audio_state_init(Object *obj)
> +static void audio_be_init(Object *obj)
>   {
> -    AudioState *s = AUDIO_STATE(obj);
> +    AudioBE *s = AUDIO_BE(obj);
>   
>       QLIST_INIT (&s->hw_head_out);
>       QLIST_INIT (&s->hw_head_in);
> @@ -1629,9 +1629,9 @@ static void audio_state_init(Object *obj)
>       vmstate_register_any(NULL, &vmstate_audio, s);
>   }
>   
> -static void audio_state_finalize(Object *obj)
> +static void audio_be_finalize(Object *obj)
>   {
> -    AudioState *s = AUDIO_STATE(obj);
> +    AudioBE *s = AUDIO_BE(obj);
>       HWVoiceOut *hwo, *hwon;
>       HWVoiceIn *hwi, *hwin;
>   
> @@ -1692,7 +1692,7 @@ static Object *get_audiodevs_root(void)
>   
>   void audio_cleanup(void)
>   {
> -    default_audio_state = NULL;
> +    default_audio_be = NULL;
>   
>       object_unparent(get_audiodevs_root());
>   }
> @@ -1743,14 +1743,14 @@ void audio_create_default_audiodevs(void)
>    * if dev == NULL => legacy implicit initialization, return the already created
>    *   state or create a new one
>    */
> -static AudioState *audio_init(Audiodev *dev, Error **errp)
> +static AudioBE *audio_init(Audiodev *dev, Error **errp)
>   {
>       int done = 0;
>       const char *drvname;
> -    AudioState *s;
> +    AudioBE *s;
>       struct audio_driver *driver;
>   
> -    s = AUDIO_STATE(object_new(TYPE_AUDIO_STATE));
> +    s = AUDIO_BE(object_new(TYPE_AUDIO_BE));
>   
>       if (dev) {
>           /* -audiodev option */
> @@ -1766,7 +1766,7 @@ static AudioState *audio_init(Audiodev *dev, Error **errp)
>               goto out;
>           }
>       } else {
> -        assert(!default_audio_state);
> +        assert(!default_audio_be);
>           for (;;) {
>               AudiodevListEntry *e = QSIMPLEQ_FIRST(&default_audiodevs);
>               if (!e) {
> @@ -1797,11 +1797,11 @@ out:
>       return NULL;
>   }
>   
> -AudioState *audio_get_default_audio_state(Error **errp)
> +AudioBE *audio_get_default_audio_be(Error **errp)
>   {
> -    if (!default_audio_state) {
> -        default_audio_state = audio_init(NULL, errp);
> -        if (!default_audio_state) {
> +    if (!default_audio_be) {
> +        default_audio_be = audio_init(NULL, errp);
> +        if (!default_audio_be) {
>               if (!QSIMPLEQ_EMPTY(&audiodevs)) {
>                   error_append_hint(errp, "Perhaps you wanted to use -audio or set audiodev=%s?\n",
>                                     QSIMPLEQ_FIRST(&audiodevs)->dev->id);
> @@ -1809,21 +1809,21 @@ AudioState *audio_get_default_audio_state(Error **errp)
>           }
>       }
>   
> -    return default_audio_state;
> +    return default_audio_be;
>   }
>   
>   bool AUD_register_card (const char *name, QEMUSoundCard *card, Error **errp)
>   {
> -    if (!card->state) {
> -        card->state = audio_get_default_audio_state(errp);
> -        if (!card->state) {
> +    if (!card->be) {
> +        card->be = audio_get_default_audio_be(errp);
> +        if (!card->be) {
>               return false;
>           }
>       }
>   
>       card->name = g_strdup (name);
>       memset (&card->entries, 0, sizeof (card->entries));
> -    QLIST_INSERT_HEAD(&card->state->card_head, card, entries);
> +    QLIST_INSERT_HEAD(&card->be->card_head, card, entries);
>   
>       return true;
>   }
> @@ -1837,7 +1837,7 @@ void AUD_remove_card (QEMUSoundCard *card)
>   static struct audio_pcm_ops capture_pcm_ops;
>   
>   CaptureVoiceOut *AUD_add_capture(
> -    AudioState *s,
> +    AudioBE *s,
>       struct audsettings *as,
>       struct audio_capture_ops *ops,
>       void *cb_opaque
> @@ -2220,7 +2220,7 @@ int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
>           audioformat_bytes_per_sample(as->fmt);
>   }
>   
> -AudioState *audio_state_by_name(const char *name, Error **errp)
> +AudioBE *audio_be_by_name(const char *name, Error **errp)
>   {
>       Object *obj = object_resolve_path_component(get_audiodevs_root(), name);
>   
> @@ -2228,15 +2228,15 @@ AudioState *audio_state_by_name(const char *name, Error **errp)
>           error_setg(errp, "audiodev '%s' not found", name);
>           return NULL;
>       } else {
> -        return AUDIO_STATE(obj);
> +        return AUDIO_BE(obj);
>       }
>   }
>   
>   const char *audio_get_id(QEMUSoundCard *card)
>   {
> -    if (card->state) {
> -        assert(card->state->dev);
> -        return card->state->dev->id;
> +    if (card->be) {
> +        assert(card->be->dev);
> +        return card->be->dev->id;
>       } else {
>           return "";
>       }
> @@ -2305,19 +2305,19 @@ AudiodevList *qmp_query_audiodevs(Error **errp)
>       return ret;
>   }
>   
> -static const TypeInfo audio_state_info = {
> -    .name = TYPE_AUDIO_STATE,
> +static const TypeInfo audio_be_info = {
> +    .name = TYPE_AUDIO_BE,
>       .parent = TYPE_OBJECT,
> -    .instance_size = sizeof(AudioState),
> -    .instance_init = audio_state_init,
> -    .instance_finalize = audio_state_finalize,
> +    .instance_size = sizeof(AudioBE),
> +    .instance_init = audio_be_init,
> +    .instance_finalize = audio_be_finalize,
>       .abstract = false, // todo, subclass and make it abstract
> -    .class_size = sizeof(AudioStateClass),
> +    .class_size = sizeof(AudioBEClass),
>   };
>   
>   static void register_types(void)
>   {
> -    type_register_static(&audio_state_info);
> +    type_register_static(&audio_be_info);
>   }
>   
>   type_init(register_types);
> diff --git a/audio/dbusaudio.c b/audio/dbusaudio.c
> index 908214a170..873f76a89e 100644
> --- a/audio/dbusaudio.c
> +++ b/audio/dbusaudio.c
> @@ -458,7 +458,7 @@ listener_in_vanished_cb(GDBusConnection *connection,
>   }
>   
>   static gboolean
> -dbus_audio_register_listener(AudioState *s,
> +dbus_audio_register_listener(AudioBE *s,
>                                GDBusMethodInvocation *invocation,
>   #ifdef G_OS_UNIX
>                                GUnixFDList *fd_list,
> @@ -615,7 +615,7 @@ dbus_audio_register_listener(AudioState *s,
>   }
>   
>   static gboolean
> -dbus_audio_register_out_listener(AudioState *s,
> +dbus_audio_register_out_listener(AudioBE *s,
>                                    GDBusMethodInvocation *invocation,
>   #ifdef G_OS_UNIX
>                                    GUnixFDList *fd_list,
> @@ -631,7 +631,7 @@ dbus_audio_register_out_listener(AudioState *s,
>   }
>   
>   static gboolean
> -dbus_audio_register_in_listener(AudioState *s,
> +dbus_audio_register_in_listener(AudioBE *s,
>                                   GDBusMethodInvocation *invocation,
>   #ifdef G_OS_UNIX
>                                   GUnixFDList *fd_list,
> @@ -646,7 +646,7 @@ dbus_audio_register_in_listener(AudioState *s,
>   }
>   
>   static void
> -dbus_audio_set_server(AudioState *s, GDBusObjectManagerServer *server, bool p2p)
> +dbus_audio_set_server(AudioBE *s, GDBusObjectManagerServer *server, bool p2p)
>   {
>       DBusAudio *da = s->drv_opaque;
>   
> diff --git a/audio/ossaudio.c b/audio/ossaudio.c
> index c5858284a1..f202e743ff 100644
> --- a/audio/ossaudio.c
> +++ b/audio/ossaudio.c
> @@ -107,13 +107,13 @@ static void oss_anal_close (int *fdp)
>   
>   static void oss_helper_poll_out (void *opaque)
>   {
> -    AudioState *s = opaque;
> +    AudioBE *s = opaque;
>       audio_run(s, "oss_poll_out");
>   }
>   
>   static void oss_helper_poll_in (void *opaque)
>   {
> -    AudioState *s = opaque;
> +    AudioBE *s = opaque;
>       audio_run(s, "oss_poll_in");
>   }
>   
> diff --git a/audio/wavcapture.c b/audio/wavcapture.c
> index 0fbc695d23..55ba0906a2 100644
> --- a/audio/wavcapture.c
> +++ b/audio/wavcapture.c
> @@ -103,7 +103,7 @@ static struct capture_ops wav_capture_ops = {
>       .info = wav_capture_info
>   };
>   
> -int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
> +int wav_start_capture(AudioBE *state, CaptureState *s, const char *path,
>                         int freq, int bits, int nchannels)
>   {
>       WAVState *wav;
> diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
> index c8c63b7915..e9ab5ac41b 100644
> --- a/hw/audio/pcspk.c
> +++ b/hw/audio/pcspk.c
> @@ -188,7 +188,7 @@ static void pcspk_realizefn(DeviceState *dev, Error **errp)
>   
>       isa_register_ioport(isadev, &s->ioport, s->iobase);
>   
> -    if (s->card.state && AUD_register_card(s_spk, &s->card, errp)) {
> +    if (s->card.be && AUD_register_card(s_spk, &s->card, errp)) {
>           pcspk_audio_init(s);
>       }
>   }
> diff --git a/hw/core/machine.c b/hw/core/machine.c
> index 681adbb7ac..2de8b89606 100644
> --- a/hw/core/machine.c
> +++ b/hw/core/machine.c
> @@ -763,7 +763,7 @@ static void machine_set_audiodev(Object *obj, const char *value,
>   {
>       MachineState *ms = MACHINE(obj);
>   
> -    if (!audio_state_by_name(value, errp)) {
> +    if (!audio_be_by_name(value, errp)) {
>           return;
>       }
>   
> diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
> index 1f810b7ddf..be682895f7 100644
> --- a/hw/core/qdev-properties-system.c
> +++ b/hw/core/qdev-properties-system.c
> @@ -499,16 +499,16 @@ static void set_audiodev(Object *obj, Visitor *v, const char* name,
>   {
>       const Property *prop = opaque;
>       QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
> -    AudioState *state;
> +    AudioBE *state;
>       g_autofree char *str = NULL;
>   
>       if (!visit_type_str(v, name, &str, errp)) {
>           return;
>       }
>   
> -    state = audio_state_by_name(str, errp);
> +    state = audio_be_by_name(str, errp);
>       if (state) {
> -        card->state = state;
> +        card->be = state;
>       }
>   }
>   
> diff --git a/ui/dbus.c b/ui/dbus.c
> index dd0336702d..962b4a8c1e 100644
> --- a/ui/dbus.c
> +++ b/ui/dbus.c
> @@ -220,16 +220,16 @@ dbus_display_complete(UserCreatable *uc, Error **errp)
>       }
>   
>       if (dd->audiodev && *dd->audiodev) {
> -        AudioState *audio_state = audio_state_by_name(dd->audiodev, errp);
> -        if (!audio_state) {
> +        AudioBE *audio_be = audio_be_by_name(dd->audiodev, errp);
> +        if (!audio_be) {
>               return;
>           }
> -        if (!g_str_equal(audio_state->drv->name, "dbus")) {
> +        if (!g_str_equal(audio_be->drv->name, "dbus")) {
>               error_setg(errp, "Audiodev '%s' is not compatible with DBus",
>                          dd->audiodev);
>               return;
>           }
> -        audio_state->drv->set_dbus_server(audio_state, dd->server, dd->p2p);
> +        audio_be->drv->set_dbus_server(audio_be, dd->server, dd->p2p);
>       }
>   
>       consoles = g_array_new(FALSE, FALSE, sizeof(guint32));
> diff --git a/ui/vnc.c b/ui/vnc.c
> index 77c823bf2e..0094ec680c 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -1276,7 +1276,7 @@ static void audio_add(VncState *vs)
>       ops.destroy = audio_capture_destroy;
>       ops.capture = audio_capture;
>   
> -    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, &ops, vs);
> +    vs->audio_cap = AUD_add_capture(vs->vd->audio_be, &vs->as, &ops, vs);
>       if (!vs->audio_cap) {
>           error_report("Failed to add audio capture");
>       }
> @@ -2193,7 +2193,7 @@ static void set_encodings(VncState *vs, int32_t *encodings, size_t n_encodings)
>               send_ext_key_event_ack(vs);
>               break;
>           case VNC_ENCODING_AUDIO:
> -            if (vs->vd->audio_state) {
> +            if (vs->vd->audio_be) {
>                   vnc_set_feature(vs, VNC_FEATURE_AUDIO);
>                   send_ext_audio_ack(vs);
>               }
> @@ -4236,12 +4236,12 @@ void vnc_display_open(const char *id, Error **errp)
>   
>       audiodev = qemu_opt_get(opts, "audiodev");
>       if (audiodev) {
> -        vd->audio_state = audio_state_by_name(audiodev, errp);
> -        if (!vd->audio_state) {
> +        vd->audio_be = audio_be_by_name(audiodev, errp);
> +        if (!vd->audio_be) {
>               goto fail;
>           }
>       } else {
> -        vd->audio_state = audio_get_default_audio_state(NULL);
> +        vd->audio_be = audio_get_default_audio_be(NULL);
>       }
>   
>       device_id = qemu_opt_get(opts, "display");


Re: [PATCH 34/43] audio: rename AudioState -> AudioBE
Posted by Paolo Bonzini 1 week, 2 days ago
On 10/21/25 11:30, Paolo Bonzini wrote:
> On 10/21/25 11:03, marcandre.lureau@redhat.com wrote:
>> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>>
>> Naming is hard. But in general in QEMU, a host "backend" is the term
>> used to fullfill the request made by the device "frontend".
>>
>> Note that "audiodev" is the corresponding QAPI type name (or 
>> configuration).
> 
> BE and FE aren't used in existing code though.  Looking at current use:
> 
> - BlockDriverState*/BlockBackend*
> 
> - Chardev*/CharBackend
> 
> - NetClientState*/NICState*
> 
> ... it's actually quite common for the *frontend* to have a pointer or 
> object of type FooBackend; that would give Audiodev* and AudioBackend*.

Hmm, I have to correct myself.

QEMUSoundCard's name field is basically unused, and QEMUSoundCard should 
be just an Audiodev*.  There's no need for a separate AudioFE struct.

Paolo

> Paolo
> 
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> ---
>>   audio/audio.h                    | 18 +++----
>>   audio/audio_int.h                | 20 +++----
>>   audio/audio_template.h           | 20 +++----
>>   ui/vnc.h                         |  2 +-
>>   audio/alsaaudio.c                |  2 +-
>>   audio/audio-hmp-cmds.c           |  2 +-
>>   audio/audio.c                    | 90 ++++++++++++++++----------------
>>   audio/dbusaudio.c                |  8 +--
>>   audio/ossaudio.c                 |  4 +-
>>   audio/wavcapture.c               |  2 +-
>>   hw/audio/pcspk.c                 |  2 +-
>>   hw/core/machine.c                |  2 +-
>>   hw/core/qdev-properties-system.c |  6 +--
>>   ui/dbus.c                        |  8 +--
>>   ui/vnc.c                         | 10 ++--
>>   15 files changed, 98 insertions(+), 98 deletions(-)
>>
>> diff --git a/audio/audio.h b/audio/audio.h
>> index 1858b930ca..845e078169 100644
>> --- a/audio/audio.h
>> +++ b/audio/audio.h
>> @@ -64,15 +64,15 @@ typedef struct SWVoiceOut SWVoiceOut;
>>   typedef struct CaptureVoiceOut CaptureVoiceOut;
>>   typedef struct SWVoiceIn SWVoiceIn;
>> -typedef struct AudioStateClass AudioStateClass;
>> -struct AudioStateClass {
>> +typedef struct AudioBEClass AudioBEClass;
>> +struct AudioBEClass {
>>       ObjectClass parent_class;
>>   };
>> -typedef struct AudioState AudioState;
>> +typedef struct AudioBE AudioBE;
>>   typedef struct QEMUSoundCard {
>>       char *name;
>> -    AudioState *state;
>> +    AudioBE *be;
>>       QLIST_ENTRY (QEMUSoundCard) entries;
>>   } QEMUSoundCard;
>> @@ -83,7 +83,7 @@ typedef struct QEMUAudioTimeStamp {
>>   bool AUD_register_card (const char *name, QEMUSoundCard *card, Error 
>> **errp);
>>   void AUD_remove_card (QEMUSoundCard *card);
>>   CaptureVoiceOut *AUD_add_capture(
>> -    AudioState *s,
>> +    AudioBE *s,
>>       struct audsettings *as,
>>       struct audio_capture_ops *ops,
>>       void *opaque
>> @@ -154,14 +154,14 @@ void audio_create_default_audiodevs(void);
>>   void audio_init_audiodevs(void);
>>   void audio_help(void);
>> -AudioState *audio_state_by_name(const char *name, Error **errp);
>> -AudioState *audio_get_default_audio_state(Error **errp);
>> +AudioBE *audio_be_by_name(const char *name, Error **errp);
>> +AudioBE *audio_get_default_audio_be(Error **errp);
>>   const char *audio_get_id(QEMUSoundCard *card);
>>   #define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
>>       DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
>> -#define TYPE_AUDIO_STATE "audio-state"
>> -OBJECT_DECLARE_TYPE(AudioState, AudioStateClass, AUDIO_STATE)
>> +#define TYPE_AUDIO_BE "audio-be"
>> +OBJECT_DECLARE_TYPE(AudioBE, AudioBEClass, AUDIO_BE)
>>   #endif /* QEMU_AUDIO_H */
>> diff --git a/audio/audio_int.h b/audio/audio_int.h
>> index cc7a6fe087..d7e24ec089 100644
>> --- a/audio/audio_int.h
>> +++ b/audio/audio_int.h
>> @@ -57,7 +57,7 @@ struct audio_pcm_info {
>>       int swap_endianness;
>>   };
>> -typedef struct AudioState AudioState;
>> +typedef struct AudioBE AudioBE;
>>   typedef struct SWVoiceCap SWVoiceCap;
>>   typedef struct STSampleBuffer {
>> @@ -66,7 +66,7 @@ typedef struct STSampleBuffer {
>>   } STSampleBuffer;
>>   typedef struct HWVoiceOut {
>> -    AudioState *s;
>> +    AudioBE *s;
>>       int enabled;
>>       int poll_mode;
>>       int pending_disable;
>> @@ -87,7 +87,7 @@ typedef struct HWVoiceOut {
>>   } HWVoiceOut;
>>   typedef struct HWVoiceIn {
>> -    AudioState *s;
>> +    AudioBE *s;
>>       int enabled;
>>       int poll_mode;
>>       struct audio_pcm_info info;
>> @@ -109,7 +109,7 @@ typedef struct HWVoiceIn {
>>   struct SWVoiceOut {
>>       QEMUSoundCard *card;
>> -    AudioState *s;
>> +    AudioBE *s;
>>       struct audio_pcm_info info;
>>       t_sample *conv;
>>       STSampleBuffer resample_buf;
>> @@ -126,7 +126,7 @@ struct SWVoiceOut {
>>   struct SWVoiceIn {
>>       QEMUSoundCard *card;
>> -    AudioState *s;
>> +    AudioBE *s;
>>       int active;
>>       struct audio_pcm_info info;
>>       void *rate;
>> @@ -147,7 +147,7 @@ struct audio_driver {
>>       void *(*init) (Audiodev *, Error **);
>>       void (*fini) (void *);
>>   #ifdef CONFIG_GIO
>> -    void (*set_dbus_server) (AudioState *s, GDBusObjectManagerServer 
>> *manager, bool p2p);
>> +    void (*set_dbus_server) (AudioBE *s, GDBusObjectManagerServer 
>> *manager, bool p2p);
>>   #endif
>>       struct audio_pcm_ops *pcm_ops;
>>       int max_voices_out;
>> @@ -206,7 +206,7 @@ static inline void *advance (void *p, int incr)
>>       return (d + incr);
>>   }
>> -int wav_start_capture(AudioState *state, CaptureState *s, const char 
>> *path,
>> +int wav_start_capture(AudioBE *state, CaptureState *s, const char *path,
>>                         int freq, int bits, int nchannels);
>>   void audio_generic_run_buffer_in(HWVoiceIn *hw);
>> @@ -238,7 +238,7 @@ struct SWVoiceCap {
>>       QLIST_ENTRY (SWVoiceCap) entries;
>>   };
>> -typedef struct AudioState {
>> +typedef struct AudioBE {
>>       Object parent;
>>       struct audio_driver *drv;
>> @@ -258,7 +258,7 @@ typedef struct AudioState {
>>       bool timer_running;
>>       uint64_t timer_last;
>>       VMChangeStateEntry *vmse;
>> -} AudioState;
>> +} AudioBE;
>>   extern const struct mixeng_volume nominal_volume;
>> @@ -271,7 +271,7 @@ void audio_pcm_info_clear_buf (struct 
>> audio_pcm_info *info, void *buf, int len);
>>   int audio_bug (const char *funcname, int cond);
>> -void audio_run(AudioState *s, const char *msg);
>> +void audio_run(AudioBE *s, const char *msg);
>>   const char *audio_application_name(void);
>> diff --git a/audio/audio_template.h b/audio/audio_template.h
>> index c29d79c443..c8f3e9dc93 100644
>> --- a/audio/audio_template.h
>> +++ b/audio/audio_template.h
>> @@ -36,7 +36,7 @@
>>   #define HWBUF hw->conv_buf
>>   #endif
>> -static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,
>> +static void glue(audio_init_nb_voices_, TYPE)(AudioBE *s,
>>                                                 struct audio_driver 
>> *drv, int min_voices)
>>   {
>>       int max_voices = glue (drv->max_voices_, TYPE);
>> @@ -221,7 +221,7 @@ static void glue (audio_pcm_hw_del_sw_, TYPE) (SW 
>> *sw)
>>   static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
>>   {
>>       HW *hw = *hwp;
>> -    AudioState *s = hw->s;
>> +    AudioBE *s = hw->s;
>>       if (!hw->sw_head.lh_first) {
>>   #ifdef DAC
>> @@ -236,12 +236,12 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW 
>> **hwp)
>>       }
>>   }
>> -static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioState *s, HW *hw)
>> +static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioBE *s, HW *hw)
>>   {
>>       return hw ? hw->entries.le_next : glue (s->hw_head_, 
>> TYPE).lh_first;
>>   }
>> -static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioState *s, 
>> HW *hw)
>> +static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioBE *s, HW 
>> *hw)
>>   {
>>       while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
>>           if (hw->enabled) {
>> @@ -251,7 +251,7 @@ static HW *glue(audio_pcm_hw_find_any_enabled_, 
>> TYPE)(AudioState *s, HW *hw)
>>       return NULL;
>>   }
>> -static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioState *s, HW 
>> *hw,
>> +static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioBE *s, HW *hw,
>>                                                      struct 
>> audsettings *as)
>>   {
>>       while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
>> @@ -262,7 +262,7 @@ static HW *glue(audio_pcm_hw_find_specific_, TYPE) 
>> (AudioState *s, HW *hw,
>>       return NULL;
>>   }
>> -static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
>> +static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioBE *s,
>>                                                struct audsettings *as)
>>   {
>>       HW *hw;
>> @@ -398,7 +398,7 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_, 
>> TYPE)(Audiodev *dev)
>>       abort();
>>   }
>> -static HW *glue(audio_pcm_hw_add_, TYPE)(AudioState *s, struct 
>> audsettings *as)
>> +static HW *glue(audio_pcm_hw_add_, TYPE)(AudioBE *s, struct 
>> audsettings *as)
>>   {
>>       HW *hw;
>>       AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s- 
>> >dev);
>> @@ -424,7 +424,7 @@ static HW *glue(audio_pcm_hw_add_, TYPE) 
>> (AudioState *s, struct audsettings *as)
>>   }
>>   static SW *glue(audio_pcm_create_voice_pair_, TYPE)(
>> -    AudioState *s,
>> +    AudioBE *s,
>>       const char *sw_name,
>>       struct audsettings *as
>>       )
>> @@ -494,7 +494,7 @@ SW *glue (AUD_open_, TYPE) (
>>       struct audsettings *as
>>       )
>>   {
>> -    AudioState *s;
>> +    AudioBE *s;
>>       AudiodevPerDirectionOptions *pdo;
>>       if (audio_bug(__func__, !card || !name || !callback_fn || !as)) {
>> @@ -503,7 +503,7 @@ SW *glue (AUD_open_, TYPE) (
>>           goto fail;
>>       }
>> -    s = card->state;
>> +    s = card->be;
>>       pdo = glue(audio_get_pdo_, TYPE)(s->dev);
>>       ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
>> diff --git a/ui/vnc.h b/ui/vnc.h
>> index f2dab2f4d9..a6aac50ec3 100644
>> --- a/ui/vnc.h
>> +++ b/ui/vnc.h
>> @@ -184,7 +184,7 @@ struct VncDisplay
>>       VncDisplaySASL sasl;
>>   #endif
>> -    AudioState *audio_state;
>> +    AudioBE *audio_be;
>>       VMChangeStateEntry *vmstate_handler_entry;
>>   };
>> diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
>> index 9b6c01c0ef..1c762e0e24 100644
>> --- a/audio/alsaaudio.c
>> +++ b/audio/alsaaudio.c
>> @@ -41,7 +41,7 @@ struct pollhlp {
>>       struct pollfd *pfds;
>>       int count;
>>       int mask;
>> -    AudioState *s;
>> +    AudioBE *s;
>>   };
>>   typedef struct ALSAVoiceOut {
>> diff --git a/audio/audio-hmp-cmds.c b/audio/audio-hmp-cmds.c
>> index 819f8fa9d8..f7a7d0c947 100644
>> --- a/audio/audio-hmp-cmds.c
>> +++ b/audio/audio-hmp-cmds.c
>> @@ -67,7 +67,7 @@ void hmp_wavcapture(Monitor *mon, const QDict *qdict)
>>       const char *audiodev = qdict_get_str(qdict, "audiodev");
>>       CaptureState *s;
>>       Error *local_err = NULL;
>> -    AudioState *as = audio_state_by_name(audiodev, &local_err);
>> +    AudioBE *as = audio_be_by_name(audiodev, &local_err);
>>       if (!as) {
>>           error_report_err(local_err);
>> diff --git a/audio/audio.c b/audio/audio.c
>> index 9e6d79b4e3..66a2e86f13 100644
>> --- a/audio/audio.c
>> +++ b/audio/audio.c
>> @@ -99,7 +99,7 @@ static audio_driver *audio_driver_lookup(const char 
>> *name)
>>       return NULL;
>>   }
>> -static AudioState *default_audio_state;
>> +static AudioBE *default_audio_be;
>>   const struct mixeng_volume nominal_volume = {
>>       .mute = 0,
>> @@ -380,7 +380,7 @@ void audio_pcm_info_clear_buf (struct 
>> audio_pcm_info *info, void *buf, int len)
>>   /*
>>    * Capture
>>    */
>> -static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioState *s,
>> +static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioBE *s,
>>                                                           struct 
>> audsettings *as)
>>   {
>>       CaptureVoiceOut *cap;
>> @@ -460,7 +460,7 @@ static void audio_detach_capture (HWVoiceOut *hw)
>>   static int audio_attach_capture (HWVoiceOut *hw)
>>   {
>> -    AudioState *s = hw->s;
>> +    AudioBE *s = hw->s;
>>       CaptureVoiceOut *cap;
>>       audio_detach_capture (hw);
>> @@ -798,7 +798,7 @@ static void audio_pcm_print_info (const char *cap, 
>> struct audio_pcm_info *info)
>>   /*
>>    * Timer
>>    */
>> -static int audio_is_timer_needed(AudioState *s)
>> +static int audio_is_timer_needed(AudioBE *s)
>>   {
>>       HWVoiceIn *hwi = NULL;
>>       HWVoiceOut *hwo = NULL;
>> @@ -816,7 +816,7 @@ static int audio_is_timer_needed(AudioState *s)
>>       return 0;
>>   }
>> -static void audio_reset_timer (AudioState *s)
>> +static void audio_reset_timer (AudioBE *s)
>>   {
>>       if (audio_is_timer_needed(s)) {
>>           timer_mod_anticipate_ns(s->ts,
>> @@ -838,7 +838,7 @@ static void audio_reset_timer (AudioState *s)
>>   static void audio_timer (void *opaque)
>>   {
>>       int64_t now, diff;
>> -    AudioState *s = opaque;
>> +    AudioBE *s = opaque;
>>       now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
>>       diff = now - s->timer_last;
>> @@ -921,7 +921,7 @@ void AUD_set_active_out (SWVoiceOut *sw, int on)
>>       hw = sw->hw;
>>       if (sw->active != on) {
>> -        AudioState *s = sw->s;
>> +        AudioBE *s = sw->s;
>>           SWVoiceOut *temp_sw;
>>           SWVoiceCap *sc;
>> @@ -969,7 +969,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on)
>>       hw = sw->hw;
>>       if (sw->active != on) {
>> -        AudioState *s = sw->s;
>> +        AudioBE *s = sw->s;
>>           SWVoiceIn *temp_sw;
>>           if (on) {
>> @@ -1137,7 +1137,7 @@ static size_t audio_pcm_hw_run_out(HWVoiceOut 
>> *hw, size_t live)
>>       return clipped;
>>   }
>> -static void audio_run_out (AudioState *s)
>> +static void audio_run_out (AudioBE *s)
>>   {
>>       HWVoiceOut *hw = NULL;
>>       SWVoiceOut *sw;
>> @@ -1291,7 +1291,7 @@ static size_t audio_pcm_hw_run_in(HWVoiceIn *hw, 
>> size_t samples)
>>       return conv;
>>   }
>> -static void audio_run_in (AudioState *s)
>> +static void audio_run_in (AudioBE *s)
>>   {
>>       HWVoiceIn *hw = NULL;
>> @@ -1339,7 +1339,7 @@ static void audio_run_in (AudioState *s)
>>       }
>>   }
>> -static void audio_run_capture (AudioState *s)
>> +static void audio_run_capture (AudioBE *s)
>>   {
>>       CaptureVoiceOut *cap;
>> @@ -1386,7 +1386,7 @@ static void audio_run_capture (AudioState *s)
>>       }
>>   }
>> -void audio_run(AudioState *s, const char *msg)
>> +void audio_run(AudioBE *s, const char *msg)
>>   {
>>       audio_run_out(s);
>>       audio_run_in(s);
>> @@ -1559,7 +1559,7 @@ size_t audio_generic_read(HWVoiceIn *hw, void 
>> *buf, size_t size)
>>       return total;
>>   }
>> -static bool audio_driver_init(AudioState *s, struct audio_driver *drv,
>> +static bool audio_driver_init(AudioBE *s, struct audio_driver *drv,
>>                                 Audiodev *dev, Error **errp)
>>   {
>>       s->drv_opaque = drv->init(dev, errp);
>> @@ -1592,7 +1592,7 @@ static bool audio_driver_init(AudioState *s, 
>> struct audio_driver *drv,
>>   static void audio_vm_change_state_handler (void *opaque, bool running,
>>                                              RunState state)
>>   {
>> -    AudioState *s = opaque;
>> +    AudioBE *s = opaque;
>>       HWVoiceOut *hwo = NULL;
>>       HWVoiceIn *hwi = NULL;
>> @@ -1613,9 +1613,9 @@ static void audio_vm_change_state_handler (void 
>> *opaque, bool running,
>>   static const VMStateDescription vmstate_audio;
>> -static void audio_state_init(Object *obj)
>> +static void audio_be_init(Object *obj)
>>   {
>> -    AudioState *s = AUDIO_STATE(obj);
>> +    AudioBE *s = AUDIO_BE(obj);
>>       QLIST_INIT (&s->hw_head_out);
>>       QLIST_INIT (&s->hw_head_in);
>> @@ -1629,9 +1629,9 @@ static void audio_state_init(Object *obj)
>>       vmstate_register_any(NULL, &vmstate_audio, s);
>>   }
>> -static void audio_state_finalize(Object *obj)
>> +static void audio_be_finalize(Object *obj)
>>   {
>> -    AudioState *s = AUDIO_STATE(obj);
>> +    AudioBE *s = AUDIO_BE(obj);
>>       HWVoiceOut *hwo, *hwon;
>>       HWVoiceIn *hwi, *hwin;
>> @@ -1692,7 +1692,7 @@ static Object *get_audiodevs_root(void)
>>   void audio_cleanup(void)
>>   {
>> -    default_audio_state = NULL;
>> +    default_audio_be = NULL;
>>       object_unparent(get_audiodevs_root());
>>   }
>> @@ -1743,14 +1743,14 @@ void audio_create_default_audiodevs(void)
>>    * if dev == NULL => legacy implicit initialization, return the 
>> already created
>>    *   state or create a new one
>>    */
>> -static AudioState *audio_init(Audiodev *dev, Error **errp)
>> +static AudioBE *audio_init(Audiodev *dev, Error **errp)
>>   {
>>       int done = 0;
>>       const char *drvname;
>> -    AudioState *s;
>> +    AudioBE *s;
>>       struct audio_driver *driver;
>> -    s = AUDIO_STATE(object_new(TYPE_AUDIO_STATE));
>> +    s = AUDIO_BE(object_new(TYPE_AUDIO_BE));
>>       if (dev) {
>>           /* -audiodev option */
>> @@ -1766,7 +1766,7 @@ static AudioState *audio_init(Audiodev *dev, 
>> Error **errp)
>>               goto out;
>>           }
>>       } else {
>> -        assert(!default_audio_state);
>> +        assert(!default_audio_be);
>>           for (;;) {
>>               AudiodevListEntry *e = QSIMPLEQ_FIRST(&default_audiodevs);
>>               if (!e) {
>> @@ -1797,11 +1797,11 @@ out:
>>       return NULL;
>>   }
>> -AudioState *audio_get_default_audio_state(Error **errp)
>> +AudioBE *audio_get_default_audio_be(Error **errp)
>>   {
>> -    if (!default_audio_state) {
>> -        default_audio_state = audio_init(NULL, errp);
>> -        if (!default_audio_state) {
>> +    if (!default_audio_be) {
>> +        default_audio_be = audio_init(NULL, errp);
>> +        if (!default_audio_be) {
>>               if (!QSIMPLEQ_EMPTY(&audiodevs)) {
>>                   error_append_hint(errp, "Perhaps you wanted to use - 
>> audio or set audiodev=%s?\n",
>>                                     QSIMPLEQ_FIRST(&audiodevs)->dev->id);
>> @@ -1809,21 +1809,21 @@ AudioState 
>> *audio_get_default_audio_state(Error **errp)
>>           }
>>       }
>> -    return default_audio_state;
>> +    return default_audio_be;
>>   }
>>   bool AUD_register_card (const char *name, QEMUSoundCard *card, Error 
>> **errp)
>>   {
>> -    if (!card->state) {
>> -        card->state = audio_get_default_audio_state(errp);
>> -        if (!card->state) {
>> +    if (!card->be) {
>> +        card->be = audio_get_default_audio_be(errp);
>> +        if (!card->be) {
>>               return false;
>>           }
>>       }
>>       card->name = g_strdup (name);
>>       memset (&card->entries, 0, sizeof (card->entries));
>> -    QLIST_INSERT_HEAD(&card->state->card_head, card, entries);
>> +    QLIST_INSERT_HEAD(&card->be->card_head, card, entries);
>>       return true;
>>   }
>> @@ -1837,7 +1837,7 @@ void AUD_remove_card (QEMUSoundCard *card)
>>   static struct audio_pcm_ops capture_pcm_ops;
>>   CaptureVoiceOut *AUD_add_capture(
>> -    AudioState *s,
>> +    AudioBE *s,
>>       struct audsettings *as,
>>       struct audio_capture_ops *ops,
>>       void *cb_opaque
>> @@ -2220,7 +2220,7 @@ int 
>> audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
>>           audioformat_bytes_per_sample(as->fmt);
>>   }
>> -AudioState *audio_state_by_name(const char *name, Error **errp)
>> +AudioBE *audio_be_by_name(const char *name, Error **errp)
>>   {
>>       Object *obj = 
>> object_resolve_path_component(get_audiodevs_root(), name);
>> @@ -2228,15 +2228,15 @@ AudioState *audio_state_by_name(const char 
>> *name, Error **errp)
>>           error_setg(errp, "audiodev '%s' not found", name);
>>           return NULL;
>>       } else {
>> -        return AUDIO_STATE(obj);
>> +        return AUDIO_BE(obj);
>>       }
>>   }
>>   const char *audio_get_id(QEMUSoundCard *card)
>>   {
>> -    if (card->state) {
>> -        assert(card->state->dev);
>> -        return card->state->dev->id;
>> +    if (card->be) {
>> +        assert(card->be->dev);
>> +        return card->be->dev->id;
>>       } else {
>>           return "";
>>       }
>> @@ -2305,19 +2305,19 @@ AudiodevList *qmp_query_audiodevs(Error **errp)
>>       return ret;
>>   }
>> -static const TypeInfo audio_state_info = {
>> -    .name = TYPE_AUDIO_STATE,
>> +static const TypeInfo audio_be_info = {
>> +    .name = TYPE_AUDIO_BE,
>>       .parent = TYPE_OBJECT,
>> -    .instance_size = sizeof(AudioState),
>> -    .instance_init = audio_state_init,
>> -    .instance_finalize = audio_state_finalize,
>> +    .instance_size = sizeof(AudioBE),
>> +    .instance_init = audio_be_init,
>> +    .instance_finalize = audio_be_finalize,
>>       .abstract = false, // todo, subclass and make it abstract
>> -    .class_size = sizeof(AudioStateClass),
>> +    .class_size = sizeof(AudioBEClass),
>>   };
>>   static void register_types(void)
>>   {
>> -    type_register_static(&audio_state_info);
>> +    type_register_static(&audio_be_info);
>>   }
>>   type_init(register_types);
>> diff --git a/audio/dbusaudio.c b/audio/dbusaudio.c
>> index 908214a170..873f76a89e 100644
>> --- a/audio/dbusaudio.c
>> +++ b/audio/dbusaudio.c
>> @@ -458,7 +458,7 @@ listener_in_vanished_cb(GDBusConnection *connection,
>>   }
>>   static gboolean
>> -dbus_audio_register_listener(AudioState *s,
>> +dbus_audio_register_listener(AudioBE *s,
>>                                GDBusMethodInvocation *invocation,
>>   #ifdef G_OS_UNIX
>>                                GUnixFDList *fd_list,
>> @@ -615,7 +615,7 @@ dbus_audio_register_listener(AudioState *s,
>>   }
>>   static gboolean
>> -dbus_audio_register_out_listener(AudioState *s,
>> +dbus_audio_register_out_listener(AudioBE *s,
>>                                    GDBusMethodInvocation *invocation,
>>   #ifdef G_OS_UNIX
>>                                    GUnixFDList *fd_list,
>> @@ -631,7 +631,7 @@ dbus_audio_register_out_listener(AudioState *s,
>>   }
>>   static gboolean
>> -dbus_audio_register_in_listener(AudioState *s,
>> +dbus_audio_register_in_listener(AudioBE *s,
>>                                   GDBusMethodInvocation *invocation,
>>   #ifdef G_OS_UNIX
>>                                   GUnixFDList *fd_list,
>> @@ -646,7 +646,7 @@ dbus_audio_register_in_listener(AudioState *s,
>>   }
>>   static void
>> -dbus_audio_set_server(AudioState *s, GDBusObjectManagerServer 
>> *server, bool p2p)
>> +dbus_audio_set_server(AudioBE *s, GDBusObjectManagerServer *server, 
>> bool p2p)
>>   {
>>       DBusAudio *da = s->drv_opaque;
>> diff --git a/audio/ossaudio.c b/audio/ossaudio.c
>> index c5858284a1..f202e743ff 100644
>> --- a/audio/ossaudio.c
>> +++ b/audio/ossaudio.c
>> @@ -107,13 +107,13 @@ static void oss_anal_close (int *fdp)
>>   static void oss_helper_poll_out (void *opaque)
>>   {
>> -    AudioState *s = opaque;
>> +    AudioBE *s = opaque;
>>       audio_run(s, "oss_poll_out");
>>   }
>>   static void oss_helper_poll_in (void *opaque)
>>   {
>> -    AudioState *s = opaque;
>> +    AudioBE *s = opaque;
>>       audio_run(s, "oss_poll_in");
>>   }
>> diff --git a/audio/wavcapture.c b/audio/wavcapture.c
>> index 0fbc695d23..55ba0906a2 100644
>> --- a/audio/wavcapture.c
>> +++ b/audio/wavcapture.c
>> @@ -103,7 +103,7 @@ static struct capture_ops wav_capture_ops = {
>>       .info = wav_capture_info
>>   };
>> -int wav_start_capture(AudioState *state, CaptureState *s, const char 
>> *path,
>> +int wav_start_capture(AudioBE *state, CaptureState *s, const char *path,
>>                         int freq, int bits, int nchannels)
>>   {
>>       WAVState *wav;
>> diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
>> index c8c63b7915..e9ab5ac41b 100644
>> --- a/hw/audio/pcspk.c
>> +++ b/hw/audio/pcspk.c
>> @@ -188,7 +188,7 @@ static void pcspk_realizefn(DeviceState *dev, 
>> Error **errp)
>>       isa_register_ioport(isadev, &s->ioport, s->iobase);
>> -    if (s->card.state && AUD_register_card(s_spk, &s->card, errp)) {
>> +    if (s->card.be && AUD_register_card(s_spk, &s->card, errp)) {
>>           pcspk_audio_init(s);
>>       }
>>   }
>> diff --git a/hw/core/machine.c b/hw/core/machine.c
>> index 681adbb7ac..2de8b89606 100644
>> --- a/hw/core/machine.c
>> +++ b/hw/core/machine.c
>> @@ -763,7 +763,7 @@ static void machine_set_audiodev(Object *obj, 
>> const char *value,
>>   {
>>       MachineState *ms = MACHINE(obj);
>> -    if (!audio_state_by_name(value, errp)) {
>> +    if (!audio_be_by_name(value, errp)) {
>>           return;
>>       }
>> diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev- 
>> properties-system.c
>> index 1f810b7ddf..be682895f7 100644
>> --- a/hw/core/qdev-properties-system.c
>> +++ b/hw/core/qdev-properties-system.c
>> @@ -499,16 +499,16 @@ static void set_audiodev(Object *obj, Visitor 
>> *v, const char* name,
>>   {
>>       const Property *prop = opaque;
>>       QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
>> -    AudioState *state;
>> +    AudioBE *state;
>>       g_autofree char *str = NULL;
>>       if (!visit_type_str(v, name, &str, errp)) {
>>           return;
>>       }
>> -    state = audio_state_by_name(str, errp);
>> +    state = audio_be_by_name(str, errp);
>>       if (state) {
>> -        card->state = state;
>> +        card->be = state;
>>       }
>>   }
>> diff --git a/ui/dbus.c b/ui/dbus.c
>> index dd0336702d..962b4a8c1e 100644
>> --- a/ui/dbus.c
>> +++ b/ui/dbus.c
>> @@ -220,16 +220,16 @@ dbus_display_complete(UserCreatable *uc, Error 
>> **errp)
>>       }
>>       if (dd->audiodev && *dd->audiodev) {
>> -        AudioState *audio_state = audio_state_by_name(dd->audiodev, 
>> errp);
>> -        if (!audio_state) {
>> +        AudioBE *audio_be = audio_be_by_name(dd->audiodev, errp);
>> +        if (!audio_be) {
>>               return;
>>           }
>> -        if (!g_str_equal(audio_state->drv->name, "dbus")) {
>> +        if (!g_str_equal(audio_be->drv->name, "dbus")) {
>>               error_setg(errp, "Audiodev '%s' is not compatible with 
>> DBus",
>>                          dd->audiodev);
>>               return;
>>           }
>> -        audio_state->drv->set_dbus_server(audio_state, dd->server, 
>> dd->p2p);
>> +        audio_be->drv->set_dbus_server(audio_be, dd->server, dd->p2p);
>>       }
>>       consoles = g_array_new(FALSE, FALSE, sizeof(guint32));
>> diff --git a/ui/vnc.c b/ui/vnc.c
>> index 77c823bf2e..0094ec680c 100644
>> --- a/ui/vnc.c
>> +++ b/ui/vnc.c
>> @@ -1276,7 +1276,7 @@ static void audio_add(VncState *vs)
>>       ops.destroy = audio_capture_destroy;
>>       ops.capture = audio_capture;
>> -    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, 
>> &ops, vs);
>> +    vs->audio_cap = AUD_add_capture(vs->vd->audio_be, &vs->as, &ops, 
>> vs);
>>       if (!vs->audio_cap) {
>>           error_report("Failed to add audio capture");
>>       }
>> @@ -2193,7 +2193,7 @@ static void set_encodings(VncState *vs, int32_t 
>> *encodings, size_t n_encodings)
>>               send_ext_key_event_ack(vs);
>>               break;
>>           case VNC_ENCODING_AUDIO:
>> -            if (vs->vd->audio_state) {
>> +            if (vs->vd->audio_be) {
>>                   vnc_set_feature(vs, VNC_FEATURE_AUDIO);
>>                   send_ext_audio_ack(vs);
>>               }
>> @@ -4236,12 +4236,12 @@ void vnc_display_open(const char *id, Error 
>> **errp)
>>       audiodev = qemu_opt_get(opts, "audiodev");
>>       if (audiodev) {
>> -        vd->audio_state = audio_state_by_name(audiodev, errp);
>> -        if (!vd->audio_state) {
>> +        vd->audio_be = audio_be_by_name(audiodev, errp);
>> +        if (!vd->audio_be) {
>>               goto fail;
>>           }
>>       } else {
>> -        vd->audio_state = audio_get_default_audio_state(NULL);
>> +        vd->audio_be = audio_get_default_audio_be(NULL);
>>       }
>>       device_id = qemu_opt_get(opts, "display");
> 
> 
> 


Re: [PATCH 34/43] audio: rename AudioState -> AudioBE
Posted by Marc-André Lureau 1 week, 2 days ago
Hi

On Tue, Oct 21, 2025 at 1:42 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 10/21/25 11:30, Paolo Bonzini wrote:
> > On 10/21/25 11:03, marcandre.lureau@redhat.com wrote:
> >> From: Marc-André Lureau <marcandre.lureau@redhat.com>
> >>
> >> Naming is hard. But in general in QEMU, a host "backend" is the term
> >> used to fullfill the request made by the device "frontend".
> >>
> >> Note that "audiodev" is the corresponding QAPI type name (or
> >> configuration).
> >
> > BE and FE aren't used in existing code though.  Looking at current use:

There is a top-level backends/ though. I meant to say that it's
usually clearer for everyone when we talk about "backend" vs
"frontend" (or not?), and I wish we would follow that naming more in
the code.

> >
> > - BlockDriverState*/BlockBackend*
> >

I am not very familiar with the block subsystem, but it is seems
BlockBackend is actually the backend and BlockDriverState is
implementation data detail. Correct me if I'm wrong

> > - Chardev*/CharBackend
> >

Those are actually always confusing... and I remember I attempted to
rename it in the past... CharBackend is the front-end side..

> > - NetClientState*/NICState*
> >
> > ... it's actually quite common for the *frontend* to have a pointer or
> > object of type FooBackend; that would give Audiodev* and AudioBackend*.
>
> Hmm, I have to correct myself.
>
> QEMUSoundCard's name field is basically unused, and QEMUSoundCard should
> be just an Audiodev*.  There's no need for a separate AudioFE struct.
>

For audio, it's pretty obvious that we have "backend" object to
implement the host audio subsystem details, while "QEMUSoundCard" is
the "frontend", or "client/user" context.

Imho, it's clearer to see the relation between the two objects if we
name them "backend" and "frontend" accordingly. If the "AudioBE" &
"AudioFE" short versions aren't readable enough, I am fine naming
"AudioBackend" & "AudioFrontend"

> Paolo
>
> > Paolo
> >
> >> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> >> ---
> >>   audio/audio.h                    | 18 +++----
> >>   audio/audio_int.h                | 20 +++----
> >>   audio/audio_template.h           | 20 +++----
> >>   ui/vnc.h                         |  2 +-
> >>   audio/alsaaudio.c                |  2 +-
> >>   audio/audio-hmp-cmds.c           |  2 +-
> >>   audio/audio.c                    | 90 ++++++++++++++++----------------
> >>   audio/dbusaudio.c                |  8 +--
> >>   audio/ossaudio.c                 |  4 +-
> >>   audio/wavcapture.c               |  2 +-
> >>   hw/audio/pcspk.c                 |  2 +-
> >>   hw/core/machine.c                |  2 +-
> >>   hw/core/qdev-properties-system.c |  6 +--
> >>   ui/dbus.c                        |  8 +--
> >>   ui/vnc.c                         | 10 ++--
> >>   15 files changed, 98 insertions(+), 98 deletions(-)
> >>
> >> diff --git a/audio/audio.h b/audio/audio.h
> >> index 1858b930ca..845e078169 100644
> >> --- a/audio/audio.h
> >> +++ b/audio/audio.h
> >> @@ -64,15 +64,15 @@ typedef struct SWVoiceOut SWVoiceOut;
> >>   typedef struct CaptureVoiceOut CaptureVoiceOut;
> >>   typedef struct SWVoiceIn SWVoiceIn;
> >> -typedef struct AudioStateClass AudioStateClass;
> >> -struct AudioStateClass {
> >> +typedef struct AudioBEClass AudioBEClass;
> >> +struct AudioBEClass {
> >>       ObjectClass parent_class;
> >>   };
> >> -typedef struct AudioState AudioState;
> >> +typedef struct AudioBE AudioBE;
> >>   typedef struct QEMUSoundCard {
> >>       char *name;
> >> -    AudioState *state;
> >> +    AudioBE *be;
> >>       QLIST_ENTRY (QEMUSoundCard) entries;
> >>   } QEMUSoundCard;
> >> @@ -83,7 +83,7 @@ typedef struct QEMUAudioTimeStamp {
> >>   bool AUD_register_card (const char *name, QEMUSoundCard *card, Error
> >> **errp);
> >>   void AUD_remove_card (QEMUSoundCard *card);
> >>   CaptureVoiceOut *AUD_add_capture(
> >> -    AudioState *s,
> >> +    AudioBE *s,
> >>       struct audsettings *as,
> >>       struct audio_capture_ops *ops,
> >>       void *opaque
> >> @@ -154,14 +154,14 @@ void audio_create_default_audiodevs(void);
> >>   void audio_init_audiodevs(void);
> >>   void audio_help(void);
> >> -AudioState *audio_state_by_name(const char *name, Error **errp);
> >> -AudioState *audio_get_default_audio_state(Error **errp);
> >> +AudioBE *audio_be_by_name(const char *name, Error **errp);
> >> +AudioBE *audio_get_default_audio_be(Error **errp);
> >>   const char *audio_get_id(QEMUSoundCard *card);
> >>   #define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
> >>       DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
> >> -#define TYPE_AUDIO_STATE "audio-state"
> >> -OBJECT_DECLARE_TYPE(AudioState, AudioStateClass, AUDIO_STATE)
> >> +#define TYPE_AUDIO_BE "audio-be"
> >> +OBJECT_DECLARE_TYPE(AudioBE, AudioBEClass, AUDIO_BE)
> >>   #endif /* QEMU_AUDIO_H */
> >> diff --git a/audio/audio_int.h b/audio/audio_int.h
> >> index cc7a6fe087..d7e24ec089 100644
> >> --- a/audio/audio_int.h
> >> +++ b/audio/audio_int.h
> >> @@ -57,7 +57,7 @@ struct audio_pcm_info {
> >>       int swap_endianness;
> >>   };
> >> -typedef struct AudioState AudioState;
> >> +typedef struct AudioBE AudioBE;
> >>   typedef struct SWVoiceCap SWVoiceCap;
> >>   typedef struct STSampleBuffer {
> >> @@ -66,7 +66,7 @@ typedef struct STSampleBuffer {
> >>   } STSampleBuffer;
> >>   typedef struct HWVoiceOut {
> >> -    AudioState *s;
> >> +    AudioBE *s;
> >>       int enabled;
> >>       int poll_mode;
> >>       int pending_disable;
> >> @@ -87,7 +87,7 @@ typedef struct HWVoiceOut {
> >>   } HWVoiceOut;
> >>   typedef struct HWVoiceIn {
> >> -    AudioState *s;
> >> +    AudioBE *s;
> >>       int enabled;
> >>       int poll_mode;
> >>       struct audio_pcm_info info;
> >> @@ -109,7 +109,7 @@ typedef struct HWVoiceIn {
> >>   struct SWVoiceOut {
> >>       QEMUSoundCard *card;
> >> -    AudioState *s;
> >> +    AudioBE *s;
> >>       struct audio_pcm_info info;
> >>       t_sample *conv;
> >>       STSampleBuffer resample_buf;
> >> @@ -126,7 +126,7 @@ struct SWVoiceOut {
> >>   struct SWVoiceIn {
> >>       QEMUSoundCard *card;
> >> -    AudioState *s;
> >> +    AudioBE *s;
> >>       int active;
> >>       struct audio_pcm_info info;
> >>       void *rate;
> >> @@ -147,7 +147,7 @@ struct audio_driver {
> >>       void *(*init) (Audiodev *, Error **);
> >>       void (*fini) (void *);
> >>   #ifdef CONFIG_GIO
> >> -    void (*set_dbus_server) (AudioState *s, GDBusObjectManagerServer
> >> *manager, bool p2p);
> >> +    void (*set_dbus_server) (AudioBE *s, GDBusObjectManagerServer
> >> *manager, bool p2p);
> >>   #endif
> >>       struct audio_pcm_ops *pcm_ops;
> >>       int max_voices_out;
> >> @@ -206,7 +206,7 @@ static inline void *advance (void *p, int incr)
> >>       return (d + incr);
> >>   }
> >> -int wav_start_capture(AudioState *state, CaptureState *s, const char
> >> *path,
> >> +int wav_start_capture(AudioBE *state, CaptureState *s, const char *path,
> >>                         int freq, int bits, int nchannels);
> >>   void audio_generic_run_buffer_in(HWVoiceIn *hw);
> >> @@ -238,7 +238,7 @@ struct SWVoiceCap {
> >>       QLIST_ENTRY (SWVoiceCap) entries;
> >>   };
> >> -typedef struct AudioState {
> >> +typedef struct AudioBE {
> >>       Object parent;
> >>       struct audio_driver *drv;
> >> @@ -258,7 +258,7 @@ typedef struct AudioState {
> >>       bool timer_running;
> >>       uint64_t timer_last;
> >>       VMChangeStateEntry *vmse;
> >> -} AudioState;
> >> +} AudioBE;
> >>   extern const struct mixeng_volume nominal_volume;
> >> @@ -271,7 +271,7 @@ void audio_pcm_info_clear_buf (struct
> >> audio_pcm_info *info, void *buf, int len);
> >>   int audio_bug (const char *funcname, int cond);
> >> -void audio_run(AudioState *s, const char *msg);
> >> +void audio_run(AudioBE *s, const char *msg);
> >>   const char *audio_application_name(void);
> >> diff --git a/audio/audio_template.h b/audio/audio_template.h
> >> index c29d79c443..c8f3e9dc93 100644
> >> --- a/audio/audio_template.h
> >> +++ b/audio/audio_template.h
> >> @@ -36,7 +36,7 @@
> >>   #define HWBUF hw->conv_buf
> >>   #endif
> >> -static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,
> >> +static void glue(audio_init_nb_voices_, TYPE)(AudioBE *s,
> >>                                                 struct audio_driver
> >> *drv, int min_voices)
> >>   {
> >>       int max_voices = glue (drv->max_voices_, TYPE);
> >> @@ -221,7 +221,7 @@ static void glue (audio_pcm_hw_del_sw_, TYPE) (SW
> >> *sw)
> >>   static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
> >>   {
> >>       HW *hw = *hwp;
> >> -    AudioState *s = hw->s;
> >> +    AudioBE *s = hw->s;
> >>       if (!hw->sw_head.lh_first) {
> >>   #ifdef DAC
> >> @@ -236,12 +236,12 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW
> >> **hwp)
> >>       }
> >>   }
> >> -static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioState *s, HW *hw)
> >> +static HW *glue(audio_pcm_hw_find_any_, TYPE)(AudioBE *s, HW *hw)
> >>   {
> >>       return hw ? hw->entries.le_next : glue (s->hw_head_,
> >> TYPE).lh_first;
> >>   }
> >> -static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioState *s,
> >> HW *hw)
> >> +static HW *glue(audio_pcm_hw_find_any_enabled_, TYPE)(AudioBE *s, HW
> >> *hw)
> >>   {
> >>       while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
> >>           if (hw->enabled) {
> >> @@ -251,7 +251,7 @@ static HW *glue(audio_pcm_hw_find_any_enabled_,
> >> TYPE)(AudioState *s, HW *hw)
> >>       return NULL;
> >>   }
> >> -static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioState *s, HW
> >> *hw,
> >> +static HW *glue(audio_pcm_hw_find_specific_, TYPE)(AudioBE *s, HW *hw,
> >>                                                      struct
> >> audsettings *as)
> >>   {
> >>       while ((hw = glue(audio_pcm_hw_find_any_, TYPE)(s, hw))) {
> >> @@ -262,7 +262,7 @@ static HW *glue(audio_pcm_hw_find_specific_, TYPE)
> >> (AudioState *s, HW *hw,
> >>       return NULL;
> >>   }
> >> -static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
> >> +static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioBE *s,
> >>                                                struct audsettings *as)
> >>   {
> >>       HW *hw;
> >> @@ -398,7 +398,7 @@ AudiodevPerDirectionOptions *glue(audio_get_pdo_,
> >> TYPE)(Audiodev *dev)
> >>       abort();
> >>   }
> >> -static HW *glue(audio_pcm_hw_add_, TYPE)(AudioState *s, struct
> >> audsettings *as)
> >> +static HW *glue(audio_pcm_hw_add_, TYPE)(AudioBE *s, struct
> >> audsettings *as)
> >>   {
> >>       HW *hw;
> >>       AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s-
> >> >dev);
> >> @@ -424,7 +424,7 @@ static HW *glue(audio_pcm_hw_add_, TYPE)
> >> (AudioState *s, struct audsettings *as)
> >>   }
> >>   static SW *glue(audio_pcm_create_voice_pair_, TYPE)(
> >> -    AudioState *s,
> >> +    AudioBE *s,
> >>       const char *sw_name,
> >>       struct audsettings *as
> >>       )
> >> @@ -494,7 +494,7 @@ SW *glue (AUD_open_, TYPE) (
> >>       struct audsettings *as
> >>       )
> >>   {
> >> -    AudioState *s;
> >> +    AudioBE *s;
> >>       AudiodevPerDirectionOptions *pdo;
> >>       if (audio_bug(__func__, !card || !name || !callback_fn || !as)) {
> >> @@ -503,7 +503,7 @@ SW *glue (AUD_open_, TYPE) (
> >>           goto fail;
> >>       }
> >> -    s = card->state;
> >> +    s = card->be;
> >>       pdo = glue(audio_get_pdo_, TYPE)(s->dev);
> >>       ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
> >> diff --git a/ui/vnc.h b/ui/vnc.h
> >> index f2dab2f4d9..a6aac50ec3 100644
> >> --- a/ui/vnc.h
> >> +++ b/ui/vnc.h
> >> @@ -184,7 +184,7 @@ struct VncDisplay
> >>       VncDisplaySASL sasl;
> >>   #endif
> >> -    AudioState *audio_state;
> >> +    AudioBE *audio_be;
> >>       VMChangeStateEntry *vmstate_handler_entry;
> >>   };
> >> diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
> >> index 9b6c01c0ef..1c762e0e24 100644
> >> --- a/audio/alsaaudio.c
> >> +++ b/audio/alsaaudio.c
> >> @@ -41,7 +41,7 @@ struct pollhlp {
> >>       struct pollfd *pfds;
> >>       int count;
> >>       int mask;
> >> -    AudioState *s;
> >> +    AudioBE *s;
> >>   };
> >>   typedef struct ALSAVoiceOut {
> >> diff --git a/audio/audio-hmp-cmds.c b/audio/audio-hmp-cmds.c
> >> index 819f8fa9d8..f7a7d0c947 100644
> >> --- a/audio/audio-hmp-cmds.c
> >> +++ b/audio/audio-hmp-cmds.c
> >> @@ -67,7 +67,7 @@ void hmp_wavcapture(Monitor *mon, const QDict *qdict)
> >>       const char *audiodev = qdict_get_str(qdict, "audiodev");
> >>       CaptureState *s;
> >>       Error *local_err = NULL;
> >> -    AudioState *as = audio_state_by_name(audiodev, &local_err);
> >> +    AudioBE *as = audio_be_by_name(audiodev, &local_err);
> >>       if (!as) {
> >>           error_report_err(local_err);
> >> diff --git a/audio/audio.c b/audio/audio.c
> >> index 9e6d79b4e3..66a2e86f13 100644
> >> --- a/audio/audio.c
> >> +++ b/audio/audio.c
> >> @@ -99,7 +99,7 @@ static audio_driver *audio_driver_lookup(const char
> >> *name)
> >>       return NULL;
> >>   }
> >> -static AudioState *default_audio_state;
> >> +static AudioBE *default_audio_be;
> >>   const struct mixeng_volume nominal_volume = {
> >>       .mute = 0,
> >> @@ -380,7 +380,7 @@ void audio_pcm_info_clear_buf (struct
> >> audio_pcm_info *info, void *buf, int len)
> >>   /*
> >>    * Capture
> >>    */
> >> -static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioState *s,
> >> +static CaptureVoiceOut *audio_pcm_capture_find_specific(AudioBE *s,
> >>                                                           struct
> >> audsettings *as)
> >>   {
> >>       CaptureVoiceOut *cap;
> >> @@ -460,7 +460,7 @@ static void audio_detach_capture (HWVoiceOut *hw)
> >>   static int audio_attach_capture (HWVoiceOut *hw)
> >>   {
> >> -    AudioState *s = hw->s;
> >> +    AudioBE *s = hw->s;
> >>       CaptureVoiceOut *cap;
> >>       audio_detach_capture (hw);
> >> @@ -798,7 +798,7 @@ static void audio_pcm_print_info (const char *cap,
> >> struct audio_pcm_info *info)
> >>   /*
> >>    * Timer
> >>    */
> >> -static int audio_is_timer_needed(AudioState *s)
> >> +static int audio_is_timer_needed(AudioBE *s)
> >>   {
> >>       HWVoiceIn *hwi = NULL;
> >>       HWVoiceOut *hwo = NULL;
> >> @@ -816,7 +816,7 @@ static int audio_is_timer_needed(AudioState *s)
> >>       return 0;
> >>   }
> >> -static void audio_reset_timer (AudioState *s)
> >> +static void audio_reset_timer (AudioBE *s)
> >>   {
> >>       if (audio_is_timer_needed(s)) {
> >>           timer_mod_anticipate_ns(s->ts,
> >> @@ -838,7 +838,7 @@ static void audio_reset_timer (AudioState *s)
> >>   static void audio_timer (void *opaque)
> >>   {
> >>       int64_t now, diff;
> >> -    AudioState *s = opaque;
> >> +    AudioBE *s = opaque;
> >>       now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
> >>       diff = now - s->timer_last;
> >> @@ -921,7 +921,7 @@ void AUD_set_active_out (SWVoiceOut *sw, int on)
> >>       hw = sw->hw;
> >>       if (sw->active != on) {
> >> -        AudioState *s = sw->s;
> >> +        AudioBE *s = sw->s;
> >>           SWVoiceOut *temp_sw;
> >>           SWVoiceCap *sc;
> >> @@ -969,7 +969,7 @@ void AUD_set_active_in (SWVoiceIn *sw, int on)
> >>       hw = sw->hw;
> >>       if (sw->active != on) {
> >> -        AudioState *s = sw->s;
> >> +        AudioBE *s = sw->s;
> >>           SWVoiceIn *temp_sw;
> >>           if (on) {
> >> @@ -1137,7 +1137,7 @@ static size_t audio_pcm_hw_run_out(HWVoiceOut
> >> *hw, size_t live)
> >>       return clipped;
> >>   }
> >> -static void audio_run_out (AudioState *s)
> >> +static void audio_run_out (AudioBE *s)
> >>   {
> >>       HWVoiceOut *hw = NULL;
> >>       SWVoiceOut *sw;
> >> @@ -1291,7 +1291,7 @@ static size_t audio_pcm_hw_run_in(HWVoiceIn *hw,
> >> size_t samples)
> >>       return conv;
> >>   }
> >> -static void audio_run_in (AudioState *s)
> >> +static void audio_run_in (AudioBE *s)
> >>   {
> >>       HWVoiceIn *hw = NULL;
> >> @@ -1339,7 +1339,7 @@ static void audio_run_in (AudioState *s)
> >>       }
> >>   }
> >> -static void audio_run_capture (AudioState *s)
> >> +static void audio_run_capture (AudioBE *s)
> >>   {
> >>       CaptureVoiceOut *cap;
> >> @@ -1386,7 +1386,7 @@ static void audio_run_capture (AudioState *s)
> >>       }
> >>   }
> >> -void audio_run(AudioState *s, const char *msg)
> >> +void audio_run(AudioBE *s, const char *msg)
> >>   {
> >>       audio_run_out(s);
> >>       audio_run_in(s);
> >> @@ -1559,7 +1559,7 @@ size_t audio_generic_read(HWVoiceIn *hw, void
> >> *buf, size_t size)
> >>       return total;
> >>   }
> >> -static bool audio_driver_init(AudioState *s, struct audio_driver *drv,
> >> +static bool audio_driver_init(AudioBE *s, struct audio_driver *drv,
> >>                                 Audiodev *dev, Error **errp)
> >>   {
> >>       s->drv_opaque = drv->init(dev, errp);
> >> @@ -1592,7 +1592,7 @@ static bool audio_driver_init(AudioState *s,
> >> struct audio_driver *drv,
> >>   static void audio_vm_change_state_handler (void *opaque, bool running,
> >>                                              RunState state)
> >>   {
> >> -    AudioState *s = opaque;
> >> +    AudioBE *s = opaque;
> >>       HWVoiceOut *hwo = NULL;
> >>       HWVoiceIn *hwi = NULL;
> >> @@ -1613,9 +1613,9 @@ static void audio_vm_change_state_handler (void
> >> *opaque, bool running,
> >>   static const VMStateDescription vmstate_audio;
> >> -static void audio_state_init(Object *obj)
> >> +static void audio_be_init(Object *obj)
> >>   {
> >> -    AudioState *s = AUDIO_STATE(obj);
> >> +    AudioBE *s = AUDIO_BE(obj);
> >>       QLIST_INIT (&s->hw_head_out);
> >>       QLIST_INIT (&s->hw_head_in);
> >> @@ -1629,9 +1629,9 @@ static void audio_state_init(Object *obj)
> >>       vmstate_register_any(NULL, &vmstate_audio, s);
> >>   }
> >> -static void audio_state_finalize(Object *obj)
> >> +static void audio_be_finalize(Object *obj)
> >>   {
> >> -    AudioState *s = AUDIO_STATE(obj);
> >> +    AudioBE *s = AUDIO_BE(obj);
> >>       HWVoiceOut *hwo, *hwon;
> >>       HWVoiceIn *hwi, *hwin;
> >> @@ -1692,7 +1692,7 @@ static Object *get_audiodevs_root(void)
> >>   void audio_cleanup(void)
> >>   {
> >> -    default_audio_state = NULL;
> >> +    default_audio_be = NULL;
> >>       object_unparent(get_audiodevs_root());
> >>   }
> >> @@ -1743,14 +1743,14 @@ void audio_create_default_audiodevs(void)
> >>    * if dev == NULL => legacy implicit initialization, return the
> >> already created
> >>    *   state or create a new one
> >>    */
> >> -static AudioState *audio_init(Audiodev *dev, Error **errp)
> >> +static AudioBE *audio_init(Audiodev *dev, Error **errp)
> >>   {
> >>       int done = 0;
> >>       const char *drvname;
> >> -    AudioState *s;
> >> +    AudioBE *s;
> >>       struct audio_driver *driver;
> >> -    s = AUDIO_STATE(object_new(TYPE_AUDIO_STATE));
> >> +    s = AUDIO_BE(object_new(TYPE_AUDIO_BE));
> >>       if (dev) {
> >>           /* -audiodev option */
> >> @@ -1766,7 +1766,7 @@ static AudioState *audio_init(Audiodev *dev,
> >> Error **errp)
> >>               goto out;
> >>           }
> >>       } else {
> >> -        assert(!default_audio_state);
> >> +        assert(!default_audio_be);
> >>           for (;;) {
> >>               AudiodevListEntry *e = QSIMPLEQ_FIRST(&default_audiodevs);
> >>               if (!e) {
> >> @@ -1797,11 +1797,11 @@ out:
> >>       return NULL;
> >>   }
> >> -AudioState *audio_get_default_audio_state(Error **errp)
> >> +AudioBE *audio_get_default_audio_be(Error **errp)
> >>   {
> >> -    if (!default_audio_state) {
> >> -        default_audio_state = audio_init(NULL, errp);
> >> -        if (!default_audio_state) {
> >> +    if (!default_audio_be) {
> >> +        default_audio_be = audio_init(NULL, errp);
> >> +        if (!default_audio_be) {
> >>               if (!QSIMPLEQ_EMPTY(&audiodevs)) {
> >>                   error_append_hint(errp, "Perhaps you wanted to use -
> >> audio or set audiodev=%s?\n",
> >>                                     QSIMPLEQ_FIRST(&audiodevs)->dev->id);
> >> @@ -1809,21 +1809,21 @@ AudioState
> >> *audio_get_default_audio_state(Error **errp)
> >>           }
> >>       }
> >> -    return default_audio_state;
> >> +    return default_audio_be;
> >>   }
> >>   bool AUD_register_card (const char *name, QEMUSoundCard *card, Error
> >> **errp)
> >>   {
> >> -    if (!card->state) {
> >> -        card->state = audio_get_default_audio_state(errp);
> >> -        if (!card->state) {
> >> +    if (!card->be) {
> >> +        card->be = audio_get_default_audio_be(errp);
> >> +        if (!card->be) {
> >>               return false;
> >>           }
> >>       }
> >>       card->name = g_strdup (name);
> >>       memset (&card->entries, 0, sizeof (card->entries));
> >> -    QLIST_INSERT_HEAD(&card->state->card_head, card, entries);
> >> +    QLIST_INSERT_HEAD(&card->be->card_head, card, entries);
> >>       return true;
> >>   }
> >> @@ -1837,7 +1837,7 @@ void AUD_remove_card (QEMUSoundCard *card)
> >>   static struct audio_pcm_ops capture_pcm_ops;
> >>   CaptureVoiceOut *AUD_add_capture(
> >> -    AudioState *s,
> >> +    AudioBE *s,
> >>       struct audsettings *as,
> >>       struct audio_capture_ops *ops,
> >>       void *cb_opaque
> >> @@ -2220,7 +2220,7 @@ int
> >> audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
> >>           audioformat_bytes_per_sample(as->fmt);
> >>   }
> >> -AudioState *audio_state_by_name(const char *name, Error **errp)
> >> +AudioBE *audio_be_by_name(const char *name, Error **errp)
> >>   {
> >>       Object *obj =
> >> object_resolve_path_component(get_audiodevs_root(), name);
> >> @@ -2228,15 +2228,15 @@ AudioState *audio_state_by_name(const char
> >> *name, Error **errp)
> >>           error_setg(errp, "audiodev '%s' not found", name);
> >>           return NULL;
> >>       } else {
> >> -        return AUDIO_STATE(obj);
> >> +        return AUDIO_BE(obj);
> >>       }
> >>   }
> >>   const char *audio_get_id(QEMUSoundCard *card)
> >>   {
> >> -    if (card->state) {
> >> -        assert(card->state->dev);
> >> -        return card->state->dev->id;
> >> +    if (card->be) {
> >> +        assert(card->be->dev);
> >> +        return card->be->dev->id;
> >>       } else {
> >>           return "";
> >>       }
> >> @@ -2305,19 +2305,19 @@ AudiodevList *qmp_query_audiodevs(Error **errp)
> >>       return ret;
> >>   }
> >> -static const TypeInfo audio_state_info = {
> >> -    .name = TYPE_AUDIO_STATE,
> >> +static const TypeInfo audio_be_info = {
> >> +    .name = TYPE_AUDIO_BE,
> >>       .parent = TYPE_OBJECT,
> >> -    .instance_size = sizeof(AudioState),
> >> -    .instance_init = audio_state_init,
> >> -    .instance_finalize = audio_state_finalize,
> >> +    .instance_size = sizeof(AudioBE),
> >> +    .instance_init = audio_be_init,
> >> +    .instance_finalize = audio_be_finalize,
> >>       .abstract = false, // todo, subclass and make it abstract
> >> -    .class_size = sizeof(AudioStateClass),
> >> +    .class_size = sizeof(AudioBEClass),
> >>   };
> >>   static void register_types(void)
> >>   {
> >> -    type_register_static(&audio_state_info);
> >> +    type_register_static(&audio_be_info);
> >>   }
> >>   type_init(register_types);
> >> diff --git a/audio/dbusaudio.c b/audio/dbusaudio.c
> >> index 908214a170..873f76a89e 100644
> >> --- a/audio/dbusaudio.c
> >> +++ b/audio/dbusaudio.c
> >> @@ -458,7 +458,7 @@ listener_in_vanished_cb(GDBusConnection *connection,
> >>   }
> >>   static gboolean
> >> -dbus_audio_register_listener(AudioState *s,
> >> +dbus_audio_register_listener(AudioBE *s,
> >>                                GDBusMethodInvocation *invocation,
> >>   #ifdef G_OS_UNIX
> >>                                GUnixFDList *fd_list,
> >> @@ -615,7 +615,7 @@ dbus_audio_register_listener(AudioState *s,
> >>   }
> >>   static gboolean
> >> -dbus_audio_register_out_listener(AudioState *s,
> >> +dbus_audio_register_out_listener(AudioBE *s,
> >>                                    GDBusMethodInvocation *invocation,
> >>   #ifdef G_OS_UNIX
> >>                                    GUnixFDList *fd_list,
> >> @@ -631,7 +631,7 @@ dbus_audio_register_out_listener(AudioState *s,
> >>   }
> >>   static gboolean
> >> -dbus_audio_register_in_listener(AudioState *s,
> >> +dbus_audio_register_in_listener(AudioBE *s,
> >>                                   GDBusMethodInvocation *invocation,
> >>   #ifdef G_OS_UNIX
> >>                                   GUnixFDList *fd_list,
> >> @@ -646,7 +646,7 @@ dbus_audio_register_in_listener(AudioState *s,
> >>   }
> >>   static void
> >> -dbus_audio_set_server(AudioState *s, GDBusObjectManagerServer
> >> *server, bool p2p)
> >> +dbus_audio_set_server(AudioBE *s, GDBusObjectManagerServer *server,
> >> bool p2p)
> >>   {
> >>       DBusAudio *da = s->drv_opaque;
> >> diff --git a/audio/ossaudio.c b/audio/ossaudio.c
> >> index c5858284a1..f202e743ff 100644
> >> --- a/audio/ossaudio.c
> >> +++ b/audio/ossaudio.c
> >> @@ -107,13 +107,13 @@ static void oss_anal_close (int *fdp)
> >>   static void oss_helper_poll_out (void *opaque)
> >>   {
> >> -    AudioState *s = opaque;
> >> +    AudioBE *s = opaque;
> >>       audio_run(s, "oss_poll_out");
> >>   }
> >>   static void oss_helper_poll_in (void *opaque)
> >>   {
> >> -    AudioState *s = opaque;
> >> +    AudioBE *s = opaque;
> >>       audio_run(s, "oss_poll_in");
> >>   }
> >> diff --git a/audio/wavcapture.c b/audio/wavcapture.c
> >> index 0fbc695d23..55ba0906a2 100644
> >> --- a/audio/wavcapture.c
> >> +++ b/audio/wavcapture.c
> >> @@ -103,7 +103,7 @@ static struct capture_ops wav_capture_ops = {
> >>       .info = wav_capture_info
> >>   };
> >> -int wav_start_capture(AudioState *state, CaptureState *s, const char
> >> *path,
> >> +int wav_start_capture(AudioBE *state, CaptureState *s, const char *path,
> >>                         int freq, int bits, int nchannels)
> >>   {
> >>       WAVState *wav;
> >> diff --git a/hw/audio/pcspk.c b/hw/audio/pcspk.c
> >> index c8c63b7915..e9ab5ac41b 100644
> >> --- a/hw/audio/pcspk.c
> >> +++ b/hw/audio/pcspk.c
> >> @@ -188,7 +188,7 @@ static void pcspk_realizefn(DeviceState *dev,
> >> Error **errp)
> >>       isa_register_ioport(isadev, &s->ioport, s->iobase);
> >> -    if (s->card.state && AUD_register_card(s_spk, &s->card, errp)) {
> >> +    if (s->card.be && AUD_register_card(s_spk, &s->card, errp)) {
> >>           pcspk_audio_init(s);
> >>       }
> >>   }
> >> diff --git a/hw/core/machine.c b/hw/core/machine.c
> >> index 681adbb7ac..2de8b89606 100644
> >> --- a/hw/core/machine.c
> >> +++ b/hw/core/machine.c
> >> @@ -763,7 +763,7 @@ static void machine_set_audiodev(Object *obj,
> >> const char *value,
> >>   {
> >>       MachineState *ms = MACHINE(obj);
> >> -    if (!audio_state_by_name(value, errp)) {
> >> +    if (!audio_be_by_name(value, errp)) {
> >>           return;
> >>       }
> >> diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-
> >> properties-system.c
> >> index 1f810b7ddf..be682895f7 100644
> >> --- a/hw/core/qdev-properties-system.c
> >> +++ b/hw/core/qdev-properties-system.c
> >> @@ -499,16 +499,16 @@ static void set_audiodev(Object *obj, Visitor
> >> *v, const char* name,
> >>   {
> >>       const Property *prop = opaque;
> >>       QEMUSoundCard *card = object_field_prop_ptr(obj, prop);
> >> -    AudioState *state;
> >> +    AudioBE *state;
> >>       g_autofree char *str = NULL;
> >>       if (!visit_type_str(v, name, &str, errp)) {
> >>           return;
> >>       }
> >> -    state = audio_state_by_name(str, errp);
> >> +    state = audio_be_by_name(str, errp);
> >>       if (state) {
> >> -        card->state = state;
> >> +        card->be = state;
> >>       }
> >>   }
> >> diff --git a/ui/dbus.c b/ui/dbus.c
> >> index dd0336702d..962b4a8c1e 100644
> >> --- a/ui/dbus.c
> >> +++ b/ui/dbus.c
> >> @@ -220,16 +220,16 @@ dbus_display_complete(UserCreatable *uc, Error
> >> **errp)
> >>       }
> >>       if (dd->audiodev && *dd->audiodev) {
> >> -        AudioState *audio_state = audio_state_by_name(dd->audiodev,
> >> errp);
> >> -        if (!audio_state) {
> >> +        AudioBE *audio_be = audio_be_by_name(dd->audiodev, errp);
> >> +        if (!audio_be) {
> >>               return;
> >>           }
> >> -        if (!g_str_equal(audio_state->drv->name, "dbus")) {
> >> +        if (!g_str_equal(audio_be->drv->name, "dbus")) {
> >>               error_setg(errp, "Audiodev '%s' is not compatible with
> >> DBus",
> >>                          dd->audiodev);
> >>               return;
> >>           }
> >> -        audio_state->drv->set_dbus_server(audio_state, dd->server,
> >> dd->p2p);
> >> +        audio_be->drv->set_dbus_server(audio_be, dd->server, dd->p2p);
> >>       }
> >>       consoles = g_array_new(FALSE, FALSE, sizeof(guint32));
> >> diff --git a/ui/vnc.c b/ui/vnc.c
> >> index 77c823bf2e..0094ec680c 100644
> >> --- a/ui/vnc.c
> >> +++ b/ui/vnc.c
> >> @@ -1276,7 +1276,7 @@ static void audio_add(VncState *vs)
> >>       ops.destroy = audio_capture_destroy;
> >>       ops.capture = audio_capture;
> >> -    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as,
> >> &ops, vs);
> >> +    vs->audio_cap = AUD_add_capture(vs->vd->audio_be, &vs->as, &ops,
> >> vs);
> >>       if (!vs->audio_cap) {
> >>           error_report("Failed to add audio capture");
> >>       }
> >> @@ -2193,7 +2193,7 @@ static void set_encodings(VncState *vs, int32_t
> >> *encodings, size_t n_encodings)
> >>               send_ext_key_event_ack(vs);
> >>               break;
> >>           case VNC_ENCODING_AUDIO:
> >> -            if (vs->vd->audio_state) {
> >> +            if (vs->vd->audio_be) {
> >>                   vnc_set_feature(vs, VNC_FEATURE_AUDIO);
> >>                   send_ext_audio_ack(vs);
> >>               }
> >> @@ -4236,12 +4236,12 @@ void vnc_display_open(const char *id, Error
> >> **errp)
> >>       audiodev = qemu_opt_get(opts, "audiodev");
> >>       if (audiodev) {
> >> -        vd->audio_state = audio_state_by_name(audiodev, errp);
> >> -        if (!vd->audio_state) {
> >> +        vd->audio_be = audio_be_by_name(audiodev, errp);
> >> +        if (!vd->audio_be) {
> >>               goto fail;
> >>           }
> >>       } else {
> >> -        vd->audio_state = audio_get_default_audio_state(NULL);
> >> +        vd->audio_be = audio_get_default_audio_be(NULL);
> >>       }
> >>       device_id = qemu_opt_get(opts, "display");
> >
> >
> >
>
>


-- 
Marc-André Lureau
Re: [PATCH 34/43] audio: rename AudioState -> AudioBE
Posted by BALATON Zoltan 1 week, 2 days ago
On Tue, 21 Oct 2025, Marc-André Lureau wrote:
> Hi
>
> On Tue, Oct 21, 2025 at 1:42 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> On 10/21/25 11:30, Paolo Bonzini wrote:
>>> On 10/21/25 11:03, marcandre.lureau@redhat.com wrote:
>>>> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>>>>
>>>> Naming is hard. But in general in QEMU, a host "backend" is the term
>>>> used to fullfill the request made by the device "frontend".
>>>>
>>>> Note that "audiodev" is the corresponding QAPI type name (or
>>>> configuration).
>>>
>>> BE and FE aren't used in existing code though.  Looking at current use:
>
> There is a top-level backends/ though. I meant to say that it's
> usually clearer for everyone when we talk about "backend" vs
> "frontend" (or not?), and I wish we would follow that naming more in
> the code.
>
>>>
>>> - BlockDriverState*/BlockBackend*
>>>
>
> I am not very familiar with the block subsystem, but it is seems
> BlockBackend is actually the backend and BlockDriverState is
> implementation data detail. Correct me if I'm wrong
>
>>> - Chardev*/CharBackend
>>>
>
> Those are actually always confusing... and I remember I attempted to
> rename it in the past... CharBackend is the front-end side..
>
>>> - NetClientState*/NICState*
>>>
>>> ... it's actually quite common for the *frontend* to have a pointer or
>>> object of type FooBackend; that would give Audiodev* and AudioBackend*.
>>
>> Hmm, I have to correct myself.
>>
>> QEMUSoundCard's name field is basically unused, and QEMUSoundCard should
>> be just an Audiodev*.  There's no need for a separate AudioFE struct.
>>
>
> For audio, it's pretty obvious that we have "backend" object to
> implement the host audio subsystem details, while "QEMUSoundCard" is
> the "frontend", or "client/user" context.
>
> Imho, it's clearer to see the relation between the two objects if we
> name them "backend" and "frontend" accordingly. If the "AudioBE" &
> "AudioFE" short versions aren't readable enough, I am fine naming
> "AudioBackend" & "AudioFrontend"

AudioBE is confusing as BE often stands for big endian and no example of 
using it for Backend. Thus AudioBackend while longer is clearer so gets my 
vote too (or anthing else less confusing than AudioBE).

Regards,
BALATON Zoltan
Re: [PATCH 34/43] audio: rename AudioState -> AudioBE
Posted by Paolo Bonzini 1 week, 2 days ago
On 10/21/25 12:40, Marc-André Lureau wrote:
>>> BE and FE aren't used in existing code though.  Looking at current use:
> 
> There is a top-level backends/ though. I meant to say that it's
> usually clearer for everyone when we talk about "backend" vs
> "frontend" (or not?), and I wish we would follow that naming more in
> the code.

Yes, but the front-end should have a *pointer* to a backend.

>>> - BlockDriverState*/BlockBackend*
> 
> I am not very familiar with the block subsystem, but it is seems
> BlockBackend is actually the backend and BlockDriverState is
> implementation data detail. Correct me if I'm wrong

Yes, note the "*".  What I meant above is "the frontend has a 
BlockBackend*, which itself has the internal BlockDriverState*".  Same 
for character and NICs below.

>>> - Chardev*/CharBackend
>>>
> 
> Those are actually always confusing... and I remember I attempted to
> rename it in the past... CharBackend is the front-end side..

Yes, they are confusing.  I'm not sure why it failed, but 
s/CharBackend/CharFrontend/ does get my vote.

>> QEMUSoundCard's name field is basically unused, and QEMUSoundCard should
>> be just an Audiodev*.  There's no need for a separate AudioFE struct.
> 
> For audio, it's pretty obvious that we have "backend" object to
> implement the host audio subsystem details, while "QEMUSoundCard" is
> the "frontend", or "client/user" context.

I agree, but unlike character devices, QEMUSoundCard is not needed at 
all.  So you can drop it and only leave Audiodev*, or AudioBackend* (but 
I prefer Audiodev* which matches both the option name and Chardev*).

Paolo


Re: [PATCH 34/43] audio: rename AudioState -> AudioBE
Posted by Marc-André Lureau 1 week, 2 days ago
Hi

On Tue, Oct 21, 2025 at 2:49 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 10/21/25 12:40, Marc-André Lureau wrote:
> >>> BE and FE aren't used in existing code though.  Looking at current use:
> >
> > There is a top-level backends/ though. I meant to say that it's
> > usually clearer for everyone when we talk about "backend" vs
> > "frontend" (or not?), and I wish we would follow that naming more in
> > the code.
>
> Yes, but the front-end should have a *pointer* to a backend.
>
> >>> - BlockDriverState*/BlockBackend*
> >
> > I am not very familiar with the block subsystem, but it is seems
> > BlockBackend is actually the backend and BlockDriverState is
> > implementation data detail. Correct me if I'm wrong
>
> Yes, note the "*".  What I meant above is "the frontend has a
> BlockBackend*, which itself has the internal BlockDriverState*".  Same
> for character and NICs below.
>
> >>> - Chardev*/CharBackend
> >>>
> >
> > Those are actually always confusing... and I remember I attempted to
> > rename it in the past... CharBackend is the front-end side..
>
> Yes, they are confusing.  I'm not sure why it failed, but
> s/CharBackend/CharFrontend/ does get my vote.
>
> >> QEMUSoundCard's name field is basically unused, and QEMUSoundCard should
> >> be just an Audiodev*.  There's no need for a separate AudioFE struct.
> >
> > For audio, it's pretty obvious that we have "backend" object to
> > implement the host audio subsystem details, while "QEMUSoundCard" is
> > the "frontend", or "client/user" context.
>
> I agree, but unlike character devices, QEMUSoundCard is not needed at
> all.  So you can drop it and only leave Audiodev*, or AudioBackend* (but
> I prefer Audiodev* which matches both the option name and Chardev*).
>

I see, I'll try to remove QEMUSoundCard.

AudioState can't easily be renamed to "Audiodev" though, since that's
the QAPI type name. There are slight typename differences between QAPI
types for chardev and audiodev. Is it breaking QMP APIs to change
typenames? I guess not, I might be wrong. However, this will likely
break external code generators based on QAPI (qapi-rs etc)..

-- 
Marc-André Lureau
Re: [PATCH 34/43] audio: rename AudioState -> AudioBE
Posted by BALATON Zoltan 1 week, 2 days ago
On Tue, 21 Oct 2025, Marc-André Lureau wrote:
> On Tue, Oct 21, 2025 at 2:49 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
>>
>> On 10/21/25 12:40, Marc-André Lureau wrote:
>>>>> BE and FE aren't used in existing code though.  Looking at current use:
>>>
>>> There is a top-level backends/ though. I meant to say that it's
>>> usually clearer for everyone when we talk about "backend" vs
>>> "frontend" (or not?), and I wish we would follow that naming more in
>>> the code.
>>
>> Yes, but the front-end should have a *pointer* to a backend.
>>
>>>>> - BlockDriverState*/BlockBackend*
>>>
>>> I am not very familiar with the block subsystem, but it is seems
>>> BlockBackend is actually the backend and BlockDriverState is
>>> implementation data detail. Correct me if I'm wrong
>>
>> Yes, note the "*".  What I meant above is "the frontend has a
>> BlockBackend*, which itself has the internal BlockDriverState*".  Same
>> for character and NICs below.
>>
>>>>> - Chardev*/CharBackend
>>>>>
>>>
>>> Those are actually always confusing... and I remember I attempted to
>>> rename it in the past... CharBackend is the front-end side..
>>
>> Yes, they are confusing.  I'm not sure why it failed, but
>> s/CharBackend/CharFrontend/ does get my vote.
>>
>>>> QEMUSoundCard's name field is basically unused, and QEMUSoundCard should
>>>> be just an Audiodev*.  There's no need for a separate AudioFE struct.
>>>
>>> For audio, it's pretty obvious that we have "backend" object to
>>> implement the host audio subsystem details, while "QEMUSoundCard" is
>>> the "frontend", or "client/user" context.
>>
>> I agree, but unlike character devices, QEMUSoundCard is not needed at
>> all.  So you can drop it and only leave Audiodev*, or AudioBackend* (but
>> I prefer Audiodev* which matches both the option name and Chardev*).
>>
>
> I see, I'll try to remove QEMUSoundCard.
>
> AudioState can't easily be renamed to "Audiodev" though, since that's
> the QAPI type name. There are slight typename differences between QAPI
> types for chardev and audiodev. Is it breaking QMP APIs to change
> typenames? I guess not, I might be wrong. However, this will likely
> break external code generators based on QAPI (qapi-rs etc)..

I'm getting lost where this is going but keeping AudioState for the QOM 
type seems better than using another name just to try to be consistent 
with char backends that was said to have a confusing naming above. So 
maybe keep the QOM convention for audio and call it AudioState and later 
try to match Char to this if that needs similar QOM'ification? If this is 
replacing QEMUSoundCard then maybe AudioCard can also be considered for 
keeping consistency with local names. But I don't know what I'm talking 
about so I stop here and let you agree on something.

Regards,
BALATON Zoltan
Re: [PATCH 34/43] audio: rename AudioState -> AudioBE
Posted by Philippe Mathieu-Daudé 1 week, 2 days ago
On 21/10/25 11:40, Paolo Bonzini wrote:
> On 10/21/25 11:30, Paolo Bonzini wrote:
>> On 10/21/25 11:03, marcandre.lureau@redhat.com wrote:
>>> From: Marc-André Lureau <marcandre.lureau@redhat.com>
>>>
>>> Naming is hard. But in general in QEMU, a host "backend" is the term
>>> used to fullfill the request made by the device "frontend".
>>>
>>> Note that "audiodev" is the corresponding QAPI type name (or 
>>> configuration).
>>
>> BE and FE aren't used in existing code though.  Looking at current use:
>>
>> - BlockDriverState*/BlockBackend*
>>
>> - Chardev*/CharBackend
>>
>> - NetClientState*/NICState*
>>
>> ... it's actually quite common for the *frontend* to have a pointer or 
>> object of type FooBackend; that would give Audiodev* and AudioBackend*.
> 
> Hmm, I have to correct myself.
> 
> QEMUSoundCard's name field is basically unused, and QEMUSoundCard should 
> be just an Audiodev*.  There's no need for a separate AudioFE struct.

AudioBackend is still a better name than AudioBE though.