audio: rework audio_bug()
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 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 21, 2026 at 16:07 UTC
ee5e1fca50143466cd915b01971d01122471cbdc
3 files changed
+46
-63
audio/audio-mixeng-be.c
+27
-42
@@ -31,6 +31,8 @@
31
32
#define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"
33
34
+#define audio_bug(fmt, ...) error_report("%s: " fmt, __func__, ##__VA_ARGS__)
35
+
36
const struct mixeng_volume nominal_volume = {
37
.mute = 0,
38
#ifdef FLOAT_MIXENG
@@ -42,23 +44,6 @@ const struct mixeng_volume nominal_volume = {
44
#endif
45
};
46
45
-int audio_bug (const char *funcname, int cond)
46
-{
47
- if (cond) {
48
- static int shown;
49
-
50
- AUD_log (NULL, "A bug was just triggered in %s\n", funcname);
51
- if (!shown) {
52
- shown = 1;
53
- AUD_log (NULL, "Save all your work and restart without audio\n");
54
- AUD_log (NULL, "I am sorry\n");
55
- }
56
- AUD_log (NULL, "Context:\n");
57
- }
58
-
59
- return cond;
60
-}
61
-
47
/*
48
* Convert audio format to mixeng_clip index. Used by audio_pcm_sw_init_ and
49
* audio_mixeng_backend_add_capture()
@@ -332,8 +317,8 @@ static size_t audio_pcm_hw_find_min_in (HWVoiceIn *hw)
317
static size_t audio_pcm_hw_get_live_in(HWVoiceIn *hw)
318
{
319
size_t live = hw->total_samples_captured - audio_pcm_hw_find_min_in (hw);
335
- if (audio_bug(__func__, live > hw->conv_buf.size)) {
336
- dolog("live=%zu hw->conv_buf.size=%zu\n", live, hw->conv_buf.size);
320
+ if (live > hw->conv_buf.size) {
321
+ audio_bug("live=%zu hw->conv_buf.size=%zu", live, hw->conv_buf.size);
322
return 0;
323
}
324
return live;
@@ -402,8 +387,8 @@ static size_t audio_pcm_sw_read(SWVoiceIn *sw, void *buf, size_t buf_len)
387
if (!live) {
388
return 0;
389
}
405
- if (audio_bug(__func__, live > hw->conv_buf.size)) {
406
- dolog("live_in=%zu hw->conv_buf.size=%zu\n", live, hw->conv_buf.size);
390
+ if (live > hw->conv_buf.size) {
391
+ audio_bug("live=%zu hw->conv_buf.size=%zu", live, hw->conv_buf.size);
392
return 0;
393
}
394
@@ -454,8 +439,8 @@ static size_t audio_pcm_hw_get_live_out (HWVoiceOut *hw, int *nb_live)
439
if (nb_live1) {
440
size_t live = smin;
441
457
- if (audio_bug(__func__, live > hw->mix_buf.size)) {
458
- dolog("live=%zu hw->mix_buf.size=%zu\n", live, hw->mix_buf.size);
442
+ if (live > hw->mix_buf.size) {
443
+ audio_bug("live=%zu hw->mix_buf.size=%zu", live, hw->mix_buf.size);
444
return 0;
445
}
446
return live;
@@ -533,8 +518,8 @@ static size_t audio_pcm_sw_write(SWVoiceOut *sw, void *buf, size_t buf_len)
518
size_t frames_in_max, frames_out_max, total_in, total_out;
519
520
live = sw->total_hw_samples_mixed;
536
- if (audio_bug(__func__, live > hw->mix_buf.size)) {
537
- dolog("live=%zu hw->mix_buf.size=%zu\n", live, hw->mix_buf.size);
521
+ if (live > hw->mix_buf.size) {
522
+ audio_bug("live=%zu hw->mix_buf.size=%zu", live, hw->mix_buf.size);
523
return 0;
524
}
525
@@ -824,9 +809,9 @@ static size_t audio_get_avail(SWVoiceIn *sw)
809
}
810
811
live = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
827
- if (audio_bug(__func__, live > sw->hw->conv_buf.size)) {
828
- dolog("live=%zu sw->hw->conv_buf.size=%zu\n", live,
829
- sw->hw->conv_buf.size);
812
+ if (live > sw->hw->conv_buf.size) {
813
+ audio_bug("live=%zu sw->hw->conv_buf.size=%zu", live,
814
+ sw->hw->conv_buf.size);
815
return 0;
816
}
817
@@ -845,9 +830,9 @@ static size_t audio_get_free(SWVoiceOut *sw)
830
831
live = sw->total_hw_samples_mixed;
832
848
- if (audio_bug(__func__, live > sw->hw->mix_buf.size)) {
849
- dolog("live=%zu sw->hw->mix_buf.size=%zu\n", live,
850
- sw->hw->mix_buf.size);
833
+ if (live > sw->hw->mix_buf.size) {
834
+ audio_bug("live=%zu sw->hw->mix_buf.size=%zu", live,
835
+ sw->hw->mix_buf.size);
836
return 0;
837
}
838
@@ -1002,8 +987,8 @@ static void audio_run_out(AudioMixengBackend *s)
987
live = 0;
988
}
989
1005
- if (audio_bug(__func__, live > hw->mix_buf.size)) {
1006
- dolog("live=%zu hw->mix_buf.size=%zu\n", live, hw->mix_buf.size);
990
+ if (live > hw->mix_buf.size) {
991
+ audio_bug("live=%zu hw->mix_buf.size=%zu", live, hw->mix_buf.size);
992
continue;
993
}
994
@@ -1033,9 +1018,9 @@ static void audio_run_out(AudioMixengBackend *s)
1018
prev_rpos = hw->mix_buf.pos;
1019
played = audio_pcm_hw_run_out(hw, live);
1020
replay_audio_out(&played);
1036
- if (audio_bug(__func__, hw->mix_buf.pos >= hw->mix_buf.size)) {
1037
- dolog("hw->mix_buf.pos=%zu hw->mix_buf.size=%zu played=%zu\n",
1038
- hw->mix_buf.pos, hw->mix_buf.size, played);
1021
+ if (hw->mix_buf.pos >= hw->mix_buf.size) {
1022
+ audio_bug("hw->mix_buf.pos=%zu hw->mix_buf.size=%zu played=%zu",
1023
+ hw->mix_buf.pos, hw->mix_buf.size, played);
1024
hw->mix_buf.pos = 0;
1025
}
1026
@@ -1050,9 +1035,9 @@ static void audio_run_out(AudioMixengBackend *s)
1035
continue;
1036
}
1037
1053
- if (audio_bug(__func__, played > sw->total_hw_samples_mixed)) {
1054
- dolog("played=%zu sw->total_hw_samples_mixed=%zu\n",
1055
- played, sw->total_hw_samples_mixed);
1038
+ if (played > sw->total_hw_samples_mixed) {
1039
+ audio_bug("played=%zu sw->total_hw_samples_mixed=%zu",
1040
+ played, sw->total_hw_samples_mixed);
1041
played = sw->total_hw_samples_mixed;
1042
}
1043
@@ -1195,9 +1180,9 @@ static void audio_run_capture(AudioMixengBackend *s)
1180
continue;
1181
}
1182
1198
- if (audio_bug(__func__, captured > sw->total_hw_samples_mixed)) {
1199
- dolog("captured=%zu sw->total_hw_samples_mixed=%zu\n",
1200
- captured, sw->total_hw_samples_mixed);
1183
+ if (captured > sw->total_hw_samples_mixed) {
1184
+ audio_bug("captured=%zu sw->total_hw_samples_mixed=%zu",
1185
+ captured, sw->total_hw_samples_mixed);
1186
captured = sw->total_hw_samples_mixed;
1187
}
1188
audio/audio_int.h
-2
@@ -244,8 +244,6 @@ extern const char *audio_prio_list[];
244
void audio_pcm_init_info (struct audio_pcm_info *info, const struct audsettings *as);
245
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
246
247
-int audio_bug (const char *funcname, int cond);
248
-
247
void audio_run(AudioMixengBackend *s, const char *msg);
248
249
typedef struct RateCtl {
audio/audio_template.h
+19
-19
@@ -64,15 +64,15 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioMixengBackend *s,
64
min_voices);
65
}
66
67
- if (audio_bug(__func__, !voice_size && max_voices)) {
68
- dolog("drv=`%s' voice_size=0 max_voices=%d\n",
69
- k->name, max_voices);
67
+ if (!voice_size && max_voices) {
68
+ audio_bug("drv=`%s' voice_size=0 max_voices=%d",
69
+ k->name, max_voices);
70
glue(s->nb_hw_voices_, TYPE) = 0;
71
}
72
73
- if (audio_bug(__func__, voice_size && !max_voices)) {
74
- dolog("drv=`%s' voice_size=%zu max_voices=0\n",
75
- k->name, voice_size);
73
+ if (voice_size && !max_voices) {
74
+ audio_bug("drv=`%s' voice_size=%zu max_voices=0",
75
+ k->name, voice_size);
76
}
77
}
78
@@ -88,8 +88,8 @@ static void glue(audio_pcm_hw_alloc_resources_, TYPE)(HW *hw)
88
{
89
if (glue(audio_get_pdo_, TYPE)(hw->s->dev)->mixing_engine) {
90
size_t samples = hw->samples;
91
- if (audio_bug(__func__, samples == 0)) {
92
- dolog("Attempted to allocate empty buffer\n");
91
+ if (samples == 0) {
92
+ audio_bug("Attempted to allocate empty buffer");
93
}
94
95
HWBUF.buffer = g_new0(st_sample, samples);
@@ -275,8 +275,8 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioMixengBackend *s,
275
return NULL;
276
}
277
278
- if (audio_bug(__func__, !glue(k->init_, TYPE))) {
279
- dolog("No host audio driver or missing init_%s\n", NAME);
278
+ if (!glue(k->init_, TYPE)) {
279
+ audio_bug("No host audio driver or missing init_%s", NAME);
280
return NULL;
281
}
282
@@ -295,8 +295,8 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioMixengBackend *s,
295
goto err0;
296
}
297
298
- if (audio_bug(__func__, hw->samples <= 0)) {
299
- dolog("hw->samples=%zd\n", hw->samples);
298
+ if (hw->samples <= 0) {
299
+ audio_bug("hw->samples=%zd", hw->samples);
300
goto err1;
301
}
302
@@ -477,8 +477,8 @@ static void glue (audio_close_, TYPE) (SW *sw)
477
static void glue(audio_mixeng_backend_close_, TYPE)(AudioBackend *be, SW *sw)
478
{
479
if (sw) {
480
- if (audio_bug(__func__, !be)) {
481
- dolog("backend=%p\n", be);
480
+ if (!be) {
481
+ audio_bug("backend=%p", be);
482
return;
483
}
484
@@ -498,9 +498,9 @@ static SW *glue(audio_mixeng_backend_open_, TYPE) (
498
AudioMixengBackendClass *k;
499
AudiodevPerDirectionOptions *pdo;
500
501
- if (audio_bug(__func__, !be || !name || !callback_fn || !as)) {
502
- dolog("backend=%p name=%p callback_fn=%p as=%p\n",
503
- be, name, callback_fn, as);
501
+ if (!be || !name || !callback_fn || !as) {
502
+ audio_bug("backend=%p name=%p callback_fn=%p as=%p",
503
+ be, name, callback_fn, as);
504
goto fail;
505
}
506
@@ -519,8 +519,8 @@ static SW *glue(audio_mixeng_backend_open_, TYPE) (
519
goto fail;
520
}
521
522
- if (audio_bug(__func__, !glue(k->init_, TYPE))) {
523
- dolog("Can not open `%s' (no host audio driver)\n", name);
522
+ if (!glue(k->init_, TYPE)) {
523
+ error_report("audio: Can not open `%s' (no host audio driver)", name);
524
goto fail;
525
}
526