diff options
author | wm4 <wm4@nowhere> | 2012-11-05 14:25:04 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-01-13 20:04:10 +0100 |
commit | c54fc507da8edcc2c5d3bc3f50b0881d1c1406d7 (patch) | |
tree | 530d112301256e1c3ea50d7bb416b7ba2109130b /video/filter/vf_dlopen.c | |
parent | 1c412169aca2f0ad38380b0c89f2485e6a256766 (diff) | |
download | mpv-c54fc507da8edcc2c5d3bc3f50b0881d1c1406d7.tar.bz2 mpv-c54fc507da8edcc2c5d3bc3f50b0881d1c1406d7.tar.xz |
video/filter: change filter API, use refcounting, remove filter DR
Change the entire filter API to use reference counted images instead
of vf_get_image().
Remove filter "direct rendering". This was useful for vf_expand and (in
rare cases) vf_sub: DR allowed these filters to pass a cropped image to
the filters before them. Then, on filtering, the image was "uncropped",
so that black bars could be added around the image without copying. This
means that in some cases, vf_expand will be slower (-vf gradfun,expand
for example).
Note that another form of DR used for in-place filters has been replaced
by simpler logic. Instead of trying to do DR, filters can check if the
image is writeable (with mp_image_is_writeable()), and do true in-place
if that's the case. This affects filters like vf_gradfun and vf_sub.
Everything has to support strides now. If something doesn't, making a
copy of the image data is required.
Diffstat (limited to 'video/filter/vf_dlopen.c')
-rw-r--r-- | video/filter/vf_dlopen.c | 115 |
1 files changed, 36 insertions, 79 deletions
diff --git a/video/filter/vf_dlopen.c b/video/filter/vf_dlopen.c index e440b3759e..639f1c1d36 100644 --- a/video/filter/vf_dlopen.c +++ b/video/filter/vf_dlopen.c @@ -19,6 +19,7 @@ #include <stdlib.h> #include <string.h> #include <inttypes.h> +#include <assert.h> #include "config.h" #include "core/mp_msg.h" @@ -149,14 +150,13 @@ static int config(struct vf_instance *vf, return 0; } - if (vf->priv->out_cnt >= 2) { - int i; - for (i = 0; i < vf->priv->out_cnt; ++i) { - vf->priv->outpic[i] = - alloc_mpi(vf->priv->out_width, vf->priv->out_height, - vf->priv->outfmt); - set_imgprop(&vf->priv->filter.outpic[i], vf->priv->outpic[i]); - } + for (int i = 0; i < vf->priv->out_cnt; ++i) { + talloc_free(vf->priv->outpic[i]); + vf->priv->outpic[i] = + mp_image_alloc(vf->priv->out_width, vf->priv->out_height, + vf->priv->outfmt); + set_imgprop(&vf->priv->filter.outpic[i], vf->priv->outpic[i]); + talloc_steal(vf, vf->priv->outpic[i]); } return vf_next_config(vf, vf->priv->out_width, @@ -175,52 +175,13 @@ static void uninit(struct vf_instance *vf) DLLClose(vf->priv->dll); vf->priv->dll = NULL; } - if (vf->priv->out_cnt >= 2) { - int i; - for (i = 0; i < vf->priv->out_cnt; ++i) { - free_mp_image(vf->priv->outpic[i]); - vf->priv->outpic[i] = NULL; - } - } if (vf->priv->qbuffer) { free(vf->priv->qbuffer); vf->priv->qbuffer = NULL; } } -// NOTE: only called if (vf->priv->out_cnt >= 2) { -static int continue_put_image(struct vf_instance *vf) -{ - int k; - int ret = 0; - - mp_image_t *dmpi = - vf_get_image(vf->next, vf->priv->outfmt, MP_IMGTYPE_EXPORT, 0, - vf->priv->outpic[vf->priv->outbufferpos]->w, - vf->priv->outpic[vf->priv->outbufferpos]->h); - for (k = 0; k < vf->priv->outpic[vf->priv->outbufferpos]->num_planes; - ++k) { - dmpi->planes[k] = vf->priv->outpic[vf->priv->outbufferpos]->planes[k]; - dmpi->stride[k] = vf->priv->outpic[vf->priv->outbufferpos]->stride[k]; - } - - // pass through qscale if we can - vf_clone_mpi_attributes(dmpi, vf->priv->outbuffermpi); - - ret = - vf_next_put_image(vf, dmpi, - vf->priv->filter.outpic[vf->priv->outbufferpos].pts); - - ++vf->priv->outbufferpos; - - // more frames left? - if (vf->priv->outbufferpos < vf->priv->outbufferlen) - vf_queue_frame(vf, continue_put_image); - - return ret; -} - -static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) +static int filter(struct vf_instance *vf, struct mp_image *mpi) { int i, k; @@ -245,36 +206,32 @@ static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) vf->priv->filter.inpic_qscalestride = 0; vf->priv->filter.inpic_qscaleshift = 0; } - vf->priv->filter.inpic.pts = pts; - - if (vf->priv->out_cnt >= 2) { - // more than one out pic - int ret = vf->priv->filter.put_image(&vf->priv->filter); - if (ret <= 0) - return ret; - - vf->priv->outbuffermpi = mpi; - vf->priv->outbufferlen = ret; - vf->priv->outbufferpos = 0; - return continue_put_image(vf); - } else { - // efficient case: exactly one out pic - mp_image_t *dmpi = - vf_get_image(vf->next, vf->priv->outfmt, - MP_IMGTYPE_TEMP, - MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE, - vf->priv->out_width, vf->priv->out_height); - set_imgprop(&vf->priv->filter.outpic[0], dmpi); - - int ret = vf->priv->filter.put_image(&vf->priv->filter); - if (ret <= 0) - return ret; - - // pass through qscale if we can - vf_clone_mpi_attributes(dmpi, mpi); - - return vf_next_put_image(vf, dmpi, vf->priv->filter.outpic[0].pts); + vf->priv->filter.inpic.pts = mpi->pts; + + struct mp_image *out[FILTER_MAX_OUTCNT] = {0}; + + for (int n = 0; n < vf->priv->out_cnt; n++) { + out[n] = vf_alloc_out_image(vf); + mp_image_copy_attributes(out[n], mpi); + set_imgprop(&vf->priv->filter.outpic[n], out[n]); + } + + // more than one out pic + int ret = vf->priv->filter.put_image(&vf->priv->filter); + if (ret < 0) + ret = 0; + assert(ret <= vf->priv->out_cnt); + + for (int n = 0; n < ret; n++) { + out[n]->pts = vf->priv->filter.outpic[n].pts; + vf_add_output_frame(vf, out[n]); + } + for (int n = ret; n < FILTER_MAX_OUTCNT; n++) { + talloc_free(out[n]); } + + talloc_free(mpi); + return 0; } //===========================================================================// @@ -319,7 +276,7 @@ static int vf_open(vf_instance_t *vf, char *args) vf->priv->cfg_dllname); return 0; } - + vf_dlopen_getcontext_func *func = (vf_dlopen_getcontext_func *) DLLSymbol(vf->priv->dll, "vf_dlopen_getcontext"); if (!func) { @@ -352,7 +309,7 @@ static int vf_open(vf_instance_t *vf, char *args) return 0; } - vf->put_image = put_image; + vf->filter_ext = filter; vf->query_format = query_format; vf->config = config; vf->uninit = uninit; |