mirror of
https://github.com/mpv-player/mpv
synced 2025-03-20 18:28:01 +00:00
timer-linux: fallback to CLOCK_MONOTONIC instead of timespec_get
CLOCK_MONOTONIC_RAW is linux-specific (macOS later supported it but it has its own timer code) and not neccessarily available everywhere like on BSDs. It makes sense to prefer it because mpv does a lot of measurements at small intervals (e.g. every frame) so theoretically it should be more accurate. However if the OS doesn't have it, fallback to CLOCK_MONOTONIC instead which is almost exactly the same and very widely supported across unix-like systems. This clock is technically optional according to POSIX, but any half-decent OS supports it anyway (sorry Solaris users). As a benefit, we now know that the clock from mp_time is always monotonic.
This commit is contained in:
parent
bc3e850168
commit
891efca9d7
@ -35,11 +35,12 @@ void mp_sleep_ns(int64_t ns)
|
||||
uint64_t mp_raw_time_ns(void)
|
||||
{
|
||||
struct timespec tp = {0};
|
||||
int ret = -1;
|
||||
#if defined(CLOCK_MONOTONIC_RAW)
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
|
||||
#else
|
||||
timespec_get(&tp, TIME_UTC);
|
||||
ret = clock_gettime(CLOCK_MONOTONIC_RAW, &tp);
|
||||
#endif
|
||||
if (ret)
|
||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||
return MP_TIME_S_TO_NS(tp.tv_sec) + tp.tv_nsec;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user