Forced subs support for mencoder
[mplayer/glamo.git] / osdep / timer-lx.c
blob4321e46bfa013b37df925f083ab4375cb5054035
1 // Precise timer routines for LINUX (C) LGB & A'rpi/ASTRAL
3 #include <unistd.h>
4 #include <stdlib.h>
5 #include <time.h>
6 #include <sys/time.h>
7 #include "../config.h"
9 int usec_sleep(int usec_delay)
11 #ifdef HAVE_NANOSLEEP
12 struct timespec ts;
13 ts.tv_sec = usec_delay / 1000000;
14 ts.tv_nsec = (usec_delay % 1000000) * 1000;
15 return nanosleep(&ts, NULL);
16 #else
17 return usleep(usec_delay);
18 #endif
22 // Returns current time in microseconds
23 unsigned int GetTimer(){
24 struct timeval tv;
25 struct timezone tz;
26 // float s;
27 gettimeofday(&tv,&tz);
28 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
29 return (tv.tv_sec*1000000+tv.tv_usec);
32 // Returns current time in milliseconds
33 unsigned int GetTimerMS(){
34 struct timeval tv;
35 struct timezone tz;
36 // float s;
37 gettimeofday(&tv,&tz);
38 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
39 return (tv.tv_sec*1000+tv.tv_usec/1000);
42 static unsigned int RelativeTime=0;
44 // Returns time spent between now and last call in seconds
45 float GetRelativeTime(){
46 unsigned int t,r;
47 t=GetTimer();
48 // t*=16;printf("time=%ud\n",t);
49 r=t-RelativeTime;
50 RelativeTime=t;
51 return (float)r * 0.000001F;
54 // Initialize timer, must be called at least once at start
55 void InitTimer(){
56 GetRelativeTime();
60 #if 0
61 void main(){
62 float t=0;
63 InitTimer();
64 while(1){ t+=GetRelativeTime();printf("time= %10.6f\r",t);fflush(stdout); }
66 #endif