[Ffmpeg-devel] [PATCH] MingW RTSP support

Michael A. Kohn mike
Mon Apr 3 20:50:45 CEST 2006



> On Sun, Apr 02, 2006 at 09:58:10AM -0500, Michael A. Kohn wrote:
>
>
> Yes. Somehow BeOS lusers get away with this stuff because their OS
> isn't considered as "lame" as windows by most developers, but I don't
> distinguish. One broken, standards-violating, proprietary OS is as bad
> as another..
>
> Rich

Okay, I'm going to try one more time I think.  This patch is just
like the others, except I changed the way the headers look.  I downloaded
a copy of BeOS just to make sure these changes don't change the way it
compiles.  The headers that used to look like this:

#include "avformat.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#if defined(__BEOS__) || defined(__INNOTEK_LIBC__)
typedef int socklen_t;
#endif
#ifndef __BEOS__
# include <arpa/inet.h>
#else
# include "barpainet.h"
#endif
#include <netdb.h>
#include <sys/time.h>
#include <fcntl.h>

now look like this (and mingw compiles and works):

#include "avformat.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <fcntl.h>
#if !defined(__MINGW32__) && !defined(__BEOS__)
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#endif

I think this is a nice comprimise.. the code looks cleaner now and
both broken OS's compile...

the only problem with BeOS (which I guess doesn't matter anyway) is
SO_ERROR doesn't exist so without commenting or #defining out, it won't
compile anyway... maybe no one even uses ffmpeg under BeOS so no one
noticed?

One other extra thing I did... I added this these lines for UINT32_MAX
and INT32_MAX in os_support.h:

#ifndef UINT32_MAX
#define UINT32_MAX (4294967295U)
#endif

BeOS required this.. and I believe OpenBSD requires it too.  So these
lines might be a good thing whether this patch is accepted or not..


-------------- next part --------------
diff -Naur ffmpeg_orig/configure ffmpeg/configure
--- ffmpeg_orig/configure	2006-03-28 17:36:07.000000000 -0600
+++ ffmpeg/configure	2006-04-01 16:17:21.000000000 -0600
@@ -922,7 +922,7 @@
     dv1394="no"
     dc1394="no"
     ffserver="no"
-    network="no"
+    extralibs="$extralibs -lws2_32"
 if test "$mingwce" = "yes"; then
     protocols="no"
 fi
diff -Naur ffmpeg_orig/libavformat/http.c ffmpeg/libavformat/http.c
--- ffmpeg_orig/libavformat/http.c	2006-01-12 16:43:23.000000000 -0600
+++ ffmpeg/libavformat/http.c	2006-04-03 13:05:51.000000000 -0500
@@ -19,14 +19,12 @@
 #include "avformat.h"
 #include <unistd.h>
 #include <sys/types.h>
+#if !defined(__MINGW32__) && !defined(__BEOS__)
 #include <sys/socket.h>
 #include <netinet/in.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
-#endif
 #include <netdb.h>
+#include <arpa/inet.h>
+#endif
 
 
 /* XXX: POST protocol is not completly implemented because ffmpeg use
diff -Naur ffmpeg_orig/libavformat/os_support.c ffmpeg/libavformat/os_support.c
--- ffmpeg_orig/libavformat/os_support.c	2006-01-22 18:57:59.000000000 -0600
+++ ffmpeg/libavformat/os_support.c	2006-03-31 09:40:29.000000000 -0600
@@ -32,6 +32,9 @@
 #include <sys/time.h>
 #endif
 #include <time.h>
+#ifdef __MINGW32__
+#include <winsock.h>
+#endif
 
 /**
  * gets the current time in micro seconds.
@@ -65,3 +68,30 @@
 }
 #endif /* !defined(HAVE_LOCALTIME_R) */
 #endif /* !defined(CONFIG_WINCE) */
+
+#ifdef __MINGW32__
+int init_winsock()
+{
+WSADATA wsaData;
+WORD wVersionRequested=MAKEWORD(1,1);
+int Win32isStupid;
+
+  Win32isStupid=WSAStartup(wVersionRequested, &wsaData);
+  if (Win32isStupid) return -1;
+
+  return 0;
+}
+
+int inet_aton(const char *hostname, struct in_addr *sin_addr)
+{
+    sin_addr->s_addr=inet_addr(hostname);
+    if (sin_addr->s_addr == INADDR_NONE) {
+      return 0;
+    }
+
+    return -1;
+}
+#endif
+
+
+
diff -Naur ffmpeg_orig/libavformat/os_support.h ffmpeg/libavformat/os_support.h
--- ffmpeg_orig/libavformat/os_support.h	2004-04-24 06:51:38.000000000 -0500
+++ ffmpeg/libavformat/os_support.h	2006-04-03 12:53:29.000000000 -0500
@@ -10,10 +10,28 @@
  * - strcasecmp() (OS/2)
  */
 
+#ifdef __BEOS__
+#include "barpainet.h"
+#endif
+
+#if defined(__BEOS__) || defined(__MINGW32__) || defined(__INNOTEK_LIBC__)
+typedef int socklen_t;
+#endif
+
 #ifdef __MINGW32__
 __declspec(dllimport) void __stdcall Sleep(unsigned long dwMilliseconds);
 // #  include <windows.h>
+#define GUID microsuck_GUID
+#include <winsock.h>
+#undef GUID
 #  define usleep(t)    Sleep((t) / 1000)
+#  define sleep(t)     Sleep((t) * 1000)
+#define O_NONBLOCK FIONBIO
+#define fcntl(fd,b,c) { u_long arg=1L; \
+                        ioctlsocket(fd, c, &arg); }
+// #define EINPROGRESS WSAEINPROGRESS
+#define EINPROGRESS 0
+int init_winsock();
 #endif
 
 #ifdef __BEOS__
