[xiph-commits] r13668 - in trunk/ezstream: . src win32

moritz at svn.xiph.org moritz at svn.xiph.org
Fri Aug 31 04:47:54 PDT 2007


Author: moritz
Date: 2007-08-31 04:47:54 -0700 (Fri, 31 Aug 2007)
New Revision: 13668

Modified:
   trunk/ezstream/NEWS
   trunk/ezstream/configure.in
   trunk/ezstream/src/compat.h
   trunk/ezstream/src/ezstream.c
   trunk/ezstream/src/util.c
   trunk/ezstream/src/util.h
   trunk/ezstream/win32/config.h
Log:
gettimeofday() everywhere; now ezstream behaves almost the same on Windows
compared to Unix. Also mention TagLib support on Windows in NEWS.


Modified: trunk/ezstream/NEWS
===================================================================
--- trunk/ezstream/NEWS	2007-08-31 11:46:05 UTC (rev 13667)
+++ trunk/ezstream/NEWS	2007-08-31 11:47:54 UTC (rev 13668)
@@ -17,13 +17,19 @@
              console. Unsupported characters are displayed as '?', which
              does not affect the actual metadata. This feature requires
              iconv() via libc, if available, or GNU libiconv.
+   - [NEW]   Support gettimeofday() functionality on all platforms, including
+             Windows. The "real-time status line" when using the -q and -v
+             parameters is now complete everywhere.
    - [MISC]  Add new --enable-debug configuration option to the configure
              script, which enables (also new) memory debugging features.
              (Not interesting for non-developers.)
    - [MISC]  Various small code cleanups.
 
+ * The Windows build of ezstream now supports reading metadata from files
+   with TagLib.
 
 
+
 Changes in 0.4.3, released on 2007-07-24:
 
  * src/ezstream.c:

Modified: trunk/ezstream/configure.in
===================================================================
--- trunk/ezstream/configure.in	2007-08-31 11:46:05 UTC (rev 13667)
+++ trunk/ezstream/configure.in	2007-08-31 11:47:54 UTC (rev 13668)
@@ -57,36 +57,6 @@
 AC_MSG_RESULT([$ez_enable_debug])
 
 
