diff --git a/main.cc b/main.cc index 4d33f48..b77aebb 100644 --- a/main.cc +++ b/main.cc @@ -16,6 +16,8 @@ static void sig_int(int); int SetupSignals(); std::string GetDefaultConfig(std::string name); +int timedeiff_ms(timeval *t1); + VideoFrame inputimage; VideoFrameFloat inputfloat; VideoFrameFloat inputfloatfilter; @@ -23,6 +25,8 @@ VideoFrame currentimage; VideoFrame currentimagefloat; VideoDevice *vdev= NULL; +double framespersecond = -1; // 60secs average frames per second + static void *thread_webserver(void *ignored_argument) { WebCamServer webserver; @@ -44,6 +48,12 @@ static void *thread_webserver(void *ignored_argument) { static void *thread_video(void *ignored_argument) { int cycle = 0; + timeval tv1; + time_t time1; + + time1 = time(NULL); + + gettimeofday(&tv1, NULL); if (config.vdev_dumpfile.length() > 0) { vdev = new VideoDevice_Dump(); @@ -72,13 +82,19 @@ static void *thread_video(void *ignored_argument) { vdev->Stop(); vdev->Start(); } - if ((cycle++ % 2) == 0) vdev->RefreshCtrls(); + if ((cycle++ % 10) == 0) vdev->RefreshCtrls(); + if (time(NULL) - time1 > 5) { + time1 = time(NULL); + debug ("FPS: %f", framespersecond); + } Lock(); inputimage.CopyTo(¤timage, config.web_width, config.web_height); if (inputfloatfilter.AddScaledImage(&inputfloat, config.filter_ratio) == 0) inputfloat.CopyTo(&inputfloatfilter); inputfloatfilter.CopyTo(¤timagefloat); UnLock(); + if (framespersecond == -1) framespersecond = 1.0/(timedeiff_ms(&tv1)/1000.0); + else framespersecond = (framespersecond * 59.0 + 1.0/(timedeiff_ms(&tv1)/1000.0)) / 60.0; } thread_video_exit: @@ -198,3 +214,15 @@ int isfile(std::string fname) { return 0; }; + +int timedeiff_ms(timeval *t1) { + timeval t2; + int res; + + gettimeofday(&t2, NULL); + res = ((t2.tv_sec - t1->tv_sec) * 1000 + (t2.tv_usec - t1->tv_usec) / 1000); + *t1 = t2; + + return res; +}; +