Skip to contentSkip to conversation

audio: cleanups & add a manual test

PATCH In review Marc-André Lureau 3 participants 90 messages Feb 16 – Feb 17 Arm/Amlogic Meson SoC support Page 2 of 2

lore
Share & tools
lore
#69 lore raw

PATCH 66/85 audio/pa: replace custom logging with report & trace

In reply to Marc-André Lureau

Replace the custom audio logging infrastructure with standard QEMU error reporting and tracing.

qpa_conn_init() is called during audio_pa_realize() and already reports an error through Error *.

---
 audio/paaudio.c | 77 ++++++++++++++++++++++++++++-----------------------------
 1 file changed, 38 insertions(+), 39 deletions(-)
audio/paaudio.c +38 -39
index b7826402e12..1501b26386a 100644
@@ -3,14 +3,13 @@
 #include "qemu/osdep.h"
 #include "qemu/module.h"
 #include "qemu/audio.h"
+#include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qom/object.h"
+#include "audio_int.h"
 
 #include <pulse/pulseaudio.h>
 
-#define AUDIO_CAP "pulseaudio"
-#include "audio_int.h"
-
 #define TYPE_AUDIO_PA "audio-pa"
 OBJECT_DECLARE_SIMPLE_TYPE(AudioPa, AUDIO_PA)
 
@@ -51,15 +50,16 @@ typedef struct {
 
 static void qpa_conn_fini(PAConnection *c);
 
-static void G_GNUC_PRINTF (2, 3) qpa_logerr (int err, const char *fmt, ...)
+static void G_GNUC_PRINTF(2, 3) qpa_logerr(int err, const char *fmt, ...)
 {
     va_list ap;
 
-    va_start (ap, fmt);
-    AUD_vlog (AUDIO_CAP, fmt, ap);
-    va_end (ap);
+    error_printf("pulseaudio: ");
+    va_start(ap, fmt);
+    error_vprintf(fmt, ap);
+    va_end(ap);
 
-    AUD_log (AUDIO_CAP, "Reason: %s\n", pa_strerror (err));
+    error_printf(" Reason: %s\n", pa_strerror(err));
 }
 
 #ifndef PA_CONTEXT_IS_GOOD
@@ -113,12 +113,12 @@ static void *qpa_get_buffer_in(HWVoiceIn *hw, size_t *size)
     pa_threaded_mainloop_lock(c->mainloop);
 
     CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
-                    "pa_threaded_mainloop_lock failed\n");
+                    "pa_threaded_mainloop_lock failed");
 
     if (!p->read_length) {
         r = pa_stream_peek(p->stream, &p->read_data, &p->read_length);
         CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail,
-                           "pa_stream_peek failed\n");
+                           "pa_stream_peek failed");
     }
 
     *size = MIN(p->read_length, *size);
@@ -141,7 +141,7 @@ static void qpa_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size)
     pa_threaded_mainloop_lock(c->mainloop);
 
     CHECK_DEAD_GOTO(c, p->stream, unlock,
-                    "pa_threaded_mainloop_lock failed\n");
+                    "pa_threaded_mainloop_lock failed");
 
     assert(buf == p->read_data && size <= p->read_length);
 
@@ -150,7 +150,7 @@ static void qpa_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size)
 
     if (size && !p->read_length) {
         r = pa_stream_drop(p->stream);
-        CHECK_SUCCESS_GOTO(c, r == 0, unlock, "pa_stream_drop failed\n");
+        CHECK_SUCCESS_GOTO(c, r == 0, unlock, "pa_stream_drop failed");
     }
 
 unlock:
@@ -166,7 +166,7 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, size_t length)
     pa_threaded_mainloop_lock(c->mainloop);
 
     CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
-                    "pa_threaded_mainloop_lock failed\n");
+                    "pa_threaded_mainloop_lock failed");
     if (pa_stream_get_state(p->stream) != PA_STREAM_READY) {
         /* wait for stream to become ready */
         goto unlock;
@@ -179,7 +179,7 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, size_t length)
         if (!p->read_length) {
             r = pa_stream_peek(p->stream, &p->read_data, &p->read_length);
             CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail,
-                               "pa_stream_peek failed\n");
+                               "pa_stream_peek failed");
             if (!p->read_length) {
                 /* buffer is empty */
                 break;
@@ -196,7 +196,7 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, size_t length)
         if (!p->read_length) {
             r = pa_stream_drop(p->stream);
             CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail,
-                               "pa_stream_drop failed\n");
+                               "pa_stream_drop failed");
         }
     }
 
@@ -218,7 +218,7 @@ static size_t qpa_buffer_get_free(HWVoiceOut *hw)
     pa_threaded_mainloop_lock(c->mainloop);
 
     CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
-                    "pa_threaded_mainloop_lock failed\n");
+                    "pa_threaded_mainloop_lock failed");
     if (pa_stream_get_state(p->stream) != PA_STREAM_READY) {
         /* wait for stream to become ready */
         l = 0;
@@ -227,7 +227,7 @@ static size_t qpa_buffer_get_free(HWVoiceOut *hw)
 
     l = pa_stream_writable_size(p->stream);
     CHECK_SUCCESS_GOTO(c, l != (size_t) -1, unlock_and_fail,
-                       "pa_stream_writable_size failed\n");
+                       "pa_stream_writable_size failed");
 
 unlock:
     pa_threaded_mainloop_unlock(c->mainloop);
@@ -248,12 +248,12 @@ static void *qpa_get_buffer_out(HWVoiceOut *hw, size_t *size)
     pa_threaded_mainloop_lock(c->mainloop);
 
     CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
-                    "pa_threaded_mainloop_lock failed\n");
+                    "pa_threaded_mainloop_lock failed");
 
     *size = -1;
     r = pa_stream_begin_write(p->stream, &ret, size);
     CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail,
-                       "pa_stream_begin_write failed\n");
+                       "pa_stream_begin_write failed");
 
     pa_threaded_mainloop_unlock(c->mainloop);
     return ret;
@@ -273,10 +273,10 @@ static size_t qpa_put_buffer_out(HWVoiceOut *hw, void *data, size_t length)
     pa_threaded_mainloop_lock(c->mainloop);
 
     CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
-                    "pa_threaded_mainloop_lock failed\n");
+                    "pa_threaded_mainloop_lock failed");
 
     r = pa_stream_write(p->stream, data, length, NULL, 0LL, PA_SEEK_RELATIVE);
-    CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_write failed\n");
+    CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_write failed");
 
     pa_threaded_mainloop_unlock(c->mainloop);
     return length;
@@ -296,7 +296,7 @@ static size_t qpa_write(HWVoiceOut *hw, void *data, size_t length)
     pa_threaded_mainloop_lock(c->mainloop);
 
     CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
-                    "pa_threaded_mainloop_lock failed\n");
+                    "pa_threaded_mainloop_lock failed");
     if (pa_stream_get_state(p->stream) != PA_STREAM_READY) {
         /* wait for stream to become ready */
         l = 0;
@@ -306,14 +306,14 @@ static size_t qpa_write(HWVoiceOut *hw, void *data, size_t length)
     l = pa_stream_writable_size(p->stream);
 
     CHECK_SUCCESS_GOTO(c, l != (size_t) -1, unlock_and_fail,
-                       "pa_stream_writable_size failed\n");
+                       "pa_stream_writable_size failed");
 
     if (l > length) {
         l = length;
     }
 
     r = pa_stream_write(p->stream, data, l, NULL, 0LL, PA_SEEK_RELATIVE);
-    CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_write failed\n");
+    CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_write failed");
 
 unlock:
     pa_threaded_mainloop_unlock(c->mainloop);
@@ -345,7 +345,7 @@ static pa_sample_format_t audfmt_to_pa(AudioFormat afmt, bool big_endian)
         format = big_endian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE;
         break;
     default:
-        dolog ("Internal logic error: Bad audio format %d\n", afmt);
+        error_report("pulseaudio: Internal logic error: Bad audio format %d", afmt);
         format = PA_SAMPLE_U8;
         break;
     }
@@ -376,12 +376,12 @@ static AudioFormat pa_to_audfmt (pa_sample_format_t fmt, int *endianness)
         *endianness = 0;
         return AUDIO_FORMAT_F32;
     default:
-        dolog ("Internal logic error: Bad pa_sample_format %d\n", fmt);
+        error_report("pulseaudio: Internal logic error: Bad pa_sample_format %d", fmt);
         return AUDIO_FORMAT_U8;
     }
 }
 
-static void context_state_cb (pa_context *c, void *userdata)
+static void context_state_cb(pa_context *c, void *userdata)
 {
     PAConnection *conn = userdata;
 
@@ -473,7 +473,7 @@ static pa_stream *qpa_simple_new (
         break;
 
     default:
-        dolog("Internal error: unsupported channel count %d\n", ss->channels);
+        error_report("pulseaudio: unsupported channel count %d", ss->channels);
         goto fail;
     }
 
@@ -553,7 +553,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as)
         &error
         );
     if (!pa->stream) {
-        qpa_logerr (error, "pa_simple_new for playback failed\n");
+        qpa_logerr(error, "pa_simple_new for playback failed");
         goto fail1;
     }
 
@@ -604,7 +604,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as)
         &error
         );
     if (!pa->stream) {
-        qpa_logerr (error, "pa_simple_new for capture failed\n");
+        qpa_logerr(error, "pa_simple_new for capture failed");
         goto fail1;
     }
 
@@ -633,7 +633,7 @@ static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream)
 
     err = pa_stream_disconnect(stream);
     if (err != 0) {
-        dolog("Failed to disconnect! err=%d\n", err);
+        error_report("pulseaudio: Failed to disconnect! err=%d", err);
     }
     pa_stream_unref(stream);
 }
@@ -664,7 +664,7 @@ static void qpa_fini_in (HWVoiceIn *hw)
             int r = pa_stream_drop(pa->stream);
             if (r) {
                 qpa_logerr(pa_context_errno(c->context),
-                           "pa_stream_drop failed\n");
+                           "pa_stream_drop failed");
             }
             pa->read_length = 0;
         }
@@ -698,7 +698,7 @@ static void qpa_volume_out(HWVoiceOut *hw, Volume *vol)
                                           &v, NULL, NULL);
     if (!op) {
         qpa_logerr(pa_context_errno(c->context),
-                   "set_sink_input_volume() failed\n");
+                   "set_sink_input_volume() failed");
     } else {
         pa_operation_unref(op);
     }
@@ -708,7 +708,7 @@ static void qpa_volume_out(HWVoiceOut *hw, Volume *vol)
                                         vol->mute, NULL, NULL);
     if (!op) {
         qpa_logerr(pa_context_errno(c->context),
-                   "set_sink_input_mute() failed\n");
+                   "set_sink_input_mute() failed");
     } else {
         pa_operation_unref(op);
     }
@@ -740,7 +740,7 @@ static void qpa_volume_in(HWVoiceIn *hw, Volume *vol)
         &v, NULL, NULL);
     if (!op) {
         qpa_logerr(pa_context_errno(c->context),
-                   "set_source_output_volume() failed\n");
+                   "set_source_output_volume() failed");
     } else {
         pa_operation_unref(op);
     }
@@ -750,7 +750,7 @@ static void qpa_volume_in(HWVoiceIn *hw, Volume *vol)
         vol->mute, NULL, NULL);
     if (!op) {
         qpa_logerr(pa_context_errno(c->context),
-                   "set_source_output_mute() failed\n");
+                   "set_source_output_mute() failed");
     } else {
         pa_operation_unref(op);
     }
@@ -788,7 +788,7 @@ static void *qpa_conn_init(const char *server)
 
     if (pa_context_connect(c->context, server, 0, NULL) < 0) {
         qpa_logerr(pa_context_errno(c->context),
-                   "pa_context_connect() failed\n");
+                   "pa_context_connect() failed");
         goto fail;
     }
 
@@ -809,7 +809,7 @@ static void *qpa_conn_init(const char *server)
 
         if (!PA_CONTEXT_IS_GOOD(state)) {
             qpa_logerr(pa_context_errno(c->context),
-                       "Wrong context state\n");
+                       "Wrong context state");
             goto unlock_and_fail;
         }
 
@@ -823,7 +823,6 @@ static void *qpa_conn_init(const char *server)
 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;
 }
Signature · 1 line
2.53.0
#70 lore raw

PATCH 67/85 audio/pw: replace custom logging with error_report

In reply to Marc-André Lureau

Replace the custom audio logging infrastructure (dolog macro) with standard QEMU error reporting (error_report).

---
 audio/pwaudio.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
audio/pwaudio.c +5 -6
index 7a009a94f3a..6a80e5a333e 100644
@@ -20,14 +20,13 @@
 #include <spa/param/props.h>
 
 #include <pipewire/pipewire.h>
+
+#include "audio_int.h"
 #include "trace.h"
 
-#define AUDIO_CAP "pipewire"
 #define RINGBUFFER_SIZE    (1u << 22)
 #define RINGBUFFER_MASK    (RINGBUFFER_SIZE - 1)
 
-#include "audio_int.h"
-
 #define TYPE_AUDIO_PW "audio-pipewire"
 OBJECT_DECLARE_SIMPLE_TYPE(AudioPw, AUDIO_PW)
 
@@ -358,7 +357,7 @@ audfmt_to_pw(AudioFormat fmt, bool big_endian)
         format = big_endian ? SPA_AUDIO_FORMAT_F32_BE : SPA_AUDIO_FORMAT_F32_LE;
         break;
     default:
-        dolog("Internal logic error: Bad audio format %d\n", fmt);
+        error_report("pipewire: internal logic error: bad audio format %d", fmt);
         format = SPA_AUDIO_FORMAT_U8;
         break;
     }
