From: Marc-André Lureau <[email protected]> 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 <[email protected]> Reviewed-by: Akihiko Odaki <[email protected]> Signed-off-by: Marc-André Lureau <[email protected]> --- audio/audio_template.h | 5 +++-- audio/audio-mixeng-be.c | 41 +++++++---------------------------------- 2 files changed, 10 insertions(+), 36 deletions(-) diff --git a/audio/audio_template.h b/audio/audio_template.h index e884c8e9b1a..5711f4a26e1 100644 --- a/audio/audio_template.h +++ b/audio/audio_template.h @@ -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; } diff --git a/audio/audio-mixeng-be.c b/audio/audio-mixeng-be.c index 7eabb1c2505..bb8c0b56f78 100644 --- a/audio/audio-mixeng-be.c +++ b/audio/audio-mixeng-be.c @@ -101,38 +101,11 @@ void AUD_log (const char *cap, const char *fmt, ...) va_end (ap); } -static void audio_print_settings (const struct audsettings *as) +static char *audsettings_to_string(const struct audsettings *as) { - dolog ("frequency=%d nchannels=%d fmt=", as->freq, as->nchannels); - - switch (as->fmt) { - case AUDIO_FORMAT_S8: - AUD_log (NULL, "S8"); - break; - case AUDIO_FORMAT_U8: - AUD_log (NULL, "U8"); - break; - case AUDIO_FORMAT_S16: - AUD_log (NULL, "S16"); - break; - case AUDIO_FORMAT_U16: - AUD_log (NULL, "U16"); - break; - case AUDIO_FORMAT_S32: - AUD_log (NULL, "S32"); - break; - case AUDIO_FORMAT_U32: - AUD_log (NULL, "U32"); - break; - case AUDIO_FORMAT_F32: - AUD_log (NULL, "F32"); - break; - default: - AUD_log (NULL, "invalid(%d)", as->fmt); - break; - } - - AUD_log (NULL, " endianness=%s\n", as->big_endian ? "big" : "little"); + return g_strdup_printf("frequency=%d nchannels=%d fmt=%s endian=%s", + as->freq, as->nchannels, AudioFormat_str(as->fmt), + as->big_endian ? "big" : "little"); } static int audio_validate_settings (const struct audsettings *as) @@ -1607,9 +1580,9 @@ static CaptureVoiceOut *audio_mixeng_backend_add_capture( return NULL; } - if (audio_validate_settings (as)) { - dolog ("Invalid settings were passed when trying to add capture\n"); - audio_print_settings (as); + if (audio_validate_settings(as)) { + g_autofree char *str = audsettings_to_string(as); + error_report("audio: Invalid audio settings when trying to add capture: %s", str); return NULL; } -- 2.53.0
