Port udp plugin to win32 (#345288).

Original commit message from CVS:
Based on patch by: Joni Valtanen  <joni dot valtanen at movial fi>
* configure.ac:
* gst/udp/Makefile.am:
* gst/udp/gstdynudpsink.c: (gst_dynudpsink_init),
(gst_dynudpsink_finalize), (gst_dynudpsink_close):
* gst/udp/gstdynudpsink.h:
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_init),
(gst_multiudpsink_finalize), (gst_multiudpsink_close):
* gst/udp/gstmultiudpsink.h:
* gst/udp/gstudp.c: (plugin_init):
* gst/udp/gstudpsink.h:
* gst/udp/gstudpsrc.c: (gst_udpsrc_init), (gst_udpsrc_create),
(gst_udpsrc_start), (gst_udpsrc_stop):
* gst/udp/gstudpsrc.h:
* gst/udp/gstudpnetutils.c: (gst_udp_net_utils_win32_inet_aton),
(gst_udp_net_utils_win32_wsa_startup):
* gst/udp/gstudpnetutils.h:
Port udp plugin to win32 (#345288).
This commit is contained in:
Joni Valtanen 2006-07-24 11:48:03 +00:00 committed by Tim-Philipp Müller
parent 0c59d11942
commit 162b374ae2
13 changed files with 242 additions and 46 deletions

View file

@ -1,3 +1,25 @@
2006-07-24 Tim-Philipp Müller <tim at centricular dot net>
Based on patch by: Joni Valtanen <joni dot valtanen at movial fi>
* configure.ac:
* gst/udp/Makefile.am:
* gst/udp/gstdynudpsink.c: (gst_dynudpsink_init),
(gst_dynudpsink_finalize), (gst_dynudpsink_close):
* gst/udp/gstdynudpsink.h:
* gst/udp/gstmultiudpsink.c: (gst_multiudpsink_init),
(gst_multiudpsink_finalize), (gst_multiudpsink_close):
* gst/udp/gstmultiudpsink.h:
* gst/udp/gstudp.c: (plugin_init):
* gst/udp/gstudpsink.h:
* gst/udp/gstudpsrc.c: (gst_udpsrc_init), (gst_udpsrc_create),
(gst_udpsrc_start), (gst_udpsrc_stop):
* gst/udp/gstudpsrc.h:
* gst/udp/gstudpnetutils.c: (gst_udp_net_utils_win32_inet_aton),
(gst_udp_net_utils_win32_wsa_startup):
* gst/udp/gstudpnetutils.h:
Port udp plugin to win32 (#345288).
2006-07-24 Wim Taymans <wim@fluendo.com>
* gst/rtsp/rtspconnection.c: (rtsp_connection_send):

View file

@ -125,13 +125,16 @@ dnl disable gst plugins we might not be able to build on this
dnl platform: udp and rtsp (ugly but minimally invasive)
dnl FIXME: maybe move to sys
AC_CHECK_HEADERS([sys/socket.h], HAVE_SYS_SOCKET_H=yes)
AM_CONDITIONAL(HAVE_SYS_SOCKET_H, test "x$HAVE_SYS_SOCKET_H" = "xyes")
AC_CHECK_HEADERS([winsock2.h], HAVE_WINSOCK2_H=yes)
if test "x$HAVE_SYS_SOCKET_H" != "xyes"; then
if test "x$HAVE_SYS_SOCKET_H" != "xyes" -a "x$HAVE_WINSOCK2_H" != "xyes"; then
GST_PLUGINS_SELECTED=`echo $GST_PLUGINS_SELECTED | $SED -e s/udp//`
GST_PLUGINS_SELECTED=`echo $GST_PLUGINS_SELECTED | $SED -e s/rtsp//`
GST_PLUGINS_NO="\tudp\n$GST_PLUGINS_NO"
GST_PLUGINS_NO="\trtsp\n$GST_PLUGINS_NO"
fi
if test "x$HAVE_WINSOCK2_H" = "xyes"; then
WIN32_LIBS="-lws2_32"
AC_SUBST(WIN32_LIBS)
fi
dnl disable monoscope plugin

View file

@ -12,16 +12,16 @@ built_headers = gstudp-enumtypes.h gstudp-marshal.h
BUILT_SOURCES = $(built_sources) $(built_headers)
libgstudp_la_SOURCES = gstudp.c gstudpsrc.c gstudpsink.c gstmultiudpsink.c gstdynudpsink.c
libgstudp_la_SOURCES = gstudp.c gstudpsrc.c gstudpsink.c gstmultiudpsink.c gstdynudpsink.c gstudpnetutils.c
libgstudp_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS)
libgstudp_la_LIBADD = $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS) \
libgstudp_la_LIBADD = $(GST_BASE_LIBS) $(GST_PLUGINS_BASE_LIBS) $(WIN32_LIBS)\
-lgstnetbuffer-@GST_MAJORMINOR@
libgstudp_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
nodist_libgstudp_la_SOURCES = \
$(built_sources)
noinst_HEADERS = gstudpsink.h gstudpsrc.h gstudp.h gstmultiudpsink.h gstdynudpsink.h
noinst_HEADERS = gstudpsink.h gstudpsrc.h gstudp.h gstmultiudpsink.h gstdynudpsink.h gstudpnetutils.h
EXTRA_DIST = README gstudp-marshal.list

