From bbbe3462b4e3a48f03d6f23e061184f1755a0ac8 Mon Sep 17 00:00:00 2001 From: "Igor V. Kovalenko" Date: Tue, 30 Dec 2025 19:18:10 +0300 Subject: [PATCH] Handle alsa-lib 1.2.15 logging change --- src/modules/alsa/alsa-util.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/modules/alsa/alsa-util.c b/src/modules/alsa/alsa-util.c index d3c092f52..6b5939bb6 100644 --- a/src/modules/alsa/alsa-util.c +++ b/src/modules/alsa/alsa-util.c @@ -49,6 +49,11 @@ #include #endif +// alsa-lib < 1.2.5 does not have SND_LIB_VER() version macro +#if !defined(SND_LIB_VER) +#define SND_LIB_VER(X,Y,Z) (((X)<<16)|((Y)<<8)|(Z)) +#endif + static int set_format(snd_pcm_t *pcm_handle, snd_pcm_hw_params_t *hwparams, pa_sample_format_t *f) { static const snd_pcm_format_t format_trans[] = { @@ -892,6 +897,20 @@ finish: snd_output_close(out); } +#if SND_LIB_VERSION >= SND_LIB_VER(1, 2, 15) +static void alsa_log_handler(int prio, int interface, const char *file, int line, const char *function, int errcode, const char *fmt, va_list arg) { + char *alsa_file; + + if (!snd_lib_log_filter(prio, interface, NULL)) + return; + + alsa_file = pa_sprintf_malloc("(alsa-lib) %s", file); + + pa_log_levelv_meta(PA_LOG_INFO, alsa_file, line, function, fmt, arg); + + pa_xfree(alsa_file); +} +#else static void alsa_error_handler(const char *file, int line, const char *function, int err, const char *fmt,...) { va_list ap; char *alsa_file; @@ -906,14 +925,21 @@ static void alsa_error_handler(const char *file, int line, const char *function, pa_xfree(alsa_file); } +#endif static pa_atomic_t n_error_handler_installed = PA_ATOMIC_INIT(0); void pa_alsa_refcnt_inc(void) { /* This is not really thread safe, but we do our best */ - if (pa_atomic_inc(&n_error_handler_installed) == 0) + if (pa_atomic_inc(&n_error_handler_installed) == 0) { + /* alsa-lib messages are printed to stderr by default, intercept them */ +#if SND_LIB_VERSION >= SND_LIB_VER(1, 2, 15) + snd_lib_log_set_handler(alsa_log_handler); +#else snd_lib_error_set_handler(alsa_error_handler); +#endif + } } void pa_alsa_refcnt_dec(void) { @@ -922,7 +948,11 @@ void pa_alsa_refcnt_dec(void) { pa_assert_se((r = pa_atomic_dec(&n_error_handler_installed)) >= 1); if (r == 1) { +#if SND_LIB_VERSION >= SND_LIB_VER(1, 2, 15) + snd_lib_log_set_handler(NULL); +#else snd_lib_error_set_handler(NULL); +#endif snd_config_update_free_global(); } }