summaryrefslogtreecommitdiffstats
path: root/player/command.c
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/command.c
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/command.c')
-rw-r--r--player/command.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index 86715c8896..a230ad460c 100644
--- a/player/command.c
+++ b/player/command.c
@@ -4085,6 +4085,25 @@ static void overlay_uninit(struct MPContext *mpctx)
mp_image_unrefp(&cmd->overlay_osd[n].packed);
}
+static void cmd_osd_overlay(void *p)
+{
+ struct mp_cmd_ctx *cmd = p;
+ struct MPContext *mpctx = cmd->mpctx;
+
+ struct osd_external_ass ov = {
+ .owner = cmd->cmd->sender,
+ .id = cmd->args[0].v.i64,
+ .format = cmd->args[1].v.i,
+ .data = cmd->args[2].v.s,
+ .res_x = cmd->args[3].v.i,
+ .res_y = cmd->args[4].v.i,
+ .z = cmd->args[5].v.i,
+ };
+
+ osd_set_external(mpctx->osd, &ov);
+ mp_wakeup_core(mpctx);
+}
+
static struct track *find_track_with_url(struct MPContext *mpctx, int type,
const char *url)
{
@@ -5877,6 +5896,19 @@ const struct mp_cmd_def mp_cmds[] = {
OPT_INT("stride", v.i, 0), }},
{ "overlay-remove", cmd_overlay_remove, { OPT_INT("id", v.i, 0) } },
+ { "osd-overlay", cmd_osd_overlay,
+ {
+ OPT_INT64("id", v.i64, 0),
+ OPT_CHOICE("format", v.i, 0, ({"none", 0},
+ {"ass-events", 1})),
+ OPT_STRING("data", v.s, 0),
+ OPT_INT("res_x", v.i, 0, OPTDEF_INT(0)),
+ OPT_INT("res_y", v.i, 0, OPTDEF_INT(720)),
+ OPT_INT("z", v.i, 0, OPTDEF_INT(0)),
+ },
+ .is_noisy = true,
+ },
+
{ "write-watch-later-config", cmd_write_watch_later_config },
{ "hook-add", cmd_hook_add, { OPT_STRING("arg0", v.s, 0),