[vlc-commits] vlc_tick: add helper macros to convert nanoseconds to/from vlc_tick_t
Steve Lhomme
git at videolan.org
Fri Jun 29 17:36:09 CEST 2018
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Jun 22 18:05:23 2018 +0200| [1d3482ef4e3031cc1dab24d21d194e9591c0cb17] | committer: Steve Lhomme
vlc_tick: add helper macros to convert nanoseconds to/from vlc_tick_t
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1d3482ef4e3031cc1dab24d21d194e9591c0cb17
---
include/vlc_tick.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/include/vlc_tick.h b/include/vlc_tick.h
index d318a0c8a4..c168113e3e 100644
--- a/include/vlc_tick.h
+++ b/include/vlc_tick.h
@@ -128,6 +128,21 @@ static inline double secf_from_vlc_tick(vlc_tick_t vtk)
#endif /* CLOCK_FREQ / 1000000 */
+/*
+ * vlc_tick_t <> nanoseconds (ns) conversions
+ */
+#if (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
+#define VLC_TICK_FROM_NS(ns) ((ns) / (INT64_C(1000000000) / CLOCK_FREQ))
+#define NS_FROM_VLC_TICK(vtk) ((vtk) * (INT64_C(1000000000) / CLOCK_FREQ))
+#else /* rounded overflowing conversion */
+#define VLC_TICK_FROM_NS(ns) (CLOCK_FREQ * (ns) / INT64_C(1000000000))
+#define NS_FROM_VLC_TICK(vtk) ((vtk) * INT64_C(1000000000) / CLOCK_FREQ)
+#endif /* CLOCK_FREQ / 1000000000 */
+
+
/*****************************************************************************
* MSTRTIME_MAX_SIZE: maximum possible size of mstrtime
*****************************************************************************
More information about the vlc-commits
mailing list