]> git.sesse.net Git - vlc/blob - include/vlc_filter.h
Core: add some LIBVLC_USED.
[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             picture_t * (*pf_buffer_new) ( filter_t * );
69             void        (*pf_buffer_del) ( filter_t *, picture_t * );
70             /* Filter mouse state.
71              *
72              * If non-NULL, you must convert from output to input formats:
73              * - If VLC_SUCCESS is returned, the mouse state is propagated.
74              * - Otherwise, the mouse change is not propagated.
75              * If NULL, the mouse state is considered unchanged and will be
76              * propagated.
77              */
78             int         (*pf_mouse)( filter_t *, vlc_mouse_t *,
79                                      const vlc_mouse_t *p_old,
80                                      const vlc_mouse_t *p_new );
81         } video;
82 #define pf_video_filter     u.video.pf_filter
83 #define pf_video_mouse      u.video.pf_mouse
84 #define pf_video_buffer_new u.video.pf_buffer_new
85 #define pf_video_buffer_del u.video.pf_buffer_del
86
87         struct
88         {
89             block_t *   (*pf_filter) ( filter_t *, block_t * );
90             block_t *   (*pf_buffer_new) ( filter_t *, int );
91         } audio;
92 #define pf_audio_filter     u.audio.pf_filter
93 #define pf_audio_buffer_new u.audio.pf_buffer_new
94
95         struct
96         {
97             void        (*pf_blend) ( filter_t *,  picture_t *,
98                                       const picture_t *, int, int, int );
99         } blend;
100 #define pf_video_blend     u.blend.pf_blend
101
102         struct
103         {
104             subpicture_t * (*pf_filter)    ( filter_t *, mtime_t );
105             subpicture_t * (*pf_buffer_new)( filter_t * );
106             void           (*pf_buffer_del)( filter_t *, subpicture_t * );
107             int            (*pf_mouse)     ( filter_t *,
108                                              const vlc_mouse_t *p_old,
109                                              const vlc_mouse_t *p_new,
110                                              const video_format_t * );
111         } sub;
112 #define pf_sub_filter      u.sub.pf_filter
113 #define pf_sub_buffer_new  u.sub.pf_buffer_new
114 #define pf_sub_buffer_del  u.sub.pf_buffer_del
115 #define pf_sub_mouse       u.sub.pf_mouse
116
117         struct
118         {
119             int         (*pf_text) ( filter_t *, subpicture_region_t *,
120                                      subpicture_region_t * );
121             int         (*pf_html) ( filter_t *, subpicture_region_t *,
122                                      subpicture_region_t * );
123         } render;
124 #define pf_render_text     u.render.pf_text
125 #define pf_render_html     u.render.pf_html
126
127     } u;
128
129     /* Input attachments
130      * XXX use filter_GetInputAttachments */
131     int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
132
133     /* Private structure for the owner of the decoder */
134     filter_owner_sys_t *p_owner;
135 };
136
137 /**
138  * This function will return a new picture usable by p_filter as an output
139  * buffer. You have to release it using filter_DeletePicture or by returning
140  * it to the caller as a pf_video_filter return value.
141  * Provided for convenience.
142  *
143  * \param p_filter filter_t object
144  * \return new picture on success or NULL on failure
145  */
146 static inline picture_t *filter_NewPicture( filter_t *p_filter )
147 {
148     picture_t *p_picture = p_filter->pf_video_buffer_new( p_filter );
149     if( !p_picture )
150         msg_Warn( p_filter, "can't get output picture" );
151     return p_picture;
152 }
153
154 /**
155  * This function will release a picture create by filter_NewPicture.
156  * Provided for convenience.
157  *
158  * \param p_filter filter_t object
159  * \param p_picture picture to be deleted
160  */
161 static inline void filter_DeletePicture( filter_t *p_filter, picture_t *p_picture )
162 {
163     p_filter->pf_video_buffer_del( p_filter, p_picture );
164 }
165
166 /**
167  * This function will return a new subpicture usable by p_filter as an output
168  * buffer. You have to release it using filter_DeleteSubpicture or by returning
169  * it to the caller as a pf_sub_filter return value.
170  * Provided for convenience.
171  *
172  * \param p_filter filter_t object
173  * \return new subpicture
174  */
175 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
176 {
177     subpicture_t *p_subpicture = p_filter->pf_sub_buffer_new( p_filter );
178     if( !p_subpicture )
179         msg_Warn( p_filter, "can't get output subpicture" );
180     return p_subpicture;
181 }
182
183 /**
184  * This function will release a subpicture create by filter_NewSubicture.
185  * Provided for convenience.
186  *
187  * \param p_filter filter_t object
188  * \param p_subpicture to be released
189  */
190 static inline void filter_DeleteSubpicture( filter_t *p_filter, subpicture_t *p_subpicture )
191 {
192     p_filter->pf_sub_buffer_del( p_filter, p_subpicture );
193 }
194
195 /**
196  * This function will return a new audio buffer usable by p_filter as an
197  * output buffer. You have to release it using block_Release or by returning
198  * it to the caller as a pf_audio_filter return value.
199  * Provided for convenience.
200  *
201  * \param p_filter filter_t object
202  * \param i_size size of audio buffer requested
203  * \return block to be used as audio output buffer
204  */
205 static inline block_t *filter_NewAudioBuffer( filter_t *p_filter, int i_size )
206 {
207     block_t *p_block = p_filter->pf_audio_buffer_new( p_filter, i_size );
208     if( !p_block )
209         msg_Warn( p_filter, "can't get output block" );
210     return p_block;
211 }
212
213 /**
214  * This function gives all input attachments at once.
215  *
216  * You MUST release the returned values
217  */
218 static inline int filter_GetInputAttachments( filter_t *p_filter,
219                                               input_attachment_t ***ppp_attachment,
220                                               int *pi_attachment )
221 {
222     if( !p_filter->pf_get_attachments )
223         return VLC_EGENERIC;
224     return p_filter->pf_get_attachments( p_filter,
225                                          ppp_attachment, pi_attachment );
226 }
227
228 /**
229  * It creates a blend filter.
230  *
231  * Only the chroma properties of the dest format is used (chroma
232  * type, rgb masks and shifts)
233  */
234 VLC_EXPORT( filter_t *, filter_NewBlend, ( vlc_object_t *, const video_format_t *p_dst_chroma ) LIBVLC_USED );
235
236 /**
237  * It configures blend filter parameters that are allowed to changed
238  * after the creation.
239  */
240 VLC_EXPORT( int, filter_ConfigureBlend, ( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src ) );
241
242 /**
243  * It blends a picture into another one.
244  *
245  * The input picture is not modified and not released.
246  */
247 VLC_EXPORT( 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 ) );
248
249 /**
250  * It destroys a blend filter created by filter_NewBlend.
251  */
252 VLC_EXPORT( void, filter_DeleteBlend, ( filter_t * ) );
253
254 /**
255  * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
256  * using a void (*)( filter_t *, picture_t *, picture_t * ) function
257  *
258  * Currently used by the chroma video filters
259  */
260 #define VIDEO_FILTER_WRAPPER( name )                                    \
261     static picture_t *name ## _Filter ( filter_t *p_filter,             \
262                                         picture_t *p_pic )              \
263     {                                                                   \
264         picture_t *p_outpic = filter_NewPicture( p_filter );            \
265         if( p_outpic )                                                  \
266         {                                                               \
267             name( p_filter, p_pic, p_outpic );                          \
268             picture_CopyProperties( p_outpic, p_pic );                  \
269         }                                                               \
270         picture_Release( p_pic );                                       \
271         return p_outpic;                                                \
272     }
273
274 /**
275  * Filter chain management API
276  * The filter chain management API is used to dynamically construct filters
277  * and add them in a chain.
278  */
279
280 typedef struct filter_chain_t filter_chain_t;
281
282 /**
283  * Create new filter chain
284  *
285  * \param p_object pointer to a vlc object
286  * \param psz_capability vlc capability of filters in filter chain
287  * \param b_allow_format_fmt_change allow changing of fmt
288  * \param pf_buffer_allocation_init callback function to initialize buffer allocations
289  * \param pf_buffer_allocation_clear callback function to clear buffer allocation initialization
290  * \param p_buffer_allocation_data pointer to private allocation data
291  * \return pointer to a filter chain
292  */
293 VLC_EXPORT( filter_chain_t *, filter_chain_New, ( vlc_object_t *, const char *, bool, int (*)( filter_t *, void * ), void (*)( filter_t * ), void *  ) LIBVLC_USED );
294 #define filter_chain_New( a, b, c, d, e, f ) filter_chain_New( VLC_OBJECT( a ), b, c, d, e, f )
295
296 /**
297  * Delete filter chain will delete all filters in the chain and free all
298  * allocated data. The pointer to the filter chain is then no longer valid.
299  *
300  * \param p_chain pointer to filter chain
301  */
302 VLC_EXPORT( void, filter_chain_Delete, ( filter_chain_t * ) );
303
304 /**
305  * Reset filter chain will delete all filters in the chain and
306  * reset p_fmt_in and p_fmt_out to the new values.
307  *
308  * \param p_chain pointer to filter chain
309  * \param p_fmt_in new fmt_in params
310  * \param p_fmt_out new fmt_out params
311  */
312 VLC_EXPORT( void, filter_chain_Reset, ( filter_chain_t *, const es_format_t *, const es_format_t * ) );
313
314 /**
315  * Append filter to the end of the chain.
316  *
317  * \param p_chain pointer to filter chain
318  * \param psz_name name of filter
319  * \param p_cfg
320  * \param p_fmt_in input es_format_t
321  * \param p_fmt_out output es_format_t
322  * \return pointer to filter chain
323  */
324 VLC_EXPORT( filter_t *, filter_chain_AppendFilter, ( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * ) );
325
326 /**
327  * Append new filter to filter chain from string.
328  *
329  * \param p_chain pointer to filter chain
330  * \param psz_string string of filters
331  * \return 0 for success
332  */
333 VLC_EXPORT( int, filter_chain_AppendFromString, ( filter_chain_t *, const char * ) );
334
335 /**
336  * Delete filter from filter chain. This function also releases the filter
337  * object and unloads the filter modules. The pointer to p_filter is no
338  * longer valid after this function successfully returns.
339  *
340  * \param p_chain pointer to filter chain
341  * \param p_filter pointer to filter object
342  * \return VLC_SUCCESS on succes, else VLC_EGENERIC
343  */
344 VLC_EXPORT( int, filter_chain_DeleteFilter, ( filter_chain_t *, filter_t * ) );
345
346 /**
347  * Get the number of filters in the filter chain.
348  *
349  * \param p_chain pointer to filter chain
350  * \return number of filters in this filter chain
351  */
352 VLC_EXPORT( int, filter_chain_GetLength, ( filter_chain_t * ) );
353
354 /**
355  * Get last p_fmt_out in the chain.
356  *
357  * \param p_chain pointer to filter chain
358  * \return last p_fmt (es_format_t) of this filter chain
359  */
360 VLC_EXPORT( const es_format_t *, filter_chain_GetFmtOut, ( filter_chain_t * ) );
361
362 /**
363  * Apply the filter chain to a video picture.
364  *
365  * \param p_chain pointer to filter chain
366  * \param p_picture picture to apply filters on
367  * \return modified picture after applying all video filters
368  */
369 VLC_EXPORT( picture_t *, filter_chain_VideoFilter, ( filter_chain_t *, picture_t * ) );
370
371 /**
372  * Apply the filter chain to a audio block.
373  *
374  * \param p_chain pointer to filter chain
375  * \param p_block audio frame to apply filters on
376  * \return modified audio frame after applying all audio filters
377  */
378 VLC_EXPORT( block_t *, filter_chain_AudioFilter, ( filter_chain_t *, block_t * ) );
379
380 /**
381  * Apply filter chain to subpictures.
382  *
383  * \param p_chain pointer to filter chain
384  * \param display_date of subpictures
385  */
386 VLC_EXPORT( void, filter_chain_SubFilter, ( filter_chain_t *, mtime_t ) );
387
388 /**
389  * Apply the filter chain to a mouse state.
390  *
391  * It will be applied from the output to the input. It makes sense only
392  * for a video filter chain.
393  *
394  * The vlc_mouse_t* pointers may be the same.
395  */
396 VLC_EXPORT( int, filter_chain_MouseFilter, ( filter_chain_t *, vlc_mouse_t *, const vlc_mouse_t * ) );
397
398 /**
399  * Inform the filter chain of mouse state.
400  *
401  * It makes sense only for a sub filter chain.
402  */
403 VLC_EXPORT( int, filter_chain_MouseEvent, ( filter_chain_t *, const vlc_mouse_t *, const video_format_t * ) );
404
405 #endif /* _VLC_FILTER_H */
406