summaryrefslogtreecommitdiffstats
path: root/player/lua/defaults.lua
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-12-23 11:40:27 +0100
committerwm4 <wm4@nowhere>2019-12-23 11:44:24 +0100
commit07287262513c0d1ea46b7beaf100e73f2008295f (patch)
tree01548db64854e14caf2f0985fde8696488e57247 /player/lua/defaults.lua
parent96932fe77c912f86d8fc51e073b4fd26a124a1fb (diff)
downloadmpv-07287262513c0d1ea46b7beaf100e73f2008295f.tar.bz2
mpv-07287262513c0d1ea46b7beaf100e73f2008295f.tar.xz
client API, lua: add new API for setting OSD overlays
Lua scripting has an undocumented mp.set_osd_ass() function, which is used by osc.lua and console.lua. Apparently, 3rd party scripts also use this. It's probably time to make this a public API. The Lua implementation just bypassed the libmpv API. To make it usable by any type of client, turn it into a command, "osd-overlay". There's already a "overlay-add". Ignore it (although the manpage admits guiltiness). I don't really want to deal with that old command. Its main problem is that it uses global IDs, while I'd like to avoid that scripts mess with each others overlays (whether that is accidentally or intentionally). Maybe "overlay-add" can eventually be merged into "osd-overlay", but I'm too lazy to do that now. Scripting now uses the commands. There is a helper to manage OSD overlays. The helper is very "thin"; I only want to force script authors to use the ID allocation, which may help with putting multiple scripts into a single .lua file without causing conflicts (basically, avoiding singletons within a script's environment). The old set_osd_ass() is emulated with the new API. The JS scripting wrapper also provides a set_osd_ass() function, which calls internal mpv API. Comment that part (to keep it compiling), but I'm leaving it to @avih to finish the change.
Diffstat (limited to 'player/lua/defaults.lua')
-rw-r--r--player/lua/defaults.lua59
1 files changed, 59 insertions, 0 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua
index ba59653828..22ffa086d1 100644
--- a/player/lua/defaults.lua
+++ b/player/lua/defaults.lua
@@ -589,6 +589,65 @@ function mp.abort_async_command(t)
end
end
+local overlay_mt = {}
+overlay_mt.__index = overlay_mt
+local overlay_new_id = 0
+
+function mp.create_osd_overlay(format)
+ overlay_new_id = overlay_new_id + 1
+ local overlay = {
+ format = format,
+ id = overlay_new_id,
+ data = "",
+ res_x = 0,
+ res_y = 720,
+ }
+ setmetatable(overlay, overlay_mt)
+ return overlay
+end
+
+function overlay_mt.update(ov)
+ local cmd = {}
+ for k, v in pairs(ov) do
+ cmd[k] = v
+ end
+ cmd.name = "osd-overlay"
+ mp.command_native(cmd)
+end
+
+function overlay_mt.remove(ov)
+ mp.command_native {
+ name = "osd-overlay",
+ id = ov.id,
+ format = "none",
+ data = "",
+ }
+end
+
+-- legacy API
+function mp.set_osd_ass(res_x, res_y, data)
+ if not mp._legacy_overlay then
+ mp._legacy_overlay = mp.create_osd_overlay("ass-events")
+ end
+ mp._legacy_overlay.res_x = res_x
+ mp._legacy_overlay.res_y = res_y
+ mp._legacy_overlay.data = data
+ mp._legacy_overlay:update()
+end
+
+function mp.get_osd_size()
+ local w = mp.get_property_number("osd-width", 0)
+ local h = mp.get_property_number("osd-height", 0)
+ local par = mp.get_property_number("osd-par", 0)
+ if par == 0 then
+ par = 1
+ end
+
+ local aspect = 1.0 * w / math.max(h) / par
+ return w, h, aspect
+end
+
+
local mp_utils = package.loaded["mp.utils"]
function mp_utils.format_table(t, set)