OSDN Git Service

added BeOS net_server support (R5 network stack), basically the same
authorFrançois Revol <revol@free.fr>
Sat, 2 Nov 2002 10:35:07 +0000 (10:35 +0000)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 2 Nov 2002 10:35:07 +0000 (10:35 +0000)
problems as with winsock (sockets != fd), and the broken select().
based on older patch by Andrew Bachmann.
patch by (François Revol <revol at free dot fr>)

Originally committed as revision 1144 to svn://svn.ffmpeg.org/ffmpeg/trunk

ffmpeg.c
libav/Makefile
libav/barpainet.c [new file with mode: 0644]
libav/barpainet.h [new file with mode: 0644]
libav/http.c
libav/rtp.c
libav/rtpproto.c
libav/rtsp.c
libav/tcp.c
libav/udp.c

index 46b4f00..a969340 100644 (file)
--- a/ffmpeg.c
+++ b/ffmpeg.c
 #include <termios.h>
 #include <sys/resource.h>
 #endif
-#ifdef __BEOS__
-/* for snooze() */
-#include <OS.h>
-#endif
 #include <time.h>
 #include <ctype.h>
 
@@ -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)
index bd33e4a..e3a8ace 100644 (file)
@@ -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 (file)
index 0000000..c1e8877
--- /dev/null
@@ -0,0 +1,25 @@
+
+#include <stdlib.h>
+#include <strings.h>
+#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 (file)
index 0000000..461403b
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef BARPA_INET_H
+#define BARPA_INET_H
+
+#include "../config.h"
+
+#ifdef CONFIG_BEOS_NETSERVER
+
+# include <socket.h>
+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 <arpa/inet.h>
+#endif
+
+#endif /* BARPA_INET_H */
index 21ac51d..7271a6d 100644 (file)
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <arpa/inet.h>
+#ifndef __BEOS__
+# include <arpa/inet.h>
+#else
+# include "barpainet.h"
+#endif
 #include <netdb.h>
 
 
index 45ccc2c..714787c 100644 (file)
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <arpa/inet.h>
+#ifndef __BEOS__
+# include <arpa/inet.h>
+#else
+# include "barpainet.h"
+#endif
 #include <netdb.h>
 
 //#define DEBUG
index dac5273..41823fc 100644 (file)
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <arpa/inet.h>
+#ifndef __BEOS__
+# include <arpa/inet.h>
+#else
+# include "barpainet.h"
+#endif
 #include <netdb.h>
 #include <fcntl.h>
 
index acacc5d..81b59f8 100644 (file)
 #include <sys/time.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
-#include <arpa/inet.h>
+#ifndef __BEOS__
+# include <arpa/inet.h>
+#else
+# include "barpainet.h"
+#endif
 
 //#define DEBUG
 
index 644e139..61d8665 100644 (file)
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <arpa/inet.h>
+#ifndef __BEOS__
+# include <arpa/inet.h>
+#else
+# include "barpainet.h"
+#endif
 #include <netdb.h>
 
 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;
 }
index ad514cb..8df93a8 100644 (file)
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <arpa/inet.h>
+#ifndef __BEOS__
+# include <arpa/inet.h>
+#else
+# include "barpainet.h"
+#endif
 #include <netdb.h>
 
 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;
 }