mirror of
https://gitlab.xiph.org/xiph/ezstream.git
synced 2025-01-03 14:56:35 -05:00
Switch to clock_gettime(CLOCK_MONOTONIC)
This commit is contained in:
parent
122728aaa2
commit
715be8094b
@ -240,7 +240,6 @@ dnl #######################
|
|||||||
AC_CHECK_FUNCS([ \
|
AC_CHECK_FUNCS([ \
|
||||||
arc4random \
|
arc4random \
|
||||||
basename \
|
basename \
|
||||||
gettimeofday \
|
|
||||||
nl_langinfo \
|
nl_langinfo \
|
||||||
pclose \
|
pclose \
|
||||||
popen \
|
popen \
|
||||||
|
@ -85,7 +85,7 @@ FILE * openResource(shout_t *, const char *, int *, metadata_t **,
|
|||||||
int reconnectServer(shout_t *, int);
|
int reconnectServer(shout_t *, int);
|
||||||
const char * getTimeString(long);
|
const char * getTimeString(long);
|
||||||
int sendStream(shout_t *, FILE *, const char *, int, const char *,
|
int sendStream(shout_t *, FILE *, const char *, int, const char *,
|
||||||
struct timeval *);
|
struct timespec *);
|
||||||
int streamFile(shout_t *, const char *);
|
int streamFile(shout_t *, const char *);
|
||||||
int streamPlaylist(shout_t *);
|
int streamPlaylist(shout_t *);
|
||||||
int ez_shutdown(int);
|
int ez_shutdown(int);
|
||||||
@ -699,19 +699,19 @@ getTimeString(long 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, struct timeval *tv)
|
int isStdin, const char *songLenStr, struct timespec *tv)
|
||||||
{
|
{
|
||||||
unsigned char buff[4096];
|
unsigned char buff[4096];
|
||||||
size_t bytes_read, total, oldTotal;
|
size_t bytes_read, total, oldTotal;
|
||||||
int ret;
|
int ret;
|
||||||
double kbps = -1.0;
|
double kbps = -1.0;
|
||||||
struct timeval timeStamp, *startTime = tv;
|
struct timespec timeStamp, *startTime = tv;
|
||||||
struct timeval callTime, currentTime;
|
struct timespec callTime, currentTime;
|
||||||
|
|
||||||
ez_gettimeofday((void *)&callTime);
|
clock_gettime(CLOCK_MONOTONIC, &callTime);
|
||||||
|
|
||||||
timeStamp.tv_sec = startTime->tv_sec;
|
timeStamp.tv_sec = startTime->tv_sec;
|
||||||
timeStamp.tv_usec = startTime->tv_usec;
|
timeStamp.tv_nsec = startTime->tv_nsec;
|
||||||
|
|
||||||
total = oldTotal = 0;
|
total = oldTotal = 0;
|
||||||
ret = STREAM_DONE;
|
ret = STREAM_DONE;
|
||||||
@ -747,7 +747,7 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ez_gettimeofday((void *)¤tTime);
|
clock_gettime(CLOCK_MONOTONIC, ¤tTime);
|
||||||
|
|
||||||
if (queryMetadata ||
|
if (queryMetadata ||
|
||||||
(0 <= cfg_get_metadata_refresh_interval() &&
|
(0 <= cfg_get_metadata_refresh_interval() &&
|
||||||
@ -776,9 +776,9 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
|
|||||||
}
|
}
|
||||||
|
|
||||||
oldTime = (double)timeStamp.tv_sec
|
oldTime = (double)timeStamp.tv_sec
|
||||||
+ (double)timeStamp.tv_usec / 1000000.0;
|
+ (double)timeStamp.tv_nsec / 1000000000.0;
|
||||||
newTime = (double)currentTime.tv_sec
|
newTime = (double)currentTime.tv_sec
|
||||||
+ (double)currentTime.tv_usec / 1000000.0;
|
+ (double)currentTime.tv_nsec / 1000000000.0;
|
||||||
if (songLenStr == NULL)
|
if (songLenStr == NULL)
|
||||||
printf(" [ %s]",
|
printf(" [ %s]",
|
||||||
getTimeString(currentTime.tv_sec -
|
getTimeString(currentTime.tv_sec -
|
||||||
@ -792,7 +792,7 @@ sendStream(shout_t *shout, FILE *filepstream, const char *fileName,
|
|||||||
kbps = (((double)(total - oldTotal)
|
kbps = (((double)(total - oldTotal)
|
||||||
/ (newTime - oldTime)) * 8.0) / 1000.0;
|
/ (newTime - oldTime)) * 8.0) / 1000.0;
|
||||||
timeStamp.tv_sec = currentTime.tv_sec;
|
timeStamp.tv_sec = currentTime.tv_sec;
|
||||||
timeStamp.tv_usec = currentTime.tv_usec;
|
timeStamp.tv_nsec = currentTime.tv_nsec;
|
||||||
oldTotal = total;
|
oldTotal = total;
|
||||||
}
|
}
|
||||||
if (kbps < 0)
|
if (kbps < 0)
|
||||||
@ -828,7 +828,7 @@ streamFile(shout_t *shout, const char *fileName)
|
|||||||
int ret, retval = 0;
|
int ret, retval = 0;
|
||||||
long songLen;
|
long songLen;
|
||||||
metadata_t *mdata;
|
metadata_t *mdata;
|
||||||
struct timeval startTime;
|
struct timespec startTime;
|
||||||
|
|
||||||
if ((filepstream = openResource(shout, fileName, &popenFlag, &mdata, &isStdin, &songLen))
|
if ((filepstream = openResource(shout, fileName, &popenFlag, &mdata, &isStdin, &songLen))
|
||||||
== NULL) {
|
== NULL) {
|
||||||
@ -861,7 +861,7 @@ streamFile(shout_t *shout, const char *fileName)
|
|||||||
|
|
||||||
if (songLen > 0)
|
if (songLen > 0)
|
||||||
songLenStr = xstrdup(getTimeString(songLen));
|
songLenStr = xstrdup(getTimeString(songLen));
|
||||||
ez_gettimeofday((void *)&startTime);
|
clock_gettime(CLOCK_MONOTONIC, &startTime);
|
||||||
do {
|
do {
|
||||||
ret = sendStream(shout, filepstream, fileName, isStdin,
|
ret = sendStream(shout, filepstream, fileName, isStdin,
|
||||||
songLenStr, &startTime);
|
songLenStr, &startTime);
|
||||||
|
18
src/util.c
18
src/util.c
@ -348,21 +348,3 @@ 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 */
|
|
||||||
/* Fallback to time(): */
|
|
||||||
tp->tv_sec = (long)time(NULL);
|
|
||||||
tp->tv_usec = 0;
|
|
||||||
ret = 0;
|
|
||||||
#endif /* HAVE_GETTIMEOFDAY */
|
|
||||||
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
|
@ -27,6 +27,5 @@ int strrcasecmp(const char *, const char *);
|
|||||||
shout_t * stream_setup(const char *, unsigned short, const char *);
|
shout_t * stream_setup(const char *, unsigned short, 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__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user