Make the wng->eof a pointer.
authorAndre <maan@p133.(none)>
Tue, 23 May 2006 18:27:23 +0000 (20:27 +0200)
committerAndre <maan@p133.(none)>
Tue, 23 May 2006 18:27:23 +0000 (20:27 +0200)
The receiver/stdin_reader already have a corresponding field.

This patch also fixes a bug in the alsa_writer which was introduced
by the previous patch. This bug caused a playback delay of one second.

alsa_writer.c
stdin.c
stdin.h
write.c
write.h
write_common.c

index 3a2226c..ad65c92 100644 (file)
@@ -140,13 +140,13 @@ static void alsa_write_pre_select(struct sched *s, struct task *t)
        struct timeval diff;
 
        t->ret = 0;
-       if (wng->eof && *wng->loaded < pad->bytes_per_frame)
+       if (*wng->eof && *wng->loaded < pad->bytes_per_frame)
                return;
        t->ret = 1;
        if (*wng->loaded < pad->bytes_per_frame)
                return;
        if (tv_diff(&s->now, &pad->next_chunk, &diff) < 0) {
-               if (tv_diff(&s->timeout, &diff, NULL) < 0)
+               if (tv_diff(&s->timeout, &diff, NULL) > 0)
                        s->timeout = diff;
        } else {
                s->timeout.tv_sec = 0;
@@ -164,8 +164,11 @@ static void alsa_write_post_select(struct sched *s, struct task *t)
        unsigned char *data = (unsigned char*)wng->buf;
 
        t->ret = 0;
-       if (!frames)
+       if (!frames) {
+               if (*wng->eof)
+                       t->ret = *wng->loaded;
                return;
+       }
        if (tv_diff(&s->now, &pad->next_chunk, NULL) < 0)
                return;
 //     PARA_INFO_LOG("%zd frames\n", frames);
diff --git a/stdin.c b/stdin.c
index cecdcb7..6b9c809 100644 (file)
--- a/stdin.c
+++ b/stdin.c
@@ -27,22 +27,14 @@ void stdin_post_select(struct sched *s, struct task *t)
        ret = read(STDIN_FILENO, sit->buf + sit->loaded, sit->bufsize - sit->loaded);
        if (ret < 0)
                t->ret = -E_STDIN_READ;
-       else {
+       else if (ret > 0) {
                sit->loaded += ret;
                t->ret = ret;
-       }
+       } else
+               t->ret = 0;
+       if (ret <= 0)
+               sit->eof = 1;
        sprintf(t->status,
                "%p stdin reader: loaded = %d, ret = %d",
                sit, sit->loaded, t->ret);
 }
-
-#if 0
-void stdin_init(struct stdin_task *sit)
-{
-       sit->task.private_data = sit;
-       sit->task.pre_select = stdin_pre_select;
-       sit->task.post_select = stdin_post_select;
-       sit->task.flags = POST_EOF_IS_ERROR;
-       sprintf(sit->task.status, "%p stdin reader: initialized", &sit->task);
-}
-#endif
diff --git a/stdin.h b/stdin.h
index 9213bf4..753cef5 100644 (file)
--- a/stdin.h
+++ b/stdin.h
@@ -3,6 +3,7 @@ struct stdin_task {
        size_t bufsize;
        size_t loaded;
        struct task task;
+       int eof;
 };
 
 void stdin_pre_select(struct sched *s, struct task *t);
diff --git a/write.c b/write.c
index 508aee7..dffa5ec 100644 (file)
--- a/write.c
+++ b/write.c
@@ -148,8 +148,10 @@ static struct writer_node_group *check_args(void)
        }
        ret = 1;
 out:
-       if (ret > 0)
+       if (ret > 0) {
+               wng->eof = &sit.eof;
                return wng;
+       }
        free(wng);
        return NULL;
 }
@@ -194,7 +196,6 @@ static void stdin_error_handler(struct task *t)
        PARA_INFO_LOG("task %p, ret: %d\n", t, t->ret);
        if (t->ret < 0)
                PARA_ERROR_LOG("%s\n", PARA_STRERROR(-t->ret));
-       wng->eof = 1;
 }
 
 int main(int argc, char *argv[])
diff --git a/write.h b/write.h
index aece231..e6e0a76 100644 (file)
--- a/write.h
+++ b/write.h
@@ -94,7 +94,7 @@ int *written;
 /** the maximum of the chunk_bytes values of the writer nodes in this group */
 size_t max_chunk_bytes;
 /** non-zero if end of file was encountered */
-int eof;
+int *eof;
 char *buf;
 size_t *loaded;
 struct task task;
index 6ff778a..2cb0eaf 100644 (file)
 const char *writer_names[] ={WRITER_NAMES};
 struct writer writers[NUM_SUPPORTED_WRITERS] = {WRITER_ARRAY};
 
-int wng_write(struct writer_node_group *g, char *buf, size_t *loaded)
-{
-       int ret, i, need_more_writes = 1;
-       size_t min_written = 0;
-
-       while (need_more_writes) {
-               need_more_writes = 0;
-               FOR_EACH_WRITER_NODE(i, g) {
-                       size_t w = g->written[i];
-                       int bytes_to_write;
-                       struct writer_node *wn = &g->writer_nodes[i];
-                       if (!i)
-                               min_written = w;
-                       else
-                               min_written = PARA_MIN(min_written, w);
-                       if (w == *loaded)
-                               continue;
-                       if (!g->eof && (*loaded < wn->chunk_bytes + w))
-                               continue;
-                       bytes_to_write = PARA_MIN(wn->chunk_bytes,
-                               *loaded - w);
-                       ret = wn->writer->write(buf + w, bytes_to_write, wn);
-                       if (ret < 0)
-                               goto out;
-                       if (ret != bytes_to_write)
-                               PARA_WARNING_LOG("short write: %d/%d\n", ret,
-                                       bytes_to_write);
-                       g->written[i] += ret;
-                       need_more_writes = 1;
-               }
-       }
-       *loaded -= min_written;
-       ret = 0;
-       if (g->eof)
-               goto out;
-       if (*loaded)
-               memmove(buf, buf + min_written, *loaded);
-       FOR_EACH_WRITER_NODE(i, g)
-               g->written[i] -= min_written;
-       ret = 1;
-out:
-       return ret;
-}
-
 static void wng_post_select(struct sched *s, struct task *t)
 {
        struct writer_node_group *g = t->private_data;
@@ -89,7 +45,7 @@ static void wng_post_select(struct sched *s, struct task *t)
                        min_written = PARA_MIN(min_written, t->ret);
        }
        *g->loaded -= min_written;
-       if (!*g->loaded && g->eof)
+       if (!*g->loaded && *g->eof)
                t->ret = 0;
        else
                t->ret = 1;
@@ -114,6 +70,7 @@ int wng_open(struct writer_node_group *g)
                wn->task.pre_select = wn->writer->pre_select;
                wn->task.post_select = wn->writer->post_select;
                wn->task.private_data = wn;
+               wn->task.flags = POST_EOF_IS_ERROR;
                register_task(&wn->task);
        }
        register_task(&g->task);