[Ffmpeg-devel] Network patch for MingW users

Måns Rullgård mans
Mon Feb 19 23:15:18 CET 2007


Klaas-Pieter Vlieg <vlieg at eurescom.eu> writes:

>> From: Ryan Martell [mailto:rdm4 at martellventures.com] 
>> Sent: 19 February 2007 21:31
>> To: FFmpeg development discussions and patches
>> Subject: Re: [Ffmpeg-devel] Network patch for MingW users
>> 
>> 
>> On Feb 4, 2007, at 2:36 PM, Ramiro Polla wrote:
>> 
>> > Klaas-Pieter Vlieg wrote:
>> >> Attached is a ffmpeg network patch for MingW users.
>> >> Credits go to Michael Kohn (http://www.mikekohn.net/stuff/ 
>> >> ffmpeg.php).
>> >>
>> >
>> > Attached patch (also based on Michael Kohn's patch) is simpler.
>> 
>> What's the status of this patch?  I'd love to have it in the 
>> main branch.
>> 
> I don't have the time to improve it so that it meets the tough
> ffmpeg dev requirements.  Maybe someone has time to do this. I've
> attached my latest version.
>
> Klaas-Pieter Vlieg
>
>
> Index: patched7991/configure
> ===================================================================
> --- patched7991/configure	(revision 7991)
> +++ patched7991/configure	(working copy)
> @@ -1087,8 +1087,8 @@
>      fi
>      dv1394="no"
>      dc1394="no"
> -    ffserver="no"
> -    network="no"
> +    ffserver="yes"

ffserver is enabled by default.  By doing that, you're overriding
command line selection.

> +    extralibs="$extralibs -lws2_32"
>      if enabled wince; then
>          protocols="no"
>      fi
> Index: patched7991/ffserver.c
> ===================================================================
> --- patched7991/ffserver.c	(revision 7991)
> +++ patched7991/ffserver.c	(working copy)
> @@ -24,7 +24,6 @@
>  #include <stdarg.h>
>  #include <unistd.h>
>  #include <fcntl.h>
> -#include <sys/ioctl.h>
>  #ifdef HAVE_SYS_POLL_H
>  #include <sys/poll.h>
>  #endif
> @@ -33,11 +32,18 @@
>  #undef time //needed because HAVE_AV_CONFIG_H is defined on top
>  #include <time.h>
>  #include <sys/types.h>
> +
> +#if !defined(__MINGW32__)
> +#include <sys/ioctl.h>
>  #include <sys/socket.h>
>  #include <sys/wait.h>
>  #include <netinet/in.h>
>  #include <arpa/inet.h>
>  #include <netdb.h>
> +#else
> +#include <winsock.h>
> +#endif

We have a network.h to hide cruft like this in.  Use it.

>  #include <signal.h>
>  #ifdef HAVE_DLFCN_H
>  #include <dlfcn.h>
> Index: patched7991/libavformat/mpegts.c
> ===================================================================
> --- patched7991/libavformat/mpegts.c	(revision 7991)
> +++ patched7991/libavformat/mpegts.c	(working copy)
> @@ -1227,11 +1227,11 @@
>              ts->set_service_ret = -1;
>  
>              /* first do a scaning to get all the services */
> -            url_fseek(pb, pos, SEEK_SET);
> -            mpegts_scan_sdt(ts);
> +//            url_fseek(pb, pos, SEEK_SET);
> +//            mpegts_scan_sdt(ts);
> +//
> +//            handle_packets(ts, s->probesize);
>  
> -            handle_packets(ts, s->probesize);
> -
>              if (ts->nb_services <= 0) {
>                  /* no SDT found, we try to look at the PAT */

Was this meant to be included in the patch?  Looks unrelated.

> Index: patched7991/libavformat/network.h
> ===================================================================
> --- patched7991/libavformat/network.h	(revision 7991)
> +++ patched7991/libavformat/network.h	(working copy)
> @@ -22,9 +22,12 @@
>  #define NETWORK_H
>  
>  #include <sys/types.h>
> +
> +#if !defined(__MINGW32__)
>  #include <sys/socket.h>
>  #include <netinet/in.h>
>  #include <arpa/inet.h>
>  #include <netdb.h>
> +#endif

Is it possible to check for functionality rather than OS here?  I
don't mind adding some extra tests to configure.

>  #endif
> Index: patched7991/libavformat/os_support.c
> ===================================================================
> --- patched7991/libavformat/os_support.c	(revision 7991)
> +++ patched7991/libavformat/os_support.c	(working copy)
> @@ -75,6 +75,31 @@
>  }
>  #endif /* !defined(CONFIG_WINCE) && !defined(HAVE_LOCALTIME_R) */
>  
> +#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

inet_aton should be checked for like any other function.

> +#if 0
>  #if !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK)
>  #include <stdlib.h>
>  #include <strings.h>
> @@ -102,6 +127,7 @@
>      return 1;
>  }
>  #endif /* !defined(HAVE_INET_ATON) && defined(CONFIG_NETWORK) */
> +#endif /* 0 */

