stream_filter:hds: the xml reader type is not an ES category
[vlc.git] / include / vlc_filter.h
blobd26cad53a994601f602e8e14523e3bb29fe31ceb
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 VLC_COMMON_MEMBERS
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 union
123 /** Filter mouse state (video filter).
125 * If non-NULL, you must convert from output to input formats:
126 * - If VLC_SUCCESS is returned, the mouse state is propagated.
127 * - Otherwise, the mouse change is not propagated.
128 * If NULL, the mouse state is considered unchanged and will be
129 * propagated. */
130 int (*pf_video_mouse)( filter_t *, struct vlc_mouse_t *,
131 const struct vlc_mouse_t *p_old,
132 const struct vlc_mouse_t *p_new );
133 int (*pf_sub_mouse)( filter_t *, const struct vlc_mouse_t *p_old,
134 const struct vlc_mouse_t *p_new,
135 const video_format_t * );
138 /* Input attachments
139 * XXX use filter_GetInputAttachments */
140 int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
142 /* Private structure for the owner of the decoder */
143 filter_owner_t owner;
147 * This function will return a new picture usable by p_filter as an output
148 * buffer. You have to release it using picture_Release or by returning
149 * it to the caller as a pf_video_filter return value.
150 * Provided for convenience.
152 * \param p_filter filter_t object
153 * \return new picture on success or NULL on failure
155 static inline picture_t *filter_NewPicture( filter_t *p_filter )
157 picture_t *pic = p_filter->owner.video.buffer_new( p_filter );
158 if( pic == NULL )
159 msg_Warn( p_filter, "can't get output picture" );
160 return pic;
164 * Flush a filter
166 * This function will flush the state of a filter (audio or video).
168 static inline void filter_Flush( filter_t *p_filter )
170 if( p_filter->pf_flush != NULL )
171 p_filter->pf_flush( p_filter );
175 * This function will drain, then flush an audio filter.
177 static inline block_t *filter_DrainAudio( filter_t *p_filter )
179 if( p_filter->pf_audio_drain )
180 return p_filter->pf_audio_drain( p_filter );
181 else
182 return NULL;
186 * This function will return a new subpicture usable by p_filter as an output
187 * buffer. You have to release it using subpicture_Delete or by returning it to
188 * the caller as a pf_sub_source return value.
189 * Provided for convenience.
191 * \param p_filter filter_t object
192 * \return new subpicture
194 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
196 subpicture_t *subpic = p_filter->owner.sub.buffer_new( p_filter );
197 if( subpic == NULL )
198 msg_Warn( p_filter, "can't get output subpicture" );
199 return subpic;
203 * This function gives all input attachments at once.
205 * You MUST release the returned values
207 static inline int filter_GetInputAttachments( filter_t *p_filter,
208 input_attachment_t ***ppp_attachment,
209 int *pi_attachment )
211 if( !p_filter->pf_get_attachments )
212 return VLC_EGENERIC;
213 return p_filter->pf_get_attachments( p_filter,
214 ppp_attachment, pi_attachment );
218 * This function duplicates every variables from the filter, and adds a proxy
219 * callback to trigger filter events from obj.
221 * \param restart_cb a vlc_callback_t to call if the event means restarting the
222 * filter (i.e. an event on a non-command variable)
224 VLC_API void filter_AddProxyCallbacks( vlc_object_t *obj, filter_t *filter,
225 vlc_callback_t restart_cb );
226 # define filter_AddProxyCallbacks(a, b, c) \
227 filter_AddProxyCallbacks(VLC_OBJECT(a), b, c)
230 * This function removes the callbacks previously added to every duplicated
231 * variables, and removes them afterward.
233 * \param restart_cb the same vlc_callback_t passed to filter_AddProxyCallbacks
235 VLC_API void filter_DelProxyCallbacks( vlc_object_t *obj, filter_t *filter,
236 vlc_callback_t restart_cb);
237 # define filter_DelProxyCallbacks(a, b, c) \
238 filter_DelProxyCallbacks(VLC_OBJECT(a), b, c)
241 * It creates a blend filter.
243 * Only the chroma properties of the dest format is used (chroma
244 * type, rgb masks and shifts)
246 VLC_API filter_t * filter_NewBlend( vlc_object_t *, const video_format_t *p_dst_chroma ) VLC_USED;
249 * It configures blend filter parameters that are allowed to changed
250 * after the creation.
252 VLC_API int filter_ConfigureBlend( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src );
255 * It blends a picture into another one.
257 * The input picture is not modified and not released.
259 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 );
262 * It destroys a blend filter created by filter_NewBlend.
264 VLC_API void filter_DeleteBlend( filter_t * );
267 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
268 * using a void (*)( filter_t *, picture_t *, picture_t * ) function
270 * Currently used by the chroma video filters
272 #define VIDEO_FILTER_WRAPPER( name ) \
273 static picture_t *name ## _Filter ( filter_t *p_filter, \
274 picture_t *p_pic ) \
276 picture_t *p_outpic = filter_NewPicture( p_filter ); \
277 if( p_outpic ) \
279 name( p_filter, p_pic, p_outpic ); \
280 picture_CopyProperties( p_outpic, p_pic ); \
282 picture_Release( p_pic ); \
283 return p_outpic; \
287 * Filter chain management API
288 * The filter chain management API is used to dynamically construct filters
289 * and add them in a chain.
292 typedef struct filter_chain_t filter_chain_t;
295 * Create new filter chain
297 * \param p_object pointer to a vlc object
298 * \param psz_capability vlc capability of filters in filter chain
299 * \return pointer to a filter chain
301 filter_chain_t * filter_chain_New( vlc_object_t *, const char *, enum es_format_category_e )
302 VLC_USED;
303 #define filter_chain_New( a, b, c ) filter_chain_New( VLC_OBJECT( a ), b, c )
306 * Creates a new video filter chain.
308 * \param obj pointer to parent VLC object
309 * \param change whether to allow changing the output format
310 * \param owner owner video buffer callbacks
311 * \return new filter chain, or NULL on error
313 VLC_API filter_chain_t * filter_chain_NewVideo( vlc_object_t *obj, bool change,
314 const filter_owner_t *owner )
315 VLC_USED;
316 #define filter_chain_NewVideo( a, b, c ) \
317 filter_chain_NewVideo( VLC_OBJECT( a ), b, c )
320 * Delete filter chain will delete all filters in the chain and free all
321 * allocated data. The pointer to the filter chain is then no longer valid.
323 * \param p_chain pointer to filter chain
325 VLC_API void filter_chain_Delete( filter_chain_t * );
328 * Reset filter chain will delete all filters in the chain and
329 * reset p_fmt_in and p_fmt_out to the new values.
331 * \param p_chain pointer to filter chain
332 * \param p_fmt_in new fmt_in params
333 * \param p_fmt_out new fmt_out params
335 VLC_API void filter_chain_Reset( filter_chain_t *, const es_format_t *, const es_format_t * );
338 * Append a filter to the chain.
340 * \param chain filter chain to append a filter to
341 * \param name filter name
342 * \param fmt_in filter input format
343 * \param fmt_out filter output format
344 * \return a pointer to the filter or NULL on error
346 VLC_API filter_t *filter_chain_AppendFilter(filter_chain_t *chain,
347 const char *name, config_chain_t *cfg, const es_format_t *fmt_in,
348 const es_format_t *fmt_out);
351 * Append a conversion to the chain.
353 * \param chain filter chain to append a filter to
354 * \param fmt_in filter input format
355 * \param fmt_out filter output format
356 * \retval 0 on success
357 * \retval -1 on failure
359 VLC_API int filter_chain_AppendConverter(filter_chain_t *chain,
360 const es_format_t *fmt_in, const es_format_t *fmt_out);
363 * Append new filter to filter chain from string.
365 * \param chain filter chain to append a filter to
366 * \param str filters chain nul-terminated string
368 VLC_API int filter_chain_AppendFromString(filter_chain_t *chain,
369 const char *str);
372 * Delete filter from filter chain. This function also releases the filter
373 * object and unloads the filter modules. The pointer to p_filter is no
374 * longer valid after this function successfully returns.
376 * \param chain filter chain to remove the filter from
377 * \param filter filter to remove from the chain and delete
379 VLC_API void filter_chain_DeleteFilter(filter_chain_t *chain,
380 filter_t *filter);
383 * Get the number of filters in the filter chain.
385 * \param chain pointer to filter chain
386 * \return number of filters in this filter chain
388 VLC_API int filter_chain_GetLength(filter_chain_t *chain);
391 * Get last output format of the last element in the filter chain.
393 * \param chain filter chain
395 VLC_API const es_format_t *filter_chain_GetFmtOut(filter_chain_t *chain);
398 * Apply the filter chain to a video picture.
400 * \param chain pointer to filter chain
401 * \param pic picture to apply filters to
402 * \return modified picture after applying all video filters
404 VLC_API picture_t *filter_chain_VideoFilter(filter_chain_t *chain,
405 picture_t *pic);
408 * Flush a video filter chain.
410 VLC_API void filter_chain_VideoFlush( filter_chain_t * );
413 * Generate subpictures from a chain of subpicture source "filters".
415 * \param chain filter chain
416 * \param display_date of subpictures
418 void filter_chain_SubSource(filter_chain_t *chain, spu_t *,
419 mtime_t display_date);
422 * Apply filter chain to subpictures.
424 * \param chain filter chain
425 * \param subpic subpicture to apply filters on
426 * \return modified subpicture after applying all subpicture filters
428 VLC_API subpicture_t *filter_chain_SubFilter(filter_chain_t *chain,
429 subpicture_t *subpic);
432 * Apply the filter chain to a mouse state.
434 * It will be applied from the output to the input. It makes sense only
435 * for a video filter chain.
437 * The vlc_mouse_t* pointers may be the same.
439 VLC_API int filter_chain_MouseFilter( filter_chain_t *, struct vlc_mouse_t *,
440 const struct vlc_mouse_t * );
443 * Inform the filter chain of mouse state.
445 * It makes sense only for a sub source chain.
447 VLC_API int filter_chain_MouseEvent( filter_chain_t *,
448 const struct vlc_mouse_t *,
449 const video_format_t * );
451 int filter_chain_ForEach( filter_chain_t *chain,
452 int (*cb)( filter_t *, void * ), void *opaque );
454 /** @} */
455 #endif /* _VLC_FILTER_H */