@@ -418,7 +417,7 @@ pw_to_audfmt(enum spa_audio_format fmt, int *endianness,
         return AUDIO_FORMAT_F32;
     default:
         *sample_size = 1;
-        dolog("Internal logic error: Bad spa_audio_format %d\n", fmt);
+        error_report("pipewire: internal logic error: bad spa_audio_format %d", fmt);
         return AUDIO_FORMAT_U8;
     }
 }
@@ -518,7 +517,7 @@ qpw_set_position(uint32_t channels, uint32_t position[SPA_AUDIO_MAX_CHANNELS])
         position[0] = SPA_AUDIO_CHANNEL_MONO;
         break;
     default:
-        dolog("Internal error: unsupported channel count %d\n", channels);
+        error_report("pipewire: unsupported channel count %d", channels);
     }
 }
 
Signature · 1 line
2.53.0
#71 lore raw

PATCH 68/85 audio/sdl: replace custom logging with error_report

In reply to Marc-André Lureau

Replace the custom audio logging infrastructure (dolog macro and AUD_log/AUD_vlog) with standard QEMU error reporting (error_report, error_printf, error_vprintf).

Note that we also dropped the abort() call in DEBUG_AUDIO, as it is not usually compiled with, doesn't help much, and can easily be added back when doing development as needed.

---
 audio/sdlaudio.c | 36 +++++++++---------------------------
 1 file changed, 9 insertions(+), 27 deletions(-)
audio/sdlaudio.c +9 -27
index d974d7eac46..5f332678209 100644
@@ -26,6 +26,7 @@
 #include <SDL.h>
 #include <SDL_thread.h>
 #include "qemu/module.h"
+#include "qemu/error-report.h"
 #include "qapi/error.h"
 #include "qemu/audio.h"
 #include "qom/object.h"
@@ -38,7 +39,6 @@
 #endif
 #endif
 
-#define AUDIO_CAP "sdl"
 #include "audio_int.h"
 
 #define TYPE_AUDIO_SDL "audio-sdl"
@@ -67,17 +67,6 @@ typedef struct SDLVoiceIn {
     SDL_AudioDeviceID devid;
 } SDLVoiceIn;
 
-static void G_GNUC_PRINTF (1, 2) sdl_logerr (const char *fmt, ...)
-{
-    va_list ap;
-
-    va_start (ap, fmt);
-    AUD_vlog (AUDIO_CAP, fmt, ap);
-    va_end (ap);
-
-    AUD_log (AUDIO_CAP, "Reason: %s\n", SDL_GetError ());
-}
-
 static int aud_to_sdlfmt (AudioFormat fmt)
 {
     switch (fmt) {
@@ -102,10 +91,7 @@ static int aud_to_sdlfmt (AudioFormat fmt)
         return AUDIO_F32LSB;
 
     default:
-        dolog ("Internal logic error: Bad audio format %d\n", fmt);
-#ifdef DEBUG_AUDIO
-        abort ();
-#endif
+        error_report("sdl: internal logic error: bad audio format %d", fmt);
         return AUDIO_U8;
     }
 }
@@ -164,7 +150,7 @@ static int sdl_to_audfmt(int sdlfmt, AudioFormat *fmt, int *endianness)
         break;
 
     default:
-        dolog ("Unrecognized SDL audio format %d\n", sdlfmt);
+        error_report("sdl: unrecognized audio format %d", sdlfmt);
         return -1;
     }
 
