summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-09-26 00:41:14 +0200
committerwm4 <wm4@nowhere>2013-09-26 01:28:58 +0200
commit6048f87e3c07d03df8a59da58c81608c5375f6dc (patch)
treebe79bfe51b5268f2c1494f456fa72538c391d54f /sub
parentb0cc3c2cf4e342e33300adaea4a98565ad866e22 (diff)
downloadmpv-6048f87e3c07d03df8a59da58c81608c5375f6dc.tar.bz2
mpv-6048f87e3c07d03df8a59da58c81608c5375f6dc.tar.xz
Add initial Lua scripting support
This is preliminary. There are still tons of issues, and any aspect of scripting may change in the future. I decided to merge this (preliminary) work now because it makes it easier to develop it, not because it's done. lua.rst is clear enough about it (plus some sarcasm). This requires linking to Lua. Lua has no official pkg-config file, but there are distribution specific .pc files, all with different names. Adding a non-pkg-config based configure test was considered, but we'd rather not. One major complication is that libquvi links against Lua too, and if the Lua version is different from mpv's, you will get a crash as soon as libquvi uses Lua. (libquvi by design always runs when a file is opened.) I would consider this the problem of distros and whoever builds mpv, but to make things easier for users, we add a terrible runtime test to the configure script, which probes whether libquvi will crash. This is disabled when cross-compiling, but in that case we hope the user knows what he is doing.
Diffstat (limited to 'sub')
-rw-r--r--sub/osd_dummy.c7
-rw-r--r--sub/osd_libass.c42
-rw-r--r--sub/sub.c11
-rw-r--r--sub/sub.h10
4 files changed, 70 insertions, 0 deletions
diff --git a/sub/osd_dummy.c b/sub/osd_dummy.c
index 782ce21942..a330c63982 100644
--- a/sub/osd_dummy.c
+++ b/sub/osd_dummy.c
@@ -23,3 +23,10 @@ void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
{
*out_imgs = (struct sub_bitmaps) {0};
}
+
+void osd_object_get_resolution(struct osd_state *osd, struct osd_object *obj,
+ int *out_w, int *out_h)
+{
+ *out_w = 0;
+ *out_h = 0;
+}
diff --git a/sub/osd_libass.c b/sub/osd_libass.c
index 36e2a0ca0f..45edbc7cc8 100644
--- a/sub/osd_libass.c
+++ b/sub/osd_libass.c
@@ -347,6 +347,38 @@ static void update_progbar(struct osd_state *osd, struct osd_object *obj)
ass_draw_reset(d);
}
+static void update_external(struct osd_state *osd, struct osd_object *obj)
+{
+ create_osd_ass_track(osd, obj);
+ clear_obj(obj);
+
+ if (osd->external_res_x < 1 || osd->external_res_y < 1)
+ return;
+
+ ASS_Track *track = obj->osd_track;
+
+ if (track->PlayResX != osd->external_res_x ||
+ track->PlayResY != osd->external_res_y)
+ {
+ track->PlayResX = osd->external_res_x;
+ track->PlayResY = osd->external_res_y;
+ // Force libass to clear its internal cache - it doesn't check for
+ // PlayRes changes itself.
+ ass_set_frame_size(osd->osd_render, 1, 1);
+ }
+
+ bstr t = bstr0(osd->external);
+ while (t.len) {
+ bstr line;
+ bstr_split_tok(t, "\n", &line, &t);
+ if (line.len) {
+ char *tmp = bstrdup0(NULL, line);
+ add_osd_ass_event(obj->osd_track, tmp);
+ talloc_free(tmp);
+ }
+ }
+}
+
static void update_sub(struct osd_state *osd, struct osd_object *obj)
{
struct MPOpts *opts = osd->opts;
@@ -386,6 +418,9 @@ static void update_object(struct osd_state *osd, struct osd_object *obj)
case OSDTYPE_PROGBAR:
update_progbar(osd, obj);
break;
+ case OSDTYPE_EXTERNAL:
+ update_external(osd, obj);
+ break;
}
}
@@ -405,3 +440,10 @@ void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
&obj->parts_cache, out_imgs);
talloc_steal(obj, obj->parts_cache);
}
+
+void osd_object_get_resolution(struct osd_state *osd, struct osd_object *obj,
+ int *out_w, int *out_h)
+{
+ *out_w = obj->osd_track ? obj->osd_track->PlayResX : 0;
+ *out_h = obj->osd_track ? obj->osd_track->PlayResY : 0;
+}
diff --git a/sub/sub.c b/sub/sub.c
index a5ff9e2593..1beb9e8138 100644
--- a/sub/sub.c
+++ b/sub/sub.c
@@ -304,3 +304,14 @@ void osd_changed_all(struct osd_state *osd)
for (int n = 0; n < MAX_OSD_PARTS; n++)
osd_changed(osd, n);
}
+
+// Scale factor to translate OSD coordinates to what the obj uses internally.
+// osd_coordinates * (sh, sh) = obj_coordinates
+void osd_object_get_scale_factor(struct osd_state *osd, struct osd_object *obj,
+ double *sw, double *sh)
+{
+ int nw, nh;
+ osd_object_get_resolution(osd, obj, &nw, &nh);
+ *sw = nw / (double)obj->vo_res.w;
+ *sh = nh / (double)obj->vo_res.h;
+}
diff --git a/sub/sub.h b/sub/sub.h
index 3cb140565c..35527f266b 100644
--- a/sub/sub.h
+++ b/sub/sub.h
@@ -90,6 +90,8 @@ enum mp_osdtype {
OSDTYPE_PROGBAR,
OSDTYPE_OSD,
+ OSDTYPE_EXTERNAL,
+
MAX_OSD_PARTS
};
@@ -137,6 +139,9 @@ struct osd_state {
float progbar_value; // range 0.0-1.0
float *progbar_stops; // used for chapter indicators (0.0-1.0 each)
int progbar_num_stops;
+ // OSDTYPE_EXTERNAL
+ char *external;
+ int external_res_x, external_res_y;
// OSDTYPE_SUB
struct dec_sub *dec_sub;
@@ -219,10 +224,15 @@ void osd_draw_on_image_p(struct osd_state *osd, struct mp_osd_res res,
double video_pts, int draw_flags,
struct mp_image_pool *pool, struct mp_image *dest);
+void osd_object_get_scale_factor(struct osd_state *osd, struct osd_object *obj,
+ double *sw, double *sh);
+
// defined in osd_libass.c and osd_dummy.c
void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj,
struct sub_bitmaps *out_imgs);
+void osd_object_get_resolution(struct osd_state *osd, struct osd_object *obj,
+ int *out_w, int *out_h);
void osd_get_function_sym(char *buffer, size_t buffer_size, int osd_function);
void osd_init_backend(struct osd_state *osd);
void osd_destroy_backend(struct osd_state *osd);