]> git.sesse.net Git - vlc/blob - include/vlc_filter.h
Added mouse support to filter_t and filter_chain_t.
[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     picture_t *         ( * pf_video_filter ) ( filter_t *, picture_t * );
64     block_t *           ( * pf_audio_filter ) ( filter_t *, block_t * );
65     void                ( * pf_video_blend )  ( filter_t *,
66                                                 picture_t *, picture_t *,
67                                                 int, int, int );
68
69     subpicture_t *      ( *pf_sub_filter ) ( filter_t *, mtime_t );
70     int                 ( *pf_render_text ) ( filter_t *, subpicture_region_t *,
71                                               subpicture_region_t * );
72     int                 ( *pf_render_html ) ( filter_t *, subpicture_region_t *,
73                                               subpicture_region_t * );
74
75     /* Filter mouse state.
76      *
77      * If non NULL, you must convert from output format to input format,
78      * if VLC_SUCCESS is returned, the mouse state is then propagated.
79      * If NULL, the mouse state is considered unchanged and will be
80      * propagated.
81      *
82      * If VLC_SUCCESS is not returned, the mouse changes are not propagated.
83      */
84     int                 ( *pf_mouse )( filter_t *, vlc_mouse_t *,
85                                        const vlc_mouse_t *p_old,
86                                        const vlc_mouse_t *p_new );
87     /*
88      * Buffers allocation
89      */
90
91     /* Audio output callbacks */
92     block_t *       ( * pf_audio_buffer_new) ( filter_t *, int );
93
94     /* Video output callbacks */
95     picture_t     * ( * pf_vout_buffer_new) ( filter_t * );
96     void            ( * pf_vout_buffer_del) ( filter_t *, picture_t * );
97     /* void            ( * pf_picture_link)    ( picture_t * );
98     void            ( * pf_picture_unlink)  ( picture_t * ); */
99
100     /* SPU output callbacks */
101     subpicture_t *  ( * pf_sub_buffer_new) ( filter_t * );
102     void            ( * pf_sub_buffer_del) ( filter_t *, subpicture_t * );
103
104     /* Private structure for the owner of the decoder */
105     filter_owner_sys_t *p_owner;
106 };
107
108 /**
109  * This function will return a new picture usable by p_filter as an output
110  * buffer. You have to release it using filter_DeletePicture or by returning
111  * it to the caller as a pf_video_filter return value.
112  * Provided for convenience.
113  *
114  * \param p_filter filter_t object
115  * \return new picture on success or NULL on failure
116  */
117 static inline picture_t *filter_NewPicture( filter_t *p_filter )
118 {
119     picture_t *p_picture = p_filter->pf_vout_buffer_new( p_filter );
120     if( !p_picture )
121         msg_Warn( p_filter, "can't get output picture" );
122     return p_picture;
123 }
124
125 /**
126  * This function will release a picture create by filter_NewPicture.
127  * Provided for convenience.
128  *
129  * \param p_filter filter_t object
130  * \param p_picture picture to be deleted
131  */
132 static inline void filter_DeletePicture( filter_t *p_filter, picture_t *p_picture )
133 {
134     p_filter->pf_vout_buffer_del( p_filter, p_picture );
135 }
136
137 /**
138  * This function will return a new subpicture usable by p_filter as an output
139  * buffer. You have to release it using filter_DeleteSubpicture or by returning
140  * it to the caller as a pf_sub_filter return value.
141  * Provided for convenience.
142  *
143  * \param p_filter filter_t object
144  * \return new subpicture
145  */
146 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
147 {
148     subpicture_t *p_subpicture = p_filter->pf_sub_buffer_new( p_filter );
149     if( !p_subpicture )
150         msg_Warn( p_filter, "can't get output subpicture" );
151     return p_subpicture;
152 }
153
154 /**
155  * This function will release a subpicture create by filter_NewSubicture.
156  * Provided for convenience.
157  *
158  * \param p_filter filter_t object
159  * \param p_subpicture to be released
160  */
161 static inline void filter_DeleteSubpicture( filter_t *p_filter, subpicture_t *p_subpicture )
162 {
163     p_filter->pf_sub_buffer_del( p_filter, p_subpicture );
164 }
165
166 /**
167  * This function will return a new audio buffer usable by p_filter as an
168  * output buffer. You have to release it using block_Release or by returning
169  * it to the caller as a pf_audio_filter return value.
170  * Provided for convenience.
171  *
172  * \param p_filter filter_t object
173  * \param i_size size of audio buffer requested
174  * \return block to be used as audio output buffer
175  */
176 static inline block_t *filter_NewAudioBuffer( filter_t *p_filter, int i_size )
177 {
178     block_t *p_block = p_filter->pf_audio_buffer_new( p_filter, i_size );
179     if( !p_block )
180         msg_Warn( p_filter, "can't get output block" );
181     return p_block;
182 }
183
184 /**
185  * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
186  * using a void (*)( filter_t *, picture_t *, picture_t * ) function
187  *
188  * Currently used by the chroma video filters
189  */
190 #define VIDEO_FILTER_WRAPPER( name )                                    \
191     static picture_t *name ## _Filter ( filter_t *p_filter,             \
192                                         picture_t *p_pic )              \
193     {                                                                   \
194         picture_t *p_outpic = filter_NewPicture( p_filter );            \
195         if( p_outpic )                                                  \
196         {                                                               \
197             name( p_filter, p_pic, p_outpic );                          \
198             picture_CopyProperties( p_outpic, p_pic );                  \
199         }                                                               \
200         picture_Release( p_pic );                                       \
201         return p_outpic;                                                \
202     }
203
204 /**
205  * Filter chain management API
206  * The filter chain management API is used to dynamically construct filters
207  * and add them in a chain.
208  */
209
210 typedef struct filter_chain_t filter_chain_t;
211
212 /**
213  * Create new filter chain
214  *
215  * \param p_object pointer to a vlc object
216  * \param psz_capability vlc capability of filters in filter chain
217  * \param b_allow_format_fmt_change allow changing of fmt
218  * \param pf_buffer_allocation_init callback function to initialize buffer allocations
219  * \param pf_buffer_allocation_clear callback function to clear buffer allocation initialization
220  * \param p_buffer_allocation_data pointer to private allocation data
221  * \return pointer to a filter chain
222  */
223 VLC_EXPORT( filter_chain_t *, __filter_chain_New, ( vlc_object_t *, const char *, bool, int (*)( filter_t *, void * ), void (*)( filter_t * ), void *  ) );
224 #define filter_chain_New( a, b, c, d, e, f ) __filter_chain_New( VLC_OBJECT( a ), b, c, d, e, f )
225
226 /**
227  * Delete filter chain will delete all filters in the chain and free all
228  * allocated data. The pointer to the filter chain is then no longer valid.
229  *
230  * \param p_chain pointer to filter chain
231  */
232 VLC_EXPORT( void, filter_chain_Delete, ( filter_chain_t * ) );
233
234 /**
235  * Reset filter chain will delete all filters in the chain and
236  * reset p_fmt_in and p_fmt_out to the new values.
237  *
238  * \param p_chain pointer to filter chain
239  * \param p_fmt_in new fmt_in params
240  * \param p_fmt_out new fmt_out params
241  */
242 VLC_EXPORT( void, filter_chain_Reset, ( filter_chain_t *, const es_format_t *, const es_format_t * ) );
243
244 /**
245  * Append filter to the end of the chain.
246  *
247  * \param p_chain pointer to filter chain
248  * \param psz_name name of filter
249  * \param p_cfg
250  * \param p_fmt_in input es_format_t
251  * \param p_fmt_out output es_format_t
252  * \return pointer to filter chain
253  */
254 VLC_EXPORT( filter_t *, filter_chain_AppendFilter, ( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * ) );
255
256 /**
257  * Append new filter to filter chain from string.
258  *
259  * \param p_chain pointer to filter chain
260  * \param psz_string string of filters
261  * \return 0 for success
262  */
263 VLC_EXPORT( int, filter_chain_AppendFromString, ( filter_chain_t *, const char * ) );
264
265 /**
266  * Delete filter from filter chain. This function also releases the filter
267  * object and unloads the filter modules. The pointer to p_filter is no
268  * longer valid after this function successfully returns.
269  *
270  * \param p_chain pointer to filter chain
271  * \param p_filter pointer to filter object
272  * \return VLC_SUCCESS on succes, else VLC_EGENERIC
273  */
274 VLC_EXPORT( int, filter_chain_DeleteFilter, ( filter_chain_t *, filter_t * ) );
275
276 /**
277  * Get filter by name of position in the filter chain.
278  *
279  * \param p_chain pointer to filter chain
280  * \param i_position position of filter in filter chain
281  * \param psz_name name of filter to get
282  * \return filter object based on position or name provided
283  */
284 VLC_EXPORT( filter_t *, filter_chain_GetFilter, ( filter_chain_t *, int, const char * ) );
285
286 /**
287  * Get the number of filters in the filter chain.
288  *
289  * \param p_chain pointer to filter chain
290  * \return number of filters in this filter chain
291  */
292 VLC_EXPORT( int, filter_chain_GetLength, ( filter_chain_t * ) );
293
294 /**
295  * Get last p_fmt_out in the chain.
296  *
297  * \param p_chain pointer to filter chain
298  * \return last p_fmt (es_format_t) of this filter chain
299  */
300 VLC_EXPORT( const es_format_t *, filter_chain_GetFmtOut, ( filter_chain_t * ) );
301
302 /**
303  * Apply the filter chain to a video picture.
304  *
305  * \param p_chain pointer to filter chain
306  * \param p_picture picture to apply filters on
307  * \return modified picture after applying all video filters
308  */
309 VLC_EXPORT( picture_t *, filter_chain_VideoFilter, ( filter_chain_t *, picture_t * ) );
310
311 /**
312  * Apply the filter chain to a audio block.
313  *
314  * \param p_chain pointer to filter chain
315  * \param p_block audio frame to apply filters on
316  * \return modified audio frame after applying all audio filters
317  */
318 VLC_EXPORT( block_t *, filter_chain_AudioFilter, ( filter_chain_t *, block_t * ) );
319
320 /**
321  * Apply filter chain to subpictures.
322  *
323  * \param p_chain pointer to filter chain
324  * \param display_date of subpictures
325  */
326 VLC_EXPORT( void, filter_chain_SubFilter, ( filter_chain_t *, mtime_t ) );
327
328 /**
329  * Apply the filter chain to a mouse state.
330  *
331  * It will be applied from the output to the input. It makes sense only
332  * for a video filter chain.
333  *
334  * The vlc_mouse_t* pointers may be the same.
335  */
336 VLC_EXPORT( int, filter_chain_MouseFilter, ( filter_chain_t *, vlc_mouse_t *, const vlc_mouse_t * ) );
337
338 #endif /* _VLC_FILTER_H */
339