vout: vout_ChangeRate: remove display assert
[vlc.git] / include / vlc_filter.h
blob49e97f7988770285545bd95f2050474f21706c9a
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>
29 #include <vlc_picture.h>
30 #include <vlc_codec.h>
32 typedef struct vlc_video_context vlc_video_context;
34 /**
35 * \defgroup filter Filters
36 * \ingroup output
37 * Audio, video, text filters
38 * @{
39 * \file
40 * Filter modules interface
43 struct filter_video_callbacks
45 picture_t *(*buffer_new)(filter_t *);
46 vlc_decoder_device * (*hold_device)(vlc_object_t *, void *sys);
49 struct filter_subpicture_callbacks
51 subpicture_t *(*buffer_new)(filter_t *);
54 typedef struct filter_owner_t
56 union
58 const struct filter_video_callbacks *video;
59 const struct filter_subpicture_callbacks *sub;
61 void *sys;
62 } filter_owner_t;
64 struct vlc_mouse_t;
66 /** Structure describing a filter
67 * @warning BIG FAT WARNING : the code relies on the first 4 members of
68 * filter_t and decoder_t to be the same, so if you have anything to add,
69 * do it at the end of the structure.
71 struct filter_t
73 struct vlc_object_t obj;
75 /* Module properties */
76 module_t * p_module;
77 void *p_sys;
79 /* Input format */
80 es_format_t fmt_in;
81 vlc_video_context *vctx_in; // video filter, set by owner
83 /* Output format of filter */
84 es_format_t fmt_out;
85 vlc_video_context *vctx_out; // video filter, handled by the filter
86 bool b_allow_fmt_out_change;
88 /* Name of the "video filter" shortcut that is requested, can be NULL */
89 const char * psz_name;
90 /* Filter configuration */
91 config_chain_t * p_cfg;
93 union
95 /** Filter a picture (video filter) */
96 picture_t * (*pf_video_filter)( filter_t *, picture_t * );
98 /** Filter an audio block (audio filter) */
99 block_t * (*pf_audio_filter)( filter_t *, block_t * );
101 /** Blend a subpicture onto a picture (blend) */
102 void (*pf_video_blend)( filter_t *, picture_t *, const picture_t *,
103 int, int, int );
105 /** Generate a subpicture (sub source) */
106 subpicture_t *(*pf_sub_source)( filter_t *, vlc_tick_t );
108 /** Filter a subpicture (sub filter) */
109 subpicture_t *(*pf_sub_filter)( filter_t *, subpicture_t * );
111 /** Render text (text render) */
112 int (*pf_render)( filter_t *, subpicture_region_t *,
113 subpicture_region_t *, const vlc_fourcc_t * );
116 union
118 /* TODO: video filter drain */
119 /** Drain (audio filter) */
120 block_t *(*pf_audio_drain) ( filter_t * );
123 /** Flush
125 * Flush (i.e. discard) any internal buffer in a video or audio filter.
127 void (*pf_flush)( filter_t * );
129 /** Change viewpoint
131 * Pass a new viewpoint to audio filters. Filters like the spatialaudio one
132 * used for Ambisonics rendering will change its output according to this
133 * viewpoint.
135 void (*pf_change_viewpoint)( filter_t *, const vlc_viewpoint_t * );
137 union
139 /** Filter mouse state (video filter).
141 * If non-NULL, you must convert from output to input formats:
142 * - If VLC_SUCCESS is returned, the mouse state is propagated.
143 * - Otherwise, the mouse change is not propagated.
144 * If NULL, the mouse state is considered unchanged and will be
145 * propagated. */
146 int (*pf_video_mouse)( filter_t *, struct vlc_mouse_t *,
147 const struct vlc_mouse_t *p_old,
148 const struct vlc_mouse_t *p_new );
151 /* Input attachments
152 * XXX use filter_GetInputAttachments */
153 int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
155 /** Private structure for the owner of the filter */
156 filter_owner_t owner;
160 * This function will return a new picture usable by p_filter as an output
161 * buffer. You have to release it using picture_Release or by returning
162 * it to the caller as a pf_video_filter return value.
163 * Provided for convenience.
165 * \param p_filter filter_t object
166 * \return new picture on success or NULL on failure
168 static inline picture_t *filter_NewPicture( filter_t *p_filter )
170 picture_t *pic = NULL;
171 if ( p_filter->owner.video != NULL && p_filter->owner.video->buffer_new != NULL)
172 pic = p_filter->owner.video->buffer_new( p_filter );
173 if ( pic == NULL )
175 // legacy filter owners not setting a default filter_allocator
176 pic = picture_NewFromFormat( &p_filter->fmt_out.video );
178 if( pic == NULL )
179 msg_Warn( p_filter, "can't get output picture" );
180 return pic;
184 * Flush a filter
186 * This function will flush the state of a filter (audio or video).
188 static inline void filter_Flush( filter_t *p_filter )
190 if( p_filter->pf_flush != NULL )
191 p_filter->pf_flush( p_filter );
194 static inline void filter_ChangeViewpoint( filter_t *p_filter,
195 const vlc_viewpoint_t *vp)
197 if( p_filter->pf_change_viewpoint != NULL )
198 p_filter->pf_change_viewpoint( p_filter, vp );
201 static inline vlc_decoder_device * filter_HoldDecoderDevice( filter_t *p_filter )
203 if ( !p_filter->owner.video || !p_filter->owner.video->hold_device )
204 return NULL;
206 return p_filter->owner.video->hold_device( VLC_OBJECT(p_filter), p_filter->owner.sys );
209 static inline vlc_decoder_device * filter_HoldDecoderDeviceType( filter_t *p_filter,
210 enum vlc_decoder_device_type type )
212 if ( !p_filter->owner.video || !p_filter->owner.video->hold_device )
213 return NULL;
215 vlc_decoder_device *dec_dev = p_filter->owner.video->hold_device( VLC_OBJECT(p_filter),
216 p_filter->owner.sys );
217 if ( dec_dev != NULL )
219 if ( dec_dev->type == type )
220 return dec_dev;
221 vlc_decoder_device_Release(dec_dev);
223 return NULL;
227 * This function will drain, then flush an audio filter.
229 static inline block_t *filter_DrainAudio( filter_t *p_filter )
231 if( p_filter->pf_audio_drain )
232 return p_filter->pf_audio_drain( p_filter );
233 else
234 return NULL;
238 * This function will return a new subpicture usable by p_filter as an output
239 * buffer. You have to release it using subpicture_Delete or by returning it to
240 * the caller as a pf_sub_source return value.
241 * Provided for convenience.
243 * \param p_filter filter_t object
244 * \return new subpicture
246 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
248 subpicture_t *subpic = p_filter->owner.sub->buffer_new( p_filter );
249 if( subpic == NULL )
250 msg_Warn( p_filter, "can't get output subpicture" );
251 return subpic;
255 * This function gives all input attachments at once.
257 * You MUST release the returned values
259 static inline int filter_GetInputAttachments( filter_t *p_filter,
260 input_attachment_t ***ppp_attachment,
261 int *pi_attachment )
263 if( !p_filter->pf_get_attachments )
264 return VLC_EGENERIC;
265 return p_filter->pf_get_attachments( p_filter,
266 ppp_attachment, pi_attachment );
270 * This function duplicates every variables from the filter, and adds a proxy
271 * callback to trigger filter events from obj.
273 * \param restart_cb a vlc_callback_t to call if the event means restarting the
274 * filter (i.e. an event on a non-command variable)
276 VLC_API void filter_AddProxyCallbacks( vlc_object_t *obj, filter_t *filter,
277 vlc_callback_t restart_cb );
278 # define filter_AddProxyCallbacks(a, b, c) \
279 filter_AddProxyCallbacks(VLC_OBJECT(a), b, c)
282 * This function removes the callbacks previously added to every duplicated
283 * variables, and removes them afterward.
285 * \param restart_cb the same vlc_callback_t passed to filter_AddProxyCallbacks
287 VLC_API void filter_DelProxyCallbacks( vlc_object_t *obj, filter_t *filter,
288 vlc_callback_t restart_cb);
289 # define filter_DelProxyCallbacks(a, b, c) \
290 filter_DelProxyCallbacks(VLC_OBJECT(a), b, c)
292 typedef filter_t vlc_blender_t;
295 * It creates a blend filter.
297 * Only the chroma properties of the dest format is used (chroma
298 * type, rgb masks and shifts)
300 VLC_API vlc_blender_t * filter_NewBlend( vlc_object_t *, const video_format_t *p_dst_chroma ) VLC_USED;
303 * It configures blend filter parameters that are allowed to changed
304 * after the creation.
306 VLC_API int filter_ConfigureBlend( vlc_blender_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src );
309 * It blends a picture into another one.
311 * The input picture is not modified and not released.
313 VLC_API int filter_Blend( vlc_blender_t *, picture_t *p_dst, int i_dst_x, int i_dst_y, const picture_t *p_src, int i_alpha );
316 * It destroys a blend filter created by filter_NewBlend.
318 VLC_API void filter_DeleteBlend( vlc_blender_t * );
321 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
322 * using a void (*)( filter_t *, picture_t *, picture_t * ) function
324 * Currently used by the chroma video filters
326 #define VIDEO_FILTER_WRAPPER( name ) \
327 static picture_t *name ## _Filter ( filter_t *p_filter, \
328 picture_t *p_pic ) \
330 picture_t *p_outpic = filter_NewPicture( p_filter ); \
331 if( p_outpic ) \
333 name( p_filter, p_pic, p_outpic ); \
334 picture_CopyProperties( p_outpic, p_pic ); \
336 picture_Release( p_pic ); \
337 return p_outpic; \
341 * Filter chain management API
342 * The filter chain management API is used to dynamically construct filters
343 * and add them in a chain.
346 typedef struct filter_chain_t filter_chain_t;
349 * Create new filter chain
351 * \param obj pointer to a vlc object
352 * \param psz_capability vlc capability of filters in filter chain
353 * \return pointer to a filter chain
355 filter_chain_t * filter_chain_NewSPU( vlc_object_t *obj, const char *psz_capability )
356 VLC_USED;
357 #define filter_chain_NewSPU( a, b ) filter_chain_NewSPU( VLC_OBJECT( a ), b )
360 * Creates a new video filter chain.
362 * \param obj pointer to parent VLC object
363 * \param change whether to allow changing the output format
364 * \param owner owner video buffer callbacks
365 * \return new filter chain, or NULL on error
367 VLC_API filter_chain_t * filter_chain_NewVideo( vlc_object_t *obj, bool change,
368 const filter_owner_t *owner )
369 VLC_USED;
370 #define filter_chain_NewVideo( a, b, c ) \
371 filter_chain_NewVideo( VLC_OBJECT( a ), b, c )
374 * Delete filter chain will delete all filters in the chain and free all
375 * allocated data. The pointer to the filter chain is then no longer valid.
377 * \param p_chain pointer to filter chain
379 VLC_API void filter_chain_Delete( filter_chain_t * );
382 * Reset filter chain will delete all filters in the chain and
383 * reset p_fmt_in and p_fmt_out to the new values.
385 * \param p_chain pointer to filter chain
386 * \param p_fmt_in new fmt_in params
387 * \paramt vctx_in new input video context
388 * \param p_fmt_out new fmt_out params
390 VLC_API void filter_chain_Reset( filter_chain_t *p_chain,
391 const es_format_t *p_fmt_in,
392 vlc_video_context *vctx_in,
393 const es_format_t *p_fmt_out );
396 * Remove all existing filters
398 * \param p_chain pointer to filter chain
400 VLC_API void filter_chain_Clear(filter_chain_t *);
403 * Append a filter to the chain.
405 * \param chain filter chain to append a filter to
406 * \param name filter name
407 * \param fmt_out filter output format
408 * \return a pointer to the filter or NULL on error
410 VLC_API filter_t *filter_chain_AppendFilter(filter_chain_t *chain,
411 const char *name, config_chain_t *cfg,
412 const es_format_t *fmt_out);
415 * Append a conversion to the chain.
417 * \param chain filter chain to append a filter to
418 * \param fmt_out filter output format
419 * \retval 0 on success
420 * \retval -1 on failure
422 VLC_API int filter_chain_AppendConverter(filter_chain_t *chain,
423 const es_format_t *fmt_out);
426 * Append new filter to filter chain from string.
428 * \param chain filter chain to append a filter to
429 * \param str filters chain nul-terminated string
431 VLC_API int filter_chain_AppendFromString(filter_chain_t *chain,
432 const char *str);
435 * Delete filter from filter chain. This function also releases the filter
436 * object and unloads the filter modules. The pointer to p_filter is no
437 * longer valid after this function successfully returns.
439 * \param chain filter chain to remove the filter from
440 * \param filter filter to remove from the chain and delete
442 VLC_API void filter_chain_DeleteFilter(filter_chain_t *chain,
443 filter_t *filter);
446 * Checks if the filter chain is empty.
448 * \param chain pointer to filter chain
449 * \return true if and only if there are no filters in this filter chain
451 VLC_API bool filter_chain_IsEmpty(const filter_chain_t *chain);
454 * Get last output format of the last element in the filter chain.
456 * \param chain filter chain
458 VLC_API const es_format_t *filter_chain_GetFmtOut(const filter_chain_t *chain);
461 * Get last output video context of the last element in the filter chain.
462 * \note doesn't create change the reference count
464 * \param chain filter chain
466 VLC_API vlc_video_context *filter_chain_GetVideoCtxOut(const filter_chain_t *chain);
469 * Apply the filter chain to a video picture.
471 * \param chain pointer to filter chain
472 * \param pic picture to apply filters to
473 * \return modified picture after applying all video filters
475 VLC_API picture_t *filter_chain_VideoFilter(filter_chain_t *chain,
476 picture_t *pic);
479 * Flush a video filter chain.
481 VLC_API void filter_chain_VideoFlush( filter_chain_t * );
484 * Generate subpictures from a chain of subpicture source "filters".
486 * \param chain filter chain
487 * \param display_date of subpictures
489 void filter_chain_SubSource(filter_chain_t *chain, spu_t *,
490 vlc_tick_t display_date);
493 * Apply filter chain to subpictures.
495 * \param chain filter chain
496 * \param subpic subpicture to apply filters on
497 * \return modified subpicture after applying all subpicture filters
499 VLC_API subpicture_t *filter_chain_SubFilter(filter_chain_t *chain,
500 subpicture_t *subpic);
503 * Apply the filter chain to a mouse state.
505 * It will be applied from the output to the input. It makes sense only
506 * for a video filter chain.
508 * The vlc_mouse_t* pointers may be the same.
510 VLC_API int filter_chain_MouseFilter( filter_chain_t *, struct vlc_mouse_t *,
511 const struct vlc_mouse_t * );
513 VLC_API int filter_chain_ForEach( filter_chain_t *chain,
514 int (*cb)( filter_t *, void * ), void *opaque );
516 /** @} */
517 #endif /* _VLC_FILTER_H */