Skip to contentSkip to conversation

Multiple simultaneous audio backends

PATCH Superseded Kővágó, Zoltán 4 participants 24 messages Jul 15, 2019 – Jul 29, 2019

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Multiple simultaneous audio backends

Hello,

This is the v2 of my audio patches. Copmpared to the previous version, the only major change is the splitting of 2 commits ("basic support for multi backend audio" and "audio: audiodev= parameters no longer optional when -audiodev present") to ease review.

I also included a patch that fixes a memory leak reported by ASAN.

Regards,
Zoltan

Kővágó, Zoltán (14):
audio: reduce glob_audio_state usage
audio: basic support for multi backend audio
audio: add audiodev property to vnc and wav_capture
audio: add audiodev properties to frontends
paaudio: prepare for multiple audiodev
audio: audiodev= parameters no longer optional when -audiodev present
paaudio: do not move stream when sink/source name is specified
paaudio: properly disconnect streams in fini_*
audio: remove audio_MIN, audio_MAX
audio: do not run each backend in audio_run
paaudio: fix playback glitches
audio: remove read and write pcm_ops
audio: use size_t where makes sense
audio: fix memory leak reported by ASAN

 audio/audio.h                    |  36 +--
 audio/audio_int.h                |  43 ++--
 audio/audio_template.h           |  62 +++--
 audio/mixeng.h                   |   9 +-
 audio/rate_template.h            |   2 +-
 include/hw/qdev-properties.h     |   3 +
 include/sysemu/replay.h          |   4 +-
 ui/vnc.h                         |   2 +
 audio/alsaaudio.c                |  49 ++--
 audio/audio.c                    | 345 ++++++++++++++-----------
 audio/coreaudio.c                |  18 +-
 audio/dsoundaudio.c              |  25 +-
 audio/noaudio.c                  |  39 +--
 audio/ossaudio.c                 |  75 +++---
 audio/paaudio.c                  | 421 ++++++++++++++++++-------------
 audio/sdlaudio.c                 |  30 +--
 audio/spiceaudio.c               |  34 +--
 audio/wavaudio.c                 |  18 +-
 audio/wavcapture.c               |   6 +-
 hw/audio/ac97.c                  |  11 +-
 hw/audio/adlib.c                 |   5 +-
 hw/audio/cs4231a.c               |   5 +-
 hw/audio/es1370.c                |  13 +-
 hw/audio/gus.c                   |   7 +-
 hw/audio/hda-codec.c             |  17 +-
 hw/audio/milkymist-ac97.c        |  14 +-
 hw/audio/pcspk.c                 |   3 +-
 hw/audio/pl041.c                 |   1 +
 hw/audio/sb16.c                  |   3 +-
 hw/audio/wm8750.c                |  10 +-
 hw/core/qdev-properties-system.c |  57 +++++
 hw/usb/dev-audio.c               |   1 +
 monitor/misc.c                   |  12 +-
 replay/replay-audio.c            |  16 +-
 replay/replay.c                  |   2 +-
 ui/vnc.c                         |  15 +-
 hmp-commands.hx                  |  13 +-
 qemu-options.hx                  |   6 +
 38 files changed, 790 insertions(+), 642 deletions(-)
Signature · 1 line
2.22.0
#3 lore raw

PATCH v2 3/14 audio: add audiodev property to vnc and wav_capture

---
 ui/vnc.h        |  2 ++
 monitor/misc.c  | 12 +++++++++++-
 ui/vnc.c        | 15 ++++++++++++++-
 hmp-commands.hx | 13 ++++++++-----
 qemu-options.hx |  6 ++++++
 5 files changed, 41 insertions(+), 7 deletions(-)
ui/vnc.h +2 -0
index 2f84db3142..6f54653455 100644
@@ -183,6 +183,8 @@ struct VncDisplay
 #ifdef CONFIG_VNC_SASL
     VncDisplaySASL sasl;
 #endif
+
+    AudioState *audio_state;
 };
 
 typedef struct VncTight {
monitor/misc.c +11 -1
index e393333a0e..f97810d370 100644
@@ -1148,7 +1148,17 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     int bits = qdict_get_try_int(qdict, "bits", -1);
     int has_channels = qdict_haskey(qdict, "nchannels");
     int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
+    const char *audiodev = qdict_get_try_str(qdict, "audiodev");
     CaptureState *s;
+    AudioState *as = NULL;
+
+    if (audiodev) {
+        as = audio_state_by_name(audiodev);
+        if (!as) {
+            monitor_printf(mon, "Invalid audiodev specified\n");
+            return;
+        }
+    }
 
     s = g_malloc0 (sizeof (*s));
 
@@ -1156,7 +1166,7 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     bits = has_bits ? bits : 16;
     nchannels = has_channels ? nchannels : 2;
 
-    if (wav_start_capture(NULL, s, path, freq, bits, nchannels)) {
+    if (wav_start_capture(as, s, path, freq, bits, nchannels)) {
         monitor_printf(mon, "Failed to add wave capture\n");
         g_free (s);
         return;
ui/vnc.c +14 -1
index 140f364dda..24f9be5b5d 100644
@@ -1222,7 +1222,7 @@ static void audio_add(VncState *vs)
     ops.destroy = audio_capture_destroy;
     ops.capture = audio_capture;
 
-    vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs);
+    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, &ops, vs);
     if (!vs->audio_cap) {
         error_report("Failed to add audio capture");
     }
@@ -3369,6 +3369,9 @@ static QemuOptsList qemu_vnc_opts = {
         },{
             .name = "non-adaptive",
             .type = QEMU_OPT_BOOL,
+        },{
+            .name = "audiodev",
+            .type = QEMU_OPT_STRING,
         },
         { /* end of list */ }
     },
@@ -3806,6 +3809,7 @@ void vnc_display_open(const char *id, Error **errp)
     const char *saslauthz;
     int lock_key_sync = 1;
     int key_delay_ms;
+    const char *audiodev;
 
     if (!vd) {
         error_setg(errp, "VNC display not active");
@@ -3991,6 +3995,15 @@ void vnc_display_open(const char *id, Error **errp)
     }
     vd->ledstate = 0;
 
+    audiodev = qemu_opt_get(opts, "audiodev");
+    if (audiodev) {
+        vd->audio_state = audio_state_by_name(audiodev);
+        if (!vd->audio_state) {
+            error_setg(errp, "Audiodev '%s' not found", audiodev);
+            goto fail;
+        }
+    }
+
     device_id = qemu_opt_get(opts, "display");
     if (device_id) {
         int head = qemu_opt_get_number(opts, "head", 0);
hmp-commands.hx +8 -5
index bfa5681dd2..fa7f009268 100644
@@ -819,16 +819,19 @@ ETEXI
 
     {
         .name       = "wavcapture",
-        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?",
-        .params     = "path [frequency [bits [channels]]]",
+        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?,audiodev:s?",
+        .params     = "path [frequency [bits [channels [audiodev]]]]",
         .help       = "capture audio to a wave file (default frequency=44100 bits=16 channels=2)",
         .cmd        = hmp_wavcapture,
     },
 STEXI
-@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels}]]]
+@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels} [@var{audiodev}]]]]
 @findex wavcapture
-Capture audio into @var{filename}. Using sample rate @var{frequency}
-bits per sample @var{bits} and number of channels @var{channels}.
+Capture audio into @var{filename} from @var{audiodev}, using sample rate
+@var{frequency} bits per sample @var{bits} and number of channels
+@var{channels}. When not using an -audiodev argument on command line,
+@var{audiodev} must be omitted, otherwise is must specify a valid
+audiodev.
 
 Defaults:
 @itemize @minus
qemu-options.hx +6 -0
index 9621e934c0..a308e5f5aa 100644
@@ -1978,6 +1978,12 @@ can help the device and guest to keep up and not lose events in case
 events are arriving in bulk.  Possible causes for the latter are flaky
 network connections, or scripts for automated testing.
 
+@item audiodev=@var{audiodev}
+
+Use the specified @var{audiodev} when the VNC client requests audio
+transmission. When not using an -audiodev argument, this option must
+be omitted, otherwise is must be present and specify a valid audiodev.
+
 @end table
 ETEXI
 
Signature · 1 line
2.22.0
#2 lore raw

PATCH v2 2/14 audio: basic support for multi backend audio

In reply to Kővágó, Zoltán

Audio functions no longer access glob_audio_state, instead they get an AudioState as a parameter. This is required in order to support multiple backends.

glob_audio_state is also gone, and replaced with a tailq so we can store more than one states.

---

Notes:
Changes from v1:

* Moved wav_capture/vnc audiodev param to a separate commit

 audio/audio.h          |  12 +++--
 audio/audio_int.h      |   2 +
 audio/audio_template.h |   2 +-
 audio/audio.c          | 102 +++++++++++++++++++++++++++++++----------
 audio/wavcapture.c     |   6 +--
 monitor/misc.c         |   2 +-
 ui/vnc.c               |   2 +-
 7 files changed, 95 insertions(+), 33 deletions(-)
audio/audio.h +9 -3
index 64b0f761bc..ad2457f4de 100644
@@ -78,8 +78,10 @@ typedef struct SWVoiceOut SWVoiceOut;
 typedef struct CaptureVoiceOut CaptureVoiceOut;
 typedef struct SWVoiceIn SWVoiceIn;
 
+typedef struct AudioState AudioState;
 typedef struct QEMUSoundCard {
     char *name;
+    AudioState *state;
     QLIST_ENTRY (QEMUSoundCard) entries;
 } QEMUSoundCard;
 
@@ -92,7 +94,8 @@ void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 
 void AUD_register_card (const char *name, QEMUSoundCard *card);
 void AUD_remove_card (QEMUSoundCard *card);
-CaptureVoiceOut *AUD_add_capture (
+CaptureVoiceOut *AUD_add_capture(
+    AudioState *s,
     struct audsettings *as,
     struct audio_capture_ops *ops,
     void *opaque
@@ -160,8 +163,8 @@ static inline void *advance (void *p, int incr)
 #define audio_MAX(a, b) ((a)<(b)?(b):(a))
 #endif
 
-int wav_start_capture (CaptureState *s, const char *path, int freq,
-                       int bits, int nchannels);
+int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
+                      int freq, int bits, int nchannels);
 
 bool audio_is_cleaning_up(void);
 void audio_cleanup(void);
@@ -175,4 +178,7 @@ void audio_parse_option(const char *opt);
 void audio_init_audiodevs(void);
 void audio_legacy_help(void);
 
+AudioState *audio_state_by_name(const char *name);
+const char *audio_get_id(QEMUSoundCard *card);
+
 #endif /* QEMU_AUDIO_H */
audio/audio_int.h +2 -0
index 8164696b2c..9f01f6ad00 100644
@@ -196,6 +196,8 @@ typedef struct AudioState {
 
     bool timer_running;
     uint64_t timer_last;
+
+    QTAILQ_ENTRY(AudioState) list;
 } AudioState;
 
 extern const struct mixeng_volume nominal_volume;
audio/audio_template.h +1 -1
index c721fed75d..54f07338e7 100644
@@ -428,7 +428,7 @@ SW *glue (AUD_open_, TYPE) (
     struct audsettings *as
     )
 {
-    AudioState *s = &glob_audio_state;
+    AudioState *s = card->state;
     AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s->dev);
 
     if (audio_bug(__func__, !card || !name || !callback_fn || !as)) {
audio/audio.c +78 -24

191 lines not on this page · raw message

audio/wavcapture.c +3 -3
index 74320dfecc..81c5c19032 100644
@@ -105,8 +105,8 @@ static struct capture_ops wav_capture_ops = {
     .info = wav_capture_info
 };
 
-int wav_start_capture (CaptureState *s, const char *path, int freq,
-                       int bits, int nchannels)
+int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
+                      int freq, int bits, int nchannels)
 {
     WAVState *wav;
     uint8_t hdr[] = {
@@ -171,7 +171,7 @@ int wav_start_capture (CaptureState *s, const char *path, int freq,
         goto error_free;
     }
 
-    cap = AUD_add_capture (&as, &ops, wav);
+    cap = AUD_add_capture(state, &as, &ops, wav);
     if (!cap) {
         error_report("Failed to add audio capture");
         goto error_free;
monitor/misc.c +1 -1
index 00338c002a..e393333a0e 100644
@@ -1156,7 +1156,7 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     bits = has_bits ? bits : 16;
     nchannels = has_channels ? nchannels : 2;
 
-    if (wav_start_capture (s, path, freq, bits, nchannels)) {
+    if (wav_start_capture(NULL, s, path, freq, bits, nchannels)) {
         monitor_printf(mon, "Failed to add wave capture\n");
         g_free (s);
         return;
ui/vnc.c +1 -1
index 38f92bfca3..140f364dda 100644
@@ -1222,7 +1222,7 @@ static void audio_add(VncState *vs)
     ops.destroy = audio_capture_destroy;
     ops.capture = audio_capture;
 
-    vs->audio_cap = AUD_add_capture(&vs->as, &ops, vs);
+    vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs);
     if (!vs->audio_cap) {
         error_report("Failed to add audio capture");
     }
Signature · 1 line
2.22.0
#11 lore raw

PATCH v2 4/14 audio: add audiodev properties to frontends

In reply to Kővágó, Zoltán

Finally add audiodev= options to audio frontends so users can specify which backend to use when multiple backends exist. Not specifying an audiodev= option currently causes the first audiodev to be used, this is fixed in the next commit.

Example usage: -audiodev pa,id=foo -device AC97,audiodev=foo

---
 audio/audio.h                    |  3 ++
 include/hw/qdev-properties.h     |  3 ++
 hw/audio/ac97.c                  |  1 +
 hw/audio/adlib.c                 |  1 +
 hw/audio/cs4231a.c               |  1 +
 hw/audio/es1370.c                |  7 +++-
 hw/audio/gus.c                   |  1 +
 hw/audio/hda-codec.c             |  1 +
 hw/audio/milkymist-ac97.c        |  6 ++++
 hw/audio/pcspk.c                 |  1 +
 hw/audio/pl041.c                 |  1 +
 hw/audio/sb16.c                  |  1 +
 hw/audio/wm8750.c                |  6 ++++
 hw/core/qdev-properties-system.c | 57 ++++++++++++++++++++++++++++++++
 hw/usb/dev-audio.c               |  1 +
 15 files changed, 90 insertions(+), 1 deletion(-)
audio/audio.h +3 -0
index ad2457f4de..c0722a5cda 100644
@@ -181,4 +181,7 @@ void audio_legacy_help(void);
 AudioState *audio_state_by_name(const char *name);
 const char *audio_get_id(QEMUSoundCard *card);
 
+#define DEFINE_AUDIO_PROPERTIES(_s, _f)         \
+    DEFINE_PROP_AUDIODEV("audiodev", _s, _f)
+
 #endif /* QEMU_AUDIO_H */
include/hw/qdev-properties.h +3 -0
index 1eae5ab056..de0b2c8423 100644
@@ -35,6 +35,7 @@ extern const PropertyInfo qdev_prop_blocksize;
 extern const PropertyInfo qdev_prop_pci_host_devaddr;
 extern const PropertyInfo qdev_prop_uuid;
 extern const PropertyInfo qdev_prop_arraylen;
+extern const PropertyInfo qdev_prop_audiodev;
 extern const PropertyInfo qdev_prop_link;
 extern const PropertyInfo qdev_prop_off_auto_pcibar;
 extern const PropertyInfo qdev_prop_pcie_link_speed;
@@ -236,6 +237,8 @@ extern const PropertyInfo qdev_prop_pcie_link_width;
             + type_check(QemuUUID, typeof_field(_state, _field)),  \
         .set_default = true,                                       \
         }
+#define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
+    DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
 
 #define DEFINE_PROP_END_OF_LIST()               \
     {}
hw/audio/ac97.c +1 -0
index fb98da2678..0d8e524233 100644
@@ -1409,6 +1409,7 @@ static int ac97_init (PCIBus *bus)
 }
 
 static Property ac97_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(AC97LinkState, card),
     DEFINE_PROP_UINT32 ("use_broken_id", AC97LinkState, use_broken_id, 0),
     DEFINE_PROP_END_OF_LIST (),
 };
hw/audio/adlib.c +1 -0
index 7dd9a89b89..df2e781788 100644
@@ -299,6 +299,7 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
 }
 
 static Property adlib_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(AdlibState, card),
     DEFINE_PROP_UINT32 ("iobase",  AdlibState, port, 0x220),
     DEFINE_PROP_UINT32 ("freq",    AdlibState, freq,  44100),
     DEFINE_PROP_END_OF_LIST (),
hw/audio/cs4231a.c +1 -0
index 7216b41cc1..e3ea830b47 100644
@@ -689,6 +689,7 @@ static int cs4231a_init (ISABus *bus)
 }
 
 static Property cs4231a_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(CSState, card),
     DEFINE_PROP_UINT32 ("iobase",  CSState, port, 0x534),
     DEFINE_PROP_UINT32 ("irq",     CSState, irq,  9),
     DEFINE_PROP_UINT32 ("dma",     CSState, dma,  3),
hw/audio/es1370.c +6 -1
index 260c142b70..7589671d20 100644
@@ -887,6 +887,11 @@ static int es1370_init (PCIBus *bus)
     return 0;
 }
 
+static Property es1370_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(ES1370State, card),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void es1370_class_init (ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS (klass);
@@ -903,6 +908,7 @@ static void es1370_class_init (ObjectClass *klass, void *data)
     dc->desc = "ENSONIQ AudioPCI ES1370";
     dc->vmsd = &vmstate_es1370;
     dc->reset = es1370_on_reset;
+    dc->props = es1370_properties;
 }
 
 static const TypeInfo es1370_info = {
@@ -923,4 +929,3 @@ static void es1370_register_types (void)
 }
 
 type_init (es1370_register_types)
-
hw/audio/gus.c +1 -0
index 9ab51631d9..566864bc9e 100644
@@ -297,6 +297,7 @@ static int GUS_init (ISABus *bus)
 }
 
 static Property gus_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(GUSState, card),
     DEFINE_PROP_UINT32 ("freq",    GUSState, freq,        44100),
     DEFINE_PROP_UINT32 ("iobase",  GUSState, port,        0x240),
     DEFINE_PROP_UINT32 ("irq",     GUSState, emu.gusirq,  7),
hw/audio/hda-codec.c +1 -0
index 84639b5424..967a10f189 100644
@@ -840,6 +840,7 @@ static const VMStateDescription vmstate_hda_audio = {
 };
 
 static Property hda_audio_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(HDAAudioState, card),
     DEFINE_PROP_UINT32("debug", HDAAudioState, debug,   0),
     DEFINE_PROP_BOOL("mixer", HDAAudioState, mixer,  true),
     DEFINE_PROP_BOOL("use-timer", HDAAudioState, use_timer,  true),
hw/audio/milkymist-ac97.c +6 -0
index bf6a5a6b96..4835229326 100644
@@ -329,6 +329,11 @@ static const VMStateDescription vmstate_milkymist_ac97 = {
     }
 };
 
+static Property milkymist_ac97_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(MilkymistAC97State, card),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void milkymist_ac97_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -336,6 +341,7 @@ static void milkymist_ac97_class_init(ObjectClass *klass, void *data)
     dc->realize = milkymist_ac97_realize;
     dc->reset = milkymist_ac97_reset;
     dc->vmsd = &vmstate_milkymist_ac97;
+    dc->props = milkymist_ac97_properties;
 }
 
 static const TypeInfo milkymist_ac97_info = {
hw/audio/pcspk.c +1 -0
index a7b3ab0c2b..01127304c2 100644
@@ -209,6 +209,7 @@ static const VMStateDescription vmstate_spk = {
 };
 
 static Property pcspk_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(PCSpkState, card),
     DEFINE_PROP_UINT32("iobase", PCSpkState, iobase,  -1),
     DEFINE_PROP_BOOL("migrate", PCSpkState, migrate,  true),
     DEFINE_PROP_END_OF_LIST(),
hw/audio/pl041.c +1 -0
index 59c6ce1f2e..ce430a7821 100644
@@ -622,6 +622,7 @@ static const VMStateDescription vmstate_pl041 = {
 };
 
 static Property pl041_device_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(PL041State, codec.card),
     /* Non-compact FIFO depth property */
     DEFINE_PROP_UINT32("nc_fifo_depth", PL041State, fifo_depth,
                        DEFAULT_FIFO_DEPTH),
hw/audio/sb16.c +1 -0
index a2db06a2bb..6b604979cf 100644
@@ -1421,6 +1421,7 @@ static int SB16_init (ISABus *bus)
 }
 
 static Property sb16_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(SB16State, card),
     DEFINE_PROP_UINT32 ("version", SB16State, ver,  0x0405), /* 4.5 */
     DEFINE_PROP_UINT32 ("iobase",  SB16State, port, 0x220),
     DEFINE_PROP_UINT32 ("irq",     SB16State, irq,  5),
hw/audio/wm8750.c +6 -0
index 81f83eea88..dfb4156ff4 100644
@@ -701,6 +701,11 @@ void wm8750_set_bclk_in(void *opaque, int new_hz)
     wm8750_clk_update(s, 1);
 }
 
+static Property wm8750_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(WM8750State, card),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void wm8750_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -711,6 +716,7 @@ static void wm8750_class_init(ObjectClass *klass, void *data)
     sc->recv = wm8750_rx;
     sc->send = wm8750_tx;
     dc->vmsd = &vmstate_wm8750;
