1 /*****************************************************************************
2 * chain.c : chain multiple chroma 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>
37 /*****************************************************************************
38 * Local and extern prototypes.
39 *****************************************************************************/
40 static int Activate ( vlc_object_t * );
41 static void Destroy ( vlc_object_t * );
42 static void Chain ( filter_t *, picture_t *, picture_t * );
44 /*****************************************************************************
46 *****************************************************************************/
48 set_description( N_("Chroma conversions using a chain of chroma conversion modules") );
49 set_capability( "chroma", 1 );
50 set_callbacks( Activate, Destroy );
57 vlc_fourcc_t i_chroma;
65 static const vlc_fourcc_t pi_allowed_chromas[] = {
66 VLC_FOURCC('I','4','2','0'),
67 VLC_FOURCC('I','4','2','2'),
68 VLC_FOURCC('R','V','3','2'),
69 VLC_FOURCC('R','V','2','4'),
73 /*****************************************************************************
74 * Activate: allocate a chroma function
75 *****************************************************************************
76 * This function allocates and initializes a chroma function
77 *****************************************************************************/
78 static int Activate( vlc_object_t *p_this )
82 filter_t *p_filter = (filter_t *)p_this;
85 if( hack > MAX_CHROMAS )
88 msg_Err( p_this, "Preventing chain chroma reccursion (already %d long)",
93 filter_sys_t *p_sys = (filter_sys_t *)malloc( sizeof( filter_sys_t ) );
99 memset( p_sys, 0, sizeof( filter_sys_t ) );
102 vlc_fourcc_t i_output_chroma = p_filter->fmt_in.video.i_chroma;
103 vlc_fourcc_t i_render_chroma = p_filter->fmt_out.video.i_chroma;
105 for( i = 0; pi_allowed_chromas[i]; i++ )
107 msg_Warn( p_filter, "Trying %4s as a chroma chain",
108 (const char *)&pi_allowed_chromas[i] );
109 p_filter->output.i_chroma = pi_allowed_chromas[i];
110 p_filter->p_chroma1.p_module = module_Need( p_vout, "chroma", NULL, 0 );
111 p_filter->output.i_chroma = i_output_chroma;
113 if( !p_vout->chroma.p_module )
116 p_sys->chroma1 = p_vout->chroma;
117 memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
119 p_vout->render.i_chroma = pi_allowed_chromas[i];
120 p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
121 p_vout->render.i_chroma = i_render_chroma;
123 if( !p_vout->chroma.p_module )
125 p_vout->chroma = p_sys->chroma1;
126 module_Unneed( p_vout, p_vout->chroma.p_module );
130 p_sys->chroma2 = p_vout->chroma;
131 memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
133 p_sys->i_chroma = pi_allowed_chromas[i];
134 p_vout->chroma.pf_convert = Chain;
135 p_vout->chroma.p_sys = p_sys;
137 printf("Init: p_sys->p_tmp= %p\n", p_sys->p_tmp );
147 static void Destroy( vlc_object_t *p_this )
150 filter_t *p_filter = (filter_t *)p_this;
151 vout_chroma_t chroma = p_vout->chroma;
153 p_vout->chroma = chroma.p_sys->chroma1;
154 module_Unneed( p_vout, p_vout->chroma.p_module );
155 p_vout->chroma = chroma.p_sys->chroma2;
156 module_Unneed( p_vout, p_vout->chroma.p_module );
157 p_vout->chroma = chroma;
159 if( chroma.p_sys->p_tmp )
161 free( chroma.p_sys->p_tmp->p_data_orig );
162 free( chroma.p_sys->p_tmp );
164 free( chroma.p_sys );
169 /*****************************************************************************
171 *****************************************************************************/
172 static void Chain( filter_t *p_filter, picture_t *p_source,
176 chroma_sys_t *p_sys = p_vout->chroma.p_sys;
180 picture_t *p_tmp = malloc( sizeof( picture_t ) );
181 vout_AllocatePicture( VLC_OBJECT( p_vout ), p_tmp,
183 p_source->p_heap->i_width,
184 p_source->p_heap->i_height,
185 p_source->p_heap->i_aspect );
188 p_sys->p_tmp = p_tmp;
189 p_tmp->pf_release = NULL;
190 p_tmp->i_status = RESERVED_PICTURE;
194 vout_chroma_t chroma = p_vout->chroma;
195 p_vout->chroma = p_sys->chroma1;
196 p_sys->chroma1.pf_convert( p_vout, p_source, p_sys->p_tmp );
197 p_vout->chroma = p_sys->chroma2;
198 p_sys->chroma2.pf_convert( p_vout, p_sys->p_tmp, p_dest );
199 p_vout->chroma = chroma;