@samitouri / QOSamiQemu / commits / c60879085a

audio/oss: replace custom logging with report & trace

Replace the custom audio logging infrastructure with standard QEMU error reporting and tracing. Note the patch drops DEBUG_MISMATCH condition, and now always trace actual audio parameters. 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 c60879085a1a942fd64919174bb63f30d9967c41
2 files changed +81 -100
audio/ossaudio.c
+76 -100
@@ -31,11 +31,10 @@
31 #include "qemu/host-utils.h"
32 #include "qapi/error.h"
33 #include "qemu/audio.h"
34 +#include "qemu/error-report.h"
35 #include "qom/object.h"
35 -#include "trace.h"
36 -
37 -#define AUDIO_CAP "oss"
36 #include "audio_int.h"
37 +#include "trace.h"
38
39 #define TYPE_AUDIO_OSS "audio-oss"
40 OBJECT_DECLARE_SIMPLE_TYPE(AudioOss, AUDIO_OSS)
@@ -76,43 +75,40 @@ struct oss_params {
75 int fragsize;
76 };
77
79 -static void G_GNUC_PRINTF (2, 3) oss_logerr (int err, const char *fmt, ...)
78 +static void G_GNUC_PRINTF(2, 3) oss_logerr(int err, const char *fmt, ...)
79 {
80 va_list ap;
81
83 - va_start (ap, fmt);
84 - AUD_vlog (AUDIO_CAP, fmt, ap);
85 - va_end (ap);
82 + error_printf("oss: ");
83 + va_start(ap, fmt);
84 + error_vprintf(fmt, ap);
85 + va_end(ap);
86
87 - AUD_log (AUDIO_CAP, "Reason: %s\n", strerror (err));
87 + error_printf(" Reason: %s\n", strerror(err));
88 }
89
90 -static void G_GNUC_PRINTF (3, 4) oss_logerr2 (
91 - int err,
92 - const char *typ,
93 - const char *fmt,
94 - ...
95 - )
90 +static void G_GNUC_PRINTF(3, 4) oss_logerr2(int err, const char *typ,
91 + const char *fmt, ...)
92 {
93 va_list ap;
94
99 - AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
95 + error_printf("oss: Could not initialize %s: ", typ);
96
101 - va_start (ap, fmt);
102 - AUD_vlog (AUDIO_CAP, fmt, ap);
103 - va_end (ap);
97 + va_start(ap, fmt);
98 + error_vprintf(fmt, ap);
99 + va_end(ap);
100
105 - AUD_log (AUDIO_CAP, "Reason: %s\n", strerror (err));
101 + error_printf(" Reason: %s\n", strerror(err));
102 }
103
108 -static void oss_anal_close (int *fdp)
104 +static void oss_anal_close(int *fdp)
105 {
106 int err;
107
112 - qemu_set_fd_handler (*fdp, NULL, NULL, NULL);
113 - err = close (*fdp);
108 + qemu_set_fd_handler(*fdp, NULL, NULL, NULL);
109 + err = close(*fdp);
110 if (err) {
115 - oss_logerr (errno, "Failed to close file(fd=%d)\n", *fdp);
111 + oss_logerr(errno, "Failed to close file(fd=%d)", *fdp);
112 }
113 *fdp = -1;
114 }
@@ -159,10 +155,7 @@ static int aud_to_ossfmt(AudioFormat fmt, bool big_endian)
155 return big_endian ? AFMT_U16_BE : AFMT_U16_LE;
156
157 default:
162 - dolog ("Internal logic error: Bad audio format %d\n", fmt);
163 -#ifdef DEBUG_AUDIO
164 - abort ();
165 -#endif
158 + error_report("oss: Internal logic error: Bad audio format %d", fmt);
159 return AFMT_U8;
160 }
161 }
@@ -201,27 +194,13 @@ static int oss_to_audfmt (int ossfmt, AudioFormat *fmt, int *endianness)
194 break;
195
196 default:
204 - dolog ("Unrecognized audio format %d\n", ossfmt);
197 + error_report("oss: Unrecognized audio format %d", ossfmt);
198 return -1;
199 }
200
201 return 0;
202 }
203
211 -#if defined DEBUG_MISMATCHES || defined DEBUG
212 -static void oss_dump_info (struct oss_params *req, struct oss_params *obt)
213 -{
214 - dolog ("parameter | requested value | obtained value\n");
215 - dolog ("format | %10d | %10d\n", req->fmt, obt->fmt);
216 - dolog ("channels | %10d | %10d\n",
217 - req->nchannels, obt->nchannels);
218 - dolog ("frequency | %10d | %10d\n", req->freq, obt->freq);
219 - dolog ("nfrags | %10d | %10d\n", req->nfrags, obt->nfrags);
220 - dolog ("fragsize | %10d | %10d\n",
221 - req->fragsize, obt->fragsize);
222 -}
223 -#endif
224 -
204 #ifdef USE_DSP_POLICY
205 static int oss_get_version (int fd, int *version, const char *typ)
206 {
@@ -240,7 +219,7 @@ static int oss_get_version (int fd, int *version, const char *typ)
219 return 0;
220 }
221 #endif
243 - oss_logerr2 (errno, typ, "Failed to get OSS version\n");
222 + oss_logerr2(errno, typ, "Failed to get OSS version");
223 return -1;
224 }
225 return 0;
@@ -269,7 +248,7 @@ static int oss_open(int in, struct oss_params *req, audsettings *as,
248
249 fd = open (dspname, oflags | O_NONBLOCK);
250 if (-1 == fd) {
272 - oss_logerr2 (errno, typ, "Failed to open `%s'\n", dspname);
251 + oss_logerr2(errno, typ, "Failed to open '%s'", dspname);
252 return -1;
253 }
254
@@ -281,23 +260,23 @@ static int oss_open(int in, struct oss_params *req, audsettings *as,
260 qapi_AudiodevOssPerDirectionOptions_base(opdo), as, 23220);
261
262 if (ioctl (fd, SNDCTL_DSP_SAMPLESIZE, &fmt)) {
284 - oss_logerr2 (errno, typ, "Failed to set sample size %d\n", req->fmt);
263 + oss_logerr2(errno, typ, "Failed to set sample size %d", req->fmt);
264 goto err;
265 }
266
267 if (ioctl (fd, SNDCTL_DSP_CHANNELS, &nchannels)) {
289 - oss_logerr2 (errno, typ, "Failed to set number of channels %d\n",
290 - req->nchannels);
268 + oss_logerr2(errno, typ, "Failed to set number of channels %d",
269 + req->nchannels);
270 goto err;
271 }
272
273 if (ioctl (fd, SNDCTL_DSP_SPEED, &freq)) {
295 - oss_logerr2 (errno, typ, "Failed to set frequency %d\n", req->freq);
274 + oss_logerr2(errno, typ, "Failed to set frequency %d", req->freq);
275 goto err;
276 }
277
278 if (ioctl (fd, SNDCTL_DSP_NONBLOCK, NULL)) {
300 - oss_logerr2 (errno, typ, "Failed to set non-blocking mode\n");
279 + oss_logerr2(errno, typ, "Failed to set non-blocking mode");
280 goto err;
281 }
282
@@ -311,9 +290,9 @@ static int oss_open(int in, struct oss_params *req, audsettings *as,
290 if (version >= 0x040000) {
291 int policy2 = policy;
292 if (ioctl(fd, SNDCTL_DSP_POLICY, &policy2)) {
314 - oss_logerr2 (errno, typ,
315 - "Failed to set timing policy to %d\n",
316 - policy);
293 + oss_logerr2(errno, typ,
294 + "Failed to set timing policy to %d",
295 + policy);
296 goto err;
297 }
298 setfragment = 0;
@@ -325,20 +304,20 @@ static int oss_open(int in, struct oss_params *req, audsettings *as,
304 if (setfragment) {
305 int mmmmssss = (req->nfrags << 16) | ctz32 (req->fragsize);
306 if (ioctl (fd, SNDCTL_DSP_SETFRAGMENT, &mmmmssss)) {
328 - oss_logerr2 (errno, typ, "Failed to set buffer length (%d, %d)\n",
329 - req->nfrags, req->fragsize);
307 + oss_logerr2(errno, typ, "Failed to set buffer length (%d, %d)",
308 + req->nfrags, req->fragsize);
309 goto err;
310 }
311 }
312
313 if (ioctl (fd, in ? SNDCTL_DSP_GETISPACE : SNDCTL_DSP_GETOSPACE, &abinfo)) {
335 - oss_logerr2 (errno, typ, "Failed to get buffer length\n");
314 + oss_logerr2(errno, typ, "Failed to get buffer length");
315 goto err;
316 }
317
318 if (!abinfo.fragstotal || !abinfo.fragsize) {
340 - AUD_log (AUDIO_CAP, "Returned bogus buffer information(%d, %d) for %s\n",
341 - abinfo.fragstotal, abinfo.fragsize, typ);
319 + error_report("oss: Returned bogus buffer information(%d, %d) for %s",
320 + abinfo.fragstotal, abinfo.fragsize, typ);
321 goto err;
322 }
323
@@ -349,20 +328,13 @@ static int oss_open(int in, struct oss_params *req, audsettings *as,
328 obt->fragsize = abinfo.fragsize;
329 *pfd = fd;
330
352 -#ifdef DEBUG_MISMATCHES
353 - if ((req->fmt != obt->fmt) ||
354 - (req->nchannels != obt->nchannels) ||
355 - (req->freq != obt->freq) ||
356 - (req->fragsize != obt->fragsize) ||
357 - (req->nfrags != obt->nfrags)) {
358 - dolog ("Audio parameters mismatch\n");
359 - oss_dump_info (req, obt);
360 - }
361 -#endif
331 + trace_oss_out_params(
332 + req->fmt, obt->fmt,
333 + req->nchannels, obt->nchannels,
334 + req->freq, obt->freq,
335 + req->nfrags, obt->nfrags,
336 + req->fragsize, obt->fragsize);
337
363 -#ifdef DEBUG
364 - oss_dump_info (req, obt);
365 -#endif
338 return 0;
339
340 err:
@@ -378,7 +350,7 @@ static size_t oss_get_available_bytes(OSSVoiceOut *oss)
350
351 err = ioctl(oss->fd, SNDCTL_DSP_GETOPTR, &cntinfo);
352 if (err < 0) {
381 - oss_logerr(errno, "SNDCTL_DSP_GETOPTR failed\n");
353 + oss_logerr(errno, "SNDCTL_DSP_GETOPTR failed");
354 return 0;
355 }
356
@@ -459,8 +431,7 @@ static size_t oss_write(HWVoiceOut *hw, void *buf, size_t len)
431 bytes_written = write(oss->fd, pcm, len);
432 if (bytes_written < 0) {
433 if (errno != EAGAIN) {
462 - oss_logerr(errno, "failed to write %zu bytes\n",
463 - len);
434 + oss_logerr(errno, "failed to write %zu bytes", len);
435 }
436 return pos;
437 }
@@ -474,18 +445,18 @@ static size_t oss_write(HWVoiceOut *hw, void *buf, size_t len)
445 return pos;
446 }
447
477 -static void oss_fini_out (HWVoiceOut *hw)
448 +static void oss_fini_out(HWVoiceOut *hw)
449 {
450 int err;
480 - OSSVoiceOut *oss = (OSSVoiceOut *) hw;
451 + OSSVoiceOut *oss = (OSSVoiceOut *)hw;
452
482 - ldebug ("oss_fini\n");
483 - oss_anal_close (&oss->fd);
453 + trace_oss_fini_out();
454 + oss_anal_close(&oss->fd);
455
456 if (oss->mmapped && hw->buf_emul) {
457 err = munmap(hw->buf_emul, hw->size_emul);
458 if (err) {
488 - oss_logerr(errno, "Failed to unmap buffer %p, size %zu\n",
459 + oss_logerr(errno, "Failed to unmap buffer %p, size %zu",
460 hw->buf_emul, hw->size_emul);
461 }
462 hw->buf_emul = NULL;
@@ -526,8 +497,8 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as)
497 oss->fragsize = obt.fragsize;
498
499 if (obt.nfrags * obt.fragsize % hw->info.bytes_per_frame) {
529 - dolog ("warning: Misaligned DAC buffer, size %d, alignment %d\n",
530 - obt.nfrags * obt.fragsize, hw->info.bytes_per_frame);
500 + warn_report("oss: Misaligned DAC buffer, size %d, alignment %d",
501 + obt.nfrags * obt.fragsize, hw->info.bytes_per_frame);
502 }
503
504 hw->samples = (obt.nfrags * obt.fragsize) / hw->info.bytes_per_frame;
@@ -544,20 +515,16 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as)
515 0
516 );
517 if (hw->buf_emul == MAP_FAILED) {
547 - oss_logerr(errno, "Failed to map %zu bytes of DAC\n",
548 - hw->size_emul);
518 + oss_logerr(errno, "Failed to map %zu bytes of DAC", hw->size_emul);
519 hw->buf_emul = NULL;
520 } else {
521 int trig = 0;
522 if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
553 - oss_logerr (errno, "SNDCTL_DSP_SETTRIGGER 0 failed\n");
523 + oss_logerr(errno, "SNDCTL_DSP_SETTRIGGER 0 failed");
524 } else {
525 trig = PCM_ENABLE_OUTPUT;
556 - if (ioctl (fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
557 - oss_logerr (
558 - errno,
559 - "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n"
560 - );
526 + if (ioctl(fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
527 + oss_logerr(errno, "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed");
528 } else {
529 oss->mmapped = 1;
530 }
@@ -566,7 +533,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as)
533 if (!oss->mmapped) {
534 err = munmap(hw->buf_emul, hw->size_emul);
535 if (err) {
569 - oss_logerr(errno, "Failed to unmap buffer %p size %zu\n",
536 + oss_logerr(errno, "Failed to unmap buffer %p size %zu",
537 hw->buf_emul, hw->size_emul);
538 }
539 hw->buf_emul = NULL;
@@ -582,13 +549,14 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as)
549 static void oss_enable_out(HWVoiceOut *hw, bool enable)
550 {
551 int trig;
585 - OSSVoiceOut *oss = (OSSVoiceOut *) hw;
552 + OSSVoiceOut *oss = (OSSVoiceOut *)hw;
553 AudiodevOssPerDirectionOptions *opdo = oss->dev->u.oss.out;
554
555 + trace_oss_enable_out(enable);
556 +
557 if (enable) {
558 hw->poll_mode = opdo->try_poll;
559
591 - ldebug("enabling voice\n");
560 if (hw->poll_mode) {
561 oss_poll_out(hw);
562 }
@@ -601,12 +569,12 @@ static void oss_enable_out(HWVoiceOut *hw, bool enable)
569 trig = PCM_ENABLE_OUTPUT;
570 if (ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
571 oss_logerr(errno,
604 - "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed\n");
572 + "SNDCTL_DSP_SETTRIGGER PCM_ENABLE_OUTPUT failed");
573 return;
574 }
575 } else {
576 if (hw->poll_mode) {
609 - qemu_set_fd_handler (oss->fd, NULL, NULL, NULL);
577 + qemu_set_fd_handler(oss->fd, NULL, NULL, NULL);
578 hw->poll_mode = 0;
579 }
580
@@ -614,10 +582,9 @@ static void oss_enable_out(HWVoiceOut *hw, bool enable)
582 return;
583 }
584
617 - ldebug ("disabling voice\n");
585 trig = 0;
619 - if (ioctl (oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
620 - oss_logerr (errno, "SNDCTL_DSP_SETTRIGGER 0 failed\n");
586 + if (ioctl(oss->fd, SNDCTL_DSP_SETTRIGGER, &trig) < 0) {
587 + oss_logerr(errno, "SNDCTL_DSP_SETTRIGGER 0 failed");
588 return;
589 }
590 }
@@ -654,9 +621,16 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as)
621 oss->nfrags = obt.nfrags;
622 oss->fragsize = obt.fragsize;
623
624 + trace_oss_in_params(
625 + req.fmt, obt.fmt,
626 + req.nchannels, obt.nchannels,
627 + req.freq, obt.freq,
628 + req.nfrags, obt.nfrags,
629 + req.fragsize, obt.fragsize);
630 +
631 if (obt.nfrags * obt.fragsize % hw->info.bytes_per_frame) {
658 - dolog ("warning: Misaligned ADC buffer, size %d, alignment %d\n",
659 - obt.nfrags * obt.fragsize, hw->info.bytes_per_frame);
632 + warn_report("oss: Misaligned ADC buffer, size %d, alignment %d",
633 + obt.nfrags * obt.fragsize, hw->info.bytes_per_frame);
634 }
635
636 hw->samples = (obt.nfrags * obt.fragsize) / hw->info.bytes_per_frame;
@@ -690,7 +664,7 @@ static size_t oss_read(HWVoiceIn *hw, void *buf, size_t len)
664 case EAGAIN:
665 break;
666 default:
693 - oss_logerr(errno, "Failed to read %zu bytes of audio (to %p)\n",
667 + oss_logerr(errno, "Failed to read %zu bytes of audio (to %p)",
668 len, dst);
669 break;
670 }
@@ -706,9 +680,11 @@ static size_t oss_read(HWVoiceIn *hw, void *buf, size_t len)
680
681 static void oss_enable_in(HWVoiceIn *hw, bool enable)
682 {
709 - OSSVoiceIn *oss = (OSSVoiceIn *) hw;
683 + OSSVoiceIn *oss = (OSSVoiceIn *)hw;
684 AudiodevOssPerDirectionOptions *opdo = oss->dev->u.oss.out;
685
686 + trace_oss_enable_in(enable);
687 +
688 if (enable) {
689 hw->poll_mode = opdo->try_poll;
690
audio/trace-events
+5
@@ -17,6 +17,11 @@ alsa_enable_in(bool enable) "enable=%d"
17
18 # ossaudio.c
19 oss_version(int version) "OSS version = 0x%x"
20 +oss_out_params(int req_fmt, int obt_fmt, int req_channels, int obt_channels, int req_freq, int obt_freq, int req_nfrags, int obt_nfrags, int req_fragsize, int obt_fragsize) "fmt=%d->%d, channels %d->%d, freq=%d->%d, nfrags=%d->%d, fragsize=%d->%d"
21 +oss_in_params(int req_fmt, int obt_fmt, int req_channels, int obt_channels, int req_freq, int obt_freq, int req_nfrags, int obt_nfrags, int req_fragsize, int obt_fragsize) "fmt=%d->%d, channels %d->%d, freq=%d->%d, nfrags=%d->%d, fragsize=%d->%d"
22 +oss_fini_out(void) ""
23 +oss_enable_out(bool enable) "enable=%d"
24 +oss_enable_in(bool enable) "enable=%d"
25
26 # dbusaudio.c
27 dbus_audio_register(const char *s, const char *dir) "sender = %s, dir = %s"