View file

@ -1,6 +1,7 @@
/* GStreamer
* Copyright (C) <2005> Philippe Khalaf <burger@speedy.org>
* Copyright (C) <2005> Nokia Corporation <kai.vehmanen@nokia.com>
* Copyright (C) <2006> Joni Valtanen <joni.valtanen@movial.fi>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -157,6 +158,8 @@ gst_dynudpsink_init (GstDynUDPSink * sink)
{
GstDynUDPSink *udpsink;
WSA_STARTUP (sink);
udpsink = GST_DYNUDPSINK (sink);
sink->sock = -1;
@ -166,6 +169,8 @@ static void
gst_dynudpsink_finalize (GObject * object)
{
G_OBJECT_CLASS (parent_class)->finalize (object);
WSA_CLEANUP (object);
}
static GstFlowReturn
@ -307,7 +312,7 @@ gst_dynudpsink_get_stats (GstDynUDPSink * sink, const gchar * host, gint port)
static void
gst_dynudpsink_close (GstDynUDPSink * sink)
{
close (sink->sock);
CLOSE_SOCKET (sink->sock);
}
static GstStateChangeReturn

View file

@ -32,12 +32,9 @@ G_BEGIN_DECLS
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include "gstudpnetutils.h"
#include "gstudp.h"
#define GST_TYPE_DYNUDPSINK (gst_dynudpsink_get_type())

View file

@ -257,6 +257,8 @@ gst_multiudpsink_class_init (GstMultiUDPSinkClass * klass)
static void
gst_multiudpsink_init (GstMultiUDPSink * sink)
{
WSA_STARTUP (sink);
sink->client_lock = g_mutex_new ();
}
@ -269,6 +271,8 @@ gst_multiudpsink_finalize (GObject * object)
g_mutex_free (sink->client_lock);
WSA_CLEANUP (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -440,7 +444,7 @@ no_broadcast:
static void
gst_multiudpsink_close (GstMultiUDPSink * sink)
{
close (sink->sock);
CLOSE_SOCKET (sink->sock);
}
void

View file

@ -30,14 +30,8 @@ G_BEGIN_DECLS
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include "gstudpnetutils.h"
#include "gstudp.h"
#define GST_TYPE_MULTIUDPSINK (gst_multiudpsink_get_type())

View file

@ -29,6 +29,11 @@
static gboolean
plugin_init (GstPlugin * plugin)
{
#ifdef G_OS_WIN32
if (!gst_udp_net_utils_win32_wsa_startup (GST_OBJECT (plugin)))
return FALSE;
#endif
if (!gst_element_register (plugin, "udpsink", GST_RANK_NONE,
GST_TYPE_UDPSINK))
return FALSE;

62
gst/udp/gstudpnetutils.c Normal file
View file

@ -0,0 +1,62 @@
/* GStreamer UDP network utility functions
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
* Copyright (C) 2006 Joni Valtanen <joni.valtanen@movial.fi>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstudpnetutils.h"
#ifdef G_OS_WIN32
int
gst_udp_net_utils_win32_inet_aton (const char *c, struct in_addr *paddr)
{
paddr->s_addr = inet_addr (c);
if (paddr->s_addr == INADDR_NONE)
return 0;
return 1;
}
gboolean
gst_udp_net_utils_win32_wsa_startup (GstObject * obj)
{
WSADATA w;
int error;
error = WSAStartup (0x0202, &w);
if (error) {
GST_WARNING_OBJECT (obj, "WSAStartup error: %d", error);
return FALSE;
}
if (w.wVersion != 0x0202) {
WSACleanup ();
GST_WARNING_OBJECT (obj, "Winsock version wrong : 0x%x", w.wVersion);
return FALSE;
}
return TRUE;
}
#endif

77
gst/udp/gstudpnetutils.h Normal file
View file

@ -0,0 +1,77 @@
/* GStreamer UDP network utility functions
* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
* Copyright (C) 2006 Joni Valtanen <joni.valtanen@movial.fi>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_UDP_NET_UTILS_H__
#define __GST_UDP_NET_UTILS_H__
#include <sys/time.h>
#include <sys/types.h>
/* Needed for G_OS_XXXX */
#include <glib.h>
#ifdef G_OS_WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
/* Needed for GstObject and GST_WARNING_OBJECT */
#include <gst/gstobject.h>
#include <gst/gstinfo.h>
#else
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/ioctl.h>
#endif
#include <fcntl.h>
#ifdef G_OS_WIN32
#define IOCTL_SOCKET ioctlsocket
#define CLOSE_SOCKET(sock) closesocket(sock)
#define setsockopt(sock,l,opt,val,len) setsockopt(sock,l,opt,(char *)(val),len)
#define inet_aton(c,addr) gst_udp_net_utils_win32_inet_aton ((c),(addr))
#define WSA_STARTUP(obj) gst_udp_net_utils_win32_wsa_startup(GST_OBJECT(obj))
#define WSA_CLEANUP(obj) WSACleanup ()
#else
#define IOCTL_SOCKET ioctl
#define CLOSE_SOCKET(sock) close(sock)
#define setsockopt(sock,l,opt,val,len) setsockopt(sock,l,opt,(void *)(val),len)
#define WSA_STARTUP(obj)
#define WSA_CLEANUP(obj)
#endif
#ifdef G_OS_WIN32
int gst_udp_net_utils_win32_inet_aton (const char *c, struct in_addr * addr);
gboolean gst_udp_net_utils_win32_wsa_startup (GstObject * obj);
#endif
#endif /* __GST_UDP_NET_UTILS_H__*/