@@ -29,4 +47,12 @@
 static inline int strcasecmp(const char* s1, const char* s2) { return stricmp(s1,s2); }
 #endif
 
+#ifndef UINT32_MAX
+#define UINT32_MAX (4294967295U)
+#endif
+
+#ifndef INT32_MAX
+#define INT32_MAX (2147483647)
+#endif
+
 #endif /* _OS_SUPPORT_H */
diff -Naur ffmpeg_orig/libavformat/rtp.c ffmpeg/libavformat/rtp.c
--- ffmpeg_orig/libavformat/rtp.c	2006-03-30 10:44:32.000000000 -0600
+++ ffmpeg/libavformat/rtp.c	2006-04-03 13:05:00.000000000 -0500
@@ -22,14 +22,12 @@
 
 #include <unistd.h>
 #include <sys/types.h>
+#if !defined(__MINGW32__) && !defined(__BEOS__)
 #include <sys/socket.h>
 #include <netinet/in.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
-#endif
 #include <netdb.h>
+#include <arpa/inet.h>
+#endif
 
 //#define DEBUG
 
diff -Naur ffmpeg_orig/libavformat/rtpproto.c ffmpeg/libavformat/rtpproto.c
--- ffmpeg_orig/libavformat/rtpproto.c	2006-01-12 16:43:25.000000000 -0600
+++ ffmpeg/libavformat/rtpproto.c	2006-04-03 13:29:34.000000000 -0500
@@ -21,15 +21,13 @@
 #include <unistd.h>
 #include <stdarg.h>
 #include <sys/types.h>
+#include <fcntl.h>
+#if !defined(__MINGW32__) && !defined(__BEOS__)
 #include <sys/socket.h>
 #include <netinet/in.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
-#endif
 #include <netdb.h>
-#include <fcntl.h>
+#include <arpa/inet.h>
+#endif
 
 #define RTP_TX_BUF_SIZE  (64 * 1024)
 #define RTP_RX_BUF_SIZE  (128 * 1024)
diff -Naur ffmpeg_orig/libavformat/rtsp.c ffmpeg/libavformat/rtsp.c
--- ffmpeg_orig/libavformat/rtsp.c	2006-03-10 18:22:21.000000000 -0600
+++ ffmpeg/libavformat/rtsp.c	2006-04-03 13:05:33.000000000 -0500
@@ -20,12 +20,10 @@
 
 #include <unistd.h> /* for select() prototype */
 #include <sys/time.h>
+#if !defined(__MINGW32__) && !defined(__BEOS__)
 #include <netinet/in.h>
 #include <sys/socket.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
+#include <arpa/inet.h>
 #endif
 
 //#define DEBUG
diff -Naur ffmpeg_orig/libavformat/tcp.c ffmpeg/libavformat/tcp.c
--- ffmpeg_orig/libavformat/tcp.c	2006-02-02 07:07:30.000000000 -0600
+++ ffmpeg/libavformat/tcp.c	2006-04-03 13:29:45.000000000 -0500
@@ -19,19 +19,14 @@
 #include "avformat.h"
 #include <unistd.h>
 #include <sys/types.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#if !defined(__MINGW32__) && !defined(__BEOS__)
 #include <sys/socket.h>
 #include <netinet/in.h>
