2 * Various utilities for ffmpeg system
3 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 * copyright (c) 2002 Francois Revol
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #if defined(CONFIG_WINCE)
25 /* Skip includes on WinCE. */
26 #elif defined(__MINGW32__)
27 #include <sys/types.h>
28 #include <sys/timeb.h>
29 #elif defined(CONFIG_OS2)
39 #ifndef HAVE_SYS_POLL_H
40 #if defined(__MINGW32__)
43 #include <sys/select.h>
48 * gets the current time in micro seconds.
50 int64_t av_gettime(void)
52 #if defined(CONFIG_WINCE)
53 return timeGetTime() * INT64_C(1000);
54 #elif defined(__MINGW32__)
57 return ((int64_t)tb.time * INT64_C(1000) + (int64_t)tb.millitm) * INT64_C(1000);
60 gettimeofday(&tv,NULL);
61 return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
65 #if !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R)
66 struct tm *localtime_r(const time_t *t, struct tm *tp)
76 #endif /* !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R) */
78 #if !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK)
81 #include "barpainet.h"
83 int inet_aton (const char * str, struct in_addr * add)
85 const char * pch = str;
86 unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0;
89 pch = strpbrk(pch,".");
90 if (pch == 0 || ++pch == 0) goto done;
92 pch = strpbrk(pch,".");
93 if (pch == 0 || ++pch == 0) goto done;
95 pch = strpbrk(pch,".");
96 if (pch == 0 || ++pch == 0) goto done;
100 add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1;
104 #endif /* !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) */
106 #ifdef CONFIG_FFSERVER
107 #ifndef HAVE_SYS_POLL_H
108 int poll(struct pollfd *fds, nfds_t numfds, int timeout)
112 fd_set exception_set;
119 FD_ZERO(&exception_set);
122 for(i = 0; i < numfds; i++) {
125 if (fds[i].fd >= FD_SETSIZE) {
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);
139 /* Hey!? Nothing to poll, in fact!!! */
143 rc = select(n+1, &read_set, &write_set, &exception_set, NULL);
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);
155 for(i = 0; i < (nfds_t) n; i++) {
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;
165 #endif /* HAVE_SYS_POLL_H */
166 #endif /* CONFIG_FFSERVER */