mirror of
https://github.com/mpv-player/mpv
synced 2024-12-22 06:42:03 +00:00
timer: fix a corner case on clock changes
It's conceivable that the OS time source is subject to clock changes. The time could jump back to before when mpv was started, which would cause mp_time_us() to return values smaller than 1. This is unexpected by the code and could trigger assertions. If there's no monotonic time source there's not much we can do anyway, so just sanitize the return value. It will cause strange behavior until the "lost" time offset has passed, but if you make such huge changes to the system clock while everything is running, you're asking for trouble anyway. (Normally we try to get a monotonic time source, though. This problem sometimes happened on Windows when compiled without winpthreads, when the code was falling back to gettimeofday(). This was already fixed by always using another method.)
This commit is contained in:
parent
f544bcf105
commit
5728295dab
@ -48,7 +48,10 @@ void mp_time_init(void)
|
||||
|
||||
int64_t mp_time_us(void)
|
||||
{
|
||||
return mp_raw_time_us() - raw_time_offset;
|
||||
int64_t r = mp_raw_time_us() - raw_time_offset;
|
||||
if (r < MP_START_TIME)
|
||||
r = MP_START_TIME;
|
||||
return r;
|
||||
}
|
||||
|
||||
double mp_time_sec(void)
|
||||
|
Loading…
Reference in New Issue
Block a user