00001 /***************************************************************************** 00002 * vlc_filter.h: filter related structures and functions 00003 ***************************************************************************** 00004 * Copyright (C) 1999-2008 the VideoLAN team 00005 * $Id$ 00006 * 00007 * Authors: Gildas Bazin <gbazin@videolan.org> 00008 * Antoine Cellerier <dionoea at videolan dot org> 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. 00023 *****************************************************************************/ 00024 00025 #ifndef VLC_FILTER_H 00026 #define VLC_FILTER_H 1 00027 00028 #include <vlc_es.h> 00029 00030 /** 00031 * \file 00032 * This file defines the structure and types used by video and audio filters 00033 */ 00034 00035 typedef struct filter_owner_sys_t filter_owner_sys_t; 00036 00037 /** Structure describing a filter 00038 * @warning BIG FAT WARNING : the code relies on the first 4 members of 00039 * filter_t and decoder_t to be the same, so if you have anything to add, 00040 * do it at the end of the structure. 00041 */ 00042 struct filter_t 00043 { 00044 VLC_COMMON_MEMBERS 00045 00046 /* Module properties */ 00047 module_t * p_module; 00048 filter_sys_t * p_sys; 00049 00050 /* Input format */ 00051 es_format_t fmt_in; 00052 00053 /* Output format of filter */ 00054 es_format_t fmt_out; 00055 bool b_allow_fmt_out_change; 00056 00057 /* Filter configuration */ 00058 config_chain_t * p_cfg; 00059 00060 picture_t * ( * pf_video_filter ) ( filter_t *, picture_t * ); 00061 block_t * ( * pf_audio_filter ) ( filter_t *, block_t * ); 00062 void ( * pf_video_blend ) ( filter_t *, picture_t *, 00063 picture_t *, picture_t *, 00064 int, int, int ); 00065 00066 subpicture_t * ( *pf_sub_filter ) ( filter_t *, mtime_t ); 00067 int ( *pf_render_text ) ( filter_t *, subpicture_region_t *, 00068 subpicture_region_t * ); 00069 int ( *pf_render_html ) ( filter_t *, subpicture_region_t *, 00070 subpicture_region_t * ); 00071 00072 /* 00073 * Buffers allocation 00074 */ 00075 00076 /* Audio output callbacks */ 00077 block_t * ( * pf_audio_buffer_new) ( filter_t *, int ); 00078 00079 /* Video output callbacks */ 00080 picture_t * ( * pf_vout_buffer_new) ( filter_t * ); 00081 void ( * pf_vout_buffer_del) ( filter_t *, picture_t * ); 00082 /* void ( * pf_picture_link) ( picture_t * ); 00083 void ( * pf_picture_unlink) ( picture_t * ); */ 00084 00085 /* SPU output callbacks */ 00086 subpicture_t * ( * pf_sub_buffer_new) ( filter_t * ); 00087 void ( * pf_sub_buffer_del) ( filter_t *, subpicture_t * ); 00088 00089 /* Private structure for the owner of the decoder */ 00090 filter_owner_sys_t *p_owner; 00091 }; 00092 00093 /** 00094 * This function will return a new picture usable by p_filter as an output 00095 * buffer. You have to release it using filter_DeletePicture or by returning 00096 * it to the caller as a pf_video_filter return value. 00097 * Provided for convenience. 00098 * 00099 * \param p_filter filter_t object 00100 * \return new picture on success or NULL on failure 00101 */ 00102 static inline picture_t *filter_NewPicture( filter_t *p_filter ) 00103 { 00104 picture_t *p_picture = p_filter->pf_vout_buffer_new( p_filter ); 00105 if( !p_picture ) 00106 msg_Warn( p_filter, "can't get output picture" ); 00107 return p_picture; 00108 } 00109 00110 /** 00111 * This function will release a picture create by filter_NewPicture. 00112 * Provided for convenience. 00113 * 00114 * \param p_filter filter_t object 00115 * \param p_picture picture to be deleted 00116 */ 00117 static inline void filter_DeletePicture( filter_t *p_filter, picture_t *p_picture ) 00118 { 00119 p_filter->pf_vout_buffer_del( p_filter, p_picture ); 00120 } 00121 00122 /** 00123 * This function will return a new subpicture usable by p_filter as an output 00124 * buffer. You have to release it using filter_DeleteSubpicture or by returning 00125 * it to the caller as a pf_sub_filter return value. 00126 * Provided for convenience. 00127 * 00128 * \param p_filter filter_t object 00129 * \return new subpicture 00130 */ 00131 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter ) 00132 { 00133 subpicture_t *p_subpicture = p_filter->pf_sub_buffer_new( p_filter ); 00134 if( !p_subpicture ) 00135 msg_Warn( p_filter, "can't get output subpicture" ); 00136 return p_subpicture; 00137 } 00138 00139 /** 00140 * This function will release a subpicture create by filter_NewSubicture. 00141 * Provided for convenience. 00142 * 00143 * \param p_filter filter_t object 00144 * \param p_subpicture to be released 00145 */ 00146 static inline void filter_DeleteSubpicture( filter_t *p_filter, subpicture_t *p_subpicture ) 00147 { 00148 p_filter->pf_sub_buffer_del( p_filter, p_subpicture ); 00149 } 00150 00151 /** 00152 * This function will return a new audio buffer usable by p_filter as an 00153 * output buffer. You have to release it using block_Release or by returning 00154 * it to the caller as a pf_audio_filter return value. 00155 * Provided for convenience. 00156 * 00157 * \param p_filter filter_t object 00158 * \param i_size size of audio buffer requested 00159 * \return block to be used as audio output buffer 00160 */ 00161 static inline block_t *filter_NewAudioBuffer( filter_t *p_filter, int i_size ) 00162 { 00163 block_t *p_block = p_filter->pf_audio_buffer_new( p_filter, i_size ); 00164 if( !p_block ) 00165 msg_Warn( p_filter, "can't get output block" ); 00166 return p_block; 00167 } 00168 00169 /** 00170 * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper 00171 * using a void (*)( filter_t *, picture_t *, picture_t * ) function 00172 * 00173 * Currently used by the chroma video filters 00174 */ 00175 #define VIDEO_FILTER_WRAPPER( name ) \ 00176 static picture_t *name ## _Filter ( filter_t *p_filter, \ 00177 picture_t *p_pic ) \ 00178 { \ 00179 picture_t *p_outpic = filter_NewPicture( p_filter ); \ 00180 if( !p_outpic ) \ 00181 { \ 00182 picture_Release( p_pic ); \ 00183 return NULL; \ 00184 } \ 00185 \ 00186 name( p_filter, p_pic, p_outpic ); \ 00187 \ 00188 picture_CopyProperties( p_outpic, p_pic ); \ 00189 picture_Release( p_pic ); \ 00190 \ 00191 return p_outpic; \ 00192 } 00193 00194 /** 00195 * Filter chain management API 00196 * The filter chain management API is used to dynamically construct filters 00197 * and add them in a chain. 00198 */ 00199 00200 typedef struct filter_chain_t filter_chain_t; 00201 00202 /** 00203 * Create new filter chain 00204 * 00205 * \param p_object pointer to a vlc object 00206 * \param psz_capability vlc capability of filters in filter chain 00207 * \param b_allow_format_fmt_change allow changing of fmt 00208 * \param pf_buffer_allocation_init callback function to initialize buffer allocations 00209 * \param pf_buffer_allocation_clear callback function to clear buffer allocation initialization 00210 * \param p_buffer_allocation_data pointer to private allocation data 00211 * \return pointer to a filter chain 00212 */ 00213 VLC_EXPORT( filter_chain_t *, __filter_chain_New, ( vlc_object_t *, const char *, bool, int (*)( filter_t *, void * ), void (*)( filter_t * ), void * ) ); 00214 #define filter_chain_New( a, b, c, d, e, f ) __filter_chain_New( VLC_OBJECT( a ), b, c, d, e, f ) 00215 00216 /** 00217 * Delete filter chain will delete all filters in the chain and free all 00218 * allocated data. The pointer to the filter chain is then no longer valid. 00219 * 00220 * \param p_chain pointer to filter chain 00221 */ 00222 VLC_EXPORT( void, filter_chain_Delete, ( filter_chain_t * ) ); 00223 00224 /** 00225 * Reset filter chain will delete all filters in the chain and 00226 * reset p_fmt_in and p_fmt_out to the new values. 00227 * 00228 * \param p_chain pointer to filter chain 00229 * \param p_fmt_in new fmt_in params 00230 * \param p_fmt_out new fmt_out params 00231 */ 00232 VLC_EXPORT( void, filter_chain_Reset, ( filter_chain_t *, const es_format_t *, const es_format_t * ) ); 00233 00234 /** 00235 * Append filter to the end of the chain. 00236 * 00237 * \param p_chain pointer to filter chain 00238 * \param psz_name name of filter 00239 * \param p_cfg 00240 * \param p_fmt_in input es_format_t 00241 * \param p_fmt_out output es_format_t 00242 * \return pointer to filter chain 00243 */ 00244 VLC_EXPORT( filter_t *, filter_chain_AppendFilter, ( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * ) ); 00245 00246 /** 00247 * Append new filter to filter chain from string. 00248 * 00249 * \param p_chain pointer to filter chain 00250 * \param psz_string string of filters 00251 * \return 0 for success 00252 */ 00253 VLC_EXPORT( int, filter_chain_AppendFromString, ( filter_chain_t *, const char * ) ); 00254 00255 /** 00256 * Delete filter from filter chain. This function also releases the filter 00257 * object and unloads the filter modules. The pointer to p_filter is no 00258 * longer valid after this function successfully returns. 00259 * 00260 * \param p_chain pointer to filter chain 00261 * \param p_filter pointer to filter object 00262 * \return VLC_SUCCESS on succes, else VLC_EGENERIC 00263 */ 00264 VLC_EXPORT( int, filter_chain_DeleteFilter, ( filter_chain_t *, filter_t * ) ); 00265 00266 /** 00267 * Get filter by name of position in the filter chain. 00268 * 00269 * \param p_chain pointer to filter chain 00270 * \param i_position position of filter in filter chain 00271 * \param psz_name name of filter to get 00272 * \return filter object based on position or name provided 00273 */ 00274 VLC_EXPORT( filter_t *, filter_chain_GetFilter, ( filter_chain_t *, int, const char * ) ); 00275 00276 /** 00277 * Get the number of filters in the filter chain. 00278 * 00279 * \param p_chain pointer to filter chain 00280 * \return number of filters in this filter chain 00281 */ 00282 VLC_EXPORT( int, filter_chain_GetLength, ( filter_chain_t * ) ); 00283 00284 /** 00285 * Get last p_fmt_out in the chain. 00286 * 00287 * \param p_chain pointer to filter chain 00288 * \return last p_fmt (es_format_t) of this filter chain 00289 */ 00290 VLC_EXPORT( const es_format_t *, filter_chain_GetFmtOut, ( filter_chain_t * ) ); 00291 00292 /** 00293 * Apply the filter chain to a video picture. 00294 * 00295 * \param p_chain pointer to filter chain 00296 * \param p_picture picture to apply filters on 00297 * \return modified picture after applying all video filters 00298 */ 00299 VLC_EXPORT( picture_t *, filter_chain_VideoFilter, ( filter_chain_t *, picture_t * ) ); 00300 00301 /** 00302 * Apply the filter chain to a audio block. 00303 * 00304 * \param p_chain pointer to filter chain 00305 * \param p_block audio frame to apply filters on 00306 * \return modified audio frame after applying all audio filters 00307 */ 00308 VLC_EXPORT( block_t *, filter_chain_AudioFilter, ( filter_chain_t *, block_t * ) ); 00309 00310 /** 00311 * Apply filter chain to subpictures. 00312 * 00313 * \param p_chain pointer to filter chain 00314 * \param display_date of subpictures 00315 */ 00316 VLC_EXPORT( void, filter_chain_SubFilter, ( filter_chain_t *, mtime_t ) ); 00317 00318 #endif /* _VLC_FILTER_H */ 00319
1.5.1