diff options
author | faust3 <faust3@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2003-03-30 21:07:17 +0000 |
---|---|---|
committer | faust3 <faust3@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2003-03-30 21:07:17 +0000 |
commit | 36b68e1022268c218d75a2091a1eda2fe03fbf26 (patch) | |
tree | 5bedb9defda6bc0dbccdfcbd08a095cbb1bbcae2 | |
parent | feedcd4be3e9b758f43150126821d72e4460f1d8 (diff) | |
download | mpv-36b68e1022268c218d75a2091a1eda2fe03fbf26.tar.bz2 mpv-36b68e1022268c218d75a2091a1eda2fe03fbf26.tar.xz |
high precision timer for windows patch by Frodo <csharprules at hotmail.com>
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9766 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | osdep/timer-win.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/osdep/timer-win.c b/osdep/timer-win.c new file mode 100644 index 0000000000..07e2b7416c --- /dev/null +++ b/osdep/timer-win.c @@ -0,0 +1,71 @@ +#include <stdio.h> +#include <stdlib.h> +#include <windows.h> +#include <mmsystem.h> +#include <sys/time.h> + +static LARGE_INTEGER qwTimerFrequency; +static LARGE_INTEGER qwTimerStart; +static LARGE_INTEGER m_lStartTime; +static float m_fuSecsPerTick; +static unsigned long RelativeTime = 0; + +int usec_sleep(int usec_delay) +{ + LARGE_INTEGER qwStartTicks, qwCurrTicks; + double dResult; + long lTick; + double fuSecDelay = ((float) usec_delay) / 1000000.0; + + QueryPerformanceCounter(&qwStartTicks); + do { + QueryPerformanceCounter(&qwCurrTicks); + dResult = + ((double) (qwCurrTicks.QuadPart - qwStartTicks.QuadPart)) / + ((double) (qwTimerFrequency.QuadPart)); + } while (dResult < fuSecDelay); +} + +// Returns current time in microseconds +unsigned long GetTimer() +{ + LARGE_INTEGER qwTime; + FLOAT fTime; + UINT64 uiQuadPart; + + QueryPerformanceCounter(&qwTime); + qwTime.QuadPart -= m_lStartTime.QuadPart; + uiQuadPart = (UINT64) qwTime.QuadPart; + uiQuadPart /= ((UINT64) 10); // prevent overflow after 4294.1 secs, now overflows after 42941 secs + fTime = ((FLOAT) (uiQuadPart)) / m_fuSecsPerTick; + return (unsigned long) fTime; +} + +// Returns current time in microseconds +float GetRelativeTime() +{ + unsigned long t, r; + + t = GetTimer(); + r = t - RelativeTime; + RelativeTime = t; + return (float) r *0.000001F; +} + +// Returns current time in milliseconds +unsigned int GetTimerMS() +{ + return GetTimer() / 1000; +} + +void InitTimer() +{ + FLOAT t; + + QueryPerformanceFrequency(&qwTimerFrequency); // ticks/sec + m_fuSecsPerTick = (FLOAT) (((FLOAT) (qwTimerFrequency.QuadPart)) / 1000.0); // tics/msec + m_fuSecsPerTick = (FLOAT) (m_fuSecsPerTick / 1000.0); // ticks/usec + m_fuSecsPerTick /= 10.0; + QueryPerformanceCounter(&m_lStartTime); + t = GetRelativeTime(); +} |