From de9b800879706734721810427248e75ea5bdc0f9 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Wed, 11 Oct 2023 11:34:14 -0500 Subject: 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. --- osdep/timer.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'osdep') 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) -- cgit v1.2.3