vlc_filter.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * vlc_filter.h: filter related structures and functions
00003  *****************************************************************************
00004  * Copyright (C) 1999-2008 the VideoLAN team
00005  * $Id: ea24344e707c5bfa8827d317294056ecd6d52eee $
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 #include <vlc_picture.h>
00030 #include <vlc_subpicture.h>
00031 #include <vlc_mouse.h>
00032 
00033 /**
00034  * \file
00035  * This file defines the structure and types used by video and audio filters
00036  */
00037 
00038 typedef struct filter_owner_sys_t filter_owner_sys_t;
00039 
00040 /** Structure describing a filter
00041  * @warning BIG FAT WARNING : the code relies on the first 4 members of
00042  * filter_t and decoder_t to be the same, so if you have anything to add,
00043  * do it at the end of the structure.
00044  */
00045 struct filter_t
00046 {
00047     VLC_COMMON_MEMBERS
00048 
00049     /* Module properties */
00050     module_t *          p_module;
00051     filter_sys_t *      p_sys;
00052 
00053     /* Input format */
00054     es_format_t         fmt_in;
00055 
00056     /* Output format of filter */
00057     es_format_t         fmt_out;
00058     bool                b_allow_fmt_out_change;
00059 
00060     /* Filter configuration */
00061     config_chain_t *    p_cfg;
00062 
00063     union
00064     {
00065         struct
00066         {
00067             picture_t * (*pf_filter) ( filter_t *, picture_t * );
00068             void        (*pf_flush)( filter_t * );
00069             picture_t * (*pf_buffer_new) ( filter_t * );
00070             void        (*pf_buffer_del) ( filter_t *, picture_t * );
00071             /* Filter mouse state.
00072              *
00073              * If non-NULL, you must convert from output to input formats:
00074              * - If VLC_SUCCESS is returned, the mouse state is propagated.
00075              * - Otherwise, the mouse change is not propagated.
00076              * If NULL, the mouse state is considered unchanged and will be
00077              * propagated.
00078              */
00079             int         (*pf_mouse)( filter_t *, vlc_mouse_t *,
00080                                      const vlc_mouse_t *p_old,
00081                                      const vlc_mouse_t *p_new );
00082         } video;
00083 #define pf_video_filter     u.video.pf_filter
00084 #define pf_video_flush      u.video.pf_flush
00085 #define pf_video_mouse      u.video.pf_mouse
00086 #define pf_video_buffer_new u.video.pf_buffer_new
00087 #define pf_video_buffer_del u.video.pf_buffer_del
00088 
00089         struct
00090         {
00091             block_t *   (*pf_filter) ( filter_t *, block_t * );
00092             block_t *   (*pf_buffer_new) ( filter_t *, int );
00093         } audio;
00094 #define pf_audio_filter     u.audio.pf_filter
00095 #define pf_audio_buffer_new u.audio.pf_buffer_new
00096 
00097         struct
00098         {
00099             void        (*pf_blend) ( filter_t *,  picture_t *,
00100                                       const picture_t *, int, int, int );
00101         } blend;
00102 #define pf_video_blend     u.blend.pf_blend
00103 
00104         struct
00105         {
00106             subpicture_t * (*pf_filter)    ( filter_t *, mtime_t );
00107             subpicture_t * (*pf_buffer_new)( filter_t * );
00108             void           (*pf_buffer_del)( filter_t *, subpicture_t * );
00109             int            (*pf_mouse)     ( filter_t *,
00110                                              const vlc_mouse_t *p_old,
00111                                              const vlc_mouse_t *p_new,
00112                                              const video_format_t * );
00113         } sub;
00114 #define pf_sub_filter      u.sub.pf_filter
00115 #define pf_sub_buffer_new  u.sub.pf_buffer_new
00116 #define pf_sub_buffer_del  u.sub.pf_buffer_del
00117 #define pf_sub_mouse       u.sub.pf_mouse
00118 
00119         struct
00120         {
00121             int         (*pf_text) ( filter_t *, subpicture_region_t *,
00122                                      subpicture_region_t * );
00123             int         (*pf_html) ( filter_t *, subpicture_region_t *,
00124                                      subpicture_region_t * );
00125         } render;
00126 #define pf_render_text     u.render.pf_text
00127 #define pf_render_html     u.render.pf_html
00128 
00129     } u;
00130 
00131     /* Input attachments
00132      * XXX use filter_GetInputAttachments */
00133     int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
00134 
00135     /* Private structure for the owner of the decoder */
00136     filter_owner_sys_t *p_owner;
00137 };
00138 
00139 /**
00140  * This function will return a new picture usable by p_filter as an output
00141  * buffer. You have to release it using filter_DeletePicture or by returning
00142  * it to the caller as a pf_video_filter return value.
00143  * Provided for convenience.
00144  *
00145  * \param p_filter filter_t object
00146  * \return new picture on success or NULL on failure
00147  */
00148 static inline picture_t *filter_NewPicture( filter_t *p_filter )
00149 {
00150     picture_t *p_picture = p_filter->pf_video_buffer_new( p_filter );
00151     if( !p_picture )
00152         msg_Warn( p_filter, "can't get output picture" );
00153     return p_picture;
00154 }
00155 
00156 /**
00157  * This function will release a picture create by filter_NewPicture.
00158  * Provided for convenience.
00159  *
00160  * \param p_filter filter_t object
00161  * \param p_picture picture to be deleted
00162  */
00163 static inline void filter_DeletePicture( filter_t *p_filter, picture_t *p_picture )
00164 {
00165     p_filter->pf_video_buffer_del( p_filter, p_picture );
00166 }
00167 
00168 /**
00169  * This function will flush the state of a video filter.
00170  */
00171 static inline void filter_FlushPictures( filter_t *p_filter )
00172 {
00173     if( p_filter->pf_video_flush )
00174         p_filter->pf_video_flush( p_filter );
00175 }
00176 
00177 /**
00178  * This function will return a new subpicture usable by p_filter as an output
00179  * buffer. You have to release it using filter_DeleteSubpicture or by returning
00180  * it to the caller as a pf_sub_filter return value.
00181  * Provided for convenience.
00182  *
00183  * \param p_filter filter_t object
00184  * \return new subpicture
00185  */
00186 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
00187 {
00188     subpicture_t *p_subpicture = p_filter->pf_sub_buffer_new( p_filter );
00189     if( !p_subpicture )
00190         msg_Warn( p_filter, "can't get output subpicture" );
00191     return p_subpicture;
00192 }
00193 
00194 /**
00195  * This function will release a subpicture create by filter_NewSubicture.
00196  * Provided for convenience.
00197  *
00198  * \param p_filter filter_t object
00199  * \param p_subpicture to be released
00200  */
00201 static inline void filter_DeleteSubpicture( filter_t *p_filter, subpicture_t *p_subpicture )
00202 {
00203     p_filter->pf_sub_buffer_del( p_filter, p_subpicture );
00204 }
00205 
00206 /**
00207  * This function will return a new audio buffer usable by p_filter as an
00208  * output buffer. You have to release it using block_Release or by returning
00209  * it to the caller as a pf_audio_filter return value.
00210  * Provided for convenience.
00211  *
00212  * \param p_filter filter_t object
00213  * \param i_size size of audio buffer requested
00214  * \return block to be used as audio output buffer
00215  */
00216 static inline block_t *filter_NewAudioBuffer( filter_t *p_filter, int i_size )
00217 {
00218     block_t *p_block = p_filter->pf_audio_buffer_new( p_filter, i_size );
00219     if( !p_block )
00220         msg_Warn( p_filter, "can't get output block" );
00221     return p_block;
00222 }
00223 
00224 /**
00225  * This function gives all input attachments at once.
00226  *
00227  * You MUST release the returned values
00228  */
00229 static inline int filter_GetInputAttachments( filter_t *p_filter,
00230                                               input_attachment_t ***ppp_attachment,
00231                                               int *pi_attachment )
00232 {
00233     if( !p_filter->pf_get_attachments )
00234         return VLC_EGENERIC;
00235     return p_filter->pf_get_attachments( p_filter,
00236                                          ppp_attachment, pi_attachment );
00237 }
00238 
00239 /**
00240  * It creates a blend filter.
00241  *
00242  * Only the chroma properties of the dest format is used (chroma
00243  * type, rgb masks and shifts)
00244  */
00245 VLC_EXPORT( filter_t *, filter_NewBlend, ( vlc_object_t *, const video_format_t *p_dst_chroma ) LIBVLC_USED );
00246 
00247 /**
00248  * It configures blend filter parameters that are allowed to changed
00249  * after the creation.
00250  */
00251 VLC_EXPORT( int, filter_ConfigureBlend, ( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src ) );
00252 
00253 /**
00254  * It blends a picture into another one.
00255  *
00256  * The input picture is not modified and not released.
00257  */
00258 VLC_EXPORT( 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 ) );
00259 
00260 /**
00261  * It destroys a blend filter created by filter_NewBlend.
00262  */
00263 VLC_EXPORT( void, filter_DeleteBlend, ( filter_t * ) );
00264 
00265 /**
00266  * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
00267  * using a void (*)( filter_t *, picture_t *, picture_t * ) function
00268  *
00269  * Currently used by the chroma video filters
00270  */
00271 #define VIDEO_FILTER_WRAPPER( name )                                    \
00272     static picture_t *name ## _Filter ( filter_t *p_filter,             \
00273                                         picture_t *p_pic )              \
00274     {                                                                   \
00275         picture_t *p_outpic = filter_NewPicture( p_filter );            \
00276         if( p_outpic )                                                  \
00277         {                                                               \
00278             name( p_filter, p_pic, p_outpic );                          \
00279             picture_CopyProperties( p_outpic, p_pic );                  \
00280         }                                                               \
00281         picture_Release( p_pic );                                       \
00282         return p_outpic;                                                \
00283     }
00284 
00285 /**
00286  * Filter chain management API
00287  * The filter chain management API is used to dynamically construct filters
00288  * and add them in a chain.
00289  */
00290 
00291 typedef struct filter_chain_t filter_chain_t;
00292 
00293 /**
00294  * Create new filter chain
00295  *
00296  * \param p_object pointer to a vlc object
00297  * \param psz_capability vlc capability of filters in filter chain
00298  * \param b_allow_format_fmt_change allow changing of fmt
00299  * \param pf_buffer_allocation_init callback function to initialize buffer allocations
00300  * \param pf_buffer_allocation_clear callback function to clear buffer allocation initialization
00301  * \param p_buffer_allocation_data pointer to private allocation data
00302  * \return pointer to a filter chain
00303  */
00304 VLC_EXPORT( filter_chain_t *, filter_chain_New, ( vlc_object_t *, const char *, bool, int (*)( filter_t *, void * ), void (*)( filter_t * ), void *  ) LIBVLC_USED );
00305 #define filter_chain_New( a, b, c, d, e, f ) filter_chain_New( VLC_OBJECT( a ), b, c, d, e, f )
00306 
00307 /**
00308  * Delete filter chain will delete all filters in the chain and free all
00309  * allocated data. The pointer to the filter chain is then no longer valid.
00310  *
00311  * \param p_chain pointer to filter chain
00312  */
00313 VLC_EXPORT( void, filter_chain_Delete, ( filter_chain_t * ) );
00314 
00315 /**
00316  * Reset filter chain will delete all filters in the chain and
00317  * reset p_fmt_in and p_fmt_out to the new values.
00318  *
00319  * \param p_chain pointer to filter chain
00320  * \param p_fmt_in new fmt_in params
00321  * \param p_fmt_out new fmt_out params
00322  */
00323 VLC_EXPORT( void, filter_chain_Reset, ( filter_chain_t *, const es_format_t *, const es_format_t * ) );
00324 
00325 /**
00326  * Append filter to the end of the chain.
00327  *
00328  * \param p_chain pointer to filter chain
00329  * \param psz_name name of filter
00330  * \param p_cfg
00331  * \param p_fmt_in input es_format_t
00332  * \param p_fmt_out output es_format_t
00333  * \return pointer to filter chain
00334  */
00335 VLC_EXPORT( filter_t *, filter_chain_AppendFilter, ( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * ) );
00336 
00337 /**
00338  * Append new filter to filter chain from string.
00339  *
00340  * \param p_chain pointer to filter chain
00341  * \param psz_string string of filters
00342  * \return 0 for success
00343  */
00344 VLC_EXPORT( int, filter_chain_AppendFromString, ( filter_chain_t *, const char * ) );
00345 
00346 /**
00347  * Delete filter from filter chain. This function also releases the filter
00348  * object and unloads the filter modules. The pointer to p_filter is no
00349  * longer valid after this function successfully returns.
00350  *
00351  * \param p_chain pointer to filter chain
00352  * \param p_filter pointer to filter object
00353  * \return VLC_SUCCESS on succes, else VLC_EGENERIC
00354  */
00355 VLC_EXPORT( int, filter_chain_DeleteFilter, ( filter_chain_t *, filter_t * ) );
00356 
00357 /**
00358  * Get the number of filters in the filter chain.
00359  *
00360  * \param p_chain pointer to filter chain
00361  * \return number of filters in this filter chain
00362  */
00363 VLC_EXPORT( int, filter_chain_GetLength, ( filter_chain_t * ) );
00364 
00365 /**
00366  * Get last p_fmt_out in the chain.
00367  *
00368  * \param p_chain pointer to filter chain
00369  * \return last p_fmt (es_format_t) of this filter chain
00370  */
00371 VLC_EXPORT( const es_format_t *, filter_chain_GetFmtOut, ( filter_chain_t * ) );
00372 
00373 /**
00374  * Apply the filter chain to a video picture.
00375  *
00376  * \param p_chain pointer to filter chain
00377  * \param p_picture picture to apply filters on
00378  * \return modified picture after applying all video filters
00379  */
00380 VLC_EXPORT( picture_t *, filter_chain_VideoFilter, ( filter_chain_t *, picture_t * ) );
00381 
00382 /**
00383  * Flush a video filter chain.
00384  */
00385 VLC_EXPORT( void, filter_chain_VideoFlush, ( filter_chain_t * ) );
00386 
00387 /**
00388  * Apply the filter chain to a audio block.
00389  *
00390  * \param p_chain pointer to filter chain
00391  * \param p_block audio frame to apply filters on
00392  * \return modified audio frame after applying all audio filters
00393  */
00394 VLC_EXPORT( block_t *, filter_chain_AudioFilter, ( filter_chain_t *, block_t * ) );
00395 
00396 /**
00397  * Apply filter chain to subpictures.
00398  *
00399  * \param p_chain pointer to filter chain
00400  * \param display_date of subpictures
00401  */
00402 VLC_EXPORT( void, filter_chain_SubFilter, ( filter_chain_t *, mtime_t ) );
00403 
00404 /**
00405  * Apply the filter chain to a mouse state.
00406  *
00407  * It will be applied from the output to the input. It makes sense only
00408  * for a video filter chain.
00409  *
00410  * The vlc_mouse_t* pointers may be the same.
00411  */
00412 VLC_EXPORT( int, filter_chain_MouseFilter, ( filter_chain_t *, vlc_mouse_t *, const vlc_mouse_t * ) );
00413 
00414 /**
00415  * Inform the filter chain of mouse state.
00416  *
00417  * It makes sense only for a sub filter chain.
00418  */
00419 VLC_EXPORT( int, filter_chain_MouseEvent, ( filter_chain_t *, const vlc_mouse_t *, const video_format_t * ) );
00420 
00421 #endif /* _VLC_FILTER_H */
00422 

Generated on Mon Nov 22 07:55:19 2010 for VLC by  doxygen 1.5.6