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:
Alexandre Ratchov 2012-09-15 01:35:39 +02:00
parent 25e3fe8839
commit e451d47880
1 changed files with 24 additions and 24 deletions

View File

@ -902,6 +902,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");
@ -929,30 +953,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);