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 VLC authors and VideoLAN
00005  * $Id: b57b7eff75390d03e7ec0e1a1a510d701e8df5ef $
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 it
00011  * under the terms of the GNU Lesser General Public License as published by
00012  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public License
00021  * along with this program; if not, write to the Free Software Foundation,
00022  * 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         } audio;
00093 #define pf_audio_filter     u.audio.pf_filter
00094 
00095         struct
00096         {
00097             void        (*pf_blend) ( filter_t *,  picture_t *,
00098                                       const picture_t *, int, int, int );
00099         } blend;
00100 #define pf_video_blend     u.blend.pf_blend
00101 
00102         struct
00103         {
00104             subpicture_t * (*pf_source)    ( filter_t *, mtime_t );
00105             subpicture_t * (*pf_buffer_new)( filter_t * );
00106             void           (*pf_buffer_del)( filter_t *, subpicture_t * );
00107             int            (*pf_mouse)     ( filter_t *,
00108                                              const vlc_mouse_t *p_old,
00109                                              const vlc_mouse_t *p_new,
00110                                              const video_format_t * );
00111         } sub;
00112 #define pf_sub_source      u.sub.pf_source
00113 #define pf_sub_buffer_new  u.sub.pf_buffer_new
00114 #define pf_sub_buffer_del  u.sub.pf_buffer_del
00115 #define pf_sub_mouse       u.sub.pf_mouse
00116 
00117         struct
00118         {
00119             subpicture_t * (*pf_filter) ( filter_t *, subpicture_t * );
00120         } subf;
00121 #define pf_sub_filter      u.subf.pf_filter
00122 
00123         struct
00124         {
00125             int         (*pf_text) ( filter_t *, subpicture_region_t *,
00126                                      subpicture_region_t *,
00127                                      const vlc_fourcc_t * );
00128             int         (*pf_html) ( filter_t *, subpicture_region_t *,
00129                                      subpicture_region_t *,
00130                                      const vlc_fourcc_t * );
00131         } render;
00132 #define pf_render_text     u.render.pf_text
00133 #define pf_render_html     u.render.pf_html
00134 
00135     } u;
00136 
00137     /* Input attachments
00138      * XXX use filter_GetInputAttachments */
00139     int (*pf_get_attachments)( filter_t *, input_attachment_t ***, int * );
00140 
00141     /* Private structure for the owner of the decoder */
00142     filter_owner_sys_t *p_owner;
00143 };
00144 
00145 /**
00146  * This function will return a new picture usable by p_filter as an output
00147  * buffer. You have to release it using filter_DeletePicture or by returning
00148  * it to the caller as a pf_video_filter return value.
00149  * Provided for convenience.
00150  *
00151  * \param p_filter filter_t object
00152  * \return new picture on success or NULL on failure
00153  */
00154 static inline picture_t *filter_NewPicture( filter_t *p_filter )
00155 {
00156     picture_t *p_picture = p_filter->pf_video_buffer_new( p_filter );
00157     if( !p_picture )
00158         msg_Warn( p_filter, "can't get output picture" );
00159     return p_picture;
00160 }
00161 
00162 /**
00163  * This function will release a picture create by filter_NewPicture.
00164  * Provided for convenience.
00165  *
00166  * \param p_filter filter_t object
00167  * \param p_picture picture to be deleted
00168  */
00169 static inline void filter_DeletePicture( filter_t *p_filter, picture_t *p_picture )
00170 {
00171     p_filter->pf_video_buffer_del( p_filter, p_picture );
00172 }
00173 
00174 /**
00175  * This function will flush the state of a video filter.
00176  */
00177 static inline void filter_FlushPictures( filter_t *p_filter )
00178 {
00179     if( p_filter->pf_video_flush )
00180         p_filter->pf_video_flush( p_filter );
00181 }
00182 
00183 /**
00184  * This function will return a new subpicture usable by p_filter as an output
00185  * buffer. You have to release it using filter_DeleteSubpicture or by returning
00186  * it to the caller as a pf_sub_source return value.
00187  * Provided for convenience.
00188  *
00189  * \param p_filter filter_t object
00190  * \return new subpicture
00191  */
00192 static inline subpicture_t *filter_NewSubpicture( filter_t *p_filter )
00193 {
00194     subpicture_t *p_subpicture = p_filter->pf_sub_buffer_new( p_filter );
00195     if( !p_subpicture )
00196         msg_Warn( p_filter, "can't get output subpicture" );
00197     return p_subpicture;
00198 }
00199 
00200 /**
00201  * This function will release a subpicture create by filter_NewSubicture.
00202  * Provided for convenience.
00203  *
00204  * \param p_filter filter_t object
00205  * \param p_subpicture to be released
00206  */
00207 static inline void filter_DeleteSubpicture( filter_t *p_filter, subpicture_t *p_subpicture )
00208 {
00209     p_filter->pf_sub_buffer_del( p_filter, p_subpicture );
00210 }
00211 
00212 #define filter_NewAudioBuffer block_New
00213 
00214 /**
00215  * This function gives all input attachments at once.
00216  *
00217  * You MUST release the returned values
00218  */
00219 static inline int filter_GetInputAttachments( filter_t *p_filter,
00220                                               input_attachment_t ***ppp_attachment,
00221                                               int *pi_attachment )
00222 {
00223     if( !p_filter->pf_get_attachments )
00224         return VLC_EGENERIC;
00225     return p_filter->pf_get_attachments( p_filter,
00226                                          ppp_attachment, pi_attachment );
00227 }
00228 
00229 /**
00230  * It creates a blend filter.
00231  *
00232  * Only the chroma properties of the dest format is used (chroma
00233  * type, rgb masks and shifts)
00234  */
00235 VLC_API filter_t * filter_NewBlend( vlc_object_t *, const video_format_t *p_dst_chroma ) VLC_USED;
00236 
00237 /**
00238  * It configures blend filter parameters that are allowed to changed
00239  * after the creation.
00240  */
00241 VLC_API int filter_ConfigureBlend( filter_t *, int i_dst_width, int i_dst_height, const video_format_t *p_src );
00242 
00243 /**
00244  * It blends a picture into another one.
00245  *
00246  * The input picture is not modified and not released.
00247  */
00248 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 );
00249 
00250 /**
00251  * It destroys a blend filter created by filter_NewBlend.
00252  */
00253 VLC_API void filter_DeleteBlend( filter_t * );
00254 
00255 /**
00256  * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
00257  * using a void (*)( filter_t *, picture_t *, picture_t * ) function
00258  *
00259  * Currently used by the chroma video filters
00260  */
00261 #define VIDEO_FILTER_WRAPPER( name )                                    \
00262     static picture_t *name ## _Filter ( filter_t *p_filter,             \
00263                                         picture_t *p_pic )              \
00264     {                                                                   \
00265         picture_t *p_outpic = filter_NewPicture( p_filter );            \
00266         if( p_outpic )                                                  \
00267         {                                                               \
00268             name( p_filter, p_pic, p_outpic );                          \
00269             picture_CopyProperties( p_outpic, p_pic );                  \
00270         }                                                               \
00271         picture_Release( p_pic );                                       \
00272         return p_outpic;                                                \
00273     }
00274 
00275 /**
00276  * Filter chain management API
00277  * The filter chain management API is used to dynamically construct filters
00278  * and add them in a chain.
00279  */
00280 
00281 typedef struct filter_chain_t filter_chain_t;
00282 
00283 /**
00284  * Create new filter chain
00285  *
00286  * \param p_object pointer to a vlc object
00287  * \param psz_capability vlc capability of filters in filter chain
00288  * \param b_allow_format_fmt_change allow changing of fmt
00289  * \param pf_buffer_allocation_init callback function to initialize buffer allocations
00290  * \param pf_buffer_allocation_clear callback function to clear buffer allocation initialization
00291  * \param p_buffer_allocation_data pointer to private allocation data
00292  * \return pointer to a filter chain
00293  */
00294 VLC_API filter_chain_t * filter_chain_New( vlc_object_t *, const char *, bool, int (*)( filter_t *, void * ), void (*)( filter_t * ), void *  ) VLC_USED;
00295 #define filter_chain_New( a, b, c, d, e, f ) filter_chain_New( VLC_OBJECT( a ), b, c, d, e, f )
00296 
00297 /**
00298  * Delete filter chain will delete all filters in the chain and free all
00299  * allocated data. The pointer to the filter chain is then no longer valid.
00300  *
00301  * \param p_chain pointer to filter chain
00302  */
00303 VLC_API void filter_chain_Delete( filter_chain_t * );
00304 
00305 /**
00306  * Reset filter chain will delete all filters in the chain and
00307  * reset p_fmt_in and p_fmt_out to the new values.
00308  *
00309  * \param p_chain pointer to filter chain
00310  * \param p_fmt_in new fmt_in params
00311  * \param p_fmt_out new fmt_out params
00312  */
00313 VLC_API void filter_chain_Reset( filter_chain_t *, const es_format_t *, const es_format_t * );
00314 
00315 /**
00316  * Append filter to the end of the chain.
00317  *
00318  * \param p_chain pointer to filter chain
00319  * \param psz_name name of filter
00320  * \param p_cfg
00321  * \param p_fmt_in input es_format_t
00322  * \param p_fmt_out output es_format_t
00323  * \return pointer to filter chain
00324  */
00325 VLC_API filter_t * filter_chain_AppendFilter( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * );
00326 
00327 /**
00328  * Append new filter to filter chain from string.
00329  *
00330  * \param p_chain pointer to filter chain
00331  * \param psz_string string of filters
00332  * \return 0 for success
00333  */
00334 VLC_API int filter_chain_AppendFromString( filter_chain_t *, const char * );
00335 
00336 /**
00337  * Delete filter from filter chain. This function also releases the filter
00338  * object and unloads the filter modules. The pointer to p_filter is no
00339  * longer valid after this function successfully returns.
00340  *
00341  * \param p_chain pointer to filter chain
00342  * \param p_filter pointer to filter object
00343  * \return VLC_SUCCESS on succes, else VLC_EGENERIC
00344  */
00345 VLC_API int filter_chain_DeleteFilter( filter_chain_t *, filter_t * );
00346 
00347 /**
00348  * Get the number of filters in the filter chain.
00349  *
00350  * \param p_chain pointer to filter chain
00351  * \return number of filters in this filter chain
00352  */
00353 VLC_API int filter_chain_GetLength( filter_chain_t * );
00354 
00355 /**
00356  * Get last p_fmt_out in the chain.
00357  *
00358  * \param p_chain pointer to filter chain
00359  * \return last p_fmt (es_format_t) of this filter chain
00360  */
00361 VLC_API const es_format_t * filter_chain_GetFmtOut( filter_chain_t * );
00362 
00363 /**
00364  * Apply the filter chain to a video picture.
00365  *
00366  * \param p_chain pointer to filter chain
00367  * \param p_picture picture to apply filters on
00368  * \return modified picture after applying all video filters
00369  */
00370 VLC_API picture_t * filter_chain_VideoFilter( filter_chain_t *, picture_t * );
00371 
00372 /**
00373  * Flush a video filter chain.
00374  */
00375 VLC_API void filter_chain_VideoFlush( filter_chain_t * );
00376 
00377 /**
00378  * Apply the filter chain to a audio block.
00379  *
00380  * \param p_chain pointer to filter chain
00381  * \param p_block audio frame to apply filters on
00382  * \return modified audio frame after applying all audio filters
00383  */
00384 VLC_API block_t * filter_chain_AudioFilter( filter_chain_t *, block_t * );
00385 
00386 /**
00387  * Apply filter chain to subpictures.
00388  *
00389  * \param p_chain pointer to filter chain
00390  * \param display_date of subpictures
00391  */
00392 VLC_API void filter_chain_SubSource( filter_chain_t *, mtime_t );
00393 
00394 /**
00395  * Apply filter chain to subpictures.
00396  *
00397  * \param p_chain pointer to filter chain
00398  * \param p_subpicture subpicture to apply filters on
00399  * \return modified subpicture after applying all subpicture filters
00400  */
00401 VLC_API subpicture_t * filter_chain_SubFilter( filter_chain_t *, subpicture_t * );
00402 
00403 /**
00404  * Apply the filter chain to a mouse state.
00405  *
00406  * It will be applied from the output to the input. It makes sense only
00407  * for a video filter chain.
00408  *
00409  * The vlc_mouse_t* pointers may be the same.
00410  */
00411 VLC_API int filter_chain_MouseFilter( filter_chain_t *, vlc_mouse_t *, const vlc_mouse_t * );
00412 
00413 /**
00414  * Inform the filter chain of mouse state.
00415  *
00416  * It makes sense only for a sub source chain.
00417  */
00418 VLC_API int filter_chain_MouseEvent( filter_chain_t *, const vlc_mouse_t *, const video_format_t * );
00419 
00420 #endif /* _VLC_FILTER_H */
00421 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines