Mercurial > mplayer.hg
annotate osdep/timer-linux.c @ 27308:e0d8be9a3261
sync'd with r27337
author | ptt |
---|---|
date | Wed, 23 Jul 2008 10:34:20 +0000 |
parents | 8eff880f638c |
children | 5cfef41a1771 |
rev | line source |
---|---|
1 | 1 // Precise timer routines for LINUX (C) LGB & A'rpi/ASTRAL |
2 | |
3 #include <unistd.h> | |
13612 | 4 #ifdef __BEOS__ |
5 #define usleep(t) snooze(t) | |
6 #endif | |
5297 | 7 #include <stdlib.h> |
2476 | 8 #include <time.h> |
1 | 9 #include <sys/time.h> |
16985 | 10 #include "config.h" |
1 | 11 |
12955 | 12 const char *timer_name = |
12954 | 13 #ifdef HAVE_NANOSLEEP |
14 "nanosleep()"; | |
15 #else | |
16 "usleep()"; | |
17 #endif | |
18 | |
2273 | 19 int usec_sleep(int usec_delay) |
20 { | |
3090 | 21 #ifdef HAVE_NANOSLEEP |
2273 | 22 struct timespec ts; |
23 ts.tv_sec = usec_delay / 1000000; | |
24 ts.tv_nsec = (usec_delay % 1000000) * 1000; | |
25 return nanosleep(&ts, NULL); | |
26 #else | |
27 return usleep(usec_delay); | |
28 #endif | |
29 } | |
30 | |
99 | 31 // Returns current time in microseconds |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16985
diff
changeset
|
32 unsigned int GetTimer(void){ |
1 | 33 struct timeval tv; |
34 // float s; | |
18467 | 35 gettimeofday(&tv,NULL); |
1 | 36 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec; |
26759
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
25510
diff
changeset
|
37 return tv.tv_sec * 1000000 + tv.tv_usec; |
1 | 38 } |
39 | |
4385 | 40 // Returns current time in milliseconds |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16985
diff
changeset
|
41 unsigned int GetTimerMS(void){ |
4385 | 42 struct timeval tv; |
43 // float s; | |
18467 | 44 gettimeofday(&tv,NULL); |
4385 | 45 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec; |
26759
8eff880f638c
cosmetics: Remove useless parentheses from return statements.
diego
parents:
25510
diff
changeset
|
46 return tv.tv_sec * 1000 + tv.tv_usec / 1000; |
4385 | 47 } |
48 | |
1 | 49 static unsigned int RelativeTime=0; |
50 | |
51 // Returns time spent between now and last call in seconds | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16985
diff
changeset
|
52 float GetRelativeTime(void){ |
1 | 53 unsigned int t,r; |
54 t=GetTimer(); | |
55 // t*=16;printf("time=%ud\n",t); | |
56 r=t-RelativeTime; | |
57 RelativeTime=t; | |
58 return (float)r * 0.000001F; | |
59 } | |
60 | |
61 // Initialize timer, must be called at least once at start | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16985
diff
changeset
|
62 void InitTimer(void){ |
1 | 63 GetRelativeTime(); |
64 } | |
65 | |
66 | |
67 #if 0 | |
25510 | 68 #include <stdio.h> |
69 int main(void){ | |
1 | 70 float t=0; |
71 InitTimer(); | |
72 while(1){ t+=GetRelativeTime();printf("time= %10.6f\r",t);fflush(stdout); } | |
73 } | |
74 #endif | |
75 |