diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-13 09:05:08 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-13 09:05:08 +0100 |
| commit | 4674ec0e4b833ab0d0365225ba99228df14abe87 (patch) | |
| tree | 1b89fe1559fc9a2422e20048700e694a72d17751 /src/blind-repeat.c | |
| parent | vu-from-video: fix Y'UV encoding + add vu-to-video (diff) | |
| download | blind-4674ec0e4b833ab0d0365225ba99228df14abe87.tar.gz blind-4674ec0e4b833ab0d0365225ba99228df14abe87.tar.bz2 blind-4674ec0e4b833ab0d0365225ba99228df14abe87.tar.xz | |
Rename to blind
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/blind-repeat.c')
| -rw-r--r-- | src/blind-repeat.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/blind-repeat.c b/src/blind-repeat.c new file mode 100644 index 0000000..367d976 --- /dev/null +++ b/src/blind-repeat.c @@ -0,0 +1,59 @@ +/* See LICENSE file for copyright and license details. */ +#include "stream.h" +#include "util.h" + +#include <errno.h> +#include <fcntl.h> +#include <stdint.h> +#include <string.h> +#include <unistd.h> + +USAGE("(count | 'inf') file") + +int +main(int argc, char *argv[]) +{ + struct stream stream; + size_t count = 0, ptr; + ssize_t r; + char buf[BUFSIZ]; + int inf = 0; + + ENOFLAGS(argc != 2); + + if (!strcmp(argv[0], "inf")) + inf = 1; + else + count = etozu_arg("the count", argv[0], 0, SIZE_MAX); + + if (inf) + einf_check_fd(STDOUT_FILENO, "<stdout>"); + + stream.file = argv[1]; + stream.fd = eopen(stream.file, O_RDONLY); + einit_stream(&stream); + if (count > SIZE_MAX / stream.frames) + eprintf("%s: video is too long\n", stream.file); + stream.frames *= count; + fprint_stream_head(stdout, &stream); + efflush(stdout, "<stdout>"); + + while (inf || count--) { + posix_fadvise(stream.fd, stream.headlen, 0, POSIX_FADV_SEQUENTIAL); + for (ptr = stream.headlen;; ptr += (size_t)r) { + r = pread(stream.fd, buf, sizeof(buf), ptr); + if (r < 0) + eprintf("pread %s:", stream.file); + if (r == 0) + break; + if (writeall(STDOUT_FILENO, buf, (size_t)r)) { + if (!inf || errno != EPIPE) + eprintf("write <stdout>:"); + return 0; + } + } + } + + close(stream.fd); + return 0; +} |
