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 *****************************************************************************/
33 #include <vlc_plugin.h>
36 /*****************************************************************************
37 * Local and extern prototypes.
38 *****************************************************************************/
39 static int Activate ( vlc_object_t * );
40 static void Destroy ( vlc_object_t * );
41 static void Chain ( vout_thread_t *, picture_t *, picture_t * );
43 /*****************************************************************************
45 *****************************************************************************/
47 set_description( _("Chroma conversions using a chain of chroma conversion modules") );
48 set_capability( "chroma", 1 );
49 set_callbacks( Activate, Destroy );
56 vlc_fourcc_t i_chroma;
58 vout_chroma_t chroma1;
59 vout_chroma_t chroma2;
64 static const vlc_fourcc_t pi_allowed_chromas[] = {
65 VLC_FOURCC('I','4','2','0'),
66 VLC_FOURCC('I','4','2','2'),
70 /*****************************************************************************
71 * Activate: allocate a chroma function
72 *****************************************************************************
73 * This function allocates and initializes a chroma function
74 *****************************************************************************/
75 static int Activate( vlc_object_t *p_this )
78 vout_thread_t *p_vout = (vout_thread_t *)p_this;
81 if( hack > MAX_CHROMAS )
84 msg_Err( p_this, "Preventing chain chroma reccursion (already %d long)",
89 chroma_sys_t *p_sys = (chroma_sys_t *)malloc( sizeof( chroma_sys_t ) );
95 memset( p_sys, 0, sizeof( chroma_sys_t ) );
98 vlc_fourcc_t i_output_chroma = p_vout->output.i_chroma;
99 vlc_fourcc_t i_render_chroma = p_vout->render.i_chroma;
101 for( i = 0; pi_allowed_chromas[i]; i++ )
103 msg_Warn( p_vout, "Trying %4s as a chroma chain",
104 (const char *)&pi_allowed_chromas[i] );
105 p_vout->output.i_chroma = pi_allowed_chromas[i];
106 p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
107 p_vout->output.i_chroma = i_output_chroma;
109 if( !p_vout->chroma.p_module )
112 p_sys->chroma1 = p_vout->chroma;
113 memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
115 p_vout->render.i_chroma = pi_allowed_chromas[i];
116 p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
117 p_vout->render.i_chroma = i_render_chroma;
119 if( !p_vout->chroma.p_module )
121 p_vout->chroma = p_sys->chroma1;
122 module_Unneed( p_vout, p_vout->chroma.p_module );
126 p_sys->chroma2 = p_vout->chroma;
127 memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
129 p_sys->i_chroma = pi_allowed_chromas[i];
130 p_vout->chroma.pf_convert = Chain;
131 p_vout->chroma.p_sys = p_sys;
133 printf("Init: p_sys->p_tmp= %p\n", p_sys->p_tmp );
142 static void Destroy( vlc_object_t *p_this )
144 vout_thread_t *p_vout = (vout_thread_t *)p_this;
145 vout_chroma_t chroma = p_vout->chroma;
148 p_vout->chroma = chroma.p_sys->chroma1;
149 module_Unneed( p_vout, p_vout->chroma.p_module );
150 p_vout->chroma = chroma.p_sys->chroma2;
151 module_Unneed( p_vout, p_vout->chroma.p_module );
152 p_vout->chroma = chroma;
154 if( chroma.p_sys->p_tmp )
156 free( chroma.p_sys->p_tmp->p_data_orig );
157 free( chroma.p_sys->p_tmp );
159 free( chroma.p_sys );
163 /*****************************************************************************
165 *****************************************************************************/
166 static void Chain( vout_thread_t *p_vout, picture_t *p_source,
169 chroma_sys_t *p_sys = p_vout->chroma.p_sys;
173 picture_t *p_tmp = malloc( sizeof( picture_t ) );
174 vout_AllocatePicture( VLC_OBJECT( p_vout ), p_tmp,
176 p_source->p_heap->i_width,
177 p_source->p_heap->i_height,
178 p_source->p_heap->i_aspect );
181 p_sys->p_tmp = p_tmp;
182 p_tmp->pf_release = NULL;
183 p_tmp->i_status = RESERVED_PICTURE;
187 vout_chroma_t chroma = p_vout->chroma;
188 p_vout->chroma = p_sys->chroma1;
189 p_sys->chroma1.pf_convert( p_vout, p_source, p_sys->p_tmp );
190 p_vout->chroma = p_sys->chroma2;
191 p_sys->chroma2.pf_convert( p_vout, p_sys->p_tmp, p_dest );
192 p_vout->chroma = chroma;