2008-01-28 22:09:21 +00:00
|
|
|
NOTE: If you want to implement a new native codec, please add it to
|
|
|
|
libavcodec. libmpcodecs is considered mostly deprecated, except for wrappers
|
|
|
|
around external libraries and codecs requiring binary support.
|
2008-01-28 12:11:41 +00:00
|
|
|
|
2002-09-15 01:18:39 +00:00
|
|
|
The libMPcodecs API details, hints - by A'rpi
|
|
|
|
==================================
|
|
|
|
|
2002-09-15 01:40:59 +00:00
|
|
|
See also: colorspaces.txt, codec-devel.txt, dr-methods.txt, codecs.conf.txt
|
2002-09-15 01:18:39 +00:00
|
|
|
|
|
|
|
The VIDEO path:
|
|
|
|
===============
|
|
|
|
|
|
|
|
[MPlayer core]
|
|
|
|
| (1)
|
2009-01-11 19:48:51 +00:00
|
|
|
______V______ (2) /~~~~~~~~~~\ (3,4) |~~~~~~|
|
2009-01-11 19:47:17 +00:00
|
|
|
| | -----> | vd_XXX.c | -------> | vd.c |
|
|
|
|
| dec_video | \__________/ <-(3a)-- |______|
|
|
|
|
| | -----, ,.............(3a,4a).....:
|
|
|
|
~~~~~~~~~~~~~ (6) V V
|
2005-05-31 22:35:40 +00:00
|
|
|
/~~~~~~~~\ /~~~~~~~~\ (8)
|
|
|
|
| vf_X.c | --> | vf_Y.c | ----> vf_vo.c / ve_XXX.c
|
|
|
|
\________/ \________/
|
|
|
|
| ^
|
|
|
|
(7) | |~~~~~~| : (7a)
|
|
|
|
`-> | vf.c |...:
|
|
|
|
|______|
|
2002-09-15 01:18:39 +00:00
|
|
|
|
|
|
|
Short description of video path:
|
2005-06-03 11:59:55 +00:00
|
|
|
1. MPlayer/MEncoder core requests the decoding of a compressed video frame:
|
2009-01-11 19:48:51 +00:00
|
|
|
calls dec_video.c::decode_video().
|
2002-09-15 01:18:39 +00:00
|
|
|
|
2009-01-11 19:48:51 +00:00
|
|
|
2. decode_video() calls the video codec previously selected in init_video().
|
2005-06-03 11:59:55 +00:00
|
|
|
(vd_XXX.c file, where XXX == vfm name, see the 'driver' line of codecs.conf)
|
2002-09-15 01:18:39 +00:00
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
3. The codec should initialize the output device before decoding the first
|
2009-01-11 19:48:51 +00:00
|
|
|
frame. It may happen in init() or at the middle of the first decode(), see
|
2005-06-03 11:59:55 +00:00
|
|
|
3a. It means calling vd.c::mpcodecs_config_vo() with the image dimensions,
|
2009-01-11 19:48:51 +00:00
|
|
|
and the _preferred_ (meaning: internal, native, best) colorspace.
|
|
|
|
NOTE: This colorspace may not be equal to the colorspace that is actually
|
|
|
|
used. It's just a _hint_ for the colorspace matching algorithm and mainly
|
|
|
|
used as input format of the converter, but _only_ when colorspace
|
|
|
|
conversion is required,
|
2002-09-15 01:18:39 +00:00
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
3a. Selecting the best output colorspace:
|
|
|
|
The vd.c::mpcodecs_config_vo() function will go through the outfmt list
|
2009-01-11 19:48:51 +00:00
|
|
|
defined by the 'out' lines in codecs.conf and query both vd (codec) and
|
|
|
|
vo (output device/filter/encoder) if the format is supported or not.
|
2002-09-15 01:18:39 +00:00
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
For the vo, it calls the query_format() function of vf_XXX.c or ve_XXX.c.
|
|
|
|
It should return a set of feature flags, the most important ones for this
|
2009-01-11 19:48:51 +00:00
|
|
|
stage are: VFCAP_CSP_SUPPORTED (colorspace supported directly or by
|
|
|
|
conversion) and VFCAP_CSP_SUPPORTED_BY_HW (colorspace supported
|
|
|
|
WITHOUT any conversion).
|
2002-09-15 01:18:39 +00:00
|
|
|
|
|
|
|
For the vd (codec), control() with VDCTRL_QUERY_FORMAT will be called.
|
2009-01-11 19:48:51 +00:00
|
|
|
If it does not implement VDCTRL_QUERY_FORMAT, (i.e. answers CONTROL_UNKNOWN
|
|
|
|
or CONTROL_NA), it is assumed to be CONTROL_TRUE (colorspace supported)!
|
2002-09-15 01:18:39 +00:00
|
|
|
|
2009-01-11 19:48:51 +00:00
|
|
|
So, by default, if the list of supported colorspaces is constant and does
|
|
|
|
not depend on the actual file/stream header, then it is enough to list the
|
|
|
|
formats in codecs.conf ('out' field) and not implement VDCTRL_QUERY_FORMAT.
|
2005-06-03 11:59:55 +00:00
|
|
|
This is the case for most codecs.
|
|
|
|
|
2009-01-11 19:48:51 +00:00
|
|
|
If the supported colorspace list depends on the file being decoded, list
|
|
|
|
the possible out formats (colorspaces) in codecs.conf and implement the
|
|
|
|
VDCTRL_QUERY_FORMAT to test the availability of the given colorspace for
|
|
|
|
the given video file/stream.
|
2005-06-03 11:59:55 +00:00
|
|
|
|
2002-09-15 01:18:39 +00:00
|
|
|
The vd.c core will find the best matching colorspace, depending on the
|
2009-01-11 19:48:51 +00:00
|
|
|
VFCAP_CSP_SUPPORTED_BY_HW flag (see vfcap.h). If no match can be found,
|
|
|
|
it will try again with the 'scale' filter inserted between vd and vo.
|
|
|
|
If this is unsuccessful, it will fail :(
|
2002-09-15 01:18:39 +00:00
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
4. Requesting buffer for the decoded frame:
|
|
|
|
The codec has to call mpcodecs_get_image() with proper imgtype & imgflag.
|
2002-09-15 01:18:39 +00:00
|
|
|
It will find the optimal buffering setup (preferred stride, alignment etc)
|
|
|
|
and return a pointer to the allocated and filled up mpi (mp_image_t*) struct.
|
2009-01-11 19:48:51 +00:00
|
|
|
The 'imgtype' controls the buffering setup, i.e. STATIC (just one buffer that
|
|
|
|
'remembers' its content between frames), TEMP (write-only, full update),
|
2002-09-15 01:18:39 +00:00
|
|
|
EXPORT (memory allocation is done by the codec, not recommended) and so on.
|
2005-06-03 11:59:55 +00:00
|
|
|
The 'imgflags' set up the limits for the buffer, i.e. stride limitations,
|
|
|
|
readability, remembering content etc. See mp_image.h for the short
|
|
|
|
description. See dr-methods.txt for the explanation of buffer
|
|
|
|
importing and mpi imgtypes.
|
|
|
|
|
2002-09-15 01:18:39 +00:00
|
|
|
Always try to implement stride support! (stride == bytes per line)
|
|
|
|
If no stride support, then stride==bytes_per_pixel*image_width.
|
2005-06-03 11:59:55 +00:00
|
|
|
If you have stride support in your decoder, use the mpi->stride[] value
|
2002-09-15 01:18:39 +00:00
|
|
|
for the byte_per_line for each plane.
|
|
|
|
Also take care of other imgflags, like MP_IMGFLAG_PRESERVE and
|
|
|
|
MP_IMGFLAG_READABLE, MP_IMGFLAG_COMMON_STRIDE and MP_IMGFLAG_COMMON_PLANE!
|
2005-06-03 11:59:55 +00:00
|
|
|
The file mp_image.h contains flag descriptions in comments, read it!
|
2009-01-11 19:48:51 +00:00
|
|
|
Ask for help on dev-eng, describing the behavior of your codec, if unsure.
|
2002-09-15 01:18:39 +00:00
|
|
|
|
|
|
|
4.a. buffer allocation, vd.c::mpcodecs_get_image():
|
|
|
|
If the requested buffer imgtype!=EXPORT, then vd.c will try to do
|
2009-01-11 19:48:51 +00:00
|
|
|
direct rendering, i.e. ask the next filter/vo for the buffer allocation.
|
2002-09-15 01:18:39 +00:00
|
|
|
It's done by calling get_image() of the vf_XXX.c file.
|
|
|
|
If it was successful, the imgflag MP_IMGFLAG_DIRECT will be set, and one
|
|
|
|
memcpy() will be saved when passing the data from vd to the next filter/vo.
|
|
|
|
See dr-methods.txt for details and examples.
|
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
5. Decode the frame, to the mpi structure requested in 4., then return the mpi
|
|
|
|
to decvideo.c. Return NULL if the decoding failed or skipped the frame.
|
2002-09-15 01:18:39 +00:00
|
|
|
|
|
|
|
6. decvideo.c::decode_video() will now pass the 'mpi' to the next filter (vf_X).
|
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
7. The filter's (vf_X) put_image() then requests a new mpi buffer by calling
|
2002-09-15 01:18:39 +00:00
|
|
|
vf.c::vf_get_image().
|
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
7.a. vf.c::vf_get_image() will try to get direct rendering by asking the
|
|
|
|
next filter to do the buffer allocation (calls vf_Y's get_image()).
|
|
|
|
If it fails, it will fall back on normal system memory allocation.
|
|
|
|
|
|
|
|
8. When we're past the whole filter chain (multiple filters can be connected,
|
|
|
|
even the same filter multiple times) then the last, 'leaf' filters will be
|
|
|
|
called. The only difference between leaf and non-leaf filters is that leaf
|
|
|
|
filters have to implement the whole filter API.
|
|
|
|
Currently leaf filters are: vf_vo.c (wrapper over libvo) and ve_XXX.c
|
|
|
|
(video encoders used by MEncoder).
|
2002-09-15 01:18:39 +00:00
|
|
|
|
2003-03-26 00:53:15 +00:00
|
|
|
|
|
|
|
Video Filters
|
|
|
|
=============
|
|
|
|
|
|
|
|
Video filters are plugin-like code modules implementing the interface
|
|
|
|
defined in vf.h.
|
|
|
|
|
|
|
|
Basically it means video output manipulation, i.e. these plugins can
|
2005-06-03 11:59:55 +00:00
|
|
|
modify the image and the image properties (size, colorspace, etc) between
|
2003-03-26 00:53:15 +00:00
|
|
|
the video decoders (vd.h) and the output layer (libvo or video encoders).
|
|
|
|
|
|
|
|
The actual API is a mixture of the video decoder (vd.h) and libvo
|
|
|
|
(video_out.h) APIs.
|
|
|
|
|
|
|
|
main differences:
|
|
|
|
- vf plugins may be "loaded" multiple times, with different parameters
|
|
|
|
and context - it's new in MPlayer, old APIs weren't reentrant.
|
|
|
|
- vf plugins don't have to implement all functions - all functions have a
|
|
|
|
'fallback' version, so the plugins only override these if wanted.
|
|
|
|
- Each vf plugin has its own get_image context, and they can interchange
|
|
|
|
images/buffers using these get_image/put_image calls.
|
|
|
|
|
|
|
|
|
2002-10-31 14:25:41 +00:00
|
|
|
The VIDEO FILTER API:
|
|
|
|
=====================
|
|
|
|
filename: vf_FILTERNAME.c
|
|
|
|
|
|
|
|
vf_info_t* info;
|
|
|
|
pointer to the filter description structure:
|
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
const char *info; // description of the filter
|
|
|
|
const char *name; // short name of the filter, must be FILTERNAME
|
2009-01-11 19:48:51 +00:00
|
|
|
const char *author; // name and email/URL of the author(s)
|
|
|
|
const char *comment; // comment, URL to papers describing algorithm etc.
|
2010-05-29 14:15:55 +00:00
|
|
|
int (*open)(struct vf_instance *vf,char* args);
|
2005-06-03 11:59:55 +00:00
|
|
|
// pointer to the open() function:
|
2002-10-31 14:25:41 +00:00
|
|
|
|
2002-11-01 01:32:30 +00:00
|
|
|
Sample:
|
|
|
|
|
|
|
|
vf_info_t vf_info_foobar = {
|
|
|
|
"Universal Foo and Bar filter",
|
|
|
|
"foobar",
|
|
|
|
"Ms. Foo Bar",
|
2005-06-03 11:59:55 +00:00
|
|
|
"based on algorithm described at http://www.foo-bar.org",
|
2002-11-01 01:32:30 +00:00
|
|
|
open
|
|
|
|
};
|
|
|
|
|
2002-10-31 14:25:41 +00:00
|
|
|
The open() function:
|
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
open() is called when the filter is appended/inserted in the filter chain.
|
|
|
|
It'll receive the handler (vf) and the optional filter parameters as
|
|
|
|
char* string. Note that encoders (ve_*) and vo wrapper (vf_vo.c) have
|
|
|
|
non-string arg, but it's specially handled by MPlayer/MEncoder.
|
|
|
|
|
2009-01-11 19:48:51 +00:00
|
|
|
The open() function should fill the vf_instance_t structure with the
|
2005-06-03 11:59:55 +00:00
|
|
|
implemented functions' pointers (see below).
|
|
|
|
It can optionally allocate memory for its internal data (vf_priv_t) and
|
2002-10-31 14:25:41 +00:00
|
|
|
store the pointer in vf->priv.
|
2005-06-03 11:59:55 +00:00
|
|
|
|
2009-01-11 19:48:51 +00:00
|
|
|
The open() function should parse (or at least check syntax of) parameters,
|
|
|
|
and fail (return 0) on error.
|
2002-10-31 14:25:41 +00:00
|
|
|
|
|
|
|
Sample:
|
|
|
|
|
2009-01-11 19:48:51 +00:00
|
|
|
static int open(vf_instance_t *vf, char* args)
|
|
|
|
{
|
|
|
|
vf->query_format = query_format;
|
|
|
|
vf->config = config;
|
|
|
|
vf->put_image = put_image;
|
2002-10-31 14:25:41 +00:00
|
|
|
// allocate local storage:
|
2009-01-11 19:48:51 +00:00
|
|
|
vf->priv = malloc(sizeof(struct vf_priv_s));
|
|
|
|
vf->priv->w =
|
|
|
|
vf->priv->h = -1;
|
2002-10-31 14:25:41 +00:00
|
|
|
if(args) // parse args:
|
2005-06-03 11:59:55 +00:00
|
|
|
if(sscanf(args, "%d:%d", &vf->priv->w, &vf->priv->h)!=2) return 0;
|
2002-10-31 14:25:41 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-01-15 03:07:09 +00:00
|
|
|
Functions in vf_instance:
|
2002-10-31 14:25:41 +00:00
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
NOTE: All these are optional, their function pointer is either NULL or points
|
|
|
|
to a default implementation. If you implement them, don't forget to set
|
2002-10-31 14:25:41 +00:00
|
|
|
vf->FUNCNAME in your open() !
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
int (*query_format)(struct vf_instance *vf, unsigned int fmt);
|
2002-10-31 14:25:41 +00:00
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
The query_format() function is called one or more times before the config(),
|
2002-10-31 14:25:41 +00:00
|
|
|
to find out the capabilities and/or support status of a given colorspace (fmt).
|
|
|
|
For the return values, see vfcap.h!
|
|
|
|
Normally, a filter should return at least VFCAP_CSP_SUPPORTED for all supported
|
2002-11-01 01:32:30 +00:00
|
|
|
colorspaces it accepts as input, and 0 for the unsupported ones.
|
|
|
|
If your filter does linear conversion, it should query the next filter,
|
2005-06-03 11:59:55 +00:00
|
|
|
and merge in its capability flags. Note: You should always ensure that the
|
2002-11-01 01:32:30 +00:00
|
|
|
next filter will accept at least one of your possible output colorspaces!
|
2002-10-31 14:25:41 +00:00
|
|
|
|
|
|
|
Sample:
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int query_format(struct vf_instance *vf, unsigned int fmt)
|
2009-01-11 19:48:51 +00:00
|
|
|
{
|
2002-10-31 14:25:41 +00:00
|
|
|
switch(fmt){
|
|
|
|
case IMGFMT_YV12:
|
|
|
|
case IMGFMT_I420:
|
|
|
|
case IMGFMT_IYUV:
|
|
|
|
case IMGFMT_422P:
|
2005-06-03 11:59:55 +00:00
|
|
|
return vf_next_query_format(vf,IMGFMT_YUY2) & (~VFCAP_CSP_SUPPORTED_BY_HW);
|
2002-10-31 14:25:41 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-11 19:48:51 +00:00
|
|
|
For the more complex case, when you have an N -> M colorspace mapping matrix,
|
2010-06-09 07:26:54 +00:00
|
|
|
see vf_scale or vf_format for examples.
|
2002-11-01 01:32:30 +00:00
|
|
|
|
2002-10-31 14:25:41 +00:00
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
int (*config)(struct vf_instance *vf,
|
2002-10-31 14:25:41 +00:00
|
|
|
int width, int height, int d_width, int d_height,
|
2005-06-03 11:59:55 +00:00
|
|
|
unsigned int flags, unsigned int outfmt);
|
2002-10-31 14:25:41 +00:00
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
The config() is called to initialize/configure the filter before using it.
|
2002-10-31 14:25:41 +00:00
|
|
|
Its parameters are already well-known from libvo:
|
|
|
|
width, height: size of the coded image
|
|
|
|
d_width, d_height: wanted display size (usually aspect corrected w/h)
|
2009-01-11 19:48:51 +00:00
|
|
|
Filters should use width, height as input image dimension, but the
|
2005-06-03 11:59:55 +00:00
|
|
|
resizing filters (crop, expand, scale, rotate, etc) should update
|
|
|
|
d_width/d_height (display size) to preserve the correct aspect ratio!
|
|
|
|
Filters should not rely on d_width, d_height as input parameters,
|
|
|
|
the only exception is when a filter replaces some libvo functionality
|
|
|
|
(like -vf scale with -zoom, or OSD rendering with -vf expand).
|
|
|
|
flags: the "good" old libvo flag set:
|
|
|
|
0x01 - force fullscreen (-fs)
|
|
|
|
0x02 - allow mode switching (-vm)
|
|
|
|
0x04 - allow software scaling (-zoom)
|
|
|
|
0x08 - flipping (-flip)
|
2002-10-31 14:25:41 +00:00
|
|
|
(Usually you don't have to worry about flags, just pass it to next config.)
|
|
|
|
outfmt: the selected colorspace/pixelformat. You'll receive images in this
|
|
|
|
format.
|
|
|
|
|
|
|
|
Sample:
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
static int config(struct vf_instance *vf,
|
2009-01-11 19:48:51 +00:00
|
|
|
int width, int height, int d_width, int d_height,
|
|
|
|
unsigned int flags, unsigned int outfmt)
|
|
|
|
{
|
|
|
|
// use d_width/d_height if not set by the user:
|
|
|
|
if (vf->priv->w == -1)
|
|
|
|
vf->priv->w = d_width;
|
|
|
|
if (vf->priv->h == -1)
|
|
|
|
vf->priv->h = d_height;
|
2002-10-31 14:25:41 +00:00
|
|
|
// initialize your filter code
|
|
|
|
...
|
2005-06-03 11:59:55 +00:00
|
|
|
// OK now config the rest of the filter chain, with our output parameters:
|
2002-10-31 14:25:41 +00:00
|
|
|
return vf_next_config(vf,vf->priv->w,vf->priv->h,d_width,d_height,flags,outfmt);
|
|
|
|
}
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
void (*uninit)(struct vf_instance *vf);
|
2002-10-31 14:25:41 +00:00
|
|
|
|
2009-01-11 19:48:51 +00:00
|
|
|
Okay, uninit() is the simplest, it's called at the end. You can free your
|
2002-10-31 14:25:41 +00:00
|
|
|
private buffers etc here.
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
int (*put_image)(struct vf_instance *vf, mp_image_t *mpi);
|
2002-10-31 14:25:41 +00:00
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
Ah, put_image(). This is the main filter function, it should convert/filter/
|
2002-10-31 14:25:41 +00:00
|
|
|
transform the image data from one format/size/color/whatever to another.
|
|
|
|
Its input parameter is an mpi (mplayer image) structure, see mp_image.h.
|
|
|
|
Your filter has to request a new image buffer for the output, using the
|
2005-06-03 11:59:55 +00:00
|
|
|
vf_get_image() function. NOTE: Even if you don't want to modify the image,
|
2002-10-31 14:25:41 +00:00
|
|
|
just pass it to the next filter, you have to either
|
2005-06-03 11:59:55 +00:00
|
|
|
- not implement put_image() at all - then it will be skipped
|
2002-10-31 14:25:41 +00:00
|
|
|
- request a new image with type==EXPORT and copy the pointers
|
2005-06-03 11:59:55 +00:00
|
|
|
NEVER pass the mpi as-is, it's local to the filters and may cause trouble.
|
2002-10-31 14:25:41 +00:00
|
|
|
|
|
|
|
If you completely copy/transform the image, then you probably want this:
|
|
|
|
|
2009-01-11 19:48:51 +00:00
|
|
|
dmpi = vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP,
|
|
|
|
MP_IMGFLAG_ACCEPT_STRIDE, vf->priv->w, vf->priv->h);
|
2002-10-31 14:25:41 +00:00
|
|
|
|
2009-01-11 19:48:51 +00:00
|
|
|
It will allocate a new image and return an mp_image structure filled by
|
2002-10-31 14:25:41 +00:00
|
|
|
buffer pointers and stride (bytes per line) values, in size of vf->priv->w
|
2005-06-03 11:59:55 +00:00
|
|
|
times vf->priv->h. If your filter cannot handle stride, then leave out
|
|
|
|
MP_IMGFLAG_ACCEPT_STRIDE. Note that you can do this, but it isn't recommended,
|
2002-10-31 14:25:41 +00:00
|
|
|
the whole video path is designed to use strides to get optimal throughput.
|
2009-01-11 19:48:51 +00:00
|
|
|
If your filter allocates output image buffers, then use MP_IMGTYPE_EXPORT
|
2002-10-31 14:25:41 +00:00
|
|
|
and fill the returned dmpi's planes[], stride[] with your buffer parameters.
|
2005-06-03 11:59:55 +00:00
|
|
|
Note, it is not recommended (no direct rendering), so if you can, use
|
2002-10-31 14:25:41 +00:00
|
|
|
vf_get_image() for buffer allocation!
|
|
|
|
For other image types and flags see mp_image.h, it has comments.
|
2009-01-11 19:48:51 +00:00
|
|
|
If you are unsure, feel free to ask on the dev-eng mailing list. Please
|
2005-06-03 11:59:55 +00:00
|
|
|
describe the behavior of your filter, and its limitations, so we can
|
2002-10-31 14:25:41 +00:00
|
|
|
suggest the optimal buffer type + flags for your code.
|
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
Now that you have the input (mpi) and output (dmpi) buffers, you can do
|
2002-10-31 14:25:41 +00:00
|
|
|
the conversion. If you didn't notice yet, mp_image has some useful info
|
2009-01-11 19:48:51 +00:00
|
|
|
fields. They may help you a lot creating if() or for() structures:
|
2002-10-31 14:25:41 +00:00
|
|
|
flags: MP_IMGFLAG_PLANAR, MP_IMGFLAG_YUV, MP_IMGFLAG_SWAPPED
|
2005-06-03 11:59:55 +00:00
|
|
|
helps you to handle various pixel formats in single code.
|
|
|
|
bpp: bits per pixel
|
|
|
|
WARNING! It's number of bits _allocated_ to store a pixel,
|
|
|
|
it is not the number of bits actually used to keep colors!
|
|
|
|
So it's 16 for both 15 and 16 bit color depth, and is 32 for
|
|
|
|
32bpp (actually 24 bit color depth) mode!
|
|
|
|
It's 1 for 1bpp, 9 for YVU9, and is 12 for YV12 mode. Get it?
|
2002-10-31 14:25:41 +00:00
|
|
|
For planar formats, you also have chroma_width, chroma_height and
|
2002-11-01 01:32:30 +00:00
|
|
|
chroma_x_shift, chroma_y_shift too, they specify the chroma subsampling
|
2009-01-11 19:48:51 +00:00
|
|
|
for YUV formats:
|
|
|
|
chroma_width = luma_width >> chroma_x_shift;
|
|
|
|
chroma_height = luma_height >> chroma_y_shift;
|
2002-10-31 14:25:41 +00:00
|
|
|
|
|
|
|
If you're done, call the rest of the filter chain to process your output
|
|
|
|
image:
|
|
|
|
return vf_next_put_image(vf,dmpi);
|
2005-06-03 11:59:55 +00:00
|
|
|
|
2002-10-31 14:25:41 +00:00
|
|
|
|
|
|
|
Ok, the rest is for advanced functionality only:
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
int (*control)(struct vf_instance *vf, int request, void* data);
|
2002-10-31 14:25:41 +00:00
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
You can control the filter at runtime from MPlayer/MEncoder/dec_video:
|
2002-10-31 14:25:41 +00:00
|
|
|
#define VFCTRL_QUERY_MAX_PP_LEVEL 4 /* test for postprocessing support (max level) */
|
2009-01-11 19:48:51 +00:00
|
|
|
#define VFCTRL_SET_PP_LEVEL 5 /* set postprocessing level */
|
|
|
|
#define VFCTRL_SET_EQUALIZER 6 /* set color options (brightness,contrast etc) */
|
|
|
|
#define VFCTRL_GET_EQUALIZER 8 /* get color options (brightness,contrast etc) */
|
|
|
|
#define VFCTRL_DRAW_OSD 7
|
2002-10-31 14:25:41 +00:00
|
|
|
|
2002-11-01 01:32:30 +00:00
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
void (*get_image)(struct vf_instance *vf, mp_image_t *mpi);
|
2005-06-03 11:59:55 +00:00
|
|
|
|
2002-10-31 14:25:41 +00:00
|
|
|
This is for direct rendering support, works the same way as in libvo drivers.
|
|
|
|
It makes in-place pixel modifications possible.
|
2009-01-11 19:48:51 +00:00
|
|
|
If you implement it (vf->get_image!=NULL), then it will be called to do the
|
2002-10-31 14:25:41 +00:00
|
|
|
buffer allocation. You SHOULD check the buffer restrictions (stride, type,
|
2005-06-03 11:59:55 +00:00
|
|
|
readability etc) and if everything is OK, then allocate the requested buffer
|
|
|
|
using the vf_get_image() function and copying the buffer pointers.
|
2002-10-31 14:25:41 +00:00
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
NOTE: You HAVE TO save the dmpi pointer, as you'll need it in put_image()
|
|
|
|
later on. It is not guaranteed that you'll get the same mpi for put_image() as
|
|
|
|
in get_image() (think of out-of-order decoding, get_image is called in decoding
|
2002-11-01 01:32:30 +00:00
|
|
|
order, while put_image is called for display) so the only safe place to save
|
|
|
|
it is in the mpi struct itself: mpi->priv=(void*)dmpi;
|
|
|
|
|
|
|
|
|
2010-05-29 14:15:55 +00:00
|
|
|
void (*draw_slice)(struct vf_instance *vf, unsigned char** src,
|
2009-01-11 19:48:51 +00:00
|
|
|
int* stride, int w,int h, int x, int y);
|
2002-10-31 14:25:41 +00:00
|
|
|
|
|
|
|
It's the good old draw_slice callback, already known from libvo.
|
2002-11-01 01:32:30 +00:00
|
|
|
If your filter can operate on partial images, you can implement this one
|
2002-10-31 14:25:41 +00:00
|
|
|
to improve performance (cache utilization).
|
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
Ah, and there are two sets of capability/requirement flags (vfcap.h type)
|
|
|
|
in vf_instance_t, used by the default query_format() implementation, and by
|
2002-10-31 14:25:41 +00:00
|
|
|
the automatic colorspace/stride matching code (vf_next_config()).
|
|
|
|
|
|
|
|
// caps:
|
|
|
|
unsigned int default_caps; // used by default query_format()
|
|
|
|
unsigned int default_reqs; // used by default config()
|
|
|
|
|
2005-06-03 11:59:55 +00:00
|
|
|
BTW, you should avoid using global or static variables to store filter instance
|
2009-01-11 19:48:51 +00:00
|
|
|
specific stuff, as filters might be used multiple times and in the future even
|
|
|
|
multiple streams might be possible.
|
2002-09-15 01:18:39 +00:00
|
|
|
|
2003-03-26 00:53:15 +00:00
|
|
|
|
2002-09-15 01:18:39 +00:00
|
|
|
The AUDIO path:
|
|
|
|
===============
|
|
|
|
TODO!!!
|