[FFmpeg-cvslog] time: Use clock_gettime if the monotonic clock is available
Luca Barbato
git at videolan.org
Wed Sep 3 14:50:41 CEST 2014
ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Sun Aug 24 18:14:47 2014 +0200| [ebef9f5a56d7df91e010a177a80cfc8dbe394305] | committer: Luca Barbato
time: Use clock_gettime if the monotonic clock is available
Signed-off-by: Luca Barbato <lu_zero at gentoo.org>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=ebef9f5a56d7df91e010a177a80cfc8dbe394305
---
configure | 4 ++++
libavutil/time.c | 10 ++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/configure b/configure
index 22b699f..af0128a 100755
--- a/configure
+++ b/configure
@@ -1432,6 +1432,7 @@ MATH_FUNCS="
SYSTEM_FUNCS="
aligned_malloc
+ clock_gettime
closesocket
CommandLineToArgvW
CoTaskMemFree
@@ -4038,6 +4039,9 @@ check_func_headers malloc.h _aligned_malloc && enable aligned_malloc
check_func ${malloc_prefix}memalign && enable memalign
check_func ${malloc_prefix}posix_memalign && enable posix_memalign
+check_cpp_condition unistd.h "defined(_POSIX_MONOTONIC_CLOCK)" &&
+ check_func_headers time.h clock_gettime || { check_func_headers time.h clock_gettime -lrt && add_extralibs -lrt; }
+
check_func fcntl
check_func fork
check_func gethrtime
diff --git a/libavutil/time.c b/libavutil/time.c
index 62cd445..e833cd0 100644
--- a/libavutil/time.c
+++ b/libavutil/time.c
@@ -21,7 +21,9 @@
#include <stddef.h>
#include <stdint.h>
#include <time.h>
-#if HAVE_GETTIMEOFDAY
+#if HAVE_CLOCK_GETTIME
+#include <time.h>
+#elif HAVE_GETTIMEOFDAY
#include <sys/time.h>
#endif
#if HAVE_UNISTD_H
@@ -36,7 +38,11 @@
int64_t av_gettime(void)
{
-#if HAVE_GETTIMEOFDAY
+#if HAVE_CLOCK_GETTIME
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (int64_t)ts.tv_sec * 100000 + ts.tv_nsec / 1000;
+#elif HAVE_GETTIMEOFDAY
struct timeval tv;
gettimeofday(&tv, NULL);
return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
More information about the ffmpeg-cvslog
mailing list