-dnl MISC SYSTEM CHARACTERISTICS
-
-dnl __progname check adapted from OpenNTPd-portable configure.ac
-AC_MSG_CHECKING([whether libc defines __progname])
-AC_LINK_IFELSE(
-	[AC_LANG_PROGRAM([[#include <stdio.h>]],
-		[[extern char *__progname; printf("%s\n", __progname); ]])],
-	[ac_cv_libc_defines___progname="yes"],
-	[ac_cv_libc_defines___progname="no"]
-)
-if test x"$ac_cv_libc_defines___progname" = "xyes"; then
-	AC_MSG_RESULT([yes])
-	AC_DEFINE(HAVE___PROGNAME, 1, [Define whether libc defines __progname])
-else
-	AC_MSG_RESULT([no])
-fi
-
-AC_C_CONST
-AC_C_VOLATILE
-AC_TYPE_SIZE_T
-AC_CHECK_TYPES(ssize_t, ,
-	[AC_DEFINE_UNQUOTED(ssize_t, long, [Define to `long' if <sys/types.h> does not define.])], 
-[
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-])
-
-
-
 dnl USEFUL HEADERS
 
 AC_CHECK_HEADERS(sys/time.h paths.h signal.h langinfo.h libgen.h locale.h)
@@ -116,6 +86,35 @@
 AC_SUBST(COMPAT_INCLUDES)
 
 
+dnl MISC SYSTEM CHARACTERISTICS
+
+dnl __progname check adapted from OpenNTPd-portable configure.ac
+AC_MSG_CHECKING([whether libc defines __progname])
+AC_LINK_IFELSE(
+	[AC_LANG_PROGRAM([[#include <stdio.h>]],
+		[[extern char *__progname; printf("%s\n", __progname); ]])],
+	[ac_cv_libc_defines___progname="yes"],
+	[ac_cv_libc_defines___progname="no"]
+)
+if test x"$ac_cv_libc_defines___progname" = "xyes"; then
+	AC_MSG_RESULT([yes])
+	AC_DEFINE(HAVE___PROGNAME, 1, [Define whether libc defines __progname])
+else
+	AC_MSG_RESULT([no])
+fi
+
+AC_C_CONST
+AC_C_VOLATILE
+AC_TYPE_SIZE_T
+AC_TYPE_SSIZE_T
+AC_CHECK_TYPES(struct timeval, , ,
+[
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+])
+
+
 dnl LIBRARY FUNCTIONS
 
 AC_CHECK_LIB(gen, basename)

Modified: trunk/ezstream/src/compat.h
===================================================================
--- trunk/ezstream/src/compat.h	2007-08-31 11:46:05 UTC (rev 13667)
+++ trunk/ezstream/src/compat.h	2007-08-31 11:47:54 UTC (rev 13668)
@@ -69,6 +69,13 @@
 # define _PATH_DEVNULL	"/dev/null"
 #endif /* !_PATH_DEVNULL */
 
+#ifndef HAVE_STRUCT_TIMEVAL
+struct timeval {
+	long	tv_sec;
+	long	tv_usec;
+};
+#endif
+
 char *	local_basename(const char *);
 
 #endif /* __COMPAT_H__ */

Modified: trunk/ezstream/src/ezstream.c
===================================================================
--- trunk/ezstream/src/ezstream.c	2007-08-31 11:46:05 UTC (rev 13667)
+++ trunk/ezstream/src/ezstream.c	2007-08-31 11:47:54 UTC (rev 13668)
@@ -102,13 +102,13 @@
 #endif /* HAVE_SIGNALS */
 
 typedef struct tag_ID3Tag {
-	char tag[3];
-	char trackName[30];
-	char artistName[30];
-	char albumName[30];
-	char year[3];
-	char comment[30];
-	char genre;
+	char	tag[3];
+	char	trackName[30];
+	char	artistName[30];
+	char	albumName[30];
+	char	year[3];
+	char	comment[30];
+	char	genre;
 } ID3Tag;
 
 int		urlParse(const char *, char **, int *, char **);
@@ -123,7 +123,7 @@
 int		reconnectServer(shout_t *, int);
 const char *	getTimeString(int);
 int		sendStream(shout_t *, FILE *, const char *, int, const char *,
-			   void *);
+			   struct timeval *);
 int		streamFile(shout_t *, const char *);
 int		streamPlaylist(shout_t *, const char *);
 char *		getProgname(const char *);
@@ -744,14 +744,13 @@
 
 int
 sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
-	   int isStdin, const char *songLenStr, void *tv)
+	   int isStdin, const char *songLenStr, struct timeval *tv)
 {
 	unsigned char	 buff[4096];
 	size_t		 read, total, oldTotal;
 	int		 ret;
-#ifdef HAVE_GETTIMEOFDAY
 	double		 kbps = -1.0;
-	struct timeval	 timeStamp, *startTime = (struct timeval *)tv;
+	struct timeval	 timeStamp, *startTime = tv;
 
 	if (startTime == NULL) {
 		printf("%s: sendStream(): Internal error: startTime is NULL\n",
@@ -761,7 +760,6 @@
 
 	timeStamp.tv_sec = startTime->tv_sec;
 	timeStamp.tv_usec = startTime->tv_usec;
-#endif /* HAVE_GETTIMEOFDAY */
 
 	total = oldTotal = 0;
 	ret = STREAM_DONE;
@@ -808,10 +806,8 @@
 
 		total += read;
 		if (qFlag && vFlag) {
-#ifdef HAVE_GETTIMEOFDAY
 			struct timeval	tv;
 			double		oldTime, newTime;
-#endif /* HAVE_GETTIMEOFDAY */
 
 			if (!isStdin && playlistMode) {
 				if (pezConfig->fileNameIsProgram) {
@@ -825,10 +821,9 @@
 					       playlist_get_num_items(playlist));
 			}
 
-#ifdef HAVE_GETTIMEOFDAY
 			oldTime = (double)timeStamp.tv_sec
 				+ (double)timeStamp.tv_usec / 1000000.0;
-			gettimeofday(&tv, NULL);
+			ez_gettimeofday((void *)&tv);
 			newTime = (double)tv.tv_sec
 				+ (double)tv.tv_usec / 1000000.0;
 			if (songLenStr == NULL)
@@ -848,7 +843,6 @@
 				printf("                 ");
 			else
 				printf("  [%8.2f kbps]", kbps);
-#endif /* HAVE_GETTIMEOFDAY */
 
 			printf("  \r");
 			fflush(stdout);
@@ -875,9 +869,7 @@
 	int		 isStdin = 0;
 	int		 ret, retval = 0, songLen;
 	metadata_t	*mdata;
-#ifdef HAVE_GETTIMEOFDAY
 	struct timeval	 startTime;
-#endif
 
 	if ((filepstream = openResource(shout, fileName, &popenFlag,
 					&mdata, &isStdin, &songLen))
@@ -905,17 +897,12 @@
 		metadata_free(&mdata);
 	}
 
-#ifdef HAVE_GETTIMEOFDAY
 	if (songLen >= 0)
 		songLenStr = xstrdup(getTimeString(songLen));
-	gettimeofday(&startTime, NULL);
+	ez_gettimeofday((void *)&startTime);
 	do {
 		ret = sendStream(shout, filepstream, fileName, isStdin,
-				 songLenStr, (void *)&startTime);
-#else
-	do {
-		ret = sendStream(shout, filepstream, fileName, isStdin, NULL, NULL);
-#endif
+				 songLenStr, &startTime);
 		if (quit)
 			break;
 		if (ret != STREAM_DONE) {

Modified: trunk/ezstream/src/util.c
===================================================================
--- trunk/ezstream/src/util.c	2007-08-31 11:46:05 UTC (rev 13667)
+++ trunk/ezstream/src/util.c	2007-08-31 11:47:54 UTC (rev 13668)
@@ -29,6 +29,11 @@
 #ifdef HAVE_SYS_TYPES_H
 # include <sys/types.h>
 #endif
+#ifdef HAVE_SYS_TIME_H
+# include <sys/time.h>
+#else
+# include <time.h>
+#endif
 
 #include <ctype.h>
 #include <errno.h>
@@ -363,3 +368,43 @@
 	return (xstrdup(in_str));
 #endif /* HAVE_ICONV */
 }
+
+int
+ez_gettimeofday(void *tp_arg)
+{
+	struct timeval	*tp = (struct timeval *)tp_arg;
+	int		 ret = -1;
+
+#ifdef HAVE_GETTIMEOFDAY
+	ret = gettimeofday(tp, NULL);
+#else /* HAVE_GETTIMEOFDAY */
+# ifdef WIN32
+	/*
+	 * Idea for this way of implementing gettimeofday()-like functionality
+	 * on Windows taken from cURL, (C) 1998 - 2007 Daniel Steinberg, et al.
+	 * http://curl.haxx.se/docs/copyright.html
+	 */
+	SYSTEMTIME	 st;
+	struct tm	 tm;
+
+	GetLocalTime(&st);
+	tm.tm_sec = st.wSecond;
+	tm.tm_min = st.wMinute;
+	tm.tm_hour = st.wHour;
+	tm.tm_mday = st.wDay;
+	tm.tm_mon = st.wMonth - 1;
+	tm.tm_year = st.wYear - 1900;
+	tm.tm_isdst = -1;
+	tp->tv_sec = (long)mktime(&tm);
+	tp->tv_usec = st.wMilliseconds * 1000;
+	ret = 0;
+# else /* WIN32 */
+	/* Fallback to time(): */
+	tp->tv_sec = (long)time(NULL);
+	tp->tv_usec = 0;
+	ret = 0;
+# endif /* WIN32 */
+#endif /* HAVE_GETTIMEOFDAY */
+
+	return (ret);
+}

Modified: trunk/ezstream/src/util.h
===================================================================
--- trunk/ezstream/src/util.h	2007-08-31 11:46:05 UTC (rev 13667)
+++ trunk/ezstream/src/util.h	2007-08-31 11:47:54 UTC (rev 13668)
@@ -29,5 +29,6 @@
 shout_t *	stream_setup(const char *, const int, const char *);
 char *		CHARtoUTF8(const char *, int);
 char *		UTF8toCHAR(const char *, int);
+int		ez_gettimeofday(void *);
 
 #endif /* __UTIL_H__ */

Modified: trunk/ezstream/win32/config.h
===================================================================
--- trunk/ezstream/win32/config.h	2007-08-31 11:46:05 UTC (rev 13667)
+++ trunk/ezstream/win32/config.h	2007-08-31 11:47:54 UTC (rev 13668)
@@ -6,6 +6,7 @@
 #define HAVE_LOCALE_H		1
 #define HAVE_STAT		1
 #define HAVE_STDINT_H		1
+#define HAVE_STRUCT_TIMEVAL	1
 #define HAVE_SYS_STAT_H 	1
 
 #define ICONV_CONST		const



More information about the commits mailing list