summaryrefslogtreecommitdiffstats
path: root/player/lua
diff options
context:
space:
mode:
Diffstat (limited to 'player/lua')
-rw-r--r--player/lua/defaults.lua62
-rw-r--r--player/lua/stats.lua11
2 files changed, 66 insertions, 7 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index 8f91899bc2..523b649b8c 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -525,6 +525,41 @@ function mp.add_hook(name, pri, cb)
mp.raw_hook_add(id, name, pri - 50)
end
+local async_call_table = {}
+local async_next_id = 1
+
+function mp.command_native_async(node, cb)
+ local id = async_next_id
+ async_next_id = async_next_id + 1
+ local res, err = mp.raw_command_native_async(id, node)
+ if not res then
+ cb(false, nil, err)
+ return res, err
+ end
+ local t = {cb = cb, id = id}
+ async_call_table[id] = t
+ return t
+end
+
+mp.register_event("command-reply", function(ev)
+ local id = tonumber(ev.id)
+ local t = async_call_table[id]
+ local cb = t.cb
+ t.id = nil
+ async_call_table[id] = nil
+ if ev.error then
+ cb(false, nil, ev.error)
+ else
+ cb(true, ev.result, nil)
+ end
+end)
+
+function mp.abort_async_command(t)
+ if t.id ~= nil then
+ mp.raw_abort_async_command(t.id)
+ end
+end
+
local mp_utils = package.loaded["mp.utils"]
function mp_utils.format_table(t, set)
@@ -593,4 +628,31 @@ function mp_utils.format_bytes_humanized(b)
return string.format("%0.2f %s", b, d[i] and d[i] or "*1024^" .. (i-1))
end
+function mp_utils.subprocess(t)
+ local cmd = {}
+ cmd.name = "subprocess"
+ cmd.capture_stdout = true
+ for k, v in pairs(t) do
+ if k == "cancellable" then
+ k = "playback_only"
+ elseif k == "max_size" then
+ k = "capture_size"
+ end
+ cmd[k] = v
+ end
+ local res, err = mp.command_native(cmd)
+ if res == nil then
+ -- an error usually happens only if parsing failed (or no args passed)
+ res = {error_string = err, status = -1}
+ end
+ if res.error_string ~= "" then
+ res.error = res.error_string
+ end
+ return res
+end
+
+function mp_utils.subprocess_detached(t)
+ mp.commandv("run", unpack(t.args))
+end
+
return {}
diff --git a/player/lua/stats.lua b/player/lua/stats.lua
index 504e54636e..db3df01c6d 100644
--- a/player/lua/stats.lua
+++ b/player/lua/stats.lua
@@ -448,13 +448,10 @@ local function add_file(s)
demuxer_cache = 0
end
local demuxer_secs = mp.get_property_number("demuxer-cache-duration", 0)
- local stream_cache = mp.get_property_number("cache-used", 0) * 1024 -- returns KiB
- if stream_cache + demuxer_cache + demuxer_secs > 0 then
- append(s, utils.format_bytes_humanized(stream_cache + demuxer_cache), {prefix="Total Cache:"})
- append(s, utils.format_bytes_humanized(demuxer_cache), {prefix="(Demuxer:",
- suffix=",", nl="", no_prefix_markup=true, indent=o.prefix_sep})
- append(s, format("%.1f", demuxer_secs), {suffix=" sec)", nl="", indent="",
- no_prefix_markup=true})
+ if demuxer_cache + demuxer_secs > 0 then
+ append(s, utils.format_bytes_humanized(demuxer_cache), {prefix="Total Cache:"})
+ append(s, format("%.1f", demuxer_secs), {prefix="(", suffix=" sec)", nl="",
+ no_prefix_markup=true, prefix_sep="", indent=o.prefix_sep})
local speed = mp.get_property_number("cache-speed", 0)
if speed > 0 then
append(s, utils.format_bytes_humanized(speed) .. "/s", {prefix="Speed:", nl="",