From 97f7e7ea79bbf2be9ae993a662eae9d19f4bef17 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Mon, 6 Dec 2010 09:07:38 -0200 Subject: [PATCH] v4l2grab: Convert "default" values into parameters Signed-off-by: Mauro Carvalho Chehab --- contrib/test/v4l2grab.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/contrib/test/v4l2grab.c b/contrib/test/v4l2grab.c index f68fc1e..de42be9 100644 --- a/contrib/test/v4l2grab.c +++ b/contrib/test/v4l2grab.c @@ -44,7 +44,8 @@ static void xioctl(int fh, unsigned long int request, void *arg) } } -int main(int argc, char **argv) +static int capture(char *dev_name, int x_res, int y_res, int n_frames, + char *out_dir) { struct v4l2_format fmt; struct v4l2_buffer buf; @@ -54,8 +55,7 @@ int main(int argc, char **argv) struct timeval tv; int r, fd = -1; unsigned int i, n_buffers; - char *dev_name = "/dev/video0"; - char out_name[256]; + char out_name[25 + strlen(out_dir)]; FILE *fout; struct buffer *buffers; @@ -67,8 +67,8 @@ int main(int argc, char **argv) CLEAR(fmt); fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; - fmt.fmt.pix.width = 640; - fmt.fmt.pix.height = 480; + fmt.fmt.pix.width = x_res; + fmt.fmt.pix.height = y_res; fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_RGB24; fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; xioctl(fd, VIDIOC_S_FMT, &fmt); @@ -76,7 +76,7 @@ int main(int argc, char **argv) printf("Libv4l didn't accept RGB24 format. Can't proceed.\n"); exit(EXIT_FAILURE); } - if ((fmt.fmt.pix.width != 640) || (fmt.fmt.pix.height != 480)) + if ((fmt.fmt.pix.width != x_res) || (fmt.fmt.pix.height != y_res)) printf("Warning: driver is sending image at %dx%d\n", fmt.fmt.pix.width, fmt.fmt.pix.height); @@ -117,7 +117,7 @@ int main(int argc, char **argv) type = V4L2_BUF_TYPE_VIDEO_CAPTURE; xioctl(fd, VIDIOC_STREAMON, &type); - for (i = 0; i < 20; i++) { + for (i = 0; i < n_frames; i++) { do { FD_ZERO(&fds); FD_SET(fd, &fds); @@ -138,7 +138,7 @@ int main(int argc, char **argv) buf.memory = V4L2_MEMORY_MMAP; xioctl(fd, VIDIOC_DQBUF, &buf); - sprintf(out_name, "out%03d.ppm", i); + sprintf(out_name, "%s/out%03d.ppm", out_dir, i); fout = fopen(out_name, "w"); if (!fout) { perror("Cannot open image"); @@ -160,3 +160,14 @@ int main(int argc, char **argv) return 0; } + +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; + + return capture(dev_name, x_res, y_res, n_frames, out_dir); +} -- 2.7.4