- struct writer_node_group *wng = wn->wng;
- struct timeval tv;
- snd_pcm_sframes_t avail, underrun;
-
- if (!pad->handle)
- return 1;
- if (wn->btrn) {
- size_t sz = btr_get_input_queue_size(wn->btrn);
- if (sz < pad->bytes_per_frame)
- return 1;
- } else {
- if (*wng->loaded - wn->written < pad->bytes_per_frame)
- return 1;
- }
- /*
- * 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;
- ms2tv(underrun, &tv);
- if (tv_diff(&s->timeout, &tv, NULL) > 0)
- s->timeout = tv;
- //PARA_CRIT_LOG("timout: %lu\n", tv2ms(&s->timeout));
- return 1;
-}
-
-static void alsa_write_pre_select_btr(struct sched *s, struct task *t)
-{
- struct writer_node *wn = container_of(t, struct writer_node, task);
- t->error = alsa_write_pre_select(s, wn);
-}
-
-static void xrun(snd_pcm_t *handle)
-{
- snd_pcm_status_t *status;
- int ret;
- struct timeval tv, diff;