From 8bc1bc53d0a8b3797337bddd30cd345ba1049817 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Wed, 24 Oct 2018 15:20:22 +0200 Subject: [PATCH] alsaloop: more avail_min cleanups 1) do not increase avail_min forever It seems that there are broken plugins like pulse which returns from poll() immediately regardless avail_min settings. 2) remove ommited debug printf() Signed-off-by: Jaroslav Kysela --- alsaloop/pcmjob.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/alsaloop/pcmjob.c b/alsaloop/pcmjob.c index 9cf3a5b..4c9517b 100644 --- a/alsaloop/pcmjob.c +++ b/alsaloop/pcmjob.c @@ -286,8 +286,16 @@ static int increase_playback_avail_min(struct loopback_handle *lhandle) { snd_pcm_t *handle = lhandle->handle; snd_pcm_sw_params_t *swparams; + struct timespec ts; int err; + if (lhandle->avail_min + (lhandle->period_size / 2) > lhandle->buffer_size) { + /* avoid 100% CPU usage for broken plugins */ + ts.tv_sec = 0; + ts.tv_nsec = 10000; + err = nanosleep(&ts, NULL); + return 0; + } snd_pcm_sw_params_alloca(&swparams); err = snd_pcm_sw_params_current(handle, swparams); if (err < 0) { @@ -302,7 +310,6 @@ static int increase_playback_avail_min(struct loopback_handle *lhandle) snd_pcm_sw_params_get_avail_min(swparams, &lhandle->avail_min); if (verbose > 6) snd_output_printf(lhandle->loopback->output, "%s: change avail_min=%li\n", lhandle->id, lhandle->avail_min); - printf("%s: change avail_min=%li\n", lhandle->id, lhandle->avail_min); err = snd_pcm_sw_params(handle, swparams); if (err < 0) { logit(LOG_CRIT, "Unable to set sw params for %s: %s\n", lhandle->id, snd_strerror(err));