+    dc->props = wm8750_properties;
 }
 
 static const TypeInfo wm8750_info = {
hw/core/qdev-properties-system.c +57 -0

69 lines not on this page · raw message

hw/usb/dev-audio.c +1 -0
index 718ab53cbb..1b1cf91132 100644
@@ -666,6 +666,7 @@ static const VMStateDescription vmstate_usb_audio = {
 };
 
 static Property usb_audio_properties[] = {
+    DEFINE_AUDIO_PROPERTIES(USBAudioState, card),
     DEFINE_PROP_UINT32("debug", USBAudioState, debug, 0),
     DEFINE_PROP_UINT32("buffer", USBAudioState, buffer,
                        32 * USBAUDIO_PACKET_SIZE),
Signature · 1 line
2.22.0
#12 lore raw

PATCH v2 5/14 paaudio: prepare for multiple audiodev

In reply to Kővágó, Zoltán

Have a pool of refcounted connections per server, so if the user creates multiple audiodevs to the same pa server, it will use a single connection. (It will still create different streams, so the user can manage those streams separately in pulseaudio.)

---
 audio/paaudio.c | 329 +++++++++++++++++++++++++++---------------------
 1 file changed, 188 insertions(+), 141 deletions(-)
audio/paaudio.c +188 -141
index 5fc886bb33..cc3a34c2ea 100644
@@ -11,10 +11,21 @@
 #include "audio_int.h"
 #include "audio_pt_int.h"
 
-typedef struct {
-    Audiodev *dev;
+typedef struct PAConnection {
+    char *server;
+    int refcount;
+    QTAILQ_ENTRY(PAConnection) list;
+
     pa_threaded_mainloop *mainloop;
     pa_context *context;
+} PAConnection;
+
+static QTAILQ_HEAD(PAConnectionHead, PAConnection) pa_conns =
+    QTAILQ_HEAD_INITIALIZER(pa_conns);
+
+typedef struct {
+    Audiodev *dev;
+    PAConnection *conn;
 } paaudio;
 
 typedef struct {
@@ -45,7 +56,7 @@ typedef struct {
     int samples;
 } PAVoiceIn;
 
-static void qpa_audio_fini(void *opaque);
+static void qpa_conn_fini(PAConnection *c);
 
 static void GCC_FMT_ATTR (2, 3) qpa_logerr (int err, const char *fmt, ...)
 {
@@ -108,11 +119,11 @@ static inline int PA_STREAM_IS_GOOD(pa_stream_state_t x)
 
 static int qpa_simple_read (PAVoiceIn *p, void *data, size_t length, int *rerror)
 {
-    paaudio *g = p->g;
+    PAConnection *c = p->g->conn;
 
-    pa_threaded_mainloop_lock (g->mainloop);
+    pa_threaded_mainloop_lock(c->mainloop);
 
-    CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
+    CHECK_DEAD_GOTO(c, p->stream, rerror, unlock_and_fail);
 
     while (length > 0) {
         size_t l;
@@ -121,11 +132,11 @@ static int qpa_simple_read (PAVoiceIn *p, void *data, size_t length, int *rerror
             int r;
 
             r = pa_stream_peek (p->stream, &p->read_data, &p->read_length);
-            CHECK_SUCCESS_GOTO (g, rerror, r == 0, unlock_and_fail);
+            CHECK_SUCCESS_GOTO(c, rerror, r == 0, unlock_and_fail);
 
             if (!p->read_data) {
-                pa_threaded_mainloop_wait (g->mainloop);
-                CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
+                pa_threaded_mainloop_wait(c->mainloop);
+                CHECK_DEAD_GOTO(c, p->stream, rerror, unlock_and_fail);
             } else {
                 p->read_index = 0;
             }
@@ -148,53 +159,53 @@ static int qpa_simple_read (PAVoiceIn *p, void *data, size_t length, int *rerror
             p->read_length = 0;
             p->read_index = 0;
 
-            CHECK_SUCCESS_GOTO (g, rerror, r == 0, unlock_and_fail);
+            CHECK_SUCCESS_GOTO(c, rerror, r == 0, unlock_and_fail);
         }
     }
 
-    pa_threaded_mainloop_unlock (g->mainloop);
+    pa_threaded_mainloop_unlock(c->mainloop);
     return 0;
 
 unlock_and_fail:
-    pa_threaded_mainloop_unlock (g->mainloop);
+    pa_threaded_mainloop_unlock(c->mainloop);
     return -1;
 }
 
 static int qpa_simple_write (PAVoiceOut *p, const void *data, size_t length, int *rerror)
 {
-    paaudio *g = p->g;
+    PAConnection *c = p->g->conn;
 
-    pa_threaded_mainloop_lock (g->mainloop);
+    pa_threaded_mainloop_lock(c->mainloop);
 
-    CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
+    CHECK_DEAD_GOTO(c, p->stream, rerror, unlock_and_fail);
 
     while (length > 0) {
         size_t l;
         int r;
 
         while (!(l = pa_stream_writable_size (p->stream))) {
-            pa_threaded_mainloop_wait (g->mainloop);
-            CHECK_DEAD_GOTO (g, p->stream, rerror, unlock_and_fail);
+            pa_threaded_mainloop_wait(c->mainloop);
+            CHECK_DEAD_GOTO(c, p->stream, rerror, unlock_and_fail);
         }
 
-        CHECK_SUCCESS_GOTO (g, rerror, l != (size_t) -1, unlock_and_fail);
+        CHECK_SUCCESS_GOTO(c, rerror, l != (size_t) -1, unlock_and_fail);
 
         if (l > length) {
             l = length;
         }
 
         r = pa_stream_write (p->stream, data, l, NULL, 0LL, PA_SEEK_RELATIVE);
-        CHECK_SUCCESS_GOTO (g, rerror, r >= 0, unlock_and_fail);
+        CHECK_SUCCESS_GOTO(c, rerror, r >= 0, unlock_and_fail);
 
         data = (const uint8_t *) data + l;
         length -= l;
     }
 
-    pa_threaded_mainloop_unlock (g->mainloop);
+    pa_threaded_mainloop_unlock(c->mainloop);
     return 0;
 
 unlock_and_fail:
-    pa_threaded_mainloop_unlock (g->mainloop);
+    pa_threaded_mainloop_unlock(c->mainloop);
     return -1;
 }
 
@@ -432,13 +443,13 @@ static AudioFormat pa_to_audfmt (pa_sample_format_t fmt, int *endianness)
 
 static void context_state_cb (pa_context *c, void *userdata)
 {
-    paaudio *g = userdata;
+    PAConnection *conn = userdata;
 
     switch (pa_context_get_state(c)) {
     case PA_CONTEXT_READY:
     case PA_CONTEXT_TERMINATED:
     case PA_CONTEXT_FAILED:
-        pa_threaded_mainloop_signal (g->mainloop, 0);
+        pa_threaded_mainloop_signal(conn->mainloop, 0);
         break;
 
     case PA_CONTEXT_UNCONNECTED:
@@ -451,14 +462,14 @@ static void context_state_cb (pa_context *c, void *userdata)
 
 static void stream_state_cb (pa_stream *s, void * userdata)
 {
-    paaudio *g = userdata;
+    PAConnection *c = userdata;
 
     switch (pa_stream_get_state (s)) {
 
     case PA_STREAM_READY:
     case PA_STREAM_FAILED:
     case PA_STREAM_TERMINATED:
-        pa_threaded_mainloop_signal (g->mainloop, 0);
+        pa_threaded_mainloop_signal(c->mainloop, 0);
         break;
 
     case PA_STREAM_UNCONNECTED:
@@ -469,13 +480,13 @@ static void stream_state_cb (pa_stream *s, void * userdata)
 
 static void stream_request_cb (pa_stream *s, size_t length, void *userdata)
 {
-    paaudio *g = userdata;
+    PAConnection *c = userdata;
 
-    pa_threaded_mainloop_signal (g->mainloop, 0);
+    pa_threaded_mainloop_signal(c->mainloop, 0);
 }
 
 static pa_stream *qpa_simple_new (
-        paaudio *g,
+        PAConnection *c,
         const char *name,
         pa_stream_direction_t dir,
         const char *dev,
@@ -486,50 +497,48 @@ static pa_stream *qpa_simple_new (
 {
     int r;
     pa_stream *stream;
+    pa_stream_flags_t flags;
 
-    pa_threaded_mainloop_lock (g->mainloop);
+    pa_threaded_mainloop_lock(c->mainloop);
 
-    stream = pa_stream_new (g->context, name, ss, map);
+    stream = pa_stream_new(c->context, name, ss, map);
     if (!stream) {
         goto fail;
     }
 
-    pa_stream_set_state_callback (stream, stream_state_cb, g);
-    pa_stream_set_read_callback (stream, stream_request_cb, g);
-    pa_stream_set_write_callback (stream, stream_request_cb, g);
+    pa_stream_set_state_callback(stream, stream_state_cb, c);
+    pa_stream_set_read_callback(stream, stream_request_cb, c);
+    pa_stream_set_write_callback(stream, stream_request_cb, c);
+
+    flags =
+        PA_STREAM_INTERPOLATE_TIMING
+#ifdef PA_STREAM_ADJUST_LATENCY
+        | PA_STREAM_ADJUST_LATENCY
+#endif
+        | PA_STREAM_AUTO_TIMING_UPDATE;
 
     if (dir == PA_STREAM_PLAYBACK) {
-        r = pa_stream_connect_playback (stream, dev, attr,
-                                        PA_STREAM_INTERPOLATE_TIMING
-#ifdef PA_STREAM_ADJUST_LATENCY
-                                        |PA_STREAM_ADJUST_LATENCY
-#endif
-                                        |PA_STREAM_AUTO_TIMING_UPDATE, NULL, NULL);
+        r = pa_stream_connect_playback(stream, dev, attr, flags, NULL, NULL);
     } else {
-        r = pa_stream_connect_record (stream, dev, attr,
-                                      PA_STREAM_INTERPOLATE_TIMING
-#ifdef PA_STREAM_ADJUST_LATENCY
-                                      |PA_STREAM_ADJUST_LATENCY
-#endif
-                                      |PA_STREAM_AUTO_TIMING_UPDATE);
+        r = pa_stream_connect_record(stream, dev, attr, flags);
     }
 
     if (r < 0) {
       goto fail;
     }
 
-    pa_threaded_mainloop_unlock (g->mainloop);
+    pa_threaded_mainloop_unlock(c->mainloop);
 
     return stream;
 
 fail:
-    pa_threaded_mainloop_unlock (g->mainloop);
+    pa_threaded_mainloop_unlock(c->mainloop);
 
     if (stream) {
         pa_stream_unref (stream);
     }
 
-    *rerror = pa_context_errno (g->context);
+    *rerror = pa_context_errno(c->context);
 
     return NULL;
 }
@@ -545,6 +554,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
     paaudio *g = pa->g = drv_opaque;
     AudiodevPaOptions *popts = &g->dev->u.pa;
     AudiodevPaPerDirectionOptions *ppdo = popts->out;
+    PAConnection *c = g->conn;
 
     ss.format = audfmt_to_pa (as->fmt, as->endianness);
     ss.channels = as->nchannels;
@@ -558,7 +568,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
     obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
 
     pa->stream = qpa_simple_new (
-        g,
+        c,
         "qemu",
         PA_STREAM_PLAYBACK,
         ppdo->has_name ? ppdo->name : NULL,
@@ -612,6 +622,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
     paaudio *g = pa->g = drv_opaque;
     AudiodevPaOptions *popts = &g->dev->u.pa;
     AudiodevPaPerDirectionOptions *ppdo = popts->in;
+    PAConnection *c = g->conn;
 
     ss.format = audfmt_to_pa (as->fmt, as->endianness);
     ss.channels = as->nchannels;
@@ -625,7 +636,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
     obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
 
     pa->stream = qpa_simple_new (
-        g,
+        c,
         "qemu",
         PA_STREAM_RECORD,
         ppdo->has_name ? ppdo->name : NULL,
@@ -714,7 +725,7 @@ static int qpa_ctl_out (HWVoiceOut *hw, int cmd, ...)
     PAVoiceOut *pa = (PAVoiceOut *) hw;
     pa_operation *op;
     pa_cvolume v;
-    paaudio *g = pa->g;
+    PAConnection *c = pa->g->conn;
 
 #ifdef PA_CHECK_VERSION    /* macro is present in 0.9.16+ */
     pa_cvolume_init (&v);  /* function is present in 0.9.13+ */
@@ -734,28 +745,29 @@ static int qpa_ctl_out (HWVoiceOut *hw, int cmd, ...)
             v.values[0] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.l) / UINT32_MAX;
             v.values[1] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.r) / UINT32_MAX;
 
-            pa_threaded_mainloop_lock (g->mainloop);
+            pa_threaded_mainloop_lock(c->mainloop);
 
-            op = pa_context_set_sink_input_volume (g->context,
+            op = pa_context_set_sink_input_volume(c->context,
                 pa_stream_get_index (pa->stream),
                 &v, NULL, NULL);
-            if (!op)
-                qpa_logerr (pa_context_errno (g->context),
-                            "set_sink_input_volume() failed\n");
-            else
-                pa_operation_unref (op);
+            if (!op) {
+                qpa_logerr(pa_context_errno(c->context),
+                           "set_sink_input_volume() failed\n");
+            } else {
+                pa_operation_unref(op);
+            }
 
-            op = pa_context_set_sink_input_mute (g->context,
+            op = pa_context_set_sink_input_mute(c->context,
                 pa_stream_get_index (pa->stream),
                sw->vol.mute, NULL, NULL);
             if (!op) {
-                qpa_logerr (pa_context_errno (g->context),
-                            "set_sink_input_mute() failed\n");
+                qpa_logerr(pa_context_errno(c->context),
+                           "set_sink_input_mute() failed\n");
             } else {
-                pa_operation_unref (op);
+                pa_operation_unref(op);
             }
 
-            pa_threaded_mainloop_unlock (g->mainloop);
+            pa_threaded_mainloop_unlock(c->mainloop);
         }
     }
     return 0;
@@ -766,7 +778,7 @@ static int qpa_ctl_in (HWVoiceIn *hw, int cmd, ...)
     PAVoiceIn *pa = (PAVoiceIn *) hw;
     pa_operation *op;
     pa_cvolume v;
-    paaudio *g = pa->g;
+    PAConnection *c = pa->g->conn;
 
 #ifdef PA_CHECK_VERSION
     pa_cvolume_init (&v);
@@ -786,29 +798,29 @@ static int qpa_ctl_in (HWVoiceIn *hw, int cmd, ...)
             v.values[0] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.l) / UINT32_MAX;
             v.values[1] = ((PA_VOLUME_NORM - PA_VOLUME_MUTED) * sw->vol.r) / UINT32_MAX;
 
-            pa_threaded_mainloop_lock (g->mainloop);
+            pa_threaded_mainloop_lock(c->mainloop);
 
-            op = pa_context_set_source_output_volume (g->context,
-                pa_stream_get_index (pa->stream),
+            op = pa_context_set_source_output_volume(c->context,
+                pa_stream_get_index(pa->stream),
                 &v, NULL, NULL);
             if (!op) {
-                qpa_logerr (pa_context_errno (g->context),
-                            "set_source_output_volume() failed\n");
+                qpa_logerr(pa_context_errno(c->context),
+                           "set_source_output_volume() failed\n");
             } else {
                 pa_operation_unref(op);
             }
 
-            op = pa_context_set_source_output_mute (g->context,
+            op = pa_context_set_source_output_mute(c->context,
                 pa_stream_get_index (pa->stream),
                 sw->vol.mute, NULL, NULL);
             if (!op) {
-                qpa_logerr (pa_context_errno (g->context),
-                            "set_source_output_mute() failed\n");
+                qpa_logerr(pa_context_errno(c->context),
+                           "set_source_output_mute() failed\n");
             } else {
                 pa_operation_unref (op);
             }
 
-            pa_threaded_mainloop_unlock (g->mainloop);
+            pa_threaded_mainloop_unlock(c->mainloop);
         }
     }
     return 0;
@@ -828,11 +840,75 @@ static int qpa_validate_per_direction_opts(Audiodev *dev,
     return 1;
 }
 
+/* common */
+static void *qpa_conn_init(const char *server)
+{
+    PAConnection *c = g_malloc0(sizeof(PAConnection));
+    QTAILQ_INSERT_TAIL(&pa_conns, c, list);
+
+    c->mainloop = pa_threaded_mainloop_new();
+    if (!c->mainloop) {
+        goto fail;
+    }
+
+    c->context = pa_context_new(pa_threaded_mainloop_get_api(c->mainloop),
+                                server);
+    if (!c->context) {
+        goto fail;
+    }
+
+    pa_context_set_state_callback(c->context, context_state_cb, c);
+
+    if (pa_context_connect(c->context, server, 0, NULL) < 0) {
+        qpa_logerr(pa_context_errno(c->context),
+                   "pa_context_connect() failed\n");
+        goto fail;
+    }
+
+    pa_threaded_mainloop_lock(c->mainloop);
+
+    if (pa_threaded_mainloop_start(c->mainloop) < 0) {
+        goto unlock_and_fail;
+    }
+
+    for (;;) {
+        pa_context_state_t state;
+
+        state = pa_context_get_state(c->context);
+
+        if (state == PA_CONTEXT_READY) {
+            break;
+        }
+
+        if (!PA_CONTEXT_IS_GOOD(state)) {
+            qpa_logerr(pa_context_errno(c->context),
+                       "Wrong context state\n");
+            goto unlock_and_fail;
+        }
+
+        /* Wait until the context is ready */
+        pa_threaded_mainloop_wait(c->mainloop);
+    }
+
+    pa_threaded_mainloop_unlock(c->mainloop);
+    return c;
+
+unlock_and_fail:
+    pa_threaded_mainloop_unlock(c->mainloop);
+fail:
+    AUD_log (AUDIO_CAP, "Failed to initialize PA context");
+    qpa_conn_fini(c);
+    return NULL;
+}
+
 static void *qpa_audio_init(Audiodev *dev)
 {
     paaudio *g;
     AudiodevPaOptions *popts = &dev->u.pa;
     const char *server;
+    PAConnection *c;
+
+    assert(dev->driver == AUDIODEV_DRIVER_PA);
 
     if (!popts->has_server) {
         char pidfile[64];
@@ -849,93 +925,64 @@ static void *qpa_audio_init(Audiodev *dev)
         }
     }
 
-    assert(dev->driver == AUDIODEV_DRIVER_PA);
-
-    g = g_malloc(sizeof(paaudio));
-    server = popts->has_server ? popts->server : NULL;
-
     if (!qpa_validate_per_direction_opts(dev, popts->in)) {
-        goto fail;
+        return NULL;
     }
     if (!qpa_validate_per_direction_opts(dev, popts->out)) {
-        goto fail;
+        return NULL;
     }
 
+    g = g_malloc0(sizeof(paaudio));
+    server = popts->has_server ? popts->server : NULL;
+
     g->dev = dev;
-    g->mainloop = NULL;
-    g->context = NULL;
 
-    g->mainloop = pa_threaded_mainloop_new ();
-    if (!g->mainloop) {
-        goto fail;
-    }
-
-    g->context = pa_context_new (pa_threaded_mainloop_get_api (g->mainloop),
-                                 server);
-    if (!g->context) {
-        goto fail;
-    }
-
-    pa_context_set_state_callback (g->context, context_state_cb, g);
-
-    if (pa_context_connect(g->context, server, 0, NULL) < 0) {
-        qpa_logerr (pa_context_errno (g->context),
-                    "pa_context_connect() failed\n");
-        goto fail;
-    }
-
-    pa_threaded_mainloop_lock (g->mainloop);
-
-    if (pa_threaded_mainloop_start (g->mainloop) < 0) {
-        goto unlock_and_fail;
-    }
-
-    for (;;) {
-        pa_context_state_t state;
-
-        state = pa_context_get_state (g->context);
-
-        if (state == PA_CONTEXT_READY) {
+    QTAILQ_FOREACH(c, &pa_conns, list) {
+        if (server == NULL || c->server == NULL ?
+            server == c->server :
+            strcmp(server, c->server) == 0) {
+            g->conn = c;
             break;
         }
-
-        if (!PA_CONTEXT_IS_GOOD (state)) {
-            qpa_logerr (pa_context_errno (g->context),
-                        "Wrong context state\n");
-            goto unlock_and_fail;
-        }
-
-        /* Wait until the context is ready */
-        pa_threaded_mainloop_wait (g->mainloop);
+    }
+    if (!g->conn) {
+        g->conn = qpa_conn_init(server);
+    }
+    if (!g->conn) {
+        g_free(g);
+        return NULL;
     }
 
-    pa_threaded_mainloop_unlock (g->mainloop);
-
+    ++g->conn->refcount;
     return g;
+}
 
-unlock_and_fail:
-    pa_threaded_mainloop_unlock (g->mainloop);
-fail:
-    AUD_log (AUDIO_CAP, "Failed to initialize PA context");
-    qpa_audio_fini(g);
-    return NULL;
+static void qpa_conn_fini(PAConnection *c)
+{
+    if (c->mainloop) {
+        pa_threaded_mainloop_stop(c->mainloop);
+    }
+
+    if (c->context) {
+        pa_context_disconnect(c->context);
+        pa_context_unref(c->context);
+    }
+
+    if (c->mainloop) {
+        pa_threaded_mainloop_free(c->mainloop);
+    }
+
+    QTAILQ_REMOVE(&pa_conns, c, list);
+    g_free(c);
 }
 
 static void qpa_audio_fini (void *opaque)
 {
     paaudio *g = opaque;
+    PAConnection *c = g->conn;
 
-    if (g->mainloop) {
-        pa_threaded_mainloop_stop (g->mainloop);
-    }
-
-    if (g->context) {
-        pa_context_disconnect (g->context);
-        pa_context_unref (g->context);
-    }
-
-    if (g->mainloop) {
-        pa_threaded_mainloop_free (g->mainloop);
+    if (--c->refcount == 0) {
+        qpa_conn_fini(c);
     }
 
     g_free(g);
Signature · 1 line
2.22.0
#19 lore raw

PATCH v2 12/14 audio: remove read and write pcm_ops

In reply to Kővágó, Zoltán

They just called audio_pcm_sw_read/write anyway, so it makes no sense to have them too. (The noaudio's read is the only exception, but it should work with the generic code too.)

---
 audio/audio_int.h   |  5 -----
 audio/alsaaudio.c   | 12 ------------
 audio/audio.c       |  8 ++++----
 audio/coreaudio.c   |  6 ------
 audio/dsoundaudio.c | 12 ------------
 audio/noaudio.c     | 19 -------------------
 audio/ossaudio.c    | 12 ------------
 audio/paaudio.c     | 12 ------------
 audio/sdlaudio.c    |  6 ------
 audio/spiceaudio.c  | 12 ------------
 audio/wavaudio.c    |  6 ------
 11 files changed, 4 insertions(+), 106 deletions(-)
audio/audio_int.h +0 -5
index 7e00c1332e..003b7ab8cc 100644
@@ -150,13 +150,11 @@ struct audio_pcm_ops {
     int  (*init_out)(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque);
     void (*fini_out)(HWVoiceOut *hw);
     int  (*run_out) (HWVoiceOut *hw, int live);
-    int  (*write)   (SWVoiceOut *sw, void *buf, int size);
     int  (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
 
     int  (*init_in) (HWVoiceIn *hw, struct audsettings *as, void *drv_opaque);
     void (*fini_in) (HWVoiceIn *hw);
     int  (*run_in)  (HWVoiceIn *hw);
-    int  (*read)    (SWVoiceIn *sw, void *buf, int size);
     int  (*ctl_in)  (HWVoiceIn *hw, int cmd, ...);
 };
 
@@ -210,11 +208,8 @@ audio_driver *audio_driver_lookup(const char *name);
 void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
 void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
 
-int  audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
 int  audio_pcm_hw_get_live_in (HWVoiceIn *hw);
 
-int  audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
-
 int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
                            int live, int pending);
 
audio/alsaaudio.c +0 -12
index 3daa7c8f8f..e9e3a4819c 100644
@@ -270,11 +270,6 @@ static int alsa_poll_in (HWVoiceIn *hw)
     return alsa_poll_helper (alsa->handle, &alsa->pollhlp, POLLIN);
 }
 
-static int alsa_write (SWVoiceOut *sw, void *buf, int len)
-{
-    return audio_pcm_sw_write (sw, buf, len);
-}
-
 static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
 {
     switch (fmt) {
@@ -988,11 +983,6 @@ static int alsa_run_in (HWVoiceIn *hw)
     return read_samples;
 }
 
-static int alsa_read (SWVoiceIn *sw, void *buf, int size)
-{
-    return audio_pcm_sw_read (sw, buf, size);
-}
-
 static int alsa_ctl_in (HWVoiceIn *hw, int cmd, ...)
 {
     ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
@@ -1076,13 +1066,11 @@ static struct audio_pcm_ops alsa_pcm_ops = {
     .init_out = alsa_init_out,
     .fini_out = alsa_fini_out,
     .run_out  = alsa_run_out,
-    .write    = alsa_write,
     .ctl_out  = alsa_ctl_out,
 
     .init_in  = alsa_init_in,
     .fini_in  = alsa_fini_in,
     .run_in   = alsa_run_in,
-    .read     = alsa_read,
     .ctl_in   = alsa_ctl_in,
 };
 
audio/audio.c +4 -4
index 07b35ffa03..254499dfa1 100644
@@ -594,7 +594,7 @@ static int audio_pcm_sw_get_rpos_in (SWVoiceIn *sw)
     }
 }
 
-int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size)
+static int audio_pcm_sw_read(SWVoiceIn *sw, void *buf, int size)
 {
     HWVoiceIn *hw = sw->hw;
     int samples, live, ret = 0, swlim, isamp, osamp, rpos, total = 0;
@@ -696,7 +696,7 @@ static int audio_pcm_hw_get_live_out (HWVoiceOut *hw, int *nb_live)
 /*
  * Soft voice (playback)
  */
-int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size)
+static int audio_pcm_sw_write(SWVoiceOut *sw, void *buf, int size)
 {
     int hwsamples, samples, isamp, osamp, wpos, live, dead, left, swlim, blck;
     int ret = 0, pos = 0, total = 0;
@@ -854,7 +854,7 @@ int AUD_write (SWVoiceOut *sw, void *buf, int size)
         return 0;
     }
 
-    return sw->hw->pcm_ops->write(sw, buf, size);
+    return audio_pcm_sw_write(sw, buf, size);
 }
 
 int AUD_read (SWVoiceIn *sw, void *buf, int size)
@@ -869,7 +869,7 @@ int AUD_read (SWVoiceIn *sw, void *buf, int size)
         return 0;
     }
 
-    return sw->hw->pcm_ops->read(sw, buf, size);
+    return audio_pcm_sw_read(sw, buf, size);
 }
 
 int AUD_get_buffer_size_out (SWVoiceOut *sw)
audio/coreaudio.c +0 -6
index f0ab4014a8..091fe84a34 100644
@@ -489,11 +489,6 @@ static OSStatus audioDeviceIOProc(
     return 0;
 }
 
-static int coreaudio_write (SWVoiceOut *sw, void *buf, int len)
-{
-    return audio_pcm_sw_write (sw, buf, len);
-}
-
 static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
                               void *drv_opaque)
 {
@@ -692,7 +687,6 @@ static struct audio_pcm_ops coreaudio_pcm_ops = {
     .init_out = coreaudio_init_out,
     .fini_out = coreaudio_fini_out,
     .run_out  = coreaudio_run_out,
-    .write    = coreaudio_write,
     .ctl_out  = coreaudio_ctl_out
 };
 
audio/dsoundaudio.c +0 -12
index 07260f881e..11594c3095 100644
@@ -454,11 +454,6 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...)
     return 0;
 }
 
-static int dsound_write (SWVoiceOut *sw, void *buf, int len)
-{
-    return audio_pcm_sw_write (sw, buf, len);
-}
-
 static int dsound_run_out (HWVoiceOut *hw, int live)
 {
     int err;
@@ -645,11 +640,6 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...)
     return 0;
 }
 
-static int dsound_read (SWVoiceIn *sw, void *buf, int len)
-{
-    return audio_pcm_sw_read (sw, buf, len);
-}
-
 static int dsound_run_in (HWVoiceIn *hw)
 {
     int err;
@@ -856,13 +846,11 @@ static struct audio_pcm_ops dsound_pcm_ops = {
     .init_out = dsound_init_out,
     .fini_out = dsound_fini_out,
     .run_out  = dsound_run_out,
-    .write    = dsound_write,
     .ctl_out  = dsound_ctl_out,
 
     .init_in  = dsound_init_in,
     .fini_in  = dsound_fini_in,
     .run_in   = dsound_run_in,
-    .read     = dsound_read,
     .ctl_in   = dsound_ctl_in
 };
 
audio/noaudio.c +0 -19
index 14a0e4ab29..cbb02d9e49 100644
@@ -61,11 +61,6 @@ static int no_run_out (HWVoiceOut *hw, int live)
     return decr;
 }
 
-static int no_write (SWVoiceOut *sw, void *buf, int len)
-{
-    return audio_pcm_sw_write(sw, buf, len);
-}
-
 static int no_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque)
 {
     audio_pcm_init_info (&hw->info, as);
@@ -118,18 +113,6 @@ static int no_run_in (HWVoiceIn *hw)
     return samples;
 }
 
-static int no_read (SWVoiceIn *sw, void *buf, int size)
-{
-    /* use custom code here instead of audio_pcm_sw_read() to avoid
-     * useless resampling/mixing */
-    int samples = size >> sw->info.shift;
-    int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
-    int to_clear = MIN (samples, total);
-    sw->total_hw_samples_acquired += total;
-    audio_pcm_info_clear_buf (&sw->info, buf, to_clear);
-    return to_clear << sw->info.shift;
-}
-
 static int no_ctl_in (HWVoiceIn *hw, int cmd, ...)
 {
     (void) hw;
@@ -151,13 +134,11 @@ static struct audio_pcm_ops no_pcm_ops = {
     .init_out = no_init_out,
     .fini_out = no_fini_out,
     .run_out  = no_run_out,
-    .write    = no_write,
     .ctl_out  = no_ctl_out,
 
     .init_in  = no_init_in,
     .fini_in  = no_fini_in,
     .run_in   = no_run_in,
-    .read     = no_read,
     .ctl_in   = no_ctl_in
 };
 
audio/ossaudio.c +0 -12
index 456fba7480..b99edbec17 100644
@@ -134,11 +134,6 @@ static void oss_poll_in (HWVoiceIn *hw)
     qemu_set_fd_handler(oss->fd, oss_helper_poll_in, NULL, hw->s);
 }
 
-static int oss_write (SWVoiceOut *sw, void *buf, int len)
-{
-    return audio_pcm_sw_write (sw, buf, len);
-}
-
 static int aud_to_ossfmt (AudioFormat fmt, int endianness)
 {
     switch (fmt) {
@@ -788,11 +783,6 @@ static int oss_run_in (HWVoiceIn *hw)
     return read_samples;
 }
 
-static int oss_read (SWVoiceIn *sw, void *buf, int size)
-{
-    return audio_pcm_sw_read (sw, buf, size);
-}
-
 static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...)
 {
     OSSVoiceIn *oss = (OSSVoiceIn *) hw;
@@ -855,13 +845,11 @@ static struct audio_pcm_ops oss_pcm_ops = {
     .init_out = oss_init_out,
     .fini_out = oss_fini_out,
     .run_out  = oss_run_out,
-    .write    = oss_write,
     .ctl_out  = oss_ctl_out,
 
     .init_in  = oss_init_in,
     .fini_in  = oss_fini_in,
     .run_in   = oss_run_in,
-    .read     = oss_read,
     .ctl_in   = oss_ctl_in
 };
 
audio/paaudio.c +0 -12
index c8ae1a6eca..efb72ced30 100644
@@ -295,11 +295,6 @@ static int qpa_run_out (HWVoiceOut *hw, int live)
     return decr;
 }
 
-static int qpa_write (SWVoiceOut *sw, void *buf, int len)
-{
-    return audio_pcm_sw_write (sw, buf, len);
-}
-
 /* capture */
 static void *qpa_thread_in (void *arg)
 {
@@ -388,11 +383,6 @@ static int qpa_run_in (HWVoiceIn *hw)
     return incr;
 }
 
-static int qpa_read (SWVoiceIn *sw, void *buf, int len)
-{
-    return audio_pcm_sw_read (sw, buf, len);
-}
-
 static pa_sample_format_t audfmt_to_pa (AudioFormat afmt, int endianness)
 {
     int format;
@@ -1016,13 +1006,11 @@ static struct audio_pcm_ops qpa_pcm_ops = {
     .init_out = qpa_init_out,
     .fini_out = qpa_fini_out,
     .run_out  = qpa_run_out,
-    .write    = qpa_write,
     .ctl_out  = qpa_ctl_out,
 
     .init_in  = qpa_init_in,
     .fini_in  = qpa_fini_in,
     .run_in   = qpa_run_in,
-    .read     = qpa_read,
     .ctl_in   = qpa_ctl_in
 };
 
audio/sdlaudio.c +0 -6
index 42f7614124..c7fd487e0e 100644
@@ -217,11 +217,6 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
     }
 }
 
-static int sdl_write_out (SWVoiceOut *sw, void *buf, int len)
-{
-    return audio_pcm_sw_write (sw, buf, len);
-}
-
 static int sdl_run_out (HWVoiceOut *hw, int live)
 {
     int decr;
@@ -342,7 +337,6 @@ static struct audio_pcm_ops sdl_pcm_ops = {
     .init_out = sdl_init_out,
     .fini_out = sdl_fini_out,
     .run_out  = sdl_run_out,
-    .write    = sdl_write_out,
     .ctl_out  = sdl_ctl_out,
 };
 
audio/spiceaudio.c +0 -12
index 6f4a0558f8..6e7f13cffa 100644
@@ -193,11 +193,6 @@ static int line_out_run (HWVoiceOut *hw, int live)
     return decr;
 }
 
-static int line_out_write (SWVoiceOut *sw, void *buf, int len)
-{
-    return audio_pcm_sw_write (sw, buf, len);
-}
-
 static int line_out_ctl (HWVoiceOut *hw, int cmd, ...)
 {
     SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw);
@@ -326,11 +321,6 @@ static int line_in_run (HWVoiceIn *hw)
     return num_samples;
 }
 
-static int line_in_read (SWVoiceIn *sw, void *buf, int size)
-{
-    return audio_pcm_sw_read (sw, buf, size);
-}
-
 static int line_in_ctl (HWVoiceIn *hw, int cmd, ...)
 {
     SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw);
@@ -378,13 +368,11 @@ static struct audio_pcm_ops audio_callbacks = {
     .init_out = line_out_init,
     .fini_out = line_out_fini,
     .run_out  = line_out_run,
-    .write    = line_out_write,
     .ctl_out  = line_out_ctl,
 
     .init_in  = line_in_init,
     .fini_in  = line_in_fini,
     .run_in   = line_in_run,
-    .read     = line_in_read,
     .ctl_in   = line_in_ctl,
 };
 
audio/wavaudio.c +0 -6
index bbf3f3b346..17ab921cef 100644
@@ -84,11 +84,6 @@ static int wav_run_out (HWVoiceOut *hw, int live)
     return decr;
 }
 
-static int wav_write_out (SWVoiceOut *sw, void *buf, int len)
-{
-    return audio_pcm_sw_write (sw, buf, len);
-}
-
 /* VICE code: Store number as little endian. */
 static void le_store (uint8_t *buf, uint32_t val, int len)
 {
@@ -240,7 +235,6 @@ static struct audio_pcm_ops wav_pcm_ops = {
     .init_out = wav_init_out,
     .fini_out = wav_fini_out,
     .run_out  = wav_run_out,
-    .write    = wav_write_out,
     .ctl_out  = wav_ctl_out,
 };
 
Signature · 1 line
2.22.0
#1 lore raw

PATCH v2 1/14 audio: reduce glob_audio_state usage

In reply to Kővágó, Zoltán

Remove glob_audio_state from functions, where possible without breaking the API. This means that most static functions in audio.c now take an AudioState pointer instead of implicitly using glob_audio_state. Also included a pointer in SWVoice*, HWVoice* structs, so that functions dealing them can know the audio state without having to pass it around separately.

This is required in order to support multiple simultaneous audio backends (added in a later commit).

---
 audio/audio_int.h      |  8 ++++++
 audio/audio_template.h | 46 ++++++++++++++++----------------
 audio/audio.c          | 59 +++++++++++++++++++-----------------------
 3 files changed, 57 insertions(+), 56 deletions(-)
audio/audio_int.h +8 -0
index 3f14842709..8164696b2c 100644
@@ -49,9 +49,11 @@ struct audio_pcm_info {
     int swap_endianness;
 };
 
+typedef struct AudioState AudioState;
 typedef struct SWVoiceCap SWVoiceCap;
 
 typedef struct HWVoiceOut {
+    AudioState *s;
     int enabled;
     int poll_mode;
     int pending_disable;
@@ -73,6 +75,7 @@ typedef struct HWVoiceOut {
 } HWVoiceOut;
 
 typedef struct HWVoiceIn {
+    AudioState *s;
     int enabled;
     int poll_mode;
     struct audio_pcm_info info;
@@ -94,6 +97,7 @@ typedef struct HWVoiceIn {
 
 struct SWVoiceOut {
     QEMUSoundCard *card;
+    AudioState *s;
     struct audio_pcm_info info;
     t_sample *conv;
     int64_t ratio;
@@ -111,6 +115,7 @@ struct SWVoiceOut {
 
 struct SWVoiceIn {
     QEMUSoundCard *card;
+    AudioState *s;
     int active;
     struct audio_pcm_info info;
     int64_t ratio;
@@ -188,6 +193,9 @@ typedef struct AudioState {
     int nb_hw_voices_in;
     int vm_running;
     int64_t period_ticks;
+
+    bool timer_running;
+    uint64_t timer_last;
 } AudioState;
 
 extern const struct mixeng_volume nominal_volume;
audio/audio_template.h +22 -24

137 lines not on this page · raw message

audio/audio.c +27 -32

175 lines not on this page · raw message

Signature · 1 line
2.22.0
#18 lore raw

PATCH v2 11/14 paaudio: fix playback glitches

In reply to Kővágó, Zoltán

Pulseaudio normally assumes that when the server wants it, the client can generate the audio samples and send it right away. Unfortunately this is not the case with QEMU -- it's up to the emulated system when does it generate the samples. Buffering the samples and sending them from a background thread is just a workaround, that doesn't work too well. Instead enable pa's compatibility support and let pa worry about the details.

---
 audio/paaudio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
audio/paaudio.c +2 -4
index f3864e1d50..c8ae1a6eca 100644
@@ -512,10 +512,8 @@ static pa_stream *qpa_simple_new (
 
     flags =
         PA_STREAM_INTERPOLATE_TIMING
-#ifdef PA_STREAM_ADJUST_LATENCY
-        | PA_STREAM_ADJUST_LATENCY
-#endif
-        | PA_STREAM_AUTO_TIMING_UPDATE;
+        | PA_STREAM_AUTO_TIMING_UPDATE
+        | PA_STREAM_EARLY_REQUESTS;
 
     if (dev) {
         /* don't move the stream if the user specified a sink/source */
Signature · 1 line
2.22.0
#13 lore raw

PATCH v2 6/14 audio: audiodev= parameters no longer optional when -audiodev present

In reply to Kővágó, Zoltán

This means you should probably stop using -soundhw (as it doesn't allow you to specify any options) and add the device manually with -device. The exception is pcspk, it's currently not possible to manually add it. To use it with audiodev, use something like this:

-audiodev id=foo,... -global isa-pcspk.audiodev=foo -soundhw pcspk

---

Notes:
Changes from v1:

* Split off paaudio changes to a different commit.

 audio/audio.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
audio/audio.c +15 -9
index 4baa37caac..d131958194 100644
@@ -101,6 +101,8 @@ const struct mixeng_volume nominal_volume = {
 #endif
 };
 
+static bool legacy_config = true;
+
 #ifdef AUDIO_IS_FLAWLESS_AND_NO_CHECKS_ARE_REQURIED
 #error No its not
 #else
@@ -1392,7 +1394,7 @@ static AudiodevListEntry *audiodev_find(
  * if dev == NULL => legacy implicit initialization, return the already created
  *   state or create a new one
  */
-static AudioState *audio_init(Audiodev *dev)
+static AudioState *audio_init(Audiodev *dev, const char *name)
 {
     static bool atexit_registered;
     size_t i;
@@ -1406,12 +1408,13 @@ static AudioState *audio_init(Audiodev *dev)
 
     if (dev) {
         /* -audiodev option */
+        legacy_config = false;
         drvname = AudiodevDriver_str(dev->driver);
     } else if (!QTAILQ_EMPTY(&audio_states)) {
-        /*
-         * todo: check for -audiodev once we have normal audiodev selection
-         * support
-         */
+        if (!legacy_config) {
+            dolog("You must specify an audiodev= for the device %s\n", name);
+            exit(1);
+        }
         return QTAILQ_FIRST(&audio_states);
     } else {
         /* legacy implicit initialization */
@@ -1518,7 +1521,7 @@ void audio_free_audiodev_list(AudiodevListHead *head)
 void AUD_register_card (const char *name, QEMUSoundCard *card)
 {
     if (!card->state) {
-        card->state = audio_init(NULL);
+        card->state = audio_init(NULL, name);
     }
 
     card->name = g_strdup (name);
@@ -1544,8 +1547,11 @@ CaptureVoiceOut *AUD_add_capture(
     struct capture_callback *cb;
 
     if (!s) {
-        /* todo: remove when we have normal audiodev selection support */
-        s = audio_init(NULL);
+        if (!legacy_config) {
+            dolog("You must specify audiodev when trying to capture\n");
+            return NULL;
+        }
+        s = audio_init(NULL, NULL);
     }
 
     if (audio_validate_settings (as)) {
@@ -1776,7 +1782,7 @@ void audio_init_audiodevs(void)
     AudiodevListEntry *e;
 
     QSIMPLEQ_FOREACH(e, &audiodevs, next) {
-        audio_init(e->dev);
+        audio_init(e->dev, NULL);
     }
 }
 
Signature · 1 line
2.22.0
#21 lore raw

PATCH v2 14/14 audio: fix memory leak reported by ASAN

In reply to Kővágó, Zoltán
---
 audio/audio.c | 6 ++++++
 1 file changed, 6 insertions(+)
audio/audio.c +6 -0
index d3c639211d..ebe49f3ca1 100644
@@ -1343,6 +1343,12 @@ static void free_audio_state(AudioState *s)
         qapi_free_Audiodev(s->dev);
         s->dev = NULL;
     }
+
+    if (s->ts) {
+        timer_free(s->ts);
+        s->ts = NULL;
+    }
+
     g_free(s);
 }
 
Signature · 1 line
2.22.0
#14 lore raw

PATCH v2 7/14 paaudio: do not move stream when sink/source name is specified

In reply to Kővágó, Zoltán

Unless we disable stream moving, pulseaudio can easily move the stream on connect, effectively ignoring the source/sink specified by the user.

---
 audio/paaudio.c | 5 +++++
 1 file changed, 5 insertions(+)
audio/paaudio.c +5 -0
index cc3a34c2ea..24d98b344a 100644
@@ -517,6 +517,11 @@ static pa_stream *qpa_simple_new (
 #endif
         | PA_STREAM_AUTO_TIMING_UPDATE;
 
+    if (dev) {
+        /* don't move the stream if the user specified a sink/source */
+        flags |= PA_STREAM_DONT_MOVE;
+    }
+
     if (dir == PA_STREAM_PLAYBACK) {
         r = pa_stream_connect_playback(stream, dev, attr, flags, NULL, NULL);
     } else {
Signature · 1 line
2.22.0
#17 lore raw

PATCH v2 10/14 audio: do not run each backend in audio_run

In reply to Kővágó, Zoltán

audio_run is called manually by alsa and oss backends when polling. In this case only the requesting backend should be run, not all of them.

---
 audio/audio_int.h |  2 +-
 audio/alsaaudio.c |  7 +++++--
 audio/audio.c     | 14 +++++---------
 audio/ossaudio.c  | 12 ++++++------
 4 files changed, 17 insertions(+), 18 deletions(-)
audio/audio_int.h +1 -1
index 9f01f6ad00..7e00c1332e 100644
@@ -221,7 +221,7 @@ int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
 int audio_bug (const char *funcname, int cond);
 void *audio_calloc (const char *funcname, int nmemb, size_t size);
 
-void audio_run (const char *msg);
+void audio_run(AudioState *s, const char *msg);
 
 #define VOICE_ENABLE 1
 #define VOICE_DISABLE 2
audio/alsaaudio.c +5 -2
index 6b9e0f06af..3daa7c8f8f 100644
@@ -39,6 +39,7 @@ struct pollhlp {
     struct pollfd *pfds;
     int count;
     int mask;
+    AudioState *s;
 };
 
 typedef struct ALSAVoiceOut {
@@ -199,11 +200,11 @@ static void alsa_poll_handler (void *opaque)
         break;
 
     case SND_PCM_STATE_PREPARED:
-        audio_run ("alsa run (prepared)");
+        audio_run(hlp->s, "alsa run (prepared)");
         break;
 
     case SND_PCM_STATE_RUNNING:
-        audio_run ("alsa run (running)");
+        audio_run(hlp->s, "alsa run (running)");
         break;
 
     default:
@@ -749,6 +750,7 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
         return -1;
     }
 
+    alsa->pollhlp.s = hw->s;
     alsa->handle = handle;
     alsa->dev = dev;
     return 0;
@@ -850,6 +852,7 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
         return -1;
     }
 
+    alsa->pollhlp.s = hw->s;
     alsa->handle = handle;
     alsa->dev = dev;
     return 0;
audio/audio.c +5 -9
index cb0222ab4a..07b35ffa03 100644
@@ -835,7 +835,7 @@ static void audio_timer (void *opaque)
     }
     s->timer_last = now;
 
-    audio_run("timer");
+    audio_run(s, "timer");
     audio_reset_timer(s);
 }
 
@@ -1237,15 +1237,11 @@ static void audio_run_capture (AudioState *s)
     }
 }
 
-void audio_run (const char *msg)
+void audio_run(AudioState *s, const char *msg)
 {
-    AudioState *s;
-
-    QTAILQ_FOREACH(s, &audio_states, list) {
-        audio_run_out(s);
-        audio_run_in(s);
-        audio_run_capture(s);
-    }
+    audio_run_out(s);
+    audio_run_in(s);
+    audio_run_capture(s);
 
 #ifdef DEBUG_POLL
     {
audio/ossaudio.c +6 -6
index 29139ef1f5..456fba7480 100644
@@ -110,28 +110,28 @@ static void oss_anal_close (int *fdp)
 
 static void oss_helper_poll_out (void *opaque)
 {
-    (void) opaque;
-    audio_run ("oss_poll_out");
+    AudioState *s = opaque;
+    audio_run(s, "oss_poll_out");
 }
 
 static void oss_helper_poll_in (void *opaque)
 {
-    (void) opaque;
-    audio_run ("oss_poll_in");
+    AudioState *s = opaque;
+    audio_run(s, "oss_poll_in");
 }
 
 static void oss_poll_out (HWVoiceOut *hw)
 {
     OSSVoiceOut *oss = (OSSVoiceOut *) hw;
 
-    qemu_set_fd_handler (oss->fd, NULL, oss_helper_poll_out, NULL);
+    qemu_set_fd_handler(oss->fd, NULL, oss_helper_poll_out, hw->s);
 }
 
 static void oss_poll_in (HWVoiceIn *hw)
 {
     OSSVoiceIn *oss = (OSSVoiceIn *) hw;
 
-    qemu_set_fd_handler (oss->fd, oss_helper_poll_in, NULL, NULL);
+    qemu_set_fd_handler(oss->fd, oss_helper_poll_in, NULL, hw->s);
 }
 
 static int oss_write (SWVoiceOut *sw, void *buf, int len)
Signature · 1 line
2.22.0
#15 lore raw

PATCH v2 8/14 paaudio: properly disconnect streams in fini_*

In reply to Kővágó, Zoltán

Currently this needs a workaround due to bug #247 in pulseaudio.

---
 audio/paaudio.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
audio/paaudio.c +23 -2
index 24d98b344a..1d68173636 100644
@@ -685,6 +685,27 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
     return -1;
 }
 
+static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream)
+{
+    int err;
+
+    pa_threaded_mainloop_lock(c->mainloop);
+    /*
+     * wait until actually connects. workaround pa bug #247
+     * https://gitlab.freedesktop.org/pulseaudio/pulseaudio/issues/247
+     */
+    while (pa_stream_get_state(stream) == PA_STREAM_CREATING) {
+        pa_threaded_mainloop_wait(c->mainloop);
+    }
+
+    err = pa_stream_disconnect(stream);
+    if (err != 0) {
+        dolog("Failed to disconnect! err=%d\n", err);
+    }
+    pa_stream_unref(stream);
+    pa_threaded_mainloop_unlock(c->mainloop);
+}
+
 static void qpa_fini_out (HWVoiceOut *hw)
 {
     void *ret;
@@ -696,7 +717,7 @@ static void qpa_fini_out (HWVoiceOut *hw)
     audio_pt_join(&pa->pt, &ret, __func__);
 
     if (pa->stream) {
-        pa_stream_unref (pa->stream);
+        qpa_simple_disconnect(pa->g->conn, pa->stream);
         pa->stream = NULL;
     }
 
@@ -716,7 +737,7 @@ static void qpa_fini_in (HWVoiceIn *hw)
     audio_pt_join(&pa->pt, &ret, __func__);
 
     if (pa->stream) {
-        pa_stream_unref (pa->stream);
+        qpa_simple_disconnect(pa->g->conn, pa->stream);
         pa->stream = NULL;
     }
 
Signature · 1 line
2.22.0
#16 lore raw

PATCH v2 9/14 audio: remove audio_MIN, audio_MAX

In reply to Kővágó, Zoltán

There's already a MIN and MAX macro in include/qemu/osdep.h, use them instead.

---
 audio/audio.h             | 17 -----------------
 audio/alsaaudio.c         |  6 +++---
 audio/audio.c             | 20 ++++++++++----------
 audio/coreaudio.c         |  2 +-
 audio/dsoundaudio.c       |  2 +-
 audio/noaudio.c           | 10 +++++-----
 audio/ossaudio.c          |  6 +++---
 audio/paaudio.c           | 12 ++++++------
 audio/sdlaudio.c          |  6 +++---
 audio/spiceaudio.c        | 10 +++++-----
 audio/wavaudio.c          |  4 ++--
 hw/audio/ac97.c           | 10 +++++-----
 hw/audio/adlib.c          |  4 ++--
 hw/audio/cs4231a.c        |  4 ++--
 hw/audio/es1370.c         |  6 +++---
 hw/audio/gus.c            |  6 +++---
 hw/audio/hda-codec.c      | 16 ++++++++--------
 hw/audio/milkymist-ac97.c |  8 ++++----
 hw/audio/pcspk.c          |  2 +-
 hw/audio/sb16.c           |  2 +-
 hw/audio/wm8750.c         |  4 ++--
 21 files changed, 70 insertions(+), 87 deletions(-)
audio/audio.h +0 -17
index c0722a5cda..4a95758516 100644
@@ -146,23 +146,6 @@ static inline void *advance (void *p, int incr)
     return (d + incr);
 }
 
-#ifdef __GNUC__
-#define audio_MIN(a, b) ( __extension__ ({      \
-    __typeof (a) ta = a;                        \
-    __typeof (b) tb = b;                        \
-    ((ta)>(tb)?(tb):(ta));                      \
-}))
-
-#define audio_MAX(a, b) ( __extension__ ({      \
-    __typeof (a) ta = a;                        \
-    __typeof (b) tb = b;                        \
-    ((ta)<(tb)?(tb):(ta));                      \
-}))
-#else
-#define audio_MIN(a, b) ((a)>(b)?(b):(a))
-#define audio_MAX(a, b) ((a)<(b)?(b):(a))
-#endif
-
 int wav_start_capture(AudioState *state, CaptureState *s, const char *path,
                       int freq, int bits, int nchannels);
 
audio/alsaaudio.c +3 -3
index 3745c823ad..6b9e0f06af 100644
@@ -634,7 +634,7 @@ static void alsa_write_pending (ALSAVoiceOut *alsa)
 
     while (alsa->pending) {
         int left_till_end_samples = hw->samples - alsa->wpos;
-        int len = audio_MIN (alsa->pending, left_till_end_samples);
+        int len = MIN (alsa->pending, left_till_end_samples);
         char *src = advance (alsa->pcm_buf, alsa->wpos << hw->info.shift);
 
         while (len) {
@@ -697,7 +697,7 @@ static int alsa_run_out (HWVoiceOut *hw, int live)
         return 0;
     }
 
-    decr = audio_MIN (live, avail);
+    decr = MIN (live, avail);
     decr = audio_pcm_hw_clip_out (hw, alsa->pcm_buf, decr, alsa->pending);
     alsa->pending += decr;
     alsa_write_pending (alsa);
@@ -915,7 +915,7 @@ static int alsa_run_in (HWVoiceIn *hw)
         }
     }
 
-    decr = audio_MIN (dead, avail);
+    decr = MIN (dead, avail);
     if (!decr) {
         return 0;
     }
audio/audio.c +10 -10
index d131958194..cb0222ab4a 100644
@@ -533,7 +533,7 @@ static int audio_pcm_hw_find_min_in (HWVoiceIn *hw)
 
     for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
         if (sw->active) {
-            m = audio_MIN (m, sw->total_hw_samples_acquired);
+            m = MIN (m, sw->total_hw_samples_acquired);
         }
     }
     return m;
@@ -553,14 +553,14 @@ int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
                            int live, int pending)
 {
     int left = hw->samples - pending;
-    int len = audio_MIN (left, live);
+    int len = MIN (left, live);
     int clipped = 0;
 
     while (len) {
         struct st_sample *src = hw->mix_buf + hw->rpos;
         uint8_t *dst = advance (pcm_buf, hw->rpos << hw->info.shift);
         int samples_till_end_of_buf = hw->samples - hw->rpos;
-        int samples_to_clip = audio_MIN (len, samples_till_end_of_buf);
+        int samples_to_clip = MIN (len, samples_till_end_of_buf);
 
         hw->clip (dst, src, samples_to_clip);
 
@@ -614,7 +614,7 @@ int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size)
     }
 
     swlim = (live * sw->ratio) >> 32;
-    swlim = audio_MIN (swlim, samples);
+    swlim = MIN (swlim, samples);
 
     while (swlim) {
         src = hw->conv_buf + rpos;
@@ -662,7 +662,7 @@ static int audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep)
 
     for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
         if (sw->active || !sw->empty) {
-            m = audio_MIN (m, sw->total_hw_samples_mixed);
+            m = MIN (m, sw->total_hw_samples_mixed);
             nb_live += 1;
         }
     }
@@ -725,7 +725,7 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size)
 
     dead = hwsamples - live;
     swlim = ((int64_t) dead << 32) / sw->ratio;
-    swlim = audio_MIN (swlim, samples);
+    swlim = MIN (swlim, samples);
     if (swlim) {
         sw->conv (sw->buf, buf, swlim);
 
@@ -737,7 +737,7 @@ int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size)
     while (swlim) {
         dead = hwsamples - live;
         left = hwsamples - wpos;
-        blck = audio_MIN (dead, left);
+        blck = MIN (dead, left);
         if (!blck) {
             break;
         }
@@ -1029,7 +1029,7 @@ static void audio_capture_mix_and_clear (HWVoiceOut *hw, int rpos, int samples)
             n = samples;
             while (n) {
                 int till_end_of_hw = hw->samples - rpos2;
-                int to_write = audio_MIN (till_end_of_hw, n);
+                int to_write = MIN (till_end_of_hw, n);
                 int bytes = to_write << hw->info.shift;
                 int written;
 
@@ -1047,7 +1047,7 @@ static void audio_capture_mix_and_clear (HWVoiceOut *hw, int rpos, int samples)
         }
     }
 
-    n = audio_MIN (samples, hw->samples - rpos);
+    n = MIN (samples, hw->samples - rpos);
     mixeng_clear (hw->mix_buf + rpos, n);
     mixeng_clear (hw->mix_buf, samples - n);
 }
@@ -1203,7 +1203,7 @@ static void audio_run_capture (AudioState *s)
         rpos = hw->rpos;
         while (live) {
             int left = hw->samples - rpos;
-            int to_capture = audio_MIN (live, left);
+            int to_capture = MIN (live, left);
             struct st_sample *src;
             struct capture_callback *cb;
 
audio/coreaudio.c +1 -1
index 4bec6c8c5c..f0ab4014a8 100644
@@ -413,7 +413,7 @@ static int coreaudio_run_out (HWVoiceOut *hw, int live)
                 core->live);
     }
 
