Statistics
| Branch: | Revision:

ffmpeg / libavformat / os_support.c @ e19fbbec

History | View | Annotate | Download (4.2 KB)

1
/*
2
 * Various utilities for ffmpeg system
3
 * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
4
 * copyright (c) 2002 Francois Revol
5
 *
6
 * This file is part of FFmpeg.
7
 *
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.
12
 *
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.
17
 *
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
21
 */
22
#include "config.h"
23
#include "avformat.h"
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)
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

    
39
#ifndef HAVE_SYS_POLL_H
40
#if defined(__MINGW32__)
41
#include <winsock2.h>
42
#else
43
#include <sys/select.h>
44
#endif
45
#endif
46

    
47
/**
48
 * gets the current time in micro seconds.
49
 */
50
int64_t av_gettime(void)
51
{
52
#if defined(CONFIG_WINCE)
53
    return timeGetTime() * INT64_C(1000);
54
#elif defined(__MINGW32__)
55
    struct timeb tb;
56
    _ftime(&tb);
57
    return ((int64_t)tb.time * INT64_C(1000) + (int64_t)tb.millitm) * INT64_C(1000);
58
#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
#if !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R)
66
struct tm *localtime_r(const time_t *t, struct tm *tp)
67
{
68
    struct tm *l;
69

    
70
    l = localtime(t);
71
    if (!l)
72
        return 0;
73
    *tp = *l;
74
    return tp;
75
}
76
#endif /* !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R) */
77

    
78
#if !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK)
79
#include <stdlib.h>
80
#include <strings.h>
81
#include "network.h"
82

    
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
}
104
#endif /* !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) */
105

    
106
#ifdef CONFIG_FFSERVER
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
}
165
#endif /* HAVE_SYS_POLL_H */
166
#endif /* CONFIG_FFSERVER */
167