From: Mauro Carvalho Chehab Date: Mon, 6 Dec 2010 11:23:00 +0000 (-0200) Subject: v4l2grab: Allow changing the capture parameters via parameters X-Git-Tag: v4l-utils-0.8.2~100 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2c29ea6fd666d2d8b9880b7d774a0aaf8c7072dd;p=platform%2Fupstream%2Fv4l-utils.git v4l2grab: Allow changing the capture parameters via parameters Instead of requiring recompilation, allow passing arguments to the capture subroutine. Signed-off-by: Mauro Carvalho Chehab --- diff --git a/contrib/test/v4l2grab.c b/contrib/test/v4l2grab.c index de42be9..383a26e 100644 --- a/contrib/test/v4l2grab.c +++ b/contrib/test/v4l2grab.c @@ -22,6 +22,7 @@ #include #include #include "../../lib/include/libv4l2.h" +#include #define CLEAR(x) memset(&(x), 0, sizeof(x)) @@ -161,13 +162,74 @@ static int capture(char *dev_name, int x_res, int y_res, int n_frames, return 0; } +/* + * Main routine. Basically, reads parameters via argp.h and passes it to the + * capture routine + */ + +const char *argp_program_version = "V4L2 grabber version " V4L_UTILS_VERSION; +const char *argp_program_bug_address = "Mauro Carvalho Chehab "; + +static const char doc[] = "\nCapture images using libv4l, storing them as ppm files\n"; + +static const struct argp_option options[] = { + {"device", 'd', "DEV", 0, "video device (default: /dev/video0)", 0}, + {"out-dir", 'o', "OUTDIR", 0, "output directory (default: current dir)", 0}, + {"xres", 'x', "XRES", 0, "horizontal resolution", 0}, + {"yres", 'y', "YRES", 0, "vertical resolution", 0}, + {"n-frames", 'n', "NFRAMES", 0, "number of frames to capture", 0}, + { 0, 0, 0, 0, 0, 0 } +}; + +/* Static vars to store the parameters */ +static char *dev_name = "/dev/video0"; +static char *out_dir = "."; +static int x_res = 640; +static int y_res = 480; +static int n_frames = 20; + +static error_t parse_opt(int k, char *arg, struct argp_state *state) +{ + int val; + + switch (k) { + case 'd': + dev_name = arg; + break; + case 'o': + out_dir = arg; + break; + case 'x': + val = atoi(arg); + if (val) + x_res = val; + break; + case 'y': + val = atoi(arg); + if (val) + y_res = val; + break; + case 'n': + val = atoi(arg); + if (val) + n_frames = val; + break; + default: + return ARGP_ERR_UNKNOWN; + } + return 0; +} + +static struct argp argp = { + .options = options, + .parser = parse_opt, + .doc = doc, +}; + + int main(int argc, char **argv) { - char *dev_name = "/dev/video0"; - char *out_dir = "."; - int x_res = 640; - int y_res = 480; - int n_frames = 20; + argp_parse(&argp, argc, argv, 0, 0, 0); return capture(dev_name, x_res, y_res, n_frames, out_dir); }