diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2021-06-22 16:06:36 +0300 |
---|---|---|
committer | avih <avih@users.noreply.github.com> | 2021-06-23 23:47:08 +0300 |
commit | 5b40db385a7b4239e2e78d67f1098209c8592202 (patch) | |
tree | da172c718693534066529c460621509e9eb0ee52 /player/lua | |
parent | f73814b180ad4616ac1d21a729eb9dda4af040cc (diff) | |
download | mpv-5b40db385a7b4239e2e78d67f1098209c8592202.tar.bz2 mpv-5b40db385a7b4239e2e78d67f1098209c8592202.tar.xz |
lua: idle observers: ensure timers are up-to-date
This fixes two issues, both of which resulted from the timers-wait
period not being re-calculated after idle-observers were executed:
- If timers were added from an idle observer then they could fire long
after they were due (only when/if the next mpv event arrives).
- Idle observers don't execute in zero time, and the wait period for
the next timer was implicitly extended by the idle observers
execution time (because it was calculated before the idle observers).
This commit ensures that if idle-observers were executed, then the
timers wait period is re-calculated, which solves both issues.
Diffstat (limited to 'player/lua')
-rw-r--r-- | player/lua/defaults.lua | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index 5e56c4fb4e..a1deca28ba 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -528,9 +528,18 @@ function mp.dispatch_events(allow_wait) if not more_events then wait = process_timers() or 1e20 -- infinity for all practical purposes if wait ~= 0 then + local idle_called = nil for _, handler in ipairs(idle_handlers) do + idle_called = true handler() end + if idle_called then + -- handlers don't complete in 0 time, and may modify timers + wait = mp.get_next_timeout() or 1e20 + if wait < 0 then + wait = 0 + end + end end -- Resume playloop - important especially if an error happened while -- suspended, and the error was handled, but no resume was done. |