Fix non-ASCII comment
[vlc/asuraparaju-public.git] / include / vlc_filter.h
blobea24344e707c5bfa8827d317294056ecd6d52eee
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 block_t * (*pf_buffer_new) ( filter_t *, int );
93 } audio;
94 #define pf_audio_filter u.audio.pf_filter
95 #define pf_audio_buffer_new u.audio.pf_buffer_new
97 struct
99 void (*pf_blend) ( filter_t *, picture_t *,
100 const picture_t *, int, int, int );
101 } blend;
102 #define pf_video_blend u.blend.pf_blend
104 struct
106 subpicture_t * (*pf_filter) ( filter_t *, mtime_t );
107 subpicture_t * (*pf_buffer_new)( filter_t * );
108 void (*pf_buffer_del)( filter_t *, subpicture_t * );
109 int (*pf_mouse) ( filter_t *,
110 const vlc_mouse_t *p_old,
111 const vlc_mouse_t *p_new,
112 const video_format_t * );
113 } sub;
114 #define pf_sub_filter u.sub.pf_filter
115 #define pf_sub_buffer_new u.sub.pf_buffer_new
116 #define pf_sub_buffer_del u.sub.pf_buffer_del
117 #define pf_sub_mouse u.sub.pf_mouse
119 struct
121 int (*pf_text) ( filter_t *, subpicture_region_t *,
122 subpicture_region_t * );
123 int (*pf_html) ( filter_t *, subpicture_region_t *,
124 subpicture_region_t * );
125 } render;
126 #define pf_render_text u.render.pf_text
127 #define pf_render_html u.render.pf_html
129 } u;
131 /* Input attachments
132 * XXX use filter_GetInputAttachments */
133 int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
135 /* Private structure for the owner of the decoder */
136 filter_owner_sys_t *p_owner;
140 * This function will return a new picture usable by p_filter as an output
141 * buffer. You have to release it using filter_DeletePicture or by returning
142 * it to the caller as a pf_video_filter return value.
143 * Provided for convenience.
145 * \param p_filter filter_t object
146 * \return new picture on success or NULL on failure
148 static inline picture_t *filter_NewPicture( filter_t *p_filter )
150 picture_t *p_picture = p_filter->pf_video_buffer_new( p_filter );
151 if( !p_picture )
152 msg_Warn( p_filter, "can't get output picture" );
153 return p_picture;
157 * This function will release a picture create by filter_NewPicture.
158 * Provided for convenience.
160 * \param p_filter filter_t object
161 * \param p_picture picture to be deleted
163 static inline void filter_DeletePicture( filter_t *p_filter, picture_t *p_picture )
165 p_filter->pf_video_buffer_del( p_filter, p_picture );
169 * This function will flush the state of a video filter.
171 static inline void filter_FlushPictures( filter_t *p_filter )
173 if( p_filter->pf_video_flush )
174 p_filter->pf_video_flush( p_filter );
178 * This function will return a new subpicture usable by p_filter as an output
179 * buffer. You have to release it using filter_DeleteSubpicture or by returning
180 * it to the caller as a pf_sub_filter return value.
181 * Provided for convenience.
183 * \param p_filter filter_t object
184 * \return new subpicture
186 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
188 subpicture_t *p_subpicture = p_filter->pf_sub_buffer_new( p_filter );
189 if( !p_subpicture )
190 msg_Warn( p_filter, "can't get output subpicture" );
191 return p_subpicture;
195 * This function will release a subpicture create by filter_NewSubicture.
196 * Provided for convenience.
198 * \param p_filter filter_t object
199 * \param p_subpicture to be released
201 static inline void filter_DeleteSubpicture( filter_t *p_filter, subpicture_t *p_subpicture )
203 p_filter->pf_sub_buffer_del( p_filter, p_subpicture );
207 * This function will return a new audio buffer usable by p_filter as an
208 * output buffer. You have to release it using block_Release or by returning
209 * it to the caller as a pf_audio_filter return value.
210 * Provided for convenience.
212 * \param p_filter filter_t object
213 * \param i_size size of audio buffer requested
214 * \return block to be used as audio output buffer
216 static inline block_t *filter_NewAudioBuffer( filter_t *p_filter, int i_size )
218 block_t *p_block = p_filter->pf_audio_buffer_new( p_filter, i_size );
219 if( !p_block )
220 msg_Warn( p_filter, "can't get output block" );
221 return p_block;
225 * This function gives all input attachments at once.
227 * You MUST release the returned values
229 static inline int filter_GetInputAttachments( filter_t *p_filter,
230 input_attachment_t ***ppp_attachment,
231 int *pi_attachment )
233 if( !p_filter->pf_get_attachments )
234 return VLC_EGENERIC;
235 return p_filter->pf_get_attachments( p_filter,
236 ppp_attachment, pi_attachment );
240 * It creates a blend filter.
242 * Only the chroma properties of the dest format is used (chroma
243 * type, rgb masks and shifts)
245 VLC_EXPORT( filter_t *, filter_NewBlend, ( vlc_object_t *, const video_format_t *p_dst_chroma ) LIBVLC_USED );
248 * It configures blend filter parameters that are allowed to changed
249 * after the creation.
251 VLC_EXPORT( int, filter_ConfigureBlend, ( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src ) );
254 * It blends a picture into another one.
256 * The input picture is not modified and not released.
258 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 ) );
261 * It destroys a blend filter created by filter_NewBlend.
263 VLC_EXPORT( void, filter_DeleteBlend, ( filter_t * ) );
266 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
267 * using a void (*)( filter_t *, picture_t *, picture_t * ) function
269 * Currently used by the chroma video filters
271 #define VIDEO_FILTER_WRAPPER( name ) \
272 static picture_t *name ## _Filter ( filter_t *p_filter, \
273 picture_t *p_pic ) \
275 picture_t *p_outpic = filter_NewPicture( p_filter ); \
276 if( p_outpic ) \
278 name( p_filter, p_pic, p_outpic ); \
279 picture_CopyProperties( p_outpic, p_pic ); \
281 picture_Release( p_pic ); \
282 return p_outpic; \
286 * Filter chain management API
287 * The filter chain management API is used to dynamically construct filters
288 * and add them in a chain.
291 typedef struct filter_chain_t filter_chain_t;
294 * Create new filter chain
296 * \param p_object pointer to a vlc object
297 * \param psz_capability vlc capability of filters in filter chain
298 * \param b_allow_format_fmt_change allow changing of fmt
299 * \param pf_buffer_allocation_init callback function to initialize buffer allocations
300 * \param pf_buffer_allocation_clear callback function to clear buffer allocation initialization
301 * \param p_buffer_allocation_data pointer to private allocation data
302 * \return pointer to a filter chain
304 VLC_EXPORT( filter_chain_t *, filter_chain_New, ( vlc_object_t *, const char *, bool, int (*)( filter_t *, void * ), void (*)( filter_t * ), void * ) LIBVLC_USED );
305 #define filter_chain_New( a, b, c, d, e, f ) filter_chain_New( VLC_OBJECT( a ), b, c, d, e, f )
308 * Delete filter chain will delete all filters in the chain and free all
309 * allocated data. The pointer to the filter chain is then no longer valid.
311 * \param p_chain pointer to filter chain
313 VLC_EXPORT( void, filter_chain_Delete, ( filter_chain_t * ) );
316 * Reset filter chain will delete all filters in the chain and
317 * reset p_fmt_in and p_fmt_out to the new values.
319 * \param p_chain pointer to filter chain
320 * \param p_fmt_in new fmt_in params
321 * \param p_fmt_out new fmt_out params
323 VLC_EXPORT( void, filter_chain_Reset, ( filter_chain_t *, const es_format_t *, const es_format_t * ) );
326 * Append filter to the end of the chain.
328 * \param p_chain pointer to filter chain
329 * \param psz_name name of filter
330 * \param p_cfg
331 * \param p_fmt_in input es_format_t
332 * \param p_fmt_out output es_format_t
333 * \return pointer to filter chain
335 VLC_EXPORT( filter_t *, filter_chain_AppendFilter, ( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * ) );
338 * Append new filter to filter chain from string.
340 * \param p_chain pointer to filter chain
341 * \param psz_string string of filters
342 * \return 0 for success
344 VLC_EXPORT( int, filter_chain_AppendFromString, ( filter_chain_t *, const char * ) );
347 * Delete filter from filter chain. This function also releases the filter
348 * object and unloads the filter modules. The pointer to p_filter is no
349 * longer valid after this function successfully returns.
351 * \param p_chain pointer to filter chain
352 * \param p_filter pointer to filter object
353 * \return VLC_SUCCESS on succes, else VLC_EGENERIC
355 VLC_EXPORT( int, filter_chain_DeleteFilter, ( filter_chain_t *, filter_t * ) );
358 * Get the number of filters in the filter chain.
360 * \param p_chain pointer to filter chain
361 * \return number of filters in this filter chain
363 VLC_EXPORT( int, filter_chain_GetLength, ( filter_chain_t * ) );
366 * Get last p_fmt_out in the chain.
368 * \param p_chain pointer to filter chain
369 * \return last p_fmt (es_format_t) of this filter chain
371 VLC_EXPORT( const es_format_t *, filter_chain_GetFmtOut, ( filter_chain_t * ) );
374 * Apply the filter chain to a video picture.
376 * \param p_chain pointer to filter chain
377 * \param p_picture picture to apply filters on
378 * \return modified picture after applying all video filters
380 VLC_EXPORT( picture_t *, filter_chain_VideoFilter, ( filter_chain_t *, picture_t * ) );
383 * Flush a video filter chain.
385 VLC_EXPORT( void, filter_chain_VideoFlush, ( filter_chain_t * ) );
388 * Apply the filter chain to a audio block.
390 * \param p_chain pointer to filter chain
391 * \param p_block audio frame to apply filters on
392 * \return modified audio frame after applying all audio filters
394 VLC_EXPORT( block_t *, filter_chain_AudioFilter, ( filter_chain_t *, block_t * ) );
397 * Apply filter chain to subpictures.
399 * \param p_chain pointer to filter chain
400 * \param display_date of subpictures
402 VLC_EXPORT( void, filter_chain_SubFilter, ( filter_chain_t *, mtime_t ) );
405 * Apply the filter chain to a mouse state.
407 * It will be applied from the output to the input. It makes sense only
408 * for a video filter chain.
410 * The vlc_mouse_t* pointers may be the same.
412 VLC_EXPORT( int, filter_chain_MouseFilter, ( filter_chain_t *, vlc_mouse_t *, const vlc_mouse_t * ) );
415 * Inform the filter chain of mouse state.
417 * It makes sense only for a sub filter chain.
419 VLC_EXPORT( int, filter_chain_MouseEvent, ( filter_chain_t *, const vlc_mouse_t *, const video_format_t * ) );
421 #endif /* _VLC_FILTER_H */