diff mbox series

[FFmpeg-devel,v2,2/4] avutil/timer: Add clock_gettime as a fallback of AV_READ_TIME

Message ID tencent_50EF736715C7A91ECEA9C54853030852B305@qq.com
State New
Headers show
Series [FFmpeg-devel,v2,1/4] avutil/aarch64: Skip define AV_READ_TIME for apple | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Zhao Zhili June 6, 2024, 5:20 p.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

---
 libavutil/timer.h | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Martin Storsjö June 7, 2024, 9:11 a.m. UTC | #1
On Fri, 7 Jun 2024, Zhao Zhili wrote:

> From: Zhao Zhili <zhilizhao@tencent.com>
>
> ---
> libavutil/timer.h | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/libavutil/timer.h b/libavutil/timer.h
> index 2cd299eca3..74c4d84e69 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,9 @@
> #       define AV_READ_TIME gethrtime
> #   elif HAVE_MACH_ABSOLUTE_TIME
> #       define AV_READ_TIME mach_absolute_time
> +#   elif HAVE_CLOCK_GETTIME && defined(CLOCK_MONOTONIC)
> +#       include "libavutil/time.h"
> +#       define AV_READ_TIME av_gettime_relative
> #   endif
> #endif
>
> -- 
> 2.34.1

This looks reasonable to me.

Although, the raw clock_gettime function, which gives nanosecond values 
(although maybe not actual nanosecond precision) probably could have more 
precision than av_gettime_relative which scales the values down to 
microseconds.

// Martin
diff mbox series

Patch

diff --git a/libavutil/timer.h b/libavutil/timer.h
index 2cd299eca3..74c4d84e69 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,9 @@ 
 #       define AV_READ_TIME gethrtime
 #   elif HAVE_MACH_ABSOLUTE_TIME
 #       define AV_READ_TIME mach_absolute_time
+#   elif HAVE_CLOCK_GETTIME && defined(CLOCK_MONOTONIC)
+#       include "libavutil/time.h"
+#       define AV_READ_TIME av_gettime_relative
 #   endif
 #endif