@@ -182,27 +168,27 @@ static SDL_AudioDeviceID sdl_open(SDL_AudioSpec *req, SDL_AudioSpec *obt,
     /* Make sure potential threads created by SDL don't hog signals.  */
     err = sigfillset (&new);
     if (err) {
-        dolog ("sdl_open: sigfillset failed: %s\n", strerror (errno));
+        error_report("sdl: sigfillset failed: %s", strerror (errno));
         return 0;
     }
     err = pthread_sigmask (SIG_BLOCK, &new, &old);
     if (err) {
-        dolog ("sdl_open: pthread_sigmask failed: %s\n", strerror (err));
+        error_report("sdl: pthread_sigmask failed: %s", strerror (err));
         return 0;
     }
 #endif
 
     devid = SDL_OpenAudioDevice(NULL, rec, req, obt, 0);
     if (!devid) {
-        sdl_logerr("SDL_OpenAudioDevice for %s failed\n",
-                   rec ? "recording" : "playback");
+        error_report("SDL_OpenAudioDevice for %s failed: %s",
+                   rec ? "recording" : "playback", SDL_GetError());
     }
 
 #ifndef _WIN32
     err = pthread_sigmask (SIG_SETMASK, &old, NULL);
     if (err) {
-        dolog ("sdl_open: pthread_sigmask (restore) failed: %s\n",
-               strerror (errno));
+        error_report("sdl: pthread_sigmask (restore) failed: %s",
+                     strerror (errno));
         /* We have failed to restore original signal mask, all bets are off,
            so exit the process */
         exit (EXIT_FAILURE);
@@ -233,8 +219,6 @@ static void sdl_callback_out(void *opaque, Uint8 *buf, int len)
 
     if (!sdl->exit) {
 
-        /* dolog("callback_out: len=%d avail=%zu\n", len, hw->pending_emul); */
-
         while (hw->pending_emul && len) {
             size_t write_len, start;
 
@@ -283,8 +267,6 @@ static void sdl_callback_in(void *opaque, Uint8 *buf, int len)
         return;
     }
 
-    /* dolog("callback_in: len=%d pending=%zu\n", len, hw->pending_emul); */
-
     while (hw->pending_emul < hw->size_emul && len) {
         size_t read_len = MIN(len, MIN(hw->size_emul - hw->pos_emul,
                                        hw->size_emul - hw->pending_emul));
Signature · 1 line
2.53.0
#72 lore raw

PATCH 69/85 audio/sndio: replace custom logging with error_report

In reply to Marc-André Lureau

Replace the custom audio logging infrastructure (dolog macro) with standard QEMU error reporting (error_report).

---
 audio/sndioaudio.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
audio/sndioaudio.c +10 -10
index 21f43836fd1..766eceeeefe 100644
@@ -18,12 +18,12 @@
 #include <poll.h>
 #include <sndio.h>
 #include "qemu/main-loop.h"
+#include "qemu/error-report.h"
 #include "qemu/audio.h"
-#include "trace.h"
 #include "qom/object.h"
 
-#define AUDIO_CAP "sndio"
 #include "audio_int.h"
+#include "trace.h"
 
 #define TYPE_AUDIO_SNDIO "audio-sndio"
 OBJECT_DECLARE_SIMPLE_TYPE(AudioSndio, AUDIO_SNDIO)
@@ -348,7 +348,7 @@ static int sndio_init(SndioVoice *self,
     /* open the device in non-blocking mode */
     self->hdl = sio_open(dev_name, mode, 1);
     if (self->hdl == NULL) {
-        dolog("failed to open device\n");
+        error_report("sndio: failed to open device");
         return -1;
     }
 
@@ -382,7 +382,7 @@ static int sndio_init(SndioVoice *self,
         req.sig = 0;
         break;
     default:
-        dolog("unknown audio sample format\n");
+        error_report("sndio: unknown audio sample format");
         return -1;
     }
 
@@ -401,12 +401,12 @@ static int sndio_init(SndioVoice *self,
     req.appbufsz = req.rate * latency / 1000000;
 
     if (!sio_setpar(self->hdl, &req)) {
-        dolog("failed set audio params\n");
+        error_report("sndio: failed to set audio params");
         goto fail;
     }
 
     if (!sio_getpar(self->hdl, &self->par)) {
-        dolog("failed get audio params\n");
+        error_report("sndio: failed to get audio params");
         goto fail;
     }
 
@@ -419,7 +419,7 @@ static int sndio_init(SndioVoice *self,
     if (self->par.bits != req.bits || self->par.bps != req.bits / 8 ||
         self->par.sig != req.sig || (req.bits > 8 && self->par.le != req.le) ||
         self->par.rate != as->freq || nch != as->nchannels) {
-        dolog("unsupported audio params\n");
+        error_report("sndio: unsupported audio params");
         goto fail;
     }
 
@@ -431,7 +431,7 @@ static int sndio_init(SndioVoice *self,
 
     self->buf = g_malloc(self->buf_size);
     if (self->buf == NULL) {
-        dolog("failed to allocate audio buffer\n");
+        error_report("sndio: failed to allocate audio buffer");
         goto fail;
     }
 
@@ -439,13 +439,13 @@ static int sndio_init(SndioVoice *self,
 
     self->pfds = g_malloc_n(nfds, sizeof(struct pollfd));
     if (self->pfds == NULL) {
-        dolog("failed to allocate pollfd structures\n");
+        error_report("sndio: failed to allocate pollfd structures");
         goto fail;
     }
 
     self->pindexes = g_malloc_n(nfds, sizeof(struct pollindex));
     if (self->pindexes == NULL) {
-        dolog("failed to allocate pollindex structures\n");
+        error_report("sndio: failed to allocate pollindex structures");
         goto fail;
     }
 
Signature · 1 line
2.53.0
#73 lore raw

PATCH 70/85 audio/spice: remove unused AUDIO_CAP macro

In reply to Marc-André Lureau

The AUDIO_CAP macro is no longer used.

---
 audio/spiceaudio.c | 1 -
 1 file changed, 1 deletion(-)
audio/spiceaudio.c +0 -1
index 0d188e974df..81b897e13e0 100644
@@ -26,7 +26,6 @@
 #include "ui/qemu-spice.h"
 #include "qom/object.h"
 
-#define AUDIO_CAP "spice"
 #include "qemu/audio.h"
 #include "audio_int.h"
 
Signature · 1 line
2.53.0
#74 lore raw

PATCH 71/85 audio/wav: replace custom logging with error_report

In reply to Marc-André Lureau

Replace the custom audio logging infrastructure (dolog macro) with standard QEMU error reporting (error_report).

---
 audio/wavaudio.c | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)
audio/wavaudio.c +13 -19
index ade8fd1d8c3..eed1e501af0 100644
@@ -24,10 +24,10 @@
 
 #include "qemu/osdep.h"
 #include "qemu/module.h"
+#include "qemu/error-report.h"
 #include "qemu/audio.h"
 #include "qom/object.h"
 
-#define AUDIO_CAP "wav"
 #include "audio_int.h"
 
 #define TYPE_AUDIO_WAV "audio-wav"
@@ -51,8 +51,8 @@ static size_t wav_write_out(HWVoiceOut *hw, void *buf, size_t len)
     assert(bytes % hw->info.bytes_per_frame == 0);
 
     if (bytes && fwrite(buf, bytes, 1, wav->f) != 1) {
-        dolog("wav_write_out: fwrite of %" PRId64 " bytes failed\nReason: %s\n",
-              bytes, strerror(errno));
+        error_report("wav: fwrite of %" PRId64 " bytes failed: %s",
+                     bytes, strerror(errno));
     }
 
     wav->total_samples += bytes / hw->info.bytes_per_frame;
@@ -98,11 +98,11 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as)
 
     case AUDIO_FORMAT_S32:
     case AUDIO_FORMAT_U32:
-        dolog ("WAVE files can not handle 32bit formats\n");
+        error_report("wav: WAVE files cannot handle 32-bit formats");
         return -1;
 
     case AUDIO_FORMAT_F32:
-        dolog("WAVE files can not handle float formats\n");
+        error_report("wav: WAVE files cannot handle float formats");
         return -1;
 
     default:
@@ -122,14 +122,13 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as)
 
     wav->f = fopen(wav_path, "wb");
     if (!wav->f) {
-        dolog ("Failed to open wave file `%s'\nReason: %s\n",
-               wav_path, strerror(errno));
+        error_report("wav: failed to open wave file '%s': %s",
+                     wav_path, strerror(errno));
         return -1;
     }
 
     if (fwrite (hdr, sizeof (hdr), 1, wav->f) != 1) {
-        dolog ("wav_init_out: failed to write header\nReason: %s\n",
-               strerror(errno));
+        error_report("wav: failed to write header: %s", strerror(errno));
         return -1;
     }
 
@@ -153,30 +152,25 @@ static void wav_fini_out (HWVoiceOut *hw)
     le_store (dlen, datalen, 4);
 
     if (fseek (wav->f, 4, SEEK_SET)) {
-        dolog ("wav_fini_out: fseek to rlen failed\nReason: %s\n",
-               strerror(errno));
+        error_report("wav: fseek to rlen failed: %s", strerror(errno));
         goto doclose;
     }
     if (fwrite (rlen, 4, 1, wav->f) != 1) {
-        dolog ("wav_fini_out: failed to write rlen\nReason: %s\n",
-               strerror (errno));
+        error_report("wav: failed to write rlen: %s", strerror(errno));
         goto doclose;
     }
     if (fseek (wav->f, 32, SEEK_CUR)) {
-        dolog ("wav_fini_out: fseek to dlen failed\nReason: %s\n",
-               strerror (errno));
+        error_report("wav: fseek to dlen failed: %s", strerror(errno));
         goto doclose;
     }
     if (fwrite (dlen, 4, 1, wav->f) != 1) {
-        dolog ("wav_fini_out: failed to write dlen\nReaons: %s\n",
-               strerror (errno));
+        error_report("wav: failed to write dlen: %s", strerror(errno));
         goto doclose;
     }
 
  doclose:
     if (fclose (wav->f))  {
-        dolog ("wav_fini_out: fclose %p failed\nReason: %s\n",
-               wav->f, strerror (errno));
+        error_report("wav: fclose failed: %s", strerror(errno));
     }
     wav->f = NULL;
 }
Signature · 1 line
2.53.0
#75 lore raw

PATCH 72/85 audio/mixeng: replace redundant pcm_info fields with AudioFormat

In reply to Marc-André Lureau

The audio_pcm_info structure stored three fields (bits, is_signed, is_float) that were always derived from the AudioFormat enum. This redundancy meant the same information was represented twice, with no type-level guarantee that they stayed in sync.

Replace these fields with a single AudioFormat field, and add helper functions to extract the derived properties when needed:
- audio_format_bits()
- audio_format_is_signed()
- audio_format_is_float()

This improves type safety by making AudioFormat the single source of truth, eliminating the possibility of inconsistent state between the format enum and its derived boolean/integer representations.

---
 audio/audio_int.h       |   4 +-
 audio/audio_template.h  |  12 +--
 include/qemu/audio.h    |  49 +++++++++++
 audio/audio-mixeng-be.c | 218 ++++++++++++++----------------------------------
 audio/dbusaudio.c       |  12 +--
 audio/coreaudio.m       |   2 +-
 6 files changed, 126 insertions(+), 171 deletions(-)
audio/audio_int.h +1 -3
index 5334c4baad2..dd5f2220d75 100644
@@ -45,9 +45,7 @@ struct audio_callback {
 };
 
 struct audio_pcm_info {
-    int bits;
-    bool is_signed;
-    bool is_float;
+    AudioFormat af;
     int freq;
     int nchannels;
     int bytes_per_frame;
audio/audio_template.h +6 -6
index 08d60422589..3da91a4782c 100644
@@ -173,7 +173,7 @@ static int glue (audio_pcm_sw_init_, TYPE) (
     sw->empty = true;
 #endif
 
-    if (sw->info.is_float) {
+    if (audio_format_is_float(hw->info.af)) {
 #ifdef DAC
         sw->conv = mixeng_conv_float[sw->info.nchannels == 2]
             [sw->info.swap_endianness];
@@ -188,9 +188,9 @@ static int glue (audio_pcm_sw_init_, TYPE) (
         sw->clip = mixeng_clip
 #endif
             [sw->info.nchannels == 2]
-            [sw->info.is_signed]
+            [audio_format_is_signed(hw->info.af)]
             [sw->info.swap_endianness]
-            [audio_bits_to_index(sw->info.bits)];
+            [audio_format_to_index(hw->info.af)];
     }
 
     sw->name = g_strdup (name);
@@ -300,7 +300,7 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioMixengBackend *s,
         goto err1;
     }
 
-    if (hw->info.is_float) {
+    if (audio_format_is_float(hw->info.af)) {
 #ifdef DAC
         hw->clip = mixeng_clip_float[hw->info.nchannels == 2]
             [hw->info.swap_endianness];
@@ -315,9 +315,9 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioMixengBackend *s,
         hw->conv = mixeng_conv
 #endif
             [hw->info.nchannels == 2]
-            [hw->info.is_signed]
+            [audio_format_is_signed(hw->info.af)]
             [hw->info.swap_endianness]
-            [audio_bits_to_index(hw->info.bits)];
+            [audio_format_to_index(hw->info.af)];
     }
 
     glue(audio_pcm_hw_alloc_resources_, TYPE)(hw);
include/qemu/audio.h +49 -0

55 lines not on this page · raw message

audio/audio-mixeng-be.c +63 -155

287 lines not on this page · raw message

audio/dbusaudio.c +6 -6
index 5f65c043c16..b212b3d6022 100644
@@ -147,9 +147,9 @@ dbus_init_out_listener(QemuDBusDisplay1AudioOutListener *listener,
     qemu_dbus_display1_audio_out_listener_call_init(
         listener,
         (uintptr_t)hw,
-        hw->info.bits,
-        hw->info.is_signed,
-        hw->info.is_float,
+        audio_format_bits(hw->info.af),
+        audio_format_is_signed(hw->info.af),
+        audio_format_is_float(hw->info.af),
         hw->info.freq,
         hw->info.nchannels,
         hw->info.bytes_per_frame,
@@ -273,9 +273,9 @@ dbus_init_in_listener(QemuDBusDisplay1AudioInListener *listener, HWVoiceIn *hw)
     qemu_dbus_display1_audio_in_listener_call_init(
         listener,
         (uintptr_t)hw,
-        hw->info.bits,
-        hw->info.is_signed,
-        hw->info.is_float,
+        audio_format_bits(hw->info.af),
+        audio_format_is_signed(hw->info.af),
+        audio_format_is_float(hw->info.af),
         hw->info.freq,
         hw->info.nchannels,
         hw->info.bytes_per_frame,
audio/coreaudio.m +1 -1
index 0c0e8583c89..1f4b3d9d467 100644
@@ -359,7 +359,7 @@ static OSStatus init_out_device(coreaudioVoiceOut *core)
     AudioValueRange frameRange;
 
     AudioStreamBasicDescription streamBasicDescription = {
-        .mBitsPerChannel = core->hw.info.bits,
+        .mBitsPerChannel = audio_format_bits(core->hw.info.af),
         .mBytesPerFrame = core->hw.info.bytes_per_frame,
         .mBytesPerPacket = core->hw.info.bytes_per_frame,
         .mChannelsPerFrame = core->hw.info.nchannels,
Signature · 1 line
2.53.0
#76 lore raw

PATCH 73/85 audio: replace int endianness with bool big_endian in audsettings

In reply to Marc-André Lureau

The endianness field used an int to represent a boolean concept, with 0 meaning little-endian and 1 meaning big-endian. This required runtime validation to reject invalid values and made the code less readable.

Replace with a bool big_endian field that is self-documenting and type-safe. The compiler now enforces valid values, eliminating the need for the validation check in audio_validate_settings().

---
 audio/dsound_template.h  |  2 +-
 include/qemu/audio.h     |  2 +-
 audio/alsaaudio.c        |  8 ++++----
 audio/audio-mixeng-be.c  | 21 ++++-----------------
 audio/jackaudio.c        |  4 ++--
 audio/ossaudio.c         | 22 +++++++++++-----------
 audio/paaudio.c          | 22 +++++++++++-----------
 audio/pwaudio.c          | 30 +++++++++++++++---------------
 audio/sdlaudio.c         | 26 +++++++++++++-------------
 audio/sndioaudio.c       |  2 +-
 audio/spiceaudio.c       |  4 ++--
 audio/wavaudio.c         |  2 +-
 audio/wavcapture.c       |  2 +-
 hw/audio/ac97.c          |  2 +-
 hw/audio/adlib.c         |  2 +-
 hw/audio/asc.c           |  2 +-
 hw/audio/cs4231a.c       |  6 +++---
 hw/audio/es1370.c        |  2 +-
 hw/audio/gus.c           |  2 +-
 hw/audio/lm4549.c        |  6 +++---
 hw/audio/sb16.c          |  8 ++++----
 hw/audio/via-ac97.c      |  2 +-
 hw/audio/virtio-snd.c    |  2 +-
 hw/audio/wm8750.c        |  4 ++--
 hw/display/xlnx_dp.c     |  2 +-
 hw/usb/dev-audio.c       |  2 +-
 tests/audio/test-audio.c |  2 +-
 ui/vnc.c                 |  2 +-
 28 files changed, 90 insertions(+), 103 deletions(-)
audio/dsound_template.h +1 -1
index af4019bcb34..f9761120875 100644
@@ -244,7 +244,7 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as)
     }
 
     ds->first_time = true;
-    obt_as.endianness = 0;
+    obt_as.big_endian = false;
     audio_pcm_init_info (&hw->info, &obt_as);
 
     if (bc.dwBufferBytes % hw->info.bytes_per_frame) {
include/qemu/audio.h +1 -1
index 9e4566d60aa..cff8a334f36 100644
@@ -38,7 +38,7 @@ typedef struct audsettings {
     int freq;
     int nchannels;
     AudioFormat fmt;
-    int endianness;
+    bool big_endian;
 } audsettings;
 
 typedef struct SWVoiceOut SWVoiceOut;
audio/alsaaudio.c +4 -4
index 889240ad0c7..e2290ea814a 100644
@@ -666,7 +666,7 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as)
     struct audsettings obt_as;
     Audiodev *dev = hw->s->dev;
 
-    req.fmt = aud_to_alsafmt (as->fmt, as->endianness);
+    req.fmt = aud_to_alsafmt (as->fmt, as->big_endian);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
 
@@ -677,7 +677,7 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as)
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.nchannels;
     obt_as.fmt = obt.fmt;
-    obt_as.endianness = obt.endianness;
+    obt_as.big_endian = obt.endianness;
 
     audio_pcm_init_info (&hw->info, &obt_as);
     hw->samples = obt.samples;
@@ -752,7 +752,7 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as)
     struct audsettings obt_as;
     Audiodev *dev = hw->s->dev;
 
-    req.fmt = aud_to_alsafmt (as->fmt, as->endianness);
+    req.fmt = aud_to_alsafmt (as->fmt, as->big_endian);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
 
@@ -763,7 +763,7 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as)
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.nchannels;
     obt_as.fmt = obt.fmt;
-    obt_as.endianness = obt.endianness;
+    obt_as.big_endian = obt.endianness;
 
     audio_pcm_init_info (&hw->info, &obt_as);
     hw->samples = obt.samples;
audio/audio-mixeng-be.c +4 -17
index 931d5b206f2..d05202aabae 100644
@@ -135,19 +135,7 @@ static void audio_print_settings (const struct audsettings *as)
         break;
     }
 
-    AUD_log (NULL, " endianness=");
-    switch (as->endianness) {
-    case 0:
-        AUD_log (NULL, "little");
-        break;
-    case 1:
-        AUD_log (NULL, "big");
-        break;
-    default:
-        AUD_log (NULL, "invalid");
-        break;
-    }
-    AUD_log (NULL, "\n");
+    AUD_log (NULL, " endianness=%s\n", as->big_endian ? "big" : "little");
 }
 
 static int audio_validate_settings (const struct audsettings *as)
@@ -155,7 +143,6 @@ static int audio_validate_settings (const struct audsettings *as)
     int invalid;
 
     invalid = as->nchannels < 1;
-    invalid |= as->endianness != 0 && as->endianness != 1;
 
     switch (as->fmt) {
     case AUDIO_FORMAT_S8:
@@ -180,7 +167,7 @@ static int audio_pcm_info_eq (struct audio_pcm_info *info, const struct audsetti
     return info->af == as->fmt
         && info->freq == as->freq
         && info->nchannels == as->nchannels
-        && info->swap_endianness == (as->endianness != HOST_BIG_ENDIAN);
+        && info->swap_endianness == (as->big_endian != HOST_BIG_ENDIAN);
 }
 
 void audio_pcm_init_info (struct audio_pcm_info *info, const struct audsettings *as)
@@ -190,7 +177,7 @@ void audio_pcm_init_info (struct audio_pcm_info *info, const struct audsettings
     info->nchannels = as->nchannels;
     info->bytes_per_frame = as->nchannels * audio_format_bits(as->fmt) / 8;
     info->bytes_per_second = info->freq * info->bytes_per_frame;
-    info->swap_endianness = (as->endianness != HOST_BIG_ENDIAN);
+    info->swap_endianness = (as->big_endian != HOST_BIG_ENDIAN);
 }
 
 void audio_pcm_info_clear_buf(struct audio_pcm_info *info, void *buf, int len)
@@ -1797,7 +1784,7 @@ audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo)
         .freq = pdo->frequency,
         .nchannels = pdo->channels,
         .fmt = pdo->format,
-        .endianness = HOST_BIG_ENDIAN,
+        .big_endian = HOST_BIG_ENDIAN,
     };
 }
 
audio/jackaudio.c +2 -2
index a2f725a3232..d9ae8edc0e0 100644
@@ -531,7 +531,7 @@ static int qjack_init_out(HWVoiceOut *hw, struct audsettings *as)
         .freq       = jo->c.freq,
         .nchannels  = jo->c.nchannels,
         .fmt        = AUDIO_FORMAT_F32,
-        .endianness = 0
+        .big_endian = false
     };
     audio_pcm_init_info(&hw->info, &os);
 
@@ -566,7 +566,7 @@ static int qjack_init_in(HWVoiceIn *hw, struct audsettings *as)
         .freq       = ji->c.freq,
         .nchannels  = ji->c.nchannels,
         .fmt        = AUDIO_FORMAT_F32,
-        .endianness = 0
+        .big_endian = false
     };
     audio_pcm_init_info(&hw->info, &is);
 
audio/ossaudio.c +11 -11
index 81f49f9a7e7..157979e84b4 100644
@@ -160,36 +160,36 @@ static int aud_to_ossfmt(AudioFormat fmt, bool big_endian)
     }
 }
 
-static int oss_to_audfmt (int ossfmt, AudioFormat *fmt, int *endianness)
+static int oss_to_audfmt (int ossfmt, AudioFormat *fmt, bool *big_endian)
 {
     switch (ossfmt) {
     case AFMT_S8:
-        *endianness = 0;
+        *big_endian = false;
         *fmt = AUDIO_FORMAT_S8;
         break;
 
     case AFMT_U8:
-        *endianness = 0;
+        *big_endian = false;
         *fmt = AUDIO_FORMAT_U8;
         break;
 
     case AFMT_S16_LE:
-        *endianness = 0;
+        *big_endian = false;
         *fmt = AUDIO_FORMAT_S16;
         break;
 
     case AFMT_U16_LE:
-        *endianness = 0;
+        *big_endian = false;
         *fmt = AUDIO_FORMAT_U16;
         break;
 
     case AFMT_S16_BE:
-        *endianness = 1;
+        *big_endian = true;
         *fmt = AUDIO_FORMAT_S16;
         break;
 
     case AFMT_U16_BE:
-        *endianness = 1;
+        *big_endian = true;
         *fmt = AUDIO_FORMAT_U16;
         break;
 
@@ -475,7 +475,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as)
 
     oss->fd = -1;
 
-    req.fmt = aud_to_ossfmt (as->fmt, as->endianness);
+    req.fmt = aud_to_ossfmt (as->fmt, as->big_endian);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
 
@@ -483,7 +483,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as)
         return -1;
     }
 
-    err = oss_to_audfmt(obt.fmt, &obt_as.fmt, &obt_as.endianness);
+    err = oss_to_audfmt(obt.fmt, &obt_as.fmt, &obt_as.big_endian);
     if (err) {
         oss_anal_close (&fd);
         return -1;
@@ -601,14 +601,14 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as)
 
     oss->fd = -1;
 