-    decr = audio_MIN (core->decr, live);
+    decr = MIN (core->decr, live);
     core->decr -= decr;
 
     core->live = live - decr;
audio/dsoundaudio.c +1 -1
index 5da4c864c3..07260f881e 100644
@@ -707,7 +707,7 @@ static int dsound_run_in (HWVoiceIn *hw)
     if (!len) {
         return 0;
     }
-    len = audio_MIN (len, dead);
+    len = MIN (len, dead);
 
     err = dsound_lock_in (
         dscb,
audio/noaudio.c +5 -5
index 9b195dc52c..14a0e4ab29 100644
@@ -52,11 +52,11 @@ static int no_run_out (HWVoiceOut *hw, int live)
     now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
     ticks = now - no->old_ticks;
     bytes = muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);
-    bytes = audio_MIN(bytes, INT_MAX);
+    bytes = MIN(bytes, INT_MAX);
     samples = bytes >> hw->info.shift;
 
     no->old_ticks = now;
-    decr = audio_MIN (live, samples);
+    decr = MIN (live, samples);
     hw->rpos = (hw->rpos + decr) % hw->samples;
     return decr;
 }
@@ -111,9 +111,9 @@ static int no_run_in (HWVoiceIn *hw)
             muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);
 
         no->old_ticks = now;
