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