From 5a00b6f95ebe4d6e487ef96c88d385844541a15b Mon Sep 17 00:00:00 2001 From: deva Date: Sat, 12 Aug 2006 15:47:29 +0000 Subject: New tasks! Made dvfile read at most 25 fps. --- client/dvfile.cc | 18 ++++++++++++++++-- client/dvfile.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'client') diff --git a/client/dvfile.cc b/client/dvfile.cc index 601c21d..a34de3d 100644 --- a/client/dvfile.cc +++ b/client/dvfile.cc @@ -31,6 +31,8 @@ #include "info.h" +#include + dvfile::dvfile() { fp = fopen(TEST_MOVIE, "r"); @@ -44,9 +46,18 @@ dvfile::~dvfile() Frame *dvfile::readFrame() { - unsigned char *ptr = new unsigned char[DVPACKAGE_SIZE]; + timeval tv; + + // Wait untill atleast 1/25th of a second has passed in order to + // preserve 25fps when enough cpu is available + gettimeofday(&tv, NULL); + long long unsigned int diff = + tv.tv_sec * 1000000LL + + tv.tv_usec - last_frame; - sleep_1_frame(); + if(diff < (1000000 / 25)) usleep((1000000 / 25) - diff); + + unsigned char *ptr = new unsigned char[DVPACKAGE_SIZE]; if(fp) { while(fread(ptr, DVPACKAGE_SIZE, 1, fp) == 0) { @@ -58,5 +69,8 @@ Frame *dvfile::readFrame() Frame *frame = new Frame((char*)ptr, DVPACKAGE_SIZE, VF_DV, NULL, 0, AF_DV); + gettimeofday(&tv, NULL); + last_frame = tv.tv_sec * 1000000LL + tv.tv_usec; + return frame; } diff --git a/client/dvfile.h b/client/dvfile.h index 9e21a4d..8a45044 100644 --- a/client/dvfile.h +++ b/client/dvfile.h @@ -46,6 +46,7 @@ public: Frame *readFrame(); private: + long long last_frame; FILE* fp; }; -- cgit v1.2.3