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