summaryrefslogtreecommitdiffstats
path: root/osdep/timer.h
diff options
context:
space:
mode:
Diffstat (limited to 'osdep/timer.h')
-rw-r--r--osdep/timer.h50
1 files changed, 33 insertions, 17 deletions
diff --git a/osdep/timer.h b/osdep/timer.h
index be5e9c0467..5fedbb69cd 100644
--- a/osdep/timer.h
+++ b/osdep/timer.h
@@ -19,38 +19,54 @@
#define MPLAYER_TIMER_H
#include <inttypes.h>
+#include "config.h"
// Initialize timer, must be called at least once at start.
void mp_time_init(void);
-// Return time in microseconds. Never wraps. Never returns 0 or negative values.
-int64_t mp_time_us(void);
+// Return time in nanoseconds. Never wraps. Never returns negative values.
+int64_t mp_time_ns(void);
-// Return time in seconds. Can have down to 1 microsecond resolution, but will
+// Return time in nanoseconds. Coverts raw time in nanoseconds to mp time, subtracts init offset.
+int64_t mp_time_ns_from_raw_time(uint64_t raw_time);
+
+// Return time in seconds. Can have down to 1 nanosecond resolution, but will
// be much worse when casted to float.
double mp_time_sec(void);
// Provided by OS specific functions (timer-linux.c)
void mp_raw_time_init(void);
-uint64_t mp_raw_time_us(void);
+// ensure this doesn't return 0
+uint64_t mp_raw_time_ns(void);
-// Sleep in microseconds.
-void mp_sleep_us(int64_t us);
+// Sleep in nanoseconds.
+void mp_sleep_ns(int64_t ns);
-#define MP_START_TIME 10000000
+#if HAVE_DARWIN
+// Coverts mach time to raw time in nanoseconds and returns it.
+uint64_t mp_raw_time_ns_from_mach(uint64_t mach_time);
+#endif
-// Duration of a second in mpv time.
-#define MP_SECOND_US (1000 * 1000)
+#ifdef _WIN32
+// returns: timer resolution in ns if needed and started successfully, else 0
+int64_t mp_start_hires_timers(int64_t wait_ns);
-// Add a time in seconds to the given time in microseconds, and return it.
-// Takes care of possible overflows. Never returns a negative or 0 time.
-int64_t mp_add_timeout(int64_t time_us, double timeout_sec);
+// call unconditionally with the return value of mp_start_hires_timers
+void mp_end_hires_timers(int64_t resolution_ns);
+#endif /* _WIN32 */
-// Convert the mp time in microseconds to a timespec using CLOCK_REALTIME.
-struct timespec mp_time_us_to_timespec(int64_t time_us);
+// 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))
-// Convert the relative timeout in seconds to a timespec.
-// The timespec is absolute, using CLOCK_REALTIME.
-struct timespec mp_rel_time_to_timespec(double timeout_sec);
+// 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)
+
+// Add a time in seconds to the given time in nanoseconds, and return it.
+// Takes care of possible overflows. Never returns a negative or 0 time.
+int64_t mp_time_ns_add(int64_t time_ns, double timeout_sec);
#endif /* MPLAYER_TIMER_H */