1 /*****************************************************************************
2 * vlc_filter.h: filter related structures and functions
3 *****************************************************************************
4 * Copyright (C) 1999-2008 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * Antoine Cellerier <dionoea at videolan dot org>
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.
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.
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 *****************************************************************************/
26 #define VLC_FILTER_H 1
29 #include <vlc_picture.h>
30 #include <vlc_subpicture.h>
31 #include <vlc_mouse.h>
35 * This file defines the structure and types used by video and audio filters
38 typedef struct filter_owner_sys_t filter_owner_sys_t
;
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.
49 /* Module properties */
56 /* Output format of filter */
58 bool b_allow_fmt_out_change
;
60 /* Filter configuration */
61 config_chain_t
* p_cfg
;
65 picture_t
* (*pf_video_filter
) ( filter_t
*, picture_t
* );
66 block_t
* (*pf_audio_filter
) ( filter_t
*, block_t
* );
67 void (*pf_video_blend
) ( filter_t
*,
68 picture_t
*, const picture_t
*,
71 subpicture_t
* (*pf_sub_filter
) ( filter_t
*, mtime_t
);
72 int (*pf_render_text
) ( filter_t
*, subpicture_region_t
*,
73 subpicture_region_t
* );
77 /* Filter mouse state.
79 * If non-NULL, you must convert from output format to input format:
80 * - If VLC_SUCCESS is returned, the mouse state is then propagated.
81 * - Otherwise, the mouse change is not propagated.
82 * If NULL, the mouse state is considered unchanged and will be
85 int (*pf_mouse
)( filter_t
*, vlc_mouse_t
*,
86 const vlc_mouse_t
*p_old
,
87 const vlc_mouse_t
*p_new
);
88 int (*pf_render_html
) ( filter_t
*, subpicture_region_t
*,
89 subpicture_region_t
* );
97 block_t
* (*pf_audio_buffer_new
) ( filter_t
*, int );
98 picture_t
* (*pf_vout_buffer_new
) ( filter_t
* );
99 subpicture_t
* (*pf_sub_buffer_new
) ( filter_t
* );
103 void (*pf_vout_buffer_del
) ( filter_t
*, picture_t
* );
104 void (*pf_sub_buffer_del
) ( filter_t
*, subpicture_t
* );
107 /* Private structure for the owner of the decoder */
108 filter_owner_sys_t
*p_owner
;
112 * This function will return a new picture usable by p_filter as an output
113 * buffer. You have to release it using filter_DeletePicture or by returning
114 * it to the caller as a pf_video_filter return value.
115 * Provided for convenience.
117 * \param p_filter filter_t object
118 * \return new picture on success or NULL on failure
120 static inline picture_t
*filter_NewPicture( filter_t
*p_filter
)
122 picture_t
*p_picture
= p_filter
->pf_vout_buffer_new( p_filter
);
124 msg_Warn( p_filter
, "can't get output picture" );
129 * This function will release a picture create by filter_NewPicture.
130 * Provided for convenience.
132 * \param p_filter filter_t object
133 * \param p_picture picture to be deleted
135 static inline void filter_DeletePicture( filter_t
*p_filter
, picture_t
*p_picture
)
137 p_filter
->pf_vout_buffer_del( p_filter
, p_picture
);
141 * This function will return a new subpicture usable by p_filter as an output
142 * buffer. You have to release it using filter_DeleteSubpicture or by returning
143 * it to the caller as a pf_sub_filter return value.
144 * Provided for convenience.
146 * \param p_filter filter_t object
147 * \return new subpicture
149 static inline subpicture_t
*filter_NewSubpicture( filter_t
*p_filter
)
151 subpicture_t
*p_subpicture
= p_filter
->pf_sub_buffer_new( p_filter
);
153 msg_Warn( p_filter
, "can't get output subpicture" );
158 * This function will release a subpicture create by filter_NewSubicture.
159 * Provided for convenience.
161 * \param p_filter filter_t object
162 * \param p_subpicture to be released
164 static inline void filter_DeleteSubpicture( filter_t
*p_filter
, subpicture_t
*p_subpicture
)
166 p_filter
->pf_sub_buffer_del( p_filter
, p_subpicture
);
170 * This function will return a new audio buffer usable by p_filter as an
171 * output buffer. You have to release it using block_Release or by returning
172 * it to the caller as a pf_audio_filter return value.
173 * Provided for convenience.
175 * \param p_filter filter_t object
176 * \param i_size size of audio buffer requested
177 * \return block to be used as audio output buffer
179 static inline block_t
*filter_NewAudioBuffer( filter_t
*p_filter
, int i_size
)
181 block_t
*p_block
= p_filter
->pf_audio_buffer_new( p_filter
, i_size
);
183 msg_Warn( p_filter
, "can't get output block" );
188 * It creates a blend filter.
190 * Only the chroma properties of the dest format is used (chroma
191 * type, rgb masks and shifts)
193 VLC_EXPORT( filter_t
*, filter_NewBlend
, ( vlc_object_t
*, const video_format_t
*p_dst_chroma
) );
196 * It configures blend filter parameters that are allowed to changed
197 * after the creation.
199 VLC_EXPORT( int, filter_ConfigureBlend
, ( filter_t
*, int i_dst_width
, int i_dst_height
, const video_format_t
*p_src
) );
202 * It blends a picture into another one.
204 * The input picture is not modified and not released.
206 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
) );
209 * It destroys a blend filter created by filter_NewBlend.
211 VLC_EXPORT( void, filter_DeleteBlend
, ( filter_t
* ) );
214 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
215 * using a void (*)( filter_t *, picture_t *, picture_t * ) function
217 * Currently used by the chroma video filters
219 #define VIDEO_FILTER_WRAPPER( name ) \
220 static picture_t *name ## _Filter ( filter_t *p_filter, \
223 picture_t *p_outpic = filter_NewPicture( p_filter ); \
226 name( p_filter, p_pic, p_outpic ); \
227 picture_CopyProperties( p_outpic, p_pic ); \
229 picture_Release( p_pic ); \
234 * Filter chain management API
235 * The filter chain management API is used to dynamically construct filters
236 * and add them in a chain.
239 typedef struct filter_chain_t filter_chain_t
;
242 * Create new filter chain
244 * \param p_object pointer to a vlc object
245 * \param psz_capability vlc capability of filters in filter chain
246 * \param b_allow_format_fmt_change allow changing of fmt
247 * \param pf_buffer_allocation_init callback function to initialize buffer allocations
248 * \param pf_buffer_allocation_clear callback function to clear buffer allocation initialization
249 * \param p_buffer_allocation_data pointer to private allocation data
250 * \return pointer to a filter chain
252 VLC_EXPORT( filter_chain_t
*, __filter_chain_New
, ( vlc_object_t
*, const char *, bool, int (*)( filter_t
*, void * ), void (*)( filter_t
* ), void * ) );
253 #define filter_chain_New( a, b, c, d, e, f ) __filter_chain_New( VLC_OBJECT( a ), b, c, d, e, f )
256 * Delete filter chain will delete all filters in the chain and free all
257 * allocated data. The pointer to the filter chain is then no longer valid.
259 * \param p_chain pointer to filter chain
261 VLC_EXPORT( void, filter_chain_Delete
, ( filter_chain_t
* ) );
264 * Reset filter chain will delete all filters in the chain and
265 * reset p_fmt_in and p_fmt_out to the new values.
267 * \param p_chain pointer to filter chain
268 * \param p_fmt_in new fmt_in params
269 * \param p_fmt_out new fmt_out params
271 VLC_EXPORT( void, filter_chain_Reset
, ( filter_chain_t
*, const es_format_t
*, const es_format_t
* ) );
274 * Append filter to the end of the chain.
276 * \param p_chain pointer to filter chain
277 * \param psz_name name of filter
279 * \param p_fmt_in input es_format_t
280 * \param p_fmt_out output es_format_t
281 * \return pointer to filter chain
283 VLC_EXPORT( filter_t
*, filter_chain_AppendFilter
, ( filter_chain_t
*, const char *, config_chain_t
*, const es_format_t
*, const es_format_t
* ) );
286 * Append new filter to filter chain from string.
288 * \param p_chain pointer to filter chain
289 * \param psz_string string of filters
290 * \return 0 for success
292 VLC_EXPORT( int, filter_chain_AppendFromString
, ( filter_chain_t
*, const char * ) );
295 * Delete filter from filter chain. This function also releases the filter
296 * object and unloads the filter modules. The pointer to p_filter is no
297 * longer valid after this function successfully returns.
299 * \param p_chain pointer to filter chain
300 * \param p_filter pointer to filter object
301 * \return VLC_SUCCESS on succes, else VLC_EGENERIC
303 VLC_EXPORT( int, filter_chain_DeleteFilter
, ( filter_chain_t
*, filter_t
* ) );
306 * Get the number of filters in the filter chain.
308 * \param p_chain pointer to filter chain
309 * \return number of filters in this filter chain
311 VLC_EXPORT( int, filter_chain_GetLength
, ( filter_chain_t
* ) );
314 * Get last p_fmt_out in the chain.
316 * \param p_chain pointer to filter chain
317 * \return last p_fmt (es_format_t) of this filter chain
319 VLC_EXPORT( const es_format_t
*, filter_chain_GetFmtOut
, ( filter_chain_t
* ) );
322 * Apply the filter chain to a video picture.
324 * \param p_chain pointer to filter chain
325 * \param p_picture picture to apply filters on
326 * \return modified picture after applying all video filters
328 VLC_EXPORT( picture_t
*, filter_chain_VideoFilter
, ( filter_chain_t
*, picture_t
* ) );
331 * Apply the filter chain to a audio block.
333 * \param p_chain pointer to filter chain
334 * \param p_block audio frame to apply filters on
335 * \return modified audio frame after applying all audio filters
337 VLC_EXPORT( block_t
*, filter_chain_AudioFilter
, ( filter_chain_t
*, block_t
* ) );
340 * Apply filter chain to subpictures.
342 * \param p_chain pointer to filter chain
343 * \param display_date of subpictures
345 VLC_EXPORT( void, filter_chain_SubFilter
, ( filter_chain_t
*, mtime_t
) );
348 * Apply the filter chain to a mouse state.
350 * It will be applied from the output to the input. It makes sense only
351 * for a video filter chain.
353 * The vlc_mouse_t* pointers may be the same.
355 VLC_EXPORT( int, filter_chain_MouseFilter
, ( filter_chain_t
*, vlc_mouse_t
*, const vlc_mouse_t
* ) );
357 #endif /* _VLC_FILTER_H */