diff options
author | Uoti Urpala <uau@mplayer2.org> | 2012-08-25 17:47:50 +0300 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2012-09-18 21:04:46 +0200 |
commit | 9bb03b7db40408b9dc4a0e1405a5bac754893e2b (patch) | |
tree | 87f36a068956b2783d48dac7f96dfa0bbd74d745 /libmpcodecs/vf_ass.c | |
parent | 44d8ec9272ad265aae02b064a0c5f4a80db5a107 (diff) | |
download | mpv-9bb03b7db40408b9dc4a0e1405a5bac754893e2b.tar.bz2 mpv-9bb03b7db40408b9dc4a0e1405a5bac754893e2b.tar.xz |
subs: libass: use a single persistent renderer for subtitles
To draw libass subtitles, the code used ASS_Renderer objects created
in vf_vo (VO rendering) or vf_ass. They were destroyed and recreated
together with the video filter chain. Change the code to use a single
persistent renderer instance stored in the main osd_state struct.
Because libass seems to misbehave if fonts are changed while a
renderer exists (even if ass_set_fonts() is called on the renderer
afterwards), the renderer is recreated after adding embedded fonts.
The known benefits are simpler code and avoiding delays when switching
between timeline parts from different files (libass fontconfig
initialization, needed when creating a new renderer, can take a long
time in some cases; switching between files rebuilds the video filter
chain, and this required recreating the renderers). On the other hand,
I'm not sure whether this could cause inefficient bitmap caching in
libass; explicitly resetting the renderer in some cases could be
beneficial. The new code does not keep the distinction of separate
renderers for vsfilter munged aspect vs normal; this means that
changing subtitle tracks can lose cache for the previous track.
The new code always sets some libass parameters on each rendering
call, which were previously only set if they had potentially changed.
This should be harmless as libass itself has checks to see if the
values differ from previous ones.
Conflicts:
command.c
libmpcodecs/vf_ass.c
libmpcodecs/vf_vo.c
mplayer.c
sub/ass_mp.c
Diffstat (limited to 'libmpcodecs/vf_ass.c')
-rw-r--r-- | libmpcodecs/vf_ass.c | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/libmpcodecs/vf_ass.c b/libmpcodecs/vf_ass.c index f7e3e62ec0..a346f658cf 100644 --- a/libmpcodecs/vf_ass.c +++ b/libmpcodecs/vf_ass.c @@ -62,9 +62,7 @@ static const struct vf_priv_s { int auto_insert; struct osd_state *osd; - ASS_Renderer *renderer; - - double realaspect; + double aspect_correction; unsigned char *planes[3]; struct line_limits { @@ -93,11 +91,7 @@ static int config(struct vf_instance *vf, vf->priv->planes[2] = malloc(vf->priv->outw * vf->priv->outh); vf->priv->line_limits = malloc((vf->priv->outh + 1) / 2 * sizeof(*vf->priv->line_limits)); - if (vf->priv->renderer) { - mp_ass_configure(vf->priv->renderer, opts, - vf->priv->outw, vf->priv->outh, 0); - vf->priv->realaspect = (double)width / height * d_height / d_width; - } + vf->priv->aspect_correction = (double)width / height * d_height / d_width; return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width, d_height, flags, outfmt); @@ -360,22 +354,21 @@ static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) { struct osd_state *osd = vf->priv->osd; ASS_Image *images = 0; - double scale = osd->vsfilter_aspect - && vf->opts->ass_vsfilter_aspect_compat - ? 1 : vf->priv->realaspect; - if (sub_visibility && vf->priv->renderer && osd->ass_track - && (pts != MP_NOPTS_VALUE)) { - ass_set_aspect_ratio(vf->priv->renderer, scale, 1); - if (osd->ass_force_reload) - mp_ass_reload_options(vf->priv->renderer, vf->opts); - osd->ass_force_reload = false; - images = ass_render_frame(vf->priv->renderer, osd->ass_track, + ASS_Renderer *renderer = osd->ass_renderer; + bool vs = osd->vsfilter_aspect && vf->opts->ass_vsfilter_aspect_compat; + if (sub_visibility && osd->ass_track && (pts != MP_NOPTS_VALUE)) { + struct mp_eosd_res dim = { .w = vf->priv->outw, .h = vf->priv->outh, + .mt = vf->opts->ass_top_margin, + .mb = vf->opts->ass_bottom_margin }; + mp_ass_configure(renderer, vf->opts, &dim, 0); + ass_set_aspect_ratio(renderer, + vs ? 1. : vf->priv->aspect_correction, 1); + images = ass_render_frame(renderer, osd->ass_track, (pts - osd->sub_offset + sub_delay) * 1000 + .5, NULL); } prepare_image(vf, mpi); - if (images) - render_frame(vf, mpi, images); + render_frame(vf, mpi, images); return vf_next_put_image(vf, vf->dmpi, pts); } @@ -398,23 +391,15 @@ static int control(vf_instance_t *vf, int request, void *data) vf->priv->osd = data; break; case VFCTRL_INIT_EOSD: - vf->priv->renderer = ass_renderer_init((ASS_Library *)data); - if (!vf->priv->renderer) - return CONTROL_FALSE; - mp_ass_configure_fonts(vf->priv->renderer); return CONTROL_TRUE; case VFCTRL_DRAW_EOSD: - if (vf->priv->renderer) - return CONTROL_TRUE; - break; + return CONTROL_TRUE; } return vf_next_control(vf, request, data); } static void uninit(struct vf_instance *vf) { - if (vf->priv->renderer) - ass_renderer_done(vf->priv->renderer); free(vf->priv->planes[1]); free(vf->priv->planes[2]); free(vf->priv->line_limits); |