aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-01-10 04:30:02 +0100
committerMattias Andrée <maandree@kth.se>2017-01-10 04:30:02 +0100
commit33d7ef1e017b52a95d55887c05548b6207997b1c (patch)
treedb33b6ee25b8fe5df90ae4bb1c02d3dcb3b55cc1
parentvu-from-image: add support for farbfeld and 16-bit RGBA PAM (diff)
downloadblind-33d7ef1e017b52a95d55887c05548b6207997b1c.tar.gz
blind-33d7ef1e017b52a95d55887c05548b6207997b1c.tar.bz2
blind-33d7ef1e017b52a95d55887c05548b6207997b1c.tar.xz
vu-repeat: add option to repeat ad infinitum
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--src/vu-repeat.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/vu-repeat.c b/src/vu-repeat.c
index aa5de9a..16f88cd 100644
--- a/src/vu-repeat.c
+++ b/src/vu-repeat.c
@@ -3,14 +3,16 @@
#include "stream.h"
#include "util.h"
+#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
+#include <string.h>
#include <unistd.h>
static void
usage(void)
{
- eprintf("usage: %s count file\n", argv0);
+ eprintf("usage: %s (count | 'inf') file\n", argv0);
}
int
@@ -20,6 +22,7 @@ main(int argc, char *argv[])
size_t count = 0, ptr, n, ptw;
ssize_t r;
char buf[BUFSIZ];
+ int inf = 0;
ARGBEGIN {
default:
@@ -29,15 +32,18 @@ main(int argc, char *argv[])
if (argc != 2)
usage();
- if (tozu(argv[0], 0, SIZE_MAX, &count))
+ if (!strcmp(argv[0], "inf")) {
+ inf = 1;
+ } else if (tozu(argv[0], 0, SIZE_MAX, &count)) {
eprintf("the count must be an integer in [0, %zu]\n", SIZE_MAX);
+ }
stream.file = argv[1];
stream.fd = open(stream.file, O_RDONLY);
if (stream.fd < 0)
eprintf("open %s:", stream.file);
einit_stream(&stream);
- if (stream.frames > SIZE_MAX / count)
+ if (count > SIZE_MAX / stream.frames)
eprintf("%s: video too long\n", stream.file);
stream.frames *= count;
fprint_stream_head(stdout, &stream);
@@ -45,12 +51,12 @@ main(int argc, char *argv[])
if (ferror(stdout))
eprintf("<stdout>:");
- while (count--) {
+ while (inf || count--) {
posix_fadvise(stream.fd, 0, 0, POSIX_FADV_SEQUENTIAL);
for (ptw = 0; ptw < stream.ptr;) {
r = write(STDOUT_FILENO, stream.buf + ptw, stream.ptr - ptw);
if (r < 0)
- eprintf("write <stdout>:");
+ goto writeerr;
ptw += (size_t)r;
}
for (ptr = 0;;) {
@@ -63,7 +69,7 @@ main(int argc, char *argv[])
for (ptw = 0; ptw < n;) {
r = write(STDOUT_FILENO, buf + ptw, n - ptw);
if (r < 0)
- eprintf("write <stdout>:");
+ goto writeerr;
ptw += (size_t)r;
}
}
@@ -71,4 +77,9 @@ main(int argc, char *argv[])
close(stream.fd);
return 0;
+
+writeerr:
+ if (!inf || errno != EPIPE)
+ eprintf("write <stdout>:");
+ return 0;
}