poll only bits set by sio_pollfd

This commit is contained in:
Alexandre Ratchov 2012-10-05 18:03:13 +02:00
parent 2b5ee784cb
commit 9c73c409dc
1 changed files with 14 additions and 10 deletions

View File

@ -55,6 +55,7 @@ struct sio_alsa_hdl {
int idelta, odelta; /* position reported to client */ int idelta, odelta; /* position reported to client */
int nfds, infds, onfds; int nfds, infds, onfds;
int running; int running;
int events;
#ifdef DEBUG #ifdef DEBUG
long long wpos, rpos, cpos; long long wpos, rpos, cpos;
#endif #endif
@ -1079,12 +1080,14 @@ static int
sio_alsa_pollfd(struct sio_hdl *sh, struct pollfd *pfd, int events) sio_alsa_pollfd(struct sio_hdl *sh, struct pollfd *pfd, int events)
{ {
struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh; struct sio_alsa_hdl *hdl = (struct sio_alsa_hdl *)sh;
int i;
if (hdl->sio.eof) if (hdl->sio.eof)
return 0; return 0;
hdl->events = events;
memset(pfd, 0, sizeof(struct pollfd) * hdl->nfds); memset(pfd, 0, sizeof(struct pollfd) * hdl->nfds);
if ((hdl->sio.mode & SIO_PLAY) && hdl->sio.started) { if ((events & POLLOUT) && (hdl->sio.mode & SIO_PLAY) && hdl->sio.started) {
if (!hdl->running && if (!hdl->running &&
snd_pcm_state(hdl->opcm) == SND_PCM_STATE_RUNNING) { snd_pcm_state(hdl->opcm) == SND_PCM_STATE_RUNNING) {
hdl->running = 1; hdl->running = 1;
@ -1099,7 +1102,7 @@ sio_alsa_pollfd(struct sio_hdl *sh, struct pollfd *pfd, int events)
} }
} else } else
hdl->onfds = 0; hdl->onfds = 0;
if ((hdl->sio.mode & SIO_REC) && hdl->sio.started) { if ((events & POLLIN) && (hdl->sio.mode & SIO_REC) && hdl->sio.started) {
if (!hdl->running && if (!hdl->running &&
snd_pcm_state(hdl->ipcm) == SND_PCM_STATE_RUNNING) { snd_pcm_state(hdl->ipcm) == SND_PCM_STATE_RUNNING) {
hdl->running = 1; hdl->running = 1;
@ -1134,20 +1137,19 @@ sio_alsa_revents(struct sio_hdl *sh, struct pollfd *pfd)
int nfds; int nfds;
unsigned short revents, r; unsigned short revents, r;
int err; int err;
#if 1
if (hdl->sio.eof) int i;
return POLLHUP;
#if 0
int i
for (i = 0; i < hdl->onfds + hdl->infds; i++) { for (i = 0; i < hdl->onfds + hdl->infds; i++) {
DPRINTF("sio_alsa_revents: pfds[%d].events = %x\n", DPRINTF("sio_alsa_revents: pfds[%d].events = %x\n",
i, pfd[i].revents); i, pfd[i].revents);
} }
#endif #endif
if (hdl->sio.eof)
return POLLHUP;
revents = nfds = 0; revents = nfds = 0;
if (hdl->sio.mode & SIO_PLAY) { if ((hdl->events & POLLOUT) && (hdl->sio.mode & SIO_PLAY)) {
ostate = snd_pcm_state(hdl->opcm); ostate = snd_pcm_state(hdl->opcm);
if (ostate == SND_PCM_STATE_XRUN) { if (ostate == SND_PCM_STATE_XRUN) {
if (!sio_alsa_xrun(hdl)) if (!sio_alsa_xrun(hdl))
@ -1163,7 +1165,7 @@ sio_alsa_revents(struct sio_hdl *sh, struct pollfd *pfd)
revents |= r; revents |= r;
nfds += hdl->onfds; nfds += hdl->onfds;
} }
if (hdl->sio.mode & SIO_REC) { if ((hdl->events & POLLIN) && (hdl->sio.mode & SIO_REC)) {
istate = snd_pcm_state(hdl->ipcm); istate = snd_pcm_state(hdl->ipcm);
if (istate == SND_PCM_STATE_XRUN) { if (istate == SND_PCM_STATE_XRUN) {
if (!sio_alsa_xrun(hdl)) if (!sio_alsa_xrun(hdl))
@ -1221,14 +1223,16 @@ sio_alsa_revents(struct sio_hdl *sh, struct pollfd *pfd)
hdl->sio.eof = 1; hdl->sio.eof = 1;
return POLLHUP; return POLLHUP;
} }
//fprintf(stderr, "iused = %d -> %d, idelta = %d\n", hdl->iused, iused, hdl->idelta);
hdl->idelta += iused - hdl->iused; hdl->idelta += iused - hdl->iused;
hdl->iused = iused; hdl->iused = iused;
if (hdl->idelta > 0) { if (hdl->idelta > 0) {
#ifdef DEBUG #ifdef DEBUG
hdl->cpos += hdl->idelta; hdl->cpos += hdl->idelta;
if (sndio_debug) if (sndio_debug)
sio_onmove_cb(&hdl->sio, hdl->idelta); sio_alsa_printpos(hdl, hdl->odelta);
#endif #endif
sio_onmove_cb(&hdl->sio, hdl->idelta);
hdl->idelta = 0; hdl->idelta = 0;
} }
} }