From 87f4726164a99f6e02ef1d233a97e67df002ad92 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 15 Feb 2022 15:35:40 +0100 Subject: [PATCH] alsa: protect against impossible timeouts Check if the new timeout is larger than 1sec in the past or future and reprogram a timeout with a saner timeout. --- spa/plugins/alsa/alsa-pcm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c index a0d84bebe..5238c34ef 100644 --- a/spa/plugins/alsa/alsa-pcm.c +++ b/spa/plugins/alsa/alsa-pcm.c @@ -2345,6 +2345,13 @@ static void alsa_on_timeout_event(struct spa_source *source) handle_capture(state, current_time, delay, target); done: + if (state->next_time > current_time + SPA_NSEC_PER_SEC || + current_time > state->next_time + SPA_NSEC_PER_SEC) { + spa_log_error(state->log, "%s: impossible timeout %lu %lu %"PRIu64" %"PRIu64" %"PRIi64 + " %d %"PRIi64, state->props.device, delay, target, current_time, state->next_time, + state->next_time - current_time, state->threshold, state->sample_count); + state->next_time = current_time + state->threshold * 1e9 / state->rate; + } set_timeout(state, state->next_time); }