diff --git a/DOCS/man/javascript.rst b/DOCS/man/javascript.rst index db12b65a09..75db7cd99e 100644 --- a/DOCS/man/javascript.rst +++ b/DOCS/man/javascript.rst @@ -153,6 +153,10 @@ success, ``fn`` is called always a-sync, ``error`` is empty string on success. ``mp.unregister_script_message(name)`` +``mp.create_osd_overlay(format)`` + +``mp.get_osd_size()`` (returned object has properties: width, height, aspect) + ``mp.msg.log(level, ...)`` ``mp.msg.fatal(...)`` diff --git a/player/javascript.c b/player/javascript.c index 5981eb848d..fa3b09c7f3 100644 --- a/player/javascript.c +++ b/player/javascript.c @@ -732,17 +732,6 @@ static void script_get_time_ms(js_State *J) js_pushnumber(J, mpv_get_time_us(jclient(J)) / (double)(1000)); } -static void script_set_osd_ass(js_State *J) -{ - struct script_ctx *ctx = jctx(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); - mp_wakeup_core(ctx->mpctx); - push_success(J); -} - // push object with properties names (NULL terminated) with respective vals static void push_nums_obj(js_State *J, const char * const names[], const double vals[]) @@ -754,16 +743,6 @@ static void push_nums_obj(js_State *J, const char * const names[], } } -// args: none, return: object with properties width, height, aspect -static void script_get_osd_size(js_State *J) -{ - struct mp_osd_res r = osd_get_vo_res(jctx(J)->mpctx->osd); - double ar = 1.0 * r.w / MPMAX(r.h, 1) / (r.display_par ? r.display_par : 1); - const char * const names[] = {"width", "height", "aspect", NULL}; - const double vals[] = {r.w, r.h, ar}; - push_nums_obj(J, names, vals); -} - // args: none, return: object with properties top, bottom, left, right static void script_get_osd_margins(js_State *J) { @@ -1258,8 +1237,6 @@ static const struct fn_entry main_fns[] = { FN_ENTRY(get_wakeup_pipe, 0), FN_ENTRY(_hook_add, 3), FN_ENTRY(_hook_continue, 1), - FN_ENTRY(set_osd_ass, 3), - FN_ENTRY(get_osd_size, 0), FN_ENTRY(get_osd_margins, 0), FN_ENTRY(get_mouse_pos, 0), FN_ENTRY(input_set_section_mouse_area, 5), diff --git a/player/javascript/defaults.js b/player/javascript/defaults.js index 2ae3fe74d0..18edab35b7 100644 --- a/player/javascript/defaults.js +++ b/player/javascript/defaults.js @@ -192,6 +192,59 @@ mp.utils.shared_script_property_set = shared_script_property_set; mp.utils.shared_script_property_get = shared_script_property_get; mp.utils.shared_script_property_observe = shared_script_property_observe; +// osd-ass +var next_assid = 1; +mp.create_osd_overlay = function create_osd_overlay(format) { + return { + format: format || "ass-events", + id: next_assid++, + data: "", + res_x: 0, + res_y: 720, + z: 0, + + update: function ass_update() { + mp.command_native({ + name: "osd-overlay", + format: this.format, + id: this.id, + data: this.data, + res_x: Math.round(this.res_x), + res_y: Math.round(this.res_y), + z: this.z, + }); + return mp.last_error() ? undefined : true; + }, + + remove: function ass_remove() { + mp.command_native({ + name: "osd-overlay", + id: this.id, + format: "none", + data: "", + }); + return mp.last_error() ? undefined : true; + }, + }; +} + +// osd-ass legacy API +mp.set_osd_ass = function set_osd_ass(res_x, res_y, data) { + if (!mp._legacy_overlay) + mp._legacy_overlay = mp.create_osd_overlay("ass-events"); + mp._legacy_overlay.res_x = res_x; + mp._legacy_overlay.res_y = res_y; + mp._legacy_overlay.data = data; + return mp._legacy_overlay.update(); +} + +mp.get_osd_size = function get_osd_size() { + var w = mp.get_property_number("osd-width", 0), + h = mp.get_property_number("osd-height", 0), + par = mp.get_property_number("osd-par", 0); + return {width: w, height: h, aspect: w / (h || 1) / (par || 1)}; +} + /********************************************************************** * key bindings *********************************************************************/