1 /*****************************************************************************
2 * chain.c : chain multiple chroma modules as a last resort solution
3 *****************************************************************************
4 * Copyright (C) 2007 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 *****************************************************************************/
35 /*****************************************************************************
36 * Local and extern prototypes.
37 *****************************************************************************/
38 static int Activate ( vlc_object_t * );
39 static void Destroy ( vlc_object_t * );
40 static void Chain ( vout_thread_t *, picture_t *, picture_t * );
42 /*****************************************************************************
44 *****************************************************************************/
46 set_description( _("Chroma conversions using a chain of chroma conversion modules") );
47 set_capability( "chroma", 1 );
48 set_callbacks( Activate, Destroy );
55 vlc_fourcc_t i_chroma;
57 vout_chroma_t chroma1;
58 vout_chroma_t chroma2;
63 static const vlc_fourcc_t pi_allowed_chromas[] = {
64 VLC_FOURCC('I','4','2','0'),
65 VLC_FOURCC('I','4','2','2'),
69 /*****************************************************************************
70 * Activate: allocate a chroma function
71 *****************************************************************************
72 * This function allocates and initializes a chroma function
73 *****************************************************************************/
74 static int Activate( vlc_object_t *p_this )
77 vout_thread_t *p_vout = (vout_thread_t *)p_this;
80 if( hack > MAX_CHROMAS )
83 msg_Err( p_this, "Preventing chain chroma reccursion (already %d long)",
88 chroma_sys_t *p_sys = (chroma_sys_t *)malloc( sizeof( chroma_sys_t ) );
94 memset( p_sys, 0, sizeof( chroma_sys_t ) );
97 vlc_fourcc_t i_output_chroma = p_vout->output.i_chroma;
98 vlc_fourcc_t i_render_chroma = p_vout->render.i_chroma;
100 for( i = 0; pi_allowed_chromas[i]; i++ )
102 msg_Warn( p_vout, "Trying %4s as a chroma chain",
103 (const char *)&pi_allowed_chromas[i] );
104 p_vout->output.i_chroma = pi_allowed_chromas[i];
105 p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
106 p_vout->output.i_chroma = i_output_chroma;
108 if( !p_vout->chroma.p_module )
111 p_sys->chroma1 = p_vout->chroma;
112 memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
114 p_vout->render.i_chroma = pi_allowed_chromas[i];
115 p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
116 p_vout->render.i_chroma = i_render_chroma;
118 if( !p_vout->chroma.p_module )
120 p_vout->chroma = p_sys->chroma1;
121 module_Unneed( p_vout, p_vout->chroma.p_module );
125 p_sys->chroma2 = p_vout->chroma;
126 memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
128 p_sys->i_chroma = pi_allowed_chromas[i];
129 p_vout->chroma.pf_convert = Chain;
130 p_vout->chroma.p_sys = p_sys;
132 printf("Init: p_sys->p_tmp= %p\n", p_sys->p_tmp );
141 static void Destroy( vlc_object_t *p_this )
143 vout_thread_t *p_vout = (vout_thread_t *)p_this;
144 vout_chroma_t chroma = p_vout->chroma;
147 p_vout->chroma = chroma.p_sys->chroma1;
148 module_Unneed( p_vout, p_vout->chroma.p_module );
149 p_vout->chroma = chroma.p_sys->chroma2;
150 module_Unneed( p_vout, p_vout->chroma.p_module );
151 p_vout->chroma = chroma;
153 if( chroma.p_sys->p_tmp )
155 free( chroma.p_sys->p_tmp->p_data_orig );
156 free( chroma.p_sys->p_tmp );
158 free( chroma.p_sys );
162 /*****************************************************************************
164 *****************************************************************************/
165 static void Chain( vout_thread_t *p_vout, picture_t *p_source,
168 chroma_sys_t *p_sys = p_vout->chroma.p_sys;
172 picture_t *p_tmp = malloc( sizeof( picture_t ) );
173 vout_AllocatePicture( VLC_OBJECT( p_vout ), p_tmp,
175 p_source->p_heap->i_width,
176 p_source->p_heap->i_height,
177 p_source->p_heap->i_aspect );
180 p_sys->p_tmp = p_tmp;
181 p_tmp->pf_release = NULL;
182 p_tmp->i_status = RESERVED_PICTURE;
186 vout_chroma_t chroma = p_vout->chroma;
187 p_vout->chroma = p_sys->chroma1;
188 p_sys->chroma1.pf_convert( p_vout, p_source, p_sys->p_tmp );
189 p_vout->chroma = p_sys->chroma2;
190 p_sys->chroma2.pf_convert( p_vout, p_sys->p_tmp, p_dest );
191 p_vout->chroma = chroma;