- if (!pad)
- return sched_min_delay(s);
- if (ret < 0)
- return sched_request_barrier_or_min_delay(&pad->drain_barrier, s);
- /*
- * Data is available to be written to the alsa handle. Compute number
- * of milliseconds until next buffer underrun would occur.
- *
- * snd_pcm_avail_update() updates the current available count of
- * samples for writing. It is a light method to obtain current stream
- * position, because it does not require the user <-> kernel context
- * switch, but the value is less accurate, because ring buffer pointers
- * are updated in kernel drivers only when an interrupt occurs.
- */
- avail = snd_pcm_avail_update(pad->handle);
- if (avail < 0)
- avail = 0;
- underrun = (pad->buffer_frames - avail) * pad->buffer_time
- / pad->buffer_frames / 1000;
- if (underrun < 50)
- underrun = 50;
- underrun -= 50;
- sched_request_timeout_ms(underrun, s);
+ if (!pad) {
+ sched_min_delay(s);
+ return;
+ }
+ if (ret < 0) {
+ sched_request_barrier_or_min_delay(&pad->drain_barrier, s);
+ return;
+ }
+ ret = snd_pcm_poll_descriptors(pad->handle, &pfd, 1);
+ if (ret < 0) {
+ PARA_ERROR_LOG("%s\n", snd_strerror(-ret));
+ t->error = -E_ALSA_POLL_FDS;
+ return;
+ }
+ pad->poll_fd = pfd.fd;
+ para_fd_set(pfd.fd, &s->rfds, &s->max_fileno);