[FFmpeg-devel] [PATCH v3 2/4] avutil/timer: Add clock_gettime as a fallback of AV_READ_TIME
Rémi Denis-Courmont
remi at remlab.net
Fri Jun 7 17:41:44 EEST 2024
Le perjantaina 7. kesäkuuta 2024, 16.44.50 EEST Zhao Zhili a écrit :
> 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;
Wouldn't INT64_C() be more idiomatic here?
> + }
> +# define AV_READ_TIME ff_read_time
> # endif
> #endif
--
レミ・デニ-クールモン
http://www.remlab.net/
More information about the ffmpeg-devel
mailing list