]> git.sesse.net Git - vlc/blob - include/vlc_filter.h
Fix potential segfault.
[vlc] / include / vlc_filter.h
1 /*****************************************************************************
2  * vlc_filter.h: filter related structures and functions
3  *****************************************************************************
4  * Copyright (C) 1999-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *          Antoine Cellerier <dionoea at videolan dot org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 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 General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, 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  * \file
32  * This file defines the structure and types used by video and audio filters
33  */
34
35 typedef struct filter_owner_sys_t filter_owner_sys_t;
36
37 /** Structure describing a filter
38  * @warning BIG FAT WARNING : the code relies in the first 4 members of
39  * filter_t and decoder_t to be the same, so if you have anything to add,
40  * do it at the end of the structure.
41  */
42 struct filter_t
43 {
44     VLC_COMMON_MEMBERS
45
46     /* Module properties */
47     module_t *          p_module;
48     filter_sys_t *      p_sys;
49
50     /* Input format */
51     es_format_t         fmt_in;
52
53     /* Output format of filter */
54     es_format_t         fmt_out;
55     bool                b_allow_fmt_out_change;
56
57     /* Filter configuration */
58     config_chain_t *    p_cfg;
59
60     picture_t *         ( * pf_video_filter ) ( filter_t *, picture_t * );
61     block_t *           ( * pf_audio_filter ) ( filter_t *, block_t * );
62     void                ( * pf_video_blend )  ( filter_t *, picture_t *,
63                                                 picture_t *, picture_t *,
64                                                 int, int, int );
65
66     subpicture_t *      ( *pf_sub_filter ) ( filter_t *, mtime_t );
67     int                 ( *pf_render_text ) ( filter_t *, subpicture_region_t *,
68                                               subpicture_region_t * );
69     int                 ( *pf_render_html ) ( filter_t *, subpicture_region_t *,
70                                               subpicture_region_t * );
71
72     /*
73      * Buffers allocation
74      */
75
76     /* Audio output callbacks */
77     block_t *       ( * pf_audio_buffer_new) ( filter_t *, int );
78
79     /* Video output callbacks */
80     picture_t     * ( * pf_vout_buffer_new) ( filter_t * );
81     void            ( * pf_vout_buffer_del) ( filter_t *, picture_t * );
82     /* void            ( * pf_picture_link)    ( picture_t * );
83     void            ( * pf_picture_unlink)  ( picture_t * ); */
84
85     /* SPU output callbacks */
86     subpicture_t *  ( * pf_sub_buffer_new) ( filter_t * );
87     void            ( * pf_sub_buffer_del) ( filter_t *, subpicture_t * );
88
89     /* Private structure for the owner of the decoder */
90     filter_owner_sys_t *p_owner;
91 };
92
93 /**
94  * This function will return a new picture usable by p_filter as an output
95  * buffer. You have to release it using filter_DeletePicture or by returning
96  * it to the caller as a pf_video_filter return value.
97  * Provided for convenience.
98  */
99 static inline picture_t *filter_NewPicture( filter_t *p_filter )
100 {
101     picture_t *p_picture = p_filter->pf_vout_buffer_new( p_filter );
102     if( !p_picture )
103         msg_Warn( p_filter, "can't get output picture" );
104     return p_picture;
105 }
106
107 /**
108  * This function will release a picture create by filter_NewPicture.
109  * Provided for convenience.
110  */
111 static inline void filter_DeletePicture( filter_t *p_filter, picture_t *p_picture )
112 {
113     p_filter->pf_vout_buffer_del( p_filter, p_picture );
114 }
115
116 /**
117  * This function will return a new subpicture usable by p_filter as an output
118  * buffer. You have to release it using filter_DeleteSubpicture or by returning
119  * it to the caller as a pf_sub_filter return value.
120  * Provided for convenience.
121  */
122 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
123 {
124     subpicture_t *p_subpicture = p_filter->pf_sub_buffer_new( p_filter );
125     if( !p_subpicture )
126         msg_Warn( p_filter, "can't get output subpicture" );
127     return p_subpicture;
128 }
129
130 /**
131  * This function will release a subpicture create by filter_NewSubicture.
132  * Provided for convenience.
133  */
134 static inline void filter_DeleteSubpicture( filter_t *p_filter, subpicture_t *p_subpicture )
135 {
136     p_filter->pf_sub_buffer_del( p_filter, p_subpicture );
137 }
138
139 /**
140  * This function will return a new audio buffer usable by p_filter as an
141  * output buffer. You have to release it using block_Release or by returning
142  * it to the caller as a pf_audio_filter return value.
143  * Provided for convenience.
144  */
145 static inline block_t *filter_NewAudioBuffer( filter_t *p_filter, int i_size )
146 {
147     block_t *p_block = p_filter->pf_audio_buffer_new( p_filter, i_size );
148     if( !p_block )
149         msg_Warn( p_filter, "can't get output block" );
150     return p_block;
151 }
152
153
154 /**
155  * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
156  * using a void (*)( filter_t *, picture_t *, picture_t * ) function
157  *
158  * Currently used by the chroma video filters
159  */
160 #define VIDEO_FILTER_WRAPPER( name )                                    \
161     static picture_t *name ## _Filter ( filter_t *p_filter,             \
162                                         picture_t *p_pic )              \
163     {                                                                   \
164         picture_t *p_outpic = filter_NewPicture( p_filter );            \
165         if( !p_outpic )                                                 \
166         {                                                               \
167             picture_Release( p_pic );                                   \
168             return NULL;                                                \
169         }                                                               \
170                                                                         \
171         name( p_filter, p_pic, p_outpic );                              \
172                                                                         \
173         picture_CopyProperties( p_outpic, p_pic );                      \
174         picture_Release( p_pic );                                       \
175                                                                         \
176         return p_outpic;                                                \
177     }
178
179 /**
180  * Filter chain management API
181  */
182
183 typedef struct filter_chain_t filter_chain_t;
184
185 VLC_EXPORT( filter_chain_t *, __filter_chain_New, ( vlc_object_t *, const char *, bool, int (*)( filter_t *, void * ), void (*)( filter_t * ), void *  ) );
186 #define filter_chain_New( a, b, c, d, e, f ) __filter_chain_New( VLC_OBJECT( a ), b, c, d, e, f )
187 VLC_EXPORT( void, filter_chain_Delete, ( filter_chain_t * ) );
188 VLC_EXPORT( void, filter_chain_Reset, ( filter_chain_t *, const es_format_t *, const es_format_t * ) );
189
190 VLC_EXPORT( filter_t *, filter_chain_AppendFilter, ( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * ) );
191 VLC_EXPORT( int, filter_chain_AppendFromString, ( filter_chain_t *, const char * ) );
192 VLC_EXPORT( int, filter_chain_DeleteFilter, ( filter_chain_t *, filter_t * ) );
193
194 VLC_EXPORT( filter_t *, filter_chain_GetFilter, ( filter_chain_t *, int, const char * ) );
195 VLC_EXPORT( int, filter_chain_GetLength, ( filter_chain_t * ) );
196 VLC_EXPORT( const es_format_t *, filter_chain_GetFmtOut, ( filter_chain_t * ) );
197
198 /**
199  * Apply the filter chain
200  */
201 VLC_EXPORT( picture_t *, filter_chain_VideoFilter, ( filter_chain_t *, picture_t * ) );
202 VLC_EXPORT( block_t *, filter_chain_AudioFilter, ( filter_chain_t *, block_t * ) );
203 VLC_EXPORT( void, filter_chain_SubFilter, ( filter_chain_t *, mtime_t ) );
204
205 #endif /* _VLC_FILTER_H */