libsndio: Fix recovery from underruns: please test

Alexandre Ratchov <[email protected]>
Newsgroups gmane.os.openbsd.tech
Message-ID <[email protected]>
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);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.