]> git.sesse.net Git - vlc/blob - include/vlc_filter.h
es_out: do not start buffering when already buferring
[vlc] / include / vlc_filter.h
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 #include <vlc_picture.h>
30 #include <vlc_subpicture.h>
31 #include <vlc_mouse.h>
32
33 /**
34  * \file
35  * This file defines the structure and types used by video and audio filters
36  */
37
38 typedef struct filter_owner_sys_t filter_owner_sys_t;
39
40 typedef struct filter_owner_t
41 {
42     void *sys;
43
44     union
45     {
46         struct
47         {
48             picture_t * (*buffer_new)( filter_t * );
49         } video;
50         struct
51         {
52             subpicture_t * (*buffer_new)( filter_t * );
53         } sub;
54     };
55 } filter_owner_t;
56
57
58 /** Structure describing a filter
59  * @warning BIG FAT WARNING : the code relies on the first 4 members of
60  * filter_t and decoder_t to be the same, so if you have anything to add,
61  * do it at the end of the structure.
62  */
63 struct filter_t
64 {
65     VLC_COMMON_MEMBERS
66
67     /* Module properties */
68     module_t *          p_module;
69     filter_sys_t *      p_sys;
70
71     /* Input format */
72     es_format_t         fmt_in;
73
74     /* Output format of filter */
75     es_format_t         fmt_out;
76     bool                b_allow_fmt_out_change;
77
78     /* Filter configuration */
79     config_chain_t *    p_cfg;
80
81     union
82     {
83         struct
84         {
85             picture_t * (*pf_filter) ( filter_t *, picture_t * );
86             void        (*pf_flush)( filter_t * );
87             /* Filter mouse state.
88              *
89              * If non-NULL, you must convert from output to input formats:
90              * - If VLC_SUCCESS is returned, the mouse state is propagated.
91              * - Otherwise, the mouse change is not propagated.
92              * If NULL, the mouse state is considered unchanged and will be
93              * propagated.
94              */
95             int         (*pf_mouse)( filter_t *, vlc_mouse_t *,
96                                      const vlc_mouse_t *p_old,
97                                      const vlc_mouse_t *p_new );
98         } video;
99 #define pf_video_filter     u.video.pf_filter
100 #define pf_video_flush      u.video.pf_flush
101 #define pf_video_mouse      u.video.pf_mouse
102
103         struct
104         {
105             block_t *   (*pf_filter) ( filter_t *, block_t * );
106         } audio;
107 #define pf_audio_filter     u.audio.pf_filter
108
109         struct
110         {
111             void        (*pf_blend) ( filter_t *,  picture_t *,
112                                       const picture_t *, int, int, int );
113         } blend;
114 #define pf_video_blend     u.blend.pf_blend
115
116         struct
117         {
118             subpicture_t * (*pf_source)    ( filter_t *, mtime_t );
119             int            (*pf_mouse)     ( filter_t *,
120                                              const vlc_mouse_t *p_old,
121                                              const vlc_mouse_t *p_new,
122                                              const video_format_t * );
123         } sub;
124 #define pf_sub_source      u.sub.pf_source
125 #define pf_sub_mouse       u.sub.pf_mouse
126
127         struct
128         {
129             subpicture_t * (*pf_filter) ( filter_t *, subpicture_t * );
130         } subf;
131 #define pf_sub_filter      u.subf.pf_filter
132
133         struct
134         {
135             int         (*pf_text) ( filter_t *, subpicture_region_t *,
136                                      subpicture_region_t *,
137                                      const vlc_fourcc_t * );
138             int         (*pf_html) ( filter_t *, subpicture_region_t *,
139                                      subpicture_region_t *,
140                                      const vlc_fourcc_t * );
141         } render;
142 #define pf_render_text     u.render.pf_text
143 #define pf_render_html     u.render.pf_html
144
145     } u;
146
147     /* Input attachments
148      * XXX use filter_GetInputAttachments */
149     int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
150
151     /* Private structure for the owner of the decoder */
152     filter_owner_t      owner;
153 };
154
155 /**
156  * This function will return a new picture usable by p_filter as an output
157  * buffer. You have to release it using picture_Release or by returning
158  * it to the caller as a pf_video_filter return value.
159  * Provided for convenience.
160  *
161  * \param p_filter filter_t object
162  * \return new picture on success or NULL on failure
163  */
164 static inline picture_t *filter_NewPicture( filter_t *p_filter )
165 {
166     picture_t *pic = p_filter->owner.video.buffer_new( p_filter );
167     if( pic == NULL )
168         msg_Warn( p_filter, "can't get output picture" );
169     return pic;
170 }
171
172 /**
173  * This function will flush the state of a video filter.
174  */
175 static inline void filter_FlushPictures( filter_t *p_filter )
176 {
177     if( p_filter->pf_video_flush )
178         p_filter->pf_video_flush( p_filter );
179 }
180
181 /**
182  * This function will return a new subpicture usable by p_filter as an output
183  * buffer. You have to release it using subpicture_Delete or by returning it to
184  * the caller as a pf_sub_source return value.
185  * Provided for convenience.
186  *
187  * \param p_filter filter_t object
188  * \return new subpicture
189  */
190 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
191 {
192     subpicture_t *subpic = p_filter->owner.sub.buffer_new( p_filter );
193     if( subpic == NULL )
194         msg_Warn( p_filter, "can't get output subpicture" );
195     return subpic;
196 }
197
198 /**
199  * This function gives all input attachments at once.
200  *
201  * You MUST release the returned values
202  */
203 static inline int filter_GetInputAttachments( filter_t *p_filter,
204                                               input_attachment_t ***ppp_attachment,
205                                               int *pi_attachment )
206 {
207     if( !p_filter->pf_get_attachments )
208         return VLC_EGENERIC;
209     return p_filter->pf_get_attachments( p_filter,
210                                          ppp_attachment, pi_attachment );
211 }
212
213 /**
214  * It creates a blend filter.
215  *
216  * Only the chroma properties of the dest format is used (chroma
217  * type, rgb masks and shifts)
218  */
219 VLC_API filter_t * filter_NewBlend( vlc_object_t *, const video_format_t *p_dst_chroma ) VLC_USED;
220
221 /**
222  * It configures blend filter parameters that are allowed to changed
223  * after the creation.
224  */
225 VLC_API int filter_ConfigureBlend( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src );
226
227 /**
228  * It blends a picture into another one.
229  *
230  * The input picture is not modified and not released.
231  */
232 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 );
233
234 /**
235  * It destroys a blend filter created by filter_NewBlend.
236  */
237 VLC_API void filter_DeleteBlend( filter_t * );
238
239 /**
240  * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
241  * using a void (*)( filter_t *, picture_t *, picture_t * ) function
242  *
243  * Currently used by the chroma video filters
244  */
245 #define VIDEO_FILTER_WRAPPER( name )                                    \
246     static picture_t *name ## _Filter ( filter_t *p_filter,             \
247                                         picture_t *p_pic )              \
248     {                                                                   \
249         picture_t *p_outpic = filter_NewPicture( p_filter );            \
250         if( p_outpic )                                                  \
251         {                                                               \
252             name( p_filter, p_pic, p_outpic );                          \
253             picture_CopyProperties( p_outpic, p_pic );                  \
254         }                                                               \
255         picture_Release( p_pic );                                       \
256         return p_outpic;                                                \
257     }
258
259 /**
260  * Filter chain management API
261  * The filter chain management API is used to dynamically construct filters
262  * and add them in a chain.
263  */
264
265 typedef struct filter_chain_t filter_chain_t;
266
267 /**
268  * Create new filter chain
269  *
270  * \param p_object pointer to a vlc object
271  * \param psz_capability vlc capability of filters in filter chain
272  * \param b_allow_format_fmt_change allow changing of fmt
273  * \return pointer to a filter chain
274  */
275 VLC_API filter_chain_t * filter_chain_New( vlc_object_t *, const char *, bool )
276 VLC_USED;
277 #define filter_chain_New( a, b, c ) filter_chain_New( VLC_OBJECT( a ), b, c )
278
279 /**
280  * Creates a new video filter chain.
281  *
282  * \param obj pointer to parent VLC object
283  * \param change whether to allow changing the output format
284  * \param owner owner video buffer callbacks
285  * \return new filter chain, or NULL on error
286  */
287 VLC_API filter_chain_t * filter_chain_NewVideo( vlc_object_t *obj, bool change,
288                                                 const filter_owner_t *owner )
289 VLC_USED;
290 #define filter_chain_NewVideo( a, b, c ) \
291         filter_chain_NewVideo( VLC_OBJECT( a ), b, c )
292
293 /**
294  * Delete filter chain will delete all filters in the chain and free all
295  * allocated data. The pointer to the filter chain is then no longer valid.
296  *
297  * \param p_chain pointer to filter chain
298  */
299 VLC_API void filter_chain_Delete( filter_chain_t * );
300
301 /**
302  * Reset filter chain will delete all filters in the chain and
303  * reset p_fmt_in and p_fmt_out to the new values.
304  *
305  * \param p_chain pointer to filter chain
306  * \param p_fmt_in new fmt_in params
307  * \param p_fmt_out new fmt_out params
308  */
309 VLC_API void filter_chain_Reset( filter_chain_t *, const es_format_t *, const es_format_t * );
310
311 /**
312  * Append filter to the end of the chain.
313  *
314  * \param p_chain pointer to filter chain
315  * \param psz_name name of filter
316  * \param p_cfg
317  * \param p_fmt_in input es_format_t
318  * \param p_fmt_out output es_format_t
319  * \return pointer to filter chain
320  */
321 VLC_API filter_t * filter_chain_AppendFilter( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * );
322
323 /**
324  * Append new filter to filter chain from string.
325  *
326  * \param p_chain pointer to filter chain
327  * \param psz_string string of filters
328  * \return 0 for success
329  */
330 VLC_API int filter_chain_AppendFromString( filter_chain_t *, const char * );
331
332 /**
333  * Delete filter from filter chain. This function also releases the filter
334  * object and unloads the filter modules. The pointer to p_filter is no
335  * longer valid after this function successfully returns.
336  *
337  * \param p_chain pointer to filter chain
338  * \param p_filter pointer to filter object
339  */
340 VLC_API void filter_chain_DeleteFilter( filter_chain_t *, filter_t * );
341
342 /**
343  * Get the number of filters in the filter chain.
344  *
345  * \param p_chain pointer to filter chain
346  * \return number of filters in this filter chain
347  */
348 VLC_API int filter_chain_GetLength( filter_chain_t * );
349
350 /**
351  * Get last p_fmt_out in the chain.
352  *
353  * \param p_chain pointer to filter chain
354  * \return last p_fmt (es_format_t) of this filter chain
355  */
356 VLC_API const es_format_t * filter_chain_GetFmtOut( filter_chain_t * );
357
358 /**
359  * Apply the filter chain to a video picture.
360  *
361  * \param p_chain pointer to filter chain
362  * \param p_picture picture to apply filters on
363  * \return modified picture after applying all video filters
364  */
365 VLC_API picture_t * filter_chain_VideoFilter( filter_chain_t *, picture_t * );
366
367 /**
368  * Flush a video filter chain.
369  */
370 VLC_API void filter_chain_VideoFlush( filter_chain_t * );
371
372 /**
373  * Apply the filter chain to a audio block.
374  *
375  * \param p_chain pointer to filter chain
376  * \param p_block audio frame to apply filters on
377  * \return modified audio frame after applying all audio filters
378  */
379 VLC_API block_t * filter_chain_AudioFilter( filter_chain_t *, block_t * );
380
381 /**
382  * Apply filter chain to subpictures.
383  *
384  * \param p_chain pointer to filter chain
385  * \param display_date of subpictures
386  */
387 void filter_chain_SubSource( filter_chain_t *, spu_t *, mtime_t );
388
389 /**
390  * Apply filter chain to subpictures.
391  *
392  * \param p_chain pointer to filter chain
393  * \param p_subpicture subpicture to apply filters on
394  * \return modified subpicture after applying all subpicture filters
395  */
396 VLC_API subpicture_t * filter_chain_SubFilter( filter_chain_t *, subpicture_t * );
397
398 /**
399  * Apply the filter chain to a mouse state.
400  *
401  * It will be applied from the output to the input. It makes sense only
402  * for a video filter chain.
403  *
404  * The vlc_mouse_t* pointers may be the same.
405  */
406 VLC_API int filter_chain_MouseFilter( filter_chain_t *, vlc_mouse_t *, const vlc_mouse_t * );
407
408 /**
409  * Inform the filter chain of mouse state.
410  *
411  * It makes sense only for a sub source chain.
412  */
413 VLC_API int filter_chain_MouseEvent( filter_chain_t *, const vlc_mouse_t *, const video_format_t * );
414
415 int filter_chain_ForEach( filter_chain_t *chain,
416                           int (*cb)( filter_t *, void * ), void *opaque );
417
418 #endif /* _VLC_FILTER_H */
419