diff options
author | wm4 <wm4@nowhere> | 2013-05-17 19:54:37 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-05-26 16:44:20 +0200 |
commit | 81439c5f35e604174408a2aaf4e4dec11b81ac39 (patch) | |
tree | abd67642f487850c7f16666cc5f456d8f7ca347f /osdep/timer.h | |
parent | 25d66f526ebae36a6c044652e5006450dd5a30df (diff) | |
download | mpv-81439c5f35e604174408a2aaf4e4dec11b81ac39.tar.bz2 mpv-81439c5f35e604174408a2aaf4e4dec11b81ac39.tar.xz |
timer: refactor, add 64 bit timer function
Make OS specific timer code export a mp_raw_time_us() function, and
add generic implementations of GetTimer()/GetTimerMS() using this
function. New mpv code is supposed to call mp_time_us() in situations
where precision is absolutely needed, or mp_time_s() otherwise.
Make it so that mp_time_us() will return a value near program start.
We don't set it to 0 though to avoid confusion with relative vs.
absolute time. Instead, pick an arbitrary offset.
Move the test program in timer-darwin.c to timer.c, and modify it to
work with the generic timer functions.
Diffstat (limited to 'osdep/timer.h')
-rw-r--r-- | osdep/timer.h | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/osdep/timer.h b/osdep/timer.h index fe04663781..033b366750 100644 --- a/osdep/timer.h +++ b/osdep/timer.h @@ -19,10 +19,28 @@ #ifndef MPLAYER_TIMER_H #define MPLAYER_TIMER_H -void InitTimer(void); -unsigned int GetTimer(void); -unsigned int GetTimerMS(void); +#include <inttypes.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 seconds. Can have down to 1 microsecond 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); + +// Sleep in microseconds. +void mp_sleep_us(int64_t us); + +// Legacy timer functions. These can wrap. +unsigned int GetTimer(void); // in us +unsigned int GetTimerMS(void); // in ms int usec_sleep(int usec_delay); #endif /* MPLAYER_TIMER_H */ |