[vlc-commits] vlc_tick: add helper macros to convert milliseconds to/from vlc_tick_t

Steve Lhomme git at videolan.org
Fri Jun 29 17:36:07 CEST 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Jun 22 18:02:36 2018 +0200| [505182d874273dcbfdc10184f450469ee63a96df] | committer: Steve Lhomme

vlc_tick: add helper macros to convert milliseconds to/from vlc_tick_t

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=505182d874273dcbfdc10184f450469ee63a96df
---

 include/vlc_tick.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/include/vlc_tick.h b/include/vlc_tick.h
index 1b18e22d44..7236b98d9d 100644
--- a/include/vlc_tick.h
+++ b/include/vlc_tick.h
@@ -98,6 +98,21 @@ static inline double secf_from_vlc_tick(vlc_tick_t vtk)
 }
 
 
+/*
+ * vlc_tick_t <> milliseconds (ms) conversions
+ */
+#if (CLOCK_FREQ % 1000) == 0
+#define VLC_TICK_FROM_MS(ms)  ((CLOCK_FREQ / INT64_C(1000)) * (ms))
+#define MS_FROM_VLC_TICK(vtk) ((vtk) / (CLOCK_FREQ / INT64_C(1000)))
+#elif (1000 % CLOCK_FREQ) == 0
+#define VLC_TICK_FROM_MS(ms)  ((ms)  / (INT64_C(1000) / CLOCK_FREQ))
+#define MS_FROM_VLC_TICK(vtk) ((vtk) * (INT64_C(1000) / CLOCK_FREQ))
+#else /* rounded overflowing conversion */
+#define VLC_TICK_FROM_MS(ms)  (CLOCK_FREQ * (ms) / 1000)
+#define MS_FROM_VLC_TICK(vtk) ((vtk) * 1000 / CLOCK_FREQ)
+#endif /* CLOCK_FREQ / 1000 */
+
+
 /*****************************************************************************
  * MSTRTIME_MAX_SIZE: maximum possible size of mstrtime
  *****************************************************************************



More information about the vlc-commits mailing list