From b2101352b6dada91ec09aae455e6bc8a662b1895 Mon Sep 17 00:00:00 2001 From: e_kumalija Date: Fri, 14 Oct 2022 13:20:25 +0900 Subject: [PATCH] log xrun trigger --- include/error.h | 17 +++++++++++++++++ src/pcm/pcm_dmix.c | 2 ++ 2 files changed, 19 insertions(+) diff --git a/include/error.h b/include/error.h index 7239db85..b5d222a1 100644 --- a/include/error.h +++ b/include/error.h @@ -74,6 +74,23 @@ extern int snd_lib_error_set_handler(snd_lib_error_handler_t handler); } #endif +#define ALSALIB_LOG_FILE "/var/log/alsa_log.txt" + +//append log to existing file +#define alsaLib_log_write(fmt, ...) { \ + FILE *fp = fopen(ALSALIB_LOG_FILE,"a"); \ + if(fp){ \ + time_t time_sec; \ + unsigned long time_ms; \ + struct timespec now; \ + clock_gettime(CLOCK_MONOTONIC,&now); \ + time_sec = now.tv_sec; \ + time_ms = now.tv_nsec/1000000; \ + fprintf(fp,"%lu.%03lu," fmt, time_sec, time_ms, ##__VA_ARGS__); \ + fclose(fp); \ + } \ +} + /** Local error handler function type */ typedef void (*snd_local_error_handler_t)(const char *file, int line, const char *func, int err, diff --git a/src/pcm/pcm_dmix.c b/src/pcm/pcm_dmix.c index d533f40c..d8e76c8e 100644 --- a/src/pcm/pcm_dmix.c +++ b/src/pcm/pcm_dmix.c @@ -44,6 +44,7 @@ #include #include #include "pcm_direct.h" +#include "error.h" #ifndef PIC /* entry for static linking */ @@ -422,6 +423,7 @@ static int snd_pcm_dmix_sync_ptr0(snd_pcm_t *pcm, snd_pcm_uframes_t slave_hw_ptr gettimestamp(&dmix->trigger_tstamp, pcm->tstamp_type); if (dmix->state == SND_PCM_STATE_RUNNING) { dmix->state = SND_PCM_STATE_XRUN; + alsaLib_log_write("Xrun avail size =%lu stop_threshold=%lu",avail,pcm->stop_threshold); return -EPIPE; } dmix->state = SND_PCM_STATE_SETUP;