1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2025-02-02 15:07:45 -05:00

gettimeofday() everywhere; now ezstream behaves almost the same on Windows

compared to Unix. Also mention TagLib support on Windows in NEWS.


git-svn-id: https://svn.xiph.org/trunk/ezstream@13668 0101bb08-14d6-0310-b084-bc0e0c8e3800
This commit is contained in:
moritz 2007-08-31 11:47:54 +00:00
parent 509dc8511e
commit 957f1d94c5
7 changed files with 102 additions and 56 deletions

6
NEWS
View File

@ -17,11 +17,17 @@ Changes in 0.5.0 (SVN):
console. Unsupported characters are displayed as '?', which console. Unsupported characters are displayed as '?', which
does not affect the actual metadata. This feature requires does not affect the actual metadata. This feature requires
iconv() via libc, if available, or GNU libiconv. 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 - [MISC] Add new --enable-debug configuration option to the configure
script, which enables (also new) memory debugging features. script, which enables (also new) memory debugging features.
(Not interesting for non-developers.) (Not interesting for non-developers.)
- [MISC] Various small code cleanups. - [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: Changes in 0.4.3, released on 2007-07-24:

View File

@ -57,36 +57,6 @@ fi
AC_MSG_RESULT([$ez_enable_debug]) 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 dnl USEFUL HEADERS
AC_CHECK_HEADERS(sys/time.h paths.h signal.h langinfo.h libgen.h locale.h) AC_CHECK_HEADERS(sys/time.h paths.h signal.h langinfo.h libgen.h locale.h)
@ -116,6 +86,35 @@ fi
AC_SUBST(COMPAT_INCLUDES) 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 dnl LIBRARY FUNCTIONS
AC_CHECK_LIB(gen, basename) AC_CHECK_LIB(gen, basename)

View File

@ -69,6 +69,13 @@
# define _PATH_DEVNULL "/dev/null" # define _PATH_DEVNULL "/dev/null"
#endif /* !_PATH_DEVNULL */ #endif /* !_PATH_DEVNULL */
#ifndef HAVE_STRUCT_TIMEVAL
struct timeval {
long tv_sec;
long tv_usec;
};
#endif
char * local_basename(const char *); char * local_basename(const char *);
#endif /* __COMPAT_H__ */ #endif /* __COMPAT_H__ */

View File

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

View File

@ -29,6 +29,11 @@
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
#endif #endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#else
# include <time.h>
#endif
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
@ -363,3 +368,43 @@ iconvert(const char *in_str, const char *from, const char *to, int mode)
return (xstrdup(in_str)); return (xstrdup(in_str));
#endif /* HAVE_ICONV */ #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);
}

View File

@ -29,5 +29,6 @@ int strrcasecmp(const char *, const char *);
shout_t * stream_setup(const char *, const int, const char *); shout_t * stream_setup(const char *, const int, const char *);
char * CHARtoUTF8(const char *, int); char * CHARtoUTF8(const char *, int);
char * UTF8toCHAR(const char *, int); char * UTF8toCHAR(const char *, int);
int ez_gettimeofday(void *);
#endif /* __UTIL_H__ */ #endif /* __UTIL_H__ */

View File

@ -6,6 +6,7 @@
#define HAVE_LOCALE_H 1 #define HAVE_LOCALE_H 1
#define HAVE_STAT 1 #define HAVE_STAT 1
#define HAVE_STDINT_H 1 #define HAVE_STDINT_H 1
#define HAVE_STRUCT_TIMEVAL 1
#define HAVE_SYS_STAT_H 1 #define HAVE_SYS_STAT_H 1
#define ICONV_CONST const #define ICONV_CONST const