Index | Thread | Search

From:
Alexandre Ratchov <alex@caoua.org>
Subject:
libsndio: Fix recovery from underruns: please test
To:
tech@openbsd.org
Date:
Fri, 3 Jul 2026 12:38:51 +0200

Download raw body.

Thread
  • Alexandre Ratchov:

    libsndio: Fix recovery from underruns: please test

After an underrun, the device is restarted and libsndio restores the
user-visible state of before the underrun (the clock, read, and write
positions).

The current code accumulates clock ticks that are not reported yet to
the upper layers (in the hdl->cpending variable). As the device is
reset, anything not visible by the upper layer must be reset as well,
which includes hdl->cpending. The diff below fixes that.

This bug may cause permanent audio stuttering or high CPU usage after
underruns, i.e. on busy systems.

Please test, especially if you've experienced above problems.

diff --git a/libsndio/sio.c b/libsndio/sio.c
index 4c83d01..de3beb0 100644
--- a/libsndio/sio.c
+++ b/libsndio/sio.c
@@ -616,6 +616,11 @@ _sio_xrun(struct sio_hdl *hdl)
 	if (hdl->mode & SIO_PLAY)
 		hdl->wsil = hdl->wused + cmove * hdl->par.bps * hdl->par.pchan;
 
+	/*
+	 * Discard any unreported clock ticks
+	 */
+	hdl->cpending = 0;
+
 	DPRINTFN(1, "%s: cmove = %d, wsil = %d, rdrop = %d\n", __func__,
 	    cmove, hdl->wsil, hdl->rdrop);