threads: remove now unused VLC_HIGHLIGHT_MUTEX
[vlc.git] / include / vlc_filter.h
blob847dc766049eb3b13d93b8a090bc13c2a2e6c630
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 typedef struct filter_owner_sys_t filter_owner_sys_t;
41 struct filter_video_callbacks
43 picture_t *(*buffer_new)(filter_t *);
46 struct filter_subpicture_callbacks
48 subpicture_t *(*buffer_new)(filter_t *);
51 typedef struct filter_owner_t
53 union
55 const struct filter_video_callbacks *video;
56 const struct filter_subpicture_callbacks *sub;
58 void *sys;
59 } filter_owner_t;
61 struct vlc_mouse_t;
63 /** Structure describing a filter
64 * @warning BIG FAT WARNING : the code relies on the first 4 members of
65 * filter_t and decoder_t to be the same, so if you have anything to add,
66 * do it at the end of the structure.
68 struct filter_t
70 struct vlc_common_members obj;
72 /* Module properties */
73 module_t * p_module;
74 void *p_sys;
76 /* Input format */
77 es_format_t fmt_in;
79 /* Output format of filter */
80 es_format_t fmt_out;
81 bool b_allow_fmt_out_change;
83 /* Name of the "video filter" shortcut that is requested, can be NULL */
84 const char * psz_name;
85 /* Filter configuration */
86 config_chain_t * p_cfg;
88 union
90 /** Filter a picture (video filter) */
91 picture_t * (*pf_video_filter)( filter_t *, picture_t * );
93 /** Filter an audio block (audio filter) */
94 block_t * (*pf_audio_filter)( filter_t *, block_t * );
96 /** Blend a subpicture onto a picture (blend) */
97 void (*pf_video_blend)( filter_t *, picture_t *, const picture_t *,
98 int, int, int );
100 /** Generate a subpicture (sub source) */
101 subpicture_t *(*pf_sub_source)( filter_t *, vlc_tick_t );
103 /** Filter a subpicture (sub filter) */
104 subpicture_t *(*pf_sub_filter)( filter_t *, subpicture_t * );
106 /** Render text (text render) */
107 int (*pf_render)( filter_t *, subpicture_region_t *,
108 subpicture_region_t *, const vlc_fourcc_t * );
111 union
113 /* TODO: video filter drain */
114 /** Drain (audio filter) */
115 block_t *(*pf_audio_drain) ( filter_t * );
118 /** Flush
120 * Flush (i.e. discard) any internal buffer in a video or audio filter.
122 void (*pf_flush)( filter_t * );
124 /** Change viewpoint
126 * Pass a new viewpoint to audio filters. Filters like the spatialaudio one
127 * used for Ambisonics rendering will change its output according to this
128 * viewpoint.
130 void (*pf_change_viewpoint)( filter_t *, const vlc_viewpoint_t * );
132 union
134 /** Filter mouse state (video filter).
136 * If non-NULL, you must convert from output to input formats:
137 * - If VLC_SUCCESS is returned, the mouse state is propagated.
138 * - Otherwise, the mouse change is not propagated.
139 * If NULL, the mouse state is considered unchanged and will be
140 * propagated. */
141 int (*pf_video_mouse)( filter_t *, struct vlc_mouse_t *,
142 const struct vlc_mouse_t *p_old,
143 const struct vlc_mouse_t *p_new );
144 int (*pf_sub_mouse)( filter_t *, const struct vlc_mouse_t *p_old,
145 const struct vlc_mouse_t *p_new,
146 const video_format_t * );
149 /* Input attachments
150 * XXX use filter_GetInputAttachments */
151 int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
153 /** Private structure for the owner of the filter */
154 filter_owner_t owner;
158 * This function will return a new picture usable by p_filter as an output
159 * buffer. You have to release it using picture_Release or by returning
160 * it to the caller as a pf_video_filter return value.
161 * Provided for convenience.
163 * \param p_filter filter_t object
164 * \return new picture on success or NULL on failure
166 static inline picture_t *filter_NewPicture( filter_t *p_filter )
168 picture_t *pic = p_filter->owner.video->buffer_new( p_filter );
169 if( pic == NULL )
170 msg_Warn( p_filter, "can't get output picture" );
171 return pic;
175 * Flush a filter
177 * This function will flush the state of a filter (audio or video).
179 static inline void filter_Flush( filter_t *p_filter )
181 if( p_filter->pf_flush != NULL )
182 p_filter->pf_flush( p_filter );
185 static inline void filter_ChangeViewpoint( filter_t *p_filter,
186 const vlc_viewpoint_t *vp)
188 if( p_filter->pf_change_viewpoint != NULL )
189 p_filter->pf_change_viewpoint( p_filter, vp );
193 * This function will drain, then flush an audio filter.
195 static inline block_t *filter_DrainAudio( filter_t *p_filter )
197 if( p_filter->pf_audio_drain )
198 return p_filter->pf_audio_drain( p_filter );
199 else
200 return NULL;
204 * This function will return a new subpicture usable by p_filter as an output
205 * buffer. You have to release it using subpicture_Delete or by returning it to
206 * the caller as a pf_sub_source return value.
207 * Provided for convenience.
209 * \param p_filter filter_t object
210 * \return new subpicture
212 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
214 subpicture_t *subpic = p_filter->owner.sub->buffer_new( p_filter );
215 if( subpic == NULL )
216 msg_Warn( p_filter, "can't get output subpicture" );
217 return subpic;
221 * This function gives all input attachments at once.
223 * You MUST release the returned values
225 static inline int filter_GetInputAttachments( filter_t *p_filter,
226 input_attachment_t ***ppp_attachment,
227 int *pi_attachment )
229 if( !p_filter->pf_get_attachments )
230 return VLC_EGENERIC;
231 return p_filter->pf_get_attachments( p_filter,
232 ppp_attachment, pi_attachment );
236 * This function duplicates every variables from the filter, and adds a proxy
237 * callback to trigger filter events from obj.
239 * \param restart_cb a vlc_callback_t to call if the event means restarting the
240 * filter (i.e. an event on a non-command variable)
242 VLC_API void filter_AddProxyCallbacks( vlc_object_t *obj, filter_t *filter,
243 vlc_callback_t restart_cb );
244 # define filter_AddProxyCallbacks(a, b, c) \
245 filter_AddProxyCallbacks(VLC_OBJECT(a), b, c)
248 * This function removes the callbacks previously added to every duplicated
249 * variables, and removes them afterward.
251 * \param restart_cb the same vlc_callback_t passed to filter_AddProxyCallbacks
253 VLC_API void filter_DelProxyCallbacks( vlc_object_t *obj, filter_t *filter,
254 vlc_callback_t restart_cb);
255 # define filter_DelProxyCallbacks(a, b, c) \
256 filter_DelProxyCallbacks(VLC_OBJECT(a), b, c)
259 * It creates a blend filter.
261 * Only the chroma properties of the dest format is used (chroma
262 * type, rgb masks and shifts)
264 VLC_API filter_t * filter_NewBlend( vlc_object_t *, const video_format_t *p_dst_chroma ) VLC_USED;
267 * It configures blend filter parameters that are allowed to changed
268 * after the creation.
270 VLC_API int filter_ConfigureBlend( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src );
273 * It blends a picture into another one.
275 * The input picture is not modified and not released.
277 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 );
280 * It destroys a blend filter created by filter_NewBlend.
282 VLC_API void filter_DeleteBlend( filter_t * );
285 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
286 * using a void (*)( filter_t *, picture_t *, picture_t * ) function
288 * Currently used by the chroma video filters
290 #define VIDEO_FILTER_WRAPPER( name ) \
291 static picture_t *name ## _Filter ( filter_t *p_filter, \
292 picture_t *p_pic ) \
294 picture_t *p_outpic = filter_NewPicture( p_filter ); \
295 if( p_outpic ) \
297 name( p_filter, p_pic, p_outpic ); \
298 picture_CopyProperties( p_outpic, p_pic ); \
300 picture_Release( p_pic ); \
301 return p_outpic; \
305 * Filter chain management API
306 * The filter chain management API is used to dynamically construct filters
307 * and add them in a chain.
310 typedef struct filter_chain_t filter_chain_t;
313 * Create new filter chain
315 * \param p_object pointer to a vlc object
316 * \param psz_capability vlc capability of filters in filter chain
317 * \return pointer to a filter chain
319 filter_chain_t * filter_chain_New( vlc_object_t *, const char *, enum es_format_category_e )
320 VLC_USED;
321 #define filter_chain_New( a, b, c ) filter_chain_New( VLC_OBJECT( a ), b, c )
324 * Creates a new video filter chain.
326 * \param obj pointer to parent VLC object
327 * \param change whether to allow changing the output format
328 * \param owner owner video buffer callbacks
329 * \return new filter chain, or NULL on error
331 VLC_API filter_chain_t * filter_chain_NewVideo( vlc_object_t *obj, bool change,
332 const filter_owner_t *owner )
333 VLC_USED;
334 #define filter_chain_NewVideo( a, b, c ) \
335 filter_chain_NewVideo( VLC_OBJECT( a ), b, c )
338 * Delete filter chain will delete all filters in the chain and free all
339 * allocated data. The pointer to the filter chain is then no longer valid.
341 * \param p_chain pointer to filter chain
343 VLC_API void filter_chain_Delete( filter_chain_t * );
346 * Reset filter chain will delete all filters in the chain and
347 * reset p_fmt_in and p_fmt_out to the new values.
349 * \param p_chain pointer to filter chain
350 * \param p_fmt_in new fmt_in params, may be NULL to leave input fmt unchanged
351 * \param p_fmt_out new fmt_out params, may be NULL to leave output fmt unchanged
353 VLC_API void filter_chain_Reset( filter_chain_t *, const es_format_t *, const es_format_t * );
356 * Append a filter to the chain.
358 * \param chain filter chain to append a filter to
359 * \param name filter name
360 * \param fmt_in filter input format
361 * \param fmt_out filter output format
362 * \return a pointer to the filter or NULL on error
364 VLC_API filter_t *filter_chain_AppendFilter(filter_chain_t *chain,
365 const char *name, config_chain_t *cfg, const es_format_t *fmt_in,
366 const es_format_t *fmt_out);
369 * Append a conversion to the chain.
371 * \param chain filter chain to append a filter to
372 * \param fmt_in filter input format
373 * \param fmt_out filter output format
374 * \retval 0 on success
375 * \retval -1 on failure
377 VLC_API int filter_chain_AppendConverter(filter_chain_t *chain,
378 const es_format_t *fmt_in, const es_format_t *fmt_out);
381 * Append new filter to filter chain from string.
383 * \param chain filter chain to append a filter to
384 * \param str filters chain nul-terminated string
386 VLC_API int filter_chain_AppendFromString(filter_chain_t *chain,
387 const char *str);
390 * Delete filter from filter chain. This function also releases the filter
391 * object and unloads the filter modules. The pointer to p_filter is no
392 * longer valid after this function successfully returns.
394 * \param chain filter chain to remove the filter from
395 * \param filter filter to remove from the chain and delete
397 VLC_API void filter_chain_DeleteFilter(filter_chain_t *chain,
398 filter_t *filter);
401 * Checks if the filter chain is empty.
403 * \param chain pointer to filter chain
404 * \return true if and only if there are no filters in this filter chain
406 VLC_API bool filter_chain_IsEmpty(const filter_chain_t *chain);
409 * Get last output format of the last element in the filter chain.
411 * \param chain filter chain
413 VLC_API const es_format_t *filter_chain_GetFmtOut(filter_chain_t *chain);
416 * Apply the filter chain to a video picture.
418 * \param chain pointer to filter chain
419 * \param pic picture to apply filters to
420 * \return modified picture after applying all video filters
422 VLC_API picture_t *filter_chain_VideoFilter(filter_chain_t *chain,
423 picture_t *pic);
426 * Flush a video filter chain.
428 VLC_API void filter_chain_VideoFlush( filter_chain_t * );
431 * Generate subpictures from a chain of subpicture source "filters".
433 * \param chain filter chain
434 * \param display_date of subpictures
436 void filter_chain_SubSource(filter_chain_t *chain, spu_t *,
437 vlc_tick_t display_date);
440 * Apply filter chain to subpictures.
442 * \param chain filter chain
443 * \param subpic subpicture to apply filters on
444 * \return modified subpicture after applying all subpicture filters
446 VLC_API subpicture_t *filter_chain_SubFilter(filter_chain_t *chain,
447 subpicture_t *subpic);
450 * Apply the filter chain to a mouse state.
452 * It will be applied from the output to the input. It makes sense only
453 * for a video filter chain.
455 * The vlc_mouse_t* pointers may be the same.
457 VLC_API int filter_chain_MouseFilter( filter_chain_t *, struct vlc_mouse_t *,
458 const struct vlc_mouse_t * );
461 * Inform the filter chain of mouse state.
463 * It makes sense only for a sub source chain.
465 VLC_API int filter_chain_MouseEvent( filter_chain_t *,
466 const struct vlc_mouse_t *,
467 const video_format_t * );
469 int filter_chain_ForEach( filter_chain_t *chain,
470 int (*cb)( filter_t *, void * ), void *opaque );
472 /** @} */
473 #endif /* _VLC_FILTER_H */