diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2012-02-29 12:36:04 +0100 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2012-04-16 23:51:14 +0200 |
commit | 6e226248939bb0598104ece1064398293a7d6305 (patch) | |
tree | 1946b6bb7fbcae90d8caf53a9bea033223606f33 /snapshot.c | |
parent | 594c6519fddcf7c1ecec7a7fea30c96066ec9c4b (diff) |
snapshot: Make viewfinder optional
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Diffstat (limited to 'snapshot.c')
-rw-r--r-- | snapshot.c | 147 |
1 files changed, 97 insertions, 50 deletions
@@ -57,7 +57,13 @@ #define SNAPSHOT_WIDTH 2048 #define SNAPSHOT_HEIGHT 1536 -static unsigned int frame_count = 0; +struct viewfinder { + unsigned int count; + bool enabled; + struct v4l2_buffers_pool *pool; +}; + +static struct viewfinder vf = { 0, false, NULL }; static unsigned int snapshot_interval = 20; static unsigned int snapshot_count = 0; @@ -81,14 +87,22 @@ static void __events_unwatch_fd(int fd) events_unwatch_fd(&events, fd); } -/* -------------------------------------------------------------------------- */ - static void sigint_handler(int signal __attribute__((__unused__))) { /* Stop the main loop when the user presses CTRL-C. */ events_stop(&events); } +/* ----------------------------------------------------------------------------- + * Snapshots + */ + +static int snapshot_capture(struct omap3_isp_device *isp) +{ + clock_gettime(CLOCK_MONOTONIC, &snapshot_time); + return omap3_isp_snapshot_capture(isp); +} + static void snapshot_process(struct omap3_isp_device *isp, struct v4l2_video_buffer *buffer) { @@ -132,8 +146,15 @@ requeue: strerror(-ret), ret); return; } + + if (!vf.enabled) + events_stop(&events); } +/* ----------------------------------------------------------------------------- + * Viewfinder + */ + static void viewfinder_process(struct omap3_isp_device *isp, struct v4l2_video_buffer *buffer) { @@ -144,13 +165,11 @@ static void viewfinder_process(struct omap3_isp_device *isp, return; } - frame_count++; - printf("viewfinder frame %u captured.\n", frame_count); + vf.count++; + printf("viewfinder frame %u captured.\n", vf.count); - if ((frame_count % snapshot_interval) == 0) { - clock_gettime(CLOCK_MONOTONIC, &snapshot_time); - omap3_isp_snapshot_capture(isp); - } + if ((vf.count % snapshot_interval) == 0) + snapshot_capture(isp); /* Requeue the buffer */ ret = omap3_isp_viewfinder_put_buffer(isp, buffer); @@ -161,6 +180,53 @@ static void viewfinder_process(struct omap3_isp_device *isp, } } +static int viewfinder_init(struct omap3_isp_device *isp) +{ + struct v4l2_mbus_framefmt view_format; + int ret; + + memset(&view_format, 0, sizeof view_format); + view_format.code = V4L2_MBUS_FMT_YUYV8_1X16; + view_format.width = VIEWFINDER_WIDTH; + view_format.height = VIEWFINDER_HEIGHT; + + ret = omap3_isp_viewfinder_setup(isp, &view_format); + if (ret < 0) { + printf("error: unable to setup pipeline\n"); + return ret; + } + + printf("viewfinder configured for %04x %ux%u\n", + view_format.code, view_format.width, view_format.height); + + /* Allocate a buffers pool and use it for the viewfinder. */ + vf.pool = v4l2_buffers_pool_new(4); + if (vf.pool == NULL) { + printf("error: unable to create buffers pool\n"); + return -ENOMEM; + } + + ret = v4l2_buffers_pool_alloc(vf.pool, view_format.width * view_format.height * 2, 4096); + if (ret < 0) { + printf("error: unable to allocate buffers memory\n"); + return ret; + } + + ret = omap3_isp_viewfinder_set_pool(isp, vf.pool); + if (ret < 0) { + printf("error: unable to set buffers pool\n"); + return ret; + } + + return 0; +} + +static void viewfinder_cleanup(struct omap3_isp_device *isp __attribute__((__unused__))) +{ + if (vf.pool) + v4l2_buffers_pool_delete(vf.pool); +} + /* -------------------------------------------------------------------------- */ static const struct { @@ -255,6 +321,7 @@ static void usage(const char *argv0) printf("-i, --interval n Capture a snapshot every n frames\n"); printf("-S, --save Save snapshots to disk\n"); printf("-s, --size wxh Set the snapshot capture size\n"); + printf("-v, --view Enable viewfinder\n"); } static struct option opts[] = { @@ -264,15 +331,14 @@ static struct option opts[] = { { "interval", 1, 0, 'i' }, { "save", 0, 0, 'S' }, { "size", 1, 0, 's' }, + { "view", 1, 0, 'v' }, { 0, 0, 0, 0 } }; int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) { - struct v4l2_mbus_framefmt view_format; struct v4l2_mbus_framefmt snap_format; struct v4l2_rect snap_crop; - struct v4l2_buffers_pool *pool = NULL; struct omap3_isp_device *isp = NULL; struct omap3_isp_operations ops; struct timespec start, end; @@ -287,7 +353,7 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu snap_format.width = SNAPSHOT_WIDTH; snap_format.height = SNAPSHOT_HEIGHT; - while ((c = getopt_long(argc, argv, "c:f:hi:Ss:", opts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "c:f:hi:Ss:v", opts, NULL)) != -1) { switch (c) { case 'c': if (parse_crop(optarg, &snap_crop)) { @@ -322,6 +388,9 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu return 1; } break; + case 'v': + vf.enabled = true; + break; default: printf("Invalid option -%c\n", c); printf("Run %s -h for help.\n", argv[0]); @@ -350,20 +419,12 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu goto cleanup; } - memset(&view_format, 0, sizeof view_format); - view_format.code = V4L2_MBUS_FMT_YUYV8_1X16; - view_format.width = VIEWFINDER_WIDTH; - view_format.height = VIEWFINDER_HEIGHT; - - ret = omap3_isp_viewfinder_setup(isp, &view_format); - if (ret < 0) { - printf("error: unable to setup pipeline\n"); - goto cleanup; + if (vf.enabled) { + ret = viewfinder_init(isp); + if (ret < 0) + goto cleanup; } - printf("viewfinder configured for %04x %ux%u\n", - view_format.code, view_format.width, view_format.height); - ret = omap3_isp_snapshot_setup(isp, do_crop ? &snap_crop : NULL, &snap_format); if (ret < 0) { printf("error: unable to setup pipeline\n"); @@ -373,40 +434,26 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu printf("snapshot configured for %04x %ux%u\n", snap_format.code, snap_format.width, snap_format.height); - /* Allocate a buffers pool and use it for the viewfinder. */ - pool = v4l2_buffers_pool_new(4); - if (pool == NULL) { - printf("error: unable to create buffers pool\n"); - goto cleanup; - } - - ret = v4l2_buffers_pool_alloc(pool, view_format.width * view_format.height * 2, 4096); - if (ret < 0) { - printf("error: unable to allocate buffers memory\n"); - goto cleanup; - } - - ret = omap3_isp_viewfinder_set_pool(isp, pool); - if (ret < 0) { - printf("error: unable to set buffers pool\n"); - goto cleanup; - } - /* Start the ISP. */ - ret = omap3_isp_viewfinder_start(isp); + if (vf.enabled) + ret = omap3_isp_viewfinder_start(isp); + else + ret = snapshot_capture(isp); + if (ret < 0) goto cleanup; + /* Main capture loop. */ clock_gettime(CLOCK_MONOTONIC, &start); - /* Main capture loop. */ if (events_loop(&events)) goto cleanup; clock_gettime(CLOCK_MONOTONIC, &end); /* Stop the ISP. */ - omap3_isp_viewfinder_stop(isp); + if (vf.enabled) + omap3_isp_viewfinder_stop(isp); /* Print some statistics. */ end.tv_sec -= start.tv_sec; @@ -416,9 +463,9 @@ int main(int argc __attribute__((__unused__)), char *argv[] __attribute__((__unu end.tv_nsec += 1000000000; } - fps = frame_count / (end.tv_sec + end.tv_nsec / 1000000000.0); + fps = vf.count / (end.tv_sec + end.tv_nsec / 1000000000.0); - printf("%u images processed in %lu.%06lu seconds (%f fps)\n", frame_count, + printf("%u images processed in %lu.%06lu seconds (%f fps)\n", vf.count, end.tv_sec, end.tv_nsec / 1000, fps); exit_code = EXIT_SUCCESS; @@ -427,8 +474,8 @@ cleanup: /* Cleanup the ISP resources. */ if (isp) omap3_isp_close(isp); - if (pool) - v4l2_buffers_pool_delete(pool); + if (vf.enabled) + viewfinder_cleanup(isp); return exit_code; } |