From 75acc22776b421374cab73f55d620ea136ea07a0 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Fri, 20 Aug 2010 00:11:52 +0200 Subject: [PATCH] recommit max delta'' fix, backed out by mistake --- libsndio/sun.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/libsndio/sun.c b/libsndio/sun.c index f032edf..0b87f87 100644 --- a/libsndio/sun.c +++ b/libsndio/sun.c @@ -25,6 +25,7 @@ * implement generic blocking sio_read() and sio_write() with poll(2) * and use non-blocking sio_ops only */ + #ifdef USE_SUN #include #include @@ -891,7 +892,7 @@ sun_revents(struct sio_hdl *sh, struct pollfd *pfd) { struct sun_hdl *hdl = (struct sun_hdl *)sh; struct audio_offset ao; - int xrun, dmove, dierr = 0, doerr = 0, doffset = 0; + int xrun, dmove, dierr = 0, doerr = 0, delta; int revents = pfd->revents; if (hdl->sio.mode & SIO_PLAY) { @@ -902,8 +903,8 @@ sun_revents(struct sio_hdl *sh, struct pollfd *pfd) } doerr = xrun - hdl->oerr; hdl->oerr = xrun; - if (hdl->sio.mode & SIO_REC) - doffset += doerr; + if (!(hdl->sio.mode & SIO_REC)) + dierr = doerr; } if (hdl->sio.mode & SIO_REC) { if (ioctl(hdl->fd, AUDIO_RERROR, &xrun) < 0) { @@ -913,10 +914,10 @@ sun_revents(struct sio_hdl *sh, struct pollfd *pfd) } dierr = xrun - hdl->ierr; hdl->ierr = xrun; - if (hdl->sio.mode & SIO_PLAY) - doffset -= dierr; + if (!(hdl->sio.mode & SIO_PLAY)) + doerr = dierr; } - hdl->offset += doffset; + hdl->offset += doerr - dierr; dmove = dierr > doerr ? dierr : doerr; hdl->idelta -= dmove; hdl->odelta -= dmove; @@ -927,25 +928,29 @@ sun_revents(struct sio_hdl *sh, struct pollfd *pfd) hdl->sio.eof = 1; return POLLHUP; } - hdl->odelta += (ao.samples - hdl->obytes) / hdl->obpf; + delta = (ao.samples - hdl->obytes) / hdl->obpf; hdl->obytes = ao.samples; - if (hdl->odelta > 0) { - sio_onmove_cb(&hdl->sio, hdl->odelta); - hdl->odelta = 0; - } + hdl->odelta += delta; + if (!(hdl->sio.mode & SIO_REC)) + hdl->idelta += delta; } - if ((revents & POLLIN) && !(hdl->sio.mode & SIO_PLAY)) { + if ((revents & POLLIN) && (hdl->sio.mode & SIO_REC)) { if (ioctl(hdl->fd, AUDIO_GETIOFFS, &ao) < 0) { DPERROR("sun_revents: GETIOFFS"); hdl->sio.eof = 1; return POLLHUP; } - hdl->idelta += (ao.samples - hdl->ibytes) / hdl->ibpf; + delta = (ao.samples - hdl->ibytes) / hdl->ibpf; hdl->ibytes = ao.samples; - if (hdl->idelta > 0) { - sio_onmove_cb(&hdl->sio, hdl->idelta); - hdl->idelta = 0; - } + 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); + hdl->idelta -= delta; + hdl->odelta -= delta; } /*