summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
Diffstat (limited to 'player')
-rw-r--r--player/client.c2
-rw-r--r--player/command.c32
-rw-r--r--player/javascript.c2
-rw-r--r--player/lua.c27
-rw-r--r--player/lua/defaults.lua59
5 files changed, 93 insertions, 29 deletions
diff --git a/player/client.c b/player/client.c
index e44f3cacea..97e43a15ce 100644
--- a/player/client.c
+++ b/player/client.c
@@ -457,7 +457,7 @@ static void mp_destroy_client(mpv_handle *ctx, bool terminate)
// causes a crash, block until all asynchronous requests were served.
mpv_wait_async_requests(ctx);
- osd_set_external(mpctx->osd, ctx, 0, 0, NULL);
+ osd_set_external_remove_owner(mpctx->osd, ctx);
mp_input_remove_sections_by_owner(mpctx->input, ctx->name);
pthread_mutex_lock(&clients->lock);
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),
diff --git a/player/javascript.c b/player/javascript.c
index d478a326a8..5981eb848d 100644
--- a/player/javascript.c
+++ b/player/javascript.c
@@ -738,7 +738,7 @@ static void script_set_osd_ass(js_State *J)
int res_x = jsL_checkint(J, 1);
int res_y = jsL_checkint(J, 2);
const char *text = js_tostring(J, 3);
- osd_set_external(ctx->mpctx->osd, ctx->client, res_x, res_y, (char *)text);
+ //osd_set_external(ctx->mpctx->osd, ctx->client, res_x, res_y, (char *)text);
mp_wakeup_core(ctx->mpctx);
push_success(J);
}
diff --git a/player/lua.c b/player/lua.c
index 69977dfd42..aec9908b69 100644
--- a/player/lua.c
+++ b/player/lua.c
@@ -998,31 +998,6 @@ static int script_raw_abort_async_command(lua_State *L)
return 0;
}
-static int script_set_osd_ass(lua_State *L)
-{
- struct script_ctx *ctx = get_ctx(L);
- int res_x = luaL_checkinteger(L, 1);
- int res_y = luaL_checkinteger(L, 2);
- const char *text = luaL_checkstring(L, 3);
- if (!text[0])
- text = " "; // force external OSD initialization
- osd_set_external(ctx->mpctx->osd, ctx->client, res_x, res_y, (char *)text);
- mp_wakeup_core(ctx->mpctx);
- return 0;
-}
-
-static int script_get_osd_size(lua_State *L)
-{
- struct MPContext *mpctx = get_mpctx(L);
- struct mp_osd_res vo_res = osd_get_vo_res(mpctx->osd);
- double aspect = 1.0 * vo_res.w / MPMAX(vo_res.h, 1) /
- (vo_res.display_par ? vo_res.display_par : 1);
- lua_pushnumber(L, vo_res.w);
- lua_pushnumber(L, vo_res.h);
- lua_pushnumber(L, aspect);
- return 3;
-}
-
static int script_get_osd_margins(lua_State *L)
{
struct MPContext *mpctx = get_mpctx(L);
@@ -1275,8 +1250,6 @@ static const struct fn_entry main_fns[] = {
FN_ENTRY(set_property_native),
FN_ENTRY(raw_observe_property),
FN_ENTRY(raw_unobserve_property),
- FN_ENTRY(set_osd_ass),
- FN_ENTRY(get_osd_size),
FN_ENTRY(get_osd_margins),
FN_ENTRY(get_mouse_pos),
FN_ENTRY(get_time),
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)