diff --git a/lib/libsndio/sio.c b/lib/libsndio/sio.c index 02e8a8dd176..5ec306a8126 100644 --- a/lib/libsndio/sio.c +++ b/lib/libsndio/sio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sio.c,v 1.28 2026/01/22 09:24:26 ratchov Exp $ */ +/* $OpenBSD: sio.c,v 1.29 2026/03/10 06:23:44 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov * @@ -112,6 +112,7 @@ sio_start(struct sio_hdl *hdl) return 0; } hdl->cpos = 0; + hdl->cpending = 0; hdl->rused = hdl->wused = 0; if (!sio_getpar(hdl, &hdl->par)) return 0; @@ -494,20 +495,24 @@ _sio_printpos(struct sio_hdl *hdl) wdiff = wdiff - wround; } DPRINTF("%011lld: " - "clk %+5lld%+5lld, wr %+5lld%+5lld rd: %+5lld%+5lld\n", + "clk %+5lld%+5lld, wr %+5lld%+5lld rd: %+5lld%+5lld (cpending: %d)\n", 1000000000LL * ts.tv_sec + ts.tv_nsec - hdl->start_nsec, - cpos, cdiff, wpos, wdiff, rpos, rdiff); + cpos, cdiff, wpos, wdiff, rpos, rdiff, hdl->cpending); } #endif void _sio_onmove_cb(struct sio_hdl *hdl, int delta) { - hdl->cpos += delta; + hdl->cpending += delta; + if (hdl->cpending <= 0) + return; + + hdl->cpos += hdl->cpending; if (hdl->mode & SIO_REC) - hdl->rused += delta * (hdl->par.bps * hdl->par.rchan); + hdl->rused += hdl->cpending * (hdl->par.bps * hdl->par.rchan); if (hdl->mode & SIO_PLAY) - hdl->wused -= delta * (hdl->par.bps * hdl->par.pchan); + hdl->wused -= hdl->cpending * (hdl->par.bps * hdl->par.pchan); #ifdef DEBUG if (_sndio_debug >= 3) _sio_printpos(hdl); @@ -518,7 +523,8 @@ _sio_onmove_cb(struct sio_hdl *hdl, int delta) } #endif if (hdl->move_cb) - hdl->move_cb(hdl->move_addr, delta); + hdl->move_cb(hdl->move_addr, hdl->cpending); + hdl->cpending = 0; hdl->xrun = 0; } diff --git a/lib/libsndio/sio_aucat.c b/lib/libsndio/sio_aucat.c index 3745defe0a9..bca50f463bf 100644 --- a/lib/libsndio/sio_aucat.c +++ b/lib/libsndio/sio_aucat.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sio_aucat.c,v 1.22 2026/01/22 09:24:26 ratchov Exp $ */ +/* $OpenBSD: sio_aucat.c,v 1.23 2026/03/10 06:23:44 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov * @@ -38,7 +38,6 @@ struct sio_aucat_hdl { unsigned int rbpf, wbpf; /* read and write bytes-per-frame */ int events; /* events the user requested */ unsigned int curvol, reqvol; /* current and requested volume */ - int delta; /* some of received deltas */ #define PSTATE_INIT 0 #define PSTATE_RUN 1 int pstate; @@ -107,13 +106,9 @@ sio_aucat_runmsg(struct sio_aucat_hdl *hdl) break; case AMSG_MOVE: delta = ntohl(hdl->aucat.rmsg.u.ts.delta); - hdl->delta += delta; - DPRINTFN(3, "aucat: move(%d), delta = %d, maxwrite = %d\n", - delta, hdl->delta, hdl->aucat.maxwrite); - if (hdl->delta >= 0) { - _sio_onmove_cb(&hdl->sio, hdl->delta); - hdl->delta = 0; - } + DPRINTFN(3, "aucat: move(%d), maxwrite = %d\n", + delta, hdl->aucat.maxwrite); + _sio_onmove_cb(&hdl->sio, delta); break; case AMSG_XRUN: DPRINTFN(3, "aucat: xrun\n"); @@ -195,7 +190,6 @@ sio_aucat_start(struct sio_hdl *sh) hdl->rbpf = hdl->sio.par.bps * hdl->sio.par.rchan; hdl->aucat.maxwrite = 0; hdl->round = hdl->sio.par.round; - hdl->delta = 0; DPRINTFN(2, "aucat: start, maxwrite = %d\n", hdl->aucat.maxwrite); AMSG_INIT(&hdl->aucat.wmsg); diff --git a/lib/libsndio/sio_priv.h b/lib/libsndio/sio_priv.h index 206b7b2119d..8d711a493bf 100644 --- a/lib/libsndio/sio_priv.h +++ b/lib/libsndio/sio_priv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sio_priv.h,v 1.13 2026/01/22 09:24:26 ratchov Exp $ */ +/* $OpenBSD: sio_priv.h,v 1.14 2026/03/10 06:23:44 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov * @@ -41,6 +41,7 @@ struct sio_hdl { int rused; /* bytes used in read buffer */ int wused; /* bytes used in write buffer */ int xrun; /* xrun reported */ + int cpending; /* clock ticks not reported yet */ long long cpos; /* clock since start */ struct sio_par par; #ifdef DEBUG diff --git a/lib/libsndio/sio_sun.c b/lib/libsndio/sio_sun.c index 11b6efbe1dc..10bfc5cb413 100644 --- a/lib/libsndio/sio_sun.c +++ b/lib/libsndio/sio_sun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sio_sun.c,v 1.33 2026/01/22 09:24:26 ratchov Exp $ */ +/* $OpenBSD: sio_sun.c,v 1.34 2026/03/10 06:23:44 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov * @@ -617,17 +617,15 @@ sio_sun_xrun(struct sio_sun_hdl *hdl) */ cmove += hdl->sio.par.round; } - hdl->idelta = -cmove; } - if (hdl->sio.mode & SIO_PLAY) { + if (hdl->sio.mode & SIO_PLAY) hdl->sio.wsil = hdl->sio.wused + cmove * hdl->obpf; - hdl->odelta = -cmove; - } DPRINTFN(1, "%s: cmove = %d, wsil = %d, rdrop = %d\n", __func__, cmove, hdl->sio.wsil, hdl->sio.rdrop); + _sio_onmove_cb(&hdl->sio, -cmove); return 1; } @@ -690,12 +688,11 @@ sio_sun_revents(struct sio_hdl *sh, struct pollfd *pfd) */ delta = hdl->odelta > hdl->idelta ? hdl->odelta : hdl->idelta; } - if (delta > 0) { - _sio_onmove_cb(&hdl->sio, delta); - if (hdl->sio.mode & SIO_PLAY) - hdl->odelta -= delta; - if (hdl->sio.mode & SIO_REC) - hdl->idelta -= delta; - } + _sio_onmove_cb(&hdl->sio, delta); + if (hdl->sio.mode & SIO_PLAY) + hdl->odelta -= delta; + if (hdl->sio.mode & SIO_REC) + hdl->idelta -= delta; + return revents; }