What's with the #if 0?

>  #ifdef CONFIG_FFSERVER
>  #ifndef HAVE_SYS_POLL_H
> @@ -164,4 +190,3 @@
>  }
>  #endif /* HAVE_SYS_POLL_H */
>  #endif /* CONFIG_FFSERVER */
> -

Cosmetic.

> Index: patched7991/libavformat/os_support.h
> ===================================================================
> --- patched7991/libavformat/os_support.h	(revision 7991)
> +++ patched7991/libavformat/os_support.h	(working copy)
> @@ -35,16 +35,25 @@
>   * - poll() (BeOS, MinGW)
>   */
>  
> -#if defined(__BEOS__) || defined(__INNOTEK_LIBC__)
> +#if defined(__BEOS__) || defined(__MINGW32__) || defined(__INNOTEK_LIBC__)
>  typedef int socklen_t;
>  #endif

Arrgh, more OS dependencies.  This too should be tested in configure.

>  #ifdef __MINGW32__
>  __declspec(dllimport) void __stdcall Sleep(unsigned long dwMilliseconds);
>  // #  include <windows.h>
> +#define GUID microsoft_issue_GUID
> +#include <winsock.h>
> +#undef GUID
>  #  define usleep(t)    Sleep((t) / 1000)
> -#  include <fcntl.h>
> -#  define lseek(f,p,w) _lseeki64((f), (p), (w))
> +#  define sleep(t)     Sleep((t) * 1000)
> +#define O_NONBLOCK FIONBIO
> +#define fcntl(fd,b,c) { u_long arg=1L; \
> +                        ioctlsocket(fd, c, &arg); }

I'm not convinced this is a good idea.  Someone might use fcntl() on a
real file.

> +// #define EINPROGRESS WSAEINPROGRESS

Why?

> +#define EINPROGRESS 0

Why??

> +int init_winsock();
> +
>  #  define HAVE_CLOSESOCKET 1
>  #endif
>  
> Index: patched7991/libavformat/tcp.c
> ===================================================================
> --- patched7991/libavformat/tcp.c	(revision 7991)
> +++ patched7991/libavformat/tcp.c	(working copy)
> @@ -68,6 +68,10 @@
>      if (port <= 0 || port >= 65536)
>          goto fail;
>  
> +#ifdef __MINGW32__
> +    init_winsock();
> +#endif

Aaaaiiiieeee!  NO MORE OF THIS. PLEASE.

>      dest_addr.sin_family = AF_INET;
>      dest_addr.sin_port = htons(port);
>      if (resolve_host(&dest_addr.sin_addr, hostname) < 0)
> Index: patched7991/libavformat/udp.c
> ===================================================================
> --- patched7991/libavformat/udp.c	(revision 7991)
> +++ patched7991/libavformat/udp.c	(working copy)
> @@ -287,6 +287,8 @@
>      struct sockaddr_in my_addr, my_addr1;
>      int len;
>  #endif
> +    int t;
> +    
>  
>      h->is_streamed = 1;
>      h->max_packet_size = 1472;
> @@ -348,13 +350,32 @@
>              goto fail;
>  
>      /* the bind is needed to give a port to the socket now */
> -    if (bind(udp_fd,(struct sockaddr *)&my_addr, sizeof(my_addr)) < 0)
> -        goto fail;
> +//    if (bind(udp_fd,(struct sockaddr *)&my_addr, sizeof(my_addr)) < 0)
> +//        goto fail;
> +    t=0;
> +    while(1)
> +    {
> +      if (bind(udp_fd,(struct sockaddr *)&my_addr, sizeof(my_addr)) < 0)
> +      {
> +        if (t>100) goto fail;
> +        s->local_port++;
> +        my_addr.sin_port = htons(s->local_port);
> +      }
> +        else
> +      { break; }
>  
> +      t++;
> +    }

No way.

>      len = sizeof(my_addr1);
>      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

Why?  Maybe this really is needed, but in that case a comment would be
nice.

-- 
M?ns Rullg?rd
mans at mansr.com




More information about the ffmpeg-devel mailing list