On Fri, 6 Apr 2018 09:28:54 -0500 Scott Cheloha <scottchel...@gmail.com> wrote:
> So that your stats stay correct if the system clock is changed. > > This is simple enough to suggest that it's correct at a glance, > but I have no hardware to test this with. Can anyone confirm that > this works? No regressions. Greetings Ben $ /usr/X11R6/bin/video -vvv video device /dev/video: encodings: yuy2 frame sizes (width x height, in pixels) and rates (in frames per second): 320x240: 30, 15 352x288: 30, 15 424x240: 30, 15 640x360: 30, 15 640x480: 30, 15 800x448: 15 960x544: 10 1280x720: 10 controls: brightness, contrast, saturation, hue, gamma, sharpness Xv adaptor 0, Intel(R) Textured Video: encodings: yuy2, uyvy max size: 3286x1200 using yuy2 encoding using frame size 640x480 (614400 bytes) using default frame rate video: got ConfigureNotify event1.34, fps: 14.94520 video: got ConfigureNotify event video: got ConfigureNotify event video: got KeyPress event: 000018.05, fps: 14.40465 run time: 18.330074 seconds frames grabbed: 265 frames played: 264 played fps: 14.348006 > > Index: app/video/video.c > =================================================================== > RCS file: /cvs/xenocara/app/video/video.c,v > retrieving revision 1.23 > diff -u -p -r1.23 video.c > --- app/video/video.c 26 Nov 2016 11:49:15 -0000 1.23 > +++ app/video/video.c 6 Apr 2018 14:21:26 -0000 > @@ -30,6 +30,7 @@ > #include <stdio.h> > #include <stdlib.h> > #include <string.h> > +#include <time.h> > #include <unistd.h> > > #include <X11/Xlib.h> > @@ -1635,7 +1636,7 @@ int > stream(struct video *vid) > { > struct xdsp *x = &vid->xdsp; > - struct timeval tp_start, tp_now, tp_run; > + struct timespec tp_start, tp_now, tp_run; > struct itimerval frit; > double run_time; > uint8_t *src; > @@ -1643,7 +1644,7 @@ stream(struct video *vid) > int sequence = 20, ret, err, todo, done; > > /* Guard against uninitialized variable in case no frame is grabbed. */ > - gettimeofday(&tp_start, NULL); > + clock_gettime(CLOCK_MONOTONIC, &tp_start); > > if (vid->fps && !vid->nofps) { > fus = 1000000 / vid->fps; > @@ -1759,21 +1760,21 @@ stream(struct video *vid) > frames_played++; > > if (frames_played == 0) > - gettimeofday(&tp_start, NULL); > + clock_gettime(CLOCK_MONOTONIC, &tp_start); > > if (vid->verbose > 1 && frames_played > 0 && > (frames_played) % sequence == 0) { > - gettimeofday(&tp_now, NULL); > - timersub(&tp_now, &tp_start, &tp_run); > + clock_gettime(CLOCK_MONOTONIC, &tp_now); > + timespecsub(&tp_now, &tp_start, &tp_run); > run_time = tp_run.tv_sec + > - (double)tp_run.tv_usec / 1000000; > + tp_run.tv_nsec / 1000000000.0; > fprintf(stderr, "frames: %08ld, seconds: " > "%09.2f, fps: %08.5f\r", frames_played, > run_time, ((double)frames_played) / run_time); > fflush(stderr); > } > } > - gettimeofday(&tp_now, NULL); > + clock_gettime(CLOCK_MONOTONIC, &tp_now); > > if (vid->fps) { > timerclear(&frit.it_value); > @@ -1793,8 +1794,8 @@ stream(struct video *vid) > fprintf(stderr, "\n"); > > if (vid->verbose > 0) { > - timersub(&tp_now, &tp_start, &tp_run); > - run_time = tp_run.tv_sec + (double)tp_run.tv_usec / 1000000; > + timespecsub(&tp_now, &tp_start, &tp_run); > + run_time = tp_run.tv_sec + tp_run.tv_nsec / 1000000000.0; > fprintf(stderr, "run time: %f seconds\n", run_time); > fprintf(stderr, "frames grabbed: %ld\n", frames_grabbed); > fprintf(stderr, "frames played: %ld\n", frames_played + 1); >