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?
--
Scott Cheloha
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);