+2006-09-05 Wim Taymans <wim@fluendo.com>
+
+ * libs/gst/net/gstnetclientclock.c: (inet_aton),
+ (gst_net_client_clock_init), (gst_net_client_clock_finalize),
+ (gst_net_client_clock_do_select), (gst_net_client_clock_new):
+ * libs/gst/net/gstnetclientclock.h:
+ * libs/gst/net/gstnettimepacket.c: (gst_net_time_packet_send):
+ * libs/gst/net/gstnettimepacket.h:
+ * libs/gst/net/gstnettimeprovider.c: (inet_aton),
+ (gst_net_time_provider_init), (gst_net_time_provider_finalize),
+ (gst_net_time_provider_thread), (gst_net_time_provider_new):
+ * libs/gst/net/gstnettimeprovider.h:
+ Make stuff compile on windows. Fixes #345295.
+
2006-09-03 Tim-Philipp Müller <tim at centricular dot net>
* gst/gst.c: (ensure_current_registry_forking):
#define DEFAULT_PORT 5637
#define DEFAULT_TIMEOUT GST_SECOND
+#ifdef G_OS_WIN32
+#define getsockname(sock,addr,len) getsockname(sock,addr,(int *)len)
+#endif
+
enum
{
PROP_0,
static void gst_net_client_clock_stop (GstNetClientClock * self);
+#ifdef G_OS_WIN32
+static int
+inet_aton (const char *c, struct in_addr *paddr)
+{
+ /* note that inet_addr is deprecated on unix because
+ * inet_addr returns -1 (INADDR_NONE) for the valid 255.255.255.255
+ * address. */
+ paddr->s_addr = inet_addr (c);
+ if (paddr->s_addr == INADDR_NONE)
+ return 0;
+
+ return 1;
+}
+#endif
+
static void
gst_net_client_clock_base_init (gpointer g_class)
{
{
GstClock *clock = GST_CLOCK_CAST (self);
+#ifdef G_OS_WIN32
+ WSADATA w;
+ int error = WSAStartup (0x0202, &w);
+
+ if (error) {
+ GST_DEBUG_OBJECT (self, "Error on WSAStartup");
+ }
+ if (w.wVersion != 0x0202) {
+ WSACleanup ();
+ }
+#endif
+
self->port = DEFAULT_PORT;
self->address = g_strdup (DEFAULT_ADDRESS);
g_free (self->servaddr);
self->servaddr = NULL;
+#ifdef G_OS_WIN32
+ WSACleanup ();
+#endif
+
G_OBJECT_CLASS (parent_class)->finalize (object);
}
diff = gst_clock_get_internal_time (GST_CLOCK (self));
GST_TIME_TO_TIMEVAL (self->current_timeout, tv);
+#ifdef G_OS_WIN32
+ if (((max_sock + 1) != READ_SOCKET (self)) ||
+ ((max_sock + 1) != WRITE_SOCKET (self))) {
+ ret =
+ select (max_sock + 1, readfds, NULL, NULL, (struct timeval *) ptv);
+ } else {
+ ret = 1;
+ }
+#else
ret = select (max_sock + 1, readfds, NULL, NULL, (struct timeval *) ptv);
-
+#endif
diff = gst_clock_get_internal_time (GST_CLOCK (self)) - diff;
if (diff > self->current_timeout)
g_warning ("unable to set the base time, expect sync problems!");
}
+#ifdef G_OS_WIN32
+ GST_DEBUG_OBJECT (ret, "creating pipe");
+ if ((iret = pipe (CONTROL_SOCKETS (ret))) < 0)
+ goto no_socket_pair;
+#else
GST_DEBUG_OBJECT (ret, "creating socket pair");
if ((iret = socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (ret))) < 0)
goto no_socket_pair;
fcntl (READ_SOCKET (ret), F_SETFL, O_NONBLOCK);
fcntl (WRITE_SOCKET (ret), F_SETFL, O_NONBLOCK);
+#endif
if (!gst_net_client_clock_start (ret))
goto failed_start;
#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>
+
+#ifdef G_OS_WIN32
+# include <winsock2.h>
+#else
+# include <netdb.h>
+# include <sys/socket.h>
+# include <netinet/in.h>
+# include <arpa/inet.h>
+#endif /*G_OS_WIN32 */
#include <fcntl.h>
#include "config.h"
#endif
+#include <glib.h>
+
#ifdef __CYGWIN__
# include <unistd.h>
# include <fcntl.h>
gst_net_time_packet_send (const GstNetTimePacket * packet, gint fd,
struct sockaddr * addr, socklen_t len)
{
-#ifdef __CYGWIN__
+#if defined __CYGWIN__
gint fdflags;
+#elif defined G_OS_WIN32
+ gulong flags;
#endif
+
guint8 *buffer;
gint ret, send_flags;
send_flags = 0;
fdflags = fcntl (fd, F_GETFL);
fcntl (fd, F_SETFL, fdflags | O_NONBLOCK);
+#elif defined G_OS_WIN32
+ flags = 1;
#else
send_flags = MSG_DONTWAIT;
#endif
buffer = gst_net_time_packet_serialize (packet);
+#ifdef G_OS_WIN32
+ ioctlsocket (fd, FIONBIO, &flags); /* Set nonblocking mode */
+ ret = sendto (fd, buffer, GST_NET_TIME_PACKET_SIZE, NULL, addr, len);
+#else
ret = sendto (fd, buffer, GST_NET_TIME_PACKET_SIZE, send_flags, addr, len);
+#endif
#ifdef __CYGWIN__
fcntl (fd, F_SETFL, fdflags);
#include <errno.h>
#include <string.h>
#include <sys/types.h>
+
+#ifdef G_OS_WIN32
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#else
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#endif
/**
* GST_NET_TIME_PACKET_SIZE:
#include "gstnettimeprovider.h"
#include "gstnettimepacket.h"
+#include <glib.h>
+
#include <unistd.h>
+#ifndef G_OS_WIN32
#include <sys/ioctl.h>
+#endif
#ifdef HAVE_FIONREAD_IN_SYS_FILIO
#include <sys/filio.h>
#define WRITE_SOCKET(self) self->control_sock[1]
#define READ_SOCKET(self) self->control_sock[0]
+#ifdef G_OS_WIN32
+#define close(sock) closesocket(sock)
+#endif
+
#define SEND_COMMAND(self, command) \
G_STMT_START { \
unsigned char c; c = command; \
#define IS_ACTIVE(self) (g_atomic_int_get (&((self)->active.active)))
+#ifdef G_OS_WIN32
+#define setsockopt(sock, sol_flags, reuse_flags, ru, sizeofru) setsockopt (sock, sol_flags, reuse_flags, (char *)ru, sizeofru)
+#endif
enum
{
PROP_0,
GST_BOILERPLATE_FULL (GstNetTimeProvider, gst_net_time_provider, GstObject,
GST_TYPE_OBJECT, _do_init);
+#ifdef G_OS_WIN32
+static int
+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;
+}
+#endif
+
static void
gst_net_time_provider_base_init (gpointer g_class)
{
gst_net_time_provider_init (GstNetTimeProvider * self,
GstNetTimeProviderClass * g_class)
{
+#ifdef G_OS_WIN32
+ WSADATA w;
+ int error = WSAStartup (0x0202, &w);
+
+ if (error) {
+ GST_DEBUG_OBJECT (self, "Error on WSAStartup");
+ }
+ if (w.wVersion != 0x0202) {
+ WSACleanup ();
+ }
+#endif
+
self->port = DEFAULT_PORT;
self->sock = -1;
self->address = g_strdup (DEFAULT_ADDRESS);
gst_object_unref (self->clock);
self->clock = NULL;
+#ifdef G_OS_WIN32
+ WSACleanup ();
+#endif
+
G_OBJECT_CLASS (parent_class)->finalize (object);
}
max_sock = MAX (self->sock, READ_SOCKET (self));
GST_LOG_OBJECT (self, "doing select");
+#ifdef G_OS_WIN32
+ if (((max_sock + 1) != READ_SOCKET (self)) ||
+ ((max_sock + 1) != WRITE_SOCKET (self))) {
+ 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 (self, "select returned %d", ret);
if (ret <= 0) {
ret = g_object_new (GST_TYPE_NET_TIME_PROVIDER, "clock", clock, "address",
address, "port", port, NULL);
+#ifdef G_OS_WIN32
+ GST_DEBUG_OBJECT (ret, "creating pipe");
+ if ((iret = pipe (CONTROL_SOCKETS (ret))) < 0)
+ goto no_socket_pair;
+#else
GST_DEBUG_OBJECT (ret, "creating socket pair");
if ((iret = socketpair (PF_UNIX, SOCK_STREAM, 0, CONTROL_SOCKETS (ret))) < 0)
goto no_socket_pair;
fcntl (READ_SOCKET (ret), F_SETFL, O_NONBLOCK);
fcntl (WRITE_SOCKET (ret), F_SETFL, O_NONBLOCK);
+#endif
if (!gst_net_time_provider_start (ret))
goto failed_start;
/* GStreamer
* Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
+ * 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
#ifndef __GST_NET_TIME_PROVIDER_H__
#define __GST_NET_TIME_PROVIDER_H__
+/* to determinate os */
+#include <glib.h>
+
#include <gst/gst.h>
G_BEGIN_DECLS
#include <errno.h>
#include <string.h>
#include <sys/types.h>
+
+#ifdef G_OS_WIN32
+#include <winsock2.h>
+#else
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#endif
#include <fcntl.h>