From: François Revol Date: Sat, 2 Nov 2002 10:35:07 +0000 (+0000) Subject: added BeOS net_server support (R5 network stack), basically the same X-Git-Tag: v0.5~17113 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9ddd71fc6063b357344f81a0f704c1d04f584ada;p=coroid%2Flibav_saccubus.git added BeOS net_server support (R5 network stack), basically the same problems as with winsock (sockets != fd), and the broken select(). based on older patch by Andrew Bachmann. patch by (François Revol ) Originally committed as revision 1144 to svn://svn.ffmpeg.org/ffmpeg/trunk --- diff --git a/ffmpeg.c b/ffmpeg.c index 46b4f0098..a96934011 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -27,10 +27,6 @@ #include #include #endif -#ifdef __BEOS__ -/* for snooze() */ -#include -#endif #include #include @@ -227,14 +223,18 @@ static void term_init(void) tcsetattr (0, TCSANOW, &tty); atexit(term_exit); +#ifdef CONFIG_BEOS_NETSERVER + fcntl(0, F_SETFL, fcntl(0, F_GETFL) | O_NONBLOCK); +#endif } /* read a key without blocking */ static int read_key(void) { - struct timeval tv; - int n; + int n = 1; unsigned char ch; +#ifndef CONFIG_BEOS_NETSERVER + struct timeval tv; fd_set rfds; FD_ZERO(&rfds); @@ -242,6 +242,7 @@ static int read_key(void) tv.tv_sec = 0; tv.tv_usec = 0; n = select(1, &rfds, NULL, NULL, &tv); +#endif if (n > 0) { n = read(0, &ch, 1); if (n == 1) diff --git a/libav/Makefile b/libav/Makefile index bd33e4aea..e3a8ace27 100644 --- a/libav/Makefile +++ b/libav/Makefile @@ -31,6 +31,10 @@ endif ifeq ($(CONFIG_NETWORK),yes) OBJS+= udp.o tcp.o http.o rtsp.o rtp.o rtpproto.o +# BeOS network stuff +ifeq ($(CONFIG_BEOS_NETSERVER),yes) +OBJS+= barpainet.o +endif endif ifeq ($(CONFIG_VORBIS),yes) diff --git a/libav/barpainet.c b/libav/barpainet.c new file mode 100644 index 000000000..c1e887771 --- /dev/null +++ b/libav/barpainet.c @@ -0,0 +1,25 @@ + +#include +#include +#include "barpainet.h" + +int inet_aton (const char * str, struct in_addr * add) { + const char * pch = str; + unsigned int add1 = 0, add2 = 0, add3 = 0, add4 = 0; + + add1 = atoi(pch); + pch = strpbrk(pch,"."); + if (pch == 0 || ++pch == 0) goto done; + add2 = atoi(pch); + pch = strpbrk(pch,"."); + if (pch == 0 || ++pch == 0) goto done; + add3 = atoi(pch); + pch = strpbrk(pch,"."); + if (pch == 0 || ++pch == 0) goto done; + add4 = atoi(pch); + +done: + add->s_addr=(add4<<24)+(add3<<16)+(add2<<8)+add1; + + return 1; +} diff --git a/libav/barpainet.h b/libav/barpainet.h new file mode 100644 index 000000000..461403b3f --- /dev/null +++ b/libav/barpainet.h @@ -0,0 +1,23 @@ +#ifndef BARPA_INET_H +#define BARPA_INET_H + +#include "../config.h" + +#ifdef CONFIG_BEOS_NETSERVER + +# include +int inet_aton (const char * str, struct in_addr * add); +# define PF_INET AF_INET +# define SO_SNDBUF 0x40000001 + +/* fake */ +struct ip_mreq { + struct in_addr imr_multiaddr; /* IP multicast address of group */ + struct in_addr imr_interface; /* local IP address of interface */ +}; + +#else +# include +#endif + +#endif /* BARPA_INET_H */ diff --git a/libav/http.c b/libav/http.c index 21ac51dd4..7271a6da8 100644 --- a/libav/http.c +++ b/libav/http.c @@ -22,7 +22,11 @@ #include #include #include -#include +#ifndef __BEOS__ +# include +#else +# include "barpainet.h" +#endif #include diff --git a/libav/rtp.c b/libav/rtp.c index 45ccc2c39..714787c88 100644 --- a/libav/rtp.c +++ b/libav/rtp.c @@ -22,7 +22,11 @@ #include #include #include -#include +#ifndef __BEOS__ +# include +#else +# include "barpainet.h" +#endif #include //#define DEBUG diff --git a/libav/rtpproto.c b/libav/rtpproto.c index dac5273a8..41823fc82 100644 --- a/libav/rtpproto.c +++ b/libav/rtpproto.c @@ -23,7 +23,11 @@ #include #include #include -#include +#ifndef __BEOS__ +# include +#else +# include "barpainet.h" +#endif #include #include diff --git a/libav/rtsp.c b/libav/rtsp.c index acacc5de9..81b59f891 100644 --- a/libav/rtsp.c +++ b/libav/rtsp.c @@ -21,7 +21,11 @@ #include #include #include -#include +#ifndef __BEOS__ +# include +#else +# include "barpainet.h" +#endif //#define DEBUG diff --git a/libav/tcp.c b/libav/tcp.c index 644e13939..61d866552 100644 --- a/libav/tcp.c +++ b/libav/tcp.c @@ -22,7 +22,11 @@ #include #include #include -#include +#ifndef __BEOS__ +# include +#else +# include "barpainet.h" +#endif #include typedef struct TCPContext { @@ -103,10 +107,18 @@ static int tcp_read(URLContext *h, UINT8 *buf, int size) size1 = size; while (size > 0) { +#ifdef CONFIG_BEOS_NETSERVER + len = recv (s->fd, buf, size, 0); +#else len = read (s->fd, buf, size); +#endif if (len < 0) { if (errno != EINTR && errno != EAGAIN) +#ifdef __BEOS__ + return errno; +#else return -errno; +#endif else continue; } else if (len == 0) { @@ -125,9 +137,17 @@ static int tcp_write(URLContext *h, UINT8 *buf, int size) size1 = size; while (size > 0) { +#ifdef CONFIG_BEOS_NETSERVER + ret = send (s->fd, buf, size, 0); +#else ret = write (s->fd, buf, size); +#endif if (ret < 0 && errno != EINTR && errno != EAGAIN) +#ifdef __BEOS__ + return errno; +#else return -errno; +#endif size -= ret; buf += ret; } @@ -137,7 +157,11 @@ static int tcp_write(URLContext *h, UINT8 *buf, int size) static int tcp_close(URLContext *h) { TCPContext *s = h->priv_data; +#ifdef CONFIG_BEOS_NETSERVER + closesocket(s->fd); +#else close(s->fd); +#endif av_free(s); return 0; } diff --git a/libav/udp.c b/libav/udp.c index ad514cb2f..8df93a8a8 100644 --- a/libav/udp.c +++ b/libav/udp.c @@ -21,7 +21,11 @@ #include #include #include -#include +#ifndef __BEOS__ +# include +#else +# include "barpainet.h" +#endif #include typedef struct { @@ -154,6 +158,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) getsockname(udp_fd, (struct sockaddr *)&my_addr1, &len); s->local_port = ntohs(my_addr1.sin_port); +#ifndef CONFIG_BEOS_NETSERVER if (s->is_multicast) { if (h->flags & URL_WRONLY) { /* output */ @@ -174,6 +179,7 @@ static int udp_open(URLContext *h, const char *uri, int flags) } } } +#endif if (is_output) { /* limit the tx buf size to limit latency */ @@ -189,7 +195,11 @@ static int udp_open(URLContext *h, const char *uri, int flags) return 0; fail: if (udp_fd >= 0) +#ifdef CONFIG_BEOS_NETSERVER + closesocket(udp_fd); +#else close(udp_fd); +#endif av_free(s); return -EIO; } @@ -237,6 +247,7 @@ static int udp_close(URLContext *h) { UDPContext *s = h->priv_data; +#ifndef CONFIG_BEOS_NETSERVER if (s->is_multicast && !(h->flags & URL_WRONLY)) { if (setsockopt(s->udp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP, &s->mreq, sizeof(s->mreq)) < 0) { @@ -244,6 +255,9 @@ static int udp_close(URLContext *h) } } close(s->udp_fd); +#else + closesocket(s->udp_fd); +#endif av_free(s); return 0; }