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.
|
|
|
|
*/
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#ifndef MPLAYER_VF_H
|
|
|
|
#define MPLAYER_VF_H
|
2002-04-06 22:05:01 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include <stdbool.h>
|
2008-03-06 08:34:50 +00:00
|
|
|
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/mp_image.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/common.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
|
|
|
|
#include "video/vfcap.h"
|
2011-11-03 13:21:53 +00:00
|
|
|
|
2008-04-16 04:06:44 +00:00
|
|
|
struct MPOpts;
|
2013-12-21 16:43:25 +00:00
|
|
|
struct mpv_global;
|
2008-04-24 02:49:44 +00:00
|
|
|
struct vf_instance;
|
2002-04-06 22:05:01 +00:00
|
|
|
struct vf_priv_s;
|
2013-12-07 18:32:44 +00:00
|
|
|
struct m_obj_settings;
|
2002-04-06 22:05:01 +00:00
|
|
|
|
2010-10-30 04:18:49 +00:00
|
|
|
typedef struct vf_info {
|
2013-10-23 17:06:42 +00:00
|
|
|
const char *description;
|
2002-04-06 22:05:01 +00:00
|
|
|
const char *name;
|
2013-12-03 23:01:38 +00:00
|
|
|
int (*open)(struct vf_instance *vf);
|
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
|
|
|
int priv_size;
|
|
|
|
const void *priv_defaults;
|
|
|
|
const struct m_option *options;
|
2013-12-21 19:04:49 +00:00
|
|
|
void (*print_help)(struct mp_log *log);
|
2002-04-06 22:05:01 +00:00
|
|
|
} vf_info_t;
|
|
|
|
|
2008-04-24 02:49:44 +00:00
|
|
|
typedef struct vf_instance {
|
2011-11-03 13:21:53 +00:00
|
|
|
const vf_info_t *info;
|
2013-06-07 23:35:44 +00:00
|
|
|
|
2013-12-07 18:35:55 +00:00
|
|
|
// Initialize the filter. The filter must set *out to the same image
|
|
|
|
// params as the images the filter functions will return for the given
|
|
|
|
// *in format.
|
|
|
|
// Note that by default, only formats reported as supported by query_format
|
|
|
|
// will be allowed for *in.
|
|
|
|
// Returns >= 0 on success, < 0 on error.
|
|
|
|
int (*reconfig)(struct vf_instance *vf, struct mp_image_params *in,
|
|
|
|
struct mp_image_params *out);
|
2013-06-07 23:35:44 +00:00
|
|
|
|
2013-12-05 21:56:51 +00:00
|
|
|
// Legacy variant, use reconfig instead.
|
|
|
|
int (*config)(struct vf_instance *vf,
|
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt);
|
|
|
|
|
2011-11-03 13:21:53 +00:00
|
|
|
int (*control)(struct vf_instance *vf, int request, void *data);
|
|
|
|
int (*query_format)(struct vf_instance *vf, unsigned int fmt);
|
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
|
|
|
|
|
|
|
// Filter mpi and return the result. The input mpi reference is owned by
|
|
|
|
// the filter, the returned reference is owned by the caller.
|
|
|
|
// Return NULL if the output frame is skipped.
|
|
|
|
struct mp_image *(*filter)(struct vf_instance *vf, struct mp_image *mpi);
|
|
|
|
|
|
|
|
// Like filter(), but can return an error code ( >= 0 means success). This
|
|
|
|
// callback is also more practical when the filter can return multiple
|
|
|
|
// output images. Use vf_add_output_frame() to queue output frames.
|
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
|
|
|
// Warning: this is called with mpi==NULL if there is no more input at
|
|
|
|
// all (i.e. the video has reached end of file condition). This
|
|
|
|
// can be used to output delayed or otherwise remaining images.
|
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
|
|
|
int (*filter_ext)(struct vf_instance *vf, struct mp_image *mpi);
|
|
|
|
|
2014-09-18 17:25:46 +00:00
|
|
|
// Produce an output frame. This is called after filter or filter_ext.
|
|
|
|
// You can add 0 or more frames with vf_add_output_frame(). (This allows
|
|
|
|
// distributing the filter load over time -> typically add at most 1 frame.)
|
|
|
|
// If this adds no frame (or is NULL), then the caller assumes that the
|
|
|
|
// filter needs new input.
|
|
|
|
// Return a negative value on error. (No more frames is not an error.)
|
|
|
|
// May be called multiple times, even if the filter gives no output.
|
|
|
|
int (*filter_out)(struct vf_instance *vf);
|
|
|
|
|
2015-01-03 02:01:58 +00:00
|
|
|
// Optional function that checks whether the filter needs additional
|
|
|
|
// input. This is for filters with asynchronous behavior: they filter
|
|
|
|
// frames in the background, and to get good pipelining behavior, new
|
|
|
|
// data should be fed, even if the playback core doesn't need any yet.
|
|
|
|
bool (*needs_input)(struct vf_instance *vf);
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
void (*uninit)(struct vf_instance *vf);
|
2006-07-06 06:58:17 +00:00
|
|
|
|
2013-05-22 21:19:57 +00:00
|
|
|
char *label;
|
2014-04-20 23:26:56 +00:00
|
|
|
bool autoinserted;
|
2013-05-22 21:19:57 +00:00
|
|
|
|
2013-12-07 18:33:11 +00:00
|
|
|
struct mp_image_params fmt_in, fmt_out;
|
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 mp_image_pool *out_pool;
|
2011-11-03 13:21:53 +00:00
|
|
|
struct vf_priv_s *priv;
|
2013-12-21 16:43:25 +00:00
|
|
|
struct mp_log *log;
|
2013-12-07 18:32:44 +00:00
|
|
|
struct mp_hwdec_info *hwdec;
|
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 mp_image **out_queued;
|
|
|
|
int num_out_queued;
|
2013-12-07 18:32:44 +00:00
|
|
|
|
2013-12-07 18:35:55 +00:00
|
|
|
// Caches valid output formats.
|
|
|
|
uint8_t last_outfmts[IMGFMT_END - IMGFMT_START];
|
|
|
|
|
2014-06-10 20:41:14 +00:00
|
|
|
struct vf_chain *chain;
|
2013-12-07 18:33:11 +00:00
|
|
|
struct vf_instance *next;
|
2002-04-06 22:05:01 +00:00
|
|
|
} vf_instance_t;
|
|
|
|
|
2013-12-07 18:32:44 +00:00
|
|
|
// A chain of video filters
|
|
|
|
struct vf_chain {
|
|
|
|
int initialized; // 0: no, 1: yes, -1: attempted to, but failed
|
|
|
|
|
2013-12-10 18:24:58 +00:00
|
|
|
struct vf_instance *first, *last;
|
|
|
|
|
2014-05-01 16:47:07 +00:00
|
|
|
struct mp_image_params input_params;
|
2014-05-01 21:15:50 +00:00
|
|
|
struct mp_image_params override_params; // input to first filter
|
2013-12-10 18:24:58 +00:00
|
|
|
struct mp_image_params output_params;
|
|
|
|
uint8_t allowed_output_formats[IMGFMT_END - IMGFMT_START];
|
2013-12-07 18:32:44 +00:00
|
|
|
|
2015-01-03 02:37:05 +00:00
|
|
|
double container_fps;
|
|
|
|
|
2013-12-21 16:43:25 +00:00
|
|
|
struct mp_log *log;
|
2013-12-07 18:32:44 +00:00
|
|
|
struct MPOpts *opts;
|
2013-12-21 16:43:25 +00:00
|
|
|
struct mpv_global *global;
|
2013-12-07 18:32:44 +00:00
|
|
|
struct mp_hwdec_info *hwdec;
|
2015-01-03 02:01:58 +00:00
|
|
|
|
|
|
|
// Call when the filter chain wants new processing (for filters with
|
|
|
|
// asynchronous behavior) - must be immutable once filters are created,
|
|
|
|
// since they are supposed to call it from foreign threads.
|
|
|
|
void (*wakeup_callback)(void *ctx);
|
|
|
|
void *wakeup_callback_ctx;
|
2013-12-07 18:32:44 +00:00
|
|
|
};
|
|
|
|
|
2011-11-03 13:21:53 +00:00
|
|
|
typedef struct vf_seteq {
|
2007-12-02 15:22:06 +00:00
|
|
|
const char *item;
|
2002-07-28 21:30:09 +00:00
|
|
|
int value;
|
|
|
|
} vf_equalizer_t;
|
|
|
|
|
2013-10-02 19:19:16 +00:00
|
|
|
enum vf_ctrl {
|
|
|
|
VFCTRL_SEEK_RESET = 1, // reset on picture and PTS discontinuities
|
|
|
|
VFCTRL_SET_EQUALIZER, // set color options (brightness,contrast etc)
|
|
|
|
VFCTRL_GET_EQUALIZER, // get color options (brightness,contrast etc)
|
|
|
|
VFCTRL_SCREENSHOT, // Take screenshot, arg is voctrl_screenshot_args
|
|
|
|
VFCTRL_INIT_OSD, // Filter OSD renderer present?
|
|
|
|
VFCTRL_SET_DEINTERLACE, // Set deinterlacing status
|
|
|
|
VFCTRL_GET_DEINTERLACE, // Get deinterlacing status
|
2014-04-13 14:04:23 +00:00
|
|
|
VFCTRL_GET_METADATA, // Get frame metadata from lavfi filters (e.g., cropdetect)
|
2013-10-02 19:19:16 +00:00
|
|
|
/* Hack to make the OSD state object available to vf_sub which
|
|
|
|
* access OSD/subtitle state outside of normal OSD draw time. */
|
|
|
|
VFCTRL_SET_OSD_OBJ,
|
|
|
|
};
|
2002-04-11 15:41:40 +00:00
|
|
|
|
2013-12-21 16:43:25 +00:00
|
|
|
struct vf_chain *vf_new(struct mpv_global *global);
|
2013-12-07 18:32:44 +00:00
|
|
|
void vf_destroy(struct vf_chain *c);
|
2014-05-01 21:15:50 +00:00
|
|
|
int vf_reconfig(struct vf_chain *c, const struct mp_image_params *params,
|
|
|
|
const struct mp_image_params *override_params);
|
2013-12-07 18:32:44 +00:00
|
|
|
int vf_control_any(struct vf_chain *c, int cmd, void *arg);
|
2014-04-13 14:00:11 +00:00
|
|
|
int vf_control_by_label(struct vf_chain *c, int cmd, void *arg, bstr label);
|
2013-12-07 18:32:44 +00:00
|
|
|
int vf_filter_frame(struct vf_chain *c, struct mp_image *img);
|
2014-05-01 17:29:17 +00:00
|
|
|
int vf_output_frame(struct vf_chain *c, bool eof);
|
2015-01-03 02:01:58 +00:00
|
|
|
int vf_needs_input(struct vf_chain *c);
|
2014-05-01 17:29:17 +00:00
|
|
|
struct mp_image *vf_read_output_frame(struct vf_chain *c);
|
2013-12-07 18:32:44 +00:00
|
|
|
void vf_seek_reset(struct vf_chain *c);
|
|
|
|
struct vf_instance *vf_append_filter(struct vf_chain *c, const char *name,
|
|
|
|
char **args);
|
2014-04-20 21:53:59 +00:00
|
|
|
void vf_remove_filter(struct vf_chain *c, struct vf_instance *vf);
|
2013-12-07 18:32:44 +00:00
|
|
|
int vf_append_filter_list(struct vf_chain *c, struct m_obj_settings *list);
|
|
|
|
struct vf_instance *vf_find_by_label(struct vf_chain *c, const char *label);
|
2014-05-04 14:07:43 +00:00
|
|
|
void vf_print_filter_chain(struct vf_chain *c, int msglevel,
|
|
|
|
struct vf_instance *vf);
|
2013-12-07 18:32:44 +00:00
|
|
|
|
|
|
|
// Filter internal API
|
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 mp_image *vf_alloc_out_image(struct vf_instance *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
|
|
|
bool vf_make_out_image_writeable(struct vf_instance *vf, struct mp_image *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
|
|
|
void vf_add_output_frame(struct vf_instance *vf, struct mp_image *img);
|
|
|
|
|
2002-04-06 22:05:01 +00:00
|
|
|
// default wrappers:
|
2010-05-29 14:15:55 +00:00
|
|
|
int vf_next_config(struct vf_instance *vf,
|
2011-11-03 13:21:53 +00:00
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt);
|
2010-05-29 14:15:55 +00:00
|
|
|
int vf_next_query_format(struct vf_instance *vf, unsigned int fmt);
|
2002-04-06 22:05:01 +00:00
|
|
|
|
2013-06-07 23:35:44 +00:00
|
|
|
|
2013-12-07 18:32:44 +00:00
|
|
|
// Helpers
|
2008-01-01 21:35:58 +00:00
|
|
|
|
2013-01-22 12:28:31 +00:00
|
|
|
void vf_rescale_dsize(int *d_width, int *d_height, int old_w, int old_h,
|
|
|
|
int new_w, int new_h);
|
2013-09-26 14:05:46 +00:00
|
|
|
void vf_set_dar(int *d_width, int *d_height, int w, int h, double dar);
|
2012-12-26 20:08:54 +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
|
|
|
struct vf_detc_pts_buf {
|
|
|
|
double inpts_prev, outpts_prev;
|
|
|
|
double lastdelta;
|
|
|
|
};
|
|
|
|
void vf_detc_init_pts_buf(struct vf_detc_pts_buf *p);
|
|
|
|
/* Adjust pts when detelecining.
|
|
|
|
* skip_frame: do not render this frame
|
|
|
|
* reset_pattern: set to 1 if the telecine pattern has reset due to scene cut
|
|
|
|
*/
|
|
|
|
double vf_detc_adjust_pts(struct vf_detc_pts_buf *p, double pts,
|
|
|
|
bool reset_pattern, bool skip_frame);
|
|
|
|
double vf_softpulldown_adjust_pts(struct vf_detc_pts_buf *p, double pts,
|
|
|
|
bool reset_pattern, bool skip_frame,
|
|
|
|
int last_frame_duration);
|
|
|
|
|
2008-02-22 09:09:46 +00:00
|
|
|
#endif /* MPLAYER_VF_H */
|