1
0
mirror of https://github.com/openbsd/src.git synced 2026-06-18 23:33:33 +02:00

libsndio: Factor handling of pending clock ticks

No behavior change.
This commit is contained in:
ratchov
2026-03-10 06:23:44 +00:00
parent c1cc2b6b41
commit 4c33f35552
4 changed files with 28 additions and 30 deletions
+13 -7
View File
@@ -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 <alex@caoua.org>
*
@@ -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;
}
+4 -10
View File
@@ -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 <alex@caoua.org>
*
@@ -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);
+2 -1
View File
@@ -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 <alex@caoua.org>
*
@@ -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
+9 -12
View File
@@ -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 <alex@caoua.org>
*
@@ -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;
}