packetizer: h264: use poc to compute missing pic_struct
[vlc.git] / include / vlc_filter.h
blob5743cac21e4b99f1be4e36c9ab94f1b479d5f148
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 /* Filter configuration */
81 config_chain_t * p_cfg;
83 union
85 /** Filter a picture (video filter) */
86 picture_t * (*pf_video_filter)( filter_t *, picture_t * );
88 /** Filter an audio block (audio filter) */
89 block_t * (*pf_audio_filter)( filter_t *, block_t * );
91 /** Blend a subpicture onto a picture (blend) */
92 void (*pf_video_blend)( filter_t *, picture_t *, const picture_t *,
93 int, int, int );
95 /** Generate a subpicture (sub source) */
96 subpicture_t *(*pf_sub_source)( filter_t *, mtime_t );
98 /** Filter a subpicture (sub filter) */
99 subpicture_t *(*pf_sub_filter)( filter_t *, subpicture_t * );
101 /** Render text (text render) */
102 int (*pf_render)( filter_t *, subpicture_region_t *,
103 subpicture_region_t *, const vlc_fourcc_t * );
106 union
108 /* TODO: video filter drain */
109 /** Drain (audio filter) */
110 block_t *(*pf_audio_drain) ( filter_t * );
113 /** Flush
115 * Flush (i.e. discard) any internal buffer in a video or audio filter.
117 void (*pf_flush)( filter_t * );
119 union
121 /** Filter mouse state (video filter).
123 * If non-NULL, you must convert from output to input formats:
124 * - If VLC_SUCCESS is returned, the mouse state is propagated.
125 * - Otherwise, the mouse change is not propagated.
126 * If NULL, the mouse state is considered unchanged and will be
127 * propagated. */
128 int (*pf_video_mouse)( filter_t *, struct vlc_mouse_t *,
129 const struct vlc_mouse_t *p_old,
130 const struct vlc_mouse_t *p_new );
131 int (*pf_sub_mouse)( filter_t *, const struct vlc_mouse_t *p_old,
132 const struct vlc_mouse_t *p_new,
133 const video_format_t * );
136 /* Input attachments
137 * XXX use filter_GetInputAttachments */
138 int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
140 /* Private structure for the owner of the decoder */
141 filter_owner_t owner;
145 * This function will return a new picture usable by p_filter as an output
146 * buffer. You have to release it using picture_Release or by returning
147 * it to the caller as a pf_video_filter return value.
148 * Provided for convenience.
150 * \param p_filter filter_t object
151 * \return new picture on success or NULL on failure
153 static inline picture_t *filter_NewPicture( filter_t *p_filter )
155 picture_t *pic = p_filter->owner.video.buffer_new( p_filter );
156 if( pic == NULL )
157 msg_Warn( p_filter, "can't get output picture" );
158 return pic;
162 * Flush a filter
164 * This function will flush the state of a filter (audio or video).
166 static inline void filter_Flush( filter_t *p_filter )
168 if( p_filter->pf_flush != NULL )
169 p_filter->pf_flush( p_filter );
173 * This function will drain, then flush an audio filter.
175 static inline block_t *filter_DrainAudio( filter_t *p_filter )
177 if( p_filter->pf_audio_drain )
178 return p_filter->pf_audio_drain( p_filter );
179 else
180 return NULL;
184 * This function will return a new subpicture usable by p_filter as an output
185 * buffer. You have to release it using subpicture_Delete or by returning it to
186 * the caller as a pf_sub_source return value.
187 * Provided for convenience.
189 * \param p_filter filter_t object
190 * \return new subpicture
192 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
194 subpicture_t *subpic = p_filter->owner.sub.buffer_new( p_filter );
195 if( subpic == NULL )
196 msg_Warn( p_filter, "can't get output subpicture" );
197 return subpic;
201 * This function gives all input attachments at once.
203 * You MUST release the returned values
205 static inline int filter_GetInputAttachments( filter_t *p_filter,
206 input_attachment_t ***ppp_attachment,
207 int *pi_attachment )
209 if( !p_filter->pf_get_attachments )
210 return VLC_EGENERIC;
211 return p_filter->pf_get_attachments( p_filter,
212 ppp_attachment, pi_attachment );
216 * It creates a blend filter.
218 * Only the chroma properties of the dest format is used (chroma
219 * type, rgb masks and shifts)
221 VLC_API filter_t * filter_NewBlend( vlc_object_t *, const video_format_t *p_dst_chroma ) VLC_USED;
224 * It configures blend filter parameters that are allowed to changed
225 * after the creation.
227 VLC_API int filter_ConfigureBlend( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src );
230 * It blends a picture into another one.
232 * The input picture is not modified and not released.
234 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 );
237 * It destroys a blend filter created by filter_NewBlend.
239 VLC_API void filter_DeleteBlend( filter_t * );
242 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
243 * using a void (*)( filter_t *, picture_t *, picture_t * ) function
245 * Currently used by the chroma video filters
247 #define VIDEO_FILTER_WRAPPER( name ) \
248 static picture_t *name ## _Filter ( filter_t *p_filter, \
249 picture_t *p_pic ) \
251 picture_t *p_outpic = filter_NewPicture( p_filter ); \
252 if( p_outpic ) \
254 name( p_filter, p_pic, p_outpic ); \
255 picture_CopyProperties( p_outpic, p_pic ); \
257 picture_Release( p_pic ); \
258 return p_outpic; \
262 * Filter chain management API
263 * The filter chain management API is used to dynamically construct filters
264 * and add them in a chain.
267 typedef struct filter_chain_t filter_chain_t;
270 * Create new filter chain
272 * \param p_object pointer to a vlc object
273 * \param psz_capability vlc capability of filters in filter chain
274 * \return pointer to a filter chain
276 filter_chain_t * filter_chain_New( vlc_object_t *, const char * )
277 VLC_USED;
278 #define filter_chain_New( a, b ) filter_chain_New( VLC_OBJECT( a ), b )
281 * Creates a new video filter chain.
283 * \param obj pointer to parent VLC object
284 * \param change whether to allow changing the output format
285 * \param owner owner video buffer callbacks
286 * \return new filter chain, or NULL on error
288 VLC_API filter_chain_t * filter_chain_NewVideo( vlc_object_t *obj, bool change,
289 const filter_owner_t *owner )
290 VLC_USED;
291 #define filter_chain_NewVideo( a, b, c ) \
292 filter_chain_NewVideo( VLC_OBJECT( a ), b, c )
295 * Delete filter chain will delete all filters in the chain and free all
296 * allocated data. The pointer to the filter chain is then no longer valid.
298 * \param p_chain pointer to filter chain
300 VLC_API void filter_chain_Delete( filter_chain_t * );
303 * Reset filter chain will delete all filters in the chain and
304 * reset p_fmt_in and p_fmt_out to the new values.
306 * \param p_chain pointer to filter chain
307 * \param p_fmt_in new fmt_in params
308 * \param p_fmt_out new fmt_out params
310 VLC_API void filter_chain_Reset( filter_chain_t *, const es_format_t *, const es_format_t * );
313 * Append a filter to the chain.
315 * \param chain filter chain to append a filter to
316 * \param name filter name
317 * \param fmt_in filter input format
318 * \param fmt_out filter output format
319 * \return a pointer to the filter or NULL on error
321 VLC_API filter_t *filter_chain_AppendFilter(filter_chain_t *chain,
322 const char *name, config_chain_t *cfg, const es_format_t *fmt_in,
323 const es_format_t *fmt_out);
326 * Append a conversion to the chain.
328 * \param chain filter chain to append a filter to
329 * \param fmt_in filter input format
330 * \param fmt_out filter output format
331 * \retval 0 on success
332 * \retval -1 on failure
334 VLC_API int filter_chain_AppendConverter(filter_chain_t *chain,
335 const es_format_t *fmt_in, const es_format_t *fmt_out);
338 * Append new filter to filter chain from string.
340 * \param chain filter chain to append a filter to
341 * \param str filters chain nul-terminated string
343 VLC_API int filter_chain_AppendFromString(filter_chain_t *chain,
344 const char *str);
347 * Delete filter from filter chain. This function also releases the filter
348 * object and unloads the filter modules. The pointer to p_filter is no
349 * longer valid after this function successfully returns.
351 * \param chain filter chain to remove the filter from
352 * \param filter filter to remove from the chain and delete
354 VLC_API void filter_chain_DeleteFilter(filter_chain_t *chain,
355 filter_t *filter);
358 * Get the number of filters in the filter chain.
360 * \param chain pointer to filter chain
361 * \return number of filters in this filter chain
363 VLC_API int filter_chain_GetLength(filter_chain_t *chain);
366 * Get last output format of the last element in the filter chain.
368 * \param chain filter chain
370 VLC_API const es_format_t *filter_chain_GetFmtOut(filter_chain_t *chain);
373 * Apply the filter chain to a video picture.
375 * \param chain pointer to filter chain
376 * \param pic picture to apply filters to
377 * \return modified picture after applying all video filters
379 VLC_API picture_t *filter_chain_VideoFilter(filter_chain_t *chain,
380 picture_t *pic);
383 * Flush a video filter chain.
385 VLC_API void filter_chain_VideoFlush( filter_chain_t * );
388 * Generate subpictures from a chain of subpicture source "filters".
390 * \param chain filter chain
391 * \param display_date of subpictures
393 void filter_chain_SubSource(filter_chain_t *chain, spu_t *,
394 mtime_t display_date);
397 * Apply filter chain to subpictures.
399 * \param chain filter chain
400 * \param subpic subpicture to apply filters on
401 * \return modified subpicture after applying all subpicture filters
403 VLC_API subpicture_t *filter_chain_SubFilter(filter_chain_t *chain,
404 subpicture_t *subpic);
407 * Apply the filter chain to a mouse state.
409 * It will be applied from the output to the input. It makes sense only
410 * for a video filter chain.
412 * The vlc_mouse_t* pointers may be the same.
414 VLC_API int filter_chain_MouseFilter( filter_chain_t *, struct vlc_mouse_t *,
415 const struct vlc_mouse_t * );
418 * Inform the filter chain of mouse state.
420 * It makes sense only for a sub source chain.
422 VLC_API int filter_chain_MouseEvent( filter_chain_t *,
423 const struct vlc_mouse_t *,
424 const video_format_t * );
426 int filter_chain_ForEach( filter_chain_t *chain,
427 int (*cb)( filter_t *, void * ), void *opaque );
429 /** @} */
430 #endif /* _VLC_FILTER_H */