-/* Open an instance of the alsa writer. */
-static int alsa_open_nobtr(struct writer_node *wn)
-{
- struct alsa_write_args_info *conf = wn->conf;
- struct writer_node_group *wng = wn->wng;
- struct private_alsa_write_data *pad = para_calloc(sizeof(*pad));
-
- wn->private_data = pad;
- if (!conf->samplerate_given && wng->samplerate)
- pad->samplerate = *wng->samplerate;
- else
- pad->samplerate = conf->samplerate_arg;
- if (!conf->channels_given && wng->channels)
- pad->channels = *wng->channels;
- else
- pad->channels = conf->channels_arg;
- PARA_INFO_LOG("%d channel(s), %dHz\n", pad->channels, pad->samplerate);
- return 1;
-}
-
-static int alsa_open_btr(struct writer_node *wn)
-{
- struct private_alsa_write_data *pad = para_calloc(sizeof(*pad));
-
- wn->private_data = pad;
- return 1;
-}
-static int alsa_open(struct writer_node *wn)
-{
- if (wn->btrn)
- return alsa_open_btr(wn);
- return alsa_open_nobtr(wn);
-}
-
-static int alsa_write_pre_select(struct sched *s, struct writer_node *wn)
-{
- struct private_alsa_write_data *pad = wn->private_data;
- struct writer_node_group *wng = wn->wng;
- struct timeval tv;
- snd_pcm_sframes_t avail, underrun;
-
- if (!pad->handle)
- return 1;
- if (wn->btrn) {
- int ret = btr_node_status(wn->btrn, wn->min_iqs, BTR_NT_LEAF);
- if (ret == 0)
- return 1;
- if (ret < 0) {
- sched_request_timeout_ms(20, s);
- return 42;
- }
- } 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)