annotate osdep/timer-lx.c @ 13394:455a5056801f

New generic 'portable anymap' video output driver. It supports portable pixmaps and graymaps in both raw and ASCII mode. Besides PPM and PGM, it can also output PGMYUV files which are PGM files with the U and V plane appended to the bottom of the Y image (bottom left and bottom right). All files can be written to the current directory, to a specified output directory or to multiple subdirectories if the filesystem can't handle the amount of files in one directory anymore. Note: This driver is not yet activated and will not be compiled and linked to libvo. A separate patch will take care of that. This is just for adding the file to the repository.
author ivo
date Mon, 20 Sep 2004 00:54:57 +0000
parents 82fb5c71f776
children c0bde085511c
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>
5297
f297030ef5ab include stdlib.h
arpi
parents: 4385
diff changeset
4 #include <stdlib.h>
2476
a6c5a537f30a a few warning fixes (missing #include's)
pl
parents: 2273
diff changeset
5 #include <time.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 #include <sys/time.h>
3090
57abb24ac58b HAVE_NANOSLEEP
alex
parents: 2476
diff changeset
7 #include "../config.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8
12955
82fb5c71f776 And a tiny compile fix.
wight
parents: 12954
diff changeset
9 const char *timer_name =
12954
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
10 #ifdef HAVE_NANOSLEEP
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
11 "nanosleep()";
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
12 #else
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
13 "usleep()";
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
14 #endif
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
15
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
16 int usec_sleep(int usec_delay)
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
17 {
3090
57abb24ac58b HAVE_NANOSLEEP
alex
parents: 2476
diff changeset
18 #ifdef HAVE_NANOSLEEP
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
19 struct timespec ts;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
20 ts.tv_sec = usec_delay / 1000000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
21 ts.tv_nsec = (usec_delay % 1000000) * 1000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
22 return nanosleep(&ts, NULL);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
23 #else
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
24 return usleep(usec_delay);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
25 #endif
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
26 }
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
27
99
fb1fc94eaff0 removed redundancy...
arpi_esp
parents: 1
diff changeset
28 // Returns current time in microseconds
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 unsigned int GetTimer(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 struct timeval tv;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 struct timezone tz;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 // float s;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 gettimeofday(&tv,&tz);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 return (tv.tv_sec*1000000+tv.tv_usec);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37
4385
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
38 // Returns current time in milliseconds
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
39 unsigned int GetTimerMS(){
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
40 struct timeval tv;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
41 struct timezone tz;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
42 // float s;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
43 gettimeofday(&tv,&tz);
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
44 // s=tv.tv_usec;s*=0.000001;s+=tv.tv_sec;
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
45 return (tv.tv_sec*1000+tv.tv_usec/1000);
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
46 }
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
47
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 static unsigned int RelativeTime=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 // Returns time spent between now and last call in seconds
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 float GetRelativeTime(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 unsigned int t,r;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 t=GetTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 // t*=16;printf("time=%ud\n",t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 r=t-RelativeTime;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 RelativeTime=t;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 return (float)r * 0.000001F;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 // Initialize timer, must be called at least once at start
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 void InitTimer(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 GetRelativeTime();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 void main(){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 float t=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 InitTimer();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 while(1){ t+=GetRelativeTime();printf("time= %10.6f\r",t);fflush(stdout); }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73