simplify writer node group
[paraslash.git] / alsa_writer.c
index d13ea3a..7dab458 100644 (file)
@@ -146,16 +146,15 @@ static int alsa_open(struct writer_node *w)
                PARA_ERROR_LOG("%s\n", "failed to set nonblock mode");
        return period_size * pad->bytes_per_frame;
 }
-static void alsa_write_pre_select(struct sched *s, struct task *t)
+
+static int alsa_write_pre_select(struct sched *s, struct writer_node *wn)
 {
-       struct writer_node *wn = t->private_data;
        struct private_alsa_data *pad = wn->private_data;
        struct writer_node_group *wng = wn->wng;
        struct timeval diff;
 
-       t->ret = 1;
        if (*wng->loaded < pad->bytes_per_frame)
-               return;
+               return 1;
        if (tv_diff(&s->now, &pad->next_chunk, &diff) < 0) {
                if (tv_diff(&s->timeout, &diff, NULL) > 0)
                        s->timeout = diff;
@@ -163,12 +162,12 @@ static void alsa_write_pre_select(struct sched *s, struct task *t)
                s->timeout.tv_sec = 0;
                s->timeout.tv_usec = 1;
        }
+       return 1;
 //     PARA_INFO_LOG("timeout: %lu\n", tv2ms(&s->timeout));
 }
 
-static void alsa_write_post_select(struct sched *s, struct task *t)
+static int alsa_write_post_select(struct sched *s, struct writer_node *wn)
 {
-       struct writer_node *wn = t->private_data;
        struct private_alsa_data *pad = wn->private_data;
        struct writer_node_group *wng = wn->wng;
        size_t frames = *wng->loaded / pad->bytes_per_frame;
@@ -176,31 +175,28 @@ static void alsa_write_post_select(struct sched *s, struct task *t)
        unsigned char *data = (unsigned char*)wng->buf;
        struct timeval tv;
 
-       t->ret = 0;
 //     PARA_INFO_LOG("%zd frames\n", frames);
        if (!frames) {
                if (*wng->input_eof)
-                       t->ret = *wng->loaded;
-               return;
+                       ret = *wng->loaded;
+               return 0;
        }
        if (tv_diff(&s->now, &pad->next_chunk, NULL) < 0)
-               return;
+               return 0;
        ret = snd_pcm_writei(pad->handle, data, frames);
        if (ret == -EPIPE) {
                PARA_WARNING_LOG("%s", "EPIPE\n");
                snd_pcm_prepare(pad->handle);
-               return;
+               return 0;
        }
        if (ret < 0) {
                PARA_WARNING_LOG("%s", "ALSA ERROR\n");
-               t->ret = -E_ALSA_WRITE;
-               return;
+               return -E_ALSA_WRITE;
        }
        ms2tv(pad->buffer_time / 4000, &tv);
 //     ms2tv(1, &tv);
        tv_add(&s->now, &tv, &pad->next_chunk);
-       t->ret = ret * pad->bytes_per_frame;
-//     PARA_INFO_LOG("ret: %d, frames: %zd\n", t->ret, frames);
+       return ret * pad->bytes_per_frame;
 }
 
 static void alsa_close(struct writer_node *wn)