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>
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 *****************************************************************************/
26 #define VLC_FILTER_H 1
29 #include <vlc_picture.h>
32 * \defgroup filter Filters
34 * Audio, video, text filters
37 * Filter modules interface
40 struct filter_video_callbacks
42 picture_t
*(*buffer_new
)(filter_t
*);
45 struct filter_subpicture_callbacks
47 subpicture_t
*(*buffer_new
)(filter_t
*);
50 typedef struct filter_owner_t
54 const struct filter_video_callbacks
*video
;
55 const struct filter_subpicture_callbacks
*sub
;
62 /** Structure describing a filter
63 * @warning BIG FAT WARNING : the code relies on the first 4 members of
64 * filter_t and decoder_t to be the same, so if you have anything to add,
65 * do it at the end of the structure.
69 struct vlc_object_t obj
;
71 /* Module properties */
78 /* Output format of filter */
80 bool b_allow_fmt_out_change
;
82 /* Name of the "video filter" shortcut that is requested, can be NULL */
83 const char * psz_name
;
84 /* Filter configuration */
85 config_chain_t
* p_cfg
;
89 /** Filter a picture (video filter) */
90 picture_t
* (*pf_video_filter
)( filter_t
*, picture_t
* );
92 /** Filter an audio block (audio filter) */
93 block_t
* (*pf_audio_filter
)( filter_t
*, block_t
* );
95 /** Blend a subpicture onto a picture (blend) */
96 void (*pf_video_blend
)( filter_t
*, picture_t
*, const picture_t
*,
99 /** Generate a subpicture (sub source) */
100 subpicture_t
*(*pf_sub_source
)( filter_t
*, vlc_tick_t
);
102 /** Filter a subpicture (sub filter) */
103 subpicture_t
*(*pf_sub_filter
)( filter_t
*, subpicture_t
* );
105 /** Render text (text render) */
106 int (*pf_render
)( filter_t
*, subpicture_region_t
*,
107 subpicture_region_t
*, const vlc_fourcc_t
* );
112 /* TODO: video filter drain */
113 /** Drain (audio filter) */
114 block_t
*(*pf_audio_drain
) ( filter_t
* );
119 * Flush (i.e. discard) any internal buffer in a video or audio filter.
121 void (*pf_flush
)( filter_t
* );
125 * Pass a new viewpoint to audio filters. Filters like the spatialaudio one
126 * used for Ambisonics rendering will change its output according to this
129 void (*pf_change_viewpoint
)( filter_t
*, const vlc_viewpoint_t
* );
133 /** Filter mouse state (video filter).
135 * If non-NULL, you must convert from output to input formats:
136 * - If VLC_SUCCESS is returned, the mouse state is propagated.
137 * - Otherwise, the mouse change is not propagated.
138 * If NULL, the mouse state is considered unchanged and will be
140 int (*pf_video_mouse
)( filter_t
*, struct vlc_mouse_t
*,
141 const struct vlc_mouse_t
*p_old
,
142 const struct vlc_mouse_t
*p_new
);
146 * XXX use filter_GetInputAttachments */
147 int (*pf_get_attachments
)( filter_t
*, input_attachment_t
***, int * );
149 /** Private structure for the owner of the filter */
150 filter_owner_t owner
;
154 * This function will return a new picture usable by p_filter as an output
155 * buffer. You have to release it using picture_Release or by returning
156 * it to the caller as a pf_video_filter return value.
157 * Provided for convenience.
159 * \param p_filter filter_t object
160 * \return new picture on success or NULL on failure
162 static inline picture_t
*filter_NewPicture( filter_t
*p_filter
)
164 picture_t
*pic
= NULL
;
165 if ( p_filter
->owner
.video
!= NULL
&& p_filter
->owner
.video
->buffer_new
!= NULL
)
166 pic
= p_filter
->owner
.video
->buffer_new( p_filter
);
169 // legacy filter owners not setting a default filter_allocator
170 pic
= picture_NewFromFormat( &p_filter
->fmt_out
.video
);
173 msg_Warn( p_filter
, "can't get output picture" );
180 * This function will flush the state of a filter (audio or video).
182 static inline void filter_Flush( filter_t
*p_filter
)
184 if( p_filter
->pf_flush
!= NULL
)
185 p_filter
->pf_flush( p_filter
);
188 static inline void filter_ChangeViewpoint( filter_t
*p_filter
,
189 const vlc_viewpoint_t
*vp
)
191 if( p_filter
->pf_change_viewpoint
!= NULL
)
192 p_filter
->pf_change_viewpoint( p_filter
, vp
);
196 * This function will drain, then flush an audio filter.
198 static inline block_t
*filter_DrainAudio( filter_t
*p_filter
)
200 if( p_filter
->pf_audio_drain
)
201 return p_filter
->pf_audio_drain( p_filter
);
207 * This function will return a new subpicture usable by p_filter as an output
208 * buffer. You have to release it using subpicture_Delete or by returning it to
209 * the caller as a pf_sub_source return value.
210 * Provided for convenience.
212 * \param p_filter filter_t object
213 * \return new subpicture
215 static inline subpicture_t
*filter_NewSubpicture( filter_t
*p_filter
)
217 subpicture_t
*subpic
= p_filter
->owner
.sub
->buffer_new( p_filter
);
219 msg_Warn( p_filter
, "can't get output subpicture" );
224 * This function gives all input attachments at once.
226 * You MUST release the returned values
228 static inline int filter_GetInputAttachments( filter_t
*p_filter
,
229 input_attachment_t
***ppp_attachment
,
232 if( !p_filter
->pf_get_attachments
)
234 return p_filter
->pf_get_attachments( p_filter
,
235 ppp_attachment
, pi_attachment
);
239 * This function duplicates every variables from the filter, and adds a proxy
240 * callback to trigger filter events from obj.
242 * \param restart_cb a vlc_callback_t to call if the event means restarting the
243 * filter (i.e. an event on a non-command variable)
245 VLC_API
void filter_AddProxyCallbacks( vlc_object_t
*obj
, filter_t
*filter
,
246 vlc_callback_t restart_cb
);
247 # define filter_AddProxyCallbacks(a, b, c) \
248 filter_AddProxyCallbacks(VLC_OBJECT(a), b, c)
251 * This function removes the callbacks previously added to every duplicated
252 * variables, and removes them afterward.
254 * \param restart_cb the same vlc_callback_t passed to filter_AddProxyCallbacks
256 VLC_API
void filter_DelProxyCallbacks( vlc_object_t
*obj
, filter_t
*filter
,
257 vlc_callback_t restart_cb
);
258 # define filter_DelProxyCallbacks(a, b, c) \
259 filter_DelProxyCallbacks(VLC_OBJECT(a), b, c)
261 typedef filter_t vlc_blender_t
;
264 * It creates a blend filter.
266 * Only the chroma properties of the dest format is used (chroma
267 * type, rgb masks and shifts)
269 VLC_API vlc_blender_t
* filter_NewBlend( vlc_object_t
*, const video_format_t
*p_dst_chroma
) VLC_USED
;
272 * It configures blend filter parameters that are allowed to changed
273 * after the creation.
275 VLC_API
int filter_ConfigureBlend( vlc_blender_t
*, int i_dst_width
, int i_dst_height
, const video_format_t
*p_src
);
278 * It blends a picture into another one.
280 * The input picture is not modified and not released.
282 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
);
285 * It destroys a blend filter created by filter_NewBlend.
287 VLC_API
void filter_DeleteBlend( vlc_blender_t
* );
290 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
291 * using a void (*)( filter_t *, picture_t *, picture_t * ) function
293 * Currently used by the chroma video filters
295 #define VIDEO_FILTER_WRAPPER( name ) \
296 static picture_t *name ## _Filter ( filter_t *p_filter, \
299 picture_t *p_outpic = filter_NewPicture( p_filter ); \
302 name( p_filter, p_pic, p_outpic ); \
303 picture_CopyProperties( p_outpic, p_pic ); \
305 picture_Release( p_pic ); \
310 * Filter chain management API
311 * The filter chain management API is used to dynamically construct filters
312 * and add them in a chain.
315 typedef struct filter_chain_t filter_chain_t
;
318 * Create new filter chain
320 * \param obj pointer to a vlc object
321 * \param psz_capability vlc capability of filters in filter chain
322 * \return pointer to a filter chain
324 filter_chain_t
* filter_chain_NewSPU( vlc_object_t
*obj
, const char *psz_capability
)
326 #define filter_chain_NewSPU( a, b ) filter_chain_NewSPU( VLC_OBJECT( a ), b )
329 * Creates a new video filter chain.
331 * \param obj pointer to parent VLC object
332 * \param change whether to allow changing the output format
333 * \param owner owner video buffer callbacks
334 * \return new filter chain, or NULL on error
336 VLC_API filter_chain_t
* filter_chain_NewVideo( vlc_object_t
*obj
, bool change
,
337 const filter_owner_t
*owner
)
339 #define filter_chain_NewVideo( a, b, c ) \
340 filter_chain_NewVideo( VLC_OBJECT( a ), b, c )
343 * Delete filter chain will delete all filters in the chain and free all
344 * allocated data. The pointer to the filter chain is then no longer valid.
346 * \param p_chain pointer to filter chain
348 VLC_API
void filter_chain_Delete( filter_chain_t
* );
351 * Reset filter chain will delete all filters in the chain and
352 * reset p_fmt_in and p_fmt_out to the new values.
354 * \param p_chain pointer to filter chain
355 * \param p_fmt_in new fmt_in params
356 * \param p_fmt_out new fmt_out params
358 VLC_API
void filter_chain_Reset( filter_chain_t
*, const es_format_t
*, const es_format_t
* );
361 * Remove all existing filters
363 * \param p_chain pointer to filter chain
365 VLC_API
void filter_chain_Clear(filter_chain_t
*);
368 * Append a filter to the chain.
370 * \param chain filter chain to append a filter to
371 * \param name filter name
372 * \param fmt_in filter input format
373 * \param fmt_out filter output format
374 * \return a pointer to the filter or NULL on error
376 VLC_API filter_t
*filter_chain_AppendFilter(filter_chain_t
*chain
,
377 const char *name
, config_chain_t
*cfg
, const es_format_t
*fmt_in
,
378 const es_format_t
*fmt_out
);
381 * Append a conversion to the chain.
383 * \param chain filter chain to append a filter to
384 * \param fmt_in filter input format
385 * \param fmt_out filter output format
386 * \retval 0 on success
387 * \retval -1 on failure
389 VLC_API
int filter_chain_AppendConverter(filter_chain_t
*chain
,
390 const es_format_t
*fmt_in
, const es_format_t
*fmt_out
);
393 * Append new filter to filter chain from string.
395 * \param chain filter chain to append a filter to
396 * \param str filters chain nul-terminated string
398 VLC_API
int filter_chain_AppendFromString(filter_chain_t
*chain
,
402 * Delete filter from filter chain. This function also releases the filter
403 * object and unloads the filter modules. The pointer to p_filter is no
404 * longer valid after this function successfully returns.
406 * \param chain filter chain to remove the filter from
407 * \param filter filter to remove from the chain and delete
409 VLC_API
void filter_chain_DeleteFilter(filter_chain_t
*chain
,
413 * Checks if the filter chain is empty.
415 * \param chain pointer to filter chain
416 * \return true if and only if there are no filters in this filter chain
418 VLC_API
bool filter_chain_IsEmpty(const filter_chain_t
*chain
);
421 * Get last output format of the last element in the filter chain.
423 * \param chain filter chain
425 VLC_API
const es_format_t
*filter_chain_GetFmtOut(const filter_chain_t
*chain
);
428 * Apply the filter chain to a video picture.
430 * \param chain pointer to filter chain
431 * \param pic picture to apply filters to
432 * \return modified picture after applying all video filters
434 VLC_API picture_t
*filter_chain_VideoFilter(filter_chain_t
*chain
,
438 * Flush a video filter chain.
440 VLC_API
void filter_chain_VideoFlush( filter_chain_t
* );
443 * Generate subpictures from a chain of subpicture source "filters".
445 * \param chain filter chain
446 * \param display_date of subpictures
448 void filter_chain_SubSource(filter_chain_t
*chain
, spu_t
*,
449 vlc_tick_t display_date
);
452 * Apply filter chain to subpictures.
454 * \param chain filter chain
455 * \param subpic subpicture to apply filters on
456 * \return modified subpicture after applying all subpicture filters
458 VLC_API subpicture_t
*filter_chain_SubFilter(filter_chain_t
*chain
,
459 subpicture_t
*subpic
);
462 * Apply the filter chain to a mouse state.
464 * It will be applied from the output to the input. It makes sense only
465 * for a video filter chain.
467 * The vlc_mouse_t* pointers may be the same.
469 VLC_API
int filter_chain_MouseFilter( filter_chain_t
*, struct vlc_mouse_t
*,
470 const struct vlc_mouse_t
* );
472 int filter_chain_ForEach( filter_chain_t
*chain
,
473 int (*cb
)( filter_t
*, void * ), void *opaque
);
476 #endif /* _VLC_FILTER_H */