From 556522f647ac3a60b0e74681168adb6c191dd9e0 Mon Sep 17 00:00:00 2001 From: tth Date: Wed, 14 Aug 2019 19:29:11 +0200 Subject: [PATCH] period time now in floating point --- v4l2/grabvidseq.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/v4l2/grabvidseq.c b/v4l2/grabvidseq.c index 31aef141..14ba0983 100644 --- a/v4l2/grabvidseq.c +++ b/v4l2/grabvidseq.c @@ -91,15 +91,15 @@ struct timeval tv; int r, fd = -1; unsigned int i, n_buffers; char *dev_name = "/dev/video0"; -char out_name[256]; + FILE *fout; struct buffer *buffers; int foo, bar; -int period = 10; /* delai entre les captures */ +double period = 10.0; /* delai entre les captures */ int nbre_capt = 1; /* nombre de captures */ int opt; -double t_debut, t_final; +double t_final; char *dest_dir = "."; /* no trailing slash */ char *outfile = "out.pnm"; @@ -114,13 +114,14 @@ while ((opt = getopt(argc, argv, "d:hn:o:O:p:v")) != -1) { case 'n': nbre_capt = atoi(optarg); break; case 'O': dest_dir = optarg; break; case 'o': outfile = optarg; break; - case 'p': period = atoi(optarg); break; + case 'p': period = 1e6*atof(optarg); break; case 'v': verbosity++; break; } } if (verbosity) { fprintf(stderr, "running %s pid=%d\n", argv[0], getpid()); + fprintf(stderr, "period is %.3f microseconds\n", period); } fd = v4l2_open(dev_name, O_RDWR | O_NONBLOCK, 0); @@ -172,7 +173,7 @@ for (n_buffers = 0; n_buffers < req.count; ++n_buffers) { } } -t_debut = fimg_timer_set(0); +(void)fimg_timer_set(0); for (i = 0; i < n_buffers; ++i) { CLEAR(buf); @@ -218,6 +219,11 @@ for (i = 0; i < nbre_capt; i++) { return errno; } + if(verbosity > 1) { + printf("%6d %5.3f\n", i, fimg_timer_get(0)); + } + + CLEAR(buf); buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; buf.memory = V4L2_MEMORY_MMAP; @@ -253,8 +259,8 @@ for (i = 0; i < nbre_capt; i++) { out_name); #endif - if (nbre_capt > 1 && period) { - sleep(period); + if (nbre_capt > 1 && period > 1.0) { + usleep(period); } xioctl(fd, VIDIOC_QBUF, &buf);