mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-01 05:39:51 +00:00
libs/gst/net/: Make stuff compile on windows. Fixes #345295.
Original commit message from CVS: * 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.
This commit is contained in:
parent
6ef1f92e88
commit
b1cb4a633c
7 changed files with 156 additions and 6 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
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):
|
||||
|
|
|
@ -89,6 +89,10 @@ G_STMT_START { \
|
|||
#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,
|
||||
|
@ -110,6 +114,21 @@ static void gst_net_client_clock_get_property (GObject * object, guint prop_id,
|
|||
|
||||
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)
|
||||
{
|
||||
|
@ -143,6 +162,18 @@ gst_net_client_clock_init (GstNetClientClock * self,
|
|||
{
|
||||
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);
|
||||
|
||||
|
@ -180,6 +211,10 @@ gst_net_client_clock_finalize (GObject * object)
|
|||
g_free (self->servaddr);
|
||||
self->servaddr = NULL;
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
WSACleanup ();
|
||||
#endif
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
@ -284,8 +319,17 @@ gst_net_client_clock_do_select (GstNetClientClock * self, fd_set * readfds)
|
|||
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)
|
||||
|
@ -569,12 +613,18 @@ gst_net_client_clock_new (gchar * name, const gchar * remote_address,
|
|||
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;
|
||||
|
|
|
@ -34,10 +34,15 @@ 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>
|
||||
|
||||
#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>
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
|
@ -169,9 +171,12 @@ gint
|
|||
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;
|
||||
|
||||
|
@ -181,13 +186,20 @@ gst_net_time_packet_send (const GstNetTimePacket * packet, gint fd,
|
|||
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);
|
||||
|
|
|
@ -28,10 +28,16 @@ G_BEGIN_DECLS
|
|||
#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:
|
||||
|
|
|
@ -42,8 +42,12 @@
|
|||
#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>
|
||||
|
@ -60,6 +64,10 @@ GST_DEBUG_CATEGORY_STATIC (ntp_debug);
|
|||
#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; \
|
||||
|
@ -76,6 +84,9 @@ G_STMT_START { \
|
|||
|
||||
#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,
|
||||
|
@ -103,6 +114,18 @@ static void gst_net_time_provider_get_property (GObject * object, guint prop_id,
|
|||
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)
|
||||
{
|
||||
|
@ -142,6 +165,18 @@ static void
|
|||
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);
|
||||
|
@ -176,6 +211,10 @@ gst_net_time_provider_finalize (GObject * object)
|
|||
gst_object_unref (self->clock);
|
||||
self->clock = NULL;
|
||||
|
||||
#ifdef G_OS_WIN32
|
||||
WSACleanup ();
|
||||
#endif
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
@ -197,7 +236,16 @@ gst_net_time_provider_thread (gpointer data)
|
|||
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) {
|
||||
|
@ -472,12 +520,18 @@ gst_net_time_provider_new (GstClock * clock, const gchar * address, gint port)
|
|||
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;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/* 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
|
||||
|
@ -21,6 +22,9 @@
|
|||
#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
|
||||
|
@ -28,10 +32,15 @@ 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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue