]> git.alsa-project.org Git - alsa-utils.git/commitdiff
alsactl: add support for new log handler (alsa-lib 1.2.15)
authorJaroslav Kysela <perex@perex.cz>
Fri, 7 Nov 2025 16:00:42 +0000 (17:00 +0100)
committerJaroslav Kysela <perex@perex.cz>
Fri, 7 Nov 2025 16:00:42 +0000 (17:00 +0100)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
alsactl/alsactl.c
alsactl/alsactl.h
alsactl/utils.c
aplay/aplay.c

index 8ad991a0f36bc1cfebcee54fd2507b83f43f377b..5614ea75e3391e3ce1aaab7a4cacc00c631fa9c8 100644 (file)
@@ -441,7 +441,11 @@ int main(int argc, char *argv[])
                        syslog(LOG_INFO, "alsactl " SND_UTIL_VERSION_STR " daemon started");
        }
 
+#if SND_LIB_VER(1, 2, 15) < SND_LIB_VERSION
        snd_lib_error_set_handler(error_handler);
+#else
+       snd_lib_log_set_handler(log_handler);
+#endif
 
        if (!strcmp(cmd, "init")) {
                res = init(cfgdir, initfile, initflags | FLAG_UCM_FBOOT | FLAG_UCM_BOOT, cardname);
index 6ae45e3853069d22c1d38db7df614b3f46cf71d2..f86f8d9c9cc1c4f4901c704c896c5921bd801b5f 100644 (file)
@@ -24,7 +24,8 @@ void info_(const char *fcn, long line, const char *fmt, ...);
 void error_(const char *fcn, long line, const char *fmt, ...);
 void cerror_(const char *fcn, long line, int cond, const char *fmt, ...);
 void dbg_(const char *fcn, long line, const char *fmt, ...);
-void error_handler(const char *file, int line, const char *function, int err, const char *fmt, ...);
+void error_handler(const char *file, int line, const char *function, int errcode, const char *fmt, ...);
+void log_handler(int prio, int interface, const char *file, int line, const char *function, int errcode, const char *fmt, va_list arg);
 
 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
 #define info(...) do { info_(__func__, __LINE__, __VA_ARGS__); } while (0)
index d8cbf535598401b1ddbdc4e80b20c410aba3f7cb..42e6eba3172a5ef36a9d27b9711c5afc184ee24b 100644 (file)
@@ -177,7 +177,7 @@ void dbg_(const char *fcn, long line, const char *fmt, ...)
        va_end(ap);
 }
 
-void error_handler(const char *file, int line, const char *function, int err, const char *fmt, ...)
+void error_handler(const char *file, int line, const char *function, int errcode, const char *fmt, ...)
 {
        char buf[2048];
        va_list arg;
@@ -187,12 +187,36 @@ void error_handler(const char *file, int line, const char *function, int err, co
        va_end(arg);
        if (use_syslog)
                syslog(LOG_ERR, "alsa-lib %s:%i:(%s) %s%s%s\n", file, line, function,
-                               buf, err ? ": " : "", err ? snd_strerror(err) : "");
+                               buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : "");
        else
                fprintf(stderr, "alsa-lib %s:%i:(%s) %s%s%s\n", file, line, function,
-                               buf, err ? ": " : "", err ? snd_strerror(err) : "");
+                               buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : "");
 }
 
+#if SND_LIB_VER(1, 2, 15) >= SND_LIB_VERSION
+void log_handler(int prio, int interface, const char *file, int line, const char *function, int errcode, const char *fmt, va_list arg)
+{
+       char buf[2048], level[50] = "";
+       const char *text1, *text2;
+
+       if (!snd_lib_log_filter(prio, interface, NULL))
+               return;
+
+       text1 = snd_lib_log_priority(prio);
+       text2 = snd_lib_log_interface(interface);
+       if (text1 || text2)
+               snprintf(level, sizeof(level), "[%s.%s] ", text1 ? text1 : "", text2 ? text2 : "");
+
+       vsnprintf(buf, sizeof(buf), fmt, arg);
+       if (use_syslog)
+               syslog(LOG_ERR, "alsa-lib %s:%i:(%s) %s%s%s%s\n", file, line, function, level,
+                               buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : "");
+       else
+               fprintf(stderr, "alsa-lib %s:%i:(%s) %s%s%s%s\n", file, line, function, level,
+                               buf, errcode ? ": " : "", errcode ? snd_strerror(errcode) : "");
+}
+#endif
+
 int load_configuration(const char *file, snd_config_t **top, int *open_failed)
 {
        snd_config_t *config;
index c58c2e98d98155498095d6417ee48379b502bd8a..bdc88c2a180bdb5adc6edcbf6b0ea0f8bb2e62ed 100644 (file)
@@ -1464,6 +1464,13 @@ static void set_params(void)
                      chunk_size, buffer_size);
                prg_exit(EXIT_FAILURE);
        }
+       if (dump_hw_params) {
+               fprintf(stderr, _("HW Params of device \"%s\":\n"),
+                       snd_pcm_name(handle));
+               fprintf(stderr, "--------------------\n");
+               snd_pcm_hw_params_dump(params, log);
+               fprintf(stderr, "--------------------\n");
+       }
        err = snd_pcm_sw_params_current(handle, swparams);
        if (err < 0) {
                error(_("Unable to get current sw params."));