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