audio: rework invalid audsettings error
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 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 22, 2026 at 01:51 UTC
358b0519e7c8f2a34399126a58a3a95ef681653d
2 files changed
+10
-36
audio/audio-mixeng-be.c
+7
-34
@@ -101,38 +101,11 @@ void AUD_log (const char *cap, const char *fmt, ...)
101
va_end (ap);
102
}
103
104
-static void audio_print_settings (const struct audsettings *as)
104
+static char *audsettings_to_string(const struct audsettings *as)
105
{
106
- dolog ("frequency=%d nchannels=%d fmt=", as->freq, as->nchannels);
107
-
108
- switch (as->fmt) {
109
- case AUDIO_FORMAT_S8:
110
- AUD_log (NULL, "S8");
111
- break;
112
- case AUDIO_FORMAT_U8:
113
- AUD_log (NULL, "U8");
114
- break;
115
- case AUDIO_FORMAT_S16:
116
- AUD_log (NULL, "S16");
117
- break;
118
- case AUDIO_FORMAT_U16:
119
- AUD_log (NULL, "U16");
120
- break;
121
- case AUDIO_FORMAT_S32:
122
- AUD_log (NULL, "S32");
123
- break;
124
- case AUDIO_FORMAT_U32:
125
- AUD_log (NULL, "U32");
126
- break;
127
- case AUDIO_FORMAT_F32:
128
- AUD_log (NULL, "F32");
129
- break;
130
- default:
131
- AUD_log (NULL, "invalid(%d)", as->fmt);
132
- break;
133
- }
134
-
135
- AUD_log (NULL, " endianness=%s\n", as->big_endian ? "big" : "little");
106
+ return g_strdup_printf("frequency=%d nchannels=%d fmt=%s endian=%s",
107
+ as->freq, as->nchannels, AudioFormat_str(as->fmt),
108
+ as->big_endian ? "big" : "little");
109
}
110
111
static int audio_validate_settings (const struct audsettings *as)
@@ -1607,9 +1580,9 @@ static CaptureVoiceOut *audio_mixeng_backend_add_capture(
1580
return NULL;
1581
}
1582
1610
- if (audio_validate_settings (as)) {
1611
- dolog ("Invalid settings were passed when trying to add capture\n");
1612
- audio_print_settings (as);
1583
+ if (audio_validate_settings(as)) {
1584
+ g_autofree char *str = audsettings_to_string(as);
1585
+ error_report("audio: Invalid audio settings when trying to add capture: %s", str);
1586
return NULL;
1587
}
1588
audio/audio_template.h
+3
-2
@@ -513,8 +513,9 @@ static SW *glue(audio_mixeng_backend_open_, TYPE) (
513
trace_audio_open_in(name, as->freq, as->nchannels, as->fmt);
514
#endif
515
516
- if (audio_bug(__func__, audio_validate_settings(as))) {
517
- audio_print_settings (as);
516
+ if (audio_validate_settings(as)) {
517
+ g_autofree char *str = audsettings_to_string(as);
518
+ error_report("audio: Invalid audio settings: %s", str);
519
goto fail;
520
}
521