1 /*****************************************************************************
2 * chain.c : chain multiple video filter modules as a last resort solution
3 *****************************************************************************
4 * Copyright (C) 2007-2008 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea at videolan dot org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_filter.h>
36 /*****************************************************************************
37 * Local and extern prototypes.
38 *****************************************************************************/
39 static int Activate ( vlc_object_t * );
40 static void Destroy ( vlc_object_t * );
41 static picture_t *Chain( filter_t *, picture_t * );
42 static int AllocInit( filter_t *p_filter, void *p_data );
44 /*****************************************************************************
46 *****************************************************************************/
48 set_description( N_("Video filtering using a chain of video filter modules") );
49 set_capability( "video filter2", 1 );
50 set_callbacks( Activate, Destroy );
57 filter_chain_t *p_chain;
60 static const vlc_fourcc_t pi_allowed_chromas[] = {
61 VLC_FOURCC('I','4','2','0'),
62 VLC_FOURCC('I','4','2','2'),
63 VLC_FOURCC('R','V','3','2'),
64 VLC_FOURCC('R','V','2','4'),
68 static int CreateChain( filter_chain_t *p_chain, es_format_t *p_fmt_mid )
72 filter_chain_AppendFilter( p_chain, NULL, NULL, NULL, p_fmt_mid )) )
74 if( !filter_chain_AppendFilter( p_chain, NULL, NULL, p_fmt_mid, NULL ) )
76 filter_chain_DeleteFilter( p_chain, p_filter1 );
82 static int AllocInit( filter_t *p_filter, void *p_data )
84 /* Not sure about all of this ... it should work */
85 p_filter->pf_vout_buffer_new = ((filter_t*)p_data)->pf_vout_buffer_new;
86 p_filter->pf_vout_buffer_del = ((filter_t*)p_data)->pf_vout_buffer_del;
87 p_filter->p_owner = ((filter_t*)p_data)->p_owner;
91 /*****************************************************************************
92 * Activate: allocate a chroma function
93 *****************************************************************************
94 * This function allocates and initializes a chroma function
95 *****************************************************************************/
96 static int Activate( vlc_object_t *p_this )
98 filter_t *p_filter = (filter_t *)p_this;
99 static int hack = 0; /* FIXME */
102 if( p_filter->fmt_in.video.i_chroma == p_filter->fmt_out.video.i_chroma )
106 if( hack >= MAX_FILTERS )
108 msg_Err( p_this, "Preventing chain filter reccursion (already %d long)",
113 filter_sys_t *p_sys = (filter_sys_t *)malloc( sizeof( filter_sys_t ) );
119 memset( p_sys, 0, sizeof( filter_sys_t ) );
120 p_filter->p_sys = p_sys;
122 p_sys->p_chain = filter_chain_New( p_filter, "video filter2", false, AllocInit, NULL, p_filter );
123 if( !p_sys->p_chain )
128 filter_chain_Reset( p_sys->p_chain, &p_filter->fmt_in, &p_filter->fmt_out );
130 if( p_filter->fmt_in.video.i_width != p_filter->fmt_out.video.i_width ||
131 p_filter->fmt_in.video.i_height != p_filter->fmt_out.video.i_height ||
132 p_filter->fmt_in.video.i_visible_width != p_filter->fmt_out.video.i_visible_width ||
133 p_filter->fmt_in.video.i_visible_height != p_filter->fmt_out.video.i_visible_height )
135 /* Lets try resizing and then doing the chroma conversion */
136 es_format_Copy( &fmt_mid, &p_filter->fmt_out );
137 fmt_mid.video.i_chroma = p_filter->fmt_out.video.i_chroma;
138 if( CreateChain( p_sys->p_chain, &fmt_mid ) == VLC_SUCCESS )
140 es_format_Clean( &fmt_mid );
141 p_filter->pf_video_filter = Chain;
145 /* Lets try it the other way arround (chroma and then resize) */
146 es_format_Clean( &fmt_mid );
147 es_format_Copy( &fmt_mid, &p_filter->fmt_in );
148 fmt_mid.video.i_chroma = p_filter->fmt_out.video.i_chroma;
149 if( CreateChain( p_sys->p_chain, &fmt_mid ) == VLC_SUCCESS )
151 es_format_Clean( &fmt_mid );
152 p_filter->pf_video_filter = Chain;
158 /* Lets try doing a chroma chain */
160 es_format_Copy( &fmt_mid, &p_filter->fmt_in );
161 for( i = 0; pi_allowed_chromas[i]; i++ )
163 fmt_mid.video.i_chroma = pi_allowed_chromas[i];
164 if( CreateChain( p_sys->p_chain, &fmt_mid ) == VLC_SUCCESS )
166 es_format_Clean( &fmt_mid );
167 p_filter->pf_video_filter = Chain;
173 /* Hum ... looks like this really isn't going to work. Too bad. */
174 es_format_Clean( &fmt_mid );
175 filter_chain_Delete( p_sys->p_chain );
181 static void Destroy( vlc_object_t *p_this )
183 filter_t *p_filter = (filter_t *)p_this;
184 filter_chain_Delete( p_filter->p_sys->p_chain );
185 free( p_filter->p_sys );
188 /*****************************************************************************
190 *****************************************************************************/
191 static picture_t *Chain( filter_t *p_filter, picture_t *p_pic )
193 return filter_chain_VideoFilter( p_filter->p_sys->p_chain, p_pic );