[vlc-devel] [PATCH] vlc_tick: simpler tick<->ns conversion

Thomas Guillem thomas at gllm.fr
Wed Aug 21 10:20:00 CEST 2019


NS_FROM_VLC_TICK() could overflow after 1000 days.
---
 include/vlc_tick.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/vlc_tick.h b/include/vlc_tick.h
index 517eff1a44..1eb1f46cc9 100644
--- a/include/vlc_tick.h
+++ b/include/vlc_tick.h
@@ -147,7 +147,10 @@ static inline vlc_tick_t vlc_tick_from_frac(uint64_t num, uint64_t den)
 /*
  * vlc_tick_t <> nanoseconds (ns) conversions
  */
-#if (CLOCK_FREQ % 1000000000) == 0
+#if (CLOCK_FREQ == 1000000)
+#define VLC_TICK_FROM_NS(ns)    ((ns) / INT64_C(1000))
+#define NS_FROM_VLC_TICK(vtk)   ((vtk) * INT64_C(1000))
+#elif (CLOCK_FREQ % 1000000000) == 0
 #define VLC_TICK_FROM_NS(ns)    ((ns)  * (CLOCK_FREQ / (INT64_C(1000000000))))
 #define NS_FROM_VLC_TICK(vtk)   ((vtk) / (CLOCK_FREQ / (INT64_C(1000000000))))
 #elif (1000000000 % CLOCK_FREQ) == 0
-- 
2.20.1



More information about the vlc-devel mailing list