From 5edf5253143331f82c35ebb8970d18cabc3495c0 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Fri, 31 Jul 2015 17:35:54 +0200 Subject: [PATCH] switch to now AUDIO_GETPOS interface --- libsndio/sio_sun.c | 67 +++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 43 deletions(-) diff --git a/libsndio/sio_sun.c b/libsndio/sio_sun.c index a6b7a57..db44f3c 100644 --- a/libsndio/sio_sun.c +++ b/libsndio/sio_sun.c @@ -806,65 +806,46 @@ int sio_sun_revents(struct sio_hdl *sh, struct pollfd *pfd) { struct sio_sun_hdl *hdl = (struct sio_sun_hdl *)sh; - struct audio_offset ao; - int xrun, dierr = 0, doerr = 0, offset, delta; + struct audio_pos ap; + int dierr = 0, doerr = 0, offset, delta; int revents = pfd->revents; if (!hdl->sio.started) 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 (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)) + delta = (ap.play_pos - hdl->obytes) / hdl->obpf; + doerr = (ap.play_xrun - hdl->oerr) / hdl->obpf; + hdl->obytes = ap.play_pos; + hdl->oerr = ap.play_xrun; + hdl->odelta += delta; + if (!(hdl->sio.mode & SIO_REC)) { 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; + } if (doerr > 0) DPRINTFN(2, "play xrun %d\n", doerr); } if (hdl->sio.mode & SIO_REC) { - if (ioctl(hdl->fd, AUDIO_RERROR, &xrun) < 0) { - DPERROR("sio_sun_revents: RERROR"); - hdl->sio.eof = 1; - return POLLHUP; - } - dierr = xrun - hdl->ierr; - hdl->ierr = xrun; - if (!(hdl->sio.mode & SIO_PLAY)) + delta = (ap.rec_pos - hdl->ibytes) / hdl->ibpf; + dierr = (ap.rec_xrun - hdl->ierr) / hdl->ibpf; + hdl->ibytes = ap.rec_pos; + hdl->ierr = ap.rec_xrun; + hdl->idelta += delta; + if (!(hdl->sio.mode & SIO_PLAY)) { + hdl->odelta += delta; doerr = dierr; + } if (dierr > 0) 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 */ 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); } else if (offset < 0) { hdl->sio.wsil += -offset * hdl->obpf; - hdl->odelta -= offset; + hdl->odelta -= -offset; DPRINTFN(2, "will insert %d and pause %d\n", -offset, dierr); }