mirror of https://github.com/ericonr/sndio.git
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.
This commit is contained in:
parent
25e3fe8839
commit
e451d47880
|
@ -902,6 +902,30 @@ sio_sun_revents(struct sio_hdl *sh, struct pollfd *pfd)
|
||||||
|
|
||||||
if (!hdl->sio.started)
|
if (!hdl->sio.started)
|
||||||
return pfd->revents;
|
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 (hdl->sio.mode & SIO_PLAY) {
|
||||||
if (ioctl(hdl->fd, AUDIO_PERROR, &xrun) < 0) {
|
if (ioctl(hdl->fd, AUDIO_PERROR, &xrun) < 0) {
|
||||||
DPERROR("sio_sun_revents: PERROR");
|
DPERROR("sio_sun_revents: PERROR");
|
||||||
|
@ -929,30 +953,6 @@ sio_sun_revents(struct sio_hdl *sh, struct pollfd *pfd)
|
||||||
hdl->idelta -= dmove;
|
hdl->idelta -= dmove;
|
||||||
hdl->odelta -= 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;
|
delta = (hdl->idelta > hdl->odelta) ? hdl->idelta : hdl->odelta;
|
||||||
if (delta > 0) {
|
if (delta > 0) {
|
||||||
sio_onmove_cb(&hdl->sio, delta);
|
sio_onmove_cb(&hdl->sio, delta);
|
||||||
|
|
Loading…
Reference in New Issue