View file

@ -31,15 +31,9 @@ G_BEGIN_DECLS
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netdb.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <arpa/inet.h>
#include "gstudp.h"
#include "gstudpnetutils.h"
#define GST_TYPE_UDPSINK (gst_udpsink_get_type())
#define GST_UDPSINK(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_UDPSINK,GstUDPSink))

View file

@ -79,7 +79,7 @@
#include "gstudpsrc.h"
#include <unistd.h>
#include <sys/ioctl.h>
#include <gst/netbuffer/gstnetbuffer.h>
#ifdef HAVE_FIONREAD_IN_SYS_FILIO
@ -222,6 +222,8 @@ gst_udpsrc_class_init (GstUDPSrcClass * klass)
static void
gst_udpsrc_init (GstUDPSrc * udpsrc, GstUDPSrcClass * g_class)
{
WSA_STARTUP (udpsrc);
gst_base_src_set_live (GST_BASE_SRC (udpsrc), TRUE);
udpsrc->port = UDP_DEFAULT_PORT;
udpsrc->sock = UDP_DEFAULT_SOCKFD;
@ -253,7 +255,13 @@ gst_udpsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
guint max_sock;
gchar *pktdata;
gint pktsize;
#ifdef G_OS_UNIX
gint readsize;
#endif
#ifdef G_OS_WIN32
gulong readsize;
#endif
gint ret;
gboolean try_again;
@ -261,7 +269,9 @@ gst_udpsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
FD_ZERO (&read_fds);
FD_SET (udpsrc->sock, &read_fds);
#ifdef G_OS_UNIX
FD_SET (READ_SOCKET (udpsrc), &read_fds);
#endif
max_sock = MAX (udpsrc->sock, READ_SOCKET (udpsrc));
do {
@ -271,13 +281,26 @@ gst_udpsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
stop = FALSE;
GST_LOG_OBJECT (udpsrc, "doing select");
#ifdef G_OS_WIN32
if (((max_sock + 1) != READ_SOCKET (udpsrc)) ||
((max_sock + 1) != WRITE_SOCKET (udpsrc))) {
ret = select (max_sock + 1, &read_fds, NULL, NULL, NULL);
} else {
ret = 1;
}
#else
ret = select (max_sock + 1, &read_fds, NULL, NULL, NULL);
#endif
GST_LOG_OBJECT (udpsrc, "select returned %d", ret);
if (ret <= 0) {
#ifdef G_OS_WIN32
if (WSAGetLastError () != WSAEINTR)
goto select_error;
#else
if (errno != EAGAIN && errno != EINTR)
goto select_error;
else
try_again = TRUE;
#endif
try_again = TRUE;
} else {
if (FD_ISSET (READ_SOCKET (udpsrc), &read_fds)) {
/* got control message */
@ -312,7 +335,7 @@ gst_udpsrc_create (GstPushSrc * psrc, GstBuffer ** buf)
} while (try_again);
/* ask how much is available for reading on the socket */
if ((ret = ioctl (udpsrc->sock, FIONREAD, &readsize)) < 0)
if ((ret = IOCTL_SOCKET (udpsrc->sock, FIONREAD, &readsize)) < 0)
goto ioctl_failed;
GST_LOG_OBJECT (udpsrc, "ioctl says %d bytes available", readsize);
@ -515,12 +538,21 @@ gst_udpsrc_start (GstBaseSrc * bsrc)
src = GST_UDPSRC (bsrc);
#ifdef G_OS_WIN32
GST_DEBUG_OBJECT (src, "creating pipe");
/* This should work on UNIX too. PF_UNIX sockets replaced with pipe */
/* pipe( CONTROL_SOCKETS(src) ) */
if ((ret = pipe (CONTROL_SOCKETS (src))) < 0)
goto no_socket_pair;
#else
GST_DEBUG_OBJECT (src, "creating socket pair");
if ((ret = socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (src))) < 0)
goto no_socket_pair;
fcntl (READ_SOCKET (src), F_SETFL, O_NONBLOCK);
fcntl (WRITE_SOCKET (src), F_SETFL, O_NONBLOCK);
#endif
if (src->sock == -1) {
if ((ret = socket (AF_INET, SOCK_DGRAM, 0)) < 0)
@ -593,7 +625,7 @@ no_socket:
}
setsockopt_error:
{
close (src->sock);
CLOSE_SOCKET (src->sock);
src->sock = -1;
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
("setsockopt failed %d: %s (%d)", ret, g_strerror (errno), errno));
@ -601,7 +633,7 @@ setsockopt_error:
}
bind_error:
{
close (src->sock);
CLOSE_SOCKET (src->sock);
src->sock = -1;
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
("bind failed %d: %s (%d)", ret, g_strerror (errno), errno));
@ -609,7 +641,7 @@ bind_error:
}
membership:
{
close (src->sock);
CLOSE_SOCKET (src->sock);
src->sock = -1;
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
("could add membership %d: %s (%d)", ret, g_strerror (errno), errno));
@ -617,7 +649,7 @@ membership:
}
getsockname_error:
{
close (src->sock);
CLOSE_SOCKET (src->sock);
src->sock = -1;
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
("getsockname failed %d: %s (%d)", ret, g_strerror (errno), errno));
@ -625,7 +657,7 @@ getsockname_error:
}
no_broadcast:
{
close (src->sock);
CLOSE_SOCKET (src->sock);
src->sock = -1;
GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL),
("could not configure socket for broadcast %d: %s (%d)", ret,
@ -655,10 +687,11 @@ gst_udpsrc_stop (GstBaseSrc * bsrc)
src = GST_UDPSRC (bsrc);
if (src->sock != -1) {
close (src->sock);
CLOSE_SOCKET (src->sock);
src->sock = -1;
}
/* pipes on WIN32 else sockets */
if (src->control_sock[0] != -1) {
close (src->control_sock[0]);
src->control_sock[0] = -1;
@ -667,6 +700,9 @@ gst_udpsrc_stop (GstBaseSrc * bsrc)
close (src->control_sock[1]);
src->control_sock[1] = -1;
}
WSA_CLEANUP (src);
return TRUE;
}

View file

@ -29,12 +29,9 @@ G_BEGIN_DECLS
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include "gstudpnetutils.h"
#include "gstudp.h"
#define GST_TYPE_UDPSRC \