aboutsummaryrefslogtreecommitdiffstats
path: root/src/stream.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-01-12 00:13:17 +0100
committerMattias Andrée <maandree@kth.se>2017-01-12 00:13:17 +0100
commit45ac53d25ba0e5d5255789d7665057e404dc3269 (patch)
tree55ccb71255871c4b6d5523b4d8676565f15b74c1 /src/stream.c
parentFix writeall + vu-split: reuse code (diff)
downloadblind-45ac53d25ba0e5d5255789d7665057e404dc3269.tar.gz
blind-45ac53d25ba0e5d5255789d7665057e404dc3269.tar.bz2
blind-45ac53d25ba0e5d5255789d7665057e404dc3269.tar.xz
cleanup
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/stream.c')
-rw-r--r--src/stream.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/stream.c b/src/stream.c
index cf6f230..c863c23 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -267,3 +267,43 @@ process_two_streams(struct stream *left, struct stream *right, int output_fd, co
}
}
}
+
+
+void
+process_multiple_streams(struct stream *streams, size_t n_streams, int output_fd, const char* output_fname,
+ void (*process)(struct stream *streams, size_t n_streams, size_t n))
+{
+ size_t closed, i, j, n;
+
+ for (i = 1; i < n_streams; i++)
+ echeck_compat(streams + i, streams);
+
+ while (n_streams) {
+ n = SIZE_MAX;
+ for (i = 0; i < n_streams; i++) {
+ if (streams[i].ptr < sizeof(streams->buf) && !eread_stream(streams + i, SIZE_MAX)) {
+ close(streams[i].fd);
+ streams[i].fd = -1;
+ }
+ if (streams[i].ptr && streams[i].ptr < n)
+ n = streams[i].ptr;
+ }
+ n -= n % streams->pixel_size;
+
+ process(streams, n_streams, n);
+ ewriteall(output_fd, streams->buf, n, output_fname);
+
+ closed = SIZE_MAX;
+ for (i = 0; i < n_streams; i++) {
+ memmove(streams[i].buf, streams[i].buf + n, streams[i].ptr -= n);
+ if (streams[i].ptr < streams->pixel_size && streams[i].fd < 0 && closed == SIZE_MAX)
+ closed = i;
+ }
+ if (closed != SIZE_MAX) {
+ for (i = (j = closed) + 1; i < n_streams; i++)
+ if (streams[i].ptr < streams->pixel_size && streams[i].fd < 0)
+ streams[j++] = streams[i];
+ n_streams = j;
+ }
+ }
+}