summaryrefslogtreecommitdiff
path: root/snapshot.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2012-02-28 13:39:39 +0100
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2012-04-16 23:50:06 +0200
commit86d964456fd999b65744084141e87a9a57fab5a0 (patch)
treefc5b6aae84c39851ae07f571c2fbc50def7c8580 /snapshot.c
parentdfb9afd9ee426993f459068acc2c891faca64888 (diff)
snapshot: Add option to save snapshots to disk
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'snapshot.c')
-rw-r--r--snapshot.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/snapshot.c b/snapshot.c
index da63b36..405b6ed 100644
--- a/snapshot.c
+++ b/snapshot.c
@@ -36,7 +36,9 @@
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/select.h>
+#include <sys/stat.h>
#include <sys/time.h>
+#include <sys/types.h>
#include <linux/spi/spidev.h>
@@ -58,7 +60,9 @@
static unsigned int frame_count = 0;
static unsigned int snapshot_interval = 20;
+static unsigned int snapshot_count = 0;
static struct timespec snapshot_time;
+static bool snapshot_save = false;
static struct events events;
@@ -89,7 +93,9 @@ static void snapshot_process(struct omap3_isp_device *isp,
struct v4l2_video_buffer *buffer)
{
static struct timespec ts;
+ char name[23];
int ret;
+ int fd;
if (buffer->error) {
printf("warning: error in dequeued buffer, skipping\n");
@@ -105,7 +111,21 @@ static void snapshot_process(struct omap3_isp_device *isp,
printf("snapshot captured in %lu.%06lus.\n", ts.tv_sec, ts.tv_nsec / 1000);
+ if (snapshot_save) {
+ sprintf(name, "snapshot-%06u.bin", snapshot_count);
+ fd = open(name, O_WRONLY | O_CREAT,
+ S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
+ if (fd == -1)
+ goto requeue;
+
+ write(fd, buffer->mem, buffer->bytesused);
+ close(fd);
+ }
+
+requeue:
/* Requeue the buffer */
+ snapshot_count++;
+
ret = omap3_isp_snapshot_put_buffer(isp, buffer);
if (ret < 0) {
printf("error: unable to requeue buffer: %s (%d)\n",
@@ -183,14 +203,16 @@ static void usage(const char *argv0)
printf("Usage: %s [options]\n", argv0);
printf("Supported options:\n");
printf("-f, --format fmt Snapshot format\n");
- printf("-h, --help Show this help screen\n");
- printf("-s, --snap n Capture a snapshot every n frames\n");
+ printf("-h, --help Show this help screen\n");
+ printf("-i, --interval n Capture a snapshot every n frames\n");
+ printf("-S, --save Save snapshots to disk\n");
}
static struct option opts[] = {
- { "help", 0, 0, 'h' },
{ "format", 1, 0, 'f' },
- { "snap", 0, 0, 's' },
+ { "help", 0, 0, 'h' },
+ { "interval", 1, 0, 'i' },
+ { "save", 0, 0, 'S' },
{ 0, 0, 0, 0 }
};
@@ -208,7 +230,7 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu
int ret;
int c;
- while ((c = getopt_long(argc, argv, "f:hs:", opts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "f:hi:S", opts, NULL)) != -1) {
switch (c) {
case 'f':
snap_code = parse_format(optarg);
@@ -220,13 +242,16 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu
case 'h':
usage(argv[0]);
return 0;
- case 's':
+ case 'i':
snapshot_interval = strtoul(optarg, NULL, 10);
if (snapshot_interval == 0) {
printf("snapshot interval value must be >0.\n");
return 1;
}
break;
+ case 'S':
+ snapshot_save = true;
+ break;
default:
printf("Invalid option -%c\n", c);
printf("Run %s -h for help.\n", argv[0]);