-        bytes = audio_MIN (bytes, INT_MAX);
+        bytes = MIN (bytes, INT_MAX);
         samples = bytes >> hw->info.shift;
-        samples = audio_MIN (samples, dead);
+        samples = MIN (samples, dead);
     }
     return samples;
 }
@@ -124,7 +124,7 @@ static int no_read (SWVoiceIn *sw, void *buf, int size)
      * useless resampling/mixing */
     int samples = size >> sw->info.shift;
     int total = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
-    int to_clear = audio_MIN (samples, total);
+    int to_clear = MIN (samples, total);
     sw->total_hw_samples_acquired += total;
     audio_pcm_info_clear_buf (&sw->info, buf, to_clear);
     return to_clear << sw->info.shift;
audio/ossaudio.c +3 -3
index c0af065b6f..29139ef1f5 100644
@@ -388,7 +388,7 @@ static void oss_write_pending (OSSVoiceOut *oss)
         int samples_written;
         ssize_t bytes_written;
         int samples_till_end = hw->samples - oss->wpos;
-        int samples_to_write = audio_MIN (oss->pending, samples_till_end);
+        int samples_to_write = MIN (oss->pending, samples_till_end);
         int bytes_to_write = samples_to_write << hw->info.shift;
         void *pcm = advance (oss->pcm_buf, oss->wpos << hw->info.shift);
 
@@ -437,7 +437,7 @@ static int oss_run_out (HWVoiceOut *hw, int live)
 
         pos = hw->rpos << hw->info.shift;
         bytes = audio_ring_dist (cntinfo.ptr, pos, bufsize);
-        decr = audio_MIN (bytes >> hw->info.shift, live);
+        decr = MIN (bytes >> hw->info.shift, live);
     }
     else {
         err = ioctl (oss->fd, SNDCTL_DSP_GETOSPACE, &abinfo);
@@ -456,7 +456,7 @@ static int oss_run_out (HWVoiceOut *hw, int live)
             return 0;
         }
 
-        decr = audio_MIN (abinfo.bytes >> hw->info.shift, live);
+        decr = MIN (abinfo.bytes >> hw->info.shift, live);
         if (!decr) {
             return 0;
         }
audio/paaudio.c +6 -6
index 1d68173636..f3864e1d50 100644
@@ -235,7 +235,7 @@ static void *qpa_thread_out (void *arg)
             }
         }
 
-        decr = to_mix = audio_MIN(pa->live, pa->samples >> 5);
+        decr = to_mix = MIN(pa->live, pa->samples >> 5);
         rpos = pa->rpos;
 
         if (audio_pt_unlock(&pa->pt, __func__)) {
@@ -244,7 +244,7 @@ static void *qpa_thread_out (void *arg)
 
         while (to_mix) {
             int error;
-            int chunk = audio_MIN (to_mix, hw->samples - rpos);
+            int chunk = MIN (to_mix, hw->samples - rpos);
             struct st_sample *src = hw->mix_buf + rpos;
 
             hw->clip (pa->pcm_buf, src, chunk);
@@ -282,7 +282,7 @@ static int qpa_run_out (HWVoiceOut *hw, int live)
         return 0;
     }
 
-    decr = audio_MIN (live, pa->decr);
+    decr = MIN (live, pa->decr);
     pa->decr -= decr;
     pa->live = live - decr;
     hw->rpos = pa->rpos;
@@ -327,7 +327,7 @@ static void *qpa_thread_in (void *arg)
             }
         }
 
