diff --git a/transmitters/shm/mkdtemp.h b/transmitters/shm/mkdtemp.h new file mode 100644 index 0000000..90b6336 --- /dev/null +++ b/transmitters/shm/mkdtemp.h @@ -0,0 +1,218 @@ +/* Copyright (C) 1999, 2001-2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C 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. + + The GNU C 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 the GNU C Library; see the file COPYING.LIB. If not, + a copy is available at Foundation, Inc., 51 Franklin Street, + Fifth Floor, Boston, MA 02110-1301 USA. */ + +/* Extracted from misc/mkdtemp.c and sysdeps/posix/tempname.c, + with R modifications for randomness and WIN32. + + mkdtemp was required by POSIX 2008: we use this substitute on + Windows. +*/ + +/* Extracted from R for farstream. See: + http://fossies.org/dox/R-2.15.3/mkdtemp_8c.html (for mkdtemp()) + http://fossies.org/dox/R-2.15.3/datetime_8c_source.html (for TimeToSeed()) +*/ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#ifndef __set_errno +# define __set_errno(Val) errno = (Val) +#endif + +#include +#include +#include + +#include +#ifndef TMP_MAX +# define TMP_MAX 238328 +#endif + +/* This is a little strange: inttypes.h is supposed according to + POSIX to include stdint.h */ +#ifdef HAVE_STDINT_H +# include +#endif +#ifdef HAVE_INTTYPES_H +# include +#endif + +#ifdef HAVE_UNISTD_H +# include +#endif + + +#ifndef WIN32 +#include +#ifdef STAT_MACROS_BROKEN +# undef S_ISDIR +#endif +#if !defined S_ISDIR && defined S_IFDIR +# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) +#endif +#if !S_IRUSR && S_IREAD +# define S_IRUSR S_IREAD +#endif +#if !S_IRUSR +# define S_IRUSR 00400 +#endif +#if !S_IWUSR && S_IWRITE +# define S_IWUSR S_IWRITE +#endif +#if !S_IWUSR +# define S_IWUSR 00200 +#endif +#if !S_IXUSR && S_IEXEC +# define S_IXUSR S_IEXEC +#endif +#if !S_IXUSR +# define S_IXUSR 00100 +#endif +#endif + +/* Use the widest available unsigned type if uint64_t is not + available. The algorithm below extracts a number less than 62**6 + (approximately 2**35.725) from uint64_t, so ancient hosts where + uintmax_t is only 32 bits lose about 3.725 bits of randomness, + which is better than not having mkstemp at all. */ +#if !defined UINT64_MAX && !defined uint64_t +# define uint64_t uintmax_t +#endif + +/* These are the characters used in temporary filenames. */ +static const char letters[] = +"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + +/* needed on Windows to avoid redefinition of tzname as _tzname */ +#define _NO_OLDNAMES +#include +#undef _NO_OLDNAMES + +unsigned int TimeToSeed(void) +{ + unsigned int seed, pid = getpid(); +#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_REALTIME) + { + struct timespec tp; + clock_gettime(CLOCK_REALTIME, &tp); + seed = ((uint_least64_t) tp.tv_nsec << 16) ^ tp.tv_sec; + } +#elif defined(HAVE_GETTIMEOFDAY) + { + struct timeval tv; + gettimeofday (&tv, NULL); + seed = ((uint_least64_t) tv.tv_usec << 16) ^ tv.tv_sec; + } +#else + /* C89, so must work */ + seed = (unsigned int) time(NULL); +#endif + seed ^= (pid <<16); + return seed; +} + + +/* Generate a temporary file name based on TMPL. TMPL must match the + rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed + does not exist at the time of the call to __gen_tempname. TMPL is + overwritten with the result. + + KIND is: + __GT_DIR: create a directory, which will be mode 0700. + + We use a clever algorithm to get hard-to-predict names. */ +static int +gen_tempname (char *tmpl) +{ + int len; + char *XXXXXX; + static uint64_t value; + uint64_t random_time_bits; + int count, fd = -1; + int save_errno = errno; + + len = (int) strlen(tmpl); + if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX")) + { + __set_errno (EINVAL); + return -1; + } + + /* This is where the Xs start. */ + XXXXXX = &tmpl[len - 6]; + + /* Get some more or less random data. We need 36 bits. */ + random_time_bits = TimeToSeed(); + value += (random_time_bits << 8) ^ getpid (); + + for (count = 0; count < TMP_MAX; value += 7777, ++count) + { + uint64_t v = value; + + /* Fill in the random bits. */ + XXXXXX[0] = letters[v % 62]; + v /= 62; + XXXXXX[1] = letters[v % 62]; + v /= 62; + XXXXXX[2] = letters[v % 62]; + v /= 62; + XXXXXX[3] = letters[v % 62]; + v /= 62; + XXXXXX[4] = letters[v % 62]; + v /= 62; + XXXXXX[5] = letters[v % 62]; + +#ifdef WIN32 + fd = mkdir (tmpl); +#else + fd = mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR); +#endif + + if (fd >= 0) + { + __set_errno (save_errno); + return fd; + } + else if (errno != EEXIST) + return -1; + } + + /* We got out of the loop because we ran out of combinations to try. */ + __set_errno (EEXIST); + return -1; +} + +/* Generate a unique temporary directory from TEMPLATE. + The last six characters of TEMPLATE must be "XXXXXX"; + they are replaced with a string that makes the filename unique. + The directory is created, mode 700, and its name is returned. + (This function comes from OpenBSD.) */ +char * +mkdtemp (char *Template) +#ifdef __cplusplus + throw() +#endif +{ + if (gen_tempname (Template)) + return NULL; + else + return Template; +} diff --git a/farstream/Makefile.am b/farstream/Makefile.am index fe4c90b..6e5cf9a 100644 --- a/farstream/Makefile.am +++ b/farstream/Makefile.am @@ -47,7 +47,7 @@ nodist_libfarstream_@FS_APIVERSION@_la_SOURCES = \ libfarstream_@FS_APIVERSION@_la_CFLAGS = \ $(FS_INTERNAL_CFLAGS) $(FS_CFLAGS) \ - $(GLIB_FLAGS) \ + $(GLIB_CFLAGS) \ $(GST_PLUGINS_BASE_CFLAGS) \ $(GST_BASE_CFLAGS) \ $(GST_CFLAGS) diff --git a/gst/fsmsnconference/fs-msn-connection.c b/gst/fsmsnconference/fs-msn-connection.c index 17093d5..d719632 100644 --- a/gst/fsmsnconference/fs-msn-connection.c +++ b/gst/fsmsnconference/fs-msn-connection.c @@ -30,12 +30,26 @@ #include "fs-msn-connection.h" -#include +#ifdef G_OS_WIN32 +# include +# include +// For some reason these aren't always defined on Windows +# ifndef EADDRINUSE +# define EADDRINUSE WSAEADDRINUSE /*100*/ +# endif +# ifndef EINPROGRESS +# define EINPROGRESS WSAEINPROGRESS /*112*/ +# endif +# define strerror_r(errno, error_str, error_string_length) strncpy( error_str, strerror( errno ), error_string_length ) +#else /*G_OS_WIN32*/ +# include +# include +# include +#endif /*G_OS_WIN32*/ + #include #include -#include #include -#include #include #include #ifdef HAVE_STDLIB_H @@ -464,7 +478,7 @@ fs_msn_open_listening_port_unlock (FsMsnConnection *self, guint16 port, { gint fd = -1; struct sockaddr_in myaddr; - guint myaddr_len = sizeof (struct sockaddr_in); + socklen_t myaddr_len = sizeof (struct sockaddr_in); FsCandidate * candidate = NULL; GList *addresses = nice_interfaces_get_local_ips (FALSE); GList *item = NULL; @@ -485,7 +499,14 @@ fs_msn_open_listening_port_unlock (FsMsnConnection *self, guint16 port, } // set non-blocking mode +#ifdef G_OS_WIN32 + { + u_long iMode = 1; // Non-blocking mode flag + ioctlsocket(fd, FIONBIO, &iMode); + } +#else fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); +#endif for (;;) { GST_DEBUG ("Attempting to listen on port %d.....",port); memset(&myaddr, 0, sizeof(myaddr)); @@ -601,8 +622,14 @@ fs_msn_connection_attempt_connection_locked (FsMsnConnection *connection, } // set non-blocking mode +#ifdef G_OS_WIN32 + { + u_long iMode = 1; // Non-blocking mode flag + ioctlsocket(fd, FIONBIO, &iMode); + } +#else fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); - +#endif theiraddr.sin_family = AF_INET; theiraddr.sin_addr.s_addr = inet_addr (candidate->ip); theiraddr.sin_port = htons (candidate->port); diff --git a/gst/fsmsnconference/fs-msn-stream.c b/gst/fsmsnconference/fs-msn-stream.c index 7ac0a85..5a698ed 100644 --- a/gst/fsmsnconference/fs-msn-stream.c +++ b/gst/fsmsnconference/fs-msn-stream.c @@ -49,10 +49,17 @@ #include "fs-msn-stream.h" -#include + +#ifdef G_OS_WIN32 +# include +# include +#else /*G_OS_WIN32*/ +# include +# include +# include +#endif /*G_OS_WIN32*/ + #include -#include -#include #include #include @@ -828,12 +835,12 @@ fs_msn_stream_set_tos_locked (FsMsnStream *self, gint tos) if (self->priv->fd < 0) return; - if (setsockopt (self->priv->fd, IPPROTO_IP, IP_TOS, &tos, sizeof (tos)) < 0) + if (setsockopt (self->priv->fd, IPPROTO_IP, IP_TOS, (const void *)&tos, sizeof (tos)) < 0) GST_WARNING ( "could not set socket ToS: %s", g_strerror (errno)); #ifdef IPV6_TCLASS if (setsockopt (self->priv->fd, IPPROTO_IPV6, IPV6_TCLASS, - &tos, sizeof (tos)) < 0) + (const void *)&tos, sizeof (tos)) < 0) GST_WARNING ("could not set TCLASS: %s", g_strerror (errno)); #endif } diff --git a/gst/fsrawconference/fs-raw-stream.c b/gst/fsrawconference/fs-raw-stream.c index e361bc7..f7e3178 100644 --- a/gst/fsrawconference/fs-raw-stream.c +++ b/gst/fsrawconference/fs-raw-stream.c @@ -48,10 +48,16 @@ #include "fs-raw-stream.h" #include "fs-raw-session.h" -#include +#ifdef G_OS_WIN32 +# include +# include +#else /*G_OS_WIN32*/ +# include +# include +# include +#endif /*G_OS_WIN32*/ + #include -#include -#include #include #include diff --git a/gst/fsrtpconference/fs-rtp-codec-specific.c b/gst/fsrtpconference/fs-rtp-codec-specific.c index f29179d..00a9feb 100644 --- a/gst/fsrtpconference/fs-rtp-codec-specific.c +++ b/gst/fsrtpconference/fs-rtp-codec-specific.c @@ -1484,7 +1484,11 @@ param_h264_profile_level_id (const struct SdpParam *sdp_param, local_level_idc = 0xFF & local_value; nego_level_idc = MIN (remote_level_idc, local_level_idc); - g_snprintf (buf, 7, "%02hhX%02hhX%02hhX", local_profile_idc, nego_profile_iop, + /* Changed from "%02hhX%02hhX%02hhX" to remove h's. + According to http://www.cplusplus.com/reference/cstdio/printf/, "hh" with "X" indicates + the passed arguments are of type unsigned char, but in fact they are all guint. + gcc 4.7.2 compiler on MinGW platform failed with "hhx" format strings. */ + g_snprintf (buf, 7, "%02X%02X%02X", local_profile_idc, nego_profile_iop, nego_level_idc); fs_codec_add_optional_parameter (negotiated_codec, sdp_param->name, buf); diff --git a/gst/fsrtpconference/fs-rtp-tfrc.c b/gst/fsrtpconference/fs-rtp-tfrc.c index 8c6c2f1..d6cf54a 100644 --- a/gst/fsrtpconference/fs-rtp-tfrc.c +++ b/gst/fsrtpconference/fs-rtp-tfrc.c @@ -29,6 +29,7 @@ #include "fs-rtp-tfrc.h" #include +#include // for PRIu64 instead of "%llu" or "%u" #include "fs-rtp-packet-modder.h" #include "farstream/fs-rtp.h" @@ -914,7 +915,7 @@ incoming_rtcp_probe (GstPad *pad, GstPadProbeInfo *info, gpointer user_data) x_recv = GST_READ_UINT32_BE (buf); buf += 4; loss_event_rate = (gdouble) GST_READ_UINT32_BE (buf) / (gdouble) G_MAXUINT; - GST_LOG_OBJECT (self, "Got RTCP TFRC packet last_sent_ts: %u" + GST_LOG_OBJECT (self, "Got RTCP TFRC packet last_sent_ts: %"PRIu64 " delay: %u x_recv: %u loss_event_rate: %f", ts, delay, x_recv, loss_event_rate); @@ -968,7 +969,7 @@ incoming_rtcp_probe (GstPad *pad, GstPadProbeInfo *info, gpointer user_data) if (rtt > 10 * 1000 * 1000) { - GST_WARNING_OBJECT (self, "Impossible RTT %u ms, ignoring", rtt); + GST_WARNING_OBJECT (self, "Impossible RTT %"PRIu64" ms, ignoring", rtt); goto done; } diff --git a/tests/rtp/Makefile.am b/tests/rtp/Makefile.am index cb603b9..1740faf 100644 --- a/tests/rtp/Makefile.am +++ b/tests/rtp/Makefile.am @@ -12,8 +12,8 @@ codec_discovery_CFLAGS = \ $(CFLAGS) LDADD = \ - $(top_builddir)/farstream/libfarstream-@FS_APIVERSION@.la \ $(top_builddir)/gst/fsrtpconference/libfsrtpconference-convenience.la \ + $(top_builddir)/farstream/libfarstream-@FS_APIVERSION@.la \ $(GST_CHECK_LIBS) \ $(GST_PLUGINS_BASE_LIBS) \ $(GST_LIBS) \ diff --git a/transmitters/multicast/fs-multicast-transmitter.c b/transmitters/multicast/fs-multicast-transmitter.c index d105798..d2ec9c2 100644 --- a/transmitters/multicast/fs-multicast-transmitter.c +++ b/transmitters/multicast/fs-multicast-transmitter.c @@ -30,6 +30,15 @@ * */ +/* Using getaddrinfo/freeaddrinfo requires a minimum Windows version of XP. + http://msdn.microsoft.com/en-us/library/6sehtctf.aspx says to set + _WIN32_WINNT to minimum version and this appears to work with MinGW as well. + This must appear before any windows.h or system #includes. + See ws2tcpip.h for condition definitions of getaddrinfo/freeaddrinfo. */ +#if defined( WIN32 ) && ( !defined( _WIN32_WINNT ) || _WIN32_WINNT < 0x0501 ) +# define _WIN32_WINNT 0x0501 +#endif + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -678,12 +687,12 @@ _bind_port ( } if (setsockopt (sock, IPPROTO_IP, IP_TOS, - &type_of_service, sizeof (type_of_service)) < 0) + (const void*)&type_of_service, sizeof (type_of_service)) < 0) GST_WARNING ("could not set socket ToS: %s", g_strerror (errno)); #ifdef IPV6_TCLASS if (setsockopt (sock, IPPROTO_IPV6, IPV6_TCLASS, - &type_of_service, sizeof (type_of_service)) < 0) + (const void*)&type_of_service, sizeof (type_of_service)) < 0) GST_WARNING ("could not set TCLASS: %s", g_strerror (errno)); #endif @@ -1214,12 +1223,12 @@ fs_multicast_transmitter_set_type_of_service (FsMulticastTransmitter *self, UdpSock *udpsock = item->data; if (setsockopt (udpsock->fd, IPPROTO_IP, IP_TOS, - &tos, sizeof (tos)) < 0) + (const void*)&tos, sizeof (tos)) < 0) GST_WARNING ( "could not set socket tos: %s", g_strerror (errno)); #ifdef IPV6_TCLASS if (setsockopt (udpsock->fd, IPPROTO_IPV6, IPV6_TCLASS, - &tos, sizeof (tos)) < 0) + (const void*)&tos, sizeof (tos)) < 0) GST_WARNING ("could not set TCLASS: %s", g_strerror (errno)); #endif } diff --git a/transmitters/nice/fs-nice-transmitter.c b/transmitters/nice/fs-nice-transmitter.c index 4cca547..3fb85df 100644 --- a/transmitters/nice/fs-nice-transmitter.c +++ b/transmitters/nice/fs-nice-transmitter.c @@ -42,7 +42,7 @@ #include #include -#include +#include #include #include diff --git a/transmitters/nice/fs-nice-transmitter.h b/transmitters/nice/fs-nice-transmitter.h index a203ce3..c39e77e 100644 --- a/transmitters/nice/fs-nice-transmitter.h +++ b/transmitters/nice/fs-nice-transmitter.h @@ -28,7 +28,7 @@ #include #include -#include +#include G_BEGIN_DECLS diff --git a/transmitters/rawudp/fs-rawudp-component.c b/transmitters/rawudp/fs-rawudp-component.c index 64ce8fb..bad9d41 100644 --- a/transmitters/rawudp/fs-rawudp-component.c +++ b/transmitters/rawudp/fs-rawudp-component.c @@ -22,6 +22,14 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/* Using getaddrinfo/freeaddrinfo requires a minimum Windows version of XP. + http://msdn.microsoft.com/en-us/library/6sehtctf.aspx says to set + _WIN32_WINNT to minimum version and this appears to work with MinGW as well. + This must appear before any windows.h or system #includes. + See ws2tcpip.h for condition definitions of getaddrinfo/freeaddrinfo. */ +#if defined( WIN32 ) && ( !defined( _WIN32_WINNT ) || _WIN32_WINNT < 0x0501 ) +# define _WIN32_WINNT 0x0501 +#endif #ifdef HAVE_CONFIG_H #include "config.h" @@ -52,6 +60,7 @@ #ifdef G_OS_WIN32 # include +# include #else /*G_OS_WIN32*/ # include # include diff --git a/transmitters/rawudp/fs-rawudp-transmitter.c b/transmitters/rawudp/fs-rawudp-transmitter.c index 27853a8..c825191 100644 --- a/transmitters/rawudp/fs-rawudp-transmitter.c +++ b/transmitters/rawudp/fs-rawudp-transmitter.c @@ -30,6 +30,15 @@ * */ +/* Using getaddrinfo/freeaddrinfo requires a minimum Windows version of XP. + http://msdn.microsoft.com/en-us/library/6sehtctf.aspx says to set + _WIN32_WINNT to minimum version and this appears to work with MinGW as well. + This must appear before any windows.h or system #includes. + See ws2tcpip.h for condition definitions of getaddrinfo/freeaddrinfo. */ +#if defined( WIN32 ) && ( !defined( _WIN32_WINNT ) || _WIN32_WINNT < 0x0501 ) +# define _WIN32_WINNT 0x0501 +#endif + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -48,7 +57,7 @@ #endif #ifdef G_OS_WIN32 -# include +# include # define close closesocket #else /*G_OS_WIN32*/ # include @@ -629,11 +638,11 @@ _bind_port ( *used_port = port; - if (setsockopt (sock, IPPROTO_IP, IP_TOS, &tos, sizeof (tos)) < 0) + if (setsockopt (sock, IPPROTO_IP, IP_TOS, (const void*)&tos, sizeof (tos)) < 0) GST_WARNING ("could not set socket ToS: %s", g_strerror (errno)); #ifdef IPV6_TCLASS - if (setsockopt (sock, IPPROTO_IPV6, IPV6_TCLASS, &tos, sizeof (tos)) < 0) + if (setsockopt (sock, IPPROTO_IPV6, IPV6_TCLASS, (const void*)&tos, sizeof (tos)) < 0) GST_WARNING ("could not set TCLASS: %s", g_strerror (errno)); #endif @@ -1314,12 +1323,12 @@ fs_rawudp_transmitter_set_type_of_service (FsRawUdpTransmitter *self, { UdpPort *udpport = item->data; - if (setsockopt (udpport->fd, IPPROTO_IP, IP_TOS, &tos, sizeof (tos)) < 0) + if (setsockopt (udpport->fd, IPPROTO_IP, IP_TOS, (const void*)&tos, sizeof (tos)) < 0) GST_WARNING ( "could not set socket ToS: %s", g_strerror (errno)); #ifdef IPV6_TCLASS if (setsockopt (udpport->fd, IPPROTO_IPV6, IPV6_TCLASS, - &tos, sizeof (tos)) < 0) + (const void*)&tos, sizeof (tos)) < 0) GST_WARNING ("could not set TCLASS: %s", g_strerror (errno)); #endif } diff --git a/transmitters/shm/fs-shm-stream-transmitter.c b/transmitters/shm/fs-shm-stream-transmitter.c index fd2192e..4d35442 100644 --- a/transmitters/shm/fs-shm-stream-transmitter.c +++ b/transmitters/shm/fs-shm-stream-transmitter.c @@ -80,6 +80,12 @@ # include #endif +#ifdef G_OS_WIN32 +/* Windows doesn't have mkdtemp, so we bring it with us from locally included source file from + http://svn.r-project.org/R/trunk/src/main/mkdtemp.c */ +# include "mkdtemp.h" +#endif /*G_OS_WIN32*/ + #include GST_DEBUG_CATEGORY_EXTERN (fs_shm_transmitter_debug);