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_vo.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_vo.c')
-rw-r--r-- | libmpcodecs/vf_vo.c | 59 |
1 files changed, 16 insertions, 43 deletions
diff --git a/libmpcodecs/vf_vo.c b/libmpcodecs/vf_vo.c index 0c747beb83..0db75b670e 100644 --- a/libmpcodecs/vf_vo.c +++ b/libmpcodecs/vf_vo.c @@ -35,11 +35,8 @@ struct vf_priv_s { struct vo *vo; -#ifdef CONFIG_ASS - ASS_Renderer *renderer; bool prev_visibility; double scale_ratio; -#endif }; #define video_out (vf->priv->vo) @@ -79,17 +76,10 @@ static int config(struct vf_instance *vf, if (vo_config(video_out, width, height, d_width, d_height, flags, outfmt)) return 0; -#ifdef CONFIG_ASS vf->priv->scale_ratio = (double) d_width / d_height * height / width; - if (vf->priv->renderer) { - mp_ass_configure(vf->priv->renderer, vf->opts, width, height, - vf->default_caps & VFCAP_EOSD_UNSCALED); - } - // force EOSD change detection reset vf->priv->prev_visibility = false; -#endif return 1; } @@ -133,46 +123,33 @@ static int control(struct vf_instance *vf, int request, void *data) return vo_control(video_out, VOCTRL_GET_EQUALIZER, ¶m) == VO_TRUE; } #ifdef CONFIG_ASS - case VFCTRL_INIT_EOSD: - { - vf->priv->renderer = ass_renderer_init(data); - if (!vf->priv->renderer) - return CONTROL_FALSE; - mp_ass_configure_fonts(vf->priv->renderer); + case VFCTRL_INIT_EOSD: { vf->priv->prev_visibility = false; return CONTROL_TRUE; } + case VFCTRL_DRAW_EOSD: { + struct mp_eosd_res dim = { 0 }; + if (!video_out->config_ok || + vo_control(video_out, VOCTRL_GET_EOSD_RES, &dim) != true) { + vf->priv->prev_visibility = false; + return CONTROL_FALSE; + } struct osd_state *osd = data; - mp_eosd_images_t images = {NULL, 2}; - ASS_Renderer *renderer = vf->priv->renderer; - double scale; - if (osd->vsfilter_aspect && vf->opts->ass_vsfilter_aspect_compat) { + mp_eosd_images_t images = { NULL, 2 }; + ASS_Renderer *renderer = osd->ass_renderer; + double scale = 1; + if (osd->vsfilter_aspect && vf->opts->ass_vsfilter_aspect_compat) scale = vf->priv->scale_ratio; - } else { - scale = 1; - } - if (!video_out->config_ok || !renderer) - return CONTROL_FALSE; - if (osd->ass_track_changed) - vf->priv->prev_visibility = false; - osd->ass_track_changed = false; if (sub_visibility && osd->ass_track && (osd->pts != MP_NOPTS_VALUE)) { - struct mp_eosd_res res = { 0 }; - if (vo_control(video_out, VOCTRL_GET_EOSD_RES, &res) == VO_TRUE) { - ass_set_frame_size(renderer, res.w, res.h); - ass_set_margins(renderer, res.mt, res.mb, res.ml, res.mr); - ass_set_aspect_ratio(renderer, scale, 1); - } - - if (osd->ass_force_reload) - mp_ass_reload_options(vf->priv->renderer, vf->opts); + mp_ass_configure(renderer, vf->opts, &dim, + vf->default_caps & VFCAP_EOSD_UNSCALED); + ass_set_aspect_ratio(renderer, scale, 1); images.imgs = ass_render_frame(renderer, osd->ass_track, (osd->pts + sub_delay) * 1000 + .5, &images.changed); - if (!vf->priv->prev_visibility || osd->ass_force_reload) + if (!vf->priv->prev_visibility) images.changed = 2; - osd->ass_force_reload = false; vf->priv->prev_visibility = true; } else vf->priv->prev_visibility = false; @@ -242,10 +219,6 @@ static void uninit(struct vf_instance *vf) /* Allow VO (which may live on to work with another instance of vf_vo) * to get rid of numbered-mpi references that will now be invalid. */ vo_seek_reset(video_out); -#ifdef CONFIG_ASS - if (vf->priv->renderer) - ass_renderer_done(vf->priv->renderer); -#endif free(vf->priv); } } |