qt: actions_manager: compareRenderers -> getMatchingRenderer
[vlc.git] / include / vlc_filter.h
blob301ca94b4c7441f010acdd813f63cb43c627efe9
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 typedef struct filter_owner_t
43 void *sys;
45 union
47 struct
49 picture_t * (*buffer_new)( filter_t * );
50 } video;
51 struct
53 subpicture_t * (*buffer_new)( filter_t * );
54 } sub;
56 } filter_owner_t;
58 struct vlc_mouse_t;
60 /** Structure describing a filter
61 * @warning BIG FAT WARNING : the code relies on the first 4 members of
62 * filter_t and decoder_t to be the same, so if you have anything to add,
63 * do it at the end of the structure.
65 struct filter_t
67 struct vlc_common_members obj;
69 /* Module properties */
70 module_t * p_module;
71 filter_sys_t * p_sys;
73 /* Input format */
74 es_format_t fmt_in;
76 /* Output format of filter */
77 es_format_t fmt_out;
78 bool b_allow_fmt_out_change;
80 /* Name of the "video filter" shortcut that is requested, can be NULL */
81 const char * psz_name;
82 /* Filter configuration */
83 config_chain_t * p_cfg;
85 union
87 /** Filter a picture (video filter) */
88 picture_t * (*pf_video_filter)( filter_t *, picture_t * );
90 /** Filter an audio block (audio filter) */
91 block_t * (*pf_audio_filter)( filter_t *, block_t * );
93 /** Blend a subpicture onto a picture (blend) */
94 void (*pf_video_blend)( filter_t *, picture_t *, const picture_t *,
95 int, int, int );
97 /** Generate a subpicture (sub source) */
98 subpicture_t *(*pf_sub_source)( filter_t *, mtime_t );
100 /** Filter a subpicture (sub filter) */
101 subpicture_t *(*pf_sub_filter)( filter_t *, subpicture_t * );
103 /** Render text (text render) */
104 int (*pf_render)( filter_t *, subpicture_region_t *,
105 subpicture_region_t *, const vlc_fourcc_t * );
108 union
110 /* TODO: video filter drain */
111 /** Drain (audio filter) */
112 block_t *(*pf_audio_drain) ( filter_t * );
115 /** Flush
117 * Flush (i.e. discard) any internal buffer in a video or audio filter.
119 void (*pf_flush)( filter_t * );
121 /** Change viewpoint
123 * Pass a new viewpoint to audio filters. Filters like the spatialaudio one
124 * used for Ambisonics rendering will change its output according to this
125 * viewpoint.
127 void (*pf_change_viewpoint)( filter_t *, const vlc_viewpoint_t * );
129 union
131 /** Filter mouse state (video filter).
133 * If non-NULL, you must convert from output to input formats:
134 * - If VLC_SUCCESS is returned, the mouse state is propagated.
135 * - Otherwise, the mouse change is not propagated.
136 * If NULL, the mouse state is considered unchanged and will be
137 * propagated. */
138 int (*pf_video_mouse)( filter_t *, struct vlc_mouse_t *,
139 const struct vlc_mouse_t *p_old,
140 const struct vlc_mouse_t *p_new );
141 int (*pf_sub_mouse)( filter_t *, const struct vlc_mouse_t *p_old,
142 const struct vlc_mouse_t *p_new,
143 const video_format_t * );
146 /* Input attachments
147 * XXX use filter_GetInputAttachments */
148 int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
150 /* Private structure for the owner of the decoder */
151 filter_owner_t owner;
155 * This function will return a new picture usable by p_filter as an output
156 * buffer. You have to release it using picture_Release or by returning
157 * it to the caller as a pf_video_filter return value.
158 * Provided for convenience.
160 * \param p_filter filter_t object
161 * \return new picture on success or NULL on failure
163 static inline picture_t *filter_NewPicture( filter_t *p_filter )
165 picture_t *pic = p_filter->owner.video.buffer_new( p_filter );
166 if( pic == NULL )
167 msg_Warn( p_filter, "can't get output picture" );
168 return pic;
172 * Flush a filter
174 * This function will flush the state of a filter (audio or video).
176 static inline void filter_Flush( filter_t *p_filter )
178 if( p_filter->pf_flush != NULL )
179 p_filter->pf_flush( p_filter );
182 static inline void filter_ChangeViewpoint( filter_t *p_filter,
183 const vlc_viewpoint_t *vp)
185 if( p_filter->pf_change_viewpoint != NULL )
186 p_filter->pf_change_viewpoint( p_filter, vp );
190 * This function will drain, then flush an audio filter.
192 static inline block_t *filter_DrainAudio( filter_t *p_filter )
194 if( p_filter->pf_audio_drain )
195 return p_filter->pf_audio_drain( p_filter );
196 else
197 return NULL;
201 * This function will return a new subpicture usable by p_filter as an output
202 * buffer. You have to release it using subpicture_Delete or by returning it to
203 * the caller as a pf_sub_source return value.
204 * Provided for convenience.
206 * \param p_filter filter_t object
207 * \return new subpicture
209 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
211 subpicture_t *subpic = p_filter->owner.sub.buffer_new( p_filter );
212 if( subpic == NULL )
213 msg_Warn( p_filter, "can't get output subpicture" );
214 return subpic;
218 * This function gives all input attachments at once.
220 * You MUST release the returned values
222 static inline int filter_GetInputAttachments( filter_t *p_filter,
223 input_attachment_t ***ppp_attachment,
224 int *pi_attachment )
226 if( !p_filter->pf_get_attachments )
227 return VLC_EGENERIC;
228 return p_filter->pf_get_attachments( p_filter,
229 ppp_attachment, pi_attachment );
233 * This function duplicates every variables from the filter, and adds a proxy
234 * callback to trigger filter events from obj.
236 * \param restart_cb a vlc_callback_t to call if the event means restarting the
237 * filter (i.e. an event on a non-command variable)
239 VLC_API void filter_AddProxyCallbacks( vlc_object_t *obj, filter_t *filter,
240 vlc_callback_t restart_cb );
241 # define filter_AddProxyCallbacks(a, b, c) \
242 filter_AddProxyCallbacks(VLC_OBJECT(a), b, c)
245 * This function removes the callbacks previously added to every duplicated
246 * variables, and removes them afterward.
248 * \param restart_cb the same vlc_callback_t passed to filter_AddProxyCallbacks
250 VLC_API void filter_DelProxyCallbacks( vlc_object_t *obj, filter_t *filter,
251 vlc_callback_t restart_cb);
252 # define filter_DelProxyCallbacks(a, b, c) \
253 filter_DelProxyCallbacks(VLC_OBJECT(a), b, c)
256 * It creates a blend filter.
258 * Only the chroma properties of the dest format is used (chroma
259 * type, rgb masks and shifts)
261 VLC_API filter_t * filter_NewBlend( vlc_object_t *, const video_format_t *p_dst_chroma ) VLC_USED;
264 * It configures blend filter parameters that are allowed to changed
265 * after the creation.
267 VLC_API int filter_ConfigureBlend( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src );
270 * It blends a picture into another one.
272 * The input picture is not modified and not released.
274 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 );
277 * It destroys a blend filter created by filter_NewBlend.
279 VLC_API void filter_DeleteBlend( filter_t * );
282 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
283 * using a void (*)( filter_t *, picture_t *, picture_t * ) function
285 * Currently used by the chroma video filters
287 #define VIDEO_FILTER_WRAPPER( name ) \
288 static picture_t *name ## _Filter ( filter_t *p_filter, \
289 picture_t *p_pic ) \
291 picture_t *p_outpic = filter_NewPicture( p_filter ); \
292 if( p_outpic ) \
294 name( p_filter, p_pic, p_outpic ); \
295 picture_CopyProperties( p_outpic, p_pic ); \
297 picture_Release( p_pic ); \
298 return p_outpic; \
302 * Filter chain management API
303 * The filter chain management API is used to dynamically construct filters
304 * and add them in a chain.
307 typedef struct filter_chain_t filter_chain_t;
310 * Create new filter chain
312 * \param p_object pointer to a vlc object
313 * \param psz_capability vlc capability of filters in filter chain
314 * \return pointer to a filter chain
316 filter_chain_t * filter_chain_New( vlc_object_t *, const char *, enum es_format_category_e )
317 VLC_USED;
318 #define filter_chain_New( a, b, c ) filter_chain_New( VLC_OBJECT( a ), b, c )
321 * Creates a new video filter chain.
323 * \param obj pointer to parent VLC object
324 * \param change whether to allow changing the output format
325 * \param owner owner video buffer callbacks
326 * \return new filter chain, or NULL on error
328 VLC_API filter_chain_t * filter_chain_NewVideo( vlc_object_t *obj, bool change,
329 const filter_owner_t *owner )
330 VLC_USED;
331 #define filter_chain_NewVideo( a, b, c ) \
332 filter_chain_NewVideo( VLC_OBJECT( a ), b, c )
335 * Delete filter chain will delete all filters in the chain and free all
336 * allocated data. The pointer to the filter chain is then no longer valid.
338 * \param p_chain pointer to filter chain
340 VLC_API void filter_chain_Delete( filter_chain_t * );
343 * Reset filter chain will delete all filters in the chain and
344 * reset p_fmt_in and p_fmt_out to the new values.
346 * \param p_chain pointer to filter chain
347 * \param p_fmt_in new fmt_in params, may be NULL to leave input fmt unchanged
348 * \param p_fmt_out new fmt_out params, may be NULL to leave output fmt unchanged
350 VLC_API void filter_chain_Reset( filter_chain_t *, const es_format_t *, const es_format_t * );
353 * Append a filter to the chain.
355 * \param chain filter chain to append a filter to
356 * \param name filter name
357 * \param fmt_in filter input format
358 * \param fmt_out filter output format
359 * \return a pointer to the filter or NULL on error
361 VLC_API filter_t *filter_chain_AppendFilter(filter_chain_t *chain,
362 const char *name, config_chain_t *cfg, const es_format_t *fmt_in,
363 const es_format_t *fmt_out);
366 * Append a conversion to the chain.
368 * \param chain filter chain to append a filter to
369 * \param fmt_in filter input format
370 * \param fmt_out filter output format
371 * \retval 0 on success
372 * \retval -1 on failure
374 VLC_API int filter_chain_AppendConverter(filter_chain_t *chain,
375 const es_format_t *fmt_in, const es_format_t *fmt_out);
378 * Append new filter to filter chain from string.
380 * \param chain filter chain to append a filter to
381 * \param str filters chain nul-terminated string
383 VLC_API int filter_chain_AppendFromString(filter_chain_t *chain,
384 const char *str);
387 * Delete filter from filter chain. This function also releases the filter
388 * object and unloads the filter modules. The pointer to p_filter is no
389 * longer valid after this function successfully returns.
391 * \param chain filter chain to remove the filter from
392 * \param filter filter to remove from the chain and delete
394 VLC_API void filter_chain_DeleteFilter(filter_chain_t *chain,
395 filter_t *filter);
398 * Checks if the filter chain is empty.
400 * \param chain pointer to filter chain
401 * \return true if and only if there are no filters in this filter chain
403 VLC_API bool filter_chain_IsEmpty(const filter_chain_t *chain);
406 * Get last output format of the last element in the filter chain.
408 * \param chain filter chain
410 VLC_API const es_format_t *filter_chain_GetFmtOut(filter_chain_t *chain);
413 * Apply the filter chain to a video picture.
415 * \param chain pointer to filter chain
416 * \param pic picture to apply filters to
417 * \return modified picture after applying all video filters
419 VLC_API picture_t *filter_chain_VideoFilter(filter_chain_t *chain,
420 picture_t *pic);
423 * Flush a video filter chain.
425 VLC_API void filter_chain_VideoFlush( filter_chain_t * );
428 * Generate subpictures from a chain of subpicture source "filters".
430 * \param chain filter chain
431 * \param display_date of subpictures
433 void filter_chain_SubSource(filter_chain_t *chain, spu_t *,
434 mtime_t display_date);
437 * Apply filter chain to subpictures.
439 * \param chain filter chain
440 * \param subpic subpicture to apply filters on
441 * \return modified subpicture after applying all subpicture filters
443 VLC_API subpicture_t *filter_chain_SubFilter(filter_chain_t *chain,
444 subpicture_t *subpic);
447 * Apply the filter chain to a mouse state.
449 * It will be applied from the output to the input. It makes sense only
450 * for a video filter chain.
452 * The vlc_mouse_t* pointers may be the same.
454 VLC_API int filter_chain_MouseFilter( filter_chain_t *, struct vlc_mouse_t *,
455 const struct vlc_mouse_t * );
458 * Inform the filter chain of mouse state.
460 * It makes sense only for a sub source chain.
462 VLC_API int filter_chain_MouseEvent( filter_chain_t *,
463 const struct vlc_mouse_t *,
464 const video_format_t * );
466 int filter_chain_ForEach( filter_chain_t *chain,
467 int (*cb)( filter_t *, void * ), void *opaque );
469 /** @} */
470 #endif /* _VLC_FILTER_H */