]> git.sesse.net Git - vlc/blob - include/vlc_filter.h
New filter chain handling API. This should make it possible to factorize
[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 #if !defined( __LIBVLC__ )
26   #error You are not libvlc or one of its plugins. You cannot include this file
27 #endif
28
29 #ifndef _VLC_FILTER_H
30 #define _VLC_FILTER_H 1
31
32 #include <vlc_es.h>
33
34 /**
35  * \file
36  * This file defines the structure and types used by video and audio filters
37  */
38
39 typedef struct filter_owner_sys_t filter_owner_sys_t;
40
41 /** Structure describing a filter
42  * @warning BIG FAT WARNING : the code relies in the first 4 members of
43  * filter_t and decoder_t to be the same, so if you have anything to add,
44  * do it at the end of the structure.
45  */
46 struct filter_t
47 {
48     VLC_COMMON_MEMBERS
49
50     /* Module properties */
51     module_t *          p_module;
52     filter_sys_t *      p_sys;
53
54     /* Input format */
55     es_format_t         fmt_in;
56
57     /* Output format of filter */
58     es_format_t         fmt_out;
59     bool                b_allow_fmt_out_change;
60
61     /* Filter configuration */
62     config_chain_t *    p_cfg;
63
64     picture_t *         ( * pf_video_filter ) ( filter_t *, picture_t * );
65     block_t *           ( * pf_audio_filter ) ( filter_t *, block_t * );
66     void                ( * pf_video_blend )  ( filter_t *, picture_t *,
67                                                 picture_t *, picture_t *,
68                                                 int, int, int );
69
70     subpicture_t *      ( *pf_sub_filter ) ( filter_t *, mtime_t );
71     int                 ( *pf_render_text ) ( filter_t *, subpicture_region_t *,
72                                               subpicture_region_t * );
73     int                 ( *pf_render_html ) ( filter_t *, subpicture_region_t *,
74                                               subpicture_region_t * );
75
76     /*
77      * Buffers allocation
78      */
79
80     /* Audio output callbacks */
81     block_t *       ( * pf_audio_buffer_new) ( filter_t *, int );
82
83     /* Video output callbacks */
84     picture_t     * ( * pf_vout_buffer_new) ( filter_t * );
85     void            ( * pf_vout_buffer_del) ( filter_t *, picture_t * );
86     /* void            ( * pf_picture_link)    ( picture_t * );
87     void            ( * pf_picture_unlink)  ( picture_t * ); */
88
89     /* SPU output callbacks */
90     subpicture_t *  ( * pf_sub_buffer_new) ( filter_t * );
91     void            ( * pf_sub_buffer_del) ( filter_t *, subpicture_t * );
92
93     /* Private structure for the owner of the decoder */
94     filter_owner_sys_t *p_owner;
95 };
96
97
98 /**
99  * Create a picture_t *(*)( filter_t *, picture_t * ) compatible wrapper
100  * using a void (*)( filter_t *, picture_t *, picture_t * ) function
101  *
102  * Currently used by the chroma video filters
103  */
104 #define VIDEO_FILTER_WRAPPER( name )                                    \
105     static picture_t *name ## _Filter ( filter_t *p_filter,             \
106                                         picture_t *p_pic )              \
107     {                                                                   \
108         picture_t *p_outpic = p_filter->pf_vout_buffer_new( p_filter ); \
109         if( !p_outpic )                                                 \
110         {                                                               \
111             msg_Warn( p_filter, "can't get output picture" );           \
112             if( p_pic->pf_release )                                     \
113                 p_pic->pf_release( p_pic );                             \
114             return NULL;                                                \
115         }                                                               \
116                                                                         \
117         name( p_filter, p_pic, p_outpic );                              \
118                                                                         \
119         p_outpic->date = p_pic->date;                                   \
120         p_outpic->b_force = p_pic->b_force;                             \
121         p_outpic->i_nb_fields = p_pic->i_nb_fields;                     \
122         p_outpic->b_progressive = p_pic->b_progressive;                 \
123         p_outpic->b_top_field_first = p_pic->b_top_field_first;         \
124                                                                         \
125         if( p_pic->pf_release )                                         \
126             p_pic->pf_release( p_pic );                                 \
127         return p_outpic;                                                \
128     }
129
130 /**
131  * Filter chain management API
132  */
133
134 typedef struct filter_chain_t filter_chain_t;
135
136 VLC_EXPORT( filter_chain_t *, __filter_chain_New, ( vlc_object_t *, const char *, bool, int (*)( filter_t *, void * ), void (*)( filter_t * ), void *  ) );
137 #define filter_chain_New( a, b, c, d, e, f ) __filter_chain_New( VLC_OBJECT( a ), b, c, d, e, f )
138 VLC_EXPORT( void, filter_chain_Delete, ( filter_chain_t * ) );
139 VLC_EXPORT( void, filter_chain_Reset, ( filter_chain_t *, const es_format_t *, const es_format_t * ) );
140
141 VLC_EXPORT( filter_t *, filter_chain_AppendFilter, ( filter_chain_t *, const char *, config_chain_t *, const es_format_t *, const es_format_t * ) );
142 VLC_EXPORT( int, filter_chain_AppendFromString, ( filter_chain_t *, const char * ) );
143 VLC_EXPORT( int, filter_chain_DeleteFilter, ( filter_chain_t *, filter_t * ) );
144
145 VLC_EXPORT( filter_t *, filter_chain_GetFilter, ( filter_chain_t *, int, const char * ) );
146 VLC_EXPORT( int, filter_chain_GetLength, ( filter_chain_t * ) );
147 VLC_EXPORT( const es_format_t *, filter_chain_GetFmtOut, ( filter_chain_t * ) );
148
149 /**
150  * Apply the filter chain
151  */
152 VLC_EXPORT( picture_t *, filter_chain_VideoFilter, ( filter_chain_t *, picture_t * ) );
153 VLC_EXPORT( block_t *, filter_chain_AudioFilter, ( filter_chain_t *, block_t * ) );
154 VLC_EXPORT( void, filter_chain_SubFilter, ( filter_chain_t *, mtime_t ) );
155
156 #endif /* _VLC_FILTER_H */