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 *****************************************************************************/
31 /*****************************************************************************
32 * Local and extern prototypes.
33 *****************************************************************************/
34 static int Activate ( vlc_object_t * );
35 static void Destroy ( vlc_object_t * );
36 static void Chain ( vout_thread_t *, picture_t *, picture_t * );
38 /*****************************************************************************
40 *****************************************************************************/
42 set_description( _("Chroma conversions using a chain of chroma conversion modules") );
43 set_capability( "chroma", 1 );
44 set_callbacks( Activate, Destroy );
51 vlc_fourcc_t i_chroma;
53 vout_chroma_t chroma1;
54 vout_chroma_t chroma2;
59 static const vlc_fourcc_t pi_allowed_chromas[] = {
60 VLC_FOURCC('I','4','2','0'),
61 VLC_FOURCC('I','4','2','2'),
65 /*****************************************************************************
66 * Activate: allocate a chroma function
67 *****************************************************************************
68 * This function allocates and initializes a chroma function
69 *****************************************************************************/
70 static int Activate( vlc_object_t *p_this )
73 vout_thread_t *p_vout = (vout_thread_t *)p_this;
77 msg_Err( p_this, "Preventing chain chroma reccursion" );
83 chroma_sys_t *p_sys = (chroma_sys_t *)malloc( sizeof( chroma_sys_t ) );
89 memset( p_sys, 0, sizeof( chroma_sys_t ) );
92 vlc_fourcc_t i_output_chroma = p_vout->output.i_chroma;
93 vlc_fourcc_t i_render_chroma = p_vout->render.i_chroma;
95 for( i = 0; pi_allowed_chromas[i]; i++ )
97 msg_Warn( p_vout, "Trying %4s as a chroma chain",
98 (const char *)&pi_allowed_chromas[i] );
99 p_vout->output.i_chroma = pi_allowed_chromas[i];
100 p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
101 p_vout->output.i_chroma = i_output_chroma;
103 if( !p_vout->chroma.p_module )
106 p_sys->chroma1 = p_vout->chroma;
107 memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
109 p_vout->render.i_chroma = pi_allowed_chromas[i];
110 p_vout->chroma.p_module = module_Need( p_vout, "chroma", NULL, 0 );
111 p_vout->render.i_chroma = i_render_chroma;
113 if( !p_vout->chroma.p_module )
115 p_vout->chroma = p_sys->chroma1;
116 module_Unneed( p_vout, p_vout->chroma.p_module );
120 p_sys->chroma2 = p_vout->chroma;
121 memset( &p_vout->chroma, 0, sizeof( vout_chroma_t ) );
123 p_sys->i_chroma = pi_allowed_chromas[i];
124 p_vout->chroma.pf_convert = Chain;
125 p_vout->chroma.p_sys = p_sys;
135 static void Destroy( vlc_object_t *p_this )
137 vout_thread_t *p_vout = (vout_thread_t *)p_this;
138 vout_chroma_t chroma = p_vout->chroma;
141 p_vout->chroma = chroma.p_sys->chroma1;
142 module_Unneed( p_vout, p_vout->chroma.p_module );
143 p_vout->chroma = chroma.p_sys->chroma2;
144 module_Unneed( p_vout, p_vout->chroma.p_module );
145 p_vout->chroma = chroma;
147 if( chroma.p_sys->p_tmp )
149 free( chroma.p_sys->p_tmp->p_data_orig );
150 free( chroma.p_sys->p_tmp );
152 free( chroma.p_sys );
155 /*****************************************************************************
157 *****************************************************************************/
158 static void Chain( vout_thread_t *p_vout, picture_t *p_source,
161 chroma_sys_t *p_sys = p_vout->chroma.p_sys;
165 picture_t *p_tmp = malloc( sizeof( picture_t ) );
166 vout_AllocatePicture( VLC_OBJECT( p_vout ), p_tmp,
168 p_source->p_heap->i_width,
169 p_source->p_heap->i_height,
170 p_source->p_heap->i_aspect );
173 p_sys->p_tmp = p_tmp;
174 p_tmp->pf_release = NULL;
175 p_tmp->i_status = RESERVED_PICTURE;
179 p_sys->chroma1.pf_convert( p_vout, p_source, p_sys->p_tmp );
180 p_sys->chroma2.pf_convert( p_vout, p_sys->p_tmp, p_dest );