diff options
author | 2012-09-14 22:50:26 +0000 | |
---|---|---|
committer | 2012-09-14 22:50:26 +0000 | |
commit | e7d2a37c8646f3d5c75d61b39b55f4c99ef5b89d (patch) | |
tree | fdf8bcddedb952029fe29e17824a38f03deac753 /lib | |
parent | Have mio_open(3) document all return values in the RETURN VALUES section. (diff) | |
download | wireguard-openbsd-e7d2a37c8646f3d5c75d61b39b55f4c99ef5b89d.tar.xz wireguard-openbsd-e7d2a37c8646f3d5c75d61b39b55f4c99ef5b89d.zip |
Don't read the xrun counter before the offset in the audio ring,
otherwise we'd open a tiny time window during which a xrun may occur
in turn making the sio_onmove() clock wrong during one tick.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libsndio/sio_sun.c | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/lib/libsndio/sio_sun.c b/lib/libsndio/sio_sun.c index f63f7581d2c..880017566be 100644 --- a/lib/libsndio/sio_sun.c +++ b/lib/libsndio/sio_sun.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sio_sun.c,v 1.6 2012/04/11 06:05:43 ratchov Exp $ */ +/* $OpenBSD: sio_sun.c,v 1.7 2012/09/14 22:50:26 ratchov Exp $ */ /* * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org> * @@ -900,6 +900,30 @@ sio_sun_revents(struct sio_hdl *sh, struct pollfd *pfd) if (!hdl->sio.started) return pfd->revents; + if ((revents & POLLOUT) && (hdl->sio.mode & SIO_PLAY)) { + if (ioctl(hdl->fd, AUDIO_GETOOFFS, &ao) < 0) { + DPERROR("sio_sun_revents: GETOOFFS"); + hdl->sio.eof = 1; + return POLLHUP; + } + delta = (ao.samples - hdl->obytes) / hdl->obpf; + hdl->obytes = ao.samples; + hdl->odelta += delta; + if (!(hdl->sio.mode & SIO_REC)) + hdl->idelta += delta; + } + if ((revents & POLLIN) && (hdl->sio.mode & SIO_REC)) { + if (ioctl(hdl->fd, AUDIO_GETIOFFS, &ao) < 0) { + DPERROR("sio_sun_revents: GETIOFFS"); + hdl->sio.eof = 1; + return POLLHUP; + } + delta = (ao.samples - hdl->ibytes) / hdl->ibpf; + hdl->ibytes = ao.samples; + hdl->idelta += delta; + if (!(hdl->sio.mode & SIO_PLAY)) + hdl->odelta += delta; + } if (hdl->sio.mode & SIO_PLAY) { if (ioctl(hdl->fd, AUDIO_PERROR, &xrun) < 0) { DPERROR("sio_sun_revents: PERROR"); @@ -927,30 +951,6 @@ sio_sun_revents(struct sio_hdl *sh, struct pollfd *pfd) hdl->idelta -= dmove; hdl->odelta -= dmove; - if ((revents & POLLOUT) && (hdl->sio.mode & SIO_PLAY)) { - if (ioctl(hdl->fd, AUDIO_GETOOFFS, &ao) < 0) { - DPERROR("sio_sun_revents: GETOOFFS"); - hdl->sio.eof = 1; - return POLLHUP; - } - delta = (ao.samples - hdl->obytes) / hdl->obpf; - hdl->obytes = ao.samples; - hdl->odelta += delta; - if (!(hdl->sio.mode & SIO_REC)) - hdl->idelta += delta; - } - if ((revents & POLLIN) && (hdl->sio.mode & SIO_REC)) { - if (ioctl(hdl->fd, AUDIO_GETIOFFS, &ao) < 0) { - DPERROR("sio_sun_revents: GETIOFFS"); - hdl->sio.eof = 1; - return POLLHUP; - } - delta = (ao.samples - hdl->ibytes) / hdl->ibpf; - hdl->ibytes = ao.samples; - hdl->idelta += delta; - if (!(hdl->sio.mode & SIO_PLAY)) - hdl->odelta += delta; - } delta = (hdl->idelta > hdl->odelta) ? hdl->idelta : hdl->odelta; if (delta > 0) { sio_onmove_cb(&hdl->sio, delta); |