From 1c65428d6f70f05333ecc8284e3f235c679fff26 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 22 Dec 2012 17:17:43 +0100 Subject: sub: do not copy the target image if there is no OSD/subs It's not easy to tell whether the OSD/subs are empty, or if something is drawn. In general you have to use osd_draw() with a custom callback. If nothing is visible, the callback is never invoked. (The actual reason why this is so "hard" is the implementation of osd_libass.c, which doesn't allow separating rendering and drawing of OSD elements, because all OSD elements share the same ASS_Renderer.) To simplify avoiding copies, make osd_draw_on_image() instead of the caller use mp_image_make_writeable(). Introduce osd_draw_on_image_p(), which works like osd_draw_on_image(), but gets the new image allocation from an image pool. This is supposed to be an optimization, because it reduces the frequency of large allocations/deallocations for image data. The result of this is that the frequency of copies needed in conjunction with vf_sub, screenshots, and vo_lavc (encoding) should be reduced. vf_sub now always does true pass-through if no subs are shown. Drop the pts check from vf_sub. This didn't make much sense. --- video/filter/vf_sub.c | 8 +++----- video/out/vo_lavc.c | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) (limited to 'video') diff --git a/video/filter/vf_sub.c b/video/filter/vf_sub.c index 8cda9f5e79..c9d22995c1 100644 --- a/video/filter/vf_sub.c +++ b/video/filter/vf_sub.c @@ -155,9 +155,7 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) struct vf_priv_s *priv = vf->priv; struct osd_state *osd = priv->osd; - if (vf->priv->opt_top_margin || vf->priv->opt_bottom_margin || - !mp_image_is_writeable(mpi)) - { + if (vf->priv->opt_top_margin || vf->priv->opt_bottom_margin) { struct mp_image *dmpi = vf_alloc_out_image(vf); mp_image_copy_attributes(dmpi, mpi); prepare_image(vf, dmpi, mpi); @@ -167,8 +165,8 @@ static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) mp_image_set_colorspace_details(mpi, &priv->csp); - if (mpi->pts != MP_NOPTS_VALUE) - osd_draw_on_image(osd, priv->dim, mpi->pts, OSD_DRAW_SUB_FILTER, mpi); + osd_draw_on_image_p(osd, priv->dim, mpi->pts, OSD_DRAW_SUB_FILTER, + vf->out_pool, mpi); return mpi; } diff --git a/video/out/vo_lavc.c b/video/out/vo_lavc.c index 35041c7f63..2aced9351a 100644 --- a/video/out/vo_lavc.c +++ b/video/out/vo_lavc.c @@ -487,7 +487,6 @@ static void draw_osd(struct vo *vo, struct osd_state *osd) }; mp_image_set_colorspace_details(vc->lastimg, &vc->colorspace); - mp_image_make_writeable(vc->lastimg); osd_draw_on_image(osd, dim, osd->vo_pts, OSD_DRAW_SUB_ONLY, vc->lastimg); } -- cgit v1.2.3