summaryrefslogtreecommitdiffstats
path: root/player/lua/defaults.lua
diff options
context:
space:
mode:
Diffstat (limited to 'player/lua/defaults.lua')
-rw-r--r--player/lua/defaults.lua36
1 files changed, 29 insertions, 7 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index 920ee425aa..0643c0b1d9 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -330,9 +330,11 @@ function mp.get_next_timeout()
return timer.next_deadline - now
end
--- Run timers that have met their deadline.
--- Return: next absolute time a timer expires as number, or nil if no timers
+-- Run timers that have met their deadline at the time of invocation.
+-- Return: time>0 in seconds till the next due timer, 0 if there are due timers
+-- (aborted to avoid infinite loop), or nil if no timers
local function process_timers()
+ local t0 = nil
while true do
local timer = get_next_timer()
if not timer then
@@ -343,6 +345,14 @@ local function process_timers()
if wait > 0 then
return wait
else
+ if not t0 then
+ t0 = now -- first due callback: always executes, remember t0
+ elseif timer.next_deadline > t0 then
+ -- don't block forever with slow callbacks and endless timers.
+ -- we'll continue right after checking mpv events.
+ return 0
+ end
+
if timer.oneshot then
timer:kill()
else
@@ -518,12 +528,20 @@ function mp.dispatch_events(allow_wait)
local wait = 0
if not more_events then
wait = process_timers() or 1e20 -- infinity for all practical purposes
- for _, handler in ipairs(idle_handlers) do
- handler()
+ 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.
- mp.resume_all()
if allow_wait ~= true then
return
end
@@ -747,6 +765,10 @@ function mp_utils.getcwd()
return mp.get_property("working-directory")
end
+function mp_utils.getpid()
+ return mp.get_property_number("pid")
+end
+
function mp_utils.format_bytes_humanized(b)
local d = {"Bytes", "KiB", "MiB", "GiB", "TiB", "PiB"}
local i = 1