qtsound: added audio capture functionality for MAC OS X
[vlc.git] / include / vlc_filter.h
blob1c2882c888fcaca26c557334d0e7e92826737e1f
1 /*****************************************************************************
2 * vlc_filter.h: filter related structures and functions
3 *****************************************************************************
4 * Copyright (C) 1999-2008 the VideoLAN team
5 * $Id$
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 *****************************************************************************/
25 #ifndef VLC_FILTER_H
26 #define VLC_FILTER_H 1
28 #include <vlc_es.h>
29 #include <vlc_picture.h>
30 #include <vlc_subpicture.h>
31 #include <vlc_mouse.h>
33 /**
34 * \file
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.
45 struct filter_t
47 VLC_COMMON_MEMBERS
49 /* Module properties */
50 module_t * p_module;
51 filter_sys_t * p_sys;
53 /* Input format */
54 es_format_t fmt_in;
56 /* Output format of filter */
57 es_format_t fmt_out;
58 bool b_allow_fmt_out_change;
60 /* Filter configuration */
61 config_chain_t * p_cfg;
63 union
65 struct
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.
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.
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
89 struct
91 block_t * (*pf_filter) ( filter_t *, block_t * );
92 } audio;
93 #define pf_audio_filter u.audio.pf_filter
95 struct
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
102 struct
104 subpicture_t * (*pf_source) ( 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_source u.sub.pf_source
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
117 struct
119 subpicture_t * (*pf_filter) ( filter_t *, subpicture_t * );
120 } subf;
121 #define pf_sub_filter u.subf.pf_filter
123 struct
125 int (*pf_text) ( filter_t *, subpicture_region_t *,
126 subpicture_region_t *,
127 const vlc_fourcc_t * );
128 int (*pf_html) ( filter_t *, subpicture_region_t *,
129 subpicture_region_t *,
130 const vlc_fourcc_t * );
131 } render;
132 #define pf_render_text u.render.pf_text
133 #define pf_render_html u.render.pf_html
135 } u;
137 /* Input attachments
138 * XXX use filter_GetInputAttachments */
139 int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
141 /* Private structure for the owner of the decoder */
142 filter_owner_sys_t *p_owner;
146 * This function will return a new picture usable by p_filter as an output
147 * buffer. You have to release it using filter_DeletePicture or by returning
148 * it to the caller as a pf_video_filter return value.
149 * Provided for convenience.
151 * \param p_filter filter_t object
152 * \return new picture on success or NULL on failure
154 static inline picture_t *filter_NewPicture( filter_t *p_filter )
156 picture_t *p_picture = p_filter->pf_video_buffer_new( p_filter );
157 if( !p_picture )
158 msg_Warn( p_filter, "can't get output picture" );
159 return p_picture;
163 * This function will release a picture create by filter_NewPicture.
164 * Provided for convenience.
166 * \param p_filter filter_t object
167 * \param p_picture picture to be deleted
169 static inline void filter_DeletePicture( filter_t *p_filter, picture_t *p_picture )
171 p_filter->pf_video_buffer_del( p_filter, p_picture );
175 * This function will flush the state of a video filter.
177 static inline void filter_FlushPictures( filter_t *p_filter )
179 if( p_filter->pf_video_flush )
180 p_filter->pf_video_flush( p_filter );
184 * This function will return a new subpicture usable by p_filter as an output
185 * buffer. You have to release it using filter_DeleteSubpicture or by returning
186 * it to the caller as a pf_sub_source return value.
187 * Provided for convenience.
189 * \param p_filter filter_t object
190 * \return new subpicture
192 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
194 subpicture_t *p_subpicture = p_filter->pf_sub_buffer_new( p_filter );
195 if( !p_subpicture )
196 msg_Warn( p_filter, "can't get output subpicture" );
197 return p_subpicture;
201 * This function will release a subpicture create by filter_NewSubicture.
202 * Provided for convenience.
204 * \param p_filter filter_t object
205 * \param p_subpicture to be released
207 static inline void filter_DeleteSubpicture( filter_t *p_filter, subpicture_t *p_subpicture )
209 p_filter->pf_sub_buffer_del( p_filter, p_subpicture );
212 #define filter_NewAudioBuffer block_New
215 * This function gives all input attachments at once.
217 * You MUST release the returned values
219 static inline int filter_GetInputAttachments( filter_t *p_filter,
220 input_attachment_t ***ppp_attachment,
221 int *pi_attachment )
223 if( !p_filter->pf_get_attachments )
224 return VLC_EGENERIC;
225 return p_filter->pf_get_attachments( p_filter,
226 ppp_attachment, pi_attachment );
230 * It creates a blend filter.
232 * Only the chroma properties of the dest format is used (chroma
233 * type, rgb masks and shifts)
235 VLC_API filter_t * filter_NewBlend( vlc_object_t *, const video_format_t *p_dst_chroma ) VLC_USED;
238 * It configures blend filter parameters that are allowed to changed
239 * after the creation.
241 VLC_API int filter_ConfigureBlend( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src );
244 * It blends a picture into another one.
246 * The input picture is not modified and not released.
248 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 );
251 * It destroys a blend filter created by filter_NewBlend.
253 VLC_API void filter_DeleteBlend( filter_t * );
256 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
257 * using a void (*)( filter_t *, picture_t *, picture_t * ) function
259 * Currently used by the chroma video filters
261 #define VIDEO_FILTER_WRAPPER( name ) \
262 static picture_t *name ## _Filter ( filter_t *p_filter, \
263 picture_t *p_pic ) \
265 picture_t *p_outpic = filter_NewPicture( p_filter ); \
266 if( p_outpic ) \
268 name( p_filter, p_pic, p_outpic ); \
269 picture_CopyProperties( p_outpic, p_pic ); \
271 picture_Release( p_pic ); \
272 return p_outpic; \
276 * Filter chain management API
277 * The filter chain management API is used to dynamically construct filters
278 * and add them in a chain.
281 typedef struct filter_chain_t filter_chain_t;
284 * Create new filter chain
286 * \param p_object pointer to a vlc object
287 * \param psz_capability vlc capability of filters in filter chain
288 * \param b_allow_format_fmt_change allow changing of fmt
289 * \param pf_buffer_allocation_init callback function to initialize buffer allocations
290 * \param pf_buffer_allocation_clear callback function to clear buffer allocation initialization
291 * \param p_buffer_allocation_data pointer to private allocation data
292 * \return pointer to a filter chain
294 VLC_API filter_chain_t * filter_chain_New( vlc_object_t *, const char *, bool, int (*)( filter_t *, void * ), void (*)( filter_t * ), void * ) VLC_USED;
295 #define filter_chain_New( a, b, c, d, e, f ) filter_chain_New( VLC_OBJECT( a ), b, c, d, e, f )
298 * Delete filter chain will delete all filters in the chain and free all
299 * allocated data. The pointer to the filter chain is then no longer valid.
301 * \param p_chain pointer to filter chain
303 VLC_API void filter_chain_Delete( filter_chain_t * );
306 * Reset filter chain will delete all filters in the chain and
307 * reset p_fmt_in and p_fmt_out to the new values.
309 * \param p_chain pointer to filter chain
310 * \param p_fmt_in new fmt_in params
311 * \param p_fmt_out new fmt_out params
313 VLC_API void filter_chain_Reset( filter_chain_t *, const es_format_t *, const es_format_t * );
316 * Append filter to the end of the chain.
318 * \param p_chain pointer to filter chain
319 * \param psz_name name of filter
320 * \param p_cfg
321 * \param p_fmt_in input es_format_t
322 * \param p_fmt_out output es_format_t
323 * \return pointer to filter chain
325 VLC_API filter_t * filter_chain_AppendFilter( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * );
328 * Append new filter to filter chain from string.
330 * \param p_chain pointer to filter chain
331 * \param psz_string string of filters
332 * \return 0 for success
334 VLC_API int filter_chain_AppendFromString( filter_chain_t *, const char * );
337 * Delete filter from filter chain. This function also releases the filter
338 * object and unloads the filter modules. The pointer to p_filter is no
339 * longer valid after this function successfully returns.
341 * \param p_chain pointer to filter chain
342 * \param p_filter pointer to filter object
343 * \return VLC_SUCCESS on succes, else VLC_EGENERIC
345 VLC_API int filter_chain_DeleteFilter( filter_chain_t *, filter_t * );
348 * Get the number of filters in the filter chain.
350 * \param p_chain pointer to filter chain
351 * \return number of filters in this filter chain
353 VLC_API int filter_chain_GetLength( filter_chain_t * );
356 * Get last p_fmt_out in the chain.
358 * \param p_chain pointer to filter chain
359 * \return last p_fmt (es_format_t) of this filter chain
361 VLC_API const es_format_t * filter_chain_GetFmtOut( filter_chain_t * );
364 * Apply the filter chain to a video picture.
366 * \param p_chain pointer to filter chain
367 * \param p_picture picture to apply filters on
368 * \return modified picture after applying all video filters
370 VLC_API picture_t * filter_chain_VideoFilter( filter_chain_t *, picture_t * );
373 * Flush a video filter chain.
375 VLC_API void filter_chain_VideoFlush( filter_chain_t * );
378 * Apply the filter chain to a audio block.
380 * \param p_chain pointer to filter chain
381 * \param p_block audio frame to apply filters on
382 * \return modified audio frame after applying all audio filters
384 VLC_API block_t * filter_chain_AudioFilter( filter_chain_t *, block_t * );
387 * Apply filter chain to subpictures.
389 * \param p_chain pointer to filter chain
390 * \param display_date of subpictures
392 VLC_API void filter_chain_SubSource( filter_chain_t *, mtime_t );
395 * Apply filter chain to subpictures.
397 * \param p_chain pointer to filter chain
398 * \param p_subpicture subpicture to apply filters on
399 * \return modified subpicture after applying all subpicture filters
401 VLC_API subpicture_t * filter_chain_SubFilter( filter_chain_t *, subpicture_t * );
404 * Apply the filter chain to a mouse state.
406 * It will be applied from the output to the input. It makes sense only
407 * for a video filter chain.
409 * The vlc_mouse_t* pointers may be the same.
411 VLC_API int filter_chain_MouseFilter( filter_chain_t *, vlc_mouse_t *, const vlc_mouse_t * );
414 * Inform the filter chain of mouse state.
416 * It makes sense only for a sub source chain.
418 VLC_API int filter_chain_MouseEvent( filter_chain_t *, const vlc_mouse_t *, const video_format_t * );
420 #endif /* _VLC_FILTER_H */