-#if defined(__BEOS__) || defined(__INNOTEK_LIBC__)
-typedef int socklen_t;
-#endif
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
-#endif
 #include <netdb.h>
-#include <sys/time.h>
-#include <fcntl.h>
+#include <arpa/inet.h>
+#endif
 
 typedef struct TCPContext {
     int fd;
@@ -77,6 +72,10 @@
     if (port <= 0 || port >= 65536)
         goto fail;
 
+#ifdef __MINGW32__
+    init_winsock();
+#endif
+
     dest_addr.sin_family = AF_INET;
     dest_addr.sin_port = htons(port);
     if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
@@ -147,11 +146,7 @@
         tv.tv_usec = 100 * 1000;
         ret = select(fd_max + 1, &rfds, NULL, NULL, &tv);
         if (ret > 0 && FD_ISSET(s->fd, &rfds)) {
-#ifdef __BEOS__
             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__
@@ -184,11 +179,7 @@
         tv.tv_usec = 100 * 1000;
         ret = select(fd_max + 1, NULL, &wfds, NULL, &tv);
         if (ret > 0 && FD_ISSET(s->fd, &wfds)) {
-#ifdef __BEOS__
             len = send(s->fd, buf, size, 0);
-#else
-            len = write(s->fd, buf, size);
-#endif
             if (len < 0) {
                 if (errno != EINTR && errno != EAGAIN) {
 #ifdef __BEOS__
@@ -211,7 +202,7 @@
 static int tcp_close(URLContext *h)
 {
     TCPContext *s = h->priv_data;
-#ifdef CONFIG_BEOS_NETSERVER
+#if defined(CONFIG_BEOS_NETSERVER) || defined(__MINGW32__)
     closesocket(s->fd);
 #else
     close(s->fd);
diff -Naur ffmpeg_orig/libavformat/udp.c ffmpeg/libavformat/udp.c
--- ffmpeg_orig/libavformat/udp.c	2006-01-12 16:43:25.000000000 -0600
+++ ffmpeg/libavformat/udp.c	2006-04-03 13:06:07.000000000 -0500
@@ -19,14 +19,12 @@
 #include "avformat.h"
 #include <unistd.h>
 #include <sys/types.h>
+#if !defined(__MINGW32__) && !defined(__BEOS__)
 #include <sys/socket.h>
+#include <netdb.h>
 #include <netinet/in.h>
-#ifndef __BEOS__
-# include <arpa/inet.h>
-#else
-# include "barpainet.h"
+#include <arpa/inet.h>
 #endif
-#include <netdb.h>
 
 #ifndef IPV6_ADD_MEMBERSHIP
 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
@@ -211,7 +209,7 @@
 
  fail:
     if (udp_fd >= 0)
-#ifdef CONFIG_BEOS_NETSERVER
+#if defined(CONFIG_BEOS_NETSERVER) || defined(__MINGW32__)
         closesocket(udp_fd);
 #else
         close(udp_fd);
@@ -357,6 +355,11 @@
     getsockname(udp_fd, (struct sockaddr *)&my_addr1, &len);
     s->local_port = ntohs(my_addr1.sin_port);
 
+#ifdef __MINGW32__
+    tmp=65536;   /* 64k UDP buffer size.  Should this be bigger? */
+    setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp));
+#endif
+
 #ifndef CONFIG_BEOS_NETSERVER
     if (s->is_multicast) {
         if (h->flags & URL_WRONLY) {
@@ -411,7 +414,7 @@
     return 0;
  fail:
     if (udp_fd >= 0)
-#ifdef CONFIG_BEOS_NETSERVER
+#if defined(CONFIG_BEOS_NETSERVER) || defined(__MINGW32__)
         closesocket(udp_fd);
 #else
         close(udp_fd);
@@ -471,7 +474,7 @@
 {
     UDPContext *s = h->priv_data;
 
-#ifndef CONFIG_BEOS_NETSERVER
+#if !defined(CONFIG_BEOS_NETSERVER) && !defined(__MINGW32__)
 #ifndef CONFIG_IPV6
     if (s->is_multicast && !(h->flags & URL_WRONLY)) {
         if (setsockopt(s->udp_fd, IPPROTO_IP, IP_DROP_MEMBERSHIP,



More information about the ffmpeg-devel mailing list