annotate osdep/timer-linux.c @ 31568:476ca8c5dbd0

Fix outdated -vo gl usage example.
author reimar
date Mon, 05 Jul 2010 19:22:52 +0000
parents 1453fc56d49c
children 514016233368
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28744
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
1 /*
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
2 * precise timer routines for Linux
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
3 * copyright (C) LGB & A'rpi/ASTRAL
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
4 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
5 * This file is part of MPlayer.
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
6 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
7 * MPlayer is free software; you can redistribute it and/or modify
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
8 * it under the terms of the GNU General Public License as published by
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
10 * (at your option) any later version.
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
11 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
12 * MPlayer is distributed in the hope that it will be useful,
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
15 * GNU General Public License for more details.
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
16 *
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
17 * You should have received a copy of the GNU General Public License along
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
5cfef41a1771 Add standard license headers to files.
diego
parents: 26759
diff changeset
20 */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 #include <unistd.h>
13612
c0bde085511c Zeta OS support, mostly working.
reimar
parents: 12955
diff changeset
23 #ifdef __BEOS__
c0bde085511c Zeta OS support, mostly working.
reimar
parents: 12955
diff changeset
24 #define usleep(t) snooze(t)
c0bde085511c Zeta OS support, mostly working.
reimar
parents: 12955
diff changeset
25 #endif
5297
f297030ef5ab include stdlib.h
arpi
parents: 4385
diff changeset
26 #include <stdlib.h>
2476
a6c5a537f30a a few warning fixes (missing #include's)
pl
parents: 2273
diff changeset
27 #include <time.h>
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 #include <sys/time.h>
16985
08cac43f1e38 Unify include paths, -I.. is in CFLAGS.
diego
parents: 13612
diff changeset
29 #include "config.h"
30554
321e9ea69b9f #include corresponding .h files in .c files.
diego
parents: 29157
diff changeset
30 #include "timer.h"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31
31464
1453fc56d49c Change timer_name type from char* to char[]; patch taken from Uoti's tree.
diego
parents: 31461
diff changeset
32 const char timer_name[] =
12954
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
33 #ifdef HAVE_NANOSLEEP
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
34 "nanosleep()";
12954
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
35 #else
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
36 "usleep()";
12954
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
37 #endif
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
38
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
39 int usec_sleep(int usec_delay)
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
40 {
3090
57abb24ac58b HAVE_NANOSLEEP
alex
parents: 2476
diff changeset
41 #ifdef HAVE_NANOSLEEP
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
42 struct timespec ts;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
43 ts.tv_sec = usec_delay / 1000000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
44 ts.tv_nsec = (usec_delay % 1000000) * 1000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
45 return nanosleep(&ts, NULL);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
46 #else
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
47 return usleep(usec_delay);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
48 #endif
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
49 }
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
50
99
fb1fc94eaff0 removed redundancy...
arpi_esp
parents: 1
diff changeset
51 // Returns current time in microseconds
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
52 unsigned int GetTimer(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
53 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
54 struct timeval tv;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
55 //float s;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
56 gettimeofday(&tv,NULL);
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
57 //s = tv.tv_usec; s *= 0.000001; s += tv.tv_sec;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
58 return tv.tv_sec * 1000000 + tv.tv_usec;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
59 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60
4385
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
61 // Returns current time in milliseconds
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
62 unsigned int GetTimerMS(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
63 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
64 struct timeval tv;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
65 //float s;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
66 gettimeofday(&tv,NULL);
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
67 //s = tv.tv_usec; s *= 0.000001; s += tv.tv_sec;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
68 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
69 }
4385
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
70
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
71 static unsigned int RelativeTime = 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 // Returns time spent between now and last call in seconds
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
74 float GetRelativeTime(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
75 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
76 unsigned int t,r;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
77 t = GetTimer();
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
78 //t *= 16; printf("time = %ud\n", t);
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
79 r = t - RelativeTime;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
80 RelativeTime = t;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
81 return (float) r * 0.000001F;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 // Initialize timer, must be called at least once at start
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
85 void InitTimer(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
86 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
87 GetRelativeTime();
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 }