diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2012-09-14 22:50:27 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2012-09-14 22:50:27 +0000 |
commit | a6884d91d148b2e2f115eb1c4fe24bd146ddc446 (patch) | |
tree | 012f904cf869b63a70b26caa62902bb77dbde1f1 | |
parent | 854769fa09bfb3ff86a0b94132631214f7b25a67 (diff) |
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.
-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); |