switch to now AUDIO_GETPOS interface

This commit is contained in:
Alexandre Ratchov 2015-07-31 17:35:54 +02:00
parent 4ca9db857c
commit 5edf525314
1 changed files with 24 additions and 43 deletions

View File

@ -806,65 +806,46 @@ int
sio_sun_revents(struct sio_hdl *sh, struct pollfd *pfd) sio_sun_revents(struct sio_hdl *sh, struct pollfd *pfd)
{ {
struct sio_sun_hdl *hdl = (struct sio_sun_hdl *)sh; struct sio_sun_hdl *hdl = (struct sio_sun_hdl *)sh;
struct audio_offset ao; struct audio_pos ap;
int xrun, dierr = 0, doerr = 0, offset, delta; int dierr = 0, doerr = 0, offset, delta;
int revents = pfd->revents; int revents = pfd->revents;
if (!hdl->sio.started) if (!hdl->sio.started)
return pfd->revents; return pfd->revents;
if (ioctl(hdl->fd, AUDIO_GETPOS, &ap) < 0) {
DPERROR("sio_sun_revents: GETPOS");
hdl->sio.eof = 1;
return POLLHUP;
}
if (hdl->sio.mode & SIO_PLAY) { if (hdl->sio.mode & SIO_PLAY) {
if (ioctl(hdl->fd, AUDIO_GETOOFFS, &ao) < 0) { delta = (ap.play_pos - hdl->obytes) / hdl->obpf;
DPERROR("sio_sun_revents: GETOOFFS"); doerr = (ap.play_xrun - hdl->oerr) / hdl->obpf;
hdl->sio.eof = 1; hdl->obytes = ap.play_pos;
return POLLHUP; hdl->oerr = ap.play_xrun;
} hdl->odelta += delta;
delta = (ao.samples - hdl->obytes) / hdl->obpf; if (!(hdl->sio.mode & SIO_REC)) {
hdl->obytes = ao.samples;
hdl->odelta += delta;
if (!(hdl->sio.mode & SIO_REC))
hdl->idelta += delta; hdl->idelta += delta;
}
if (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");
hdl->sio.eof = 1;
return POLLHUP;
}
doerr = xrun - hdl->oerr;
hdl->oerr = xrun;
if (!(hdl->sio.mode & SIO_REC))
dierr = doerr; dierr = doerr;
}
if (doerr > 0) if (doerr > 0)
DPRINTFN(2, "play xrun %d\n", doerr); DPRINTFN(2, "play xrun %d\n", doerr);
} }
if (hdl->sio.mode & SIO_REC) { if (hdl->sio.mode & SIO_REC) {
if (ioctl(hdl->fd, AUDIO_RERROR, &xrun) < 0) { delta = (ap.rec_pos - hdl->ibytes) / hdl->ibpf;
DPERROR("sio_sun_revents: RERROR"); dierr = (ap.rec_xrun - hdl->ierr) / hdl->ibpf;
hdl->sio.eof = 1; hdl->ibytes = ap.rec_pos;
return POLLHUP; hdl->ierr = ap.rec_xrun;
} hdl->idelta += delta;
dierr = xrun - hdl->ierr; if (!(hdl->sio.mode & SIO_PLAY)) {
hdl->ierr = xrun; hdl->odelta += delta;
if (!(hdl->sio.mode & SIO_PLAY))
doerr = dierr; doerr = dierr;
}
if (dierr > 0) if (dierr > 0)
DPRINTFN(2, "rec xrun %d\n", dierr); DPRINTFN(2, "rec xrun %d\n", dierr);
} }
/* /*
* GET{I,O}OFFS report positions including xruns, * GETPOS reports positions including xruns,
* so we have to substract to get the real position * so we have to substract to get the real position
*/ */
hdl->idelta -= dierr; hdl->idelta -= dierr;
@ -877,7 +858,7 @@ sio_sun_revents(struct sio_hdl *sh, struct pollfd *pfd)
DPRINTFN(2, "will drop %d and pause %d\n", offset, doerr); DPRINTFN(2, "will drop %d and pause %d\n", offset, doerr);
} else if (offset < 0) { } else if (offset < 0) {
hdl->sio.wsil += -offset * hdl->obpf; hdl->sio.wsil += -offset * hdl->obpf;
hdl->odelta -= offset; hdl->odelta -= -offset;
DPRINTFN(2, "will insert %d and pause %d\n", -offset, dierr); DPRINTFN(2, "will insert %d and pause %d\n", -offset, dierr);
} }