1 /*****************************************************************************
2 * clone.c : Clone video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: clone.c,v 1.7 2002/06/11 09:44:21 gbazin 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 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
34 #include "filter_common.h"
36 /*****************************************************************************
37 * Capabilities defined in the other files.
38 *****************************************************************************/
39 static void vout_getfunctions( function_list_t * p_function_list );
41 /*****************************************************************************
42 * Build configuration tree.
43 *****************************************************************************/
44 #define COUNT_TEXT N_("Number of clones")
45 #define COUNT_LONGTEXT N_("Select the number of video windows in which to "\
49 ADD_CATEGORY_HINT( N_("Miscellaneous"), NULL )
50 ADD_INTEGER ( "clone-count", 2, NULL, COUNT_TEXT, COUNT_LONGTEXT )
54 SET_DESCRIPTION( _("image clone video module") )
55 /* Capability score set to 0 because we don't want to be spawned
56 * as a video output unless explicitly requested to */
57 ADD_CAPABILITY( VOUT_FILTER, 0 )
58 ADD_SHORTCUT( "clone" )
62 vout_getfunctions( &p_module->p_functions->vout );
65 MODULE_DEACTIVATE_START
66 MODULE_DEACTIVATE_STOP
68 /*****************************************************************************
69 * vout_sys_t: Clone video output method descriptor
70 *****************************************************************************
71 * This structure is part of the video output thread descriptor.
72 * It describes the Clone specific properties of an output thread.
73 *****************************************************************************/
77 vout_thread_t **pp_vout;
80 /*****************************************************************************
82 *****************************************************************************/
83 static int vout_Create ( vout_thread_t * );
84 static int vout_Init ( vout_thread_t * );
85 static void vout_End ( vout_thread_t * );
86 static void vout_Destroy ( vout_thread_t * );
87 static int vout_Manage ( vout_thread_t * );
88 static void vout_Render ( vout_thread_t *, picture_t * );
89 static void vout_Display ( vout_thread_t *, picture_t * );
91 static void RemoveAllVout ( vout_thread_t *p_vout );
93 /*****************************************************************************
94 * Functions exported as capabilities. They are declared as static so that
95 * we don't pollute the namespace too much.
96 *****************************************************************************/
97 static void vout_getfunctions( function_list_t * p_function_list )
99 p_function_list->functions.vout.pf_create = vout_Create;
100 p_function_list->functions.vout.pf_init = vout_Init;
101 p_function_list->functions.vout.pf_end = vout_End;
102 p_function_list->functions.vout.pf_destroy = vout_Destroy;
103 p_function_list->functions.vout.pf_manage = vout_Manage;
104 p_function_list->functions.vout.pf_render = vout_Render;
105 p_function_list->functions.vout.pf_display = vout_Display;
108 /*****************************************************************************
109 * vout_Create: allocates Clone video thread output method
110 *****************************************************************************
111 * This function allocates and initializes a Clone vout method.
112 *****************************************************************************/
113 static int vout_Create( vout_thread_t *p_vout )
116 /* Allocate structure */
117 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
118 if( p_vout->p_sys == NULL )
120 msg_Err( p_vout, "out of memory" );
124 /* Look what method was requested */
125 p_vout->p_sys->i_clones = config_GetInt( p_vout, "clone-count" );
127 p_vout->p_sys->i_clones = __MAX( 1, __MIN( 99, p_vout->p_sys->i_clones ) );
129 msg_Dbg( p_vout, "spawning %i clone(s)", p_vout->p_sys->i_clones );
131 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_clones *
132 sizeof(vout_thread_t *) );
133 if( p_vout->p_sys->pp_vout == NULL )
135 msg_Err( p_vout, "out of memory" );
136 free( p_vout->p_sys );
143 /*****************************************************************************
144 * vout_Init: initialize Clone video thread output method
145 *****************************************************************************/
146 static int vout_Init( vout_thread_t *p_vout )
151 I_OUTPUTPICTURES = 0;
153 /* Initialize the output structure */
154 p_vout->output.i_chroma = p_vout->render.i_chroma;
155 p_vout->output.i_width = p_vout->render.i_width;
156 p_vout->output.i_height = p_vout->render.i_height;
157 p_vout->output.i_aspect = p_vout->render.i_aspect;
159 /* Try to open the real video output */
160 msg_Dbg( p_vout, "spawning the real video outputs" );
162 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
164 p_vout->p_sys->pp_vout[ i_vout ] =
165 vout_CreateThread( p_vout,
166 p_vout->render.i_width, p_vout->render.i_height,
167 p_vout->render.i_chroma, p_vout->render.i_aspect );
168 if( p_vout->p_sys->pp_vout[ i_vout ] == NULL )
170 msg_Err( p_vout, "failed to clone %i vout threads",
171 p_vout->p_sys->i_clones );
172 p_vout->p_sys->i_clones = i_vout;
173 RemoveAllVout( p_vout );
178 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
183 /*****************************************************************************
184 * vout_End: terminate Clone video thread output method
185 *****************************************************************************/
186 static void vout_End( vout_thread_t *p_vout )
190 /* Free the fake output buffers we allocated */
191 for( i_index = I_OUTPUTPICTURES ; i_index ; )
194 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
198 /*****************************************************************************
199 * vout_Destroy: destroy Clone video thread output method
200 *****************************************************************************
201 * Terminate an output method created by CloneCreateOutputMethod
202 *****************************************************************************/
203 static void vout_Destroy( vout_thread_t *p_vout )
205 RemoveAllVout( p_vout );
207 free( p_vout->p_sys->pp_vout );
208 free( p_vout->p_sys );
211 /*****************************************************************************
212 * vout_Manage: handle Clone events
213 *****************************************************************************
214 * This function should be called regularly by video output thread. It manages
215 * console events. It returns a non null value on error.
216 *****************************************************************************/
217 static int vout_Manage( vout_thread_t *p_vout )
222 /*****************************************************************************
223 * vout_Render: displays previously rendered output
224 *****************************************************************************
225 * This function send the currently rendered image to Clone image, waits
226 * until it is displayed and switch the two rendering buffers, preparing next
228 *****************************************************************************/
229 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
231 picture_t *p_outpic = NULL;
234 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
237 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ], 0, 0, 0 )
240 if( p_vout->b_die || p_vout->b_error )
243 p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
247 msleep( VOUT_OUTMEM_SLEEP );
250 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ],
251 p_outpic, p_pic->date );
252 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
254 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
256 u8 *p_in, *p_in_end, *p_out;
257 int i_in_pitch = p_pic->p[i_plane].i_pitch;
258 const int i_out_pitch = p_outpic->p[i_plane].i_pitch;
260 p_in = p_pic->p[i_plane].p_pixels;
262 p_in_end = p_in + p_outpic->p[i_plane].i_lines
263 * p_pic->p[i_plane].i_pitch;
265 p_out = p_outpic->p[i_plane].p_pixels;
267 while( p_in < p_in_end )
269 p_vout->p_vlc->pf_memcpy( p_out, p_in, i_out_pitch );
271 p_out += i_out_pitch;
275 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
276 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
280 /*****************************************************************************
281 * vout_Display: displays previously rendered output
282 *****************************************************************************
283 * This function send the currently rendered image to Invert image, waits
284 * until it is displayed and switch the two rendering buffers, preparing next
286 *****************************************************************************/
287 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
292 /*****************************************************************************
293 * RemoveAllVout: destroy all the child video output threads
294 *****************************************************************************/
295 static void RemoveAllVout( vout_thread_t *p_vout )
297 while( p_vout->p_sys->i_clones )
299 --p_vout->p_sys->i_clones;
300 vout_DestroyThread( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones] );