]> git.tue.mpg.de Git - paraslash.git/commitdiff
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 3a2226cfad1dedd05b4e822f49c75b389fac76c3..ad65c92fb6df70db22ca569d140514beba0f13a0 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 cecdcb77521964b7303423f564d04117233a3d1b..6b9c80988b365c76fe77e8a470004e2398739d5f 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 9213bf4623dbe0179b53ca81dd125f1d2a4ed197..753cef5696570fc4eeac99a879e7f45d0f9e498c 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 508aee790b728b169b4ac5b82832d8385a833f10..dffa5ecd65ca554de4f1ab60857901bb6033dfbe 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 aece23133c14e9934c363fc7aeb5c83287080ba0..e6e0a762f7e56819b37cd5bbbeb0b65347cbcea6 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 6ff778a92d0451ab0500c2dc8b88fbff02e30323..2cb0eafd45437d58fd79f988a6757fd41a69d7eb 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);