-        incr = to_grab = audio_MIN(pa->dead, pa->samples >> 5);
+        incr = to_grab = MIN(pa->dead, pa->samples >> 5);
         wpos = pa->wpos;
 
         if (audio_pt_unlock(&pa->pt, __func__)) {
@@ -336,7 +336,7 @@ static void *qpa_thread_in (void *arg)
 
         while (to_grab) {
             int error;
-            int chunk = audio_MIN (to_grab, hw->samples - wpos);
+            int chunk = MIN (to_grab, hw->samples - wpos);
             void *buf = advance (pa->pcm_buf, wpos);
 
             if (qpa_simple_read (pa, buf,
@@ -375,7 +375,7 @@ static int qpa_run_in (HWVoiceIn *hw)
 
     live = audio_pcm_hw_get_live_in (hw);
     dead = hw->samples - live;
-    incr = audio_MIN (dead, pa->incr);
+    incr = MIN (dead, pa->incr);
     pa->incr -= incr;
     pa->dead = dead - incr;
     hw->wpos = pa->wpos;
audio/sdlaudio.c +3 -3
index e7179ff1d4..42f7614124 100644
@@ -193,10 +193,10 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
 
     /* dolog ("in callback samples=%d live=%d\n", samples, sdl->live); */
 
-    to_mix = audio_MIN(samples, sdl->live);
+    to_mix = MIN(samples, sdl->live);
     decr = to_mix;
     while (to_mix) {
-        int chunk = audio_MIN(to_mix, hw->samples - hw->rpos);
+        int chunk = MIN(to_mix, hw->samples - hw->rpos);
         struct st_sample *src = hw->mix_buf + hw->rpos;
 
         /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
@@ -236,7 +236,7 @@ static int sdl_run_out (HWVoiceOut *hw, int live)
                 sdl->live);
     }
 
-    decr = audio_MIN (sdl->decr, live);
+    decr = MIN (sdl->decr, live);
     sdl->decr -= decr;
 
     sdl->live = live;
audio/spiceaudio.c +5 -5
index 0ead5ae43a..6f4a0558f8 100644
@@ -164,20 +164,20 @@ static int line_out_run (HWVoiceOut *hw, int live)
     }
 
     decr = rate_get_samples (&hw->info, &out->rate);
-    decr = audio_MIN (live, decr);
+    decr = MIN (live, decr);
 
     samples = decr;
     rpos = hw->rpos;
     while (samples) {
         int left_till_end_samples = hw->samples - rpos;
-        int len = audio_MIN (samples, left_till_end_samples);
+        int len = MIN (samples, left_till_end_samples);
 
         if (!out->frame) {
             spice_server_playback_get_buffer (&out->sin, &out->frame, &out->fsize);
             out->fpos = out->frame;
         }
         if (out->frame) {
-            len = audio_MIN (len, out->fsize);
+            len = MIN (len, out->fsize);
             hw->clip (out->fpos, hw->mix_buf + rpos, len);
             out->fsize -= len;
             out->fpos  += len;
@@ -295,7 +295,7 @@ static int line_in_run (HWVoiceIn *hw)
     }
 
     delta_samp = rate_get_samples (&hw->info, &in->rate);
-    num_samples = audio_MIN (num_samples, delta_samp);
+    num_samples = MIN (num_samples, delta_samp);
 
     ready = spice_server_record_get_samples (&in->sin, in->samples, num_samples);
     samples = in->samples;
@@ -305,7 +305,7 @@ static int line_in_run (HWVoiceIn *hw)
         ready = LINE_IN_SAMPLES;
     }
 
-    num_samples = audio_MIN (ready, num_samples);
+    num_samples = MIN (ready, num_samples);
 
     if (hw->wpos + num_samples > hw->samples) {
         len[0] = hw->samples - hw->wpos;
audio/wavaudio.c +2 -2
index 803b6cb1f3..bbf3f3b346 100644
@@ -59,12 +59,12 @@ static int wav_run_out (HWVoiceOut *hw, int live)
     }
 
     wav->old_ticks = now;
-    decr = audio_MIN (live, samples);
+    decr = MIN (live, samples);
     samples = decr;
     rpos = hw->rpos;
     while (samples) {
         int left_till_end_samples = hw->samples - rpos;
-        int convert_samples = audio_MIN (samples, left_till_end_samples);
+        int convert_samples = MIN (samples, left_till_end_samples);
 
         src = hw->mix_buf + rpos;
         dst = advance (wav->pcm_buf, rpos << hw->info.shift);
hw/audio/ac97.c +5 -5
index 0d8e524233..060bafdac3 100644
@@ -964,7 +964,7 @@ static int write_audio (AC97LinkState *s, AC97BusMasterRegs *r,
     uint32_t temp = r->picb << 1;
     uint32_t written = 0;
     int to_copy = 0;
-    temp = audio_MIN (temp, max);
+    temp = MIN (temp, max);
 
     if (!temp) {
         *stop = 1;
@@ -973,7 +973,7 @@ static int write_audio (AC97LinkState *s, AC97BusMasterRegs *r,
 
     while (temp) {
         int copied;
-        to_copy = audio_MIN (temp, sizeof (tmpbuf));
+        to_copy = MIN (temp, sizeof (tmpbuf));
         pci_dma_read (&s->dev, addr, tmpbuf, to_copy);
         copied = AUD_write (s->voice_po, tmpbuf, to_copy);
         dolog ("write_audio max=%x to_copy=%x copied=%x\n",
@@ -1019,7 +1019,7 @@ static void write_bup (AC97LinkState *s, int elapsed)
     }
 
     while (elapsed) {
-        int temp = audio_MIN (elapsed, sizeof (s->silence));
+        int temp = MIN (elapsed, sizeof (s->silence));
         while (temp) {
             int copied = AUD_write (s->voice_po, s->silence, temp);
             if (!copied)
@@ -1040,7 +1040,7 @@ static int read_audio (AC97LinkState *s, AC97BusMasterRegs *r,
     int to_copy = 0;
     SWVoiceIn *voice = (r - s->bm_regs) == MC_INDEX ? s->voice_mc : s->voice_pi;
 
-    temp = audio_MIN (temp, max);
+    temp = MIN (temp, max);
 
     if (!temp) {
         *stop = 1;
@@ -1049,7 +1049,7 @@ static int read_audio (AC97LinkState *s, AC97BusMasterRegs *r,
 
     while (temp) {
         int acquired;
-        to_copy = audio_MIN (temp, sizeof (tmpbuf));
+        to_copy = MIN (temp, sizeof (tmpbuf));
         acquired = AUD_read (voice, tmpbuf, to_copy);
         if (!acquired) {
             *stop = 1;
hw/audio/adlib.c +2 -2
index df2e781788..1b32c4ff7f 100644
@@ -195,7 +195,7 @@ static void adlib_callback (void *opaque, int free)
         return;
     }
 
-    to_play = audio_MIN (s->left, samples);
+    to_play = MIN (s->left, samples);
     while (to_play) {
         written = write_audio (s, to_play);
 
@@ -210,7 +210,7 @@ static void adlib_callback (void *opaque, int free)
         }
     }
 
-    samples = audio_MIN (samples, s->samples - s->pos);
+    samples = MIN (samples, s->samples - s->pos);
     if (!samples) {
         return;
     }
hw/audio/cs4231a.c +2 -2
index e3ea830b47..ca3af8a987 100644
@@ -535,7 +535,7 @@ static int cs_write_audio (CSState *s, int nchan, int dma_pos,
         int copied;
         size_t to_copy;
 
-        to_copy = audio_MIN (temp, left);
+        to_copy = MIN (temp, left);
         if (to_copy > sizeof (tmpbuf)) {
             to_copy = sizeof (tmpbuf);
         }
@@ -578,7 +578,7 @@ static int cs_dma_read (void *opaque, int nchan, int dma_pos, int dma_len)
         till = (s->dregs[Playback_Lower_Base_Count]
             | (s->dregs[Playback_Upper_Base_Count] << 8)) << s->shift;
         till -= s->transferred;
-        copy = audio_MIN (till, copy);
+        copy = MIN (till, copy);
     }
 
     if ((copy <= 0) || (dma_len <= 0)) {
hw/audio/es1370.c +3 -3
index 7589671d20..50b144ded0 100644
@@ -645,7 +645,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,
     int size = d->frame_cnt & 0xffff;
     int left = ((size - cnt + 1) << 2) + d->leftover;
     int transferred = 0;
-    int temp = audio_MIN (max, audio_MIN (left, csc_bytes));
+    int temp = MIN (max, MIN (left, csc_bytes));
     int index = d - &s->chan[0];
 
     addr += (cnt << 2) + d->leftover;
@@ -654,7 +654,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,
         while (temp) {
             int acquired, to_copy;
 
-            to_copy = audio_MIN ((size_t) temp, sizeof (tmpbuf));
+            to_copy = MIN ((size_t) temp, sizeof (tmpbuf));
             acquired = AUD_read (s->adc_voice, tmpbuf, to_copy);
             if (!acquired)
                 break;
@@ -672,7 +672,7 @@ static void es1370_transfer_audio (ES1370State *s, struct chan *d, int loop_sel,
         while (temp) {
             int copied, to_copy;
 
-            to_copy = audio_MIN ((size_t) temp, sizeof (tmpbuf));
+            to_copy = MIN ((size_t) temp, sizeof (tmpbuf));
             pci_dma_read (&s->dev, addr, tmpbuf, to_copy);
             copied = AUD_write (voice, tmpbuf, to_copy);
             if (!copied)
hw/audio/gus.c +3 -3
index 566864bc9e..325efd8df7 100644
@@ -117,7 +117,7 @@ static void GUS_callback (void *opaque, int free)
     GUSState *s = opaque;
 
     samples = free >> s->shift;
-    to_play = audio_MIN (samples, s->left);
+    to_play = MIN (samples, s->left);
 
     while (to_play) {
         int written = write_audio (s, to_play);
@@ -132,7 +132,7 @@ static void GUS_callback (void *opaque, int free)
         net += written;
     }
 
-    samples = audio_MIN (samples, s->samples);
+    samples = MIN (samples, s->samples);
     if (samples) {
         gus_mixvoices (&s->emu, s->freq, samples, s->mixbuf);
 
@@ -192,7 +192,7 @@ static int GUS_read_DMA (void *opaque, int nchan, int dma_pos, int dma_len)
     ldebug ("read DMA %#x %d\n", dma_pos, dma_len);
     mode = k->has_autoinitialization(s->isa_dma, s->emu.gusdma);
     while (left) {
-        int to_copy = audio_MIN ((size_t) left, sizeof (tmpbuf));
+        int to_copy = MIN ((size_t) left, sizeof (tmpbuf));
         int copied;
 
         ldebug ("left=%d to_copy=%d pos=%d\n", left, to_copy, pos);
hw/audio/hda-codec.c +8 -8
index 967a10f189..c8f513d3ff 100644
@@ -234,10 +234,10 @@ static void hda_audio_input_timer(void *opaque)
         goto out_timer;
     }
 
-    int64_t to_transfer = audio_MIN(wpos - rpos, wanted_rpos - rpos);
+    int64_t to_transfer = MIN(wpos - rpos, wanted_rpos - rpos);
     while (to_transfer) {
         uint32_t start = (rpos & B_MASK);
-        uint32_t chunk = audio_MIN(B_SIZE - start, to_transfer);
+        uint32_t chunk = MIN(B_SIZE - start, to_transfer);
         int rc = hda_codec_xfer(
                 &st->state->hda, st->stream, false, st->buf + start, chunk);
         if (!rc) {
@@ -262,13 +262,13 @@ static void hda_audio_input_cb(void *opaque, int avail)
     int64_t wpos = st->wpos;
     int64_t rpos = st->rpos;
 
-    int64_t to_transfer = audio_MIN(B_SIZE - (wpos - rpos), avail);
+    int64_t to_transfer = MIN(B_SIZE - (wpos - rpos), avail);
 
     hda_timer_sync_adjust(st, -((wpos - rpos) + to_transfer - (B_SIZE >> 1)));
 
     while (to_transfer) {
         uint32_t start = (uint32_t) (wpos & B_MASK);
-        uint32_t chunk = (uint32_t) audio_MIN(B_SIZE - start, to_transfer);
+        uint32_t chunk = (uint32_t) MIN(B_SIZE - start, to_transfer);
         uint32_t read = AUD_read(st->voice.in, st->buf + start, chunk);
         wpos += read;
         to_transfer -= read;
@@ -298,10 +298,10 @@ static void hda_audio_output_timer(void *opaque)
         goto out_timer;
     }
 
-    int64_t to_transfer = audio_MIN(B_SIZE - (wpos - rpos), wanted_wpos - wpos);
+    int64_t to_transfer = MIN(B_SIZE - (wpos - rpos), wanted_wpos - wpos);
     while (to_transfer) {
         uint32_t start = (wpos & B_MASK);
-        uint32_t chunk = audio_MIN(B_SIZE - start, to_transfer);
+        uint32_t chunk = MIN(B_SIZE - start, to_transfer);
         int rc = hda_codec_xfer(
                 &st->state->hda, st->stream, true, st->buf + start, chunk);
         if (!rc) {
@@ -326,7 +326,7 @@ static void hda_audio_output_cb(void *opaque, int avail)
     int64_t wpos = st->wpos;
     int64_t rpos = st->rpos;
 
-    int64_t to_transfer = audio_MIN(wpos - rpos, avail);
+    int64_t to_transfer = MIN(wpos - rpos, avail);
 
     if (wpos - rpos == B_SIZE) {
         /* drop buffer, reset timer adjust */
@@ -341,7 +341,7 @@ static void hda_audio_output_cb(void *opaque, int avail)
 
     while (to_transfer) {
         uint32_t start = (uint32_t) (rpos & B_MASK);
-        uint32_t chunk = (uint32_t) audio_MIN(B_SIZE - start, to_transfer);
+        uint32_t chunk = (uint32_t) MIN(B_SIZE - start, to_transfer);
         uint32_t written = AUD_write(st->voice.out, st->buf + start, chunk);
         rpos += written;
         to_transfer -= written;
hw/audio/milkymist-ac97.c +4 -4
index 4835229326..929b856587 100644
@@ -184,7 +184,7 @@ static void ac97_in_cb(void *opaque, int avail_b)
     MilkymistAC97State *s = opaque;
     uint8_t buf[4096];
     uint32_t remaining = s->regs[R_U_REMAINING];
-    int temp = audio_MIN(remaining, avail_b);
+    int temp = MIN(remaining, avail_b);
     uint32_t addr = s->regs[R_U_ADDR];
     int transferred = 0;
 
@@ -198,7 +198,7 @@ static void ac97_in_cb(void *opaque, int avail_b)
     while (temp) {
         int acquired, to_copy;
 
-        to_copy = audio_MIN(temp, sizeof(buf));
+        to_copy = MIN(temp, sizeof(buf));
         acquired = AUD_read(s->voice_in, buf, to_copy);
         if (!acquired) {
             break;
@@ -227,7 +227,7 @@ static void ac97_out_cb(void *opaque, int free_b)
     MilkymistAC97State *s = opaque;
     uint8_t buf[4096];
     uint32_t remaining = s->regs[R_D_REMAINING];
-    int temp = audio_MIN(remaining, free_b);
+    int temp = MIN(remaining, free_b);
     uint32_t addr = s->regs[R_D_ADDR];
     int transferred = 0;
 
@@ -241,7 +241,7 @@ static void ac97_out_cb(void *opaque, int free_b)
     while (temp) {
         int copied, to_copy;
 
-        to_copy = audio_MIN(temp, sizeof(buf));
+        to_copy = MIN(temp, sizeof(buf));
         cpu_physical_memory_read(addr, buf, to_copy);
         copied = AUD_write(s->voice_out, buf, to_copy);
         if (!copied) {
hw/audio/pcspk.c +1 -1
index 01127304c2..6bb1455c1b 100644
@@ -103,7 +103,7 @@ static void pcspk_callback(void *opaque, int free)
     }
 
     while (free > 0) {
-        n = audio_MIN(s->samples - s->play_pos, (unsigned int)free);
+        n = MIN(s->samples - s->play_pos, (unsigned int)free);
         n = AUD_write(s->voice, &s->sample_buf[s->play_pos], n);
         if (!n)
             break;
hw/audio/sb16.c +1 -1
index 6b604979cf..5182eba8eb 100644
@@ -1168,7 +1168,7 @@ static int write_audio (SB16State *s, int nchan, int dma_pos,
         int copied;
         size_t to_copy;
 
-        to_copy = audio_MIN (temp, left);
+        to_copy = MIN (temp, left);
         if (to_copy > sizeof (tmpbuf)) {
             to_copy = sizeof (tmpbuf);
         }
hw/audio/wm8750.c +2 -2
index dfb4156ff4..ab04bfa2c3 100644
@@ -69,7 +69,7 @@ static inline void wm8750_in_load(WM8750State *s)
 {
     if (s->idx_in + s->req_in <= sizeof(s->data_in))
         return;
-    s->idx_in = audio_MAX(0, (int) sizeof(s->data_in) - s->req_in);
+    s->idx_in = MAX(0, (int) sizeof(s->data_in) - s->req_in);
     AUD_read(*s->in[0], s->data_in + s->idx_in,
              sizeof(s->data_in) - s->idx_in);
 }
@@ -100,7 +100,7 @@ static void wm8750_audio_out_cb(void *opaque, int free_b)
         wm8750_out_flush(s);
     } else
         s->req_out = free_b - s->idx_out;
- 
+
     s->data_req(s->opaque, s->req_out >> 2, s->req_in >> 2);
 }
 
Signature · 1 line
2.22.0
#20 lore raw

PATCH v2 13/14 audio: use size_t where makes sense

In reply to Kővágó, Zoltán
---
 audio/audio.h           |   4 +-
 audio/audio_int.h       |  26 +++----
 audio/audio_template.h  |  14 ++--
 audio/mixeng.h          |   9 +--
 audio/rate_template.h   |   2 +-
 include/sysemu/replay.h |   4 +-
 audio/alsaaudio.c       |  26 +++----
 audio/audio.c           | 156 ++++++++++++++++++++--------------------
 audio/coreaudio.c       |  10 +--
 audio/dsoundaudio.c     |  11 +--
 audio/noaudio.c         |  16 ++---
 audio/ossaudio.c        |  45 ++++++------
 audio/paaudio.c         |  44 ++++++------
 audio/sdlaudio.c        |  20 +++---
 audio/spiceaudio.c      |  12 ++--
 audio/wavaudio.c        |   8 +--
 replay/replay-audio.c   |  16 ++---
 replay/replay.c         |   2 +-
 18 files changed, 212 insertions(+), 213 deletions(-)
audio/audio.h +2 -2
index 4a95758516..2db27bba7b 100644
@@ -112,7 +112,7 @@ SWVoiceOut *AUD_open_out (
     );
 
 void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
-int  AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
+size_t AUD_write (SWVoiceOut *sw, void *pcm_buf, size_t size);
 int  AUD_get_buffer_size_out (SWVoiceOut *sw);
 void AUD_set_active_out (SWVoiceOut *sw, int on);
 int  AUD_is_active_out (SWVoiceOut *sw);
@@ -133,7 +133,7 @@ SWVoiceIn *AUD_open_in (
     );
 
 void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
-int  AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
+size_t AUD_read (SWVoiceIn *sw, void *pcm_buf, size_t size);
 void AUD_set_active_in (SWVoiceIn *sw, int on);
 int  AUD_is_active_in (SWVoiceIn *sw);
 
audio/audio_int.h +13 -13
index 003b7ab8cc..a674c5374a 100644
@@ -61,12 +61,12 @@ typedef struct HWVoiceOut {
 
     f_sample *clip;
 
-    int rpos;
+    size_t rpos;
     uint64_t ts_helper;
 
     struct st_sample *mix_buf;
 
-    int samples;
+    size_t samples;
     QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
     QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
     int ctl_caps;
@@ -82,13 +82,13 @@ typedef struct HWVoiceIn {
 
     t_sample *conv;
 
-    int wpos;
-    int total_samples_captured;
+    size_t wpos;
+    size_t total_samples_captured;
     uint64_t ts_helper;
 
     struct st_sample *conv_buf;
 
-    int samples;
+    size_t samples;
     QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
     int ctl_caps;
     struct audio_pcm_ops *pcm_ops;
@@ -103,7 +103,7 @@ struct SWVoiceOut {
     int64_t ratio;
     struct st_sample *buf;
     void *rate;
-    int total_hw_samples_mixed;
+    size_t total_hw_samples_mixed;
     int active;
     int empty;
     HWVoiceOut *hw;
@@ -120,7 +120,7 @@ struct SWVoiceIn {
     struct audio_pcm_info info;
     int64_t ratio;
     void *rate;
-    int total_hw_samples_acquired;
+    size_t total_hw_samples_acquired;
     struct st_sample *buf;
     f_sample *clip;
     HWVoiceIn *hw;
@@ -149,12 +149,12 @@ struct audio_driver {
 struct audio_pcm_ops {
     int  (*init_out)(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque);
     void (*fini_out)(HWVoiceOut *hw);
-    int  (*run_out) (HWVoiceOut *hw, int live);
+    size_t (*run_out)(HWVoiceOut *hw, size_t live);
     int  (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
 
     int  (*init_in) (HWVoiceIn *hw, struct audsettings *as, void *drv_opaque);
     void (*fini_in) (HWVoiceIn *hw);
-    int  (*run_in)  (HWVoiceIn *hw);
+    size_t (*run_in)(HWVoiceIn *hw);
     int  (*ctl_in)  (HWVoiceIn *hw, int cmd, ...);
 };
 
@@ -208,10 +208,10 @@ audio_driver *audio_driver_lookup(const char *name);
 void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
 void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
 
-int  audio_pcm_hw_get_live_in (HWVoiceIn *hw);
+size_t audio_pcm_hw_get_live_in(HWVoiceIn *hw);
 
-int audio_pcm_hw_clip_out (HWVoiceOut *hw, void *pcm_buf,
-                           int live, int pending);
+size_t audio_pcm_hw_clip_out(HWVoiceOut *hw, void *pcm_buf,
+                             size_t live, size_t pending);
 
 int audio_bug (const char *funcname, int cond);
 void *audio_calloc (const char *funcname, int nmemb, size_t size);
@@ -224,7 +224,7 @@ void audio_run(AudioState *s, const char *msg);
 
 #define VOICE_VOLUME_CAP (1 << VOICE_VOLUME)
 
-static inline int audio_ring_dist (int dst, int src, int len)
+static inline size_t audio_ring_dist(size_t dst, size_t src, size_t len)
 {
     return (dst >= src) ? (dst - src) : (len - src + dst);
 }
audio/audio_template.h +7 -7
index 54f07338e7..2562bf5f00 100644
@@ -75,16 +75,16 @@ static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)
     HWBUF = NULL;
 }
 
-static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
+static bool glue(audio_pcm_hw_alloc_resources_, TYPE)(HW *hw)
 {
     HWBUF = audio_calloc(__func__, hw->samples, sizeof(struct st_sample));
     if (!HWBUF) {
-        dolog ("Could not allocate " NAME " buffer (%d samples)\n",
-               hw->samples);
-        return -1;
+        dolog("Could not allocate " NAME " buffer (%zu samples)\n",
+              hw->samples);
+        return false;
     }
 
-    return 0;
+    return true;
 }
 
 static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw)
@@ -265,7 +265,7 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
     }
 
     if (audio_bug(__func__, hw->samples <= 0)) {
-        dolog ("hw->samples=%d\n", hw->samples);
+        dolog("hw->samples=%zd\n", hw->samples);
         goto err1;
     }
 
@@ -279,7 +279,7 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
         [hw->info.swap_endianness]
         [audio_bits_to_index (hw->info.bits)];
 
-    if (glue (audio_pcm_hw_alloc_resources_, TYPE) (hw)) {
+    if (!glue(audio_pcm_hw_alloc_resources_, TYPE)(hw)) {
         goto err1;
     }
 
audio/mixeng.h +5 -4
index b53a5ef99a..18e62c7c49 100644
@@ -33,6 +33,7 @@ struct st_sample { mixeng_real l; mixeng_real r; };
 struct mixeng_volume { int mute; int64_t r; int64_t l; };
 struct st_sample { int64_t l; int64_t r; };
 #endif
+typedef struct st_sample st_sample;
 
 typedef void (t_sample) (struct st_sample *dst, const void *src, int samples);
 typedef void (f_sample) (void *dst, const struct st_sample *src, int samples);
@@ -41,10 +42,10 @@ extern t_sample *mixeng_conv[2][2][2][3];
 extern f_sample *mixeng_clip[2][2][2][3];
 
 void *st_rate_start (int inrate, int outrate);
-void st_rate_flow (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
-                   int *isamp, int *osamp);
-void st_rate_flow_mix (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
-                       int *isamp, int *osamp);
+void st_rate_flow(void *opaque, st_sample *ibuf, st_sample *obuf,
+                  size_t *isamp, size_t *osamp);
+void st_rate_flow_mix(void *opaque, st_sample *ibuf, st_sample *obuf,
+                      size_t *isamp, size_t *osamp);
 void st_rate_stop (void *opaque);
 void mixeng_clear (struct st_sample *buf, int len);
 void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volume *vol);
audio/rate_template.h +1 -1
index 6e93588877..f94c940c61 100644
@@ -28,7 +28,7 @@
  * Return number of samples processed.
  */
 void NAME (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
-           int *isamp, int *osamp)
+           size_t *isamp, size_t *osamp)
 {
     struct rate *rate = opaque;
     struct st_sample *istart, *iend;
include/sysemu/replay.h +2 -2
index 3a7c58e423..5c0a91e44f 100644
@@ -179,9 +179,9 @@ void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
 /* Audio */
 
 /*! Saves/restores number of played samples of audio out operation. */
-void replay_audio_out(int *played);
+void replay_audio_out(size_t *played);
 /*! Saves/restores recorded samples of audio in operation. */
-void replay_audio_in(int *recorded, void *samples, int *wpos, int size);
+void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size);
 
 /* VM state operations */
 
audio/alsaaudio.c +13 -13
index e9e3a4819c..591344dccd 100644
@@ -681,10 +681,10 @@ static void alsa_write_pending (ALSAVoiceOut *alsa)
     }
 }
 
-static int alsa_run_out (HWVoiceOut *hw, int live)
+static size_t alsa_run_out(HWVoiceOut *hw, size_t live)
 {
     ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
-    int decr;
+    size_t decr;
     snd_pcm_sframes_t avail;
 
     avail = alsa_get_avail (alsa->handle);
@@ -739,8 +739,8 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
 
     alsa->pcm_buf = audio_calloc(__func__, obt.samples, 1 << hw->info.shift);
     if (!alsa->pcm_buf) {
-        dolog ("Could not allocate DAC buffer (%d samples, each %d bytes)\n",
-               hw->samples, 1 << hw->info.shift);
+        dolog("Could not allocate DAC buffer (%zu samples, each %d bytes)\n",
+              hw->samples, 1 << hw->info.shift);
         alsa_anal_close1 (&handle);
         return -1;
     }
@@ -841,8 +841,8 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 
     alsa->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
     if (!alsa->pcm_buf) {
-        dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n",
-               hw->samples, 1 << hw->info.shift);
+        dolog("Could not allocate ADC buffer (%zu samples, each %d bytes)\n",
+              hw->samples, 1 << hw->info.shift);
         alsa_anal_close1 (&handle);
         return -1;
     }
@@ -863,17 +863,17 @@ static void alsa_fini_in (HWVoiceIn *hw)
     alsa->pcm_buf = NULL;
 }
 
-static int alsa_run_in (HWVoiceIn *hw)
+static size_t alsa_run_in(HWVoiceIn *hw)
 {
     ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
     int hwshift = hw->info.shift;
     int i;
-    int live = audio_pcm_hw_get_live_in (hw);
-    int dead = hw->samples - live;
-    int decr;
+    size_t live = audio_pcm_hw_get_live_in (hw);
+    size_t dead = hw->samples - live;
+    size_t decr;
     struct {
-        int add;
-        int len;
+        size_t add;
+        size_t len;
     } bufs[2] = {
         { .add = hw->wpos, .len = 0 },
         { .add = 0,        .len = 0 }
@@ -913,7 +913,7 @@ static int alsa_run_in (HWVoiceIn *hw)
         }
     }
 
-    decr = MIN (dead, avail);
+    decr = MIN(dead, avail);
     if (!decr) {
         return 0;
     }
audio/audio.c +76 -80

376 lines not on this page · raw message

audio/coreaudio.c +5 -5
index 091fe84a34..d1be58b40a 100644
@@ -43,9 +43,9 @@ typedef struct coreaudioVoiceOut {
     UInt32 audioDevicePropertyBufferFrameSize;
     AudioStreamBasicDescription outputStreamBasicDescription;
     AudioDeviceIOProcID ioprocid;
-    int live;
-    int decr;
-    int rpos;
+    size_t live;
+    size_t decr;
+    size_t rpos;
 } coreaudioVoiceOut;
 
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
@@ -397,9 +397,9 @@ static int coreaudio_unlock (coreaudioVoiceOut *core, const char *fn_name)
     return 0;
 }
 
-static int coreaudio_run_out (HWVoiceOut *hw, int live)
+static size_t coreaudio_run_out(HWVoiceOut *hw, size_t live)
 {
-    int decr;
+    size_t decr;
     coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
 
     if (coreaudio_lock (core, "coreaudio_run_out")) {
audio/dsoundaudio.c +6 -5
index 11594c3095..67aa1d0ad5 100644
@@ -454,19 +454,20 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...)
     return 0;
 }
 
-static int dsound_run_out (HWVoiceOut *hw, int live)
+static size_t dsound_run_out(HWVoiceOut *hw, size_t live)
 {
     int err;
     HRESULT hr;
     DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
     LPDIRECTSOUNDBUFFER dsb = ds->dsound_buffer;
-    int len, hwshift;
+    size_t len;
+    int hwshift;
     DWORD blen1, blen2;
     DWORD len1, len2;
     DWORD decr;
     DWORD wpos, ppos, old_pos;
     LPVOID p1, p2;
-    int bufsize;
+    size_t bufsize;
     dsound *s = ds->s;
     AudiodevDsoundOptions *dso = &s->dev->u.dsound;
 
@@ -640,13 +641,13 @@ static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...)
     return 0;
 }
 
-static int dsound_run_in (HWVoiceIn *hw)
+static size_t dsound_run_in(HWVoiceIn *hw)
 {
     int err;
     HRESULT hr;
     DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
     LPDIRECTSOUNDCAPTUREBUFFER dscb = ds->dsound_capture_buffer;
-    int live, len, dead;
+    size_t live, len, dead;
     DWORD blen1, blen2;
     DWORD len1, len2;
     DWORD decr;
audio/noaudio.c +8 -8
index cbb02d9e49..0fb2629cf2 100644
@@ -41,10 +41,10 @@ typedef struct NoVoiceIn {
     int64_t old_ticks;
 } NoVoiceIn;
 
-static int no_run_out (HWVoiceOut *hw, int live)
+static size_t no_run_out(HWVoiceOut *hw, size_t live)
 {
     NoVoiceOut *no = (NoVoiceOut *) hw;
-    int decr, samples;
+    size_t decr, samples;
     int64_t now;
     int64_t ticks;
     int64_t bytes;
@@ -52,7 +52,7 @@ static int no_run_out (HWVoiceOut *hw, int live)
     now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
     ticks = now - no->old_ticks;
     bytes = muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);
-    bytes = MIN(bytes, INT_MAX);
+    bytes = MIN(bytes, SIZE_MAX);
     samples = bytes >> hw->info.shift;
 
     no->old_ticks = now;
@@ -92,12 +92,12 @@ static void no_fini_in (HWVoiceIn *hw)
     (void) hw;
 }
 
-static int no_run_in (HWVoiceIn *hw)
+static size_t no_run_in(HWVoiceIn *hw)
 {
     NoVoiceIn *no = (NoVoiceIn *) hw;
-    int live = audio_pcm_hw_get_live_in (hw);
-    int dead = hw->samples - live;
-    int samples = 0;
+    size_t live = audio_pcm_hw_get_live_in(hw);
+    size_t dead = hw->samples - live;
+    size_t samples = 0;
 
     if (dead) {
         int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
@@ -106,7 +106,7 @@ static int no_run_in (HWVoiceIn *hw)
             muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);
 
         no->old_ticks = now;
-        bytes = MIN (bytes, INT_MAX);
+        bytes = MIN (bytes, SIZE_MAX);
         samples = bytes >> hw->info.shift;
         samples = MIN (samples, dead);
     }
audio/ossaudio.c +23 -22

110 lines not on this page · raw message

audio/paaudio.c +22 -22

114 lines not on this page · raw message

audio/sdlaudio.c +10 -10
index c7fd487e0e..14b11f0335 100644
@@ -41,8 +41,8 @@
 
 typedef struct SDLVoiceOut {
     HWVoiceOut hw;
-    int live;
-    int decr;
+    size_t live;
+    size_t decr;
 } SDLVoiceOut;
 
 static struct SDLAudioState {
@@ -184,22 +184,22 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
     SDLVoiceOut *sdl = opaque;
     SDLAudioState *s = &glob_sdl;
     HWVoiceOut *hw = &sdl->hw;
-    int samples = len >> hw->info.shift;
-    int to_mix, decr;
+    size_t samples = len >> hw->info.shift;
+    size_t to_mix, decr;
 
     if (s->exit || !sdl->live) {
         return;
     }
 
-    /* dolog ("in callback samples=%d live=%d\n", samples, sdl->live); */
+    /* dolog ("in callback samples=%zu live=%zu\n", samples, sdl->live); */
 
     to_mix = MIN(samples, sdl->live);
     decr = to_mix;
     while (to_mix) {
-        int chunk = MIN(to_mix, hw->samples - hw->rpos);
+        size_t chunk = MIN(to_mix, hw->samples - hw->rpos);
         struct st_sample *src = hw->mix_buf + hw->rpos;
 
-        /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
+        /* dolog ("in callback to_mix %zu, chunk %zu\n", to_mix, chunk); */
         hw->clip(buf, src, chunk);
         hw->rpos = (hw->rpos + chunk) % hw->samples;
         to_mix -= chunk;
@@ -209,7 +209,7 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
     sdl->live -= decr;
     sdl->decr += decr;
 
-    /* dolog ("done len=%d\n", len); */
+    /* dolog ("done len=%zu\n", len); */
 
     /* SDL2 does not clear the remaining buffer for us, so do it on our own */
     if (samples) {
@@ -217,9 +217,9 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
     }
 }
 
-static int sdl_run_out (HWVoiceOut *hw, int live)
+static size_t sdl_run_out(HWVoiceOut *hw, size_t live)
 {
-    int decr;
+    size_t decr;
     SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
 
     SDL_LockAudio();
audio/spiceaudio.c +6 -6
index 6e7f13cffa..d9db1a39e6 100644
@@ -153,11 +153,11 @@ static void line_out_fini (HWVoiceOut *hw)
     spice_server_remove_interface (&out->sin.base);
 }
 
-static int line_out_run (HWVoiceOut *hw, int live)
+static size_t line_out_run (HWVoiceOut *hw, size_t live)
 {
     SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw);
-    int rpos, decr;
-    int samples;
+    size_t rpos, decr;
+    size_t samples;
 
     if (!live) {
         return 0;
@@ -276,12 +276,12 @@ static void line_in_fini (HWVoiceIn *hw)
     spice_server_remove_interface (&in->sin.base);
 }
 
-static int line_in_run (HWVoiceIn *hw)
+static size_t line_in_run(HWVoiceIn *hw)
 {
     SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw);
-    int num_samples;
+    size_t num_samples;
     int ready;
-    int len[2];
+    size_t len[2];
     uint64_t delta_samp;
     const uint32_t *samples;
 
audio/wavaudio.c +4 -4
index 17ab921cef..b6eeeb4e26 100644
@@ -40,10 +40,10 @@ typedef struct WAVVoiceOut {
     int total_samples;
 } WAVVoiceOut;
 
-static int wav_run_out (HWVoiceOut *hw, int live)
+static size_t wav_run_out(HWVoiceOut *hw, size_t live)
 {
     WAVVoiceOut *wav = (WAVVoiceOut *) hw;
-    int rpos, decr, samples;
+    size_t rpos, decr, samples;
     uint8_t *dst;
     struct st_sample *src;
     int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
@@ -139,8 +139,8 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as,
     hw->samples = 1024;
     wav->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
     if (!wav->pcm_buf) {
-        dolog ("Could not allocate buffer (%d bytes)\n",
-               hw->samples << hw->info.shift);
+        dolog("Could not allocate buffer (%zu bytes)\n",
+              hw->samples << hw->info.shift);
         return -1;
     }
 
replay/replay-audio.c +8 -8
index b113836de4..efe1628727 100644
@@ -16,18 +16,18 @@
 #include "sysemu/sysemu.h"
 #include "audio/audio.h"
 
-void replay_audio_out(int *played)
+void replay_audio_out(size_t *played)
 {
     if (replay_mode == REPLAY_MODE_RECORD) {
         g_assert(replay_mutex_locked());
         replay_save_instructions();
         replay_put_event(EVENT_AUDIO_OUT);
-        replay_put_dword(*played);
+        replay_put_qword(*played);
     } else if (replay_mode == REPLAY_MODE_PLAY) {
         g_assert(replay_mutex_locked());
         replay_account_executed_instructions();
         if (replay_next_event_is(EVENT_AUDIO_OUT)) {
-            *played = replay_get_dword();
+            *played = replay_get_qword();
             replay_finish_event();
         } else {
             error_report("Missing audio out event in the replay log");
@@ -36,7 +36,7 @@ void replay_audio_out(int *played)
     }
 }
 
-void replay_audio_in(int *recorded, void *samples, int *wpos, int size)
+void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size)
 {
     int pos;
     uint64_t left, right;
@@ -44,8 +44,8 @@ void replay_audio_in(int *recorded, void *samples, int *wpos, int size)
         g_assert(replay_mutex_locked());
         replay_save_instructions();
         replay_put_event(EVENT_AUDIO_IN);
-        replay_put_dword(*recorded);
-        replay_put_dword(*wpos);
+        replay_put_qword(*recorded);
+        replay_put_qword(*wpos);
         for (pos = (*wpos - *recorded + size) % size ; pos != *wpos
              ; pos = (pos + 1) % size) {
             audio_sample_to_uint64(samples, pos, &left, &right);
@@ -56,8 +56,8 @@ void replay_audio_in(int *recorded, void *samples, int *wpos, int size)
         g_assert(replay_mutex_locked());
         replay_account_executed_instructions();
         if (replay_next_event_is(EVENT_AUDIO_IN)) {
-            *recorded = replay_get_dword();
-            *wpos = replay_get_dword();
+            *recorded = replay_get_qword();
+            *wpos = replay_get_qword();
             for (pos = (*wpos - *recorded + size) % size ; pos != *wpos
                  ; pos = (pos + 1) % size) {
                 left = replay_get_qword();
replay/replay.c +1 -1
index 8b172b2d1b..a1135a9943 100644
@@ -22,7 +22,7 @@
 
 /* Current version of the replay mechanism.
    Increase it when file format changes. */
-#define REPLAY_VERSION              0xe02007
+#define REPLAY_VERSION              0xe02008
 /* Size of replay log header */
 #define HEADER_SIZE                 (sizeof(uint32_t) + sizeof(uint64_t))
 
Signature · 1 line
2.22.0
#22 lore raw
In reply to Kővágó, Zoltán
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Type: series
Subject: [Qemu-devel] [PATCH v2 00/14] Multiple simultaneous audio backends

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Switched to a new branch 'test'
9bd8bc6 audio: fix memory leak reported by ASAN
e8d23f6 audio: use size_t where makes sense
7035d9f audio: remove read and write pcm_ops
82038f1 paaudio: fix playback glitches
ad773f9 audio: do not run each backend in audio_run
e5bae54 audio: remove audio_MIN, audio_MAX
3f525e4 paaudio: properly disconnect streams in fini_*
e76429c paaudio: do not move stream when sink/source name is specified 232f925 audio: audiodev= parameters no longer optional when -audiodev present 0475ef4 paaudio: prepare for multiple audiodev
d0ccdb3 audio: add audiodev properties to frontends
b8bbf6b audio: add audiodev property to vnc and wav_capture 45bece9 audio: basic support for multi backend audio
b8ed8fa audio: reduce glob_audio_state usage

=== OUTPUT BEGIN ===
1/14 Checking commit b8ed8fa72e64 (audio: reduce glob_audio_state usage)
2/14 Checking commit 45bece9445ff (audio: basic support for multi backend audio)
3/14 Checking commit b8bbf6b1534a (audio: add audiodev property to vnc and wav_capture) 4/14 Checking commit d0ccdb31831d (audio: add audiodev properties to frontends)
5/14 Checking commit 0475ef4aa556 (paaudio: prepare for multiple audiodev)
6/14 Checking commit 232f925703f4 (audio: audiodev= parameters no longer optional when -audiodev present) 7/14 Checking commit e76429c12dda (paaudio: do not move stream when sink/source name is specified) 8/14 Checking commit 3f525e459011 (paaudio: properly disconnect streams in fini_*)
9/14 Checking commit e5bae54fc748 (audio: remove audio_MIN, audio_MAX)
ERROR: space prohibited between function name and open parenthesis '('
#23: FILE: audio/alsaaudio.c:637:
+ int len = MIN (alsa->pending, left_till_end_samples);

ERROR: space prohibited between function name and open parenthesis '(' #32: FILE: audio/alsaaudio.c:700:
+ decr = MIN (live, avail);

ERROR: space prohibited between function name and open parenthesis '(' #41: FILE: audio/alsaaudio.c:918:
+ decr = MIN (dead, avail);

ERROR: space prohibited between function name and open parenthesis '(' #54: FILE: audio/audio.c:536:
+ m = MIN (m, sw->total_hw_samples_acquired);

ERROR: space prohibited between function name and open parenthesis '(' #63: FILE: audio/audio.c:556:
+ int len = MIN (left, live);

ERROR: space prohibited between function name and open parenthesis '(' #71: FILE: audio/audio.c:563:
+ int samples_to_clip = MIN (len, samples_till_end_of_buf);

ERROR: space prohibited between function name and open parenthesis '(' #80: FILE: audio/audio.c:617:
+ swlim = MIN (swlim, samples);

ERROR: space prohibited between function name and open parenthesis '(' #89: FILE: audio/audio.c:665:
+ m = MIN (m, sw->total_hw_samples_mixed);

ERROR: space prohibited between function name and open parenthesis '(' #98: FILE: audio/audio.c:728:
+ swlim = MIN (swlim, samples);

ERROR: space prohibited between function name and open parenthesis '(' #107: FILE: audio/audio.c:740:
+ blck = MIN (dead, left);

ERROR: space prohibited between function name and open parenthesis '(' #116: FILE: audio/audio.c:1032:
+ int to_write = MIN (till_end_of_hw, n);

ERROR: space prohibited between function name and open parenthesis '(' #125: FILE: audio/audio.c:1050:
+ n = MIN (samples, hw->samples - rpos);

ERROR: space prohibited between function name and open parenthesis '(' #134: FILE: audio/audio.c:1206:
+ int to_capture = MIN (live, left);

ERROR: space prohibited between function name and open parenthesis '(' #175: FILE: audio/coreaudio.c:416:
+ decr = MIN (core->decr, live);

ERROR: space prohibited between function name and open parenthesis '(' #188: FILE: audio/dsoundaudio.c:710:
+ len = MIN (len, dead);

ERROR: space prohibited between function name and open parenthesis '(' #206: FILE: audio/noaudio.c:59:
+ decr = MIN (live, samples);

ERROR: space prohibited between function name and open parenthesis '(' #215: FILE: audio/noaudio.c:114:
+ bytes = MIN (bytes, INT_MAX);

ERROR: space prohibited between function name and open parenthesis '(' #218: FILE: audio/noaudio.c:116:
+ samples = MIN (samples, dead);

ERROR: space prohibited between function name and open parenthesis '(' #227: FILE: audio/noaudio.c:127:
+ int to_clear = MIN (samples, total);

ERROR: space prohibited between function name and open parenthesis '(' #240: FILE: audio/ossaudio.c:391:
+ int samples_to_write = MIN (oss->pending, samples_till_end);

ERROR: space prohibited between function name and open parenthesis '(' #249: FILE: audio/ossaudio.c:440:
+ decr = MIN (bytes >> hw->info.shift, live);

ERROR: space prohibited between function name and open parenthesis '(' #258: FILE: audio/ossaudio.c:459:
+ decr = MIN (abinfo.bytes >> hw->info.shift, live);

ERROR: space prohibited between function name and open parenthesis '(' #280: FILE: audio/paaudio.c:247:
+ int chunk = MIN (to_mix, hw->samples - rpos);

ERROR: space prohibited between function name and open parenthesis '(' #289: FILE: audio/paaudio.c:285:
+ decr = MIN (live, pa->decr);

ERROR: space prohibited between function name and open parenthesis '(' #307: FILE: audio/paaudio.c:339:
+ int chunk = MIN (to_grab, hw->samples - wpos);

ERROR: space prohibited between function name and open parenthesis '(' #316: FILE: audio/paaudio.c:378:
+ incr = MIN (dead, pa->incr);

ERROR: space prohibited between function name and open parenthesis '(' #342: FILE: audio/sdlaudio.c:239:
+ decr = MIN (sdl->decr, live);

ERROR: space prohibited between function name and open parenthesis '(' #355: FILE: audio/spiceaudio.c:167:
+ decr = MIN (live, decr);

ERROR: space prohibited between function name and open parenthesis '(' #362: FILE: audio/spiceaudio.c:173:
+ int len = MIN (samples, left_till_end_samples);

ERROR: space prohibited between function name and open parenthesis '(' #370: FILE: audio/spiceaudio.c:180:
+ len = MIN (len, out->fsize);

ERROR: space prohibited between function name and open parenthesis '(' #379: FILE: audio/spiceaudio.c:298:
+ num_samples = MIN (num_samples, delta_samp);

ERROR: space prohibited between function name and open parenthesis '(' #388: FILE: audio/spiceaudio.c:308:
+ num_samples = MIN (ready, num_samples);

ERROR: space prohibited between function name and open parenthesis '(' #401: FILE: audio/wavaudio.c:62:
+ decr = MIN (live, samples);

ERROR: space prohibited between function name and open parenthesis '(' #407: FILE: audio/wavaudio.c:67:
+ int convert_samples = MIN (samples, left_till_end_samples);

ERROR: space prohibited between function name and open parenthesis '(' #420: FILE: hw/audio/ac97.c:967:
+ temp = MIN (temp, max);

ERROR: space prohibited between function name and open parenthesis '(' #429: FILE: hw/audio/ac97.c:976:
+ to_copy = MIN (temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #429: FILE: hw/audio/ac97.c:976:
+ to_copy = MIN (temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #438: FILE: hw/audio/ac97.c:1022:
+ int temp = MIN (elapsed, sizeof (s->silence));

ERROR: space prohibited between function name and open parenthesis '(' #438: FILE: hw/audio/ac97.c:1022:
+ int temp = MIN (elapsed, sizeof (s->silence));

ERROR: space prohibited between function name and open parenthesis '(' #447: FILE: hw/audio/ac97.c:1043:
+ temp = MIN (temp, max);

ERROR: space prohibited between function name and open parenthesis '(' #456: FILE: hw/audio/ac97.c:1052:
+ to_copy = MIN (temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #456: FILE: hw/audio/ac97.c:1052:
+ to_copy = MIN (temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #469: FILE: hw/audio/adlib.c:198:
+ to_play = MIN (s->left, samples);

ERROR: space prohibited between function name and open parenthesis '(' #478: FILE: hw/audio/adlib.c:213:
+ samples = MIN (samples, s->samples - s->pos);

ERROR: space prohibited between function name and open parenthesis '(' #491: FILE: hw/audio/cs4231a.c:538:
+ to_copy = MIN (temp, left);

ERROR: space prohibited between function name and open parenthesis '(' #500: FILE: hw/audio/cs4231a.c:581:
+ copy = MIN (till, copy);

ERROR: space prohibited between function name and open parenthesis '(' #513: FILE: hw/audio/es1370.c:648:
+ int temp = MIN (max, MIN (left, csc_bytes));

ERROR: space prohibited between function name and open parenthesis '(' #513: FILE: hw/audio/es1370.c:648:
+ int temp = MIN (max, MIN (left, csc_bytes));

ERROR: space prohibited between function name and open parenthesis '(' #522: FILE: hw/audio/es1370.c:657:
+ to_copy = MIN ((size_t) temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #522: FILE: hw/audio/es1370.c:657:
+ to_copy = MIN ((size_t) temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #531: FILE: hw/audio/es1370.c:675:
+ to_copy = MIN ((size_t) temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #531: FILE: hw/audio/es1370.c:675:
+ to_copy = MIN ((size_t) temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #544: FILE: hw/audio/gus.c:120:
+ to_play = MIN (samples, s->left);

ERROR: space prohibited between function name and open parenthesis '(' #553: FILE: hw/audio/gus.c:135:
+ samples = MIN (samples, s->samples);

ERROR: space prohibited between function name and open parenthesis '(' #562: FILE: hw/audio/gus.c:195:
+ int to_copy = MIN ((size_t) left, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #562: FILE: hw/audio/gus.c:195:
+ int to_copy = MIN ((size_t) left, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #692: FILE: hw/audio/sb16.c:1171:
+ to_copy = MIN (temp, left);

total: 57 errors, 0 warnings, 559 lines checked

Patch 9/14 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

10/14 Checking commit ad773f9083fd (audio: do not run each backend in audio_run) 11/14 Checking commit 82038f13a873 (paaudio: fix playback glitches) 12/14 Checking commit 7035d9f79802 (audio: remove read and write pcm_ops) 13/14 Checking commit e8d23f670a27 (audio: use size_t where makes sense)
ERROR: space prohibited between function name and open parenthesis '(' #62: FILE: audio/alsaaudio.c:871:
+ size_t live = audio_pcm_hw_get_live_in (hw);

ERROR: space prohibited between function name and open parenthesis '(' #91: FILE: audio/audio.c:529:
+static size_t audio_pcm_hw_find_min_in (HWVoiceIn *hw)

ERROR: space prohibited between function name and open parenthesis '(' #109: FILE: audio/audio.c:544:
+ size_t live = hw->total_samples_captured - audio_pcm_hw_find_min_in (hw);

ERROR: space prohibited between function name and open parenthesis '(' #126: FILE: audio/audio.c:556:
+ size_t len = MIN (left, live);

ERROR: space prohibited between function name and open parenthesis '(' #135: FILE: audio/audio.c:563:
+ size_t samples_to_clip = MIN (len, samples_till_end_of_buf);

ERROR: space prohibited between function name and open parenthesis '(' #210: FILE: audio/audio.c:652:
+static size_t audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep)

ERROR: space prohibited between function name and open parenthesis '(' #223: FILE: audio/audio.c:669:
+static size_t audio_pcm_hw_get_live_out (HWVoiceOut *hw, int *nb_live)

WARNING: line over 80 characters
#253: FILE: audio/audio.c:696:
+ size_t hwsamples, samples, isamp, osamp, wpos, live, dead, left, swlim, blck;

ERROR: space prohibited between function name and open parenthesis '(' #301: FILE: audio/audio.c:964:
+static size_t audio_get_avail (SWVoiceIn *sw)

ERROR: space prohibited between function name and open parenthesis '(' #409: FILE: audio/audio.c:1066:
+ dolog ("live=%zu hw->samples=%zu\n", live, hw->samples);

ERROR: space prohibited between function name and open parenthesis '(' #795: FILE: audio/noaudio.c:109:
+ bytes = MIN (bytes, SIZE_MAX);

ERROR: space prohibited between function name and open parenthesis '(' #886: FILE: audio/ossaudio.c:723:
+ size_t live = audio_pcm_hw_get_live_in (hw);

ERROR: space prohibited between function name and open parenthesis '(' #981: FILE: audio/paaudio.c:247:
+ size_t chunk = MIN (to_mix, hw->samples - rpos);

ERROR: space prohibited between function name and open parenthesis '(' #1011: FILE: audio/paaudio.c:334:
+ size_t chunk = MIN (to_grab, hw->samples - wpos);

ERROR: space prohibited between function name and open parenthesis '(' #1135: FILE: audio/spiceaudio.c:156:
+static size_t line_out_run (HWVoiceOut *hw, size_t live)

WARNING: line over 80 characters
#1201: FILE: include/sysemu/replay.h:184:
+void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size);

total: 14 errors, 2 warnings, 1106 lines checked

Patch 13/14 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

14/14 Checking commit 9bd8bc6a283d (audio: fix memory leak reported by ASAN) === OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#4 lore raw

Re: [Qemu-devel] [PATCH v2 03/14] audio: add audiodev property to vnc and wav_capture

In reply to Kővágó, Zoltán
Quoted 31 lines · Zoltán
---
 ui/vnc.h        |  2 ++
 monitor/misc.c  | 12 +++++++++++-
 ui/vnc.c        | 15 ++++++++++++++-
 hmp-commands.hx | 13 ++++++++-----
 qemu-options.hx |  6 ++++++
 5 files changed, 41 insertions(+), 7 deletions(-)
ui/vnc.h +2 -0
index 2f84db3142..6f54653455 100644
@@ -183,6 +183,8 @@ struct VncDisplay
 #ifdef CONFIG_VNC_SASL
     VncDisplaySASL sasl;
 #endif
+
+    AudioState *audio_state;
 };
 
 typedef struct VncTight {
monitor/misc.c +1 -0
index e393333a0e..f97810d370 100644
@@ -1148,7 +1148,17 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     int bits = qdict_get_try_int(qdict, "bits", -1);
     int has_channels = qdict_haskey(qdict, "nchannels");
     int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
+    const char *audiodev = qdict_get_try_str(qdict, "audiodev");

monitor/misc.c static void hmp_wavcapture(Monitor *mon, const QDict *qdict) · line 1161

Quoted 10 lines
monitor/misc.c +9 -0
     CaptureState *s;
+    AudioState *as = NULL;
+
+    if (audiodev) {
+        as = audio_state_by_name(audiodev);
+        if (!as) {
+            monitor_printf(mon, "Invalid audiodev specified\n");
+            return;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

monitor/misc.c static void hmp_wavcapture(Monitor *mon, const QDict *qdict) · line 1172

Quoted 12 lines
monitor/misc.c +1 -1
     s = g_malloc0 (sizeof (*s));
 
@@ -1156,7 +1166,7 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     bits = has_bits ? bits : 16;
     nchannels = has_channels ? nchannels : 2;
 
-    if (wav_start_capture(NULL, s, path, freq, bits, nchannels)) {
+    if (wav_start_capture(as, s, path, freq, bits, nchannels)) {
         monitor_printf(mon, "Failed to add wave capture\n");
         g_free (s);
         return;

Note for later: this is the only other failure mode.

Quoted 33 lines
ui/vnc.c +5 -1
index 140f364dda..24f9be5b5d 100644
@@ -1222,7 +1222,7 @@ static void audio_add(VncState *vs)
     ops.destroy = audio_capture_destroy;
     ops.capture = audio_capture;
 
-    vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs);
+    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, &ops, vs);
     if (!vs->audio_cap) {
         error_report("Failed to add audio capture");
     }
@@ -3369,6 +3369,9 @@ static QemuOptsList qemu_vnc_opts = {
         },{
             .name = "non-adaptive",
             .type = QEMU_OPT_BOOL,
+        },{
+            .name = "audiodev",
+            .type = QEMU_OPT_STRING,
         },
         { /* end of list */ }
     },
@@ -3806,6 +3809,7 @@ void vnc_display_open(const char *id, Error **errp)
     const char *saslauthz;
     int lock_key_sync = 1;
     int key_delay_ms;
+    const char *audiodev;
 
     if (!vd) {
         error_setg(errp, "VNC display not active");
@@ -3991,6 +3995,15 @@ void vnc_display_open(const char *id, Error **errp)
     }

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 4005

Quoted 10 lines
ui/vnc.c +8 -0
     vd->ledstate = 0;
 
+    audiodev = qemu_opt_get(opts, "audiodev");
+    if (audiodev) {
+        vd->audio_state = audio_state_by_name(audiodev);
+        if (!vd->audio_state) {
+            error_setg(errp, "Audiodev '%s' not found", audiodev);
+            goto fail;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

I like this error message better than the one in hmp_wavcapture(). Use it there, too?

Move it into audio_state_by_name() by giving it an Error **errp parameter? Matter of taste, up to you.

Quoted 20 lines
ui/vnc.c +1 -0
+
     device_id = qemu_opt_get(opts, "display");
     if (device_id) {
         int head = qemu_opt_get_number(opts, "head", 0);
hmp-commands.hx +2 -2
index bfa5681dd2..fa7f009268 100644
@@ -819,16 +819,19 @@ ETEXI
 
     {
         .name       = "wavcapture",
-        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?",
-        .params     = "path [frequency [bits [channels]]]",
+        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?,audiodev:s?",
+        .params     = "path [frequency [bits [channels [audiodev]]]]",
         .help       = "capture audio to a wave file (default frequency=44100 bits=16 channels=2)",
         .cmd        = hmp_wavcapture,
     },
 STEXI

hmp-commands.hx ETEXI · line 834

Quoted 10 lines
hmp-commands.hx +6 -3
-@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels}]]]
+@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels} [@var{audiodev}]]]]
 @findex wavcapture
-Capture audio into @var{filename}. Using sample rate @var{frequency}
-bits per sample @var{bits} and number of channels @var{channels}.
+Capture audio into @var{filename} from @var{audiodev}, using sample rate
+@var{frequency} bits per sample @var{bits} and number of channels
+@var{channels}. When not using an -audiodev argument on command line,
+@var{audiodev} must be omitted, otherwise is must specify a valid
+audiodev.

I can see the code for "must specify a valid audiodev" in hmp_wavcapture(). Where is "must be omitted" checked?

Preexisting: the list "sample rate @var{frequency} bits per sample @var{bits} and number of channels @var{channels}" lacks a comma after @var{frequency}, please fix that. I'd put one after @var{bits} as well, but that's a matter of taste[*]

The sentence is of the form "if not COND then A else B". The less-negated form "if COND then B else A" is commonly easier to read.

Documentation says "from @var{audiodev}". But when "not using an -audiodev argument on command line, +@var{audiodev} must be omitted". Where does it sample from then? I figure from some default audio device. Where is that default audio device explained? I skimmed the -audiodev documentation in qemu-options.hx, but couldn't see it there.

Suggest to say "an -audiodev command line option" instead of "an -audiodev argument on command line".

Double-checking:

* -audiodev is the only way to create an audio backend.

* If the user creates no audio backend, QEMU supplies a default audio backend.

Correct?

Other kinds of backends can also be created at run-time with the monitor. I'm not asking you provide that for audio. I'm just wondering whether it could conceivably be useful.

If yes, you might want to avoid the narrow "if using -audiodev", and instead say "if the default audio device is in use".

Quoted 9 lines
hmp-commands.hx +0 -0
 Defaults:
 @itemize @minus
qemu-options.hx +0 -0
index 9621e934c0..a308e5f5aa 100644
@@ -1978,6 +1978,12 @@ can help the device and guest to keep up and not lose events in case
 events are arriving in bulk.  Possible causes for the latter are flaky

qemu-options.hx can help the device and guest to keep up and not lose events in case · line 1988

Quoted 10 lines
qemu-options.hx +6 -0
 network connections, or scripts for automated testing.
 
+@item audiodev=@var{audiodev}
+
+Use the specified @var{audiodev} when the VNC client requests audio
+transmission. When not using an -audiodev argument, this option must
+be omitted, otherwise is must be present and specify a valid audiodev.
+
 @end table
 ETEXI

Same as for wavcapture, basically.

[*] https://en.wikipedia.org/wiki/Serial_comma

#5 lore raw

Re: [Qemu-devel] [PATCH v2 03/14] audio: add audiodev property to vnc and wav_capture

Quoted 140 lines · * Markus Armbruster ([email protected]) wrote:
Quoted 31 lines · Zoltán
---
 ui/vnc.h        |  2 ++
 monitor/misc.c  | 12 +++++++++++-
 ui/vnc.c        | 15 ++++++++++++++-
 hmp-commands.hx | 13 ++++++++-----
 qemu-options.hx |  6 ++++++
 5 files changed, 41 insertions(+), 7 deletions(-)
ui/vnc.h +2 -0
index 2f84db3142..6f54653455 100644
@@ -183,6 +183,8 @@ struct VncDisplay
 #ifdef CONFIG_VNC_SASL
     VncDisplaySASL sasl;
 #endif
+
+    AudioState *audio_state;
 };
 
 typedef struct VncTight {
monitor/misc.c +1 -0
index e393333a0e..f97810d370 100644
@@ -1148,7 +1148,17 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     int bits = qdict_get_try_int(qdict, "bits", -1);
     int has_channels = qdict_haskey(qdict, "nchannels");
     int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
+    const char *audiodev = qdict_get_try_str(qdict, "audiodev");

monitor/misc.c static void hmp_wavcapture(Monitor *mon, const QDict *qdict) · line 1161

Quoted 10 lines
monitor/misc.c +9 -0
     CaptureState *s;
+    AudioState *as = NULL;
+
+    if (audiodev) {
+        as = audio_state_by_name(audiodev);
+        if (!as) {
+            monitor_printf(mon, "Invalid audiodev specified\n");
+            return;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

monitor/misc.c static void hmp_wavcapture(Monitor *mon, const QDict *qdict) · line 1172

Quoted 12 lines
monitor/misc.c +1 -1
     s = g_malloc0 (sizeof (*s));
 
@@ -1156,7 +1166,7 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
     bits = has_bits ? bits : 16;
     nchannels = has_channels ? nchannels : 2;
 
-    if (wav_start_capture(NULL, s, path, freq, bits, nchannels)) {
+    if (wav_start_capture(as, s, path, freq, bits, nchannels)) {
         monitor_printf(mon, "Failed to add wave capture\n");
         g_free (s);
         return;

Note for later: this is the only other failure mode.

Quoted 33 lines
ui/vnc.c +5 -1
index 140f364dda..24f9be5b5d 100644
@@ -1222,7 +1222,7 @@ static void audio_add(VncState *vs)
     ops.destroy = audio_capture_destroy;
     ops.capture = audio_capture;
 
-    vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs);
+    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, &ops, vs);
     if (!vs->audio_cap) {
         error_report("Failed to add audio capture");
     }
@@ -3369,6 +3369,9 @@ static QemuOptsList qemu_vnc_opts = {
         },{
             .name = "non-adaptive",
             .type = QEMU_OPT_BOOL,
+        },{
+            .name = "audiodev",
+            .type = QEMU_OPT_STRING,
         },
         { /* end of list */ }
     },
@@ -3806,6 +3809,7 @@ void vnc_display_open(const char *id, Error **errp)
     const char *saslauthz;
     int lock_key_sync = 1;
     int key_delay_ms;
+    const char *audiodev;
 
     if (!vd) {
         error_setg(errp, "VNC display not active");
@@ -3991,6 +3995,15 @@ void vnc_display_open(const char *id, Error **errp)
     }

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 4005

Quoted 10 lines
ui/vnc.c +8 -0
     vd->ledstate = 0;
 
+    audiodev = qemu_opt_get(opts, "audiodev");
+    if (audiodev) {
+        vd->audio_state = audio_state_by_name(audiodev);
+        if (!vd->audio_state) {
+            error_setg(errp, "Audiodev '%s' not found", audiodev);
+            goto fail;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

I like this error message better than the one in hmp_wavcapture(). Use it there, too?

Move it into audio_state_by_name() by giving it an Error **errp parameter? Matter of taste, up to you.

Quoted 25 lines
ui/vnc.c +1 -0
+
     device_id = qemu_opt_get(opts, "display");
     if (device_id) {
         int head = qemu_opt_get_number(opts, "head", 0);
hmp-commands.hx +3 -5
index bfa5681dd2..fa7f009268 100644
@@ -819,16 +819,19 @@ ETEXI
 
     {
         .name       = "wavcapture",
-        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?",
-        .params     = "path [frequency [bits [channels]]]",
+        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?,audiodev:s?",
+        .params     = "path [frequency [bits [channels [audiodev]]]]",
         .help       = "capture audio to a wave file (default frequency=44100 bits=16 channels=2)",
         .cmd        = hmp_wavcapture,
     },
 STEXI
-@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels}]]]
+@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels} [@var{audiodev}]]]]
 @findex wavcapture
-Capture audio into @var{filename}. Using sample rate @var{frequency}
-bits per sample @var{bits} and number of channels @var{channels}.
Quoted 8 lines

hmp-commands.hx ETEXI · line 834

Quoted 5 lines
hmp-commands.hx +5 -0
+Capture audio into @var{filename} from @var{audiodev}, using sample rate
+@var{frequency} bits per sample @var{bits} and number of channels
+@var{channels}. When not using an -audiodev argument on command line,
+@var{audiodev} must be omitted, otherwise is must specify a valid
+audiodev.

I can see the code for "must specify a valid audiodev" in hmp_wavcapture(). Where is "must be omitted" checked?

Isn't that just that there wont be any named devices so you wont be able to specify a valid one?

Dave

Quoted 56 lines

Preexisting: the list "sample rate @var{frequency} bits per sample @var{bits} and number of channels @var{channels}" lacks a comma after @var{frequency}, please fix that. I'd put one after @var{bits} as well, but that's a matter of taste[*]

The sentence is of the form "if not COND then A else B". The less-negated form "if COND then B else A" is commonly easier to read.

Documentation says "from @var{audiodev}". But when "not using an -audiodev argument on command line, +@var{audiodev} must be omitted". Where does it sample from then? I figure from some default audio device. Where is that default audio device explained? I skimmed the -audiodev documentation in qemu-options.hx, but couldn't see it there.

Suggest to say "an -audiodev command line option" instead of "an -audiodev argument on command line".

Double-checking:

* -audiodev is the only way to create an audio backend.

* If the user creates no audio backend, QEMU supplies a default audio backend.

Correct?

Other kinds of backends can also be created at run-time with the monitor. I'm not asking you provide that for audio. I'm just wondering whether it could conceivably be useful.

If yes, you might want to avoid the narrow "if using -audiodev", and instead say "if the default audio device is in use".

Quoted 9 lines
hmp-commands.hx +0 -0
 Defaults:
 @itemize @minus
qemu-options.hx +0 -0
index 9621e934c0..a308e5f5aa 100644
@@ -1978,6 +1978,12 @@ can help the device and guest to keep up and not lose events in case
 events are arriving in bulk.  Possible causes for the latter are flaky

qemu-options.hx can help the device and guest to keep up and not lose events in case · line 1988

Quoted 10 lines
qemu-options.hx +6 -0
 network connections, or scripts for automated testing.
 
+@item audiodev=@var{audiodev}
+
+Use the specified @var{audiodev} when the VNC client requests audio
+transmission. When not using an -audiodev argument, this option must
+be omitted, otherwise is must be present and specify a valid audiodev.
+
 @end table
 ETEXI

Same as for wavcapture, basically.

Quoted 1 line

[*] https://en.wikipedia.org/wiki/Serial_comma

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#23 lore raw
In reply to Kővágó, Zoltán
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Subject: [Qemu-devel] [PATCH v2 00/14] Multiple simultaneous audio backends
Message-id: [email protected]

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
Submodule 'capstone' (https://git.qemu.org/git/capstone.git) registered for path 'capstone'
Submodule 'dtc' (https://git.qemu.org/git/dtc.git) registered for path 'dtc'
Submodule 'roms/QemuMacDrivers' (https://git.qemu.org/git/QemuMacDrivers.git) registered for path 'roms/QemuMacDrivers' Submodule 'roms/SLOF' (https://git.qemu.org/git/SLOF.git) registered for path 'roms/SLOF'
Submodule 'roms/edk2' (https://git.qemu.org/git/edk2.git) registered for path 'roms/edk2'
Submodule 'roms/ipxe' (https://git.qemu.org/git/ipxe.git) registered for path 'roms/ipxe'
Submodule 'roms/openbios' (https://git.qemu.org/git/openbios.git) registered for path 'roms/openbios'
Submodule 'roms/openhackware' (https://git.qemu.org/git/openhackware.git) registered for path 'roms/openhackware'
Submodule 'roms/qemu-palcode' (https://git.qemu.org/git/qemu-palcode.git) registered for path 'roms/qemu-palcode'
Submodule 'roms/seabios' (https://git.qemu.org/git/seabios.git/) registered for path 'roms/seabios'
Submodule 'roms/seabios-hppa' (https://git.qemu.org/git/seabios-hppa.git) registered for path 'roms/seabios-hppa'
Submodule 'roms/sgabios' (https://git.qemu.org/git/sgabios.git) registered for path 'roms/sgabios'
Submodule 'roms/skiboot' (https://git.qemu.org/git/skiboot.git) registered for path 'roms/skiboot'
Submodule 'roms/u-boot' (https://git.qemu.org/git/u-boot.git) registered for path 'roms/u-boot'
Submodule 'roms/u-boot-sam460ex' (https://git.qemu.org/git/u-boot-sam460ex.git) registered for path 'roms/u-boot-sam460ex' Submodule 'slirp' (https://git.qemu.org/git/libslirp.git) registered for path 'slirp'
Submodule 'tests/fp/berkeley-softfloat-3' (https://git.qemu.org/git/berkeley-softfloat-3.git) registered for path 'tests/fp/berkeley-softfloat-3' Submodule 'tests/fp/berkeley-testfloat-3' (https://git.qemu.org/git/berkeley-testfloat-3.git) registered for path 'tests/fp/berkeley-testfloat-3' Submodule 'ui/keycodemapdb' (https://git.qemu.org/git/keycodemapdb.git) registered for path 'ui/keycodemapdb'
Cloning into 'capstone'...
Submodule path 'capstone': checked out '22ead3e0bfdb87516656453336160e0a37b066bf'
Cloning into 'dtc'...
Submodule path 'dtc': checked out '88f18909db731a627456f26d779445f84e449536'
Cloning into 'roms/QemuMacDrivers'...
Submodule path 'roms/QemuMacDrivers': checked out '90c488d5f4a407342247b9ea869df1c2d9c8e266'
Cloning into 'roms/SLOF'...
Submodule path 'roms/SLOF': checked out 'ba1ab360eebe6338bb8d7d83a9220ccf7e213af3'
Cloning into 'roms/edk2'...
Submodule path 'roms/edk2': checked out '20d2e5a125e34fc8501026613a71549b2a1a3e54'
Submodule 'SoftFloat' (https://github.com/ucb-bar/berkeley-softfloat-3.git) registered for path 'ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3' Submodule 'CryptoPkg/Library/OpensslLib/openssl' (https://github.com/openssl/openssl) registered for path 'CryptoPkg/Library/OpensslLib/openssl' Cloning into 'ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3'...
Submodule path 'roms/edk2/ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3': checked out 'b64af41c3276f97f0e181920400ee056b9c88037' Cloning into 'CryptoPkg/Library/OpensslLib/openssl'...
Submodule path 'roms/edk2/CryptoPkg/Library/OpensslLib/openssl': checked out '50eaac9f3337667259de725451f201e784599687' Submodule 'boringssl' (https://boringssl.googlesource.com/boringssl) registered for path 'boringssl'
Submodule 'krb5' (https://github.com/krb5/krb5) registered for path 'krb5'
Submodule 'pyca.cryptography' (https://github.com/pyca/cryptography.git) registered for path 'pyca-cryptography'
Cloning into 'boringssl'...
Submodule path 'roms/edk2/CryptoPkg/Library/OpensslLib/openssl/boringssl': checked out '2070f8ad9151dc8f3a73bffaa146b5e6937a583f' Cloning into 'krb5'...
Submodule path 'roms/edk2/CryptoPkg/Library/OpensslLib/openssl/krb5': checked out 'b9ad6c49505c96a088326b62a52568e3484f2168' Cloning into 'pyca-cryptography'...
Submodule path 'roms/edk2/CryptoPkg/Library/OpensslLib/openssl/pyca-cryptography': checked out '09403100de2f6f1cdd0d484dcb8e620f1c335c8f' Cloning into 'roms/ipxe'...
Submodule path 'roms/ipxe': checked out 'de4565cbe76ea9f7913a01f331be3ee901bb6e17'
Cloning into 'roms/openbios'...
Submodule path 'roms/openbios': checked out 'c79e0ecb84f4f1ee3f73f521622e264edd1bf174'
Cloning into 'roms/openhackware'...
Submodule path 'roms/openhackware': checked out 'c559da7c8eec5e45ef1f67978827af6f0b9546f5'
Cloning into 'roms/qemu-palcode'...
Submodule path 'roms/qemu-palcode': checked out 'bf0e13698872450164fa7040da36a95d2d4b326f'
Cloning into 'roms/seabios'...
Submodule path 'roms/seabios': checked out 'a5cab58e9a3fb6e168aba919c5669bea406573b4'
Cloning into 'roms/seabios-hppa'...
Submodule path 'roms/seabios-hppa': checked out '0f4fe84658165e96ce35870fd19fc634e182e77b'
Cloning into 'roms/sgabios'...
Submodule path 'roms/sgabios': checked out 'cbaee52287e5f32373181cff50a00b6c4ac9015a'
Cloning into 'roms/skiboot'...
Submodule path 'roms/skiboot': checked out '261ca8e779e5138869a45f174caa49be6a274501'
Cloning into 'roms/u-boot'...
Submodule path 'roms/u-boot': checked out 'd3689267f92c5956e09cc7d1baa4700141662bff'
Cloning into 'roms/u-boot-sam460ex'...
Submodule path 'roms/u-boot-sam460ex': checked out '60b3916f33e617a815973c5a6df77055b2e3a588'
Cloning into 'slirp'...
Submodule path 'slirp': checked out 'f0da6726207b740f6101028b2992f918477a4b08'
Cloning into 'tests/fp/berkeley-softfloat-3'...
Submodule path 'tests/fp/berkeley-softfloat-3': checked out 'b64af41c3276f97f0e181920400ee056b9c88037'
Cloning into 'tests/fp/berkeley-testfloat-3'...
Submodule path 'tests/fp/berkeley-testfloat-3': checked out '5a59dcec19327396a011a17fd924aed4fec416b3'
Cloning into 'ui/keycodemapdb'...
Submodule path 'ui/keycodemapdb': checked out '6b3d716e2b6472eb7189d3220552280ef3d832ce'
Switched to a new branch 'test'
9bd8bc6 audio: fix memory leak reported by ASAN
e8d23f6 audio: use size_t where makes sense
7035d9f audio: remove read and write pcm_ops
82038f1 paaudio: fix playback glitches
ad773f9 audio: do not run each backend in audio_run
e5bae54 audio: remove audio_MIN, audio_MAX
3f525e4 paaudio: properly disconnect streams in fini_*
e76429c paaudio: do not move stream when sink/source name is specified
232f925 audio: audiodev= parameters no longer optional when -audiodev present
0475ef4 paaudio: prepare for multiple audiodev
d0ccdb3 audio: add audiodev properties to frontends
b8bbf6b audio: add audiodev property to vnc and wav_capture
45bece9 audio: basic support for multi backend audio
b8ed8fa audio: reduce glob_audio_state usage

=== OUTPUT BEGIN ===
1/14 Checking commit b8ed8fa72e64 (audio: reduce glob_audio_state usage)
2/14 Checking commit 45bece9445ff (audio: basic support for multi backend audio)
3/14 Checking commit b8bbf6b1534a (audio: add audiodev property to vnc and wav_capture) 4/14 Checking commit d0ccdb31831d (audio: add audiodev properties to frontends)
5/14 Checking commit 0475ef4aa556 (paaudio: prepare for multiple audiodev)
6/14 Checking commit 232f925703f4 (audio: audiodev= parameters no longer optional when -audiodev present) 7/14 Checking commit e76429c12dda (paaudio: do not move stream when sink/source name is specified) 8/14 Checking commit 3f525e459011 (paaudio: properly disconnect streams in fini_*)
9/14 Checking commit e5bae54fc748 (audio: remove audio_MIN, audio_MAX)
ERROR: space prohibited between function name and open parenthesis '('
#23: FILE: audio/alsaaudio.c:637:
+ int len = MIN (alsa->pending, left_till_end_samples);

ERROR: space prohibited between function name and open parenthesis '(' #32: FILE: audio/alsaaudio.c:700:
+ decr = MIN (live, avail);

ERROR: space prohibited between function name and open parenthesis '(' #41: FILE: audio/alsaaudio.c:918:
+ decr = MIN (dead, avail);

ERROR: space prohibited between function name and open parenthesis '(' #54: FILE: audio/audio.c:536:
+ m = MIN (m, sw->total_hw_samples_acquired);

ERROR: space prohibited between function name and open parenthesis '(' #63: FILE: audio/audio.c:556:
+ int len = MIN (left, live);

ERROR: space prohibited between function name and open parenthesis '(' #71: FILE: audio/audio.c:563:
+ int samples_to_clip = MIN (len, samples_till_end_of_buf);

ERROR: space prohibited between function name and open parenthesis '(' #80: FILE: audio/audio.c:617:
+ swlim = MIN (swlim, samples);

ERROR: space prohibited between function name and open parenthesis '(' #89: FILE: audio/audio.c:665:
+ m = MIN (m, sw->total_hw_samples_mixed);

ERROR: space prohibited between function name and open parenthesis '(' #98: FILE: audio/audio.c:728:
+ swlim = MIN (swlim, samples);

ERROR: space prohibited between function name and open parenthesis '(' #107: FILE: audio/audio.c:740:
+ blck = MIN (dead, left);

ERROR: space prohibited between function name and open parenthesis '(' #116: FILE: audio/audio.c:1032:
+ int to_write = MIN (till_end_of_hw, n);

ERROR: space prohibited between function name and open parenthesis '(' #125: FILE: audio/audio.c:1050:
+ n = MIN (samples, hw->samples - rpos);

ERROR: space prohibited between function name and open parenthesis '(' #134: FILE: audio/audio.c:1206:
+ int to_capture = MIN (live, left);

ERROR: space prohibited between function name and open parenthesis '(' #175: FILE: audio/coreaudio.c:416:
+ decr = MIN (core->decr, live);

ERROR: space prohibited between function name and open parenthesis '(' #188: FILE: audio/dsoundaudio.c:710:
+ len = MIN (len, dead);

ERROR: space prohibited between function name and open parenthesis '(' #206: FILE: audio/noaudio.c:59:
+ decr = MIN (live, samples);

ERROR: space prohibited between function name and open parenthesis '(' #215: FILE: audio/noaudio.c:114:
+ bytes = MIN (bytes, INT_MAX);

ERROR: space prohibited between function name and open parenthesis '(' #218: FILE: audio/noaudio.c:116:
+ samples = MIN (samples, dead);

ERROR: space prohibited between function name and open parenthesis '(' #227: FILE: audio/noaudio.c:127:
+ int to_clear = MIN (samples, total);

ERROR: space prohibited between function name and open parenthesis '(' #240: FILE: audio/ossaudio.c:391:
+ int samples_to_write = MIN (oss->pending, samples_till_end);

ERROR: space prohibited between function name and open parenthesis '(' #249: FILE: audio/ossaudio.c:440:
+ decr = MIN (bytes >> hw->info.shift, live);

ERROR: space prohibited between function name and open parenthesis '(' #258: FILE: audio/ossaudio.c:459:
+ decr = MIN (abinfo.bytes >> hw->info.shift, live);

ERROR: space prohibited between function name and open parenthesis '(' #280: FILE: audio/paaudio.c:247:
+ int chunk = MIN (to_mix, hw->samples - rpos);

ERROR: space prohibited between function name and open parenthesis '(' #289: FILE: audio/paaudio.c:285:
+ decr = MIN (live, pa->decr);

ERROR: space prohibited between function name and open parenthesis '(' #307: FILE: audio/paaudio.c:339:
+ int chunk = MIN (to_grab, hw->samples - wpos);

ERROR: space prohibited between function name and open parenthesis '(' #316: FILE: audio/paaudio.c:378:
+ incr = MIN (dead, pa->incr);

ERROR: space prohibited between function name and open parenthesis '(' #342: FILE: audio/sdlaudio.c:239:
+ decr = MIN (sdl->decr, live);

ERROR: space prohibited between function name and open parenthesis '(' #355: FILE: audio/spiceaudio.c:167:
+ decr = MIN (live, decr);

ERROR: space prohibited between function name and open parenthesis '(' #362: FILE: audio/spiceaudio.c:173:
+ int len = MIN (samples, left_till_end_samples);

ERROR: space prohibited between function name and open parenthesis '(' #370: FILE: audio/spiceaudio.c:180:
+ len = MIN (len, out->fsize);

ERROR: space prohibited between function name and open parenthesis '(' #379: FILE: audio/spiceaudio.c:298:
+ num_samples = MIN (num_samples, delta_samp);

ERROR: space prohibited between function name and open parenthesis '(' #388: FILE: audio/spiceaudio.c:308:
+ num_samples = MIN (ready, num_samples);

ERROR: space prohibited between function name and open parenthesis '(' #401: FILE: audio/wavaudio.c:62:
+ decr = MIN (live, samples);

ERROR: space prohibited between function name and open parenthesis '(' #407: FILE: audio/wavaudio.c:67:
+ int convert_samples = MIN (samples, left_till_end_samples);

ERROR: space prohibited between function name and open parenthesis '(' #420: FILE: hw/audio/ac97.c:967:
+ temp = MIN (temp, max);

ERROR: space prohibited between function name and open parenthesis '(' #429: FILE: hw/audio/ac97.c:976:
+ to_copy = MIN (temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #429: FILE: hw/audio/ac97.c:976:
+ to_copy = MIN (temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #438: FILE: hw/audio/ac97.c:1022:
+ int temp = MIN (elapsed, sizeof (s->silence));

ERROR: space prohibited between function name and open parenthesis '(' #438: FILE: hw/audio/ac97.c:1022:
+ int temp = MIN (elapsed, sizeof (s->silence));

ERROR: space prohibited between function name and open parenthesis '(' #447: FILE: hw/audio/ac97.c:1043:
+ temp = MIN (temp, max);

ERROR: space prohibited between function name and open parenthesis '(' #456: FILE: hw/audio/ac97.c:1052:
+ to_copy = MIN (temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #456: FILE: hw/audio/ac97.c:1052:
+ to_copy = MIN (temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #469: FILE: hw/audio/adlib.c:198:
+ to_play = MIN (s->left, samples);

ERROR: space prohibited between function name and open parenthesis '(' #478: FILE: hw/audio/adlib.c:213:
+ samples = MIN (samples, s->samples - s->pos);

ERROR: space prohibited between function name and open parenthesis '(' #491: FILE: hw/audio/cs4231a.c:538:
+ to_copy = MIN (temp, left);

ERROR: space prohibited between function name and open parenthesis '(' #500: FILE: hw/audio/cs4231a.c:581:
+ copy = MIN (till, copy);

ERROR: space prohibited between function name and open parenthesis '(' #513: FILE: hw/audio/es1370.c:648:
+ int temp = MIN (max, MIN (left, csc_bytes));

ERROR: space prohibited between function name and open parenthesis '(' #513: FILE: hw/audio/es1370.c:648:
+ int temp = MIN (max, MIN (left, csc_bytes));

ERROR: space prohibited between function name and open parenthesis '(' #522: FILE: hw/audio/es1370.c:657:
+ to_copy = MIN ((size_t) temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #522: FILE: hw/audio/es1370.c:657:
+ to_copy = MIN ((size_t) temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #531: FILE: hw/audio/es1370.c:675:
+ to_copy = MIN ((size_t) temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #531: FILE: hw/audio/es1370.c:675:
+ to_copy = MIN ((size_t) temp, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #544: FILE: hw/audio/gus.c:120:
+ to_play = MIN (samples, s->left);

ERROR: space prohibited between function name and open parenthesis '(' #553: FILE: hw/audio/gus.c:135:
+ samples = MIN (samples, s->samples);

ERROR: space prohibited between function name and open parenthesis '(' #562: FILE: hw/audio/gus.c:195:
+ int to_copy = MIN ((size_t) left, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #562: FILE: hw/audio/gus.c:195:
+ int to_copy = MIN ((size_t) left, sizeof (tmpbuf));

ERROR: space prohibited between function name and open parenthesis '(' #692: FILE: hw/audio/sb16.c:1171:
+ to_copy = MIN (temp, left);

total: 57 errors, 0 warnings, 559 lines checked

Patch 9/14 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

10/14 Checking commit ad773f9083fd (audio: do not run each backend in audio_run) 11/14 Checking commit 82038f13a873 (paaudio: fix playback glitches) 12/14 Checking commit 7035d9f79802 (audio: remove read and write pcm_ops) 13/14 Checking commit e8d23f670a27 (audio: use size_t where makes sense)
ERROR: space prohibited between function name and open parenthesis '(' #62: FILE: audio/alsaaudio.c:871:
+ size_t live = audio_pcm_hw_get_live_in (hw);

ERROR: space prohibited between function name and open parenthesis '(' #91: FILE: audio/audio.c:529:
+static size_t audio_pcm_hw_find_min_in (HWVoiceIn *hw)

ERROR: space prohibited between function name and open parenthesis '(' #109: FILE: audio/audio.c:544:
+ size_t live = hw->total_samples_captured - audio_pcm_hw_find_min_in (hw);

ERROR: space prohibited between function name and open parenthesis '(' #126: FILE: audio/audio.c:556:
+ size_t len = MIN (left, live);

ERROR: space prohibited between function name and open parenthesis '(' #135: FILE: audio/audio.c:563:
+ size_t samples_to_clip = MIN (len, samples_till_end_of_buf);

ERROR: space prohibited between function name and open parenthesis '(' #210: FILE: audio/audio.c:652:
+static size_t audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep)

ERROR: space prohibited between function name and open parenthesis '(' #223: FILE: audio/audio.c:669:
+static size_t audio_pcm_hw_get_live_out (HWVoiceOut *hw, int *nb_live)

WARNING: line over 80 characters
#253: FILE: audio/audio.c:696:
+ size_t hwsamples, samples, isamp, osamp, wpos, live, dead, left, swlim, blck;

ERROR: space prohibited between function name and open parenthesis '(' #301: FILE: audio/audio.c:964:
+static size_t audio_get_avail (SWVoiceIn *sw)

ERROR: space prohibited between function name and open parenthesis '(' #409: FILE: audio/audio.c:1066:
+ dolog ("live=%zu hw->samples=%zu\n", live, hw->samples);

ERROR: space prohibited between function name and open parenthesis '(' #795: FILE: audio/noaudio.c:109:
+ bytes = MIN (bytes, SIZE_MAX);

ERROR: space prohibited between function name and open parenthesis '(' #886: FILE: audio/ossaudio.c:723:
+ size_t live = audio_pcm_hw_get_live_in (hw);

ERROR: space prohibited between function name and open parenthesis '(' #981: FILE: audio/paaudio.c:247:
+ size_t chunk = MIN (to_mix, hw->samples - rpos);

ERROR: space prohibited between function name and open parenthesis '(' #1011: FILE: audio/paaudio.c:334:
+ size_t chunk = MIN (to_grab, hw->samples - wpos);

ERROR: space prohibited between function name and open parenthesis '(' #1135: FILE: audio/spiceaudio.c:156:
+static size_t line_out_run (HWVoiceOut *hw, size_t live)

WARNING: line over 80 characters
#1201: FILE: include/sysemu/replay.h:184:
+void replay_audio_in(size_t *recorded, void *samples, size_t *wpos, size_t size);

total: 14 errors, 2 warnings, 1106 lines checked

Patch 13/14 has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

14/14 Checking commit 9bd8bc6a283d (audio: fix memory leak reported by ASAN) === OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#6 lore raw

Re: [Qemu-devel] [PATCH v2 03/14] audio: add audiodev property to vnc and wav_capture

In reply to Markus Armbruster
Quoted 140 lines · Markus Armbruster
Quoted 31 lines · Zoltán
---
  ui/vnc.h        |  2 ++
  monitor/misc.c  | 12 +++++++++++-
  ui/vnc.c        | 15 ++++++++++++++-
  hmp-commands.hx | 13 ++++++++-----
  qemu-options.hx |  6 ++++++
  5 files changed, 41 insertions(+), 7 deletions(-)
ui/vnc.h +2 -0
index 2f84db3142..6f54653455 100644
@@ -183,6 +183,8 @@ struct VncDisplay
  #ifdef CONFIG_VNC_SASL
      VncDisplaySASL sasl;
  #endif
+
+    AudioState *audio_state;
  };
 
  typedef struct VncTight {
monitor/misc.c +1 -0
index e393333a0e..f97810d370 100644
@@ -1148,7 +1148,17 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
      int bits = qdict_get_try_int(qdict, "bits", -1);
      int has_channels = qdict_haskey(qdict, "nchannels");
      int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
+    const char *audiodev = qdict_get_try_str(qdict, "audiodev");

monitor/misc.c static void hmp_wavcapture(Monitor *mon, const QDict *qdict) · line 1161

Quoted 10 lines
monitor/misc.c +9 -0
      CaptureState *s;
+    AudioState *as = NULL;
+
+    if (audiodev) {
+        as = audio_state_by_name(audiodev);
+        if (!as) {
+            monitor_printf(mon, "Invalid audiodev specified\n");
+            return;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

monitor/misc.c static void hmp_wavcapture(Monitor *mon, const QDict *qdict) · line 1172

Quoted 12 lines
monitor/misc.c +1 -1
      s = g_malloc0 (sizeof (*s));
 
@@ -1156,7 +1166,7 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
      bits = has_bits ? bits : 16;
      nchannels = has_channels ? nchannels : 2;
 
-    if (wav_start_capture(NULL, s, path, freq, bits, nchannels)) {
+    if (wav_start_capture(as, s, path, freq, bits, nchannels)) {
          monitor_printf(mon, "Failed to add wave capture\n");
          g_free (s);
          return;

Note for later: this is the only other failure mode.

Quoted 33 lines
ui/vnc.c +5 -1
index 140f364dda..24f9be5b5d 100644
@@ -1222,7 +1222,7 @@ static void audio_add(VncState *vs)
      ops.destroy = audio_capture_destroy;
      ops.capture = audio_capture;
 
-    vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs);
+    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, &ops, vs);
      if (!vs->audio_cap) {
          error_report("Failed to add audio capture");
      }
@@ -3369,6 +3369,9 @@ static QemuOptsList qemu_vnc_opts = {
          },{
              .name = "non-adaptive",
              .type = QEMU_OPT_BOOL,
+        },{
+            .name = "audiodev",
+            .type = QEMU_OPT_STRING,
          },
          { /* end of list */ }
      },
@@ -3806,6 +3809,7 @@ void vnc_display_open(const char *id, Error **errp)
      const char *saslauthz;
      int lock_key_sync = 1;
      int key_delay_ms;
+    const char *audiodev;
 
      if (!vd) {
          error_setg(errp, "VNC display not active");
@@ -3991,6 +3995,15 @@ void vnc_display_open(const char *id, Error **errp)
      }

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 4005

Quoted 10 lines
ui/vnc.c +8 -0
      vd->ledstate = 0;
 
+    audiodev = qemu_opt_get(opts, "audiodev");
+    if (audiodev) {
+        vd->audio_state = audio_state_by_name(audiodev);
+        if (!vd->audio_state) {
+            error_setg(errp, "Audiodev '%s' not found", audiodev);
+            goto fail;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

I like this error message better than the one in hmp_wavcapture(). Use it there, too?

Move it into audio_state_by_name() by giving it an Error **errp parameter? Matter of taste, up to you.

Quoted 25 lines
ui/vnc.c +1 -0
+
      device_id = qemu_opt_get(opts, "display");
      if (device_id) {
          int head = qemu_opt_get_number(opts, "head", 0);
hmp-commands.hx +3 -5
index bfa5681dd2..fa7f009268 100644
@@ -819,16 +819,19 @@ ETEXI
 
      {
          .name       = "wavcapture",
-        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?",
-        .params     = "path [frequency [bits [channels]]]",
+        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?,audiodev:s?",
+        .params     = "path [frequency [bits [channels [audiodev]]]]",
          .help       = "capture audio to a wave file (default frequency=44100 bits=16 channels=2)",
          .cmd        = hmp_wavcapture,
      },
  STEXI
-@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels}]]]
+@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels} [@var{audiodev}]]]]
  @findex wavcapture
-Capture audio into @var{filename}. Using sample rate @var{frequency}
-bits per sample @var{bits} and number of channels @var{channels}.
Quoted 8 lines

hmp-commands.hx ETEXI · line 834

Quoted 5 lines
hmp-commands.hx +5 -0
+Capture audio into @var{filename} from @var{audiodev}, using sample rate
+@var{frequency} bits per sample @var{bits} and number of channels
+@var{channels}. When not using an -audiodev argument on command line,
+@var{audiodev} must be omitted, otherwise is must specify a valid
+audiodev.

I can see the code for "must specify a valid audiodev" in hmp_wavcapture(). Where is "must be omitted" checked?

It's not checked right now, but if the user specifies audiodev, it must be a valid audiodev id. So if the user can guess the id (which is not too hard ATM, it's simply the driver's name), it will work even in this case.

Quoted 5 lines

Preexisting: the list "sample rate @var{frequency} bits per sample @var{bits} and number of channels @var{channels}" lacks a comma after @var{frequency}, please fix that. I'd put one after @var{bits} as well, but that's a matter of taste[*]

Quoted 8 lines

The sentence is of the form "if not COND then A else B". The less-negated form "if COND then B else A" is commonly easier to read.

Documentation says "from @var{audiodev}". But when "not using an -audiodev argument on command line, +@var{audiodev} must be omitted". Where does it sample from then? I figure from some default audio device. Where is that default audio device explained? I skimmed the -audiodev documentation in qemu-options.hx, but couldn't see it there.

Currently there are two ways to specify audio options, the legacy ones using the QEMU_AUDIO_* environment variables, and the new one using -audiodev arguments. The two formats cannot be mixed, and eventually we should remove the legacy ones (IIRC my previous patch series already deprecated them), then we can get rid of this madness. Maybe something like "When using the legacy environment variable based audio config, @var{audiodev} must be omitted." would be better?

Quoted 4 lines

Suggest to say "an -audiodev command line option" instead of "an -audiodev argument on command line".

Quoted 8 lines

Double-checking:

* -audiodev is the only way to create an audio backend.

* If the user creates no audio backend, QEMU supplies a default audio backend.

Correct?

Not exactly a default audio backend, as it can be customized through environment variables, and as I previously said this is deprecated. When we remove the legacy config, there will be no default backend (like with -netdev and -device).

Quoted 3 lines

Other kinds of backends can also be created at run-time with the monitor. I'm not asking you provide that for audio. I'm just wondering whether it could conceivably be useful.

Yes, since we can create new soundcard devices run-time, creating backends would make sense too.

Quoted 29 lines

If yes, you might want to avoid the narrow "if using -audiodev", and instead say "if the default audio device is in use".

Quoted 9 lines
hmp-commands.hx +0 -0
  Defaults:
  @itemize @minus
qemu-options.hx +0 -0
index 9621e934c0..a308e5f5aa 100644
@@ -1978,6 +1978,12 @@ can help the device and guest to keep up and not lose events in case
  events are arriving in bulk.  Possible causes for the latter are flaky

qemu-options.hx can help the device and guest to keep up and not lose events in case · line 1988

Quoted 10 lines
qemu-options.hx +6 -0
  network connections, or scripts for automated testing.
 
+@item audiodev=@var{audiodev}
+
+Use the specified @var{audiodev} when the VNC client requests audio
+transmission. When not using an -audiodev argument, this option must
+be omitted, otherwise is must be present and specify a valid audiodev.
+
  @end table
  ETEXI

Same as for wavcapture, basically.

[*] https://en.wikipedia.org/wiki/Serial_comma

#7 lore raw

Re: [Qemu-devel] [PATCH v2 03/14] audio: add audiodev property to vnc and wav_capture

Quoted 157 lines · Zoltán Kővágó
Quoted 134 lines · Markus Armbruster
Quoted 30 lines · Zoltán
---
  ui/vnc.h        |  2 ++
  monitor/misc.c  | 12 +++++++++++-
  ui/vnc.c        | 15 ++++++++++++++-
  hmp-commands.hx | 13 ++++++++-----
  qemu-options.hx |  6 ++++++
  5 files changed, 41 insertions(+), 7 deletions(-)
ui/vnc.h +2 -0
index 2f84db3142..6f54653455 100644
@@ -183,6 +183,8 @@ struct VncDisplay
  #ifdef CONFIG_VNC_SASL
      VncDisplaySASL sasl;
  #endif
+
+    AudioState *audio_state;
  };
    typedef struct VncTight {
monitor/misc.c +1 -0
index e393333a0e..f97810d370 100644
@@ -1148,7 +1148,17 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
      int bits = qdict_get_try_int(qdict, "bits", -1);
      int has_channels = qdict_haskey(qdict, "nchannels");
      int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
+    const char *audiodev = qdict_get_try_str(qdict, "audiodev");

monitor/misc.c static void hmp_wavcapture(Monitor *mon, const QDict *qdict) · line 1161

Quoted 10 lines
monitor/misc.c +9 -0
      CaptureState *s;
+    AudioState *as = NULL;
+
+    if (audiodev) {
+        as = audio_state_by_name(audiodev);
+        if (!as) {
+            monitor_printf(mon, "Invalid audiodev specified\n");
+            return;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

Quoted 11 lines
monitor/misc.c +0 -0
        s = g_malloc0 (sizeof (*s));
  @@ -1156,7 +1166,7 @@ static void hmp_wavcapture(Monitor *mon,
 const QDict *qdict)
      bits = has_bits ? bits : 16;
      nchannels = has_channels ? nchannels : 2;
  -    if (wav_start_capture(NULL, s, path, freq, bits, nchannels))
{
+    if (wav_start_capture(as, s, path, freq, bits, nchannels)) {
          monitor_printf(mon, "Failed to add wave capture\n");
          g_free (s);
          return;

Note for later: this is the only other failure mode.

Quoted 30 lines
ui/vnc.c +5 -0
index 140f364dda..24f9be5b5d 100644
@@ -1222,7 +1222,7 @@ static void audio_add(VncState *vs)
      ops.destroy = audio_capture_destroy;
      ops.capture = audio_capture;
  -    vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs);
+    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, &ops, vs);
      if (!vs->audio_cap) {
          error_report("Failed to add audio capture");
      }
@@ -3369,6 +3369,9 @@ static QemuOptsList qemu_vnc_opts = {
          },{
              .name = "non-adaptive",
              .type = QEMU_OPT_BOOL,
+        },{
+            .name = "audiodev",
+            .type = QEMU_OPT_STRING,
          },
          { /* end of list */ }
      },
@@ -3806,6 +3809,7 @@ void vnc_display_open(const char *id, Error **errp)
      const char *saslauthz;
      int lock_key_sync = 1;
      int key_delay_ms;
+    const char *audiodev;
        if (!vd) {
          error_setg(errp, "VNC display not active");

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 4004

Quoted 10 lines
ui/vnc.c +7 -0
@@ -3991,6 +3995,15 @@ void vnc_display_open(const char *id, Error **errp)
      }
      vd->ledstate = 0;
  +    audiodev = qemu_opt_get(opts, "audiodev");
+    if (audiodev) {
+        vd->audio_state = audio_state_by_name(audiodev);
+        if (!vd->audio_state) {
+            error_setg(errp, "Audiodev '%s' not found", audiodev);
+            goto fail;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

I like this error message better than the one in hmp_wavcapture(). Use it there, too?

Move it into audio_state_by_name() by giving it an Error **errp parameter? Matter of taste, up to you.

Quoted 24 lines
ui/vnc.c +1 -0
+
      device_id = qemu_opt_get(opts, "display");
      if (device_id) {
          int head = qemu_opt_get_number(opts, "head", 0);
hmp-commands.hx +3 -5
index bfa5681dd2..fa7f009268 100644
@@ -819,16 +819,19 @@ ETEXI
        {
          .name       = "wavcapture",
-        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?",
-        .params     = "path [frequency [bits [channels]]]",
+        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?,audiodev:s?",
+        .params     = "path [frequency [bits [channels [audiodev]]]]",
          .help       = "capture audio to a wave file (default frequency=44100 bits=16 channels=2)",
          .cmd        = hmp_wavcapture,
      },
  STEXI
-@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels}]]]
+@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels} [@var{audiodev}]]]]
  @findex wavcapture
-Capture audio into @var{filename}. Using sample rate @var{frequency}
-bits per sample @var{bits} and number of channels @var{channels}.
Quoted 8 lines

hmp-commands.hx ETEXI · line 834

Quoted 5 lines
hmp-commands.hx +5 -0
+Capture audio into @var{filename} from @var{audiodev}, using sample rate
+@var{frequency} bits per sample @var{bits} and number of channels
+@var{channels}. When not using an -audiodev argument on command line,
+@var{audiodev} must be omitted, otherwise is must specify a valid
+audiodev.

I can see the code for "must specify a valid audiodev" in hmp_wavcapture(). Where is "must be omitted" checked?

It's not checked right now, but if the user specifies audiodev, it must be a valid audiodev id. So if the user can guess the id (which is not too hard ATM, it's simply the driver's name), it will work even in this case.

Quoted 8 lines

Preexisting: the list "sample rate @var{frequency} bits per sample @var{bits} and number of channels @var{channels}" lacks a comma after @var{frequency}, please fix that. I'd put one after @var{bits} as well, but that's a matter of taste[*]

The sentence is of the form "if not COND then A else B". The less-negated form "if COND then B else A" is commonly easier to read.

Quoted 13 lines
Quoted 5 lines

Documentation says "from @var{audiodev}". But when "not using an -audiodev argument on command line, +@var{audiodev} must be omitted". Where does it sample from then? I figure from some default audio device. Where is that default audio device explained? I skimmed the -audiodev documentation in qemu-options.hx, but couldn't see it there.

Currently there are two ways to specify audio options, the legacy ones using the QEMU_AUDIO_* environment variables, and the new one using -audiodev arguments. The two formats cannot be mixed, and eventually we should remove the legacy ones (IIRC my previous patch series already deprecated them), then we can get rid of this madness. Maybe something like "When using the legacy environment variable based audio config, @var{audiodev} must be omitted." would be better?

What about effectively de-documenting the deprecated method? I.e. write as if it was already gone. This should result in more readable documentation.

Double-checking: will audiodev become mandatory once the deprecated method is gone?

Quoted 11 lines
Quoted 11 lines

Suggest to say "an -audiodev command line option" instead of "an -audiodev argument on command line".

Double-checking:

* -audiodev is the only way to create an audio backend.

* If the user creates no audio backend, QEMU supplies a default audio backend.

Quoted 6 lines
Quoted 1 line

Correct?

Not exactly a default audio backend, as it can be customized through environment variables, and as I previously said this is deprecated. When we remove the legacy config, there will be no default backend (like with -netdev and -device).

Thanks, I see more clearly now.

Quoted 34 lines
Quoted 3 lines

Other kinds of backends can also be created at run-time with the monitor. I'm not asking you provide that for audio. I'm just wondering whether it could conceivably be useful.

Yes, since we can create new soundcard devices run-time, creating backends would make sense too.

Quoted 27 lines

If yes, you might want to avoid the narrow "if using -audiodev", and instead say "if the default audio device is in use".

Quoted 7 lines
hmp-commands.hx +0 -0
    Defaults:
  @itemize @minus
qemu-options.hx +0 -0
index 9621e934c0..a308e5f5aa 100644

qemu-options.hx can help the device and guest to keep up and not lose events in case · line 1987

Quoted 10 lines
qemu-options.hx +5 -0
@@ -1978,6 +1978,12 @@ can help the device and guest to keep up and not lose events in case
  events are arriving in bulk.  Possible causes for the latter are flaky
  network connections, or scripts for automated testing.
  +@item audiodev=@var{audiodev}
+
+Use the specified @var{audiodev} when the VNC client requests audio
+transmission. When not using an -audiodev argument, this option must
+be omitted, otherwise is must be present and specify a valid audiodev.
+
  @end table
  ETEXI

Same as for wavcapture, basically.

[*] https://en.wikipedia.org/wiki/Serial_comma

#8 lore raw

Re: [Qemu-devel] [PATCH v2 03/14] audio: add audiodev property to vnc and wav_capture

Quoted 173 lines · Markus Armbruster
Quoted 157 lines · Zoltán Kővágó
Quoted 134 lines · Markus Armbruster
Quoted 30 lines · Zoltán
---
   ui/vnc.h        |  2 ++
   monitor/misc.c  | 12 +++++++++++-
   ui/vnc.c        | 15 ++++++++++++++-
   hmp-commands.hx | 13 ++++++++-----
   qemu-options.hx |  6 ++++++
   5 files changed, 41 insertions(+), 7 deletions(-)
ui/vnc.h +2 -0
index 2f84db3142..6f54653455 100644
@@ -183,6 +183,8 @@ struct VncDisplay
   #ifdef CONFIG_VNC_SASL
       VncDisplaySASL sasl;
   #endif
+
+    AudioState *audio_state;
   };
     typedef struct VncTight {
monitor/misc.c +1 -0
index e393333a0e..f97810d370 100644
@@ -1148,7 +1148,17 @@ static void hmp_wavcapture(Monitor *mon, const QDict *qdict)
       int bits = qdict_get_try_int(qdict, "bits", -1);
       int has_channels = qdict_haskey(qdict, "nchannels");
       int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
+    const char *audiodev = qdict_get_try_str(qdict, "audiodev");

monitor/misc.c static void hmp_wavcapture(Monitor *mon, const QDict *qdict) · line 1161

Quoted 10 lines
monitor/misc.c +9 -0
       CaptureState *s;
+    AudioState *as = NULL;
+
+    if (audiodev) {
+        as = audio_state_by_name(audiodev);
+        if (!as) {
+            monitor_printf(mon, "Invalid audiodev specified\n");
+            return;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

Quoted 11 lines
monitor/misc.c +0 -0
         s = g_malloc0 (sizeof (*s));
   @@ -1156,7 +1166,7 @@ static void hmp_wavcapture(Monitor *mon,
 const QDict *qdict)
       bits = has_bits ? bits : 16;
       nchannels = has_channels ? nchannels : 2;
   -    if (wav_start_capture(NULL, s, path, freq, bits, nchannels))
{
+    if (wav_start_capture(as, s, path, freq, bits, nchannels)) {
           monitor_printf(mon, "Failed to add wave capture\n");
           g_free (s);
           return;

Note for later: this is the only other failure mode.

Quoted 30 lines
ui/vnc.c +5 -0
index 140f364dda..24f9be5b5d 100644
@@ -1222,7 +1222,7 @@ static void audio_add(VncState *vs)
       ops.destroy = audio_capture_destroy;
       ops.capture = audio_capture;
   -    vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs);
+    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, &ops, vs);
       if (!vs->audio_cap) {
           error_report("Failed to add audio capture");
       }
@@ -3369,6 +3369,9 @@ static QemuOptsList qemu_vnc_opts = {
           },{
               .name = "non-adaptive",
               .type = QEMU_OPT_BOOL,
+        },{
+            .name = "audiodev",
+            .type = QEMU_OPT_STRING,
           },
           { /* end of list */ }
       },
@@ -3806,6 +3809,7 @@ void vnc_display_open(const char *id, Error **errp)
       const char *saslauthz;
       int lock_key_sync = 1;
       int key_delay_ms;
+    const char *audiodev;
         if (!vd) {
           error_setg(errp, "VNC display not active");

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 4004

Quoted 10 lines
ui/vnc.c +7 -0
@@ -3991,6 +3995,15 @@ void vnc_display_open(const char *id, Error **errp)
       }
       vd->ledstate = 0;
   +    audiodev = qemu_opt_get(opts, "audiodev");
+    if (audiodev) {
+        vd->audio_state = audio_state_by_name(audiodev);
+        if (!vd->audio_state) {
+            error_setg(errp, "Audiodev '%s' not found", audiodev);
+            goto fail;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

I like this error message better than the one in hmp_wavcapture(). Use it there, too?

Move it into audio_state_by_name() by giving it an Error **errp parameter? Matter of taste, up to you.

Quoted 24 lines
ui/vnc.c +1 -0
+
       device_id = qemu_opt_get(opts, "display");
       if (device_id) {
           int head = qemu_opt_get_number(opts, "head", 0);
hmp-commands.hx +3 -5
index bfa5681dd2..fa7f009268 100644
@@ -819,16 +819,19 @@ ETEXI
         {
           .name       = "wavcapture",
-        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?",
-        .params     = "path [frequency [bits [channels]]]",
+        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?,audiodev:s?",
+        .params     = "path [frequency [bits [channels [audiodev]]]]",
           .help       = "capture audio to a wave file (default frequency=44100 bits=16 channels=2)",
           .cmd        = hmp_wavcapture,
       },
   STEXI
-@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels}]]]
+@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels} [@var{audiodev}]]]]
   @findex wavcapture
-Capture audio into @var{filename}. Using sample rate @var{frequency}
-bits per sample @var{bits} and number of channels @var{channels}.
Quoted 8 lines

hmp-commands.hx ETEXI · line 834

Quoted 5 lines
hmp-commands.hx +5 -0
+Capture audio into @var{filename} from @var{audiodev}, using sample rate
+@var{frequency} bits per sample @var{bits} and number of channels
+@var{channels}. When not using an -audiodev argument on command line,
+@var{audiodev} must be omitted, otherwise is must specify a valid
+audiodev.

I can see the code for "must specify a valid audiodev" in hmp_wavcapture(). Where is "must be omitted" checked?

It's not checked right now, but if the user specifies audiodev, it must be a valid audiodev id. So if the user can guess the id (which is not too hard ATM, it's simply the driver's name), it will work even in this case.

Quoted 8 lines

Preexisting: the list "sample rate @var{frequency} bits per sample @var{bits} and number of channels @var{channels}" lacks a comma after @var{frequency}, please fix that. I'd put one after @var{bits} as well, but that's a matter of taste[*]

The sentence is of the form "if not COND then A else B". The less-negated form "if COND then B else A" is commonly easier to read.

Quoted 13 lines
Quoted 5 lines

Documentation says "from @var{audiodev}". But when "not using an -audiodev argument on command line, +@var{audiodev} must be omitted". Where does it sample from then? I figure from some default audio device. Where is that default audio device explained? I skimmed the -audiodev documentation in qemu-options.hx, but couldn't see it there.

Currently there are two ways to specify audio options, the legacy ones using the QEMU_AUDIO_* environment variables, and the new one using -audiodev arguments. The two formats cannot be mixed, and eventually we should remove the legacy ones (IIRC my previous patch series already deprecated them), then we can get rid of this madness. Maybe something like "When using the legacy environment variable based audio config, @var{audiodev} must be omitted." would be better?

Quoted 3 lines

What about effectively de-documenting the deprecated method? I.e. write as if it was already gone. This should result in more readable documentation.

Makes sense. User will less likely use deprecated methods that way and it simplifies the documentation.

Quoted 2 lines

Double-checking: will audiodev become mandatory once the deprecated method is gone?

Yes.

Quoted 55 lines
Quoted 12 lines
Quoted 12 lines

Suggest to say "an -audiodev command line option" instead of "an -audiodev argument on command line".

Double-checking:

* -audiodev is the only way to create an audio backend.

* If the user creates no audio backend, QEMU supplies a default audio backend.

Quoted 6 lines
Quoted 1 line

Correct?

Not exactly a default audio backend, as it can be customized through environment variables, and as I previously said this is deprecated. When we remove the legacy config, there will be no default backend (like with -netdev and -device).

Thanks, I see more clearly now.

Quoted 34 lines
Quoted 3 lines

Other kinds of backends can also be created at run-time with the monitor. I'm not asking you provide that for audio. I'm just wondering whether it could conceivably be useful.

Yes, since we can create new soundcard devices run-time, creating backends would make sense too.

Quoted 27 lines

If yes, you might want to avoid the narrow "if using -audiodev", and instead say "if the default audio device is in use".

Quoted 7 lines
hmp-commands.hx +0 -0
     Defaults:
   @itemize @minus
qemu-options.hx +0 -0
index 9621e934c0..a308e5f5aa 100644

qemu-options.hx can help the device and guest to keep up and not lose events in case · line 1987

Quoted 10 lines
qemu-options.hx +5 -0
@@ -1978,6 +1978,12 @@ can help the device and guest to keep up and not lose events in case
   events are arriving in bulk.  Possible causes for the latter are flaky
   network connections, or scripts for automated testing.
   +@item audiodev=@var{audiodev}
+
+Use the specified @var{audiodev} when the VNC client requests audio
+transmission. When not using an -audiodev argument, this option must
+be omitted, otherwise is must be present and specify a valid audiodev.
+
   @end table
   ETEXI

Same as for wavcapture, basically.

[*] https://en.wikipedia.org/wiki/Serial_comma

#9 lore raw

Re: [Qemu-devel] [PATCH v2 03/14] audio: add audiodev property to vnc and wav_capture

Quoted 188 lines · Zoltán Kővágó
Quoted 183 lines · Markus Armbruster
Quoted 167 lines · Zoltán Kővágó
Quoted 143 lines · Markus Armbruster
Quoted 31 lines · Zoltán

---
   ui/vnc.h        |  2 ++
   monitor/misc.c  | 12 +++++++++++-
   ui/vnc.c        | 15 ++++++++++++++-
   hmp-commands.hx | 13 ++++++++-----
   qemu-options.hx |  6 ++++++

   5 files changed, 41 insertions(+), 7 deletions(-)
ui/vnc.h +2 -0
index 2f84db3142..6f54653455 100644
@@ -183,6 +183,8 @@ struct VncDisplay
    #ifdef CONFIG_VNC_SASL
        VncDisplaySASL sasl;
    #endif
+
+    AudioState *audio_state;
    };
      typedef struct VncTight {
monitor/misc.c +1 -0
index e393333a0e..f97810d370 100644
@@ -1148,7 +1148,17 @@ static void hmp_wavcapture(Monitor *mon, 
 const QDict *qdict)
        int bits = qdict_get_try_int(qdict, "bits", -1);
        int has_channels = qdict_haskey(qdict, "nchannels");
        int nchannels = qdict_get_try_int(qdict, "nchannels", -1);
+    const char *audiodev = qdict_get_try_str(qdict, "audiodev");

monitor/misc.c static void hmp_wavcapture(Monitor *mon, · line 1162

Quoted 10 lines
monitor/misc.c +9 -0
        CaptureState *s;
+    AudioState *as = NULL;
+
+    if (audiodev) {
+        as = audio_state_by_name(audiodev);
+        if (!as) {
+            monitor_printf(mon, "Invalid audiodev specified\n");
+            return;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

Quoted 11 lines
monitor/misc.c +0 -0
          s = g_malloc0 (sizeof (*s));
    @@ -1156,7 +1166,7 @@ static void hmp_wavcapture(Monitor *mon,

const QDict *qdict)
       bits = has_bits ? bits : 16;
       nchannels = has_channels ? nchannels : 2;
   -    if (wav_start_capture(NULL, s, path, freq, bits, nchannels)) {
+    if (wav_start_capture(as, s, path, freq, bits, nchannels)) { monitor_printf(mon, "Failed to add wave capture\n"); g_free (s);
           return;

Note for later: this is the only other failure mode.

Quoted 33 lines
ui/vnc.c +1 -0
index 140f364dda..24f9be5b5d 100644
@@ -1222,7 +1222,7 @@ static void audio_add(VncState *vs)
        ops.destroy = audio_capture_destroy;
        ops.capture = audio_capture;
    -    vs->audio_cap = AUD_add_capture(NULL, &vs->as, &ops, vs);
+    vs->audio_cap = AUD_add_capture(vs->vd->audio_state, &vs->as, 
 &ops, vs);
        if (!vs->audio_cap) {
            error_report("Failed to add audio capture");

       }

ui/vnc.c +4 -0
@@ -3369,6 +3369,9 @@ static QemuOptsList qemu_vnc_opts = {
            },{
                .name = "non-adaptive",
                .type = QEMU_OPT_BOOL,
+        },{
+            .name = "audiodev",
+            .type = QEMU_OPT_STRING,
            },
            { /* end of list */ }
        },
@@ -3806,6 +3809,7 @@ void vnc_display_open(const char *id, Error 
 **errp)
        const char *saslauthz;
        int lock_key_sync = 1;
        int key_delay_ms;
+    const char *audiodev;
          if (!vd) {
            error_setg(errp, "VNC display not active");
@@ -3991,6 +3995,15 @@ void vnc_display_open(const char *id, Error 
 **errp)

ui/vnc.c void vnc_display_open(const char *id, Error · line 4005

Quoted 10 lines
ui/vnc.c +7 -0
        }
        vd->ledstate = 0;
    +    audiodev = qemu_opt_get(opts, "audiodev");
+    if (audiodev) {
+        vd->audio_state = audio_state_by_name(audiodev);
+        if (!vd->audio_state) {
+            error_setg(errp, "Audiodev '%s' not found", audiodev);
+            goto fail;
+        }
+    }

Note for later: if "audiodev" is specified, it must name an existing AudioState.

I like this error message better than the one in hmp_wavcapture().  Use it there, too?

Move it into audio_state_by_name() by giving it an Error **errp parameter?  Matter of taste, up to you.

Quoted 29 lines
ui/vnc.c +1 -0
+
        device_id = qemu_opt_get(opts, "display");
        if (device_id) {

           int head = qemu_opt_get_number(opts, "head", 0);

hmp-commands.hx +2 -2
index bfa5681dd2..fa7f009268 100644
@@ -819,16 +819,19 @@ ETEXI
          {
            .name       = "wavcapture",
-        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?",
-        .params     = "path [frequency [bits [channels]]]",
+        .args_type  = 
 "path:F,freq:i?,bits:i?,nchannels:i?,audiodev:s?",
+        .params     = "path [frequency [bits [channels 
 [audiodev]]]]",
            .help       = "capture audio to a wave file (default frequency=44100 bits=16 channels=2)",
            .cmd        = hmp_wavcapture,
        },

   STEXI
-@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels}]]]
+@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels} [@var{audiodev}]]]]
   @findex wavcapture

hmp-commands.hx +1 -2
-Capture audio into @var{filename}. Using sample rate @var{frequency}
-bits per sample @var{bits} and number of channels @var{channels}.
+Capture audio into @var{filename} from @var{audiodev}, using 
Quoted 8 lines
Quoted 5 lines

sample rate
+@var{frequency} bits per sample @var{bits} and number of channels +@var{channels}. When not using an -audiodev argument on command line, +@var{audiodev} must be omitted, otherwise is must specify a valid +audiodev.

I can see the code for "must specify a valid audiodev" in hmp_wavcapture().  Where is "must be omitted" checked?

It's not checked right now, but if the user specifies audiodev, it must be a valid audiodev id.  So if the user can guess the id (which is not too hard ATM, it's simply the driver's name), it will work even in this case.

Quoted 9 lines

Preexisting: the list "sample rate @var{frequency} bits per sample @var{bits} and number of channels @var{channels}" lacks a comma after @var{frequency}, please fix that.  I'd put one after @var{bits} as well,
but that's a matter of taste[*]

The sentence is of the form "if not COND then A else B".  The less-negated form "if COND then B else A" is commonly easier to read.

Quoted 13 lines
Quoted 5 lines

Documentation says "from @var{audiodev}".  But when "not using an -audiodev argument on command line, +@var{audiodev} must be omitted". Where does it sample from then?  I figure from some default audio device.  Where is that default audio device explained?  I skimmed the -audiodev documentation in qemu-options.hx, but couldn't see it there.

Currently there are two ways to specify audio options, the legacy ones using the QEMU_AUDIO_* environment variables, and the new one using -audiodev arguments.  The two formats cannot be mixed, and eventually we should remove the legacy ones (IIRC my previous patch series already deprecated them), then we can get rid of this madness.  Maybe something like "When using the legacy environment variable based audio config, @var{audiodev} must be omitted." would be better?

Quoted 3 lines

What about effectively de-documenting the deprecated method?  I.e. write as if it was already gone.  This should result in more readable documentation.

Quoted 6 lines

Makes sense.  User will less likely use deprecated methods that way and it simplifies the documentation.

Quoted 2 lines

Double-checking: will audiodev become mandatory once the deprecated method is gone?

Yes.

Actually, now that I took a second look at the params, it might be problematic. Currently audiodev is the last parameter, so if it becomes mandatory, that will effectively mean other parameters will become mandatory too. And if I were to change the order and move audiodev first, that would break backward compatibility during the deprecation period.

Quoted 59 lines
Quoted 58 lines
Quoted 13 lines
Quoted 13 lines

Suggest to say "an -audiodev command line option" instead of "an -audiodev argument on command line".

Double-checking:

* -audiodev is the only way to create an audio backend.

* If the user creates no audio backend, QEMU supplies a default audio backend.

Quoted 6 lines
Quoted 1 line

Correct?

Not exactly a default audio backend, as it can be customized through environment variables, and as I previously said this is deprecated. When we remove the legacy config, there will be no default backend (like with -netdev and -device).

Thanks, I see more clearly now.

Quoted 36 lines
Quoted 3 lines

Other kinds of backends can also be created at run-time with the monitor.  I'm not asking you provide that for audio.  I'm just wondering whether it could conceivably be useful.

Yes, since we can create new soundcard devices run-time, creating backends would make sense too.

Quoted 29 lines

If yes, you might want to avoid the narrow "if using -audiodev", and instead say "if the default audio device is in use".

Quoted 15 lines

     Defaults:
   @itemize @minus

qemu-options.hx +0 -0
index 9621e934c0..a308e5f5aa 100644
@@ -1978,6 +1978,12 @@ can help the device and guest to keep up and 

not lose events in case
   events are arriving in bulk.  Possible causes for the latter are flaky network connections, or scripts for automated testing. +@item audiodev=@var{audiodev}

qemu-options.hx +4 -0
+
+Use the specified @var{audiodev} when the VNC client requests audio
+transmission. When not using an -audiodev argument, this option must
+be omitted, otherwise is must be present and specify a valid 
Quoted 4 lines

audiodev.
+
   @end table
   ETEXI

Same as for wavcapture, basically.

[*] https://en.wikipedia.org/wiki/Serial_comma

#10 lore raw

Re: [Qemu-devel] [PATCH v2 03/14] audio: add audiodev property to vnc and wav_capture

Quoted 5 lines · Zoltán Kővágó
Quoted 4 lines · Zoltán Kővágó
Quoted 3 lines · Markus Armbruster
Quoted 1 line · Zoltán Kővágó

On 2019-07-16 08:23, Markus Armbruster wrote:

[...]

Quoted 73 lines
Quoted 73 lines
Quoted 63 lines
Quoted 49 lines
Quoted 26 lines
Quoted 26 lines
hmp-commands.hx +2 -2
index bfa5681dd2..fa7f009268 100644
@@ -819,16 +819,19 @@ ETEXI
          {
            .name       = "wavcapture",
-        .args_type  = "path:F,freq:i?,bits:i?,nchannels:i?",
-        .params     = "path [frequency [bits [channels]]]",
+        .args_type  =
 "path:F,freq:i?,bits:i?,nchannels:i?,audiodev:s?",
+        .params     = "path [frequency [bits [channels
 [audiodev]]]]",

           .help       = "capture audio to a wave file (default frequency=44100 bits=16 channels=2)",
           .cmd        = hmp_wavcapture,
       },
   STEXI
-@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels}]]]
+@item wavcapture @var{filename} [@var{frequency} [@var{bits} [@var{channels} [@var{audiodev}]]]]
   @findex wavcapture

hmp-commands.hx +1 -2
-Capture audio into @var{filename}. Using sample rate @var{frequency}
-bits per sample @var{bits} and number of channels @var{channels}.
+Capture audio into @var{filename} from @var{audiodev}, using
Quoted 8 lines
Quoted 5 lines

sample rate
+@var{frequency} bits per sample @var{bits} and number of channels +@var{channels}. When not using an -audiodev argument on command line, +@var{audiodev} must be omitted, otherwise is must specify a valid +audiodev.

I can see the code for "must specify a valid audiodev" in hmp_wavcapture().  Where is "must be omitted" checked?

It's not checked right now, but if the user specifies audiodev, it must be a valid audiodev id.  So if the user can guess the id (which is not too hard ATM, it's simply the driver's name), it will work even in this case.

Quoted 9 lines

Preexisting: the list "sample rate @var{frequency} bits per sample @var{bits} and number of channels @var{channels}" lacks a comma after @var{frequency}, please fix that.  I'd put one after @var{bits} as well,
but that's a matter of taste[*]

The sentence is of the form "if not COND then A else B".  The less-negated form "if COND then B else A" is commonly easier to read.

Quoted 13 lines
Quoted 5 lines

Documentation says "from @var{audiodev}".  But when "not using an -audiodev argument on command line, +@var{audiodev} must be omitted". Where does it sample from then?  I figure from some default audio device.  Where is that default audio device explained?  I skimmed the -audiodev documentation in qemu-options.hx, but couldn't see it there.

Currently there are two ways to specify audio options, the legacy ones using the QEMU_AUDIO_* environment variables, and the new one using -audiodev arguments.  The two formats cannot be mixed, and eventually we should remove the legacy ones (IIRC my previous patch series already deprecated them), then we can get rid of this madness.  Maybe something like "When using the legacy environment variable based audio config, @var{audiodev} must be omitted." would be better?

Quoted 3 lines

What about effectively de-documenting the deprecated method?  I.e. write as if it was already gone.  This should result in more readable documentation.

Makes sense.  User will less likely use deprecated methods that way and it simplifies the documentation.

Quoted 2 lines

Double-checking: will audiodev become mandatory once the deprecated method is gone?

Quoted 8 lines
Quoted 1 line

Yes.

Actually, now that I took a second look at the params, it might be problematic. Currently audiodev is the last parameter, so if it becomes mandatory, that will effectively mean other parameters will become mandatory too. And if I were to change the order and move audiodev first, that would break backward compatibility during the deprecation period.

HMP is not a stable interface. We can break compatibility there when we have a reason.

In this case, we can either break it right away (insert audiodev before the other optional parameters), or later (insert it last, move it when it becomes mandatory). Matter of taste. I'd break it right away.