Commit Graph

24 Commits

Author SHA1 Message Date
Dudemanguy 59dd7d94af timer: change mp_sleep_us to mp_sleep_ns
Linux and macOS already use nanosecond resolution for their sleep
functions. It was just being converted from microseconds before. Since
we have mp_time_ns now, go ahead and bump the precision here. The timer
for windows uses some timeBeginPeriod thing which I'm not sure what it
does really but whatever just convert the units to ms like they were
doing before. There's really no reason to keep the mp_sleep_us helper
around. A multiplication by 1000 is trivial and underlying OS clocks
have nanosecond precision.
2023-10-10 19:10:55 +00:00
Kacper Michajłow 9606c3fca9 timer: teach it about nanoseconds
Those changes will alow to change vsync base to more precise time base.
In general there is no reason to truncate values returned by system.
2023-09-29 20:48:58 +00:00
Avi Halachmi (:avih) 930b483a68 win32: Windows 10: timeBeginPeriod on demand
Before this commit, timeBeginPeriod(1) was set once when mpv starts,
and the timers remained hi-res till mpv exits.

Now we do the same as before on Windows version < 10.
On Windows 10+ we now use timeBeginPeriod if needed, per timeout.

To force a mode regardless of Windows version, set env MPV_HRT:
- "always":  the old behavior - hires timers as long as mpv runs.
- "perwait": sets 1ms timer resolution if timeout <= 50ms.
- "never":   don't use timeBeginPeriod at all.

It was observed that on Windows 10 we lose about 0.5ms accuracy of
timeouts with "perwait" mode (acceptable), but otherwise it works
well for continuous timeouts (one after the other) and random ones.

On Windows 7 with "perwait": continous timeouts are accurate, but
random timeouts (after some time without timeouts) have bad
accuracy - roughly 16ms resolution instead of the requested 1ms.

Windows 8 was not tested, so to err on the side of caution, we keep
the legacy behavior "always" by default.
2021-09-21 00:45:08 +10:00
Pedro Pombeiro 4637b029cd Universal Windows Plaform (UWP) support
libmpv only. Some things are still missing.

Heavily reworked.

Signed-off-by: wm4 <wm4@nowhere>
2017-06-29 10:36:16 +02:00
wm4 cf0bce19bb osdep/timer*: change license to LGPL
All authors have agreed, with the following exceptions:

e68d7f6858: wight wasn't asked (I think...), but even if he modified the
patch he applied, all code added by it was removed again later.

cb7768f9bb: nick could not be reached, but the declarations he added as
well as the full timer.c file were deleted again in cff81fe498 and
f800a42e45 (did it really take 6 years to remove unused declarations?).

ffaf4af230: it looks like this person wasn't contacted, but the code
added was removed again in f544bcf105.
2017-05-05 12:35:57 +02:00
James Ross-Gowan f544bcf105 win32: use QueryPerformanceCounter for timing
clock_gettime is implemented in winpthreads, so it's unavailable when
mpv is compiled with its internal pthreads implementation. This makes
mp_raw_time_us fall back to gettimeofday(), which can cause an assert
failure in mp_add_timeout() when the system clock is changed. Use
QueryPerformanceCounter instead.

The clock_gettime(CLOCK_MONOTONIC) implementation in winpthreads uses
QueryPerformanceCounter anyway, so there shouldn't be any change in
behaviour.
2015-07-04 15:54:14 +02:00
wm4 ac879545ad win32: do not call timeEndPeriod(1) on termination
This was called for formal reasons at best. The way it does this is
somewhat dangerous, because if libmpv is unloaded as DLL, this would
attempt to call a dangling function pointer.

(No, we don't want an extra DllMain entrypoint just for win32.)
2015-05-21 22:52:14 +02:00
Marcin Kurczewski f43017bfe9 Update license headers
Signed-off-by: wm4 <wm4@nowhere>
2015-04-13 12:10:01 +02:00
Hiltjo Posthuma ffaf4af230 win32: use monotonic clock on windows if possible 2015-01-19 19:01:08 +01:00
wm4 c6166ff448 timer: init only once
This avoids trouble if another mpv instance is initialized in the same
process.

Since timeBeginPeriod/timeEndPeriod are hereby not easily matched
anymore, use an atexit() handler to call timeEndPeriod, so that we
can be sure these calls are matched, even if we allow multiple
initializations later when introducing the client API.
2014-02-10 01:12:34 +01:00
wm4 561aab2d77 timer: use gettimeofday() on Windows
MinGW-w64 emulates this via GetSystemTimeAsFileTime(), which has
supposedly the best and most stable timer source out of most others.

http://mingw-w64.svn.sourceforge.net/viewvc/mingw-w64/trunk/mingw-w64-crt/misc/gettimeofday.c
2013-05-26 16:44:20 +02:00
wm4 81439c5f35 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.
2013-05-26 16:44:20 +02:00
wm4 c5e2120e15 timer: remove timer_name
This was unreferenced and useless.
2012-09-07 16:06:36 +02:00
Uoti Urpala 0eb321bf2c Remove trailing whitespace from most files 2009-07-07 02:34:35 +03:00
Uoti Urpala e0172b96e3 Merge svn changes up to r28862 2009-03-07 01:04:41 +02:00
diego 86a2eadf4c Add standard license headers to files.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28779 b3059339-0415-0410-9bf9-f77b7e298cf2
2009-03-01 13:13:25 +00:00
Uoti Urpala 9bcd12fdf5 Merge svn changes up to r28310
The libdvdread4 and libdvdnav directories, which are externals in the
svn repository, are at least for now not included in any form. I added
configure checks to automatically disable internal libdvdread and
libdvdnav if the corresponding directories are not present; if they're
added manually then things work the same as in svn.
2009-01-15 05:57:31 +02:00
uau 453198ae1b timer-win2.c: Fix "voi" (void) typo breaking Windows compilation
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28269 b3059339-0415-0410-9bf9-f77b7e298cf2
2009-01-05 18:05:34 +00:00
diego 824abb5a65 Add missing 'void' keyword to parameterless function declarations.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28267 b3059339-0415-0410-9bf9-f77b7e298cf2
2009-01-05 14:48:03 +00:00
Uoti Urpala eaf7857b7f timers: Remove GetRelativeTime()
Move the code calculating time delta since last query out of the
platform-specific drivers and into mplayer.c. The platform-specific
drivers now return absolute values only.

The way the code in timer-darwin.c uses doubles in wrapping arithmetic
looks questionable and this change might make problems in it more
visible.
2008-04-28 12:18:45 +03:00
Uoti Urpala c693b77e93 osdep: Change timer_name to a saner type
timer_name was a (non-const) pointer to a const char array. Make the
symbol the array itself.
2008-04-28 12:16:13 +03:00
wight e68d7f6858 Native darwin timer update.
Patch by Dan Christiansen <danchr@daimi.au.dk>


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@12955 b3059339-0415-0410-9bf9-f77b7e298cf2
2004-08-04 15:48:43 +00:00
faust3 01c75bcd70 Sleep(0) != usleep(0), bugreport by Paul-Kenji Cahier
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@11481 b3059339-0415-0410-9bf9-f77b7e298cf2
2003-11-16 15:11:52 +00:00
faust3 0015a97826 alternative timer and glob emulation code for mingw32 port
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9984 b3059339-0415-0410-9bf9-f77b7e298cf2
2003-04-25 10:00:18 +00:00