History

js: support mp.create_osd_overlay (match 07287262)

The legacy mp.set_osd_ass(...) is still supported (but also still undocumented) as a wrapper for the new mp.create_osd_overlay(...).

Avi Halachmi (:avih) committed 6 years ago

Commit 9f2fda71 parent 5a74bf53 files · +57 −23Browse files

Unified · Split

3 files
  1. DOCS/man/javascript.rst +4 −0
  2. player/javascript.c +0 −23
  3. player/javascript/defaults.js +53 −0
DOCS/man/javascript.rst+4−0
@@ -153,6 +153,10 @@ success, ``fn`` is called always a-sync, ``error`` is empty string on success. · 152 unmodified lines
153 153
154``mp.unregister_script_message(name)``154``mp.unregister_script_message(name)``
155 155
156``mp.create_osd_overlay(format)``
157
158``mp.get_osd_size()`` (returned object has properties: width, height, aspect)
159
156``mp.msg.log(level, ...)``160``mp.msg.log(level, ...)``
157 161
158``mp.msg.fatal(...)``162``mp.msg.fatal(...)``
player/javascript.c+0−23
@@ -732,17 +732,6 @@ static void script_get_time_ms(js_State *J) · 731 unmodified lines
732 js_pushnumber(J, mpv_get_time_us(jclient(J)) / (double)(1000));732 js_pushnumber(J, mpv_get_time_us(jclient(J)) / (double)(1000));
733}733}
734 734
735static void script_set_osd_ass(js_State *J)
736{
737 struct script_ctx *ctx = jctx(J);
738 int res_x = jsL_checkint(J, 1);
739 int res_y = jsL_checkint(J, 2);
740 const char *text = js_tostring(J, 3);
741 //osd_set_external(ctx->mpctx->osd, ctx->client, res_x, res_y, (char *)text);
742 mp_wakeup_core(ctx->mpctx);
743 push_success(J);
744}
745
746// push object with properties names (NULL terminated) with respective vals735// push object with properties names (NULL terminated) with respective vals
747static void push_nums_obj(js_State *J, const char * const names[],736static void push_nums_obj(js_State *J, const char * const names[],
748 const double vals[])737 const double vals[])
@@ -754,16 +743,6 @@ static void push_nums_obj(js_State *J, const char * const names[], · 5 unmodified lines
754 }743 }
755}744}
756 745
757// args: none, return: object with properties width, height, aspect
758static void script_get_osd_size(js_State *J)
759{
760 struct mp_osd_res r = osd_get_vo_res(jctx(J)->mpctx->osd);
761 double ar = 1.0 * r.w / MPMAX(r.h, 1) / (r.display_par ? r.display_par : 1);
762 const char * const names[] = {"width", "height", "aspect", NULL};
763 const double vals[] = {r.w, r.h, ar};
764 push_nums_obj(J, names, vals);
765}
766
767// args: none, return: object with properties top, bottom, left, right746// args: none, return: object with properties top, bottom, left, right
768static void script_get_osd_margins(js_State *J)747static void script_get_osd_margins(js_State *J)
769{748{
@@ -1258,8 +1237,6 @@ static const struct fn_entry main_fns[] = { · 488 unmodified lines
1258 FN_ENTRY(get_wakeup_pipe, 0),1237 FN_ENTRY(get_wakeup_pipe, 0),
1259 FN_ENTRY(_hook_add, 3),1238 FN_ENTRY(_hook_add, 3),
1260 FN_ENTRY(_hook_continue, 1),1239 FN_ENTRY(_hook_continue, 1),
1261 FN_ENTRY(set_osd_ass, 3),
1262 FN_ENTRY(get_osd_size, 0),
1263 FN_ENTRY(get_osd_margins, 0),1240 FN_ENTRY(get_osd_margins, 0),
1264 FN_ENTRY(get_mouse_pos, 0),1241 FN_ENTRY(get_mouse_pos, 0),
1265 FN_ENTRY(input_set_section_mouse_area, 5),1242 FN_ENTRY(input_set_section_mouse_area, 5),
player/javascript/defaults.js+53−0
@@ -192,6 +192,59 @@ mp.utils.shared_script_property_set = shared_script_property_set; · 191 unmodified lines
192mp.utils.shared_script_property_get = shared_script_property_get;192mp.utils.shared_script_property_get = shared_script_property_get;
193mp.utils.shared_script_property_observe = shared_script_property_observe;193mp.utils.shared_script_property_observe = shared_script_property_observe;
194 194
195// osd-ass
196var next_assid = 1;
197mp.create_osd_overlay = function create_osd_overlay(format) {
198 return {
199 format: format || "ass-events",
200 id: next_assid++,
201 data: "",
202 res_x: 0,
203 res_y: 720,
204 z: 0,
205
206 update: function ass_update() {
207 mp.command_native({
208 name: "osd-overlay",
209 format: this.format,
210 id: this.id,
211 data: this.data,
212 res_x: Math.round(this.res_x),
213 res_y: Math.round(this.res_y),
214 z: this.z,
215 });
216 return mp.last_error() ? undefined : true;
217 },
218
219 remove: function ass_remove() {
220 mp.command_native({
221 name: "osd-overlay",
222 id: this.id,
223 format: "none",
224 data: "",
225 });
226 return mp.last_error() ? undefined : true;
227 },
228 };
229}
230
231// osd-ass legacy API
232mp.set_osd_ass = function set_osd_ass(res_x, res_y, data) {
233 if (!mp._legacy_overlay)
234 mp._legacy_overlay = mp.create_osd_overlay("ass-events");
235 mp._legacy_overlay.res_x = res_x;
236 mp._legacy_overlay.res_y = res_y;
237 mp._legacy_overlay.data = data;
238 return mp._legacy_overlay.update();
239}
240
241mp.get_osd_size = function get_osd_size() {
242 var w = mp.get_property_number("osd-width", 0),
243 h = mp.get_property_number("osd-height", 0),
244 par = mp.get_property_number("osd-par", 0);
245 return {width: w, height: h, aspect: w / (h || 1) / (par || 1)};
246}
247
195/**********************************************************************248/**********************************************************************
196 * key bindings249 * key bindings
197 *********************************************************************/250 *********************************************************************/

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t