access: linsys: clear some warnings
[vlc.git] / include / vlc_filter.h
blobb2a8f871a4e0cd45585fbbb4e774b38d902d5e6b
1 /*****************************************************************************
2 * vlc_filter.h: filter related structures and functions
3 *****************************************************************************
4 * Copyright (C) 1999-2014 VLC authors and VideoLAN
6 * Authors: Gildas Bazin <gbazin@videolan.org>
7 * Antoine Cellerier <dionoea at videolan dot org>
8 * RĂ©mi Denis-Courmont
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * 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>
30 /**
31 * \defgroup filter Filters
32 * \ingroup output
33 * Audio, video, text filters
34 * @{
35 * \file
36 * Filter modules interface
39 struct filter_video_callbacks
41 picture_t *(*buffer_new)(filter_t *);
44 struct filter_subpicture_callbacks
46 subpicture_t *(*buffer_new)(filter_t *);
49 typedef struct filter_owner_t
51 union
53 const struct filter_video_callbacks *video;
54 const struct filter_subpicture_callbacks *sub;
56 void *sys;
57 } filter_owner_t;
59 struct vlc_mouse_t;
61 /** Structure describing a filter
62 * @warning BIG FAT WARNING : the code relies on the first 4 members of
63 * filter_t and decoder_t to be the same, so if you have anything to add,
64 * do it at the end of the structure.
66 struct filter_t
68 struct vlc_common_members obj;
70 /* Module properties */
71 module_t * p_module;
72 void *p_sys;
74 /* Input format */
75 es_format_t fmt_in;
77 /* Output format of filter */
78 es_format_t fmt_out;
79 bool b_allow_fmt_out_change;
81 /* Name of the "video filter" shortcut that is requested, can be NULL */
82 const char * psz_name;
83 /* Filter configuration */
84 config_chain_t * p_cfg;
86 union
88 /** Filter a picture (video filter) */
89 picture_t * (*pf_video_filter)( filter_t *, picture_t * );
91 /** Filter an audio block (audio filter) */
92 block_t * (*pf_audio_filter)( filter_t *, block_t * );
94 /** Blend a subpicture onto a picture (blend) */
95 void (*pf_video_blend)( filter_t *, picture_t *, const picture_t *,
96 int, int, int );
98 /** Generate a subpicture (sub source) */
99 subpicture_t *(*pf_sub_source)( filter_t *, vlc_tick_t );
101 /** Filter a subpicture (sub filter) */
102 subpicture_t *(*pf_sub_filter)( filter_t *, subpicture_t * );
104 /** Render text (text render) */
105 int (*pf_render)( filter_t *, subpicture_region_t *,
106 subpicture_region_t *, const vlc_fourcc_t * );
109 union
111 /* TODO: video filter drain */
112 /** Drain (audio filter) */
113 block_t *(*pf_audio_drain) ( filter_t * );
116 /** Flush
118 * Flush (i.e. discard) any internal buffer in a video or audio filter.
120 void (*pf_flush)( filter_t * );
122 /** Change viewpoint
124 * Pass a new viewpoint to audio filters. Filters like the spatialaudio one
125 * used for Ambisonics rendering will change its output according to this
126 * viewpoint.
128 void (*pf_change_viewpoint)( filter_t *, const vlc_viewpoint_t * );
130 union
132 /** Filter mouse state (video filter).
134 * If non-NULL, you must convert from output to input formats:
135 * - If VLC_SUCCESS is returned, the mouse state is propagated.
136 * - Otherwise, the mouse change is not propagated.
137 * If NULL, the mouse state is considered unchanged and will be
138 * propagated. */
139 int (*pf_video_mouse)( filter_t *, struct vlc_mouse_t *,
140 const struct vlc_mouse_t *p_old,
141 const struct vlc_mouse_t *p_new );
142 int (*pf_sub_mouse)( filter_t *, const struct vlc_mouse_t *p_old,
143 const struct vlc_mouse_t *p_new,
144 const video_format_t * );
147 /* Input attachments
148 * XXX use filter_GetInputAttachments */
149 int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
151 /** Private structure for the owner of the filter */
152 filter_owner_t owner;
156 * This function will return a new picture usable by p_filter as an output
157 * buffer. You have to release it using picture_Release or by returning
158 * it to the caller as a pf_video_filter return value.
159 * Provided for convenience.
161 * \param p_filter filter_t object
162 * \return new picture on success or NULL on failure
164 static inline picture_t *filter_NewPicture( filter_t *p_filter )
166 picture_t *pic = p_filter->owner.video->buffer_new( p_filter );
167 if( pic == NULL )
168 msg_Warn( p_filter, "can't get output picture" );
169 return pic;
173 * Flush a filter
175 * This function will flush the state of a filter (audio or video).
177 static inline void filter_Flush( filter_t *p_filter )
179 if( p_filter->pf_flush != NULL )
180 p_filter->pf_flush( p_filter );
183 static inline void filter_ChangeViewpoint( filter_t *p_filter,
184 const vlc_viewpoint_t *vp)
186 if( p_filter->pf_change_viewpoint != NULL )
187 p_filter->pf_change_viewpoint( p_filter, vp );
191 * This function will drain, then flush an audio filter.
193 static inline block_t *filter_DrainAudio( filter_t *p_filter )
195 if( p_filter->pf_audio_drain )
196 return p_filter->pf_audio_drain( p_filter );
197 else
198 return NULL;
202 * This function will return a new subpicture usable by p_filter as an output
203 * buffer. You have to release it using subpicture_Delete or by returning it to
204 * the caller as a pf_sub_source return value.
205 * Provided for convenience.
207 * \param p_filter filter_t object
208 * \return new subpicture
210 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
212 subpicture_t *subpic = p_filter->owner.sub->buffer_new( p_filter );
213 if( subpic == NULL )
214 msg_Warn( p_filter, "can't get output subpicture" );
215 return subpic;
219 * This function gives all input attachments at once.
221 * You MUST release the returned values
223 static inline int filter_GetInputAttachments( filter_t *p_filter,
224 input_attachment_t ***ppp_attachment,
225 int *pi_attachment )
227 if( !p_filter->pf_get_attachments )
228 return VLC_EGENERIC;
229 return p_filter->pf_get_attachments( p_filter,
230 ppp_attachment, pi_attachment );
234 * This function duplicates every variables from the filter, and adds a proxy
235 * callback to trigger filter events from obj.
237 * \param restart_cb a vlc_callback_t to call if the event means restarting the
238 * filter (i.e. an event on a non-command variable)
240 VLC_API void filter_AddProxyCallbacks( vlc_object_t *obj, filter_t *filter,
241 vlc_callback_t restart_cb );
242 # define filter_AddProxyCallbacks(a, b, c) \
243 filter_AddProxyCallbacks(VLC_OBJECT(a), b, c)
246 * This function removes the callbacks previously added to every duplicated
247 * variables, and removes them afterward.
249 * \param restart_cb the same vlc_callback_t passed to filter_AddProxyCallbacks
251 VLC_API void filter_DelProxyCallbacks( vlc_object_t *obj, filter_t *filter,
252 vlc_callback_t restart_cb);
253 # define filter_DelProxyCallbacks(a, b, c) \
254 filter_DelProxyCallbacks(VLC_OBJECT(a), b, c)
257 * It creates a blend filter.
259 * Only the chroma properties of the dest format is used (chroma
260 * type, rgb masks and shifts)
262 VLC_API filter_t * filter_NewBlend( vlc_object_t *, const video_format_t *p_dst_chroma ) VLC_USED;
265 * It configures blend filter parameters that are allowed to changed
266 * after the creation.
268 VLC_API int filter_ConfigureBlend( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src );
271 * It blends a picture into another one.
273 * The input picture is not modified and not released.
275 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 );
278 * It destroys a blend filter created by filter_NewBlend.
280 VLC_API void filter_DeleteBlend( filter_t * );
283 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
284 * using a void (*)( filter_t *, picture_t *, picture_t * ) function
286 * Currently used by the chroma video filters
288 #define VIDEO_FILTER_WRAPPER( name ) \
289 static picture_t *name ## _Filter ( filter_t *p_filter, \
290 picture_t *p_pic ) \
292 picture_t *p_outpic = filter_NewPicture( p_filter ); \
293 if( p_outpic ) \
295 name( p_filter, p_pic, p_outpic ); \
296 picture_CopyProperties( p_outpic, p_pic ); \
298 picture_Release( p_pic ); \
299 return p_outpic; \
303 * Filter chain management API
304 * The filter chain management API is used to dynamically construct filters
305 * and add them in a chain.
308 typedef struct filter_chain_t filter_chain_t;
311 * Create new filter chain
313 * \param p_object pointer to a vlc object
314 * \param psz_capability vlc capability of filters in filter chain
315 * \return pointer to a filter chain
317 filter_chain_t * filter_chain_New( vlc_object_t *, const char *, enum es_format_category_e )
318 VLC_USED;
319 #define filter_chain_New( a, b, c ) filter_chain_New( VLC_OBJECT( a ), b, c )
322 * Creates a new video filter chain.
324 * \param obj pointer to parent VLC object
325 * \param change whether to allow changing the output format
326 * \param owner owner video buffer callbacks
327 * \return new filter chain, or NULL on error
329 VLC_API filter_chain_t * filter_chain_NewVideo( vlc_object_t *obj, bool change,
330 const filter_owner_t *owner )
331 VLC_USED;
332 #define filter_chain_NewVideo( a, b, c ) \
333 filter_chain_NewVideo( VLC_OBJECT( a ), b, c )
336 * Delete filter chain will delete all filters in the chain and free all
337 * allocated data. The pointer to the filter chain is then no longer valid.
339 * \param p_chain pointer to filter chain
341 VLC_API void filter_chain_Delete( filter_chain_t * );
344 * Reset filter chain will delete all filters in the chain and
345 * reset p_fmt_in and p_fmt_out to the new values.
347 * \param p_chain pointer to filter chain
348 * \param p_fmt_in new fmt_in params, may be NULL to leave input fmt unchanged
349 * \param p_fmt_out new fmt_out params, may be NULL to leave output fmt unchanged
351 VLC_API void filter_chain_Reset( filter_chain_t *, const es_format_t *, const es_format_t * );
354 * Append a filter to the chain.
356 * \param chain filter chain to append a filter to
357 * \param name filter name
358 * \param fmt_in filter input format
359 * \param fmt_out filter output format
360 * \return a pointer to the filter or NULL on error
362 VLC_API filter_t *filter_chain_AppendFilter(filter_chain_t *chain,
363 const char *name, config_chain_t *cfg, const es_format_t *fmt_in,
364 const es_format_t *fmt_out);
367 * Append a conversion to the chain.
369 * \param chain filter chain to append a filter to
370 * \param fmt_in filter input format
371 * \param fmt_out filter output format
372 * \retval 0 on success
373 * \retval -1 on failure
375 VLC_API int filter_chain_AppendConverter(filter_chain_t *chain,
376 const es_format_t *fmt_in, const es_format_t *fmt_out);
379 * Append new filter to filter chain from string.
381 * \param chain filter chain to append a filter to
382 * \param str filters chain nul-terminated string
384 VLC_API int filter_chain_AppendFromString(filter_chain_t *chain,
385 const char *str);
388 * Delete filter from filter chain. This function also releases the filter
389 * object and unloads the filter modules. The pointer to p_filter is no
390 * longer valid after this function successfully returns.
392 * \param chain filter chain to remove the filter from
393 * \param filter filter to remove from the chain and delete
395 VLC_API void filter_chain_DeleteFilter(filter_chain_t *chain,
396 filter_t *filter);
399 * Checks if the filter chain is empty.
401 * \param chain pointer to filter chain
402 * \return true if and only if there are no filters in this filter chain
404 VLC_API bool filter_chain_IsEmpty(const filter_chain_t *chain);
407 * Get last output format of the last element in the filter chain.
409 * \param chain filter chain
411 VLC_API const es_format_t *filter_chain_GetFmtOut(const filter_chain_t *chain);
414 * Apply the filter chain to a video picture.
416 * \param chain pointer to filter chain
417 * \param pic picture to apply filters to
418 * \return modified picture after applying all video filters
420 VLC_API picture_t *filter_chain_VideoFilter(filter_chain_t *chain,
421 picture_t *pic);
424 * Flush a video filter chain.
426 VLC_API void filter_chain_VideoFlush( filter_chain_t * );
429 * Generate subpictures from a chain of subpicture source "filters".
431 * \param chain filter chain
432 * \param display_date of subpictures
434 void filter_chain_SubSource(filter_chain_t *chain, spu_t *,
435 vlc_tick_t display_date);
438 * Apply filter chain to subpictures.
440 * \param chain filter chain
441 * \param subpic subpicture to apply filters on
442 * \return modified subpicture after applying all subpicture filters
444 VLC_API subpicture_t *filter_chain_SubFilter(filter_chain_t *chain,
445 subpicture_t *subpic);
448 * Apply the filter chain to a mouse state.
450 * It will be applied from the output to the input. It makes sense only
451 * for a video filter chain.
453 * The vlc_mouse_t* pointers may be the same.
455 VLC_API int filter_chain_MouseFilter( filter_chain_t *, struct vlc_mouse_t *,
456 const struct vlc_mouse_t * );
459 * Inform the filter chain of mouse state.
461 * It makes sense only for a sub source chain.
463 VLC_API int filter_chain_MouseEvent( filter_chain_t *,
464 const struct vlc_mouse_t *,
465 const video_format_t * );
467 int filter_chain_ForEach( filter_chain_t *chain,
468 int (*cb)( filter_t *, void * ), void *opaque );
470 /** @} */
471 #endif /* _VLC_FILTER_H */