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-reverse.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-reverse.c')
| -rw-r--r-- | src/blind-reverse.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/blind-reverse.c b/src/blind-reverse.c new file mode 100644 index 0000000..5c978f2 --- /dev/null +++ b/src/blind-reverse.c @@ -0,0 +1,47 @@ +/* See LICENSE file for copyright and license details. */ +#include "stream.h" +#include "util.h" + +#include <limits.h> +#include <unistd.h> + +USAGE("file") + +int +main(int argc, char *argv[]) +{ + struct stream stream; + size_t frame_size, ptr, end, n; + ssize_t r; + char buf[BUFSIZ]; + + ENOFLAGS(argc != 1); + + stream.file = argv[0]; + stream.fd = eopen(stream.file, O_RDONLY); + einit_stream(&stream); + fprint_stream_head(stdout, &stream); + efflush(stdout, "<stdout>"); + echeck_frame_size(stream.width, stream.height, stream.pixel_size, 0, stream.file); + frame_size = stream.width * stream.height * stream.pixel_size; + if (stream.frames > SSIZE_MAX / frame_size) + eprintf("%s: video is too large\n", stream.file); + + posix_fadvise(stream.fd, 0, 0, POSIX_FADV_RANDOM); + while (stream.frames--) { + ptr = stream.frames * frame_size; + end = ptr + frame_size; + while (ptr < end) { + r = pread(stream.fd, buf, sizeof(buf), ptr); + if (r < 0) + eprintf("pread %s:", stream.file); + else if (r == 0) + eprintf("%s: file is shorter than expected\n", stream.file); + ptr += n = (size_t)r; + ewriteall(STDOUT_FILENO, buf, n, "<stdout>"); + } + } + + close(stream.fd); + return 0; +} |
