- size_t bufsize, prebuf_size, bytes_to_load;
- struct timeval delay;
- int ret, not_yet_started = 1;
-
- ret = wng_open(wng);
- if (ret < 0)
- goto out;
- PARA_INFO_LOG("max chunk_bytes: %d\n", wng->max_chunk_bytes);
- bufsize = (conf.bufsize_arg * 1024 / wng->max_chunk_bytes)
- * wng->max_chunk_bytes;
- audiobuf = para_realloc(audiobuf, bufsize);
- prebuf_size = conf.prebuffer_arg * bufsize / 100;
- bytes_to_load = PARA_MAX(prebuf_size, wng->max_chunk_bytes);
- ret = read_stdin(audiobuf, bytes_to_load, &loaded);
- if (ret <= 0 || loaded < bytes_to_load) {
- if (ret >= 0)
- ret = -E_PREMATURE_END;
- goto out;
+ int i, n, ret, writer_given = OPT_GIVEN(WRITER, lpr);
+ struct btr_node *cw_btrn;
+ struct writer_node *wns;
+ static struct sched s;
+ struct wav_params wp;
+ struct write_task wt;
+
+ sit.btrn = btr_new_node(&(struct btr_node_description)
+ EMBRACE(.name = "stdin"));
+ stdin_task_register(&sit, &s);
+
+ LLS_COPY_WAV_PARMS(&wp, LSG_WRITE_PARA_WRITE, lpr);
+ wt.cwc = check_wav_init(sit.btrn, NULL, &wp, &cw_btrn);
+ wt.task = task_register(&(struct task_info) {
+ .name = "write",
+ .pre_select = write_pre_select,
+ .post_select = write_post_select,
+ .context = &wt,
+ }, &s);
+
+ n = writer_given? writer_given : 1;
+ wns = para_calloc(n * sizeof(*wns));
+ for (i = 0; i < n; i++) {
+ const char *arg = i < writer_given?
+ lls_string_val(i, OPT_RESULT(WRITER, lpr)) : NULL;
+ wns[i].wid = check_writer_arg_or_die(arg, &wns[i].lpr);
+ register_writer_node(wns + i, cw_btrn, &s);