VLC  3.0.15
vlc_filter.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * vlc_filter.h: filter related structures and functions
3  *****************************************************************************
4  * Copyright (C) 1999-2014 VLC authors and VideoLAN
5  *
6  * Authors: Gildas Bazin <gbazin@videolan.org>
7  * Antoine Cellerier <dionoea at videolan dot org>
8  * RĂ©mi Denis-Courmont
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24 
25 #ifndef VLC_FILTER_H
26 #define VLC_FILTER_H 1
27 
28 #include <vlc_es.h>
29 
30 /**
31  * \defgroup filter Filters
32  * \ingroup output
33  * Audio, video, text filters
34  * @{
35  * \file
36  * Filter modules interface
37  */
38 
40 
41 typedef struct filter_owner_t
42 {
43  void *sys;
44 
45  union
46  {
47  struct
48  {
49  picture_t * (*buffer_new)( filter_t * );
50  } video;
51  struct
52  {
53  subpicture_t * (*buffer_new)( filter_t * );
54  } sub;
55  };
57 
58 struct vlc_mouse_t;
59 
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.
64  */
65 struct filter_t
66 {
68 
69  /* Module properties */
72 
73  /* Input format */
75 
76  /* Output format of filter */
79 
80  /* Name of the "video filter" shortcut that is requested, can be NULL */
81  const char * psz_name;
82  /* Filter configuration */
84 
85  union
86  {
87  /** Filter a picture (video filter) */
88  picture_t * (*pf_video_filter)( filter_t *, picture_t * );
89 
90  /** Filter an audio block (audio filter) */
91  block_t * (*pf_audio_filter)( filter_t *, block_t * );
92 
93  /** Blend a subpicture onto a picture (blend) */
94  void (*pf_video_blend)( filter_t *, picture_t *, const picture_t *,
95  int, int, int );
96 
97  /** Generate a subpicture (sub source) */
98  subpicture_t *(*pf_sub_source)( filter_t *, mtime_t );
99 
100  /** Filter a subpicture (sub filter) */
101  subpicture_t *(*pf_sub_filter)( filter_t *, subpicture_t * );
102 
103  /** Render text (text render) */
105  subpicture_region_t *, const vlc_fourcc_t * );
106  };
107 
108  union
109  {
110  /* TODO: video filter drain */
111  /** Drain (audio filter) */
112  block_t *(*pf_audio_drain) ( filter_t * );
113  };
114 
115  /** Flush
116  *
117  * Flush (i.e. discard) any internal buffer in a video or audio filter.
118  */
119  void (*pf_flush)( filter_t * );
120 
121  /** Change viewpoint
122  *
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.
126  */
128 
129  union
130  {
131  /** Filter mouse state (video filter).
132  *
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 * );
144  };
145 
146  /* Input attachments
147  * XXX use filter_GetInputAttachments */
149 
150  /* Private structure for the owner of the decoder */
152 };
153 
154 /**
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.
159  *
160  * \param p_filter filter_t object
161  * \return new picture on success or NULL on failure
162  */
163 static inline picture_t *filter_NewPicture( filter_t *p_filter )
164 {
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;
169 }
170 
171 /**
172  * Flush a filter
173  *
174  * This function will flush the state of a filter (audio or video).
175  */
176 static inline void filter_Flush( filter_t *p_filter )
177 {
178  if( p_filter->pf_flush != NULL )
179  p_filter->pf_flush( p_filter );
180 }
181 
182 static inline void filter_ChangeViewpoint( filter_t *p_filter,
183  const vlc_viewpoint_t *vp)
184 {
185  if( p_filter->pf_change_viewpoint != NULL )
186  p_filter->pf_change_viewpoint( p_filter, vp );
187 }
188 
189 /**
190  * This function will drain, then flush an audio filter.
191  */
192 static inline block_t *filter_DrainAudio( filter_t *p_filter )
193 {
194  if( p_filter->pf_audio_drain )
195  return p_filter->pf_audio_drain( p_filter );
196  else
197  return NULL;
198 }
199 
200 /**
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.
205  *
206  * \param p_filter filter_t object
207  * \return new subpicture
208  */
209 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
210 {
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;
215 }
216 
217 /**
218  * This function gives all input attachments at once.
219  *
220  * You MUST release the returned values
221  */
222 static inline int filter_GetInputAttachments( filter_t *p_filter,
223  input_attachment_t ***ppp_attachment,
224  int *pi_attachment )
225 {
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 );
230 }
231 
232 /**
233  * This function duplicates every variables from the filter, and adds a proxy
234  * callback to trigger filter events from obj.
235  *
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)
238  */
240  vlc_callback_t restart_cb );
241 # define filter_AddProxyCallbacks(a, b, c) \
242  filter_AddProxyCallbacks(VLC_OBJECT(a), b, c)
243 
244 /**
245  * This function removes the callbacks previously added to every duplicated
246  * variables, and removes them afterward.
247  *
248  * \param restart_cb the same vlc_callback_t passed to filter_AddProxyCallbacks
249  */
251  vlc_callback_t restart_cb);
252 # define filter_DelProxyCallbacks(a, b, c) \
253  filter_DelProxyCallbacks(VLC_OBJECT(a), b, c)
254 
255 /**
256  * It creates a blend filter.
257  *
258  * Only the chroma properties of the dest format is used (chroma
259  * type, rgb masks and shifts)
260  */
262 
263 /**
264  * It configures blend filter parameters that are allowed to changed
265  * after the creation.
266  */
267 VLC_API int filter_ConfigureBlend( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src );
268 
269 /**
270  * It blends a picture into another one.
271  *
272  * The input picture is not modified and not released.
273  */
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 );
275 
276 /**
277  * It destroys a blend filter created by filter_NewBlend.
278  */
280 
281 /**
282  * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
283  * using a void (*)( filter_t *, picture_t *, picture_t * ) function
284  *
285  * Currently used by the chroma video filters
286  */
287 #define VIDEO_FILTER_WRAPPER( name ) \
288  static picture_t *name ## _Filter ( filter_t *p_filter, \
289  picture_t *p_pic ) \
290  { \
291  picture_t *p_outpic = filter_NewPicture( p_filter ); \
292  if( p_outpic ) \
293  { \
294  name( p_filter, p_pic, p_outpic ); \
295  picture_CopyProperties( p_outpic, p_pic ); \
296  } \
297  picture_Release( p_pic ); \
298  return p_outpic; \
299  }
300 
301 /**
302  * Filter chain management API
303  * The filter chain management API is used to dynamically construct filters
304  * and add them in a chain.
305  */
306 
308 
309 /**
310  * Create new filter chain
311  *
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
315  */
317 VLC_USED;
318 #define filter_chain_New( a, b, c ) filter_chain_New( VLC_OBJECT( a ), b, c )
319 
320 /**
321  * Creates a new video filter chain.
322  *
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
327  */
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 )
333 
334 /**
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.
337  *
338  * \param p_chain pointer to filter chain
339  */
341 
342 /**
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.
345  *
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
349  */
351 
352 /**
353  * Append a filter to the chain.
354  *
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
360  */
362  const char *name, config_chain_t *cfg, const es_format_t *fmt_in,
363  const es_format_t *fmt_out);
364 
365 /**
366  * Append a conversion to the chain.
367  *
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
373  */
375  const es_format_t *fmt_in, const es_format_t *fmt_out);
376 
377 /**
378  * Append new filter to filter chain from string.
379  *
380  * \param chain filter chain to append a filter to
381  * \param str filters chain nul-terminated string
382  */
384  const char *str);
385 
386 /**
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.
390  *
391  * \param chain filter chain to remove the filter from
392  * \param filter filter to remove from the chain and delete
393  */
395  filter_t *filter);
396 
397 /**
398  * Checks if the filter chain is empty.
399  *
400  * \param chain pointer to filter chain
401  * \return true if and only if there are no filters in this filter chain
402  */
403 VLC_API bool filter_chain_IsEmpty(const filter_chain_t *chain);
404 
405 /**
406  * Get last output format of the last element in the filter chain.
407  *
408  * \param chain filter chain
409  */
411 
412 /**
413  * Apply the filter chain to a video picture.
414  *
415  * \param chain pointer to filter chain
416  * \param pic picture to apply filters to
417  * \return modified picture after applying all video filters
418  */
420  picture_t *pic);
421 
422 /**
423  * Flush a video filter chain.
424  */
426 
427 /**
428  * Generate subpictures from a chain of subpicture source "filters".
429  *
430  * \param chain filter chain
431  * \param display_date of subpictures
432  */
434  mtime_t display_date);
435 
436 /**
437  * Apply filter chain to subpictures.
438  *
439  * \param chain filter chain
440  * \param subpic subpicture to apply filters on
441  * \return modified subpicture after applying all subpicture filters
442  */
444  subpicture_t *subpic);
445 
446 /**
447  * Apply the filter chain to a mouse state.
448  *
449  * It will be applied from the output to the input. It makes sense only
450  * for a video filter chain.
451  *
452  * The vlc_mouse_t* pointers may be the same.
453  */
455  const struct vlc_mouse_t * );
456 
457 /**
458  * Inform the filter chain of mouse state.
459  *
460  * It makes sense only for a sub source chain.
461  */
463  const struct vlc_mouse_t *,
464  const video_format_t * );
465 
467  int (*cb)( filter_t *, void * ), void *opaque );
468 
469 /** @} */
470 #endif /* _VLC_FILTER_H */
vlc_mouse_t
Mouse state.
Definition: vlc_mouse.h:45
filter_chain_Delete
void filter_chain_Delete(filter_chain_t *)
Delete filter chain will delete all filters in the chain and free all allocated data.
Definition: filter_chain.c:148
vlc_es.h
VLC_API
#define VLC_API
Definition: fourcc_gen.c:30
VLC_COMMON_MEMBERS
#define VLC_COMMON_MEMBERS
Backward compatibility macro.
Definition: vlc_common.h:453
input_attachment_t
Definition: vlc_input.h:154
filter_chain_VideoFlush
void filter_chain_VideoFlush(filter_chain_t *)
Flush a video filter chain.
Definition: filter_chain.c:435
filter_owner_t::video
struct filter_owner_t::@166::@168 video
vlc_common.h
filter_t::p_module
module_t * p_module
Definition: vlc_filter.h:70
filter_ConfigureBlend
int filter_ConfigureBlend(filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src)
It configures blend filter parameters that are allowed to changed after the creation.
Definition: filter.c:134
filter_chain_DeleteFilter
void filter_chain_DeleteFilter(filter_chain_t *chain, filter_t *filter)
Delete filter from filter chain.
Definition: filter_chain.c:281
filter_DrainAudio
static block_t * filter_DrainAudio(filter_t *p_filter)
This function will drain, then flush an audio filter.
Definition: vlc_filter.h:192
filter_chain_t::fmt_in
es_format_t fmt_in
Chain input format (constant)
Definition: filter_chain.c:58
filter_DelProxyCallbacks
#define filter_DelProxyCallbacks(a, b, c)
Definition: vlc_filter.h:252
filter_owner_sys_t
struct filter_owner_sys_t filter_owner_sys_t
Definition: vlc_filter.h:39
filter_NewBlend
filter_t * filter_NewBlend(vlc_object_t *, const video_format_t *p_dst_chroma)
It creates a blend filter.
Definition: filter.c:104
filter_t::fmt_in
es_format_t fmt_in
Definition: vlc_filter.h:74
video_format_t
video format description
Definition: vlc_es.h:325
filter_owner_t
struct filter_owner_t filter_owner_t
vlc_viewpoint_t
Viewpoints.
Definition: vlc_viewpoint.h:44
filter_t::pf_sub_mouse
int(* pf_sub_mouse)(filter_t *, const struct vlc_mouse_t *p_old, const struct vlc_mouse_t *p_new, const video_format_t *)
Definition: vlc_filter.h:141
VLC_EGENERIC
#define VLC_EGENERIC
Unspecified error.
Definition: vlc_common.h:350
filter_t::pf_get_attachments
int(* pf_get_attachments)(filter_t *, input_attachment_t ***, int *)
Definition: vlc_filter.h:148
filter_Blend
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)
It blends a picture into another one.
Definition: filter.c:166
filter_Flush
static void filter_Flush(filter_t *p_filter)
Flush a filter.
Definition: vlc_filter.h:176
picture_t
Video picture.
Definition: vlc_picture.h:68
filter_chain_SubSource
void filter_chain_SubSource(filter_chain_t *chain, spu_t *, mtime_t display_date)
Generate subpictures from a chain of subpicture source "filters".
Definition: filter_chain.c:448
filter_t::pf_change_viewpoint
void(* pf_change_viewpoint)(filter_t *, const vlc_viewpoint_t *)
Change viewpoint.
Definition: vlc_filter.h:127
filter_sys_t
struct filter_sys_t filter_sys_t
Definition: vlc_common.h:284
filter_AddProxyCallbacks
#define filter_AddProxyCallbacks(a, b, c)
Definition: vlc_filter.h:241
filter_t::fmt_out
es_format_t fmt_out
Definition: vlc_filter.h:77
es_format_category_e
es_format_category_e
ES Categories.
Definition: vlc_es.h:563
filter_chain_GetFmtOut
const es_format_t * filter_chain_GetFmtOut(filter_chain_t *chain)
Get last output format of the last element in the filter chain.
Definition: filter_chain.c:380
msg_Warn
#define msg_Warn(p_this,...)
Definition: vlc_messages.h:84
filter_DeleteBlend
void filter_DeleteBlend(filter_t *)
It destroys a blend filter created by filter_NewBlend.
Definition: filter.c:177
filter_chain_NewVideo
#define filter_chain_NewVideo(a, b, c)
Definition: vlc_filter.h:331
filter_owner_t
Definition: vlc_filter.h:41
filter_chain_New
#define filter_chain_New(a, b, c)
Definition: vlc_filter.h:318
config_chain_t
Definition: vlc_configuration.h:155
module_t
Internal module descriptor.
Definition: modules.h:79
filter_t
Structure describing a filter.
Definition: vlc_filter.h:65
es_format_t
Definition: vlc_es.h:580
filter_owner_t::sys
void * sys
Definition: vlc_filter.h:43
subpicture_t
Video subtitle.
Definition: vlc_subpicture.h:153
filter_chain_MouseFilter
int filter_chain_MouseFilter(filter_chain_t *, struct vlc_mouse_t *, const struct vlc_mouse_t *)
Apply the filter chain to a mouse state.
spu_t
Subpicture unit descriptor.
Definition: vlc_spu.h:47
subpicture_region_t
Video subtitle region.
Definition: vlc_subpicture.h:57
filter_t::pf_render
int(* pf_render)(filter_t *, subpicture_region_t *, subpicture_region_t *, const vlc_fourcc_t *)
Render text (text render)
Definition: vlc_filter.h:104
filter_chain_ForEach
int filter_chain_ForEach(filter_chain_t *chain, int(*cb)(filter_t *, void *), void *opaque)
Definition: filter_chain.c:363
filter_NewSubpicture
static subpicture_t * filter_NewSubpicture(filter_t *p_filter)
This function will return a new subpicture usable by p_filter as an output buffer.
Definition: vlc_filter.h:209
vlc_object_t
The main vlc_object_t structure.
Definition: vlc_objects.h:39
filter_t::pf_audio_drain
block_t *(* pf_audio_drain)(filter_t *)
Drain (audio filter)
Definition: vlc_filter.h:112
filter_GetInputAttachments
static int filter_GetInputAttachments(filter_t *p_filter, input_attachment_t ***ppp_attachment, int *pi_attachment)
This function gives all input attachments at once.
Definition: vlc_filter.h:222
filter_chain_t
Definition: filter_chain.c:51
VLC_USED
#define VLC_USED
Definition: fourcc_gen.c:31
filter_t::pf_video_mouse
int(* pf_video_mouse)(filter_t *, struct vlc_mouse_t *, const struct vlc_mouse_t *p_old, const struct vlc_mouse_t *p_new)
Filter mouse state (video filter).
Definition: vlc_filter.h:138
filter_chain_IsEmpty
bool filter_chain_IsEmpty(const filter_chain_t *chain)
Checks if the filter chain is empty.
Definition: filter_chain.c:375
filter_chain_t::fmt_out
es_format_t fmt_out
Chain current output format.
Definition: filter_chain.c:59
filter_chain_VideoFilter
picture_t * filter_chain_VideoFilter(filter_chain_t *chain, picture_t *pic)
Apply the filter chain to a video picture.
Definition: filter_chain.c:412
name
const char name[16]
Definition: httpd.c:1249
filter_t::p_sys
filter_sys_t * p_sys
Definition: vlc_filter.h:71
filter_t::psz_name
const char * psz_name
Definition: vlc_filter.h:81
filter_t::pf_video_blend
void(* pf_video_blend)(filter_t *, picture_t *, const picture_t *, int, int, int)
Blend a subpicture onto a picture (blend)
Definition: vlc_filter.h:94
filter_ChangeViewpoint
static void filter_ChangeViewpoint(filter_t *p_filter, const vlc_viewpoint_t *vp)
Definition: vlc_filter.h:182
filter_NewPicture
static picture_t * filter_NewPicture(filter_t *p_filter)
This function will return a new picture usable by p_filter as an output buffer.
Definition: vlc_filter.h:163
filter_t::pf_flush
void(* pf_flush)(filter_t *)
Flush.
Definition: vlc_filter.h:119
mtime_t
int64_t mtime_t
High precision date or time interval.
Definition: vlc_common.h:150
filter_chain_t::owner
filter_owner_t owner
Owner (downstream) callbacks.
Definition: filter_chain.c:54
filter_owner_t::sub
struct filter_owner_t::@166::@169 sub
filter_chain_MouseEvent
int filter_chain_MouseEvent(filter_chain_t *, const struct vlc_mouse_t *, const video_format_t *)
Inform the filter chain of mouse state.
filter_t::b_allow_fmt_out_change
bool b_allow_fmt_out_change
Definition: vlc_filter.h:78
filter_chain_Reset
void filter_chain_Reset(filter_chain_t *, const es_format_t *, const es_format_t *)
Reset filter chain will delete all filters in the chain and reset p_fmt_in and p_fmt_out to the new v...
Definition: filter_chain.c:161
block_t
Definition: vlc_block.h:111
filter_chain_AppendConverter
int filter_chain_AppendConverter(filter_chain_t *chain, const es_format_t *fmt_in, const es_format_t *fmt_out)
Append a conversion to the chain.
Definition: filter_chain.c:274
filter_chain_SubFilter
subpicture_t * filter_chain_SubFilter(filter_chain_t *chain, subpicture_t *subpic)
Apply filter chain to subpictures.
Definition: filter_chain.c:460
filter_chain_AppendFilter
filter_t * filter_chain_AppendFilter(filter_chain_t *chain, const char *name, config_chain_t *cfg, const es_format_t *fmt_in, const es_format_t *fmt_out)
Append a filter to the chain.
Definition: filter_chain.c:266
vlc_fourcc_t
uint32_t vlc_fourcc_t
Definition: fourcc_gen.c:32
filter_t::p_cfg
config_chain_t * p_cfg
Definition: vlc_filter.h:83
filter_t::owner
filter_owner_t owner
Definition: vlc_filter.h:151
filter_chain_AppendFromString
int filter_chain_AppendFromString(filter_chain_t *chain, const char *str)
Append new filter to filter chain from string.
Definition: filter_chain.c:317
vlc_callback_t
int(* vlc_callback_t)(vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void *)
Definition: vlc_common.h:361