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>
30 #include <vlc_codec.h>
32 typedef struct vlc_video_context vlc_video_context
;
33 struct vlc_audio_loudness
;
36 * \defgroup filter Filters
38 * Audio, video, text filters
41 * Filter modules interface
44 struct filter_video_callbacks
46 picture_t
*(*buffer_new
)(filter_t
*);
47 vlc_decoder_device
* (*hold_device
)(vlc_object_t
*, void *sys
);
50 struct filter_audio_callbacks
54 void (*on_changed
)(filter_t
*,
55 const struct vlc_audio_loudness
*loudness
);
59 struct filter_subpicture_callbacks
61 subpicture_t
*(*buffer_new
)(filter_t
*);
64 typedef struct filter_owner_t
68 const struct filter_video_callbacks
*video
;
69 const struct filter_audio_callbacks
*audio
;
70 const struct filter_subpicture_callbacks
*sub
;
74 * XXX use filter_GetInputAttachments */
75 int (*pf_get_attachments
)( filter_t
*, input_attachment_t
***, int * );
82 /** Structure describing a filter
83 * @warning BIG FAT WARNING : the code relies on the first 4 members of
84 * filter_t and decoder_t to be the same, so if you have anything to add,
85 * do it at the end of the structure.
89 struct vlc_object_t obj
;
91 /* Module properties */
97 vlc_video_context
*vctx_in
; // video filter, set by owner
99 /* Output format of filter */
101 vlc_video_context
*vctx_out
; // video filter, handled by the filter
102 bool b_allow_fmt_out_change
;
104 /* Name of the "video filter" shortcut that is requested, can be NULL */
105 const char * psz_name
;
106 /* Filter configuration */
107 config_chain_t
* p_cfg
;
111 /** Filter a picture (video filter) */
112 picture_t
* (*pf_video_filter
)( filter_t
*, picture_t
* );
114 /** Filter an audio block (audio filter) */
115 block_t
* (*pf_audio_filter
)( filter_t
*, block_t
* );
117 /** Blend a subpicture onto a picture (blend) */
118 void (*pf_video_blend
)( filter_t
*, picture_t
*, const picture_t
*,
121 /** Generate a subpicture (sub source) */
122 subpicture_t
*(*pf_sub_source
)( filter_t
*, vlc_tick_t
);
124 /** Filter a subpicture (sub filter) */
125 subpicture_t
*(*pf_sub_filter
)( filter_t
*, subpicture_t
* );
127 /** Render text (text render) */
128 int (*pf_render
)( filter_t
*, subpicture_region_t
*,
129 subpicture_region_t
*, const vlc_fourcc_t
* );
134 /* TODO: video filter drain */
135 /** Drain (audio filter) */
136 block_t
*(*pf_audio_drain
) ( filter_t
* );
141 * Flush (i.e. discard) any internal buffer in a video or audio filter.
143 void (*pf_flush
)( filter_t
* );
147 * Pass a new viewpoint to audio filters. Filters like the spatialaudio one
148 * used for Ambisonics rendering will change its output according to this
151 void (*pf_change_viewpoint
)( filter_t
*, const vlc_viewpoint_t
* );
155 /** Filter mouse state (video filter).
157 * If non-NULL, you must convert from output to input formats:
158 * - If VLC_SUCCESS is returned, the mouse state is propagated.
159 * - Otherwise, the mouse change is not propagated.
160 * If NULL, the mouse state is considered unchanged and will be
162 int (*pf_video_mouse
)( filter_t
*, struct vlc_mouse_t
*,
163 const struct vlc_mouse_t
*p_old
);
166 /** Private structure for the owner of the filter */
167 filter_owner_t owner
;
171 * This function will return a new picture usable by p_filter as an output
172 * buffer. You have to release it using picture_Release or by returning
173 * it to the caller as a pf_video_filter return value.
174 * Provided for convenience.
176 * \param p_filter filter_t object
177 * \return new picture on success or NULL on failure
179 static inline picture_t
*filter_NewPicture( filter_t
*p_filter
)
181 picture_t
*pic
= NULL
;
182 if ( p_filter
->owner
.video
!= NULL
&& p_filter
->owner
.video
->buffer_new
!= NULL
)
183 pic
= p_filter
->owner
.video
->buffer_new( p_filter
);
186 // legacy filter owners not setting a default filter_allocator
187 pic
= picture_NewFromFormat( &p_filter
->fmt_out
.video
);
190 msg_Warn( p_filter
, "can't get output picture" );
197 * This function will flush the state of a filter (audio or video).
199 static inline void filter_Flush( filter_t
*p_filter
)
201 if( p_filter
->pf_flush
!= NULL
)
202 p_filter
->pf_flush( p_filter
);
205 static inline void filter_ChangeViewpoint( filter_t
*p_filter
,
206 const vlc_viewpoint_t
*vp
)
208 if( p_filter
->pf_change_viewpoint
!= NULL
)
209 p_filter
->pf_change_viewpoint( p_filter
, vp
);
212 static inline vlc_decoder_device
* filter_HoldDecoderDevice( filter_t
*p_filter
)
214 if ( !p_filter
->owner
.video
|| !p_filter
->owner
.video
->hold_device
)
217 return p_filter
->owner
.video
->hold_device( VLC_OBJECT(p_filter
), p_filter
->owner
.sys
);
220 static inline vlc_decoder_device
* filter_HoldDecoderDeviceType( filter_t
*p_filter
,
221 enum vlc_decoder_device_type type
)
223 if ( !p_filter
->owner
.video
|| !p_filter
->owner
.video
->hold_device
)
226 vlc_decoder_device
*dec_dev
= p_filter
->owner
.video
->hold_device( VLC_OBJECT(p_filter
),
227 p_filter
->owner
.sys
);
228 if ( dec_dev
!= NULL
)
230 if ( dec_dev
->type
== type
)
232 vlc_decoder_device_Release(dec_dev
);
238 * This function will drain, then flush an audio filter.
240 static inline block_t
*filter_DrainAudio( filter_t
*p_filter
)
242 if( p_filter
->pf_audio_drain
)
243 return p_filter
->pf_audio_drain( p_filter
);
248 static inline void filter_SendAudioLoudness(filter_t
*filter
,
249 const struct vlc_audio_loudness
*loudness
)
251 assert(filter
->owner
.audio
->meter_loudness
.on_changed
);
252 filter
->owner
.audio
->meter_loudness
.on_changed(filter
, loudness
);
256 * This function will return a new subpicture usable by p_filter as an output
257 * buffer. You have to release it using subpicture_Delete or by returning it to
258 * the caller as a pf_sub_source return value.
259 * Provided for convenience.
261 * \param p_filter filter_t object
262 * \return new subpicture
264 static inline subpicture_t
*filter_NewSubpicture( filter_t
*p_filter
)
266 subpicture_t
*subpic
= p_filter
->owner
.sub
->buffer_new( p_filter
);
268 msg_Warn( p_filter
, "can't get output subpicture" );
273 * This function gives all input attachments at once.
275 * You MUST release the returned values
277 static inline int filter_GetInputAttachments( filter_t
*p_filter
,
278 input_attachment_t
***ppp_attachment
,
281 if( !p_filter
->owner
.pf_get_attachments
)
283 return p_filter
->owner
.pf_get_attachments( p_filter
,
284 ppp_attachment
, pi_attachment
);
288 * This function duplicates every variables from the filter, and adds a proxy
289 * callback to trigger filter events from obj.
291 * \param restart_cb a vlc_callback_t to call if the event means restarting the
292 * filter (i.e. an event on a non-command variable)
294 VLC_API
void filter_AddProxyCallbacks( vlc_object_t
*obj
, filter_t
*filter
,
295 vlc_callback_t restart_cb
);
296 # define filter_AddProxyCallbacks(a, b, c) \
297 filter_AddProxyCallbacks(VLC_OBJECT(a), b, c)
300 * This function removes the callbacks previously added to every duplicated
301 * variables, and removes them afterward.
303 * \param restart_cb the same vlc_callback_t passed to filter_AddProxyCallbacks
305 VLC_API
void filter_DelProxyCallbacks( vlc_object_t
*obj
, filter_t
*filter
,
306 vlc_callback_t restart_cb
);
307 # define filter_DelProxyCallbacks(a, b, c) \
308 filter_DelProxyCallbacks(VLC_OBJECT(a), b, c)
310 typedef filter_t vlc_blender_t
;
313 * It creates a blend filter.
315 * Only the chroma properties of the dest format is used (chroma
316 * type, rgb masks and shifts)
318 VLC_API vlc_blender_t
* filter_NewBlend( vlc_object_t
*, const video_format_t
*p_dst_chroma
) VLC_USED
;
321 * It configures blend filter parameters that are allowed to changed
322 * after the creation.
324 VLC_API
int filter_ConfigureBlend( vlc_blender_t
*, int i_dst_width
, int i_dst_height
, const video_format_t
*p_src
);
327 * It blends a picture into another one.
329 * The input picture is not modified and not released.
331 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
);
334 * It destroys a blend filter created by filter_NewBlend.
336 VLC_API
void filter_DeleteBlend( vlc_blender_t
* );
339 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
340 * using a void (*)( filter_t *, picture_t *, picture_t * ) function
342 * Currently used by the chroma video filters
344 #define VIDEO_FILTER_WRAPPER( name ) \
345 static picture_t *name ## _Filter ( filter_t *p_filter, \
348 picture_t *p_outpic = filter_NewPicture( p_filter ); \
351 name( p_filter, p_pic, p_outpic ); \
352 picture_CopyProperties( p_outpic, p_pic ); \
354 picture_Release( p_pic ); \
359 * Filter chain management API
360 * The filter chain management API is used to dynamically construct filters
361 * and add them in a chain.
364 typedef struct filter_chain_t filter_chain_t
;
367 * Create new filter chain
369 * \param obj pointer to a vlc object
370 * \param psz_capability vlc capability of filters in filter chain
371 * \return pointer to a filter chain
373 filter_chain_t
* filter_chain_NewSPU( vlc_object_t
*obj
, const char *psz_capability
)
375 #define filter_chain_NewSPU( a, b ) filter_chain_NewSPU( VLC_OBJECT( a ), b )
378 * Creates a new video filter chain.
380 * \param obj pointer to parent VLC object
381 * \param change whether to allow changing the output format
382 * \param owner owner video buffer callbacks
383 * \return new filter chain, or NULL on error
385 VLC_API filter_chain_t
* filter_chain_NewVideo( vlc_object_t
*obj
, bool change
,
386 const filter_owner_t
*owner
)
388 #define filter_chain_NewVideo( a, b, c ) \
389 filter_chain_NewVideo( VLC_OBJECT( a ), b, c )
392 * Delete filter chain will delete all filters in the chain and free all
393 * allocated data. The pointer to the filter chain is then no longer valid.
395 * \param p_chain pointer to filter chain
397 VLC_API
void filter_chain_Delete( filter_chain_t
* );
400 * Reset filter chain will delete all filters in the chain and
401 * reset p_fmt_in and p_fmt_out to the new values.
403 * \param p_chain pointer to filter chain
404 * \param p_fmt_in new fmt_in params
405 * \paramt vctx_in new input video context
406 * \param p_fmt_out new fmt_out params
408 VLC_API
void filter_chain_Reset( filter_chain_t
*p_chain
,
409 const es_format_t
*p_fmt_in
,
410 vlc_video_context
*vctx_in
,
411 const es_format_t
*p_fmt_out
);
414 * Remove all existing filters
416 * \param p_chain pointer to filter chain
418 VLC_API
void filter_chain_Clear(filter_chain_t
*);
421 * Append a filter to the chain.
423 * \param chain filter chain to append a filter to
424 * \param name filter name
425 * \param fmt_out filter output format
426 * \return a pointer to the filter or NULL on error
428 VLC_API filter_t
*filter_chain_AppendFilter(filter_chain_t
*chain
,
429 const char *name
, config_chain_t
*cfg
,
430 const es_format_t
*fmt_out
);
433 * Append a conversion to the chain.
435 * \param chain filter chain to append a filter to
436 * \param fmt_out filter output format
437 * \retval 0 on success
438 * \retval -1 on failure
440 VLC_API
int filter_chain_AppendConverter(filter_chain_t
*chain
,
441 const es_format_t
*fmt_out
);
444 * Append new filter to filter chain from string.
446 * \param chain filter chain to append a filter to
447 * \param str filters chain nul-terminated string
449 VLC_API
int filter_chain_AppendFromString(filter_chain_t
*chain
,
453 * Delete filter from filter chain. This function also releases the filter
454 * object and unloads the filter modules. The pointer to p_filter is no
455 * longer valid after this function successfully returns.
457 * \param chain filter chain to remove the filter from
458 * \param filter filter to remove from the chain and delete
460 VLC_API
void filter_chain_DeleteFilter(filter_chain_t
*chain
,
464 * Checks if the filter chain is empty.
466 * \param chain pointer to filter chain
467 * \return true if and only if there are no filters in this filter chain
469 VLC_API
bool filter_chain_IsEmpty(const filter_chain_t
*chain
);
472 * Get last output format of the last element in the filter chain.
474 * \param chain filter chain
476 VLC_API
const es_format_t
*filter_chain_GetFmtOut(const filter_chain_t
*chain
);
479 * Get last output video context of the last element in the filter chain.
480 * \note doesn't create change the reference count
482 * \param chain filter chain
484 VLC_API vlc_video_context
*filter_chain_GetVideoCtxOut(const filter_chain_t
*chain
);
487 * Apply the filter chain to a video picture.
489 * \param chain pointer to filter chain
490 * \param pic picture to apply filters to
491 * \return modified picture after applying all video filters
493 VLC_API picture_t
*filter_chain_VideoFilter(filter_chain_t
*chain
,
497 * Flush a video filter chain.
499 VLC_API
void filter_chain_VideoFlush( filter_chain_t
* );
502 * Generate subpictures from a chain of subpicture source "filters".
504 * \param chain filter chain
505 * \param display_date of subpictures
507 void filter_chain_SubSource(filter_chain_t
*chain
, spu_t
*,
508 vlc_tick_t display_date
);
511 * Apply filter chain to subpictures.
513 * \param chain filter chain
514 * \param subpic subpicture to apply filters on
515 * \return modified subpicture after applying all subpicture filters
517 VLC_API subpicture_t
*filter_chain_SubFilter(filter_chain_t
*chain
,
518 subpicture_t
*subpic
);
521 * Apply the filter chain to a mouse state.
523 * It will be applied from the output to the input. It makes sense only
524 * for a video filter chain.
526 * The vlc_mouse_t* pointers may be the same.
528 VLC_API
int filter_chain_MouseFilter( filter_chain_t
*, struct vlc_mouse_t
*,
529 const struct vlc_mouse_t
* );
531 VLC_API
int filter_chain_ForEach( filter_chain_t
*chain
,
532 int (*cb
)( filter_t
*, void * ), void *opaque
);
535 #endif /* _VLC_FILTER_H */