Mercurial > libavformat.hg
annotate os_support.c @ 1978:9beecb275bae libavformat
cosmetics: Put audio (de)muxer entries in alphabetical order.
author | diego |
---|---|
date | Tue, 03 Apr 2007 15:57:38 +0000 |
parents | c0c0f19f0db6 |
children | 9a8908eaa2ea |
rev | line source |
---|---|
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
1 /* |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
2 * Various utilities for ffmpeg system |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard |
1506 | 4 * copyright (c) 2002 Francois Revol |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
5 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
6 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
7 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
8 * FFmpeg is free software; you can redistribute it and/or |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
10 * License as published by the Free Software Foundation; either |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
11 * version 2.1 of the License, or (at your option) any later version. |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
12 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
13 * FFmpeg is distributed in the hope that it will be useful, |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
16 * Lesser General Public License for more details. |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
17 * |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1171
diff
changeset
|
19 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
885
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
21 */ |
443
afbe3a5aae02
libavformat/os_support.c HAVE_LOCALTIME_R patch by ("Steven M. Schultz" <sms at 2BSD dot COM>)
michael
parents:
230
diff
changeset
|
22 #include "config.h" |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
23 #include "avformat.h" |
908
5b0ff52e008e
Skip all includes for WinCE, instead of falling through to the #else case.
diego
parents:
907
diff
changeset
|
24 #if defined(CONFIG_WINCE) |
5b0ff52e008e
Skip all includes for WinCE, instead of falling through to the #else case.
diego
parents:
907
diff
changeset
|
25 /* Skip includes on WinCE. */ |
1171
2a0c729ac640
CONFIG_WIN32 implies MinGW and Cygwin and possibly more, so use just
diego
parents:
908
diff
changeset
|
26 #elif defined(__MINGW32__) |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
27 #include <sys/types.h> |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
28 #include <sys/timeb.h> |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
29 #elif defined(CONFIG_OS2) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
30 #include <string.h> |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
31 #include <sys/time.h> |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
32 #else |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
33 #include <unistd.h> |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
34 #include <fcntl.h> |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
35 #include <sys/time.h> |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
36 #endif |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
37 #include <time.h> |
1798
d1e61f4d02cd
MinGW patch by <koyama AT infocity DOT co DOT jp>, reworked. Removed placeholder for winsock.
mmu_man
parents:
1797
diff
changeset
|
38 |
1797 | 39 #ifndef HAVE_SYS_POLL_H |
1798
d1e61f4d02cd
MinGW patch by <koyama AT infocity DOT co DOT jp>, reworked. Removed placeholder for winsock.
mmu_man
parents:
1797
diff
changeset
|
40 #if defined(__MINGW32__) |
d1e61f4d02cd
MinGW patch by <koyama AT infocity DOT co DOT jp>, reworked. Removed placeholder for winsock.
mmu_man
parents:
1797
diff
changeset
|
41 #include <winsock2.h> |
d1e61f4d02cd
MinGW patch by <koyama AT infocity DOT co DOT jp>, reworked. Removed placeholder for winsock.
mmu_man
parents:
1797
diff
changeset
|
42 #else |
1797 | 43 #include <sys/select.h> |
44 #endif | |
1798
d1e61f4d02cd
MinGW patch by <koyama AT infocity DOT co DOT jp>, reworked. Removed placeholder for winsock.
mmu_man
parents:
1797
diff
changeset
|
45 #endif |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
46 |
580 | 47 /** |
48 * gets the current time in micro seconds. | |
49 */ | |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
50 int64_t av_gettime(void) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
51 { |
907 | 52 #if defined(CONFIG_WINCE) |
1556 | 53 return timeGetTime() * INT64_C(1000); |
1171
2a0c729ac640
CONFIG_WIN32 implies MinGW and Cygwin and possibly more, so use just
diego
parents:
908
diff
changeset
|
54 #elif defined(__MINGW32__) |
448
66217205fe4e
cygwin patch by ("Sascha Sommer" <saschasommer at freenet dot de>)
michael
parents:
443
diff
changeset
|
55 struct timeb tb; |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
56 _ftime(&tb); |
1556 | 57 return ((int64_t)tb.time * INT64_C(1000) + (int64_t)tb.millitm) * INT64_C(1000); |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
58 #else |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
59 struct timeval tv; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
60 gettimeofday(&tv,NULL); |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
61 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
62 #endif |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
63 } |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
64 |
1497 | 65 #if !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R) |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
66 struct tm *localtime_r(const time_t *t, struct tm *tp) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
67 { |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
68 struct tm *l; |
885 | 69 |
230
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
70 l = localtime(t); |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
71 if (!l) |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
72 return 0; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
73 *tp = *l; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
74 return tp; |
9f4f4ca9f7b5
simpler strptime - added os_support.[ch] - moved localtime_r to os_support.c
bellard
parents:
diff
changeset
|
75 } |
1497 | 76 #endif /* !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R) */ |
1506 | 77 |
1511
6d9dd5b5e764
MinGW compilation fix, inet_aton and #includes depend on networking support.
diego
parents:
1506
diff
changeset
|
78 #if !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) |
6d9dd5b5e764
MinGW compilation fix, inet_aton and #includes depend on networking support.
diego
parents:
1506
diff
changeset
|
79 #include <stdlib.h> |
6d9dd5b5e764
MinGW compilation fix, inet_aton and #includes depend on networking support.
diego
parents:
1506
diff
changeset
|
80 #include <strings.h> |
1943
c0c0f19f0db6
Some more BeOS cleanup: check for arpa/inet.h; declare the prototype for inet_aton if not found; remove barpainet.h as it's not longer needed.
mmu_man
parents:
1799
diff
changeset
|
81 #include "network.h" |
1511
6d9dd5b5e764
MinGW compilation fix, inet_aton and #includes depend on networking support.
diego
parents:
1506
diff
changeset
|
82 |
1506 | 83 int inet_aton (const char * str, struct in_addr * add) |
84 { | |
85 const char * pch = str; | |
86 unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0; | |
87 | |
88 add1 = atoi(pch); | |
89 pch = strpbrk(pch,"."); | |
90 if (pch == 0 || ++pch == 0) goto done; | |
91 add2 = atoi(pch); | |
92 pch = strpbrk(pch,"."); | |
93 if (pch == 0 || ++pch == 0) goto done; | |
94 add3 = atoi(pch); | |
95 pch = strpbrk(pch,"."); | |
96 if (pch == 0 || ++pch == 0) goto done; | |
97 add4 = atoi(pch); | |
98 | |
99 done: | |
100 add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1; | |
101 | |
102 return 1; | |
103 } | |
1511
6d9dd5b5e764
MinGW compilation fix, inet_aton and #includes depend on networking support.
diego
parents:
1506
diff
changeset
|
104 #endif /* !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) */ |
1797 | 105 |
1799
0dc3a767943d
Make sure we don't try to emulate poll() when it's there if --disable-ffserver... 10l
mmu_man
parents:
1798
diff
changeset
|
106 #ifdef CONFIG_FFSERVER |
1797 | 107 #ifndef HAVE_SYS_POLL_H |
108 int poll(struct pollfd *fds, nfds_t numfds, int timeout) | |
109 { | |
110 fd_set read_set; | |
111 fd_set write_set; | |
112 fd_set exception_set; | |
113 nfds_t i; | |
114 int n; | |
115 int rc; | |
116 | |
117 FD_ZERO(&read_set); | |
118 FD_ZERO(&write_set); | |
119 FD_ZERO(&exception_set); | |
120 | |
121 n = -1; | |
122 for(i = 0; i < numfds; i++) { | |
123 if (fds[i].fd < 0) | |
124 continue; | |
125 if (fds[i].fd >= FD_SETSIZE) { | |
126 errno = EINVAL; | |
127 return -1; | |
128 } | |
129 | |
130 if (fds[i].events & POLLIN) FD_SET(fds[i].fd, &read_set); | |
131 if (fds[i].events & POLLOUT) FD_SET(fds[i].fd, &write_set); | |
132 if (fds[i].events & POLLERR) FD_SET(fds[i].fd, &exception_set); | |
133 | |
134 if (fds[i].fd > n) | |
135 n = fds[i].fd; | |
136 }; | |
137 | |
138 if (n == -1) | |
139 /* Hey!? Nothing to poll, in fact!!! */ | |
140 return 0; | |
141 | |
142 if (timeout < 0) | |
143 rc = select(n+1, &read_set, &write_set, &exception_set, NULL); | |
144 else { | |
145 struct timeval tv; | |
146 | |
147 tv.tv_sec = timeout / 1000; | |
148 tv.tv_usec = 1000 * (timeout % 1000); | |
149 rc = select(n+1, &read_set, &write_set, &exception_set, &tv); | |
150 }; | |
151 | |
152 if (rc < 0) | |
153 return rc; | |
154 | |
155 for(i = 0; i < (nfds_t) n; i++) { | |
156 fds[i].revents = 0; | |
157 | |
158 if (FD_ISSET(fds[i].fd, &read_set)) fds[i].revents |= POLLIN; | |
159 if (FD_ISSET(fds[i].fd, &write_set)) fds[i].revents |= POLLOUT; | |
160 if (FD_ISSET(fds[i].fd, &exception_set)) fds[i].revents |= POLLERR; | |
161 }; | |
162 | |
163 return rc; | |
164 } | |
1799
0dc3a767943d
Make sure we don't try to emulate poll() when it's there if --disable-ffserver... 10l
mmu_man
parents:
1798
diff
changeset
|
165 #endif /* HAVE_SYS_POLL_H */ |
0dc3a767943d
Make sure we don't try to emulate poll() when it's there if --disable-ffserver... 10l
mmu_man
parents:
1798
diff
changeset
|
166 #endif /* CONFIG_FFSERVER */ |
1797 | 167 |