summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-07-16 13:33:19 +0200
committerwm4 <wm4@nowhere>2017-07-16 13:33:19 +0200
commit572802e8664a344481682990db1458f13eb6b9eb (patch)
tree8ea2686e123ccfcd0557d1e83a05e938631c152a /sub
parentddd068491c9e8f7f77b6bba61269f867bdad204b (diff)
downloadmpv-572802e8664a344481682990db1458f13eb6b9eb.tar.bz2
mpv-572802e8664a344481682990db1458f13eb6b9eb.tar.xz
osd_libass: avoid libass warnings if scripts set ASS text early
Lua scripts can call osd_set_external() early (before the VO window is created and obj->vo_res is filled), in which case the PlayResX field would be set to nonsense, and libass would print a pointless warning. There's an easy and a hard fix: either just go on and pass dummy values to libass (basically like before, just clamp them to avoid the values which make libass print the warning). Or attempt to update the PlayRes field to correct values on rendering (since at rendering time, you always know the screen size and the correct values). Do the latter. Since various things use PlayRes for scaling things, this might still not be fully ideal. This is a general problem with the async scripting interface.
Diffstat (limited to 'sub')
-rw-r--r--sub/osd_libass.c48
-rw-r--r--sub/osd_state.h1
2 files changed, 30 insertions, 19 deletions
diff --git a/sub/osd_libass.c b/sub/osd_libass.c
index 44fcf6d269..046007d66b 100644
--- a/sub/osd_libass.c
+++ b/sub/osd_libass.c
@@ -96,34 +96,40 @@ void osd_destroy_backend(struct osd_state *osd)
}
}
-static void create_ass_track(struct osd_state *osd, struct osd_object *obj,
- struct ass_state *ass, int res_x, int res_y)
+static void update_playres(struct ass_state *ass, struct mp_osd_res *vo_res)
{
- create_ass_renderer(osd, ass);
-
ASS_Track *track = ass->track;
- if (!track)
- track = ass_new_track(ass->library);
-
int old_res_x = track->PlayResX;
int old_res_y = track->PlayResY;
- double aspect = 1.0 * obj->vo_res.w / FFMAX(obj->vo_res.h, 1) /
- obj->vo_res.display_par;
+ double aspect = 1.0 * vo_res->w / MPMAX(vo_res->h, 1);
+ if (vo_res->display_par > 0)
+ aspect = aspect / vo_res->display_par;
- track->track_type = TRACK_TYPE_ASS;
- track->Timer = 100.;
- track->PlayResY = res_y ? res_y : MP_ASS_FONT_PLAYRESY;
- track->PlayResX = res_x ? res_x : track->PlayResY * aspect;
- track->WrapStyle = 1; // end-of-line wrapping instead of smart wrapping
- track->Kerning = true;
+ track->PlayResY = ass->res_y ? ass->res_y : MP_ASS_FONT_PLAYRESY;
+ track->PlayResX = ass->res_x ? ass->res_x : track->PlayResY * aspect;
// Force libass to clear its internal cache - it doesn't check for
// PlayRes changes itself.
if (old_res_x != track->PlayResX || old_res_y != track->PlayResY)
ass_set_frame_size(ass->render, 1, 1);
+}
- ass->track = track;
+static void create_ass_track(struct osd_state *osd, struct osd_object *obj,
+ struct ass_state *ass)
+{
+ create_ass_renderer(osd, ass);
+
+ ASS_Track *track = ass->track;
+ if (!track)
+ track = ass->track = ass_new_track(ass->library);
+
+ track->track_type = TRACK_TYPE_ASS;
+ track->Timer = 100.;
+ track->WrapStyle = 1; // end-of-line wrapping instead of smart wrapping
+ track->Kerning = true;
+
+ update_playres(ass, &obj->vo_res);
}
static int find_style(ASS_Track *track, const char *name, int def)
@@ -223,7 +229,7 @@ static ASS_Style *prepare_osd_ass(struct osd_state *osd, struct osd_object *obj)
{
struct MPOpts *opts = osd->opts;
- create_ass_track(osd, obj, &obj->ass, 0, 0);
+ create_ass_track(osd, obj, &obj->ass);
struct osd_style_opts font = *opts->osd_style;
font.font_size *= opts->osd_scale;
@@ -338,7 +344,7 @@ static void get_osd_bar_box(struct osd_state *osd, struct osd_object *obj,
{
struct MPOpts *opts = osd->opts;
- create_ass_track(osd, obj, &obj->ass, 0, 0);
+ create_ass_track(osd, obj, &obj->ass);
ASS_Track *track = obj->ass.track;
ASS_Style *style = get_style(&obj->ass, "progbar");
@@ -461,7 +467,9 @@ static void update_external(struct osd_state *osd, struct osd_object *obj,
bstr t = bstr0(ext->text);
if (!t.len)
return;
- create_ass_track(osd, obj, &ext->ass, ext->res_x, ext->res_y);
+ ext->ass.res_x = ext->res_x;
+ ext->ass.res_y = ext->res_y;
+ create_ass_track(osd, obj, &ext->ass);
clear_ass(&ext->ass);
@@ -537,6 +545,8 @@ static void append_ass(struct ass_state *ass, struct mp_osd_res *res,
return;
}
+ update_playres(ass, res);
+
ass_set_frame_size(ass->render, res->w, res->h);
ass_set_aspect_ratio(ass->render, res->display_par, 1.0);
diff --git a/sub/osd_state.h b/sub/osd_state.h
index dc2d6d5b6c..5cb0f1e07c 100644
--- a/sub/osd_state.h
+++ b/sub/osd_state.h
@@ -22,6 +22,7 @@ struct ass_state {
struct ass_track *track;
struct ass_renderer *render;
struct ass_library *library;
+ int res_x, res_y;
};
struct osd_object {