diff options
author | wm4 <wm4@nowhere> | 2015-07-04 17:24:10 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-07-04 17:24:10 +0200 |
commit | 5728295daba6abf7cb47ff5f27e9795a7ce36cce (patch) | |
tree | 6bc406d1dcf3a9832d1f6ccdcdb905c6a1332f20 /osdep | |
parent | f544bcf1056e0acee483a951408160fa2d39ffdd (diff) |
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.)
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/timer.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/osdep/timer.c b/osdep/timer.c index 053d12dd7c..32f0172b0b 100644 --- a/osdep/timer.c +++ b/osdep/timer.c @@ -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) |