Re: video(1): measure with mono clock (tester wanted)

2018-04-07 Thread Benjamin Baier
On Fri, 6 Apr 2018 09:28:54 -0500
Scott Cheloha  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: 18.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 -  1.23
> +++ app/video/video.c 6 Apr 2018 14:21:26 -
> @@ -30,6 +30,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  
>  #include 
> @@ -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 = 100 / 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 / 100;
> + tp_run.tv_nsec / 10.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 / 100;
> + timespecsub(&tp_now, &tp_start, &tp_run);
> + run_time = tp_run.tv_sec + tp_run.tv_nsec / 10.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);
> 



video(1): measure with mono clock (tester wanted)

2018-04-06 Thread Scott Cheloha
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 -  1.23
+++ app/video/video.c   6 Apr 2018 14:21:26 -
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -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 = 100 / 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 / 100;
+   tp_run.tv_nsec / 10.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 / 100;
+   timespecsub(&tp_now, &tp_start, &tp_run);
+   run_time = tp_run.tv_sec + tp_run.tv_nsec / 10.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);