1 /*****************************************************************************
2 * clone.c : Clone video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002, 2003 VideoLAN
5 * $Id: clone.c,v 1.10 2003/05/15 22:27:37 massiot Exp $
7 * Authors: Samuel Hocevar <sam@zoy.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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
33 #include "filter_common.h"
35 #define VOUTSEPARATOR ','
37 /*****************************************************************************
39 *****************************************************************************/
40 static int Create ( vlc_object_t * );
41 static void Destroy ( vlc_object_t * );
43 static int Init ( vout_thread_t * );
44 static void End ( vout_thread_t * );
45 static void Render ( vout_thread_t *, picture_t * );
47 static void RemoveAllVout ( vout_thread_t *p_vout );
49 static int SendEvents( vlc_object_t *, char const *,
50 vlc_value_t, vlc_value_t, void * );
52 /*****************************************************************************
54 *****************************************************************************/
55 #define COUNT_TEXT N_("Number of clones")
56 #define COUNT_LONGTEXT N_("Select the number of video windows in which to "\
59 #define VOUTLIST_TEXT N_("List of vout modules")
60 #define VOUTLIST_LONGTEXT N_("Select the specific vout modules that you want to activate")
63 add_category_hint( N_("Clone"), NULL, VLC_FALSE );
64 add_integer( "clone-count", 2, NULL, COUNT_TEXT, COUNT_LONGTEXT, VLC_FALSE );
65 add_string ( "clone-vout-list", NULL, NULL, VOUTLIST_TEXT, VOUTLIST_LONGTEXT, VLC_FALSE );
66 set_description( _("clone video filter") );
67 set_capability( "video filter", 0 );
68 add_shortcut( "clone" );
69 set_callbacks( Create, Destroy );
72 /*****************************************************************************
73 * vout_sys_t: Clone video output method descriptor
74 *****************************************************************************
75 * This structure is part of the video output thread descriptor.
76 * It describes the Clone specific properties of an output thread.
77 *****************************************************************************/
82 /* list of vout modules to use. "default" will launch a default
83 * module. If specified, overrides the setting in i_clones (which it
84 * sets to the list length) */
85 char **ppsz_vout_list;
87 vout_thread_t **pp_vout;
90 /*****************************************************************************
91 * Create: allocates Clone video thread output method
92 *****************************************************************************
93 * This function allocates and initializes a Clone vout method.
94 *****************************************************************************/
95 static int Create( vlc_object_t *p_this )
97 vout_thread_t *p_vout = (vout_thread_t *)p_this;
100 /* Allocate structure */
101 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
102 if( p_vout->p_sys == NULL )
104 msg_Err( p_vout, "out of memory" );
108 p_vout->pf_init = Init;
109 p_vout->pf_end = End;
110 p_vout->pf_manage = NULL;
111 p_vout->pf_render = Render;
112 p_vout->pf_display = NULL;
114 psz_clonelist = config_GetPsz( p_vout, "clone-vout-list" );
120 /* Count the number of defined vout */
121 p_vout->p_sys->i_clones = 1;
123 while( psz_clonelist[i_dummy] != 0 )
125 if( psz_clonelist[i_dummy] == VOUTSEPARATOR )
126 p_vout->p_sys->i_clones++;
130 p_vout->p_sys->ppsz_vout_list = malloc( p_vout->p_sys->i_clones
132 if( !p_vout->p_sys->ppsz_vout_list )
134 msg_Err( p_vout, "out of memory" );
135 free( p_vout->p_sys );
139 /* Tokenize the list */
141 psz_token = psz_clonelist;
142 while( psz_token && *psz_token )
145 psz_module = psz_token;
146 psz_token = strchr( psz_module, VOUTSEPARATOR );
152 p_vout->p_sys->ppsz_vout_list[i_dummy] = strdup( psz_module );
156 free( psz_clonelist );
160 /* No list was specified. We will use the default vout, and get
161 * the number of clones from clone-count */
162 p_vout->p_sys->i_clones = config_GetInt( p_vout, "clone-count" );
163 p_vout->p_sys->ppsz_vout_list = NULL;
166 p_vout->p_sys->i_clones = __MAX( 1, __MIN( 99, p_vout->p_sys->i_clones ) );
168 msg_Dbg( p_vout, "spawning %i clone(s)", p_vout->p_sys->i_clones );
170 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_clones *
171 sizeof(vout_thread_t *) );
172 if( p_vout->p_sys->pp_vout == NULL )
174 msg_Err( p_vout, "out of memory" );
175 free( p_vout->p_sys );
182 /*****************************************************************************
183 * Init: initialize Clone video thread output method
184 *****************************************************************************/
185 static int Init( vout_thread_t *p_vout )
189 char *psz_default_vout;
191 I_OUTPUTPICTURES = 0;
193 /* Initialize the output structure */
194 p_vout->output.i_chroma = p_vout->render.i_chroma;
195 p_vout->output.i_width = p_vout->render.i_width;
196 p_vout->output.i_height = p_vout->render.i_height;
197 p_vout->output.i_aspect = p_vout->render.i_aspect;
199 /* Try to open the real video output */
200 msg_Dbg( p_vout, "spawning the real video outputs" );
202 /* Save the default vout */
203 psz_default_vout = config_GetPsz( p_vout, "vout" );
205 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
207 if( p_vout->p_sys->ppsz_vout_list == NULL
208 || ( !strncmp( p_vout->p_sys->ppsz_vout_list[i_vout],
211 p_vout->p_sys->pp_vout[i_vout] =
212 vout_Create( p_vout, p_vout->render.i_width,
213 p_vout->render.i_height, p_vout->render.i_chroma,
214 p_vout->render.i_aspect );
218 /* create the appropriate vout instead of the default one */
219 config_PutPsz( p_vout, "vout",
220 p_vout->p_sys->ppsz_vout_list[i_vout] );
221 p_vout->p_sys->pp_vout[i_vout] =
222 vout_Create( p_vout, p_vout->render.i_width,
223 p_vout->render.i_height, p_vout->render.i_chroma,
224 p_vout->render.i_aspect );
226 /* Reset the default value */
227 config_PutPsz( p_vout, "vout", psz_default_vout );
230 if( p_vout->p_sys->pp_vout[ i_vout ] == NULL )
232 msg_Err( p_vout, "failed to clone %i vout threads",
233 p_vout->p_sys->i_clones );
234 p_vout->p_sys->i_clones = i_vout;
235 if( psz_default_vout ) free( psz_default_vout );
236 RemoveAllVout( p_vout );
240 ADD_CALLBACKS( p_vout->p_sys->pp_vout[ i_vout ], SendEvents );
243 if( psz_default_vout ) free( psz_default_vout );
244 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
249 /*****************************************************************************
250 * End: terminate Clone video thread output method
251 *****************************************************************************/
252 static void End( vout_thread_t *p_vout )
256 /* Free the fake output buffers we allocated */
257 for( i_index = I_OUTPUTPICTURES ; i_index ; )
260 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
264 /*****************************************************************************
265 * Destroy: destroy Clone video thread output method
266 *****************************************************************************
267 * Terminate an output method created by CloneCreateOutputMethod
268 *****************************************************************************/
269 static void Destroy( vlc_object_t *p_this )
271 vout_thread_t *p_vout = (vout_thread_t *)p_this;
273 RemoveAllVout( p_vout );
275 free( p_vout->p_sys->pp_vout );
276 free( p_vout->p_sys );
279 /*****************************************************************************
280 * Render: displays previously rendered output
281 *****************************************************************************
282 * This function send the currently rendered image to Clone image, waits
283 * until it is displayed and switch the two rendering buffers, preparing next
285 *****************************************************************************/
286 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
288 picture_t *p_outpic = NULL;
291 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
294 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ], 0, 0, 0 )
297 if( p_vout->b_die || p_vout->b_error )
300 p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
304 msleep( VOUT_OUTMEM_SLEEP );
307 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ],
308 p_outpic, p_pic->date );
309 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
311 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
313 uint8_t *p_in, *p_in_end, *p_out;
314 int i_in_pitch = p_pic->p[i_plane].i_pitch;
315 const int i_out_pitch = p_outpic->p[i_plane].i_pitch;
316 const int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
318 p_in = p_pic->p[i_plane].p_pixels;
319 p_out = p_outpic->p[i_plane].p_pixels;
321 if( i_in_pitch == i_copy_pitch
322 && i_out_pitch == i_copy_pitch )
324 p_vout->p_vlc->pf_memcpy( p_out, p_in, i_in_pitch
325 * p_outpic->p[i_plane].i_lines );
329 p_in_end = p_in + i_in_pitch * p_outpic->p[i_plane].i_lines;
331 while( p_in < p_in_end )
333 p_vout->p_vlc->pf_memcpy( p_out, p_in, i_copy_pitch );
335 p_out += i_out_pitch;
340 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
341 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
345 /*****************************************************************************
346 * RemoveAllVout: destroy all the child video output threads
347 *****************************************************************************/
348 static void RemoveAllVout( vout_thread_t *p_vout )
350 while( p_vout->p_sys->i_clones )
352 --p_vout->p_sys->i_clones;
353 DEL_CALLBACKS( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones],
355 vlc_object_detach( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones] );
356 vout_Destroy( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones] );
360 /*****************************************************************************
361 * SendEvents: forward mouse and keyboard events to the parent p_vout
362 *****************************************************************************/
363 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
364 vlc_value_t oldval, vlc_value_t newval, void *p_data )
366 var_Set( (vlc_object_t *)p_data, psz_var, newval );