Statistics
| Branch: | Revision:

ffmpeg / libavformat / os_support.c @ e19fbbec

History | View | Annotate | Download (4.2 KB)

1 f71869a4 Fabrice Bellard
/*
2
 * Various utilities for ffmpeg system
3
 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4 54eb77c0 Diego Biurrun
 * copyright (c) 2002 Francois Revol
5 f71869a4 Fabrice Bellard
 *
6 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9 f71869a4 Fabrice Bellard
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
12 f71869a4 Fabrice Bellard
 *
13 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
14 f71869a4 Fabrice Bellard
 * 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.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
20 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 f71869a4 Fabrice Bellard
 */
22 17c22f57 Steven M. Schultz
#include "config.h"
23 f71869a4 Fabrice Bellard
#include "avformat.h"
24 fdc7b570 Diego Biurrun
#if defined(CONFIG_WINCE)
25
/* Skip includes on WinCE. */
26 2f30a81d Diego Biurrun
#elif defined(__MINGW32__)
27 f71869a4 Fabrice Bellard
#include <sys/types.h>
28
#include <sys/timeb.h>
29
#elif defined(CONFIG_OS2)
30
#include <string.h>
31
#include <sys/time.h>
32
#else
33
#include <unistd.h>
34
#include <fcntl.h>
35
#include <sys/time.h>
36
#endif
37
#include <time.h>
38 36c07acd François Revol
39 b0c858d8 François Revol
#ifndef HAVE_SYS_POLL_H
40 36c07acd François Revol
#if defined(__MINGW32__)
41
#include <winsock2.h>
42
#else
43 b0c858d8 François Revol
#include <sys/select.h>
44
#endif
45 36c07acd François Revol
#endif
46 f71869a4 Fabrice Bellard
47 f6506a54 Michael Niedermayer
/**
48
 * gets the current time in micro seconds.
49
 */
50 f71869a4 Fabrice Bellard
int64_t av_gettime(void)
51
{
52 ac44871c Gildas Bazin
#if defined(CONFIG_WINCE)
53 8da9266c Måns Rullgård
    return timeGetTime() * INT64_C(1000);
54 2f30a81d Diego Biurrun
#elif defined(__MINGW32__)
55 2a86d50b Sascha Sommer
    struct timeb tb;
56 f71869a4 Fabrice Bellard
    _ftime(&tb);
57 8da9266c Måns Rullgård
    return ((int64_t)tb.time * INT64_C(1000) + (int64_t)tb.millitm) * INT64_C(1000);
58 f71869a4 Fabrice Bellard
#else
59
    struct timeval tv;
60
    gettimeofday(&tv,NULL);
61
    return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
62
#endif
63
}
64
65 fa28bc16 Måns Rullgård
#if !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R)
66 f71869a4 Fabrice Bellard
struct tm *localtime_r(const time_t *t, struct tm *tp)
67
{
68
    struct tm *l;
69 115329f1 Diego Biurrun
70 f71869a4 Fabrice Bellard
    l = localtime(t);
71
    if (!l)
72
        return 0;
73
    *tp = *l;
74
    return tp;
75
}
76 fa28bc16 Måns Rullgård
#endif /* !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R) */
77 54eb77c0 Diego Biurrun
78 eaa53b95 Diego Biurrun
#if !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK)
79
#include <stdlib.h>
80
#include <strings.h>
81 c9fdab0d François Revol
#include "network.h"
82 eaa53b95 Diego Biurrun
83 54eb77c0 Diego Biurrun
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
}
104 eaa53b95 Diego Biurrun
#endif /* !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) */
105 b0c858d8 François Revol
106 457b101e François Revol
#ifdef CONFIG_FFSERVER
107 b0c858d8 François Revol
#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
}
165
#endif /* HAVE_SYS_POLL_H */
166 457b101e François Revol
#endif /* CONFIG_FFSERVER */