summaryrefslogtreecommitdiffstats
path: root/osdep/timer.h
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2023-10-11 11:34:14 -0500
committerDudemanguy <random342@airmail.cc>2023-10-16 15:38:59 +0000
commitde9b800879706734721810427248e75ea5bdc0f9 (patch)
treef2cc425e6050d215b239372e2dba88167aaf7d5e /osdep/timer.h
parent9d3e607cf749b7be057ba8f30ffd3d55c695a70b (diff)
downloadmpv-de9b800879706734721810427248e75ea5bdc0f9.tar.bz2
mpv-de9b800879706734721810427248e75ea5bdc0f9.tar.xz
timer: add convenience time unit conversion macros
There's a lot of wild 1e6, 1000, etc. lying around in the code. A macro is much easier to read and understand at a glance. Add some helpers for this. We don't need to convert everything now but there's some simple things that can be done so they are included in this commit.
Diffstat (limited to 'osdep/timer.h')
-rw-r--r--osdep/timer.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/osdep/timer.h b/osdep/timer.h
index b273cb405e..efbfc4e358 100644
--- a/osdep/timer.h
+++ b/osdep/timer.h
@@ -50,6 +50,16 @@ void mp_end_hires_timers(int resolution_ms);
#define MP_START_TIME 10 * INT64_C(1000000000)
+// Converts time units to nanoseconds (int64_t)
+#define MP_TIME_S_TO_NS(s) ((s) * INT64_C(1000000000))
+#define MP_TIME_MS_TO_NS(ms) ((ms) * INT64_C(1000000))
+#define MP_TIME_US_TO_NS(us) ((us) * INT64_C(1000))
+
+// Converts nanoseconds to specified time unit (double)
+#define MP_TIME_NS_TO_S(ns) ((ns) / (double)1000000000)
+#define MP_TIME_NS_TO_MS(ns) ((ns) / (double)1000000)
+#define MP_TIME_NS_TO_US(ns) ((ns) / (double)1000)
+
// Duration of a second in mpv time.
#define MP_SECOND_US (1000 * 1000)