1
0
mirror of https://gitlab.xiph.org/xiph/ezstream.git synced 2024-09-15 04:08:07 -04:00

Switch to clock_gettime(CLOCK_MONOTONIC)

This commit is contained in:
Moritz Grimm 2015-05-28 00:10:52 +02:00
parent 122728aaa2
commit 715be8094b
4 changed files with 12 additions and 32 deletions

View File

@ -240,7 +240,6 @@ dnl #######################
AC_CHECK_FUNCS([ \
arc4random \
basename \
gettimeofday \
nl_langinfo \
pclose \
popen \

View File

@ -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 *)&currentTime);
clock_gettime(CLOCK_MONOTONIC, &currentTime);
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);

View File

@ -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);
}

View File

@ -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__ */