diff --git a/configure.ac b/configure.ac index 04581f8..d285e6a 100644 --- a/configure.ac +++ b/configure.ac @@ -240,7 +240,6 @@ dnl ####################### AC_CHECK_FUNCS([ \ arc4random \ basename \ - gettimeofday \ nl_langinfo \ pclose \ popen \ diff --git a/src/ezstream.c b/src/ezstream.c index 674ac63..3eb794d 100644 --- a/src/ezstream.c +++ b/src/ezstream.c @@ -85,7 +85,7 @@ FILE * openResource(shout_t *, const char *, int *, metadata_t **, int reconnectServer(shout_t *, int); const char * getTimeString(long); int sendStream(shout_t *, FILE *, const char *, int, const char *, - struct timeval *); + struct timespec *); int streamFile(shout_t *, const char *); int streamPlaylist(shout_t *); int ez_shutdown(int); @@ -699,19 +699,19 @@ getTimeString(long seconds) int sendStream(shout_t *shout, FILE *filepstream, const char *fileName, - int isStdin, const char *songLenStr, struct timeval *tv) + int isStdin, const char *songLenStr, struct timespec *tv) { unsigned char buff[4096]; size_t bytes_read, total, oldTotal; int ret; double kbps = -1.0; - struct timeval timeStamp, *startTime = tv; - struct timeval callTime, currentTime; + struct timespec timeStamp, *startTime = tv; + struct timespec callTime, currentTime; - ez_gettimeofday((void *)&callTime); + clock_gettime(CLOCK_MONOTONIC, &callTime); timeStamp.tv_sec = startTime->tv_sec; - timeStamp.tv_usec = startTime->tv_usec; + timeStamp.tv_nsec = startTime->tv_nsec; total = oldTotal = 0; ret = STREAM_DONE; @@ -747,7 +747,7 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName, break; } - ez_gettimeofday((void *)¤tTime); + clock_gettime(CLOCK_MONOTONIC, ¤tTime); if (queryMetadata || (0 <= cfg_get_metadata_refresh_interval() && @@ -776,9 +776,9 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName, } oldTime = (double)timeStamp.tv_sec - + (double)timeStamp.tv_usec / 1000000.0; + + (double)timeStamp.tv_nsec / 1000000000.0; newTime = (double)currentTime.tv_sec - + (double)currentTime.tv_usec / 1000000.0; + + (double)currentTime.tv_nsec / 1000000000.0; if (songLenStr == NULL) printf(" [ %s]", getTimeString(currentTime.tv_sec - @@ -792,7 +792,7 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName, kbps = (((double)(total - oldTotal) / (newTime - oldTime)) * 8.0) / 1000.0; timeStamp.tv_sec = currentTime.tv_sec; - timeStamp.tv_usec = currentTime.tv_usec; + timeStamp.tv_nsec = currentTime.tv_nsec; oldTotal = total; } if (kbps < 0) @@ -828,7 +828,7 @@ streamFile(shout_t *shout, const char *fileName) int ret, retval = 0; long songLen; metadata_t *mdata; - struct timeval startTime; + struct timespec startTime; if ((filepstream = openResource(shout, fileName, &popenFlag, &mdata, &isStdin, &songLen)) == NULL) { @@ -861,7 +861,7 @@ streamFile(shout_t *shout, const char *fileName) if (songLen > 0) songLenStr = xstrdup(getTimeString(songLen)); - ez_gettimeofday((void *)&startTime); + clock_gettime(CLOCK_MONOTONIC, &startTime); do { ret = sendStream(shout, filepstream, fileName, isStdin, songLenStr, &startTime); diff --git a/src/util.c b/src/util.c index 8659d3d..6a136cd 100644 --- a/src/util.c +++ b/src/util.c @@ -348,21 +348,3 @@ iconvert(const char *in_str, const char *from, const char *to, int mode) 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 */ - /* Fallback to time(): */ - tp->tv_sec = (long)time(NULL); - tp->tv_usec = 0; - ret = 0; -#endif /* HAVE_GETTIMEOFDAY */ - - return (ret); -} diff --git a/src/util.h b/src/util.h index 3f955e9..1a2297a 100644 --- a/src/util.h +++ b/src/util.h @@ -27,6 +27,5 @@ int strrcasecmp(const char *, const char *); shout_t * stream_setup(const char *, unsigned short, const char *); char * CHARtoUTF8(const char *, int); char * UTF8toCHAR(const char *, int); -int ez_gettimeofday(void *); #endif /* __UTIL_H__ */