@samitouri / QOSamiQemu / commits / 4b6b4a7251

audio/pa: replace custom logging with report & trace

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 *. Reviewed-by: Mark Cave-Ayland <mark.caveayland@nutanix.com> Reviewed-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>

Marc-André Lureau committed Jan 20, 2026 at 19:32 UTC 4b6b4a72519605da5006e26e74596ab7a60d7c1e
1 file changed +38 -39
audio/paaudio.c
+38 -39
@@ -3,14 +3,13 @@
3 #include "qemu/osdep.h"
4 #include "qemu/module.h"
5 #include "qemu/audio.h"
6 +#include "qemu/error-report.h"
7 #include "qapi/error.h"
8 #include "qom/object.h"
9 +#include "audio_int.h"
10
11 #include <pulse/pulseaudio.h>
12
11 -#define AUDIO_CAP "pulseaudio"
12 -#include "audio_int.h"
13 -
13 #define TYPE_AUDIO_PA "audio-pa"
14 OBJECT_DECLARE_SIMPLE_TYPE(AudioPa, AUDIO_PA)
15
@@ -51,15 +50,16 @@ typedef struct {
50
51 static void qpa_conn_fini(PAConnection *c);
52
54 -static void G_GNUC_PRINTF (2, 3) qpa_logerr (int err, const char *fmt, ...)
53 +static void G_GNUC_PRINTF(2, 3) qpa_logerr(int err, const char *fmt, ...)
54 {
55 va_list ap;
56
58 - va_start (ap, fmt);
59 - AUD_vlog (AUDIO_CAP, fmt, ap);
60 - va_end (ap);
57 + error_printf("pulseaudio: ");
58 + va_start(ap, fmt);
59 + error_vprintf(fmt, ap);
60 + va_end(ap);
61
62 - AUD_log (AUDIO_CAP, "Reason: %s\n", pa_strerror (err));
62 + error_printf(" Reason: %s\n", pa_strerror(err));
63 }
64
65 #ifndef PA_CONTEXT_IS_GOOD
@@ -113,12 +113,12 @@ static void *qpa_get_buffer_in(HWVoiceIn *hw, size_t *size)
113 pa_threaded_mainloop_lock(c->mainloop);
114
115 CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
116 - "pa_threaded_mainloop_lock failed\n");
116 + "pa_threaded_mainloop_lock failed");
117
118 if (!p->read_length) {
119 r = pa_stream_peek(p->stream, &p->read_data, &p->read_length);
120 CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail,
121 - "pa_stream_peek failed\n");
121 + "pa_stream_peek failed");
122 }
123
124 *size = MIN(p->read_length, *size);
@@ -141,7 +141,7 @@ static void qpa_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size)
141 pa_threaded_mainloop_lock(c->mainloop);
142
143 CHECK_DEAD_GOTO(c, p->stream, unlock,
144 - "pa_threaded_mainloop_lock failed\n");
144 + "pa_threaded_mainloop_lock failed");
145
146 assert(buf == p->read_data && size <= p->read_length);
147
@@ -150,7 +150,7 @@ static void qpa_put_buffer_in(HWVoiceIn *hw, void *buf, size_t size)
150
151 if (size && !p->read_length) {
152 r = pa_stream_drop(p->stream);
153 - CHECK_SUCCESS_GOTO(c, r == 0, unlock, "pa_stream_drop failed\n");
153 + CHECK_SUCCESS_GOTO(c, r == 0, unlock, "pa_stream_drop failed");
154 }
155
156 unlock:
@@ -166,7 +166,7 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, size_t length)
166 pa_threaded_mainloop_lock(c->mainloop);
167
168 CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
169 - "pa_threaded_mainloop_lock failed\n");
169 + "pa_threaded_mainloop_lock failed");
170 if (pa_stream_get_state(p->stream) != PA_STREAM_READY) {
171 /* wait for stream to become ready */
172 goto unlock;
@@ -179,7 +179,7 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, size_t length)
179 if (!p->read_length) {
180 r = pa_stream_peek(p->stream, &p->read_data, &p->read_length);
181 CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail,
182 - "pa_stream_peek failed\n");
182 + "pa_stream_peek failed");
183 if (!p->read_length) {
184 /* buffer is empty */
185 break;
@@ -196,7 +196,7 @@ static size_t qpa_read(HWVoiceIn *hw, void *data, size_t length)
196 if (!p->read_length) {
197 r = pa_stream_drop(p->stream);
198 CHECK_SUCCESS_GOTO(c, r == 0, unlock_and_fail,
199 - "pa_stream_drop failed\n");
199 + "pa_stream_drop failed");
200 }
201 }
202
@@ -218,7 +218,7 @@ static size_t qpa_buffer_get_free(HWVoiceOut *hw)
218 pa_threaded_mainloop_lock(c->mainloop);
219
220 CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
221 - "pa_threaded_mainloop_lock failed\n");
221 + "pa_threaded_mainloop_lock failed");
222 if (pa_stream_get_state(p->stream) != PA_STREAM_READY) {
223 /* wait for stream to become ready */
224 l = 0;
@@ -227,7 +227,7 @@ static size_t qpa_buffer_get_free(HWVoiceOut *hw)
227
228 l = pa_stream_writable_size(p->stream);
229 CHECK_SUCCESS_GOTO(c, l != (size_t) -1, unlock_and_fail,
230 - "pa_stream_writable_size failed\n");
230 + "pa_stream_writable_size failed");
231
232 unlock:
233 pa_threaded_mainloop_unlock(c->mainloop);
@@ -248,12 +248,12 @@ static void *qpa_get_buffer_out(HWVoiceOut *hw, size_t *size)
248 pa_threaded_mainloop_lock(c->mainloop);
249
250 CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
251 - "pa_threaded_mainloop_lock failed\n");
251 + "pa_threaded_mainloop_lock failed");
252
253 *size = -1;
254 r = pa_stream_begin_write(p->stream, &ret, size);
255 CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail,
256 - "pa_stream_begin_write failed\n");
256 + "pa_stream_begin_write failed");
257
258 pa_threaded_mainloop_unlock(c->mainloop);
259 return ret;
@@ -273,10 +273,10 @@ static size_t qpa_put_buffer_out(HWVoiceOut *hw, void *data, size_t length)
273 pa_threaded_mainloop_lock(c->mainloop);
274
275 CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
276 - "pa_threaded_mainloop_lock failed\n");
276 + "pa_threaded_mainloop_lock failed");
277
278 r = pa_stream_write(p->stream, data, length, NULL, 0LL, PA_SEEK_RELATIVE);
279 - CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_write failed\n");
279 + CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_write failed");
280
281 pa_threaded_mainloop_unlock(c->mainloop);
282 return length;
@@ -296,7 +296,7 @@ static size_t qpa_write(HWVoiceOut *hw, void *data, size_t length)
296 pa_threaded_mainloop_lock(c->mainloop);
297
298 CHECK_DEAD_GOTO(c, p->stream, unlock_and_fail,
299 - "pa_threaded_mainloop_lock failed\n");
299 + "pa_threaded_mainloop_lock failed");
300 if (pa_stream_get_state(p->stream) != PA_STREAM_READY) {
301 /* wait for stream to become ready */
302 l = 0;
@@ -306,14 +306,14 @@ static size_t qpa_write(HWVoiceOut *hw, void *data, size_t length)
306 l = pa_stream_writable_size(p->stream);
307
308 CHECK_SUCCESS_GOTO(c, l != (size_t) -1, unlock_and_fail,
309 - "pa_stream_writable_size failed\n");
309 + "pa_stream_writable_size failed");
310
311 if (l > length) {
312 l = length;
313 }
314
315 r = pa_stream_write(p->stream, data, l, NULL, 0LL, PA_SEEK_RELATIVE);
316 - CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_write failed\n");
316 + CHECK_SUCCESS_GOTO(c, r >= 0, unlock_and_fail, "pa_stream_write failed");
317
318 unlock:
319 pa_threaded_mainloop_unlock(c->mainloop);
@@ -345,7 +345,7 @@ static pa_sample_format_t audfmt_to_pa(AudioFormat afmt, bool big_endian)
345 format = big_endian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE;
346 break;
347 default:
348 - dolog ("Internal logic error: Bad audio format %d\n", afmt);
348 + error_report("pulseaudio: Internal logic error: Bad audio format %d", afmt);
349 format = PA_SAMPLE_U8;
350 break;
351 }
@@ -376,12 +376,12 @@ static AudioFormat pa_to_audfmt (pa_sample_format_t fmt, int *endianness)
376 *endianness = 0;
377 return AUDIO_FORMAT_F32;
378 default:
379 - dolog ("Internal logic error: Bad pa_sample_format %d\n", fmt);
379 + error_report("pulseaudio: Internal logic error: Bad pa_sample_format %d", fmt);
380 return AUDIO_FORMAT_U8;
381 }
382 }
383
384 -static void context_state_cb (pa_context *c, void *userdata)
384 +static void context_state_cb(pa_context *c, void *userdata)
385 {
386 PAConnection *conn = userdata;
387
@@ -473,7 +473,7 @@ static pa_stream *qpa_simple_new (
473 break;
474
475 default:
476 - dolog("Internal error: unsupported channel count %d\n", ss->channels);
476 + error_report("pulseaudio: unsupported channel count %d", ss->channels);
477 goto fail;
478 }
479
@@ -553,7 +553,7 @@ static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as)
553 &error
554 );
555 if (!pa->stream) {
556 - qpa_logerr (error, "pa_simple_new for playback failed\n");
556 + qpa_logerr(error, "pa_simple_new for playback failed");
557 goto fail1;
558 }
559
@@ -604,7 +604,7 @@ static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as)
604 &error
605 );
606 if (!pa->stream) {
607 - qpa_logerr (error, "pa_simple_new for capture failed\n");
607 + qpa_logerr(error, "pa_simple_new for capture failed");
608 goto fail1;
609 }
610
@@ -633,7 +633,7 @@ static void qpa_simple_disconnect(PAConnection *c, pa_stream *stream)
633
634 err = pa_stream_disconnect(stream);
635 if (err != 0) {
636 - dolog("Failed to disconnect! err=%d\n", err);
636 + error_report("pulseaudio: Failed to disconnect! err=%d", err);
637 }
638 pa_stream_unref(stream);
639 }
@@ -664,7 +664,7 @@ static void qpa_fini_in (HWVoiceIn *hw)
664 int r = pa_stream_drop(pa->stream);
665 if (r) {
666 qpa_logerr(pa_context_errno(c->context),
667 - "pa_stream_drop failed\n");
667 + "pa_stream_drop failed");
668 }
669 pa->read_length = 0;
670 }
@@ -698,7 +698,7 @@ static void qpa_volume_out(HWVoiceOut *hw, Volume *vol)
698 &v, NULL, NULL);
699 if (!op) {
700 qpa_logerr(pa_context_errno(c->context),
701 - "set_sink_input_volume() failed\n");
701 + "set_sink_input_volume() failed");
702 } else {
703 pa_operation_unref(op);
704 }
@@ -708,7 +708,7 @@ static void qpa_volume_out(HWVoiceOut *hw, Volume *vol)
708 vol->mute, NULL, NULL);
709 if (!op) {
710 qpa_logerr(pa_context_errno(c->context),
711 - "set_sink_input_mute() failed\n");
711 + "set_sink_input_mute() failed");
712 } else {
713 pa_operation_unref(op);
714 }
@@ -740,7 +740,7 @@ static void qpa_volume_in(HWVoiceIn *hw, Volume *vol)
740 &v, NULL, NULL);
741 if (!op) {
742 qpa_logerr(pa_context_errno(c->context),
743 - "set_source_output_volume() failed\n");
743 + "set_source_output_volume() failed");
744 } else {
745 pa_operation_unref(op);
746 }
@@ -750,7 +750,7 @@ static void qpa_volume_in(HWVoiceIn *hw, Volume *vol)
750 vol->mute, NULL, NULL);
751 if (!op) {
752 qpa_logerr(pa_context_errno(c->context),
753 - "set_source_output_mute() failed\n");
753 + "set_source_output_mute() failed");
754 } else {
755 pa_operation_unref(op);
756 }
@@ -788,7 +788,7 @@ static void *qpa_conn_init(const char *server)
788
789 if (pa_context_connect(c->context, server, 0, NULL) < 0) {
790 qpa_logerr(pa_context_errno(c->context),
791 - "pa_context_connect() failed\n");
791 + "pa_context_connect() failed");
792 goto fail;
793 }
794
@@ -809,7 +809,7 @@ static void *qpa_conn_init(const char *server)
809
810 if (!PA_CONTEXT_IS_GOOD(state)) {
811 qpa_logerr(pa_context_errno(c->context),
812 - "Wrong context state\n");
812 + "Wrong context state");
813 goto unlock_and_fail;
814 }
815
@@ -823,7 +823,6 @@ static void *qpa_conn_init(const char *server)
823 unlock_and_fail:
824 pa_threaded_mainloop_unlock(c->mainloop);
825 fail:
826 - AUD_log (AUDIO_CAP, "Failed to initialize PA context");
826 qpa_conn_fini(c);
827 return NULL;
828 }