1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-26 00:42:57 +00:00

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.
This commit is contained in:
wm4 2017-07-16 13:33:19 +02:00
parent ddd068491c
commit 572802e866
2 changed files with 30 additions and 19 deletions

View File

@ -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);

View File

@ -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 {