-    req.fmt = aud_to_ossfmt (as->fmt, as->endianness);
+    req.fmt = aud_to_ossfmt (as->fmt, as->big_endian);
     req.freq = as->freq;
     req.nchannels = as->nchannels;
     if (oss_open(1, &req, as, &obt, &fd, dev)) {
         return -1;
     }
 
-    err = oss_to_audfmt(obt.fmt, &obt_as.fmt, &obt_as.endianness);
+    err = oss_to_audfmt(obt.fmt, &obt_as.fmt, &obt_as.big_endian);
     if (err) {
         oss_anal_close (&fd);
         return -1;
audio/paaudio.c +11 -11
index 1501b26386a..c9957105543 100644
@@ -352,28 +352,28 @@ static pa_sample_format_t audfmt_to_pa(AudioFormat afmt, bool big_endian)
     return format;
 }
 
-static AudioFormat pa_to_audfmt (pa_sample_format_t fmt, int *endianness)
+static AudioFormat pa_to_audfmt (pa_sample_format_t fmt, bool *big_endian)
 {
     switch (fmt) {
     case PA_SAMPLE_U8:
         return AUDIO_FORMAT_U8;
     case PA_SAMPLE_S16BE:
-        *endianness = 1;
+        *big_endian = true;
         return AUDIO_FORMAT_S16;
     case PA_SAMPLE_S16LE:
-        *endianness = 0;
+        *big_endian = false;
         return AUDIO_FORMAT_S16;
     case PA_SAMPLE_S32BE:
-        *endianness = 1;
+        *big_endian = true;
         return AUDIO_FORMAT_S32;
     case PA_SAMPLE_S32LE:
-        *endianness = 0;
+        *big_endian = false;
         return AUDIO_FORMAT_S32;
     case PA_SAMPLE_FLOAT32BE:
-        *endianness = 1;
+        *big_endian = true;
         return AUDIO_FORMAT_F32;
     case PA_SAMPLE_FLOAT32LE:
-        *endianness = 0;
+        *big_endian = false;
         return AUDIO_FORMAT_F32;
     default:
         error_report("pulseaudio: Internal logic error: Bad pa_sample_format %d", fmt);
@@ -531,7 +531,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as)
     PAConnection *c = apa->conn;
 
     pa->g = apa;
-    ss.format = audfmt_to_pa (as->fmt, as->endianness);
+    ss.format = audfmt_to_pa (as->fmt, as->big_endian);
     ss.channels = as->nchannels;
     ss.rate = as->freq;
 
@@ -541,7 +541,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as)
     ba.maxlength = -1;
     ba.prebuf = -1;
 
-    obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
+    obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.big_endian);
 
     pa->stream = qpa_simple_new (
         c,
@@ -582,7 +582,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as)
     PAConnection *c = apa->conn;
 
     pa->g = apa;
-    ss.format = audfmt_to_pa (as->fmt, as->endianness);
+    ss.format = audfmt_to_pa (as->fmt, as->big_endian);
     ss.channels = as->nchannels;
     ss.rate = as->freq;
 
@@ -592,7 +592,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as)
     ba.minreq = -1;
     ba.prebuf = -1;
 
-    obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.endianness);
+    obt_as.fmt = pa_to_audfmt (ss.format, &obt_as.big_endian);
 
     pa->stream = qpa_simple_new (
         c,
audio/pwaudio.c +15 -15
index 6a80e5a333e..b70bf0c1353 100644
@@ -365,7 +365,7 @@ audfmt_to_pw(AudioFormat fmt, bool big_endian)
 }
 
 static AudioFormat
