annotate osdep/timer-linux.c @ 29335:5f45df619c7c

TS demuxer: make the IDs used by DEMUXER_CTRL_SWITCH_* and DEMUXER_CTRL_IDENTIFY_PROGRAM match those printed as ID_VIDEO_ID/ID_AUDIO_ID and accepted with -vid/-aid
author reimar
date Sun, 21 Jun 2009 10:47:44 +0000
parents e67f8e8d2e74
children 321e9ea69b9f
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"
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30
12955
82fb5c71f776 And a tiny compile fix.
wight
parents: 12954
diff changeset
31 const char *timer_name =
12954
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
32 #ifdef HAVE_NANOSLEEP
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
33 "nanosleep()";
12954
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
34 #else
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
35 "usleep()";
12954
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
36 #endif
f9755d9c479a Native darwin timer update.
wight
parents: 9380
diff changeset
37
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
38 int usec_sleep(int usec_delay)
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
39 {
3090
57abb24ac58b HAVE_NANOSLEEP
alex
parents: 2476
diff changeset
40 #ifdef HAVE_NANOSLEEP
2273
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
41 struct timespec ts;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
42 ts.tv_sec = usec_delay / 1000000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
43 ts.tv_nsec = (usec_delay % 1000000) * 1000;
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
44 return nanosleep(&ts, NULL);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
45 #else
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
46 return usleep(usec_delay);
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
47 #endif
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
48 }
e407fc4562f1 sleep stuff moved to linux/timer
arpi
parents: 99
diff changeset
49
99
fb1fc94eaff0 removed redundancy...
arpi_esp
parents: 1
diff changeset
50 // Returns current time in microseconds
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
51 unsigned int GetTimer(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
52 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
53 struct timeval tv;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
54 //float s;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
55 gettimeofday(&tv,NULL);
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
56 //s = tv.tv_usec; s *= 0.000001; s += tv.tv_sec;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
57 return tv.tv_sec * 1000000 + tv.tv_usec;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
58 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59
4385
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
60 // Returns current time in milliseconds
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
61 unsigned int GetTimerMS(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
62 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
63 struct timeval tv;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
64 //float s;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
65 gettimeofday(&tv,NULL);
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
66 //s = tv.tv_usec; s *= 0.000001; s += tv.tv_sec;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
67 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
68 }
4385
7bb8f7905000 GetTimerMS added - get timer in millisec
arpi
parents: 3090
diff changeset
69
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
70 static unsigned int RelativeTime = 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 // Returns time spent between now and last call in seconds
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
73 float GetRelativeTime(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
74 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
75 unsigned int t,r;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
76 t = GetTimer();
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
77 //t *= 16; printf("time = %ud\n", t);
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
78 r = t - RelativeTime;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
79 RelativeTime = t;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
80 return (float) r * 0.000001F;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 // Initialize timer, must be called at least once at start
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
84 void InitTimer(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
85 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
86 GetRelativeTime();
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 #if 0
25510
c0e1528c7432 Fix warnings when compiling test application.
diego
parents: 25101
diff changeset
91 #include <stdio.h>
29157
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
92 int main(void)
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
93 {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
94 float t = 0;
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
95 InitTimer();
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
96 while (1) {
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
97 t += GetRelativeTime();
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
98 printf("time = %10.6f\r", t);
e67f8e8d2e74 cosmetics: reindent
diego
parents: 28744
diff changeset
99 fflush(stdout); }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 #endif