]> git.sesse.net Git - vlc/blob - include/vlc_filter.h
Allowed to give the list of prefered chroma to "text renderer".
[vlc] / include / vlc_filter.h
1 /*****************************************************************************
2  * vlc_filter.h: filter related structures and functions
3  *****************************************************************************
4  * Copyright (C) 1999-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *          Antoine Cellerier <dionoea at videolan dot org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef VLC_FILTER_H
26 #define VLC_FILTER_H 1
27
28 #include <vlc_es.h>
29 #include <vlc_picture.h>
30 #include <vlc_subpicture.h>
31 #include <vlc_mouse.h>
32
33 /**
34  * \file
35  * This file defines the structure and types used by video and audio filters
36  */
37
38 typedef struct filter_owner_sys_t filter_owner_sys_t;
39
40 /** Structure describing a filter
41  * @warning BIG FAT WARNING : the code relies on the first 4 members of
42  * filter_t and decoder_t to be the same, so if you have anything to add,
43  * do it at the end of the structure.
44  */
45 struct filter_t
46 {
47     VLC_COMMON_MEMBERS
48
49     /* Module properties */
50     module_t *          p_module;
51     filter_sys_t *      p_sys;
52
53     /* Input format */
54     es_format_t         fmt_in;
55
56     /* Output format of filter */
57     es_format_t         fmt_out;
58     bool                b_allow_fmt_out_change;
59
60     /* Filter configuration */
61     config_chain_t *    p_cfg;
62
63     union
64     {
65         struct
66         {
67             picture_t * (*pf_filter) ( filter_t *, picture_t * );
68             void        (*pf_flush)( filter_t * );
69             picture_t * (*pf_buffer_new) ( filter_t * );
70             void        (*pf_buffer_del) ( filter_t *, picture_t * );
71             /* Filter mouse state.
72              *
73              * If non-NULL, you must convert from output to input formats:
74              * - If VLC_SUCCESS is returned, the mouse state is propagated.
75              * - Otherwise, the mouse change is not propagated.
76              * If NULL, the mouse state is considered unchanged and will be
77              * propagated.
78              */
79             int         (*pf_mouse)( filter_t *, vlc_mouse_t *,
80                                      const vlc_mouse_t *p_old,
81                                      const vlc_mouse_t *p_new );
82         } video;
83 #define pf_video_filter     u.video.pf_filter
84 #define pf_video_flush      u.video.pf_flush
85 #define pf_video_mouse      u.video.pf_mouse
86 #define pf_video_buffer_new u.video.pf_buffer_new
87 #define pf_video_buffer_del u.video.pf_buffer_del
88
89         struct
90         {
91             block_t *   (*pf_filter) ( filter_t *, block_t * );
92             block_t *   (*pf_buffer_new) ( filter_t *, int );
93         } audio;
94 #define pf_audio_filter     u.audio.pf_filter
95 #define pf_audio_buffer_new u.audio.pf_buffer_new
96
97         struct
98         {
99             void        (*pf_blend) ( filter_t *,  picture_t *,
100                                       const picture_t *, int, int, int );
101         } blend;
102 #define pf_video_blend     u.blend.pf_blend
103
104         struct
105         {
106             subpicture_t * (*pf_source)    ( filter_t *, mtime_t );
107             subpicture_t * (*pf_buffer_new)( filter_t * );
108             void           (*pf_buffer_del)( filter_t *, subpicture_t * );
109             int            (*pf_mouse)     ( filter_t *,
110                                              const vlc_mouse_t *p_old,
111                                              const vlc_mouse_t *p_new,
112                                              const video_format_t * );
113         } sub;
114 #define pf_sub_source      u.sub.pf_source
115 #define pf_sub_buffer_new  u.sub.pf_buffer_new
116 #define pf_sub_buffer_del  u.sub.pf_buffer_del
117 #define pf_sub_mouse       u.sub.pf_mouse
118
119         struct
120         {
121             subpicture_t * (*pf_filter) ( filter_t *, subpicture_t * );
122         } subf;
123 #define pf_sub_filter      u.subf.pf_filter
124
125         struct
126         {
127             int         (*pf_text) ( filter_t *, subpicture_region_t *,
128                                      subpicture_region_t *,
129                                      const vlc_fourcc_t * );
130             int         (*pf_html) ( filter_t *, subpicture_region_t *,
131                                      subpicture_region_t *,
132                                      const vlc_fourcc_t * );
133         } render;
134 #define pf_render_text     u.render.pf_text
135 #define pf_render_html     u.render.pf_html
136
137     } u;
138
139     /* Input attachments
140      * XXX use filter_GetInputAttachments */
141     int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
142
143     /* Private structure for the owner of the decoder */
144     filter_owner_sys_t *p_owner;
145 };
146
147 /**
148  * This function will return a new picture usable by p_filter as an output
149  * buffer. You have to release it using filter_DeletePicture or by returning
150  * it to the caller as a pf_video_filter return value.
151  * Provided for convenience.
152  *
153  * \param p_filter filter_t object
154  * \return new picture on success or NULL on failure
155  */
156 static inline picture_t *filter_NewPicture( filter_t *p_filter )
157 {
158     picture_t *p_picture = p_filter->pf_video_buffer_new( p_filter );
159     if( !p_picture )
160         msg_Warn( p_filter, "can't get output picture" );
161     return p_picture;
162 }
163
164 /**
165  * This function will release a picture create by filter_NewPicture.
166  * Provided for convenience.
167  *
168  * \param p_filter filter_t object
169  * \param p_picture picture to be deleted
170  */
171 static inline void filter_DeletePicture( filter_t *p_filter, picture_t *p_picture )
172 {
173     p_filter->pf_video_buffer_del( p_filter, p_picture );
174 }
175
176 /**
177  * This function will flush the state of a video filter.
178  */
179 static inline void filter_FlushPictures( filter_t *p_filter )
180 {
181     if( p_filter->pf_video_flush )
182         p_filter->pf_video_flush( p_filter );
183 }
184
185 /**
186  * This function will return a new subpicture usable by p_filter as an output
187  * buffer. You have to release it using filter_DeleteSubpicture or by returning
188  * it to the caller as a pf_sub_source return value.
189  * Provided for convenience.
190  *
191  * \param p_filter filter_t object
192  * \return new subpicture
193  */
194 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
195 {
196     subpicture_t *p_subpicture = p_filter->pf_sub_buffer_new( p_filter );
197     if( !p_subpicture )
198         msg_Warn( p_filter, "can't get output subpicture" );
199     return p_subpicture;
200 }
201
202 /**
203  * This function will release a subpicture create by filter_NewSubicture.
204  * Provided for convenience.
205  *
206  * \param p_filter filter_t object
207  * \param p_subpicture to be released
208  */
209 static inline void filter_DeleteSubpicture( filter_t *p_filter, subpicture_t *p_subpicture )
210 {
211     p_filter->pf_sub_buffer_del( p_filter, p_subpicture );
212 }
213
214 /**
215  * This function will return a new audio buffer usable by p_filter as an
216  * output buffer. You have to release it using block_Release or by returning
217  * it to the caller as a pf_audio_filter return value.
218  * Provided for convenience.
219  *
220  * \param p_filter filter_t object
221  * \param i_size size of audio buffer requested
222  * \return block to be used as audio output buffer
223  */
224 static inline block_t *filter_NewAudioBuffer( filter_t *p_filter, int i_size )
225 {
226     block_t *p_block = p_filter->pf_audio_buffer_new( p_filter, i_size );
227     if( !p_block )
228         msg_Warn( p_filter, "can't get output block" );
229     return p_block;
230 }
231
232 /**
233  * This function gives all input attachments at once.
234  *
235  * You MUST release the returned values
236  */
237 static inline int filter_GetInputAttachments( filter_t *p_filter,
238                                               input_attachment_t ***ppp_attachment,
239                                               int *pi_attachment )
240 {
241     if( !p_filter->pf_get_attachments )
242         return VLC_EGENERIC;
243     return p_filter->pf_get_attachments( p_filter,
244                                          ppp_attachment, pi_attachment );
245 }
246
247 /**
248  * It creates a blend filter.
249  *
250  * Only the chroma properties of the dest format is used (chroma
251  * type, rgb masks and shifts)
252  */
253 VLC_API filter_t * filter_NewBlend( vlc_object_t *, const video_format_t *p_dst_chroma ) VLC_USED;
254
255 /**
256  * It configures blend filter parameters that are allowed to changed
257  * after the creation.
258  */
259 VLC_API int filter_ConfigureBlend( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src );
260
261 /**
262  * It blends a picture into another one.
263  *
264  * The input picture is not modified and not released.
265  */
266 VLC_API int filter_Blend( filter_t *, picture_t *p_dst, int i_dst_x, int i_dst_y, const picture_t *p_src, int i_alpha );
267
268 /**
269  * It destroys a blend filter created by filter_NewBlend.
270  */
271 VLC_API void filter_DeleteBlend( filter_t * );
272
273 /**
274  * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
275  * using a void (*)( filter_t *, picture_t *, picture_t * ) function
276  *
277  * Currently used by the chroma video filters
278  */
279 #define VIDEO_FILTER_WRAPPER( name )                                    \
280     static picture_t *name ## _Filter ( filter_t *p_filter,             \
281                                         picture_t *p_pic )              \
282     {                                                                   \
283         picture_t *p_outpic = filter_NewPicture( p_filter );            \
284         if( p_outpic )                                                  \
285         {                                                               \
286             name( p_filter, p_pic, p_outpic );                          \
287             picture_CopyProperties( p_outpic, p_pic );                  \
288         }                                                               \
289         picture_Release( p_pic );                                       \
290         return p_outpic;                                                \
291     }
292
293 /**
294  * Filter chain management API
295  * The filter chain management API is used to dynamically construct filters
296  * and add them in a chain.
297  */
298
299 typedef struct filter_chain_t filter_chain_t;
300
301 /**
302  * Create new filter chain
303  *
304  * \param p_object pointer to a vlc object
305  * \param psz_capability vlc capability of filters in filter chain
306  * \param b_allow_format_fmt_change allow changing of fmt
307  * \param pf_buffer_allocation_init callback function to initialize buffer allocations
308  * \param pf_buffer_allocation_clear callback function to clear buffer allocation initialization
309  * \param p_buffer_allocation_data pointer to private allocation data
310  * \return pointer to a filter chain
311  */
312 VLC_API filter_chain_t * filter_chain_New( vlc_object_t *, const char *, bool, int (*)( filter_t *, void * ), void (*)( filter_t * ), void *  ) VLC_USED;
313 #define filter_chain_New( a, b, c, d, e, f ) filter_chain_New( VLC_OBJECT( a ), b, c, d, e, f )
314
315 /**
316  * Delete filter chain will delete all filters in the chain and free all
317  * allocated data. The pointer to the filter chain is then no longer valid.
318  *
319  * \param p_chain pointer to filter chain
320  */
321 VLC_API void filter_chain_Delete( filter_chain_t * );
322
323 /**
324  * Reset filter chain will delete all filters in the chain and
325  * reset p_fmt_in and p_fmt_out to the new values.
326  *
327  * \param p_chain pointer to filter chain
328  * \param p_fmt_in new fmt_in params
329  * \param p_fmt_out new fmt_out params
330  */
331 VLC_API void filter_chain_Reset( filter_chain_t *, const es_format_t *, const es_format_t * );
332
333 /**
334  * Append filter to the end of the chain.
335  *
336  * \param p_chain pointer to filter chain
337  * \param psz_name name of filter
338  * \param p_cfg
339  * \param p_fmt_in input es_format_t
340  * \param p_fmt_out output es_format_t
341  * \return pointer to filter chain
342  */
343 VLC_API filter_t * filter_chain_AppendFilter( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * );
344
345 /**
346  * Append new filter to filter chain from string.
347  *
348  * \param p_chain pointer to filter chain
349  * \param psz_string string of filters
350  * \return 0 for success
351  */
352 VLC_API int filter_chain_AppendFromString( filter_chain_t *, const char * );
353
354 /**
355  * Delete filter from filter chain. This function also releases the filter
356  * object and unloads the filter modules. The pointer to p_filter is no
357  * longer valid after this function successfully returns.
358  *
359  * \param p_chain pointer to filter chain
360  * \param p_filter pointer to filter object
361  * \return VLC_SUCCESS on succes, else VLC_EGENERIC
362  */
363 VLC_API int filter_chain_DeleteFilter( filter_chain_t *, filter_t * );
364
365 /**
366  * Get the number of filters in the filter chain.
367  *
368  * \param p_chain pointer to filter chain
369  * \return number of filters in this filter chain
370  */
371 VLC_API int filter_chain_GetLength( filter_chain_t * );
372
373 /**
374  * Get last p_fmt_out in the chain.
375  *
376  * \param p_chain pointer to filter chain
377  * \return last p_fmt (es_format_t) of this filter chain
378  */
379 VLC_API const es_format_t * filter_chain_GetFmtOut( filter_chain_t * );
380
381 /**
382  * Apply the filter chain to a video picture.
383  *
384  * \param p_chain pointer to filter chain
385  * \param p_picture picture to apply filters on
386  * \return modified picture after applying all video filters
387  */
388 VLC_API picture_t * filter_chain_VideoFilter( filter_chain_t *, picture_t * );
389
390 /**
391  * Flush a video filter chain.
392  */
393 VLC_API void filter_chain_VideoFlush( filter_chain_t * );
394
395 /**
396  * Apply the filter chain to a audio block.
397  *
398  * \param p_chain pointer to filter chain
399  * \param p_block audio frame to apply filters on
400  * \return modified audio frame after applying all audio filters
401  */
402 VLC_API block_t * filter_chain_AudioFilter( filter_chain_t *, block_t * );
403
404 /**
405  * Apply filter chain to subpictures.
406  *
407  * \param p_chain pointer to filter chain
408  * \param display_date of subpictures
409  */
410 VLC_API void filter_chain_SubSource( filter_chain_t *, mtime_t );
411
412 /**
413  * Apply filter chain to subpictures.
414  *
415  * \param p_chain pointer to filter chain
416  * \param p_subpicture subpicture to apply filters on
417  * \return modified subpicture after applying all subpicture filters
418  */
419 VLC_API subpicture_t * filter_chain_SubFilter( filter_chain_t *, subpicture_t * );
420
421 /**
422  * Apply the filter chain to a mouse state.
423  *
424  * It will be applied from the output to the input. It makes sense only
425  * for a video filter chain.
426  *
427  * The vlc_mouse_t* pointers may be the same.
428  */
429 VLC_API int filter_chain_MouseFilter( filter_chain_t *, vlc_mouse_t *, const vlc_mouse_t * );
430
431 /**
432  * Inform the filter chain of mouse state.
433  *
434  * It makes sense only for a sub source chain.
435  */
436 VLC_API int filter_chain_MouseEvent( filter_chain_t *, const vlc_mouse_t *, const video_format_t * );
437
438 #endif /* _VLC_FILTER_H */
439