-pw_to_audfmt(enum spa_audio_format fmt, int *endianness,
+pw_to_audfmt(enum spa_audio_format fmt, bool *big_endian,
              uint32_t *sample_size)
 {
     switch (fmt) {
@@ -377,43 +377,43 @@ pw_to_audfmt(enum spa_audio_format fmt, int *endianness,
         return AUDIO_FORMAT_U8;
     case SPA_AUDIO_FORMAT_S16_BE:
         *sample_size = 2;
-        *endianness = 1;
+        *big_endian = true;
         return AUDIO_FORMAT_S16;
     case SPA_AUDIO_FORMAT_S16_LE:
         *sample_size = 2;
-        *endianness = 0;
+        *big_endian = false;
         return AUDIO_FORMAT_S16;
     case SPA_AUDIO_FORMAT_U16_BE:
         *sample_size = 2;
-        *endianness = 1;
+        *big_endian = true;
         return AUDIO_FORMAT_U16;
     case SPA_AUDIO_FORMAT_U16_LE:
         *sample_size = 2;
-        *endianness = 0;
+        *big_endian = false;
         return AUDIO_FORMAT_U16;
     case SPA_AUDIO_FORMAT_S32_BE:
         *sample_size = 4;
-        *endianness = 1;
+        *big_endian = true;
         return AUDIO_FORMAT_S32;
     case SPA_AUDIO_FORMAT_S32_LE:
         *sample_size = 4;
-        *endianness = 0;
+        *big_endian = false;
         return AUDIO_FORMAT_S32;
     case SPA_AUDIO_FORMAT_U32_BE:
         *sample_size = 4;
-        *endianness = 1;
+        *big_endian = true;
         return AUDIO_FORMAT_U32;
     case SPA_AUDIO_FORMAT_U32_LE:
         *sample_size = 4;
-        *endianness = 0;
+        *big_endian = false;
         return AUDIO_FORMAT_U32;
     case SPA_AUDIO_FORMAT_F32_BE:
         *sample_size = 4;
-        *endianness = 1;
+        *big_endian = true;
         return AUDIO_FORMAT_F32;
     case SPA_AUDIO_FORMAT_F32_LE:
         *sample_size = 4;
-        *endianness = 0;
+        *big_endian = false;
         return AUDIO_FORMAT_F32;
     default:
         *sample_size = 1;
@@ -534,13 +534,13 @@ qpw_init_out(HWVoiceOut *hw, struct audsettings *as)
 
     pw_thread_loop_lock(c->thread_loop);
 
-    v->info.format = audfmt_to_pw(as->fmt, as->endianness);
+    v->info.format = audfmt_to_pw(as->fmt, as->big_endian);
     v->info.channels = as->nchannels;
     qpw_set_position(as->nchannels, v->info.position);
     v->info.rate = as->freq;
 
     obt_as.fmt =
-        pw_to_audfmt(v->info.format, &obt_as.endianness, &v->frame_size);
+        pw_to_audfmt(v->info.format, &obt_as.big_endian, &v->frame_size);
     v->frame_size *= as->nchannels;
 
     v->req = (uint64_t)AUDIO_MIXENG_BACKEND(c)->dev->timer_period * v->info.rate
@@ -581,13 +581,13 @@ qpw_init_in(HWVoiceIn *hw, struct audsettings *as)
 
     pw_thread_loop_lock(c->thread_loop);
 
-    v->info.format = audfmt_to_pw(as->fmt, as->endianness);
+    v->info.format = audfmt_to_pw(as->fmt, as->big_endian);
     v->info.channels = as->nchannels;
     qpw_set_position(as->nchannels, v->info.position);
     v->info.rate = as->freq;
 
     obt_as.fmt =
-        pw_to_audfmt(v->info.format, &obt_as.endianness, &v->frame_size);
+        pw_to_audfmt(v->info.format, &obt_as.big_endian, &v->frame_size);
     v->frame_size *= as->nchannels;
 
     /* call the function that creates a new stream for recording */
audio/sdlaudio.c +13 -13
index 5f332678209..936a3ed076d 100644
@@ -96,56 +96,56 @@ static int aud_to_sdlfmt (AudioFormat fmt)
     }
 }
 
-static int sdl_to_audfmt(int sdlfmt, AudioFormat *fmt, int *endianness)
+static int sdl_to_audfmt(int sdlfmt, AudioFormat *fmt, bool *big_endian)
 {
     switch (sdlfmt) {
     case AUDIO_S8:
-        *endianness = 0;
+        *big_endian = false;
         *fmt = AUDIO_FORMAT_S8;
         break;
 
     case AUDIO_U8:
-        *endianness = 0;
+        *big_endian = false;
         *fmt = AUDIO_FORMAT_U8;
         break;
 
     case AUDIO_S16LSB:
-        *endianness = 0;
+        *big_endian = false;
         *fmt = AUDIO_FORMAT_S16;
         break;
 
     case AUDIO_U16LSB:
-        *endianness = 0;
+        *big_endian = false;
         *fmt = AUDIO_FORMAT_U16;
         break;
 
     case AUDIO_S16MSB:
-        *endianness = 1;
+        *big_endian = true;
         *fmt = AUDIO_FORMAT_S16;
         break;
 
     case AUDIO_U16MSB:
-        *endianness = 1;
+        *big_endian = true;
         *fmt = AUDIO_FORMAT_U16;
         break;
 
     case AUDIO_S32LSB:
-        *endianness = 0;
+        *big_endian = false;
         *fmt = AUDIO_FORMAT_S32;
         break;
 
     case AUDIO_S32MSB:
-        *endianness = 1;
+        *big_endian = true;
         *fmt = AUDIO_FORMAT_S32;
         break;
 
     case AUDIO_F32LSB:
-        *endianness = 0;
+        *big_endian = false;
         *fmt = AUDIO_FORMAT_F32;
         break;
 
     case AUDIO_F32MSB:
-        *endianness = 1;
+        *big_endian = true;
         *fmt = AUDIO_FORMAT_F32;
         break;
 
@@ -350,7 +350,7 @@ static int sdl_init_out(HWVoiceOut *hw, struct audsettings *as)
         return -1;
     }
 
-    err = sdl_to_audfmt(obt.format, &obt_as.fmt, &obt_as.endianness);
+    err = sdl_to_audfmt(obt.format, &obt_as.fmt, &obt_as.big_endian);
     if (err) {
         sdl_close_out(sdl);
         return -1;
@@ -406,7 +406,7 @@ static int sdl_init_in(HWVoiceIn *hw, audsettings *as)
         return -1;
     }
 
-    err = sdl_to_audfmt(obt.format, &obt_as.fmt, &obt_as.endianness);
+    err = sdl_to_audfmt(obt.format, &obt_as.fmt, &obt_as.big_endian);
     if (err) {
         sdl_close_in(sdl);
         return -1;
audio/sndioaudio.c +1 -1
index 766eceeeefe..761f23f8273 100644
@@ -387,7 +387,7 @@ static int sndio_init(SndioVoice *self,
     }
 
     if (req.bits > 8) {
-        req.le = as->endianness ? 0 : 1;
+        req.le = !as->big_endian;
     }
 
     req.rate = as->freq;
audio/spiceaudio.c +2 -2
index 81b897e13e0..f903ef77e72 100644
@@ -106,7 +106,7 @@ static int line_out_init(HWVoiceOut *hw, struct audsettings *as)
 #endif
     settings.nchannels  = SPICE_INTERFACE_PLAYBACK_CHAN;
     settings.fmt        = AUDIO_FORMAT_S16;
-    settings.endianness = HOST_BIG_ENDIAN;
+    settings.big_endian = HOST_BIG_ENDIAN;
 
     audio_pcm_init_info (&hw->info, &settings);
     hw->samples = LINE_OUT_SAMPLES;
@@ -222,7 +222,7 @@ static int line_in_init(HWVoiceIn *hw, struct audsettings *as)
 #endif
     settings.nchannels  = SPICE_INTERFACE_RECORD_CHAN;
     settings.fmt        = AUDIO_FORMAT_S16;
-    settings.endianness = HOST_BIG_ENDIAN;
+    settings.big_endian = HOST_BIG_ENDIAN;
 
     audio_pcm_init_info (&hw->info, &settings);
     hw->samples = LINE_IN_SAMPLES;
audio/wavaudio.c +1 -1
index eed1e501af0..55d12d6cdfd 100644
@@ -111,7 +111,7 @@ static int wav_init_out(HWVoiceOut *hw, struct audsettings *as)
 
     hdr[34] = bits16 ? 0x10 : 0x08;
 
-    wav_as.endianness = 0;
+    wav_as.big_endian = false;
     audio_pcm_init_info (&hw->info, &wav_as);
 
     hw->samples = 1024;
audio/wavcapture.c +1 -1
index 69aa91e35f6..2dac9461710 100644
@@ -137,7 +137,7 @@ int wav_start_capture(AudioBackend *state, CaptureState *s, const char *path,
     as.freq = freq;
     as.nchannels = 1 << stereo;
     as.fmt = bits16 ? AUDIO_FORMAT_S16 : AUDIO_FORMAT_U8;
-    as.endianness = 0;
+    as.big_endian = false;
 
     ops.notify = wav_notify;
     ops.capture = wav_capture;
hw/audio/ac97.c +1 -1
index 5d442b7e067..fd74c249949 100644
@@ -313,7 +313,7 @@ static void open_voice(AC97LinkState *s, int index, int freq)
     as.freq = freq;
     as.nchannels = 2;
     as.fmt = AUDIO_FORMAT_S16;
-    as.endianness = 0;
+    as.big_endian = false;
 
     if (freq > 0) {
         s->invalid_freq[index] = 0;
hw/audio/adlib.c +1 -1
index ce17e21d5fd..52ee5cb6256 100644
@@ -254,7 +254,7 @@ static void adlib_realizefn (DeviceState *dev, Error **errp)
     as.freq = s->freq;
     as.nchannels = SHIFT;
     as.fmt = AUDIO_FORMAT_S16;
-    as.endianness = HOST_BIG_ENDIAN;
+    as.big_endian = HOST_BIG_ENDIAN;
 
     s->voice = audio_be_open_out(
         s->audio_be,
hw/audio/asc.c +1 -1
index 35c7b5750d6..ea59bdde7b8 100644
@@ -648,7 +648,7 @@ static void asc_realize(DeviceState *dev, Error **errp)
     as.freq = ASC_FREQ;
     as.nchannels = 2;
     as.fmt = AUDIO_FORMAT_U8;
-    as.endianness = HOST_BIG_ENDIAN;
+    as.big_endian = HOST_BIG_ENDIAN;
 
     s->voice = audio_be_open_out(s->audio_be, s->voice, "asc.out", s, asc_out_cb,
                             &as);
hw/audio/cs4231a.c +3 -3
index e6cae9c988e..c589670e855 100644
@@ -289,7 +289,7 @@ static void cs_reset_voices (CSState *s, uint32_t val)
     }
 
     as.nchannels = (val & (1 << 4)) ? 2 : 1;
-    as.endianness = 0;
+    as.big_endian = false;
     s->tab = NULL;
 
     switch ((val >> 5) & ((s->dregs[MODE_And_ID] & MODE2) ? 7 : 3)) {
@@ -305,12 +305,12 @@ static void cs_reset_voices (CSState *s, uint32_t val)
         s->tab = ALawDecompressTable;
     x_law:
         as.fmt = AUDIO_FORMAT_S16;
-        as.endianness = HOST_BIG_ENDIAN;
+        as.big_endian = HOST_BIG_ENDIAN;
         s->shift = as.nchannels == 2;
         break;
 
     case 6:
-        as.endianness = 1;
+        as.big_endian = true;
         /* fall through */
     case 2:
         as.fmt = AUDIO_FORMAT_S16;
hw/audio/es1370.c +1 -1
index e1658393c6a..ca7ad16df49 100644
@@ -407,7 +407,7 @@ static void es1370_update_voices (ES1370State *s, uint32_t ctl, uint32_t sctl)
                 as.freq = new_freq;
                 as.nchannels = 1 << (new_fmt & 1);
                 as.fmt = (new_fmt & 2) ? AUDIO_FORMAT_S16 : AUDIO_FORMAT_U8;
-                as.endianness = 0;
+                as.big_endian = false;
 
                 if (i == ADC_CHANNEL) {
                     s->adc_voice =
hw/audio/gus.c +1 -1
index 5c2a34c09d2..196c4f72205 100644
@@ -256,7 +256,7 @@ static void gus_realizefn (DeviceState *dev, Error **errp)
     as.freq = s->freq;
     as.nchannels = 2;
     as.fmt = AUDIO_FORMAT_S16;
-    as.endianness = HOST_BIG_ENDIAN;
+    as.big_endian = HOST_BIG_ENDIAN;
 
     s->voice = audio_be_open_out(
         s->audio_be,
hw/audio/lm4549.c +3 -3
index 14e15a844ba..a891e975106 100644
@@ -202,7 +202,7 @@ void lm4549_write(lm4549_state *s,
         as.freq = value;
         as.nchannels = 2;
         as.fmt = AUDIO_FORMAT_S16;
-        as.endianness = 0;
+        as.big_endian = false;
 
         s->voice = audio_be_open_out(
             s->audio_be,
@@ -272,7 +272,7 @@ static int lm4549_post_load(void *opaque, int version_id)
     as.freq = freq;
     as.nchannels = 2;
     as.fmt = AUDIO_FORMAT_S16;
-    as.endianness = 0;
+    as.big_endian = false;
 
     s->voice = audio_be_open_out(
         s->audio_be,
@@ -312,7 +312,7 @@ void lm4549_init(lm4549_state *s, lm4549_callback data_req_cb, void* opaque,
     as.freq = 48000;
     as.nchannels = 2;
     as.fmt = AUDIO_FORMAT_S16;
-    as.endianness = 0;
+    as.big_endian = false;
 
     s->voice = audio_be_open_out(
         s->audio_be,
hw/audio/sb16.c +4 -4
index c8fc7df8b44..1b5e452a29b 100644
@@ -213,7 +213,7 @@ static void continue_dma8 (SB16State *s)
         as.freq = s->freq;
         as.nchannels = 1 << s->fmt_stereo;
         as.fmt = s->fmt;
-        as.endianness = 0;
+        as.big_endian = false;
 
         s->voice = audio_be_open_out(
             s->audio_be,
@@ -376,7 +376,7 @@ static void dma_cmd (SB16State *s, uint8_t cmd, uint8_t d0, int dma_len)
         as.freq = s->freq;
         as.nchannels = 1 << s->fmt_stereo;
         as.fmt = s->fmt;
-        as.endianness = 0;
+        as.big_endian = false;
 
         s->voice = audio_be_open_out(
             s->audio_be,
@@ -877,7 +877,7 @@ static void legacy_reset (SB16State *s)
     as.freq = s->freq;
     as.nchannels = 1;
     as.fmt = AUDIO_FORMAT_U8;
-    as.endianness = 0;
+    as.big_endian = false;
 
     s->voice = audio_be_open_out(
         s->audio_be,
@@ -1300,7 +1300,7 @@ static int sb16_post_load (void *opaque, int version_id)
             as.freq = s->freq;
             as.nchannels = 1 << s->fmt_stereo;
             as.fmt = s->fmt;
-            as.endianness = 0;
+            as.big_endian = false;
 
             s->voice = audio_be_open_out(
                 s->audio_be,
hw/audio/via-ac97.c +1 -1
index 84d137b41a3..9d61283542a 100644
@@ -237,7 +237,7 @@ static void open_voice_out(ViaAC97State *s)
         .freq = CODEC_REG(s, AC97_PCM_Front_DAC_Rate),
         .nchannels = s->aur.type & BIT(4) ? 2 : 1,
         .fmt = s->aur.type & BIT(5) ? AUDIO_FORMAT_S16 : AUDIO_FORMAT_S8,
-        .endianness = 0,
+        .big_endian = false,
     };
     s->vo = audio_be_open_out(s->audio_be, s->vo, "via-ac97.out", s, out_cb, &as);
 }
hw/audio/virtio-snd.c +1 -1
index 89e24c0a8e0..8b949146468 100644
@@ -378,7 +378,7 @@ static void virtio_snd_get_qemu_audsettings(audsettings *as,
     as->nchannels = MIN(AUDIO_MAX_CHANNELS, params->channels);
     as->fmt = virtio_snd_get_qemu_format(params->format);
     as->freq = virtio_snd_get_qemu_freq(params->rate);
-    as->endianness = 0; /* Conforming to VIRTIO 1.0: always little endian. */
+    as->big_endian = false; /* Conforming to VIRTIO 1.0: always little endian. */
 }
 
 /*
hw/audio/wm8750.c +2 -2
index 2a286515b14..e2507b0269a 100644
@@ -202,7 +202,7 @@ static void wm8750_set_format(WM8750State *s)
         return;
 
     /* Setup input */
-    in_fmt.endianness = 0;
+    in_fmt.big_endian = false;
     in_fmt.nchannels = 2;
     in_fmt.freq = s->adc_hz;
     in_fmt.fmt = AUDIO_FORMAT_S16;
@@ -215,7 +215,7 @@ static void wm8750_set_format(WM8750State *s)
                     CODEC ".input3", s, wm8750_audio_in_cb, &in_fmt);
 
     /* Setup output */
-    out_fmt.endianness = 0;
+    out_fmt.big_endian = false;
     out_fmt.nchannels = 2;
     out_fmt.freq = s->dac_hz;
     out_fmt.fmt = AUDIO_FORMAT_S16;
hw/display/xlnx_dp.c +1 -1
index 9aa4709b411..7d037b46a35 100644
@@ -1393,7 +1393,7 @@ static void xlnx_dp_realize(DeviceState *dev, Error **errp)
     as.freq = 44100;
     as.nchannels = 2;
     as.fmt = AUDIO_FORMAT_S16;
-    as.endianness = 0;
+    as.big_endian = false;
 
     s->amixer_output_stream = audio_be_open_out(s->audio_be,
                                            s->amixer_output_stream,
hw/usb/dev-audio.c +1 -1
index 7b758718c12..e18e0a1dfd6 100644
@@ -975,7 +975,7 @@ static void usb_audio_reinit(USBDevice *dev, unsigned channels)
     s->out.as.freq       = USBAUDIO_SAMPLE_RATE;
     s->out.as.nchannels  = s->out.channels;
     s->out.as.fmt        = AUDIO_FORMAT_S16;
-    s->out.as.endianness = 0;
+    s->out.as.big_endian = false;
     streambuf_init(&s->out.buf, s->buffer, s->out.channels);
 
     s->out.voice = audio_be_open_out(s->audio_be, s->out.voice, TYPE_USB_AUDIO,
tests/audio/test-audio.c +1 -1
index 90d96ae0575..b87a12eb55b 100644
@@ -57,7 +57,7 @@ static const struct audsettings default_test_settings = {
     .freq = SAMPLE_RATE,
     .nchannels = CHANNELS,
     .fmt = AUDIO_FORMAT_S16,
-    .endianness = 0,
+    .big_endian = false,
 };
 
 static void dummy_audio_callback(void *opaque, int avail)
ui/vnc.c +1 -1
index d56fe2c180e..daf5b01d342 100644
@@ -3372,7 +3372,7 @@ static void vnc_connect(VncDisplay *vd, QIOChannelSocket *sioc,
     vs->as.freq = 44100;
     vs->as.nchannels = 2;
     vs->as.fmt = AUDIO_FORMAT_S16;
-    vs->as.endianness = 0;
+    vs->as.big_endian = false;
 
     qemu_mutex_init(&vs->output_mutex);
     vs->bh = qemu_bh_new(vnc_jobs_bh, vs);
Signature · 1 line
2.53.0
#77 lore raw

PATCH 74/85 audio: replace ldebug with trace events

In reply to Marc-André Lureau

Replace the ldebug macro calls with proper trace events:
- audio_get_avail: traces available samples in capture stream
- audio_open_out/audio_open_in: traces stream open parameters

This provides structured tracing that can be enabled at runtime without requiring debug builds.

---
 audio/audio_template.h  | 7 +++++--
 audio/audio-mixeng-be.c | 6 +-----
 audio/trace-events      | 7 +++++++
 3 files changed, 13 insertions(+), 7 deletions(-)
audio/audio_template.h +5 -2
index 3da91a4782c..c47a2f202f0 100644
@@ -507,8 +507,11 @@ static SW *glue(audio_mixeng_backend_open_, TYPE) (
     k = AUDIO_MIXENG_BACKEND_GET_CLASS(s);
     pdo = glue(audio_get_pdo_, TYPE)(s->dev);
 
-    ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
-            name, as->freq, as->nchannels, as->fmt);
+#ifdef DAC
+    trace_audio_open_out(name, as->freq, as->nchannels, as->fmt);
+#else
+    trace_audio_open_in(name, as->freq, as->nchannels, as->fmt);
+#endif
 
     if (audio_bug(__func__, audio_validate_settings(as))) {
         audio_print_settings (as);
audio/audio-mixeng-be.c +1 -5
index d05202aabae..84e4d136de3 100644
@@ -881,11 +881,7 @@ static size_t audio_get_avail(SWVoiceIn *sw)
         return 0;
     }
 
-    ldebug (
-        "%s: get_avail live %zu frontend frames %u\n",
-        SW_NAME (sw),
-        live, st_rate_frames_out(sw->rate, live)
-        );
+    trace_audio_get_avail(SW_NAME(sw), live, st_rate_frames_out(sw->rate, live));
 
     return live;
 }
audio/trace-events +7 -0
index f33be2dd8e3..4749c54fc04 100644
@@ -58,3 +58,10 @@ audio_be_set_active_out(void *sw, bool on) "sw=%p, on=%d"
 audio_timer_start(int interval) "interval %d ms"
 audio_timer_stop(void) ""
 audio_timer_delayed(int interval) "interval %d ms"
+
+# audio-mixeng-be.c
+audio_get_avail(const char *name, size_t live, uint32_t frontend_frames) "%s: get_avail live %zu frontend frames %u"
+
+# audio_template.h
+audio_open_out(const char *name, int freq, int nchannels, int fmt) "open %s, freq %d, nchannels %d, fmt %d"
+audio_open_in(const char *name, int freq, int nchannels, int fmt) "open %s, freq %d, nchannels %d, fmt %d"
Signature · 1 line
2.53.0
#78 lore raw

PATCH 75/85 audio: rework DEBUG_POLL

In reply to Marc-André Lureau

Use more correct GTimer, specific for each backend, with a trace event.

---
 audio/audio_int.h       |  1 +
 include/qemu/timer.h    |  1 +
 audio/audio-mixeng-be.c | 25 +++++++++----------------
 audio/trace-events      |  1 +
 4 files changed, 12 insertions(+), 16 deletions(-)
audio/audio_int.h +1 -0
index dd5f2220d75..e0ed6af67ed 100644
@@ -224,6 +224,7 @@ struct AudioMixengBackend {
     Audiodev *dev;
 
     QEMUTimer *ts;
+    GTimer *run_timer;
     QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
     QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
     QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
include/qemu/timer.h +1 -0
index 7c18da16525..b931181f53d 100644
@@ -6,6 +6,7 @@
 #include "qemu/host-utils.h"
 
 #define NANOSECONDS_PER_SECOND 1000000000LL
+#define MICROSECONDS_PER_SECOND 1000000LL
 
 /* timers */
 
audio/audio-mixeng-be.c +9 -16
index 84e4d136de3..2aeb05ba37e 100644
@@ -24,13 +24,13 @@
 #include "system/replay.h"
 #include "system/runstate.h"
 #include "trace.h"
+#include "trace/control.h"
 
 #define AUDIO_CAP "audio"
 #include "audio_int.h"
 
 /* #define DEBUG_OUT */
 /* #define DEBUG_CAPTURE */
-/* #define DEBUG_POLL */
 
 #define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"
 
@@ -1269,22 +1269,12 @@ void audio_run(AudioMixengBackend *s, const char *msg)
     audio_run_in(s);
     audio_run_capture(s);
 
-#ifdef DEBUG_POLL
-    {
-        static double prevtime;
-        double currtime;
-        struct timeval tv;
-
-        if (gettimeofday (&tv, NULL)) {
-            perror ("audio_run: gettimeofday");
-            return;
-        }
-
-        currtime = tv.tv_sec + tv.tv_usec * 1e-6;
-        dolog ("Elapsed since last %s: %f\n", msg, currtime - prevtime);
-        prevtime = currtime;
+    if (trace_event_get_state(TRACE_AUDIO_RUN_POLL)) {
+        /* Convert seconds to microseconds for trace event */
+        int64_t elapsed_us = g_timer_elapsed(s->run_timer, NULL) * MICROSECONDS_PER_SECOND;
+        trace_audio_run_poll(msg, elapsed_us);
+        g_timer_start(s->run_timer);
     }
-#endif
 }
 
 void audio_generic_run_buffer_in(HWVoiceIn *hw)
@@ -1545,6 +1535,7 @@ static void audio_mixeng_backend_init(Object *obj)
     QLIST_INIT(&s->hw_head_in);
     QLIST_INIT(&s->cap_head);
     s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
+    s->run_timer = g_timer_new();
 
     s->vmse = qemu_add_vm_change_state_handler(audio_vm_change_state_handler, s);
     assert(s->vmse != NULL);
@@ -1596,6 +1587,8 @@ static void audio_mixeng_backend_finalize(Object *obj)
         s->ts = NULL;
     }
 
+    g_clear_pointer(&s->run_timer, g_timer_destroy);
+
     if (s->vmse) {
         qemu_del_vm_change_state_handler(s->vmse);
         s->vmse = NULL;
audio/trace-events +1 -0
index 4749c54fc04..d66a712e871 100644
@@ -61,6 +61,7 @@ audio_timer_delayed(int interval) "interval %d ms"
 
 # audio-mixeng-be.c
 audio_get_avail(const char *name, size_t live, uint32_t frontend_frames) "%s: get_avail live %zu frontend frames %u"
+audio_run_poll(const char *msg, int64_t elapsed_us) "Elapsed since last %s: %" PRId64 " us"
 
 # audio_template.h
 audio_open_out(const char *name, int freq, int nchannels, int fmt) "open %s, freq %d, nchannels %d, fmt %d"
Signature · 1 line
2.53.0
#79 lore raw

PATCH 76/85 audio: replace DEBUG_CAPTURE with traces

In reply to Marc-André Lureau
---
 audio/audio-mixeng-be.c | 20 +++++++-------------
 audio/trace-events      |  3 +++
 2 files changed, 10 insertions(+), 13 deletions(-)
audio/audio-mixeng-be.c +7 -13
index 2aeb05ba37e..1963f3e5c79 100644
@@ -30,7 +30,6 @@
 #include "audio_int.h"
 
 /* #define DEBUG_OUT */
-/* #define DEBUG_CAPTURE */
 
 #define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"
 
@@ -249,9 +248,8 @@ static void audio_notify_capture (CaptureVoiceOut *cap, audcnotification_e cmd)
 {
     struct capture_callback *cb;
 
-#ifdef DEBUG_CAPTURE
-    dolog ("notification %d sent\n", cmd);
-#endif
+    trace_audio_notify_capture(cmd);
+
     for (cb = cap->cb_head.lh_first; cb; cb = cb->entries.le_next) {
         cb->ops.notify (cb->opaque, cmd);
     }
@@ -333,12 +331,10 @@ static int audio_attach_capture (HWVoiceOut *hw)
         sw->rate = st_rate_start (sw->info.freq, hw_cap->info.freq);
         QLIST_INSERT_HEAD (&hw_cap->sw_head, sw, entries);
         QLIST_INSERT_HEAD (&hw->cap_head, sc, entries);
-#ifdef DEBUG_CAPTURE
-        sw->name = g_strdup_printf ("for %p %d,%d,%d",
-                                    hw, sw->info.freq, sw->info.bits,
-                                    sw->info.nchannels);
-        dolog ("Added %s active = %d\n", sw->name, sw->active);
-#endif
+        sw->name = g_strdup_printf("for %p %d,%s,%d",
+                                   hw, sw->info.freq, AudioFormat_str(sw->info.af),
+                                   sw->info.nchannels);
+        trace_audio_capture_attach(sw->name, sw->active);
         if (sw->active) {
             audio_capture_maybe_changed (cap, 1);
         }
@@ -1707,10 +1703,8 @@ static void audio_mixeng_backend_del_capture(
 
                 while (sw) {
                     SWVoiceCap *sc = (SWVoiceCap *) sw;
-#ifdef DEBUG_CAPTURE
-                    dolog ("freeing %s\n", sw->name);
-#endif
 
+                    trace_audio_capture_free_sw(sw->name);
                     sw1 = sw->entries.le_next;
                     if (sw->rate) {
                         st_rate_stop (sw->rate);
audio/trace-events +3 -0
index d66a712e871..3f8ebf9c6cb 100644
@@ -58,10 +58,13 @@ audio_be_set_active_out(void *sw, bool on) "sw=%p, on=%d"
 audio_timer_start(int interval) "interval %d ms"
 audio_timer_stop(void) ""
 audio_timer_delayed(int interval) "interval %d ms"
+audio_notify_capture(int cmd) "notification %d sent"
+audio_capture_attach(const char *name, bool active) "capture %s active=%d"
 
 # audio-mixeng-be.c
 audio_get_avail(const char *name, size_t live, uint32_t frontend_frames) "%s: get_avail live %zu frontend frames %u"
 audio_run_poll(const char *msg, int64_t elapsed_us) "Elapsed since last %s: %" PRId64 " us"
+audio_capture_free_sw(const char *name) "freeing %s"
 
 # audio_template.h
 audio_open_out(const char *name, int freq, int nchannels, int fmt) "open %s, freq %d, nchannels %d, fmt %d"
Signature · 1 line
2.53.0
#80 lore raw

PATCH 77/85 audio: replace DEBUG_OUT with traces

In reply to Marc-André Lureau
---
 audio/audio-mixeng-be.c | 32 ++++++++------------------------
 audio/trace-events      |  5 +++++
 2 files changed, 13 insertions(+), 24 deletions(-)
audio/audio-mixeng-be.c +8 -24
index 1963f3e5c79..3dd9d17dd25 100644
@@ -29,8 +29,6 @@
 #define AUDIO_CAP "audio"
 #include "audio_int.h"
 
-/* #define DEBUG_OUT */
-
 #define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"
 
 const struct mixeng_volume nominal_volume = {
@@ -568,9 +566,7 @@ static size_t audio_pcm_sw_write(SWVoiceOut *sw, void *buf, size_t buf_len)
     }
 
     if (live == hw->mix_buf.size) {
-#ifdef DEBUG_OUT
-        dolog ("%s is full %zu\n", sw->name, live);
-#endif
+        trace_audio_out_full(sw->name, live);
         return 0;
     }
 
@@ -618,15 +614,8 @@ static size_t audio_pcm_sw_write(SWVoiceOut *sw, void *buf, size_t buf_len)
         sw->resample_buf.pos = 0;
     }
 
-#ifdef DEBUG_OUT
-    dolog (
-        "%s: write size %zu written %zu total mixed %zu\n",
-        SW_NAME(sw),
-        buf_len / sw->info.bytes_per_frame,
-        total_in,
-        sw->total_hw_samples_mixed
-        );
-#endif
+    trace_audio_sw_write(SW_NAME(sw), buf_len / sw->info.bytes_per_frame,
+                         total_in, sw->total_hw_samples_mixed);
 
     return total_in * sw->info.bytes_per_frame;
 }
@@ -900,10 +889,8 @@ static size_t audio_get_free(SWVoiceOut *sw)
 
     dead = sw->hw->mix_buf.size - live;
 
-#ifdef DEBUG_OUT
-    dolog("%s: get_free live %zu dead %zu frontend frames %u\n",
-          SW_NAME(sw), live, dead, st_rate_frames_in(sw->rate, dead));
-#endif
+    trace_audio_get_free(SW_NAME(sw), live, dead,
+                         st_rate_frames_in(sw->rate, dead));
 
     return dead;
 }
@@ -1058,9 +1045,8 @@ static void audio_run_out(AudioMixengBackend *s)
 
         if (hw->pending_disable && !nb_live) {
             SWVoiceCap *sc;
-#ifdef DEBUG_OUT
-            dolog ("Disabling voice\n");
-#endif
+
+            trace_audio_out_disable();
             hw->enabled = false;
             hw->pending_disable = false;
             if (k->enable_out) {
@@ -1089,9 +1075,7 @@ static void audio_run_out(AudioMixengBackend *s)
             hw->mix_buf.pos = 0;
         }
 
-#ifdef DEBUG_OUT
-        dolog("played=%zu\n", played);
-#endif
+        trace_audio_out_played(played);
 
         if (played) {
             audio_capture_mix_and_clear (hw, prev_rpos, played);
audio/trace-events +5 -0
index 3f8ebf9c6cb..7a73d6eb84f 100644
@@ -65,6 +65,11 @@ audio_capture_attach(const char *name, bool active) "capture %s active=%d"
 audio_get_avail(const char *name, size_t live, uint32_t frontend_frames) "%s: get_avail live %zu frontend frames %u"
 audio_run_poll(const char *msg, int64_t elapsed_us) "Elapsed since last %s: %" PRId64 " us"
 audio_capture_free_sw(const char *name) "freeing %s"
+audio_out_full(const char *name, size_t live) "%s is full %zu"
+audio_sw_write(const char *name, size_t size, size_t written, size_t total_mixed) "%s: write size %zu written %zu total mixed %zu"
+audio_get_free(const char *name, size_t live, size_t dead, uint32_t frontend_frames) "%s: get_free live %zu dead %zu frontend frames %u"
+audio_out_disable(void) "Disabling voice"
+audio_out_played(size_t played) "played=%zu"
 
 # audio_template.h
 audio_open_out(const char *name, int freq, int nchannels, int fmt) "open %s, freq %d, nchannels %d, fmt %d"
Signature · 1 line
2.53.0
#81 lore raw

PATCH 78/85 audio: replace DEBUG_AUDIO with trace

In reply to Marc-André Lureau
---
 audio/audio_template.h  | 10 +++++-----
 audio/audio-mixeng-be.c |  9 ---------
 audio/trace-events      |  1 +
 3 files changed, 6 insertions(+), 14 deletions(-)
audio/audio_template.h +5 -5
index c47a2f202f0..e884c8e9b1a 100644
@@ -556,11 +556,11 @@ static SW *glue(audio_mixeng_backend_open_, TYPE) (
     sw->callback.fn = callback_fn;
     sw->callback.opaque = callback_opaque;
 
-#ifdef DEBUG_AUDIO
-    dolog ("%s\n", name);
-    audio_pcm_print_info ("hw", &sw->hw->info);
-    audio_pcm_print_info ("sw", &sw->info);
-#endif
+    trace_audio_voice_pair(G_STRINGIFY(TYPE), name,
+                           AudioFormat_str(sw->hw->info.af),
+                           sw->hw->info.freq, sw->hw->info.nchannels,
+                           AudioFormat_str(sw->info.af),
+                           sw->info.freq, sw->info.nchannels);
 
     return sw;
 
audio/audio-mixeng-be.c +0 -9
index 3dd9d17dd25..7eabb1c2505 100644
@@ -620,15 +620,6 @@ static size_t audio_pcm_sw_write(SWVoiceOut *sw, void *buf, size_t buf_len)
     return total_in * sw->info.bytes_per_frame;
 }
 
-#ifdef DEBUG_AUDIO
-static void audio_pcm_print_info (const char *cap, struct audio_pcm_info *info)
-{
-    dolog("%s: %s, freq %d, nchan %d\n",
-          cap, AudioFormat_str(info->af), info->freq,
-          info->nchannels);
-}
-#endif
-
 #define DAC
 #include "audio_template.h"
 #undef DAC
audio/trace-events +1 -0
index 7a73d6eb84f..ed04792d508 100644
@@ -74,3 +74,4 @@ audio_out_played(size_t played) "played=%zu"
 # audio_template.h
 audio_open_out(const char *name, int freq, int nchannels, int fmt) "open %s, freq %d, nchannels %d, fmt %d"
 audio_open_in(const char *name, int freq, int nchannels, int fmt) "open %s, freq %d, nchannels %d, fmt %d"
+audio_voice_pair(const char *type, const char *name, const char *hw_fmt, int hw_freq, int hw_nchannels, const char *sw_fmt, int sw_freq, int sw_nchannels) "%s: name=%s hw=%s/%d/%d sw=%s/%d/%d"
Signature · 1 line
2.53.0
#82 lore raw

PATCH 79/85 tests/audio: add an invalid settings test

In reply to Marc-André Lureau

As we are going to change the related code next.

---
 tests/audio/test-audio.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
tests/audio/test-audio.c +21 -0
index b87a12eb55b..af8cf03d10e 100644
@@ -534,6 +534,26 @@ static void test_audio_multiple_voices(void)
     audio_be_close_out(be, out1);
 }
 
+static const struct audsettings invalid_test_settings = {
+    .nchannels = 0,
+    .freq = SAMPLE_RATE,
+    .fmt = AUDIO_FORMAT_S16,
+    .big_endian = false,
+};
+
+static void test_audio_invalid_settings(void)
+{
+    AudioBackend *be = get_test_audio_backend();
+    void *voice;
+
+    voice = audio_be_open_out(be, NULL, "invalid", NULL,
+                              dummy_audio_callback, &invalid_test_settings);
+    g_assert_null(voice);
+    voice = audio_be_open_in(be, NULL, "invalid", NULL,
+                             dummy_audio_callback, &invalid_test_settings);
+    g_assert_null(voice);
+}
+
 int main(int argc, char **argv)
 {
     GOptionContext *context;
@@ -589,6 +609,7 @@ int main(int argc, char **argv)
 
     g_test_add_func("/audio/null-handling", test_audio_null_handling);
     g_test_add_func("/audio/multiple-voices", test_audio_multiple_voices);
+    g_test_add_func("/audio/invalid-settings", test_audio_invalid_settings);
 
     ret = g_test_run();
 
Signature · 1 line
2.53.0
#83 lore raw

PATCH 80/85 audio: rework invalid audsettings error

In reply to Marc-André Lureau

Currently, when given invalid settings, QEMU will print to stderr:

A bug was just triggered in audio_mixeng_backend_open_out Save all your work and restart without audio
I am sorry
Context:
audio: frequency=44100 nchannels=0 fmt=S16 endianness=little

Now it will use error_report() and simply report:
audio: Invalid audio settings: frequency=44100 nchannels=0 fmt=s16 endian=little

---
 audio/audio_template.h  |  5 +++--
 audio/audio-mixeng-be.c | 41 +++++++----------------------------------
 2 files changed, 10 insertions(+), 36 deletions(-)
audio/audio_template.h +3 -2
index e884c8e9b1a..5711f4a26e1 100644
@@ -513,8 +513,9 @@ static SW *glue(audio_mixeng_backend_open_, TYPE) (
     trace_audio_open_in(name, as->freq, as->nchannels, as->fmt);
 #endif
 
-    if (audio_bug(__func__, audio_validate_settings(as))) {
-        audio_print_settings (as);
+    if (audio_validate_settings(as)) {
+        g_autofree char *str = audsettings_to_string(as);
+        error_report("audio: Invalid audio settings: %s", str);
         goto fail;
     }
 
audio/audio-mixeng-be.c +7 -34

54 lines not on this page · raw message

Signature · 1 line
2.53.0
#84 lore raw

PATCH 81/85 audio: rework audio_bug()

In reply to Marc-André Lureau

audio_bug() is a bit unconventional, it is meant to be used as a condition expression, passing the actual condition as second argument (and __func__ as first argument).

If the condition is true, it uses AUD_log() to print to stderr, and has some dubious recommendations printed only once.

This change:
- clears the control flow, and make the condition directly visible in the 'if' statement.
- uses standard QEMU error_report()
- audio_bug() now captures __func__
- remove the "Save all your work and restart..." once hint

---
 audio/audio_int.h       |  2 --
 audio/audio_template.h  | 38 +++++++++++++--------------
 audio/audio-mixeng-be.c | 69 +++++++++++++++++++------------------------------
 3 files changed, 46 insertions(+), 63 deletions(-)
audio/audio_int.h +0 -2
index e0ed6af67ed..20ec7883aab 100644
@@ -244,8 +244,6 @@ extern const char *audio_prio_list[];
 void audio_pcm_init_info (struct audio_pcm_info *info, const struct audsettings *as);
 void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
 
-int audio_bug (const char *funcname, int cond);
-
 void audio_run(AudioMixengBackend *s, const char *msg);
 
 typedef struct RateCtl {
audio/audio_template.h +19 -19
index 5711f4a26e1..9dde36738bc 100644
@@ -64,15 +64,15 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioMixengBackend *s,
                min_voices);
     }
 
-    if (audio_bug(__func__, !voice_size && max_voices)) {
-        dolog("drv=`%s' voice_size=0 max_voices=%d\n",
-               k->name, max_voices);
+    if (!voice_size && max_voices) {
+        audio_bug("drv=`%s' voice_size=0 max_voices=%d",
+                  k->name, max_voices);
         glue(s->nb_hw_voices_, TYPE) = 0;
     }
 
-    if (audio_bug(__func__, voice_size && !max_voices)) {
-        dolog("drv=`%s' voice_size=%zu max_voices=0\n",
-              k->name, voice_size);
+    if (voice_size && !max_voices) {
+        audio_bug("drv=`%s' voice_size=%zu max_voices=0",
+                  k->name, voice_size);
     }
 }
 
@@ -88,8 +88,8 @@ static void glue(audio_pcm_hw_alloc_resources_, TYPE)(HW *hw)
 {
     if (glue(audio_get_pdo_, TYPE)(hw->s->dev)->mixing_engine) {
         size_t samples = hw->samples;
-        if (audio_bug(__func__, samples == 0)) {
-            dolog("Attempted to allocate empty buffer\n");
+        if (samples == 0) {
+            audio_bug("Attempted to allocate empty buffer");
         }
 
         HWBUF.buffer = g_new0(st_sample, samples);
@@ -275,8 +275,8 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioMixengBackend *s,
         return NULL;
     }
 
-    if (audio_bug(__func__, !glue(k->init_, TYPE))) {
-        dolog("No host audio driver or missing init_%s\n", NAME);
+    if (!glue(k->init_, TYPE)) {
+        audio_bug("No host audio driver or missing init_%s", NAME);
         return NULL;
     }
 
@@ -295,8 +295,8 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioMixengBackend *s,
         goto err0;
     }
 
-    if (audio_bug(__func__, hw->samples <= 0)) {
-        dolog("hw->samples=%zd\n", hw->samples);
+    if (hw->samples <= 0) {
+        audio_bug("hw->samples=%zd", hw->samples);
         goto err1;
     }
 
@@ -477,8 +477,8 @@ static void glue (audio_close_, TYPE) (SW *sw)
 static void glue(audio_mixeng_backend_close_, TYPE)(AudioBackend *be, SW *sw)
 {
     if (sw) {
-        if (audio_bug(__func__, !be)) {
-            dolog("backend=%p\n", be);
+        if (!be) {
+            audio_bug("backend=%p", be);
             return;
         }
 
@@ -498,9 +498,9 @@ static SW *glue(audio_mixeng_backend_open_, TYPE) (
     AudioMixengBackendClass *k;
     AudiodevPerDirectionOptions *pdo;
 
-    if (audio_bug(__func__, !be || !name || !callback_fn || !as)) {
-        dolog("backend=%p name=%p callback_fn=%p as=%p\n",
-              be, name, callback_fn, as);
+    if (!be || !name || !callback_fn || !as) {
+        audio_bug("backend=%p name=%p callback_fn=%p as=%p",
+                  be, name, callback_fn, as);
         goto fail;
     }
 
@@ -519,8 +519,8 @@ static SW *glue(audio_mixeng_backend_open_, TYPE) (
         goto fail;
     }
 
-    if (audio_bug(__func__, !glue(k->init_, TYPE))) {
-        dolog("Can not open `%s' (no host audio driver)\n", name);
+    if (!glue(k->init_, TYPE)) {
+        error_report("audio: Can not open `%s' (no host audio driver)", name);
         goto fail;
     }
 
audio/audio-mixeng-be.c +27 -42

141 lines not on this page · raw message

Signature · 1 line
2.53.0
#85 lore raw

PATCH 82/85 audio: replace remaining dolog() and AUD_log

In reply to Marc-André Lureau

Use warn_report/error_report and trace instead.

---
 audio/audio_template.h  | 19 ++++++++-----------
 audio/audio-mixeng-be.c | 14 ++++++--------
 audio/trace-events      |  1 +
 3 files changed, 15 insertions(+), 19 deletions(-)
audio/audio_template.h +8 -11
index 9dde36738bc..760aaf5f31f 100644
@@ -47,21 +47,19 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioMixengBackend *s,
     if (glue(s->nb_hw_voices_, TYPE) > max_voices) {
         if (!max_voices) {
 #ifdef DAC
-            dolog("Driver `%s' does not support " NAME "\n", k->name);
+            warn_report("audio: Driver '%s' does not support " NAME, k->name);
 #endif
         } else {
-            dolog("Driver `%s' does not support %d " NAME " voices, max %d\n",
-                   k->name,
-                   glue(s->nb_hw_voices_, TYPE),
-                   max_voices);
+            warn_report("audio: Driver '%s' does not support %d " NAME " voices, max %d",
+                        k->name, glue(s->nb_hw_voices_, TYPE), max_voices);
         }
         glue(s->nb_hw_voices_, TYPE) = max_voices;
     }
 
     if (glue(s->nb_hw_voices_, TYPE) < min_voices) {
-        dolog("Bogus number of " NAME " voices %d, setting to %d\n",
-               glue(s->nb_hw_voices_, TYPE),
-               min_voices);
+        warn_report("audio: Bogus number of " NAME " voices %d, setting to %d",
+                    glue(s->nb_hw_voices_, TYPE),
+                    min_voices);
     }
 
     if (!voice_size && max_voices) {
@@ -443,7 +441,7 @@ static SW *glue(audio_pcm_create_voice_pair_, TYPE)(
 
     hw = glue(audio_pcm_hw_add_, TYPE)(s, &hw_as);
     if (!hw) {
-        dolog("Could not create a backend for voice `%s'\n", sw_name);
+        error_report("audio: Could not create a backend for voice '%s'", sw_name);
         goto err1;
     }
 
@@ -537,8 +535,7 @@ static SW *glue(audio_mixeng_backend_open_, TYPE) (
         HW *hw = sw->hw;
 
         if (!hw) {
-            dolog("Internal logic error: voice `%s' has no backend\n",
-                  SW_NAME(sw));
+            audio_bug("Internal logic error: voice '%s' has no backend", SW_NAME(sw));
             goto fail;
         }
 
audio/audio-mixeng-be.c +6 -8
index 45bcfb74338..87e5a2fc3af 100644
@@ -654,7 +654,7 @@ static size_t audio_mixeng_backend_write(AudioBackend *be, SWVoiceOut *sw,
     hw = sw->hw;
 
     if (!hw->enabled) {
-        dolog("Writing to disabled voice %s\n", SW_NAME(sw));
+        warn_report("audio: Writing to disabled voice %s", SW_NAME(sw));
         return 0;
     }
 
@@ -677,7 +677,7 @@ static size_t audio_mixeng_backend_read(AudioBackend *be,
     hw = sw->hw;
 
     if (!hw->enabled) {
-        dolog("Reading from disabled voice %s\n", SW_NAME(sw));
+        warn_report("audio: Reading from disabled voice %s", SW_NAME(sw));
         return 0;
     }
 
@@ -874,9 +874,8 @@ static void audio_capture_mix_and_clear(HWVoiceOut *hw, size_t rpos,
                 sw->empty = sw->total_hw_samples_mixed == 0;
 
                 if (to_read - frames_in) {
-                    dolog("Could not mix %zu frames into a capture "
-                          "buffer, mixed %zu\n",
-                          to_read, frames_in);
+                    audio_bug("Could not mix %zu frames into a capture "
+                              "buffer, mixed %zu", to_read, frames_in);
                     break;
                 }
                 n -= to_read;
@@ -1561,7 +1560,7 @@ static CaptureVoiceOut *audio_mixeng_backend_add_capture(
     }
 
     if (!audio_get_pdo_out(s->dev)->mixing_engine) {
-        dolog("Can't capture with mixeng disabled\n");
+        error_report("audio: Can't capture with mixeng disabled");
         return NULL;
     }
 
@@ -1754,8 +1753,7 @@ size_t audio_rate_peek_bytes(RateCtl *rate, struct audio_pcm_info *info)
 void audio_rate_add_bytes(RateCtl *rate, size_t bytes_used)
 {
     if (rate->peeked_frames < 0 || rate->peeked_frames > 65536) {
-        AUD_log(NULL, "Resetting rate control (%" PRId64 " frames)\n",
-                rate->peeked_frames);
+        trace_audio_rate_reset(rate->peeked_frames);
         audio_rate_start(rate);
     }
 
audio/trace-events +1 -0
index ed04792d508..222e73c7e88 100644
@@ -70,6 +70,7 @@ audio_sw_write(const char *name, size_t size, size_t written, size_t total_mixed
 audio_get_free(const char *name, size_t live, size_t dead, uint32_t frontend_frames) "%s: get_free live %zu dead %zu frontend frames %u"
 audio_out_disable(void) "Disabling voice"
 audio_out_played(size_t played) "played=%zu"
+audio_rate_reset(int64_t frames) "Resetting rate control (%" PRId64 " frames)"
 
 # audio_template.h
 audio_open_out(const char *name, int freq, int nchannels, int fmt) "open %s, freq %d, nchannels %d, fmt %d"
Signature · 1 line
2.53.0
#86 lore raw

PATCH 83/85 audio: remove AUD_log/ldebug

In reply to Marc-André Lureau

audio/ is now converted to use QEMU standard trace & error reporting.

---
 audio/audio_int.h       | 14 --------------
 audio/audio_template.h  |  2 +-
 audio/audio-mixeng-be.c | 19 -------------------
 audio/mixeng.c          |  1 -
 4 files changed, 1 insertion(+), 35 deletions(-)
audio/audio_int.h +0 -14
index 20ec7883aab..3fc4b516878 100644
@@ -33,12 +33,6 @@
 #include "qemu/audio-capture.h"
 #include "mixeng.h"
 
-void G_GNUC_PRINTF(2, 0)
-AUD_vlog(const char *cap, const char *fmt, va_list ap);
-
-void G_GNUC_PRINTF(2, 3)
-AUD_log(const char *cap, const char *fmt, ...);
-
 struct audio_callback {
     void *opaque;
     audio_callback_fn fn;
@@ -276,14 +270,6 @@ static inline size_t audio_ring_posb(size_t pos, size_t dist, size_t len)
     return pos >= dist ? pos - dist : len - dist + pos;
 }
 
-#define dolog(fmt, ...) AUD_log(AUDIO_CAP, fmt, ## __VA_ARGS__)
-
-#ifdef DEBUG
-#define ldebug(fmt, ...) AUD_log(AUDIO_CAP, fmt, ## __VA_ARGS__)
-#else
-#define ldebug(fmt, ...) (void)0
-#endif
-
 AudiodevPerDirectionOptions *audio_get_pdo_in(Audiodev *dev);
 AudiodevPerDirectionOptions *audio_get_pdo_out(Audiodev *dev);
 
audio/audio_template.h +1 -1
index 760aaf5f31f..85a128e2f47 100644
@@ -128,7 +128,7 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw)
         /* f_fe_min = ceil(1 [frames] * f_be [Hz] / size_be [frames]) */
         f_fe_min = (f_be + HWBUF.size - 1) / HWBUF.size;
         qemu_log_mask(LOG_UNIMP,
-                      AUDIO_CAP ": The guest selected a " NAME " sample rate"
+                      "audio: The guest selected a " NAME " sample rate"
                       " of %d Hz for %s. Only sample rates >= %" PRIu64 " Hz"
                       " are supported.\n",
                       sw->info.freq, sw->name, f_fe_min);
audio/audio-mixeng-be.c +0 -19
index 87e5a2fc3af..a6d5812fc65 100644
@@ -26,7 +26,6 @@
 #include "trace.h"
 #include "trace/control.h"
 
-#define AUDIO_CAP "audio"
 #include "audio_int.h"
 
 #define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"
@@ -68,24 +67,6 @@ static int audio_format_to_index(AudioFormat af)
     g_assert_not_reached();
 }
 
-void AUD_vlog (const char *cap, const char *fmt, va_list ap)
-{
-    if (cap) {
-        fprintf(stderr, "%s: ", cap);
-    }
-
-    vfprintf(stderr, fmt, ap);
-}
-
-void AUD_log (const char *cap, const char *fmt, ...)
-{
-    va_list ap;
-
-    va_start (ap, fmt);
-    AUD_vlog (cap, fmt, ap);
-    va_end (ap);
-}
-
 static char *audsettings_to_string(const struct audsettings *as)
 {
     return g_strdup_printf("frequency=%d nchannels=%d fmt=%s endian=%s",
audio/mixeng.c +0 -1
index e63c76e021d..a209737a913 100644
@@ -26,7 +26,6 @@
 #include "qemu/bswap.h"
 #include "qemu/audio.h"
 
-#define AUDIO_CAP "mixeng"
 #include "audio_int.h"
 #ifdef FLOAT_MIXENG
 #include "qemu/error-report.h"
Signature · 1 line
2.53.0
#87 lore raw

PATCH 84/85 audio: remove AudioMixengBackendClass.name

In reply to Marc-André Lureau

Simply use the class name instead.

---
 audio/audio_int.h      |  1 -
 audio/audio_template.h | 15 ++++++++-------
 audio/alsaaudio.c      |  1 -
 audio/dbusaudio.c      |  1 -
 audio/dsoundaudio.c    |  1 -
 audio/jackaudio.c      |  1 -
 audio/noaudio.c        |  1 -
 audio/ossaudio.c       |  1 -
 audio/paaudio.c        |  1 -
 audio/pwaudio.c        |  1 -
 audio/sdlaudio.c       |  1 -
 audio/sndioaudio.c     |  1 -
 audio/spiceaudio.c     |  1 -
 audio/wavaudio.c       |  1 -
 audio/coreaudio.m      |  1 -
 15 files changed, 8 insertions(+), 21 deletions(-)
audio/audio_int.h +0 -1
index 3fc4b516878..06f79ade6b0 100644
@@ -173,7 +173,6 @@ struct SWVoiceCap {
 struct AudioMixengBackendClass {
     AudioBackendClass parent_class;
 
-    const char *name;
     int max_voices_out;
     int max_voices_in;
     size_t voice_size_out;
audio/audio_template.h +8 -7
index 85a128e2f47..228369cf9a1 100644
@@ -40,6 +40,7 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioMixengBackend *s,
                                               AudioMixengBackendClass *k,
                                               int min_voices)
 {
+    const char *be_name = object_class_get_name(OBJECT_CLASS(k));
     int max_voices = glue(k->max_voices_, TYPE);
     size_t voice_size = glue(k->voice_size_, TYPE);
 
@@ -47,11 +48,11 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioMixengBackend *s,
     if (glue(s->nb_hw_voices_, TYPE) > max_voices) {
         if (!max_voices) {
 #ifdef DAC
-            warn_report("audio: Driver '%s' does not support " NAME, k->name);
+            warn_report("audio: '%s' backend does not support " NAME, be_name);
 #endif
         } else {
-            warn_report("audio: Driver '%s' does not support %d " NAME " voices, max %d",
-                        k->name, glue(s->nb_hw_voices_, TYPE), max_voices);
+            warn_report("audio: '%s' backend does not support %d " NAME " voices, max %d",
+                        be_name, glue(s->nb_hw_voices_, TYPE), max_voices);
         }
         glue(s->nb_hw_voices_, TYPE) = max_voices;
     }
@@ -63,14 +64,14 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioMixengBackend *s,
     }
 
     if (!voice_size && max_voices) {
-        audio_bug("drv=`%s' voice_size=0 max_voices=%d",
-                  k->name, max_voices);
+        audio_bug("backend=`%s' voice_size=0 max_voices=%d",
+                  be_name, max_voices);
         glue(s->nb_hw_voices_, TYPE) = 0;
     }
 
     if (voice_size && !max_voices) {
-        audio_bug("drv=`%s' voice_size=%zu max_voices=0",
-                  k->name, voice_size);
+        audio_bug("backend=`%s' voice_size=%zu max_voices=0",
+                  be_name, voice_size);
     }
 }
 
audio/alsaaudio.c +0 -1
index e2290ea814a..dc99ccb44fa 100644
@@ -895,7 +895,6 @@ static void audio_alsa_class_init(ObjectClass *klass, const void *data)
     audio_alsa_parent_class = AUDIO_BACKEND_CLASS(object_class_get_parent(klass));
 
     b->realize = audio_alsa_realize;
-    k->name = "alsa";
     k->max_voices_out = INT_MAX;
     k->max_voices_in = INT_MAX;
     k->voice_size_out = sizeof(ALSAVoiceOut);
audio/dbusaudio.c +0 -1
index b212b3d6022..e9bdf6adb5b 100644
@@ -699,7 +699,6 @@ static void audio_dbus_class_init(ObjectClass *klass, const void *data)
 
     b->realize = audio_dbus_realize;
     b->set_dbus_server = dbus_audio_set_server;
-    k->name = "dbus";
     k->max_voices_out = INT_MAX;
     k->max_voices_in = INT_MAX;
     k->voice_size_out = sizeof(DBusVoiceOut);
audio/dsoundaudio.c +0 -1
index 704bc3da73b..338ee49c2fe 100644
@@ -649,7 +649,6 @@ static void audio_dsound_class_init(ObjectClass *klass, const void *data)
     audio_dsound_parent_class = AUDIO_BACKEND_CLASS(object_class_get_parent(klass));
 
     b->realize = audio_dsound_realize;
-    k->name = "dsound";
     k->max_voices_out = INT_MAX;
     k->max_voices_in = 1;
     k->voice_size_out = sizeof(DSoundVoiceOut);
audio/jackaudio.c +0 -1
index d9ae8edc0e0..f49fd82c45c 100644
@@ -663,7 +663,6 @@ static void audio_jack_class_init(ObjectClass *klass, const void *data)
 {
     AudioMixengBackendClass *k = AUDIO_MIXENG_BACKEND_CLASS(klass);
 
-    k->name = "jack";
     k->max_voices_out = INT_MAX;
     k->max_voices_in = INT_MAX;
     k->voice_size_out = sizeof(QJackOut);
audio/noaudio.c +0 -1
index 70316c572ec..ea6a78c7055 100644
@@ -113,7 +113,6 @@ static void audio_none_class_init(ObjectClass *klass, const void *data)
 {
     AudioMixengBackendClass *k = AUDIO_MIXENG_BACKEND_CLASS(klass);
 
-    k->name = "none";
     k->max_voices_out = INT_MAX;
     k->max_voices_in = INT_MAX;
     k->voice_size_out = sizeof(NoVoiceOut);
audio/ossaudio.c +0 -1
index 157979e84b4..63c6e0a291f 100644
@@ -739,7 +739,6 @@ static void audio_oss_class_init(ObjectClass *klass, const void *data)
     audio_oss_parent_class = AUDIO_BACKEND_CLASS(object_class_get_parent(klass));
 
     b->realize = audio_oss_realize;
-    k->name = "oss";
     k->max_voices_out = INT_MAX;
     k->max_voices_in = INT_MAX;
     k->voice_size_out = sizeof(OSSVoiceOut);
audio/paaudio.c +0 -1
index c9957105543..23e8767a46b 100644
@@ -920,7 +920,6 @@ static void audio_pa_class_init(ObjectClass *klass, const void *data)
     audio_pa_parent_class = AUDIO_BACKEND_CLASS(object_class_get_parent(klass));
 
     b->realize = audio_pa_realize;
-    k->name = "pa";
     k->max_voices_out = INT_MAX;
     k->max_voices_in = INT_MAX;
     k->voice_size_out = sizeof(PAVoiceOut);
audio/pwaudio.c +0 -1
index b70bf0c1353..a59c22e60b8 100644
@@ -829,7 +829,6 @@ static void audio_pw_class_init(ObjectClass *klass, const void *data)
     audio_pw_parent_class = AUDIO_BACKEND_CLASS(object_class_get_parent(klass));
 
     b->realize = audio_pw_realize;
-    k->name = "pipewire";
     k->max_voices_out = INT_MAX;
     k->max_voices_in = INT_MAX;
     k->voice_size_out = sizeof(PWVoiceOut);
audio/sdlaudio.c +0 -1
index 936a3ed076d..bd6a46e2af1 100644
@@ -458,7 +458,6 @@ static void audio_sdl_class_init(ObjectClass *klass, const void *data)
     audio_sdl_parent_class = AUDIO_BACKEND_CLASS(object_class_get_parent(klass));
 
     b->realize = audio_sdl_realize;
-    k->name = "sdl";
     k->max_voices_out = INT_MAX;
     k->max_voices_in = INT_MAX;
     k->voice_size_out = sizeof(SDLVoiceOut);
audio/sndioaudio.c +0 -1
index 761f23f8273..2e05ef7ea74 100644
@@ -531,7 +531,6 @@ static void audio_sndio_class_init(ObjectClass *klass, const void *data)
 {
     AudioMixengBackendClass *k = AUDIO_MIXENG_BACKEND_CLASS(klass);
 
-    k->name = "sndio";
     k->max_voices_out = INT_MAX;
     k->max_voices_in = INT_MAX;
     k->voice_size_out = sizeof(SndioVoice);
audio/spiceaudio.c +0 -1
index f903ef77e72..70a0b60dd83 100644
@@ -303,7 +303,6 @@ static void audio_spice_class_init(ObjectClass *klass, const void *data)
     audio_spice_parent_class = AUDIO_BACKEND_CLASS(object_class_get_parent(klass));
 
     b->realize = spice_audio_realize;
-    k->name = "spice";
     k->max_voices_out = 1;
     k->max_voices_in = 1;
     k->voice_size_out = sizeof(SpiceVoiceOut);
audio/wavaudio.c +0 -1
index 55d12d6cdfd..d247dd3ffe6 100644
@@ -188,7 +188,6 @@ static void audio_wav_class_init(ObjectClass *klass, const void *data)
 {
     AudioMixengBackendClass *k = AUDIO_MIXENG_BACKEND_CLASS(klass);
 
-    k->name = "wav";
     k->max_voices_out = 1;
     k->max_voices_in = 0;
     k->voice_size_out = sizeof(WAVVoiceOut);
audio/coreaudio.m +0 -1
index 1f4b3d9d467..a28fa77d73f 100644
@@ -646,7 +646,6 @@ static void audio_coreaudio_class_init(ObjectClass *klass, const void *data)
 {
     AudioMixengBackendClass *k = AUDIO_MIXENG_BACKEND_CLASS(klass);
 
-    k->name = "coreaudio";
     k->max_voices_out = 1;
     k->max_voices_in = 0;
     k->voice_size_out = sizeof(coreaudioVoiceOut);
Signature · 1 line
2.53.0
#88 lore raw

PATCH 85/85 audio: fix leak of audio capture name

In reply to Marc-André Lureau
---
 audio/audio-mixeng-be.c | 2 ++
 1 file changed, 2 insertions(+)
audio/audio-mixeng-be.c +2 -0
index a6d5812fc65..37040450511 100644
@@ -227,6 +227,7 @@ static void audio_detach_capture (HWVoiceOut *hw)
         CaptureVoiceOut *cap = sc->cap;
         int was_active = sw->active;
 
+        g_clear_pointer(&sw->name, g_free);
         if (sw->rate) {
             st_rate_stop (sw->rate);
             sw->rate = NULL;
@@ -1618,6 +1619,7 @@ static void audio_mixeng_backend_del_capture(
                     SWVoiceCap *sc = (SWVoiceCap *) sw;
 
                     trace_audio_capture_free_sw(sw->name);
+                    g_clear_pointer(&sw->name, g_free);
                     sw1 = sw->entries.le_next;
                     if (sw->rate) {
                         st_rate_stop (sw->rate);
Signature · 1 line
2.53.0
Reviewed-by on the v1 series
#89 lore raw
In reply to Marc-André Lureau
Quoted 18 lines · Marc-André Lureau

Hi

This is the combination of the two earlier series:
[PATCH 00/37] audio: cleanups & add a manual test [PATCH 00/43] audio: more cleanups (2/2 for 11.0)

Patches missing r-b trailers:
- scripts/modinfo: use argparse
- scripts/modinfo: make --devices optional
- scripts/modinfo: add --skip-missing-deps
- util: add some extra stubs for qemu modules initialization
- tests: start manual audio backend test
- audio: use DEFINE_TYPES
- audio: replace type_init() with DEFINE_TYPES
- audio: keep a strong reference on the backend
- replay: remove dependency on audio/
- audio: fix leak of audio capture name

Quoted 1 line

This is a huge but nice cleanup: