2010-01-30 16:57:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* 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
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2002-04-06 22:05:01 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2011-07-30 16:03:20 +00:00
|
|
|
#include <assert.h>
|
2012-07-31 21:37:56 +00:00
|
|
|
#include <sys/types.h>
|
2012-08-15 20:23:02 +00:00
|
|
|
#include <libavutil/common.h>
|
|
|
|
#include <libavutil/mem.h>
|
2002-04-06 22:05:01 +00:00
|
|
|
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "config.h"
|
2002-05-25 13:22:28 +00:00
|
|
|
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/mp_msg.h"
|
|
|
|
#include "mpvcore/m_option.h"
|
|
|
|
#include "mpvcore/m_config.h"
|
2002-08-13 23:32:05 +00:00
|
|
|
|
2013-08-06 20:41:30 +00:00
|
|
|
#include "mpvcore/options.h"
|
2002-04-06 22:05:01 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.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 "video/mp_image_pool.h"
|
2002-04-06 22:05:01 +00:00
|
|
|
#include "vf.h"
|
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/memcpy_pic.h"
|
2003-05-20 17:42:33 +00:00
|
|
|
|
2007-11-09 06:57:24 +00:00
|
|
|
extern const vf_info_t vf_info_vo;
|
|
|
|
extern const vf_info_t vf_info_crop;
|
|
|
|
extern const vf_info_t vf_info_expand;
|
|
|
|
extern const vf_info_t vf_info_pp;
|
|
|
|
extern const vf_info_t vf_info_scale;
|
|
|
|
extern const vf_info_t vf_info_format;
|
|
|
|
extern const vf_info_t vf_info_noformat;
|
|
|
|
extern const vf_info_t vf_info_flip;
|
|
|
|
extern const vf_info_t vf_info_rotate;
|
|
|
|
extern const vf_info_t vf_info_mirror;
|
|
|
|
extern const vf_info_t vf_info_noise;
|
2012-11-15 14:16:12 +00:00
|
|
|
extern const vf_info_t vf_info_eq;
|
2009-07-07 02:01:36 +00:00
|
|
|
extern const vf_info_t vf_info_gradfun;
|
2007-11-09 06:57:24 +00:00
|
|
|
extern const vf_info_t vf_info_unsharp;
|
|
|
|
extern const vf_info_t vf_info_swapuv;
|
|
|
|
extern const vf_info_t vf_info_down3dright;
|
|
|
|
extern const vf_info_t vf_info_hqdn3d;
|
|
|
|
extern const vf_info_t vf_info_ilpack;
|
|
|
|
extern const vf_info_t vf_info_dsize;
|
|
|
|
extern const vf_info_t vf_info_softpulldown;
|
|
|
|
extern const vf_info_t vf_info_pullup;
|
|
|
|
extern const vf_info_t vf_info_delogo;
|
|
|
|
extern const vf_info_t vf_info_phase;
|
|
|
|
extern const vf_info_t vf_info_divtc;
|
|
|
|
extern const vf_info_t vf_info_softskip;
|
|
|
|
extern const vf_info_t vf_info_screenshot;
|
2012-10-21 16:31:34 +00:00
|
|
|
extern const vf_info_t vf_info_sub;
|
2007-11-09 06:57:24 +00:00
|
|
|
extern const vf_info_t vf_info_yadif;
|
2010-10-22 17:46:12 +00:00
|
|
|
extern const vf_info_t vf_info_stereo3d;
|
2012-08-23 10:32:13 +00:00
|
|
|
extern const vf_info_t vf_info_dlopen;
|
2013-03-10 23:16:34 +00:00
|
|
|
extern const vf_info_t vf_info_lavfi;
|
2013-09-20 13:55:13 +00:00
|
|
|
extern const vf_info_t vf_info_vaapi;
|
2002-04-06 22:05:01 +00:00
|
|
|
|
|
|
|
// list of available filters:
|
2011-11-03 13:21:53 +00:00
|
|
|
static const vf_info_t *const filter_list[] = {
|
2002-04-06 22:05:01 +00:00
|
|
|
&vf_info_crop,
|
|
|
|
&vf_info_expand,
|
2002-04-07 20:21:37 +00:00
|
|
|
&vf_info_scale,
|
2002-04-06 22:05:01 +00:00
|
|
|
&vf_info_vo,
|
2002-04-09 14:01:53 +00:00
|
|
|
&vf_info_format,
|
2004-02-06 20:31:57 +00:00
|
|
|
&vf_info_noformat,
|
2002-04-11 03:17:14 +00:00
|
|
|
&vf_info_flip,
|
2002-04-19 02:18:46 +00:00
|
|
|
&vf_info_rotate,
|
2002-04-21 14:36:36 +00:00
|
|
|
&vf_info_mirror,
|
2011-12-11 05:48:26 +00:00
|
|
|
|
2012-02-27 16:18:49 +00:00
|
|
|
#ifdef CONFIG_LIBPOSTPROC
|
2010-10-31 00:19:56 +00:00
|
|
|
&vf_info_pp,
|
2012-02-27 16:18:49 +00:00
|
|
|
#endif
|
2013-03-10 23:16:34 +00:00
|
|
|
#ifdef CONFIG_VF_LAVFI
|
|
|
|
&vf_info_lavfi,
|
|
|
|
#endif
|
Remove useless video filters
Most of these have very limited actual use, or are even entirely
useless. They only serve to bloat the codebase and to make life harder.
Drowning users in tons of barely useful filters isn't exactly helpful
either. Some of these filters were redundant or marked as obsolete.
The dlopen and lua (to be added soon) video filters provide ways to add
custom filters.
Detailed listing for each filter with reasons (with contributions from
divVerent and lachs0r):
1bpp:
Replaced by "scale".
2xsai:
Pixel art scaling algorithm, useless with lossy video.
blackframe:
Not very useful. Apparently one use is combining it with scripts,
that pass the
bmovl:
Weirdly complex and insane (using FIFO commands), questionable use.
cropdetect:
Only sort-of useful when used with scripts, and then it will be
very fragile.
It's probably better to use the dlopen rectangle filter, or to
implement the common use-case in a better way.
decimate:
Not needed/useful with modern video codecs, is an
encoding-only filter.
denoise3d:
"hqdn3d" is better.
detc:
Some of the worse deteleciners.
dint:
Useless, actually crashes. (On an assert in vf.c that is disabled
by default in mplayer-svn.)
dvbscale:
Not even practical, and the same effect can be achieved through
other means.
eq:
Worse/older version of eq2.
field:
Limited use, available as dlopen filter.
fil:
Quoting the manpage:
This filter is very similar to the il filter but much faster,
the main disadvantage is that it does not always work.
Especially if combined with other filters it may produce
randomly messed up images, so be happy if it works but do not
complain if it does not for your combination of filters.
filmdint:
Kind of redundant with pullup, and slightly worse.
fixpts:
Never useful. (Most if not all filters have been fixed for PTS.)
framestep:
Questionable use. For things like creating thumbnails, ffmpeg or
--sstep should be used.
geq:
Limited use, will be redundant with the "lua" filter.
halfpack:
Useless, probably redundant with "scale".
harddup:
Useless.
hue:
Most VOs support this.
il:
Useless.
ivtc:
Another of the worse deteleciners.
kerndeint:
A bad deinterlacer.
lavc:
For DVB output devices. We removed that support.
lavcdeint:
A bad deinterlacer, was already deprecated.
Still available as --vf=pp=fd.
mcdeint:
A broken deinterlacer that uses lavc internals.
ow:
Very slow, barely any quality benefit over "hqdn3d".
palette:
Done by "scale".
perspective:
Files with incorrect perspective are extremely rare. About the
only real-world use for this is keystone correction, which is
usually done in hardware by the projector or by graphics
drivers/compositors.
pp7:
Another useless postprocessing filter with bad and complicated code.
Use libpostprocess with "pp" instead.
qp:
Useless.
remove-logo:
Redundant with delogo, which is better and more practical.
rgbtest:
Useless.
sab, smartblur, boxblur:
Blur filters, redundant to "unsharp".
softskip:
Does nothing.
spp, fspp, uspp:
Useless postprocessing filters. "spp" needs ffmpeg internals.
"fspp" is the optimized version of the "spp" filter (???), while
"uspp" is the slow version (????).
Use libpostprocess with "pp" instead.
telecine:
Evil and useless. Available as dlopen filter for testing
purposes.
test:
Useless.
tfields:
Useless, probably.
tile:
Questionable use. Available as dlopen filter.
tinterlace:
Evil and useless.
yuvcsp:
Probably useless.
yvu9:
Redundant with "scale".
Also remove the following left-over files: vd_null.c, vqf.h
2012-10-02 12:14:07 +00:00
|
|
|
|
2008-04-11 08:11:16 +00:00
|
|
|
&vf_info_screenshot,
|
2011-12-11 05:48:26 +00:00
|
|
|
|
2002-06-14 01:14:56 +00:00
|
|
|
&vf_info_noise,
|
2012-11-15 14:16:12 +00:00
|
|
|
&vf_info_eq,
|
2009-07-07 02:01:36 +00:00
|
|
|
&vf_info_gradfun,
|
2002-10-29 22:37:11 +00:00
|
|
|
&vf_info_unsharp,
|
2002-10-31 18:13:56 +00:00
|
|
|
&vf_info_swapuv,
|
2003-02-11 21:44:55 +00:00
|
|
|
&vf_info_down3dright,
|
2003-02-15 22:24:32 +00:00
|
|
|
&vf_info_hqdn3d,
|
2003-04-19 01:39:37 +00:00
|
|
|
&vf_info_ilpack,
|
2003-04-27 18:55:04 +00:00
|
|
|
&vf_info_dsize,
|
2003-08-03 12:09:58 +00:00
|
|
|
&vf_info_softpulldown,
|
2003-08-18 15:24:08 +00:00
|
|
|
&vf_info_pullup,
|
2003-09-03 22:44:28 +00:00
|
|
|
&vf_info_delogo,
|
2004-03-29 04:39:04 +00:00
|
|
|
&vf_info_phase,
|
2004-04-17 17:08:31 +00:00
|
|
|
&vf_info_divtc,
|
2012-10-21 16:31:34 +00:00
|
|
|
&vf_info_sub,
|
2006-06-06 23:30:23 +00:00
|
|
|
&vf_info_yadif,
|
2010-10-22 17:46:12 +00:00
|
|
|
&vf_info_stereo3d,
|
2013-07-12 16:33:39 +00:00
|
|
|
#ifdef CONFIG_DLOPEN
|
2012-08-23 10:32:13 +00:00
|
|
|
&vf_info_dlopen,
|
2013-09-20 13:55:13 +00:00
|
|
|
#endif
|
|
|
|
#if CONFIG_VAAPI_VPP
|
|
|
|
&vf_info_vaapi,
|
2013-07-09 07:28:05 +00:00
|
|
|
#endif
|
2002-04-06 22:05:01 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
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
|
|
|
static bool get_desc(struct m_obj_desc *dst, int index)
|
|
|
|
{
|
|
|
|
if (index >= MP_ARRAY_SIZE(filter_list) - 1)
|
|
|
|
return false;
|
|
|
|
const vf_info_t *vf = filter_list[index];
|
|
|
|
*dst = (struct m_obj_desc) {
|
|
|
|
.name = vf->name,
|
2013-10-23 17:06:42 +00:00
|
|
|
.description = vf->description,
|
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 = vf->priv_size,
|
|
|
|
.priv_defaults = vf->priv_defaults,
|
|
|
|
.options = vf->options,
|
|
|
|
.p = vf,
|
|
|
|
};
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-03-15 18:01:02 +00:00
|
|
|
// For the vf option
|
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
|
|
|
const struct m_obj_list vf_obj_list = {
|
|
|
|
.get_desc = get_desc,
|
|
|
|
.description = "video filters",
|
2013-07-22 21:06:22 +00:00
|
|
|
.legacy_hacks = true, // some filters have custom option parsing
|
2003-03-15 18:01:02 +00:00
|
|
|
};
|
|
|
|
|
2013-07-14 22:57:04 +00:00
|
|
|
int vf_control(struct vf_instance *vf, int cmd, void *arg)
|
|
|
|
{
|
|
|
|
return vf->control(vf, cmd, arg);
|
|
|
|
}
|
|
|
|
|
2013-07-18 11:37:24 +00:00
|
|
|
static void vf_fix_img_params(struct mp_image *img, struct mp_image_params *p)
|
|
|
|
{
|
|
|
|
// Filters must absolutely set these correctly.
|
|
|
|
assert(img->w == p->w && img->h == p->h);
|
|
|
|
assert(img->imgfmt == p->imgfmt);
|
|
|
|
// Too many things don't set this correctly.
|
|
|
|
// If --colormatrix is used, decoder and filter chain disagree too.
|
|
|
|
// In general, it's probably more convenient to force these here,
|
|
|
|
// instead of requiring filters to set these correctly.
|
|
|
|
img->colorspace = p->colorspace;
|
|
|
|
img->levels = p->colorlevels;
|
|
|
|
img->chroma_location = p->chroma_location;
|
2013-08-24 14:33:13 +00:00
|
|
|
mp_image_set_display_size(img, p->d_w, p->d_h);
|
2013-07-18 11:37:24 +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
|
|
|
// Get a new image for filter output, with size and pixel format according to
|
|
|
|
// the last vf_config call.
|
|
|
|
struct mp_image *vf_alloc_out_image(struct vf_instance *vf)
|
2011-11-03 13:21:53 +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
|
|
|
assert(vf->fmt_out.configured);
|
2013-07-18 11:37:24 +00:00
|
|
|
struct mp_image_params *p = &vf->fmt_out.params;
|
|
|
|
struct mp_image *img = mp_image_pool_get(vf->out_pool, p->imgfmt, p->w, p->h);
|
|
|
|
vf_fix_img_params(img, p);
|
|
|
|
return img;
|
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
|
|
|
}
|
2011-11-03 13:21:53 +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
|
|
|
void vf_make_out_image_writeable(struct vf_instance *vf, struct mp_image *img)
|
|
|
|
{
|
2013-06-07 23:35:44 +00:00
|
|
|
struct mp_image_params *p = &vf->fmt_out.params;
|
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
|
|
|
assert(vf->fmt_out.configured);
|
2013-06-07 23:35:44 +00:00
|
|
|
assert(p->imgfmt == img->imgfmt);
|
|
|
|
assert(p->w == img->w && p->h == img->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
|
|
|
mp_image_pool_make_writeable(vf->out_pool, img);
|
2002-04-06 22:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2011-11-03 13:21:53 +00:00
|
|
|
static int vf_default_query_format(struct vf_instance *vf, unsigned int fmt)
|
|
|
|
{
|
|
|
|
return vf_next_query_format(vf, fmt);
|
2002-10-30 17:48:39 +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 struct mp_image *vf_default_filter(struct vf_instance *vf,
|
|
|
|
struct mp_image *mpi)
|
|
|
|
{
|
|
|
|
assert(!vf->filter_ext);
|
|
|
|
return mpi;
|
|
|
|
}
|
|
|
|
|
2013-01-14 18:19:23 +00:00
|
|
|
static void print_fmt(int msglevel, struct vf_format *fmt)
|
|
|
|
{
|
|
|
|
if (fmt && fmt->configured) {
|
2013-06-07 23:35:44 +00:00
|
|
|
struct mp_image_params *p = &fmt->params;
|
|
|
|
mp_msg(MSGT_VFILTER, msglevel, "%dx%d", p->w, p->h);
|
|
|
|
if (p->w != p->d_w || p->h != p->d_h)
|
|
|
|
mp_msg(MSGT_VFILTER, msglevel, "->%dx%d", p->d_w, p->d_h);
|
|
|
|
mp_msg(MSGT_VFILTER, msglevel, " %s %#x", mp_imgfmt_to_name(p->imgfmt),
|
2013-01-14 18:19:23 +00:00
|
|
|
fmt->flags);
|
2013-07-16 21:22:55 +00:00
|
|
|
mp_msg(MSGT_VFILTER, msglevel, " %s/%s", mp_csp_names[p->colorspace],
|
|
|
|
mp_csp_levels_names[p->colorlevels]);
|
2013-01-14 18:19:23 +00:00
|
|
|
} else {
|
|
|
|
mp_msg(MSGT_VFILTER, msglevel, "???");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void vf_print_filter_chain(int msglevel, struct vf_instance *vf)
|
|
|
|
{
|
|
|
|
if (!mp_msg_test(MSGT_VFILTER, msglevel))
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (vf_instance_t *f = vf; f; f = f->next) {
|
|
|
|
mp_msg(MSGT_VFILTER, msglevel, " [%s] ", f->info->name);
|
|
|
|
print_fmt(msglevel, &f->fmt_in);
|
|
|
|
if (f->next) {
|
|
|
|
mp_msg(MSGT_VFILTER, msglevel, " -> ");
|
|
|
|
print_fmt(msglevel, &f->fmt_out);
|
|
|
|
}
|
|
|
|
mp_msg(MSGT_VFILTER, msglevel, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-21 17:23:32 +00:00
|
|
|
static struct vf_instance *vf_open(struct MPOpts *opts, vf_instance_t *next,
|
|
|
|
const char *name, char **args)
|
2010-01-16 18:37:13 +00:00
|
|
|
{
|
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
|
|
|
struct m_obj_desc desc;
|
|
|
|
if (!m_obj_list_find(&desc, &vf_obj_list, bstr0(name))) {
|
|
|
|
mp_tmsg(MSGT_VFILTER, MSGL_ERR,
|
|
|
|
"Couldn't find video filter '%s'.\n", name);
|
|
|
|
return NULL;
|
2002-04-06 22:05:01 +00:00
|
|
|
}
|
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
|
|
|
vf_instance_t *vf = talloc_zero(NULL, struct vf_instance);
|
|
|
|
*vf = (vf_instance_t) {
|
|
|
|
.info = desc.p,
|
|
|
|
.opts = opts,
|
|
|
|
.next = next,
|
|
|
|
.config = vf_next_config,
|
|
|
|
.control = vf_next_control,
|
|
|
|
.query_format = vf_default_query_format,
|
|
|
|
.filter = vf_default_filter,
|
|
|
|
.out_pool = talloc_steal(vf, mp_image_pool_new(16)),
|
|
|
|
};
|
|
|
|
struct m_config *config = m_config_from_obj_desc(vf, &desc);
|
|
|
|
void *priv = NULL;
|
|
|
|
if (m_config_initialize_obj(config, &desc, &priv, &args) < 0)
|
|
|
|
goto error;
|
|
|
|
vf->priv = priv;
|
2013-10-23 17:06:42 +00:00
|
|
|
int retcode = vf->info->open(vf, (char *)args);
|
2013-09-20 12:00:19 +00:00
|
|
|
if (retcode < 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
|
|
|
goto error;
|
|
|
|
return vf;
|
|
|
|
|
|
|
|
error:
|
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(vf);
|
2002-04-06 22:05:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-03 13:21:53 +00:00
|
|
|
vf_instance_t *vf_open_filter(struct MPOpts *opts, vf_instance_t *next,
|
|
|
|
const char *name, char **args)
|
|
|
|
{
|
|
|
|
if (args && strcmp(args[0], "_oldargs_")) {
|
|
|
|
int i, l = 0;
|
|
|
|
for (i = 0; args && args[2 * i]; i++)
|
|
|
|
l += 1 + strlen(args[2 * i]) + 1 + strlen(args[2 * i + 1]);
|
|
|
|
l += strlen(name);
|
|
|
|
{
|
|
|
|
char str[l + 1];
|
|
|
|
char *p = str;
|
|
|
|
p += sprintf(str, "%s", name);
|
|
|
|
for (i = 0; args && args[2 * i]; i++)
|
|
|
|
p += sprintf(p, " %s=%s", args[2 * i], args[2 * i + 1]);
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_INFO, "%s[%s]\n",
|
|
|
|
mp_gtext("Opening video filter: "), str);
|
|
|
|
}
|
|
|
|
} else if (strcmp(name, "vo")) {
|
|
|
|
if (args && strcmp(args[0], "_oldargs_") == 0)
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_INFO, "%s[%s=%s]\n",
|
|
|
|
mp_gtext("Opening video filter: "), name, args[1]);
|
|
|
|
else
|
|
|
|
mp_msg(MSGT_VFILTER, MSGL_INFO, "%s[%s]\n",
|
|
|
|
mp_gtext("Opening video filter: "), name);
|
2003-03-15 18:01:02 +00:00
|
|
|
}
|
2013-07-21 17:23:32 +00:00
|
|
|
return vf_open(opts, next, name, args);
|
2002-04-10 23:23:36 +00:00
|
|
|
}
|
|
|
|
|
2004-12-18 14:06:35 +00:00
|
|
|
/**
|
|
|
|
* \brief adds a filter before the last one (which should be the vo filter).
|
|
|
|
* \param vf start of the filter chain.
|
|
|
|
* \param name name of the filter to add.
|
|
|
|
* \param args argument list for the filter.
|
|
|
|
* \return pointer to the filter instance that was created.
|
|
|
|
*/
|
2011-11-03 13:21:53 +00:00
|
|
|
vf_instance_t *vf_add_before_vo(vf_instance_t **vf, char *name, char **args)
|
|
|
|
{
|
|
|
|
struct MPOpts *opts = (*vf)->opts;
|
|
|
|
vf_instance_t *vo, *prev = NULL, *new;
|
|
|
|
// Find the last filter (should be vf_vo)
|
|
|
|
for (vo = *vf; vo->next; vo = vo->next)
|
|
|
|
prev = vo;
|
|
|
|
new = vf_open_filter(opts, vo, name, args);
|
|
|
|
if (prev)
|
|
|
|
prev->next = new;
|
|
|
|
else
|
|
|
|
*vf = new;
|
|
|
|
return new;
|
2004-12-18 14:06:35 +00:00
|
|
|
}
|
|
|
|
|
2002-04-06 22:05:01 +00:00
|
|
|
//============================================================================
|
|
|
|
|
2011-11-03 13:21:53 +00:00
|
|
|
unsigned int vf_match_csp(vf_instance_t **vfp, const unsigned int *list,
|
|
|
|
unsigned int preferred)
|
|
|
|
{
|
|
|
|
vf_instance_t *vf = *vfp;
|
2008-04-16 04:06:44 +00:00
|
|
|
struct MPOpts *opts = vf->opts;
|
2011-11-03 13:21:53 +00:00
|
|
|
const unsigned int *p;
|
|
|
|
unsigned int best = 0;
|
2002-04-11 20:56:17 +00:00
|
|
|
int ret;
|
2011-11-03 13:21:53 +00:00
|
|
|
if ((p = list))
|
|
|
|
while (*p) {
|
|
|
|
ret = vf->query_format(vf, *p);
|
2011-11-03 13:47:50 +00:00
|
|
|
mp_msg(MSGT_VFILTER, MSGL_V, "[%s] query(%s) -> %x\n",
|
|
|
|
vf->info->name, vo_format_name(*p), ret);
|
|
|
|
if (ret & VFCAP_CSP_SUPPORTED_BY_HW) {
|
2011-11-03 13:21:53 +00:00
|
|
|
best = *p;
|
|
|
|
break;
|
2011-11-03 13:47:50 +00:00
|
|
|
}
|
|
|
|
if (ret & VFCAP_CSP_SUPPORTED && !best)
|
|
|
|
best = *p;
|
2011-11-03 13:21:53 +00:00
|
|
|
++p;
|
|
|
|
}
|
|
|
|
if (best)
|
|
|
|
return best; // bingo, they have common csp!
|
2002-04-11 20:56:17 +00:00
|
|
|
// ok, then try with scale:
|
2011-11-03 13:21:53 +00:00
|
|
|
if (vf->info == &vf_info_scale)
|
|
|
|
return 0; // avoid infinite recursion!
|
|
|
|
vf = vf_open_filter(opts, vf, "scale", NULL);
|
|
|
|
if (!vf)
|
|
|
|
return 0; // failed to init "scale"
|
2002-04-11 20:56:17 +00:00
|
|
|
// try the preferred csp first:
|
2011-11-03 13:21:53 +00:00
|
|
|
if (preferred && vf->query_format(vf, preferred))
|
|
|
|
best = preferred;
|
|
|
|
else
|
|
|
|
// try the list again, now with "scaler" :
|
|
|
|
if ((p = list))
|
|
|
|
while (*p) {
|
|
|
|
ret = vf->query_format(vf, *p);
|
2011-11-03 13:47:50 +00:00
|
|
|
mp_msg(MSGT_VFILTER, MSGL_V, "[%s] query(%s) -> %x\n",
|
|
|
|
vf->info->name, vo_format_name(*p), ret);
|
|
|
|
if (ret & VFCAP_CSP_SUPPORTED_BY_HW) {
|
2011-11-03 13:21:53 +00:00
|
|
|
best = *p;
|
|
|
|
break;
|
|
|
|
}
|
2011-11-03 13:47:50 +00:00
|
|
|
if (ret & VFCAP_CSP_SUPPORTED && !best)
|
|
|
|
best = *p;
|
2011-11-03 13:21:53 +00:00
|
|
|
++p;
|
|
|
|
}
|
|
|
|
if (best)
|
|
|
|
*vfp = vf; // else uninit vf !FIXME!
|
2002-04-11 20:56:17 +00:00
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
// Used by filters to add a filtered frame to the output queue.
|
|
|
|
// Ownership of img is transferred from caller to the filter chain.
|
|
|
|
void vf_add_output_frame(struct vf_instance *vf, struct mp_image *img)
|
2006-07-06 06:58:17 +00:00
|
|
|
{
|
2013-07-16 21:22:55 +00:00
|
|
|
if (img) {
|
|
|
|
// vf_vo doesn't have output config
|
2013-07-18 11:37:24 +00:00
|
|
|
if (vf->fmt_out.configured)
|
|
|
|
vf_fix_img_params(img, &vf->fmt_out.params);
|
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_TARRAY_APPEND(vf, vf->out_queued, vf->num_out_queued, img);
|
2013-07-16 21:22:55 +00:00
|
|
|
}
|
2006-07-06 06:58:17 +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 struct mp_image *vf_dequeue_output_frame(struct vf_instance *vf)
|
|
|
|
{
|
|
|
|
struct mp_image *res = NULL;
|
|
|
|
if (vf->num_out_queued) {
|
|
|
|
res = vf->out_queued[0];
|
|
|
|
MP_TARRAY_REMOVE_AT(vf->out_queued, vf->num_out_queued, 0);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Input a frame into the filter chain.
|
|
|
|
// Return >= 0 on success, < 0 on failure (even if output frames were produced)
|
|
|
|
int vf_filter_frame(struct vf_instance *vf, struct mp_image *img)
|
|
|
|
{
|
|
|
|
assert(vf->fmt_in.configured);
|
2013-07-18 11:37:24 +00:00
|
|
|
vf_fix_img_params(img, &vf->fmt_in.params);
|
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
|
|
|
|
|
|
|
if (vf->filter_ext) {
|
|
|
|
return vf->filter_ext(vf, img);
|
|
|
|
} else {
|
|
|
|
vf_add_output_frame(vf, vf->filter(vf, img));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2006-07-06 06:58:17 +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
|
|
|
// Output the next queued image (if any) from the full filter chain.
|
|
|
|
struct mp_image *vf_chain_output_queued_frame(struct vf_instance *vf)
|
2006-07-06 06:58:17 +00:00
|
|
|
{
|
|
|
|
while (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
|
|
|
struct vf_instance *last = NULL;
|
|
|
|
for (struct vf_instance * cur = vf; cur; cur = cur->next) {
|
|
|
|
if (cur->num_out_queued)
|
|
|
|
last = cur;
|
|
|
|
}
|
2011-11-03 13:21:53 +00:00
|
|
|
if (!last)
|
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
|
|
|
return NULL;
|
|
|
|
struct mp_image *img = vf_dequeue_output_frame(last);
|
|
|
|
if (!last->next)
|
|
|
|
return img;
|
|
|
|
vf_filter_frame(last->next, img);
|
2006-07-06 06:58:17 +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 void vf_forget_frames(struct vf_instance *vf)
|
|
|
|
{
|
|
|
|
for (int n = 0; n < vf->num_out_queued; n++)
|
|
|
|
talloc_free(vf->out_queued[n]);
|
|
|
|
vf->num_out_queued = 0;
|
|
|
|
}
|
2006-07-06 06:58:17 +00:00
|
|
|
|
2013-01-20 02:03:40 +00:00
|
|
|
void vf_chain_seek_reset(struct vf_instance *vf)
|
|
|
|
{
|
|
|
|
vf->control(vf, VFCTRL_SEEK_RESET, NULL);
|
|
|
|
for (struct vf_instance *cur = vf; cur; cur = cur->next)
|
|
|
|
vf_forget_frames(cur);
|
|
|
|
}
|
|
|
|
|
2013-07-27 19:16:34 +00:00
|
|
|
int vf_reconfig_wrapper(struct vf_instance *vf, const struct mp_image_params *p,
|
2013-06-07 23:35:44 +00:00
|
|
|
int flags)
|
2005-03-01 20:21:58 +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
|
|
|
vf_forget_frames(vf);
|
|
|
|
mp_image_pool_clear(vf->out_pool);
|
|
|
|
|
2013-06-07 23:35:44 +00:00
|
|
|
vf->fmt_in = (struct vf_format) {
|
|
|
|
.params = *p,
|
|
|
|
.flags = flags,
|
|
|
|
};
|
|
|
|
vf->fmt_out = (struct vf_format){0};
|
|
|
|
|
|
|
|
int r;
|
|
|
|
if (vf->reconfig) {
|
2013-07-27 19:16:34 +00:00
|
|
|
struct mp_image_params params = *p;
|
|
|
|
r = vf->reconfig(vf, ¶ms, flags);
|
2013-06-07 23:35:44 +00:00
|
|
|
} else {
|
|
|
|
r = vf->config(vf, p->w, p->h, p->d_w, p->d_h, flags, p->imgfmt);
|
|
|
|
r = r ? 0 : -1;
|
|
|
|
}
|
|
|
|
if (r >= 0) {
|
|
|
|
vf->fmt_in.configured = 1;
|
|
|
|
if (vf->next)
|
|
|
|
vf->fmt_out = vf->next->fmt_in;
|
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
|
|
|
}
|
2005-12-16 18:32:58 +00:00
|
|
|
return r;
|
2005-03-01 20:21:58 +00:00
|
|
|
}
|
2003-04-19 02:48:53 +00:00
|
|
|
|
2013-06-07 23:35:44 +00:00
|
|
|
int vf_next_reconfig(struct vf_instance *vf, struct mp_image_params *p,
|
|
|
|
int outflags)
|
2011-11-03 13:21:53 +00:00
|
|
|
{
|
2008-04-16 04:06:44 +00:00
|
|
|
struct MPOpts *opts = vf->opts;
|
2013-06-07 23:35:44 +00:00
|
|
|
int flags = vf->next->query_format(vf->next, p->imgfmt);
|
2011-11-03 13:21:53 +00:00
|
|
|
if (!flags) {
|
|
|
|
// hmm. colorspace mismatch!!!
|
|
|
|
// let's insert the 'scale' filter, it does the job for us:
|
|
|
|
vf_instance_t *vf2;
|
|
|
|
if (vf->next->info == &vf_info_scale)
|
2013-06-07 23:35:44 +00:00
|
|
|
return -1; // scale->scale
|
2011-11-03 13:21:53 +00:00
|
|
|
vf2 = vf_open_filter(opts, vf->next, "scale", NULL);
|
|
|
|
if (!vf2)
|
2013-06-07 23:35:44 +00:00
|
|
|
return -1; // shouldn't happen!
|
2011-11-03 13:21:53 +00:00
|
|
|
vf->next = vf2;
|
2013-06-07 23:35:44 +00:00
|
|
|
flags = vf->next->query_format(vf->next, p->imgfmt);
|
2011-11-03 13:21:53 +00:00
|
|
|
if (!flags) {
|
|
|
|
mp_tmsg(MSGT_VFILTER, MSGL_ERR, "Cannot find matching colorspace, "
|
|
|
|
"even by inserting 'scale' :(\n");
|
2013-06-07 23:35:44 +00:00
|
|
|
return -1; // FAIL
|
2011-11-03 13:21:53 +00:00
|
|
|
}
|
2002-04-11 20:56:17 +00:00
|
|
|
}
|
2013-06-07 23:35:44 +00:00
|
|
|
return vf_reconfig_wrapper(vf->next, p, outflags);
|
|
|
|
}
|
|
|
|
|
|
|
|
int vf_next_config(struct vf_instance *vf,
|
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int voflags, unsigned int outfmt)
|
|
|
|
{
|
|
|
|
struct mp_image_params p = {
|
|
|
|
.imgfmt = outfmt,
|
|
|
|
.w = width,
|
|
|
|
.h = height,
|
|
|
|
.d_w = d_width,
|
|
|
|
.d_h = d_height,
|
|
|
|
.colorspace = vf->fmt_in.params.colorspace,
|
|
|
|
.colorlevels = vf->fmt_in.params.colorlevels,
|
vo_opengl: handle chroma location
Use the video decoder chroma location flags and render chroma locations
other than centered. Until now, we've always used the intuitive and
obvious centered chroma location, but H.264 uses something else.
FFmpeg provides a small overview in libavcodec/avcodec.h:
-----------
/**
* X X 3 4 X X are luma samples,
* 1 2 1-6 are possible chroma positions
* X X 5 6 X 0 is undefined/unknown position
*/
enum AVChromaLocation{
AVCHROMA_LOC_UNSPECIFIED = 0,
AVCHROMA_LOC_LEFT = 1, ///< mpeg2/4, h264 default
AVCHROMA_LOC_CENTER = 2, ///< mpeg1, jpeg, h263
AVCHROMA_LOC_TOPLEFT = 3, ///< DV
AVCHROMA_LOC_TOP = 4,
AVCHROMA_LOC_BOTTOMLEFT = 5,
AVCHROMA_LOC_BOTTOM = 6,
AVCHROMA_LOC_NB , ///< Not part of ABI
};
-----------
The visual difference is literally minimal, but since videophiles
apparently consider this detail as quality mark of a video renderer,
support it anyway. We don't bother with chroma locations other than
centered and left, though.
Not sure about correctness, but it's probably ok.
2013-06-08 00:15:24 +00:00
|
|
|
.chroma_location = vf->fmt_in.params.chroma_location,
|
2013-08-24 17:37:34 +00:00
|
|
|
.outputlevels = vf->fmt_in.params.outputlevels,
|
2013-06-07 23:35:44 +00:00
|
|
|
};
|
2013-07-16 21:22:55 +00:00
|
|
|
// Fix csp in case of pixel format change
|
|
|
|
mp_image_params_guess_csp(&p);
|
2013-06-07 23:35:44 +00:00
|
|
|
int r = vf_reconfig_wrapper(vf->next, &p, voflags);
|
|
|
|
return r < 0 ? 0 : 1;
|
2002-04-06 22:05:01 +00:00
|
|
|
}
|
|
|
|
|
2011-11-03 13:21:53 +00:00
|
|
|
int vf_next_control(struct vf_instance *vf, int request, void *data)
|
|
|
|
{
|
|
|
|
return vf->next->control(vf->next, request, data);
|
2002-04-06 22:05:01 +00:00
|
|
|
}
|
|
|
|
|
2011-11-03 13:21:53 +00:00
|
|
|
int vf_next_query_format(struct vf_instance *vf, unsigned int fmt)
|
|
|
|
{
|
2013-03-01 10:16:01 +00:00
|
|
|
return vf->next->query_format(vf->next, fmt);
|
2002-04-06 22:05:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
2011-11-03 13:21:53 +00:00
|
|
|
vf_instance_t *append_filters(vf_instance_t *last,
|
2008-04-25 10:58:12 +00:00
|
|
|
struct m_obj_settings *vf_settings)
|
|
|
|
{
|
2011-11-03 13:21:53 +00:00
|
|
|
struct MPOpts *opts = last->opts;
|
|
|
|
vf_instance_t *vf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (vf_settings) {
|
|
|
|
// We want to add them in the 'right order'
|
|
|
|
for (i = 0; vf_settings[i].name; i++)
|
|
|
|
/* NOP */;
|
|
|
|
for (i--; i >= 0; i--) {
|
|
|
|
//printf("Open filter %s\n",vf_settings[i].name);
|
|
|
|
vf = vf_open_filter(opts, last, vf_settings[i].name,
|
|
|
|
vf_settings[i].attribs);
|
2013-05-22 21:19:57 +00:00
|
|
|
if (vf) {
|
|
|
|
if (vf_settings[i].label)
|
|
|
|
vf->label = talloc_strdup(vf, vf_settings[i].label);
|
2011-11-03 13:21:53 +00:00
|
|
|
last = vf;
|
2013-05-22 21:19:57 +00:00
|
|
|
}
|
2011-11-03 13:21:53 +00:00
|
|
|
}
|
2002-04-06 22:05:01 +00:00
|
|
|
}
|
2011-11-03 13:21:53 +00:00
|
|
|
return last;
|
2002-04-06 22:05:01 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 21:19:57 +00:00
|
|
|
vf_instance_t *vf_find_by_label(vf_instance_t *chain, const char *label)
|
|
|
|
{
|
|
|
|
while (chain) {
|
|
|
|
if (chain->label && label && strcmp(chain->label, label) == 0)
|
|
|
|
return chain;
|
|
|
|
chain = chain->next;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-04-06 22:05:01 +00:00
|
|
|
//============================================================================
|
|
|
|
|
2011-11-03 13:21:53 +00:00
|
|
|
void vf_uninit_filter(vf_instance_t *vf)
|
|
|
|
{
|
|
|
|
if (vf->uninit)
|
|
|
|
vf->uninit(vf);
|
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_forget_frames(vf);
|
|
|
|
talloc_free(vf);
|
2002-04-20 22:24:19 +00:00
|
|
|
}
|
|
|
|
|
2011-11-03 13:21:53 +00:00
|
|
|
void vf_uninit_filter_chain(vf_instance_t *vf)
|
|
|
|
{
|
|
|
|
while (vf) {
|
|
|
|
vf_instance_t *next = vf->next;
|
|
|
|
vf_uninit_filter(vf);
|
|
|
|
vf = next;
|
2002-04-20 22:24:19 +00:00
|
|
|
}
|
|
|
|
}
|
vf_*: fix pts values passed to the next filter
Many video filters failed to calculate or even just pass through pts
values for their output frames. Fix this, and also make the two
remaining filters that called vf_next_put_image() twice for the same
input frame (vf_softpulldown, vf_telecine) use vf_queue_frame() so
that e.g. framestepping properly sees both frames.
Changed filters: vf_bmovl, vf_detc, vf_divtc, vf_filmdint, vf_ivtc,
vf_lavc, vf_phase, vf_pullup, vf_softpulldown, vf_telecine, vf_tile,
vf_tinterlace.
2011-04-23 16:56:47 +00:00
|
|
|
|
2013-01-22 12:28:31 +00:00
|
|
|
// When changing the size of an image that had old_w/old_h with
|
|
|
|
// DAR *d_width/*d_height to the new size new_w/new_h, adjust
|
|
|
|
// *d_width/*d_height such that the new image has the same pixel aspect ratio.
|
|
|
|
void vf_rescale_dsize(int *d_width, int *d_height, int old_w, int old_h,
|
|
|
|
int new_w, int new_h)
|
2012-12-26 20:08:54 +00:00
|
|
|
{
|
|
|
|
*d_width = *d_width * new_w / old_w;
|
|
|
|
*d_height = *d_height * new_h / old_h;
|
|
|
|
}
|
|
|
|
|
2013-09-26 14:05:46 +00:00
|
|
|
// Set *d_width/*d_height to display aspect ratio with the givem source size
|
|
|
|
void vf_set_dar(int *d_w, int *d_h, int w, int h, double dar)
|
|
|
|
{
|
|
|
|
*d_w = w;
|
|
|
|
*d_h = h;
|
|
|
|
if (dar > 0.01) {
|
|
|
|
*d_w = h * dar;
|
|
|
|
// we don't like horizontal downscale
|
|
|
|
if (*d_w < w) {
|
|
|
|
*d_w = w;
|
|
|
|
*d_h = w / dar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
vf_*: fix pts values passed to the next filter
Many video filters failed to calculate or even just pass through pts
values for their output frames. Fix this, and also make the two
remaining filters that called vf_next_put_image() twice for the same
input frame (vf_softpulldown, vf_telecine) use vf_queue_frame() so
that e.g. framestepping properly sees both frames.
Changed filters: vf_bmovl, vf_detc, vf_divtc, vf_filmdint, vf_ivtc,
vf_lavc, vf_phase, vf_pullup, vf_softpulldown, vf_telecine, vf_tile,
vf_tinterlace.
2011-04-23 16:56:47 +00:00
|
|
|
void vf_detc_init_pts_buf(struct vf_detc_pts_buf *p)
|
|
|
|
{
|
|
|
|
p->inpts_prev = MP_NOPTS_VALUE;
|
|
|
|
p->outpts_prev = MP_NOPTS_VALUE;
|
|
|
|
p->lastdelta = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static double vf_detc_adjust_pts_internal(struct vf_detc_pts_buf *p,
|
|
|
|
double pts, bool reset_pattern,
|
|
|
|
bool skip_frame, double delta,
|
|
|
|
double boundfactor_minus,
|
|
|
|
double increasefactor,
|
|
|
|
double boundfactor_plus)
|
|
|
|
{
|
|
|
|
double newpts;
|
|
|
|
|
|
|
|
if (pts == MP_NOPTS_VALUE)
|
|
|
|
return pts;
|
|
|
|
|
|
|
|
if (delta <= 0) {
|
|
|
|
if (p->inpts_prev == MP_NOPTS_VALUE)
|
|
|
|
delta = 0;
|
2011-11-03 13:21:53 +00:00
|
|
|
else if (pts == p->inpts_prev)
|
vf_*: fix pts values passed to the next filter
Many video filters failed to calculate or even just pass through pts
values for their output frames. Fix this, and also make the two
remaining filters that called vf_next_put_image() twice for the same
input frame (vf_softpulldown, vf_telecine) use vf_queue_frame() so
that e.g. framestepping properly sees both frames.
Changed filters: vf_bmovl, vf_detc, vf_divtc, vf_filmdint, vf_ivtc,
vf_lavc, vf_phase, vf_pullup, vf_softpulldown, vf_telecine, vf_tile,
vf_tinterlace.
2011-04-23 16:56:47 +00:00
|
|
|
delta = p->lastdelta;
|
|
|
|
else
|
|
|
|
delta = pts - p->inpts_prev;
|
|
|
|
}
|
|
|
|
p->inpts_prev = pts;
|
|
|
|
p->lastdelta = delta;
|
|
|
|
|
|
|
|
if (skip_frame)
|
|
|
|
return MP_NOPTS_VALUE;
|
|
|
|
|
2011-11-03 13:21:53 +00:00
|
|
|
/* detect bogus deltas and then passthru pts (possibly caused by seeking,
|
|
|
|
* or bad input) */
|
|
|
|
if (p->outpts_prev == MP_NOPTS_VALUE || reset_pattern || delta <= 0.0 ||
|
|
|
|
delta >= 0.5)
|
vf_*: fix pts values passed to the next filter
Many video filters failed to calculate or even just pass through pts
values for their output frames. Fix this, and also make the two
remaining filters that called vf_next_put_image() twice for the same
input frame (vf_softpulldown, vf_telecine) use vf_queue_frame() so
that e.g. framestepping properly sees both frames.
Changed filters: vf_bmovl, vf_detc, vf_divtc, vf_filmdint, vf_ivtc,
vf_lavc, vf_phase, vf_pullup, vf_softpulldown, vf_telecine, vf_tile,
vf_tinterlace.
2011-04-23 16:56:47 +00:00
|
|
|
newpts = pts;
|
2011-11-03 13:21:53 +00:00
|
|
|
else {
|
vf_*: fix pts values passed to the next filter
Many video filters failed to calculate or even just pass through pts
values for their output frames. Fix this, and also make the two
remaining filters that called vf_next_put_image() twice for the same
input frame (vf_softpulldown, vf_telecine) use vf_queue_frame() so
that e.g. framestepping properly sees both frames.
Changed filters: vf_bmovl, vf_detc, vf_divtc, vf_filmdint, vf_ivtc,
vf_lavc, vf_phase, vf_pullup, vf_softpulldown, vf_telecine, vf_tile,
vf_tinterlace.
2011-04-23 16:56:47 +00:00
|
|
|
// turn 5 frames into 4
|
|
|
|
newpts = p->outpts_prev + delta * increasefactor;
|
|
|
|
|
|
|
|
// bound to input pts in a sensible way; these numbers come because we
|
|
|
|
// map frames the following way when ivtc'ing:
|
|
|
|
// 0/30 -> 0/24 diff=0
|
|
|
|
// 1/30 -> 1/24 diff=1/120
|
|
|
|
// 2/30 -> -
|
|
|
|
// 3/30 -> 2/24 diff=-1/60
|
|
|
|
// 4/30 -> 3/24 diff=-1/120
|
|
|
|
if (newpts < pts - delta * boundfactor_minus)
|
|
|
|
newpts = pts - delta * boundfactor_minus;
|
|
|
|
if (newpts > pts + delta * boundfactor_plus)
|
|
|
|
newpts = pts + delta * boundfactor_plus;
|
|
|
|
if (newpts < p->outpts_prev)
|
2011-11-03 13:21:53 +00:00
|
|
|
newpts = p->outpts_prev; // damage control
|
vf_*: fix pts values passed to the next filter
Many video filters failed to calculate or even just pass through pts
values for their output frames. Fix this, and also make the two
remaining filters that called vf_next_put_image() twice for the same
input frame (vf_softpulldown, vf_telecine) use vf_queue_frame() so
that e.g. framestepping properly sees both frames.
Changed filters: vf_bmovl, vf_detc, vf_divtc, vf_filmdint, vf_ivtc,
vf_lavc, vf_phase, vf_pullup, vf_softpulldown, vf_telecine, vf_tile,
vf_tinterlace.
2011-04-23 16:56:47 +00:00
|
|
|
}
|
|
|
|
p->outpts_prev = newpts;
|
|
|
|
|
|
|
|
return newpts;
|
|
|
|
}
|
|
|
|
|
|
|
|
double vf_detc_adjust_pts(struct vf_detc_pts_buf *p, double pts,
|
|
|
|
bool reset_pattern, bool skip_frame)
|
|
|
|
{
|
|
|
|
// standard telecine (see above)
|
|
|
|
return vf_detc_adjust_pts_internal(p, pts, reset_pattern, skip_frame,
|
|
|
|
0, 0.5, 1.25, 0.25);
|
|
|
|
}
|
|
|
|
|
|
|
|
double vf_softpulldown_adjust_pts(struct vf_detc_pts_buf *p, double pts,
|
|
|
|
bool reset_pattern, bool skip_frame,
|
|
|
|
int last_frame_duration)
|
|
|
|
{
|
|
|
|
// for the softpulldown filter we get:
|
|
|
|
// 0/60 -> 0/30
|
|
|
|
// 2/60 -> 1/30
|
|
|
|
// 5/60 -> 2/30
|
|
|
|
// 7/60 -> 3/30, 4/30
|
|
|
|
return vf_detc_adjust_pts_internal(p, pts, reset_pattern, skip_frame,
|
|
|
|
0, 1.0 / last_frame_duration,
|
|
|
|
2.0 / last_frame_duration,
|
|
|
|
1.0 / last_frame_duration);
|
|
|
|
}
|