+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):
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
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
/* 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
{
GstDynUDPSink *udpsink;
+ WSA_STARTUP (sink);
+
udpsink = GST_DYNUDPSINK (sink);
sink->sock = -1;
gst_dynudpsink_finalize (GObject * object)
{
G_OBJECT_CLASS (parent_class)->finalize (object);
+
+ WSA_CLEANUP (object);
}
static GstFlowReturn
static void
gst_dynudpsink_close (GstDynUDPSink * sink)
{
- close (sink->sock);
+ CLOSE_SOCKET (sink->sock);
}
static GstStateChangeReturn
#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())
static void
gst_multiudpsink_init (GstMultiUDPSink * sink)
{
+ WSA_STARTUP (sink);
+
sink->client_lock = g_mutex_new ();
}
g_mutex_free (sink->client_lock);
+ WSA_CLEANUP (object);
+
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gst_multiudpsink_close (GstMultiUDPSink * sink)
{
- close (sink->sock);
+ CLOSE_SOCKET (sink->sock);
}
void
#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())
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;
--- /dev/null
+/* 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
--- /dev/null
+/* 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__*/
+
#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))
#include "gstudpsrc.h"
#include <unistd.h>
-#include <sys/ioctl.h>
+
#include <gst/netbuffer/gstnetbuffer.h>
#ifdef HAVE_FIONREAD_IN_SYS_FILIO
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;
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;
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 {
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 */
} 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);
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)
}
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));
}
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));
}
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));
}
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));
}
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,
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;
close (src->control_sock[1]);
src->control_sock[1] = -1;
}
+
+ WSA_CLEANUP (src);
+
return TRUE;
}
#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 \