2012-08-23 10:32:13 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2012-08-23 10:32:13 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or modify
|
2012-08-23 10:32:13 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2012-08-23 10:32:13 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2015-04-13 07:36:54 +00:00
|
|
|
* with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2012-08-23 10:32:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <inttypes.h>
|
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.
2012-11-05 13:25:04 +00:00
|
|
|
#include <assert.h>
|
2012-08-23 10:32:13 +00:00
|
|
|
|
|
|
|
#include "config.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/msg.h"
|
2012-08-23 10:32:13 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
2012-08-23 10:32:13 +00:00
|
|
|
#include "vf.h"
|
|
|
|
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2012-08-23 10:32:13 +00:00
|
|
|
|
|
|
|
#include "vf_dlopen.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# include <windows.h>
|
2015-01-07 20:33:14 +00:00
|
|
|
# define DLLOpen(name) LoadLibraryA(name)
|
2012-08-23 10:32:13 +00:00
|
|
|
# define DLLClose(handle) FreeLibrary(handle)
|
|
|
|
# define DLLSymbol(handle, name) ((void *)GetProcAddress(handle, name))
|
|
|
|
#else
|
|
|
|
# include <dlfcn.h>
|
|
|
|
# define DLLOpen(name) dlopen(name, RTLD_NOW)
|
|
|
|
# define DLLClose(handle) dlclose(handle)
|
|
|
|
# define DLLSymbol(handle, name) dlsym(handle, name)
|
|
|
|
#endif
|
|
|
|
|
2013-12-05 21:55:09 +00:00
|
|
|
struct vf_priv_s {
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
char *cfg_dllname;
|
2012-08-23 10:32:13 +00:00
|
|
|
int cfg_argc;
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
char *cfg_argv[16];
|
2012-08-23 10:32:13 +00:00
|
|
|
void *dll;
|
|
|
|
struct vf_dlopen_context filter;
|
|
|
|
|
|
|
|
// output mp_image_t stuff
|
|
|
|
mp_image_t *outpic[FILTER_MAX_OUTCNT];
|
|
|
|
|
2012-09-10 11:03:32 +00:00
|
|
|
// generic
|
|
|
|
unsigned int out_cnt, out_width, out_height;
|
|
|
|
|
2012-08-23 10:32:13 +00:00
|
|
|
// multi frame output
|
|
|
|
unsigned int outbufferpos;
|
|
|
|
unsigned int outbufferlen;
|
|
|
|
mp_image_t *outbuffermpi;
|
|
|
|
|
|
|
|
unsigned int outfmt;
|
|
|
|
|
|
|
|
int argc;
|
2013-12-05 21:55:09 +00:00
|
|
|
};
|
2012-08-23 10:32:13 +00:00
|
|
|
|
2013-02-03 14:52:01 +00:00
|
|
|
struct fmtname {
|
|
|
|
const char *name;
|
|
|
|
enum mp_imgfmt fmt;
|
|
|
|
};
|
|
|
|
|
2012-08-23 10:32:13 +00:00
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
static void set_imgprop(struct vf_dlopen_picdata *out, const mp_image_t *mpi)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
out->planes = mpi->num_planes;
|
|
|
|
for (i = 0; i < mpi->num_planes; ++i) {
|
|
|
|
out->plane[i] = mpi->planes[i];
|
|
|
|
out->planestride[i] = mpi->stride[i];
|
|
|
|
out->planewidth[i] =
|
2015-04-10 19:02:16 +00:00
|
|
|
i ? (/*mpi->chroma_width*/ mpi->w >> mpi->fmt.chroma_xs) : mpi->w;
|
2012-08-23 10:32:13 +00:00
|
|
|
out->planeheight[i] =
|
2015-04-10 19:02:16 +00:00
|
|
|
i ? (/*mpi->chroma_height*/ mpi->h >> mpi->fmt.chroma_ys) : mpi->h;
|
|
|
|
out->planexshift[i] = i ? mpi->fmt.chroma_xs : 0;
|
|
|
|
out->planeyshift[i] = i ? mpi->fmt.chroma_ys : 0;
|
2012-08-23 10:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int config(struct vf_instance *vf,
|
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int fmt)
|
|
|
|
{
|
|
|
|
vf->priv->filter.in_width = width;
|
|
|
|
vf->priv->filter.in_height = height;
|
|
|
|
vf->priv->filter.in_d_width = d_width;
|
|
|
|
vf->priv->filter.in_d_height = d_height;
|
2014-06-14 07:58:48 +00:00
|
|
|
vf->priv->filter.in_fmt = talloc_strdup(vf, mp_imgfmt_to_name(fmt));
|
2012-08-23 10:32:13 +00:00
|
|
|
vf->priv->filter.out_width = width;
|
|
|
|
vf->priv->filter.out_height = height;
|
|
|
|
vf->priv->filter.out_d_width = d_width;
|
|
|
|
vf->priv->filter.out_d_height = d_height;
|
|
|
|
vf->priv->filter.out_fmt = NULL;
|
|
|
|
vf->priv->filter.out_cnt = 1;
|
|
|
|
|
|
|
|
if (!vf->priv->filter.in_fmt) {
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_ERR(vf, "invalid input/output format\n");
|
2012-08-23 10:32:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (vf->priv->filter.config && vf->priv->filter.config(&vf->priv->filter) < 0) {
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_ERR(vf, "filter config failed\n");
|
2012-08-23 10:32:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-10 11:03:32 +00:00
|
|
|
// copy away stuff to sanity island
|
|
|
|
vf->priv->out_cnt = vf->priv->filter.out_cnt;
|
|
|
|
vf->priv->out_width = vf->priv->filter.out_width;
|
|
|
|
vf->priv->out_height = vf->priv->filter.out_height;
|
|
|
|
|
2012-08-23 10:32:13 +00:00
|
|
|
if (vf->priv->filter.out_fmt)
|
2014-05-14 19:50:27 +00:00
|
|
|
vf->priv->outfmt = mp_imgfmt_from_name(bstr0(vf->priv->filter.out_fmt), false);
|
2012-08-23 10:32:13 +00:00
|
|
|
else {
|
|
|
|
struct vf_dlopen_formatpair *p = vf->priv->filter.format_mapping;
|
|
|
|
vf->priv->outfmt = 0;
|
|
|
|
if (p) {
|
|
|
|
for (; p->from; ++p) {
|
|
|
|
// TODO support pixel format classes in matching
|
|
|
|
if (!strcmp(p->from, vf->priv->filter.in_fmt)) {
|
2014-05-14 19:50:27 +00:00
|
|
|
if(p->to)
|
|
|
|
vf->priv->outfmt = mp_imgfmt_from_name(bstr0(p->to), false);
|
|
|
|
else
|
|
|
|
vf->priv->outfmt = mp_imgfmt_from_name(bstr0(p->from), false);
|
2012-08-23 10:32:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
vf->priv->outfmt = fmt;
|
2014-06-14 07:58:48 +00:00
|
|
|
vf->priv->filter.out_fmt =
|
|
|
|
talloc_strdup(vf, mp_imgfmt_to_name(vf->priv->outfmt));
|
2012-08-23 10:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!vf->priv->outfmt) {
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_ERR(vf, "filter config wants an unsupported output format\n");
|
2012-08-23 10:32:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-09-10 11:03:32 +00:00
|
|
|
if (!vf->priv->out_cnt || vf->priv->out_cnt > FILTER_MAX_OUTCNT) {
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_ERR(vf, "filter config wants to yield zero or too many output frames\n");
|
2012-08-23 10:32:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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.
2012-11-05 13:25:04 +00:00
|
|
|
for (int i = 0; i < vf->priv->out_cnt; ++i) {
|
|
|
|
talloc_free(vf->priv->outpic[i]);
|
|
|
|
vf->priv->outpic[i] =
|
2014-06-19 20:54:10 +00:00
|
|
|
mp_image_alloc(vf->priv->outfmt,
|
|
|
|
vf->priv->out_width, vf->priv->out_height);
|
video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)
But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.
Functions whose return values changed semantics:
mp_image_alloc
mp_image_new_copy
mp_image_new_ref
mp_image_make_writeable
mp_image_setrefp
mp_image_to_av_frame_and_unref
mp_image_from_av_frame
mp_image_new_external_ref
mp_image_new_custom_ref
mp_image_pool_make_writeable
mp_image_pool_get
mp_image_pool_new_copy
mp_vdpau_mixed_frame_create
vf_alloc_out_image
vf_make_out_image_writeable
glGetWindowScreenshot
2014-06-17 20:43:43 +00:00
|
|
|
if (!vf->priv->outpic[i])
|
|
|
|
return 0; // OOM
|
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.
2012-11-05 13:25:04 +00:00
|
|
|
talloc_steal(vf, vf->priv->outpic[i]);
|
video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)
But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.
Functions whose return values changed semantics:
mp_image_alloc
mp_image_new_copy
mp_image_new_ref
mp_image_make_writeable
mp_image_setrefp
mp_image_to_av_frame_and_unref
mp_image_from_av_frame
mp_image_new_external_ref
mp_image_new_custom_ref
mp_image_pool_make_writeable
mp_image_pool_get
mp_image_pool_new_copy
mp_vdpau_mixed_frame_create
vf_alloc_out_image
vf_make_out_image_writeable
glGetWindowScreenshot
2014-06-17 20:43:43 +00:00
|
|
|
set_imgprop(&vf->priv->filter.outpic[i], vf->priv->outpic[i]);
|
2012-08-23 10:32:13 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 11:03:32 +00:00
|
|
|
return vf_next_config(vf, vf->priv->out_width,
|
|
|
|
vf->priv->out_height,
|
2012-08-23 10:32:13 +00:00
|
|
|
vf->priv->filter.out_d_width,
|
|
|
|
vf->priv->filter.out_d_height,
|
|
|
|
flags, vf->priv->outfmt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uninit(struct vf_instance *vf)
|
|
|
|
{
|
|
|
|
if (vf->priv->filter.uninit)
|
|
|
|
vf->priv->filter.uninit(&vf->priv->filter);
|
2012-11-13 08:52:53 +00:00
|
|
|
memset(&vf->priv->filter, 0, sizeof(vf->priv->filter));
|
2012-08-23 10:32:13 +00:00
|
|
|
if (vf->priv->dll) {
|
|
|
|
DLLClose(vf->priv->dll);
|
|
|
|
vf->priv->dll = NULL;
|
|
|
|
}
|
2013-12-05 21:55:21 +00:00
|
|
|
}
|
|
|
|
|
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.
2012-11-05 13:25:04 +00:00
|
|
|
static int filter(struct vf_instance *vf, struct mp_image *mpi)
|
2012-08-23 10:32:13 +00:00
|
|
|
{
|
video: don't drop last frame when deinterlacing with yadif
Or in other words, add support for properly draining remaining frames
from video filters. vf_yadif is buffering at least one frame, and the
buffered frame was not retrieved on EOF.
For most filters, ignore this for now, and just adjust them to the
changed semantics of filter_ext. But for vf_lavfi (used by vf_yadif),
real support is implemented. libavfilter handles this simply by passing
a NULL frame to av_buffersrc_add_frame(), so we just have to make
mp_to_av() handle NULL arguments.
In load_next_vo_frame(), we first try to output a frame buffered in the
VO, then the filter, and then (if EOF is reached and there's still no
new frame) the VO again, with draining enabled. I guess this was
implemented slightly incorrectly before, because the filter chain still
could have had remaining output frames.
2014-04-28 17:44:35 +00:00
|
|
|
if (!mpi)
|
|
|
|
return 0;
|
|
|
|
|
2012-08-23 10:32:13 +00:00
|
|
|
set_imgprop(&vf->priv->filter.inpic, mpi);
|
2014-12-03 21:59:12 +00:00
|
|
|
vf->priv->filter.inpic_qscale = NULL;
|
|
|
|
vf->priv->filter.inpic_qscalestride = 0;
|
|
|
|
vf->priv->filter.inpic_qscaleshift = 0;
|
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.
2012-11-05 13:25:04 +00:00
|
|
|
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);
|
video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)
But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.
Functions whose return values changed semantics:
mp_image_alloc
mp_image_new_copy
mp_image_new_ref
mp_image_make_writeable
mp_image_setrefp
mp_image_to_av_frame_and_unref
mp_image_from_av_frame
mp_image_new_external_ref
mp_image_new_custom_ref
mp_image_pool_make_writeable
mp_image_pool_get
mp_image_pool_new_copy
mp_vdpau_mixed_frame_create
vf_alloc_out_image
vf_make_out_image_writeable
glGetWindowScreenshot
2014-06-17 20:43:43 +00:00
|
|
|
if (!out[n]) {
|
|
|
|
talloc_free(mpi);
|
|
|
|
return -1;
|
|
|
|
}
|
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.
2012-11-05 13:25:04 +00:00
|
|
|
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]);
|
2012-09-10 11:03:32 +00:00
|
|
|
}
|
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.
2012-11-05 13:25:04 +00:00
|
|
|
|
|
|
|
talloc_free(mpi);
|
|
|
|
return 0;
|
2012-08-23 10:32:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================//
|
|
|
|
|
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
|
|
|
{
|
2012-10-22 20:52:22 +00:00
|
|
|
if (IMGFMT_IS_HWACCEL(fmt))
|
2012-08-23 10:32:13 +00:00
|
|
|
return 0; // these can't really be filtered
|
2012-12-19 11:04:38 +00:00
|
|
|
if (fmt == IMGFMT_PAL8)
|
2012-08-23 10:32:13 +00:00
|
|
|
return 0; // we don't have palette support, sorry
|
2014-05-14 19:50:27 +00:00
|
|
|
const char *fmtname = mp_imgfmt_to_name(fmt);
|
2012-08-23 10:32:13 +00:00
|
|
|
if (!fmtname)
|
|
|
|
return 0;
|
|
|
|
struct vf_dlopen_formatpair *p = vf->priv->filter.format_mapping;
|
|
|
|
unsigned int outfmt = 0;
|
|
|
|
if (p) {
|
|
|
|
for (; p->from; ++p) {
|
|
|
|
// TODO support pixel format classes in matching
|
|
|
|
if (!strcmp(p->from, fmtname)) {
|
2014-05-14 19:50:27 +00:00
|
|
|
if (p->to)
|
|
|
|
outfmt = mp_imgfmt_from_name(bstr0(p->to), false);
|
|
|
|
else
|
|
|
|
outfmt = mp_imgfmt_from_name(bstr0(p->from), false);
|
2012-08-23 10:32:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-05-14 19:50:27 +00:00
|
|
|
} else {
|
2012-08-23 10:32:13 +00:00
|
|
|
outfmt = fmt;
|
2014-05-14 19:50:27 +00:00
|
|
|
}
|
2012-08-23 10:32:13 +00:00
|
|
|
if (!outfmt)
|
|
|
|
return 0;
|
|
|
|
return vf_next_query_format(vf, outfmt);
|
|
|
|
}
|
|
|
|
|
2013-12-03 23:01:38 +00:00
|
|
|
static int vf_open(vf_instance_t *vf)
|
2012-08-23 10:32:13 +00:00
|
|
|
{
|
2013-06-16 15:26:28 +00:00
|
|
|
int i;
|
2012-08-23 10:32:13 +00:00
|
|
|
if (!vf->priv->cfg_dllname) {
|
2014-05-14 20:26:07 +00:00
|
|
|
MP_ERR(vf, "usage: --vf=dlopen=/path/to/filename.so:args\n");
|
2012-08-23 10:32:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
vf->priv->dll = DLLOpen(vf->priv->cfg_dllname);
|
|
|
|
if (!vf->priv->dll) {
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_ERR(vf, "library not found: %s\n",
|
2012-08-23 10:32:13 +00:00
|
|
|
vf->priv->cfg_dllname);
|
|
|
|
return 0;
|
|
|
|
}
|
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.
2012-11-05 13:25:04 +00:00
|
|
|
|
2012-08-23 10:32:13 +00:00
|
|
|
vf_dlopen_getcontext_func *func =
|
|
|
|
(vf_dlopen_getcontext_func *) DLLSymbol(vf->priv->dll, "vf_dlopen_getcontext");
|
|
|
|
if (!func) {
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_ERR(vf, "library is not a filter: %s\n",
|
2012-08-23 10:32:13 +00:00
|
|
|
vf->priv->cfg_dllname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&vf->priv->filter, 0, sizeof(vf->priv->filter));
|
|
|
|
vf->priv->filter.major_version = VF_DLOPEN_MAJOR_VERSION;
|
|
|
|
vf->priv->filter.minor_version = VF_DLOPEN_MINOR_VERSION;
|
|
|
|
|
|
|
|
// count arguments
|
2013-06-14 12:32:18 +00:00
|
|
|
for (vf->priv->cfg_argc = sizeof(vf->priv->cfg_argv) / sizeof(vf->priv->cfg_argv[0]);
|
|
|
|
vf->priv->cfg_argc > 0 && !vf->priv->cfg_argv[vf->priv->cfg_argc - 1];
|
|
|
|
--vf->priv->cfg_argc)
|
2012-08-23 10:32:13 +00:00
|
|
|
;
|
|
|
|
|
2013-06-14 12:32:18 +00:00
|
|
|
// fix empty arguments
|
|
|
|
for (i = 0; i < vf->priv->cfg_argc; ++i)
|
|
|
|
if (vf->priv->cfg_argv[i] == NULL)
|
|
|
|
vf->priv->cfg_argv[i] = talloc_strdup (vf->priv, "");
|
|
|
|
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
if (func(&vf->priv->filter, vf->priv->cfg_argc,
|
|
|
|
(const char **)vf->priv->cfg_argv) < 0)
|
|
|
|
{
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_ERR(vf, "function did not create a filter: %s\n",
|
2012-08-23 10:32:13 +00:00
|
|
|
vf->priv->cfg_dllname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vf->priv->filter.put_image) {
|
2013-12-21 16:43:25 +00:00
|
|
|
MP_ERR(vf, "function did not create a filter that can put images: %s\n",
|
2012-08-23 10:32:13 +00:00
|
|
|
vf->priv->cfg_dllname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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.
2012-11-05 13:25:04 +00:00
|
|
|
vf->filter_ext = filter;
|
2012-08-23 10:32:13 +00:00
|
|
|
vf->query_format = query_format;
|
|
|
|
vf->config = config;
|
|
|
|
vf->uninit = uninit;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
#define OPT_BASE_STRUCT struct vf_priv_s
|
|
|
|
static const m_option_t vf_opts_fields[] = {
|
|
|
|
OPT_STRING("dll", cfg_dllname, 0),
|
|
|
|
OPT_STRING("a0", cfg_argv[0], 0),
|
|
|
|
OPT_STRING("a1", cfg_argv[1], 0),
|
|
|
|
OPT_STRING("a2", cfg_argv[2], 0),
|
|
|
|
OPT_STRING("a3", cfg_argv[3], 0),
|
|
|
|
OPT_STRING("a4", cfg_argv[4], 0),
|
|
|
|
OPT_STRING("a5", cfg_argv[5], 0),
|
|
|
|
OPT_STRING("a6", cfg_argv[6], 0),
|
|
|
|
OPT_STRING("a7", cfg_argv[7], 0),
|
|
|
|
OPT_STRING("a8", cfg_argv[8], 0),
|
|
|
|
OPT_STRING("a9", cfg_argv[9], 0),
|
|
|
|
OPT_STRING("a10", cfg_argv[10], 0),
|
|
|
|
OPT_STRING("a11", cfg_argv[11], 0),
|
|
|
|
OPT_STRING("a12", cfg_argv[12], 0),
|
|
|
|
OPT_STRING("a13", cfg_argv[13], 0),
|
|
|
|
OPT_STRING("a14", cfg_argv[14], 0),
|
|
|
|
OPT_STRING("a15", cfg_argv[15], 0),
|
|
|
|
{0}
|
2012-08-23 10:32:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const vf_info_t vf_info_dlopen = {
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = "Dynamic library filter",
|
|
|
|
.name = "dlopen",
|
|
|
|
.open = vf_open,
|
options: use m_config for options instead of m_struct
For some reason, both m_config and m_struct are somewhat similar, except
that m_config is much more powerful. m_config is used for VOs and some
other things, so to unify them. We plan to kick out m_struct and use
m_config for everything. (Unfortunately, m_config is also a bit more
bloated, so this commit isn't all that great, but it will allow to
reduce the option parser mess somewhat.)
This commit also switches all video filters to use the option macros.
One reason is that m_struct and m_config, even though they both use
m_option, store the offsets of the option fields differently (sigh...),
meaning the options defined for either are incompatible. It's easier to
switch everything in one go.
This commit will allow using the -vf option parser for other things,
like VOs and AOs.
2013-07-21 17:33:08 +00:00
|
|
|
.priv_size = sizeof(struct vf_priv_s),
|
|
|
|
.options = vf_opts_fields,
|
2012-08-23 10:32:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================//
|