annotate DOCS/tech/libmpcodecs.txt @ 9170:bcf4bf10f9c7

hopefully better uninit check
author arpi
date Wed, 29 Jan 2003 23:28:55 +0000
parents 6a11d77bef9a
children f7106682cac8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7397
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
1 The libMPcodecs API details, hints - by A'rpi
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
2 ==================================
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
3
7399
56bb20a00bc9 cross-ref
arpi
parents: 7397
diff changeset
4 See also: colorspaces.txt, codec-devel.txt, dr-methods.txt, codecs.conf.txt
7397
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
5
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
6 The VIDEO path:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
7 ===============
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
8
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
9 [MPlayer core]
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
10 | (1)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
11 _____V______ (2) /~~~~~~~~~~\ (3,4) |~~~~~~|
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
12 | | -----> | vd_XXX.c | -------> | vd.c |
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
13 | decvideo | \__________/ <-(3a)-- |______|
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
14 | | -----, ,.............(3a,4a).....:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
15 ~~~~~~~~~~~~ (6) V V
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
16 /~~~~~~~~\ /~~~~~~~~\ (8)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
17 | vf_X.c | --> | vf_Y.c | ----> vf_vo.c / ve_XXX.c
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
18 \________/ \________/
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
19 | ^
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
20 (7) | |~~~~~~| : (7a)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
21 `-> | vf.c |...:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
22 |______|
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
23
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
24 Short description of video path:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
25 1. mplayer/mencoder core requests the decoding of a compressed video frame:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
26 calls decvideo.c::decode_video()
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
27
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
28 2. decode_video() calls the previously ( init_video() ) selected video codec
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
29 (vd_XXXX.c file, where XXXX == vfm name, see the 'driver' line of codecs.conf)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
30
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
31 3. the codec should initialize output device before decoding the first frame,
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
32 it may happen in init() or at the middle of the first decode(). see 3.a.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
33 it means calling vd.c::mpcodecs_config_vo() with the image dimensions,
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
34 and the _preferred_ (mean: internal, native, best) colorspace.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
35 NOTE: this colorspace may not be equal to the actually used colorspace, it's
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
36 just a _hint_ for the csp matching algorithm, and mainly used _only_ when
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
37 csp conversion is required, as input format of the converter.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
38
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
39 3.a. selecting the best output colorspace:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
40 the vd.c::mpcodecs_config_vo() function will go through the outfmt list
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
41 defined by codecs.conf's 'out' lines, and query both vd (codec) and vo
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
42 (output device/filter/encoder) if it's supported or not.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
43
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
44 For the vo, it calls the query_format() func of vf_XXX.c or ve_XXX.c.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
45 It should return a set of feature flags, the most important ons for this
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
46 stage are: VFCAP_CSP_SUPPORTED (csp supported directly or by conversion)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
47 and VFCAP_CSP_SUPPORTED_BY_HW (csp supported WITHOUT any conversion).
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
48
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
49 For the vd (codec), control() with VDCTRL_QUERY_FORMAT will be called.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
50 If it doesn't implement VDCTRL_QUERY_FORMAT, (ie answers CONTROL_UNKNOWN
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
51 or CONTROL_NA) it will be assumed to be CONTROL_TRUE (csp supported)!
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
52
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
53 So, by default, if the list of supported colorspaces is constant, doesn't
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
54 depend on the actual file's/stream's header, it's enough to list them
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
55 in codecs.conf ('out' field), and don't implement VDCTRL_QUERY_FORMAT.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
56 It's the case for the most codecs.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
57
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
58 If the supported csp list depends on the file being decoded, list the
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
59 possible out formats (colorspaces) in codecs.conf, and implement the
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
60 VDCTRL_QUERY_FORMAT to test the availability of the given csp for the
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
61 given video file/stream.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
62
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
63 The vd.c core will find the best matching colorspace, depending on the
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
64 VFCAP_CSP_SUPPORTED_BY_HW flag (see vfcap.h). If no match at all, it
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
65 will try again with the 'scale' filter inserted between vd and vo.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
66 If still no match, it will fail :(
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
67
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
68 4. requesting buffer for the decoded frame:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
69 The codec have to call mpcodecs_get_image() with proper imgtype & imgflag.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
70 It will find the optimal buffering setup (preferred stride, alignment etc)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
71 and return a pointer to the allocated and filled up mpi (mp_image_t*) struct.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
72 The 'imgtype' controls the buffering setup, ie STATIC (just one buffer,
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
73 it 'remembers' its contents between frames), TEMP (write-only, full update),
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
74 EXPORT (memory allocation is done by the codec, not recommended) and so on.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
75 The 'imgflags' set up the limits for the buffer, ie stride limitations,
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
76 readability, remembering content etc. See mp_image.h for the short descr.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
77 See dr-methods.txt for the explanation of buffer importing and mpi imgtypes.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
78
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
79 Always try to implement stride support! (stride == bytes per line)
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
80 If no stride support, then stride==bytes_per_pixel*image_width.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
81 If you have stride supoprt in your decoder, use the mpi->stride[] value
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
82 for the byte_per_line for each plane.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
83 Also take care of other imgflags, like MP_IMGFLAG_PRESERVE and
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
84 MP_IMGFLAG_READABLE, MP_IMGFLAG_COMMON_STRIDE and MP_IMGFLAG_COMMON_PLANE!
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
85 The file mp_image.h contains description of flags in comments, read it!
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
86 Ask for help on -dev-eng, describing the behaviour your codec, if unsure.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
87
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
88 4.a. buffer allocation, vd.c::mpcodecs_get_image():
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
89 If the requested buffer imgtype!=EXPORT, then vd.c will try to do
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
90 direct rendering, ie. asks the next filter/vo for the buffer allocation.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
91 It's done by calling get_image() of the vf_XXX.c file.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
92 If it was successful, the imgflag MP_IMGFLAG_DIRECT will be set, and one
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
93 memcpy() will be saved when passing the data from vd to the next filter/vo.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
94 See dr-methods.txt for details and examples.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
95
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
96 5. decode the frame, to the mpi structure requested at 4, then return the mpi
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
97 to decvideo.c. Return NULL if the decoding failed or skipped frame.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
98
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
99 6. decvideo.c::decode_video() will now pass the 'mpi' to the next filter (vf_X).
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
100
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
101 7. the filter's (vf_X) put_image() then requests a new mpi buffer by calling
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
102 vf.c::vf_get_image().
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
103
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
104 7.a. vf.c::vf_get_image() will try to get direct rendering, by asking the
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
105 next fliter to do the buffer allocation (calls vf_Y's get_image()).
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
106 if it fails, it will fallback to normal system memory allocation.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
107
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
108 8. when we're over the whole filter chain (multiple filters can be connected,
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
109 even the same filter multiple times) then the last, 'leaf' filter will be
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
110 called. The only difference between leaf and non-leaf filter is that leaf
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
111 filter have to implement the whole filter api.
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
112 Leaf filters are now: vf_vo.c (wrapper over libvo) and ve_XXX.c (video
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
113 encoders used by mencoder).
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
114
8001
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
115 The VIDEO FILTER API:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
116 =====================
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
117 filename: vf_FILTERNAME.c
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
118
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
119 vf_info_t* info;
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
120 pointer to the filter description structure:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
121
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
122 const char *info; // description of the filter
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
123 const char *name; // short name of the filter, must be FILTERNAME
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
124 const char *author; // name and email/url of the author(s)
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
125 const char *comment;// comment, url to papers describing algo etc.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
126 int (*open)(struct vf_instance_s* vf,char* args);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
127 // pointer to the open() function:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
128
8020
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
129 Sample:
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
130
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
131 vf_info_t vf_info_foobar = {
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
132 "Universal Foo and Bar filter",
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
133 "foobar",
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
134 "Ms. Foo Bar",
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
135 "based on algo described at http://www.foo-bar.org",
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
136 open
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
137 };
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
138
8001
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
139 The open() function:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
140
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
141 open() is called when the filter is appended/inserted to the filter chain.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
142 it'll receive the handler (vf) and the optional filter parameters as
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
143 char* string. Note, that encoders (ve_*) and vo wrapper (vf_vo.c) have
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
144 non-string arg, but it's specially handled by mplayer/mencoder.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
145
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
146 The open() function should fill the vf_instance_t structure, with the
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
147 implemented functions' pointers (see bellow).
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
148 It can optinally allocate memory for its internal data (vf_priv_t) and
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
149 store the pointer in vf->priv.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
150
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
151 The open() func should parse (or at least check syntax) of parameters,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
152 and fail (return 0) if error.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
153
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
154 Sample:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
155
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
156 static int open(vf_instance_t *vf, char* args){
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
157 vf->query_format=query_format;
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
158 vf->config=config;
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
159 vf->put_image=put_image;
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
160 // allocate local storage:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
161 vf->priv=malloc(sizeof(struct vf_priv_s));
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
162 vf->priv->w=
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
163 vf->priv->h=-1;
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
164 if(args) // parse args:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
165 if(sscanf(args, "%d:%d", &vf->priv->w, &vf->priv->h)!=2) return 0;
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
166 return 1;
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
167 }
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
168
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
169 Functions in vf_instance_s:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
170
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
171 NOTE: All these are optional, their func pointer is either NULL or points to
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
172 a default implementation. If you implement them, don't forget to set
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
173 vf->FUNCNAME in your open() !
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
174
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
175 int (*query_format)(struct vf_instance_s* vf,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
176 unsigned int fmt);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
177
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
178 The query_format() func. is called one or more times before the config(),
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
179 to find out the capabilities and/or support status of a given colorspace (fmt).
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
180 For the return values, see vfcap.h!
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
181 Normally, a filter should return at least VFCAP_CSP_SUPPORTED for all supported
8020
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
182 colorspaces it accepts as input, and 0 for the unsupported ones.
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
183 If your filter does linear conversion, it should query the next filter,
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
184 and merge in its capability flags. Note: you should always ensure that the
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
185 next filter will accept at least one of your possible output colorspaces!
8001
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
186
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
187 Sample:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
188
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
189 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
190 switch(fmt){
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
191 case IMGFMT_YV12:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
192 case IMGFMT_I420:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
193 case IMGFMT_IYUV:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
194 case IMGFMT_422P:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
195 return vf_next_query_format(vf,IMGFMT_YUY2) & (~VFCAP_CSP_SUPPORTED_BY_HW);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
196 }
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
197 return 0;
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
198 }
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
199
8020
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
200 For the more complex case, when you have an N->M colorspace mapping matrix,
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
201 see vf_scale or vf_rgb2bgr for examples.
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
202
8001
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
203
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
204 int (*config)(struct vf_instance_s* vf,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
205 int width, int height, int d_width, int d_height,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
206 unsigned int flags, unsigned int outfmt);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
207
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
208 The config() is called to initialize/confugre the filter before using it.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
209 Its parameters are already well-known from libvo:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
210 width, height: size of the coded image
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
211 d_width, d_height: wanted display size (usually aspect corrected w/h)
8020
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
212 Filters should use width,height as input image dimension, but the
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
213 resizing filters (crop, expand, scale, rotate, etc) should update
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
214 d_width/d_height (display size) to preserve the correct aspect ratio!
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
215 Filters should not rely on d_width, d_height as input parameters,
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
216 the only exception is when a filter replaces some libvo functionality
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
217 (like -vop scale with -zoom, or OSD rendering wiht -vop expand).
8001
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
218 flags: the "good" old flags set of libvo:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
219 0x01 - force fullscreen (-fs)
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
220 0x02 - allow mode switching (-vm)
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
221 0x04 - allow software scaling (-zoom)
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
222 0x08 - flipping (-flip)
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
223 (Usually you don't have to worry about flags, just pass it to next config.)
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
224 outfmt: the selected colorspace/pixelformat. You'll receive images in this
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
225 format.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
226
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
227 Sample:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
228
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
229 static int config(struct vf_instance_s* vf,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
230 int width, int height, int d_width, int d_height,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
231 unsigned int flags, unsigned int outfmt){
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
232 // use d_width/d_height if not set by user:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
233 if(vf->priv->w==-1) vf->priv->w=d_width;
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
234 if(vf->priv->h==-1) vf->priv->h=d_width;
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
235 // initialize your filter code
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
236 ...
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
237 // ok now config the rest of the filter chain, with our output parameters:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
238 return vf_next_config(vf,vf->priv->w,vf->priv->h,d_width,d_height,flags,outfmt);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
239 }
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
240
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
241 void (*uninit)(struct vf_instance_s* vf);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
242
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
243 Okey, uninit() is the simplest, it's called at the end. You can free your
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
244 private buffers etc here.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
245
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
246 int (*put_image)(struct vf_instance_s* vf,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
247 mp_image_t *mpi);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
248
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
249 Ah, put_image(). This is the main filter function it should convert/filter/
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
250 transform the image data from one format/size/color/whatever to another.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
251 Its input parameter is an mpi (mplayer image) structure, see mp_image.h.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
252 Your filter has to request a new image buffer for the output, using the
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
253 vf_get_image() function. NOTE: even if you don't want to modify the image,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
254 just pass it to the next filter, you have to either
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
255 - do not implement put_image() at all - then it will be skipped
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
256 - request a new image with type==EXPORT and copy the pointers
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
257 NEVER pass the mpi as-is, it's local to filters and may cause trouble.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
258
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
259 If you completely copy/transform the image, then you probably want this:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
260
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
261 dmpi=vf_get_image(vf->next,mpi->imgfmt,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
262 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
263 vf->priv->w, vf->priv->h);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
264
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
265 It will allocate a new image, and return an mp_image structure filled by
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
266 buffer pointers and stride (bytes per line) values, in size of vf->priv->w
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
267 times vf->priv->h. If your filter cannot handle stride, then left out
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
268 MP_IMGFLAG_ACCEPT_STRIDE. Note, that you can do this, but it isn't recommended,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
269 the whole video path is designed to use strides to get optimal throughput.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
270 If your filter allocates output image buffers, then use MP_IMGTYPE_EXPORT,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
271 and fill the returned dmpi's planes[], stride[] with your buffer parameters.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
272 Note, it is not recommended (no direct rendering), so if you can, use
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
273 vf_get_image() for buffer allocation!
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
274 For other image types and flags see mp_image.h, it has comments.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
275 If you are unsure, feel free to ask on the -dev-eng maillist. Please
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
276 describe the behaviour of your filter, an dits limitations, so we can
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
277 suggest the optimal buffer type + flags for your code.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
278
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
279 Now, that you have the input (mpi) and output (dmpi) buffers, you can do
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
280 the conversion. If you didn't notice yet, mp_image has some useful info
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
281 fields, may help you a lot creating if() or for() structures:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
282 flags: MP_IMGFLAG_PLANAR, MP_IMGFLAG_YUV, MP_IMGFLAG_SWAPPED
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
283 helps you to handle various pixel formats in single code.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
284 bpp: bits per pixel
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
285 WARNING! It's number of bits _allocated_ to store a pixel,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
286 it is not the number of bits actually used to keep colors!
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
287 So, it's 16 for both 15 and 16bit color depth, and is 32 for
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
288 32bpp (actually 24bit color depth) mode!
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
289 It's 1 for 1bpp, 9 for YVU9, and is 12 for YV12 mode. Get it?
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
290 For planar formats, you also have chroma_width, chroma_height and
8020
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
291 chroma_x_shift, chroma_y_shift too, they specify the chroma subsampling
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
292 for yuv formats:
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
293 chroma_width = luma_width >>chroma_x_shift;
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
294 chroma_height= luma_height>>chroma_y_shift;
8001
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
295
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
296 If you're done, call the rest of the filter chain to process your output
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
297 image:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
298 return vf_next_put_image(vf,dmpi);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
299
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
300
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
301 Ok, the rest is for advanced functionality only:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
302
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
303 int (*control)(struct vf_instance_s* vf,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
304 int request, void* data);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
305
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
306 You can control the filter in runtime from mplayer/mencoder/dec_video:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
307 #define VFCTRL_QUERY_MAX_PP_LEVEL 4 /* test for postprocessing support (max level) */
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
308 #define VFCTRL_SET_PP_LEVEL 5 /* set postprocessing level */
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
309 #define VFCTRL_SET_EQUALIZER 6 /* set color options (brightness,contrast etc) */
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
310 #define VFCTRL_GET_EQUALIZER 8 /* gset color options (brightness,contrast etc) */
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
311 #define VFCTRL_DRAW_OSD 7
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
312 #define VFCTRL_CHANGE_RECTANGLE 9 /* Change the rectangle boundaries */
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
313
8020
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
314
8001
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
315 void (*get_image)(struct vf_instance_s* vf,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
316 mp_image_t *mpi);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
317
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
318 This is for direct rendering support, works the same way as in libvo drivers.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
319 It makes in-place pixel modifications possible.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
320 If you implement it (vf->get_image!=NULL) then it will be called to do the
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
321 buffer allocation. You SHOULD check the buffer restrictions (stride, type,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
322 readability etc) and if all OK, then allocate the requested buffer using
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
323 the vf_get_image() func and copying the buffer pointers.
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
324
8020
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
325 NOTE: You HAVE TO save dmpi pointer, as you'll need it in put_image() later.
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
326 It is not guaranteed that you'll get the same mpi for put_image() as in
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
327 get_image() (think of out-of-order decoding, get_image is called in decoding
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
328 order, while put_image is called for display) so the only safe place to save
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
329 it is in the mpi struct itself: mpi->priv=(void*)dmpi;
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
330
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
331
8001
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
332 void (*draw_slice)(struct vf_instance_s* vf,
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
333 unsigned char** src, int* stride, int w,int h, int x, int y);
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
334
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
335 It's the good old draw_slice callback, already known from libvo.
8020
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
336 If your filter can operate on partial images, you can implement this one
8001
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
337 to improve performance (cache utilization).
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
338
8020
6a11d77bef9a - some explanations suggested by Michael & Rich
arpi
parents: 8001
diff changeset
339 Ah, and there is two set of capability/requirement flags (vfcap.h type)
8001
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
340 in vf_instance_t, used by default query_format() implementation, and by
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
341 the automatic colorspace/stride matching code (vf_next_config()).
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
342
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
343 // caps:
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
344 unsigned int default_caps; // used by default query_format()
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
345 unsigned int default_reqs; // used by default config()
f02197bd1409 some docs about video filter api
arpi
parents: 7399
diff changeset
346
7397
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
347
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
348 The AUDIO path:
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
349 ===============
379e379bd4f4 some words and drawing about video path
arpi
parents:
diff changeset
350 TODO!!!