- u_int8_t buf[100];
- int len = read(0, buf, sizeof(buf));
- g_print("read %d bytes from stdin\n", len);
+ struct stdin_read_param *p = (struct stdin_read_param*)data;
+ static size_t offset = 0;
+ static u_int8_t buf[100];
+
+ int len = read(0, &(buf[offset]), sizeof(buf) - offset);
+ if(len <= 0) {
+ if(len) g_printerr("Error on STDIN\n");
+ else g_print("EOF on STDIN\n");
+ g_main_loop_quit(p->loop);
+ }
+
+ offset+=len;
+ if(offset > sizeof(buf)) offset = sizeof(buf);
+
+ size_t i;
+ for(i=0; i < offset; ++i) {
+ if(buf[i] == '\n') {
+ buf[i] = 0;
+
+ struct play_file_param* data = malloc(sizeof(struct play_file_param));
+ if(data) {
+ data->name = buf;
+ data->pipeline = p->pipeline;
+ data->source = p->source;
+ data->sval = p->sval;
+ data->cond = p->cond;
+ data->mutex = p->mutex;
+ g_thread_create(play_file, data, 0, NULL);
+ }
+
+ if(i < offset) {
+ memmove(buf, &(buf[i+1]), offset - (i+1));
+ offset -= i+1;
+ } else offset = 0;
+ }
+ }
+
+ return 1;