annotate linux/timer-lx.c @ 2751:69a77510f0eb

FF_POSTPROCESS shouldn't be defined if there is no ffmpeg's libavcodec found
author pl
date Tue, 06 Nov 2001 19:51:15 +0000
parents a6c5a537f30a
children 57abb24ac58b
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>
2476
a6c5a537f30a a few warning fixes (missing #include's)
pl
parents: 2273
diff changeset
4 #include <time.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 #include <sys/time.h>
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
7 int usec_sleep(int usec_delay)
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
8 {
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
9 #if 1
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
10 struct timespec ts;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
11 ts.tv_sec = usec_delay / 1000000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
12 ts.tv_nsec = (usec_delay % 1000000) * 1000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
13 return nanosleep(&ts, NULL);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
14 #else
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
15 return usleep(usec_delay);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
16 #endif
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
17 }
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
18
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
19
99
fb1fc94eaff0 removed redundancy...
arpi_esp
parents: 1
diff changeset
20 // Returns current time in microseconds
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 unsigned int GetTimer(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 struct timeval tv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 struct timezone tz;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 // float s;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 gettimeofday(&tv,&tz);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 return (tv.tv_sec*1000000+tv.tv_usec);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 static unsigned int RelativeTime=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 // Returns time spent between now and last call in seconds
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 float GetRelativeTime(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 unsigned int t,r;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 t=GetTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 // t*=16;printf("time=%ud\n",t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 r=t-RelativeTime;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 RelativeTime=t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 return (float)r * 0.000001F;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 // Initialize timer, must be called at least once at start
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 void InitTimer(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 GetRelativeTime();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 void main(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 float t=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 InitTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 while(1){ t+=GetRelativeTime();printf("time= %10.6f\r",t);fflush(stdout); }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55