annotate osdep/timer-lx.c @ 15308:e9865b828a89

LIBAVFORMAT_BUILD >= 4624
author michael
date Sun, 01 May 2005 02:03:58 +0000
parents c0bde085511c
children 08cac43f1e38
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 // Precise timer routines for LINUX (C) LGB & A'rpi/ASTRAL
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 #include <unistd.h>
13612
c0bde085511c Zeta OS support, mostly working.
reimar
parents: 12955
diff changeset
4 #ifdef __BEOS__
c0bde085511c Zeta OS support, mostly working.
reimar
parents: 12955
diff changeset
5 #define usleep(t) snooze(t)
c0bde085511c Zeta OS support, mostly working.
reimar
parents: 12955
diff changeset
6 #endif
5297
f297030ef5ab include stdlib.h
arpi
parents: 4385
diff changeset
7 #include <stdlib.h>
2476
a6c5a537f30a a few warning fixes (missing #include's)
pl
parents: 2273
diff changeset
8 #include <time.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 #include <sys/time.h>
3090
57abb24ac58b HAVE_NANOSLEEP
alex
parents: 2476
diff changeset
10 #include "../config.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11
12955
82fb5c71f776 And a tiny compile fix.
wight
parents: 12954
diff changeset
12 const char *timer_name =
12954
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
13 #ifdef HAVE_NANOSLEEP
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
14 "nanosleep()";
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
15 #else
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
16 "usleep()";
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
17 #endif
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
18
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
19 int usec_sleep(int usec_delay)
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
20 {
3090
57abb24ac58b HAVE_NANOSLEEP
alex
parents: 2476
diff changeset
21 #ifdef HAVE_NANOSLEEP
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
22 struct timespec ts;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
23 ts.tv_sec = usec_delay / 1000000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
24 ts.tv_nsec = (usec_delay % 1000000) * 1000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
25 return nanosleep(&ts, NULL);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
26 #else
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
27 return usleep(usec_delay);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
28 #endif
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
29 }
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
30
99
fb1fc94eaff0 removed redundancy...
arpi_esp
parents: 1
diff changeset
31 // Returns current time in microseconds
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 unsigned int GetTimer(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 struct timeval tv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 struct timezone tz;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 // float s;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 gettimeofday(&tv,&tz);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 return (tv.tv_sec*1000000+tv.tv_usec);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40
4385
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
41 // Returns current time in milliseconds
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
42 unsigned int GetTimerMS(){
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
43 struct timeval tv;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
44 struct timezone tz;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
45 // float s;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
46 gettimeofday(&tv,&tz);
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
47 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
48 return (tv.tv_sec*1000+tv.tv_usec/1000);
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
49 }
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
50
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 static unsigned int RelativeTime=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 // Returns time spent between now and last call in seconds
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 float GetRelativeTime(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 unsigned int t,r;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 t=GetTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 // t*=16;printf("time=%ud\n",t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 r=t-RelativeTime;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 RelativeTime=t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 return (float)r * 0.000001F;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 // Initialize timer, must be called at least once at start
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 void InitTimer(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 GetRelativeTime();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 void main(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 float t=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 InitTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 while(1){ t+=GetRelativeTime();printf("time= %10.6f\r",t);fflush(stdout); }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76