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