[FFmpeg-devel] [PATCH v3 2/4] avutil/timer: Add clock_gettime as a fallback of AV_READ_TIME
Zhao Zhili
quinkblack at foxmail.com
Fri Jun 7 16:44:50 EEST 2024
From: Zhao Zhili <zhilizhao at tencent.com>
---
v3: add ff_read_time() rather than use av_gettime_relative() to get
nanosecond precision.
libavutil/timer.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/libavutil/timer.h b/libavutil/timer.h
index 2cd299eca3..3e5d5ef23f 100644
--- a/libavutil/timer.h
+++ b/libavutil/timer.h
@@ -46,6 +46,8 @@
#include "macos_kperf.h"
#elif HAVE_MACH_ABSOLUTE_TIME
#include <mach/mach_time.h>
+#elif HAVE_CLOCK_GETTIME
+#include <time.h>
#endif
#include "common.h"
@@ -70,6 +72,14 @@
# define AV_READ_TIME gethrtime
# elif HAVE_MACH_ABSOLUTE_TIME
# define AV_READ_TIME mach_absolute_time
+# elif HAVE_CLOCK_GETTIME && defined(CLOCK_MONOTONIC)
+ static inline int64_t ff_read_time(void)
+ {
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ return (int64_t) ts.tv_sec * 1000000000 + ts.tv_nsec;
+ }
+# define AV_READ_TIME ff_read_time
# endif
#endif
--
2.42.0
More information about the ffmpeg-devel
mailing list