1 /*****************************************************************************
2 * clone.c : Clone video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: clone.c,v 1.2 2002/05/19 12:57:32 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() */
31 #include <videolan/vlc.h>
34 #include "video_output.h"
36 #include "filter_common.h"
38 /*****************************************************************************
39 * Capabilities defined in the other files.
40 *****************************************************************************/
41 static void vout_getfunctions( function_list_t * p_function_list );
43 /*****************************************************************************
44 * Build configuration tree.
45 *****************************************************************************/
50 SET_DESCRIPTION( _("image clone video module") )
51 /* Capability score set to 0 because we don't want to be spawned
52 * as a video output unless explicitly requested to */
53 ADD_CAPABILITY( VOUT, 0 )
54 ADD_SHORTCUT( "clone" )
58 vout_getfunctions( &p_module->p_functions->vout );
61 MODULE_DEACTIVATE_START
62 MODULE_DEACTIVATE_STOP
64 /*****************************************************************************
65 * vout_sys_t: Clone video output method descriptor
66 *****************************************************************************
67 * This structure is part of the video output thread descriptor.
68 * It describes the Clone specific properties of an output thread.
69 *****************************************************************************/
70 typedef struct vout_sys_s
73 vout_thread_t **pp_vout;
77 /*****************************************************************************
79 *****************************************************************************/
80 static int vout_Create ( vout_thread_t * );
81 static int vout_Init ( vout_thread_t * );
82 static void vout_End ( vout_thread_t * );
83 static void vout_Destroy ( vout_thread_t * );
84 static int vout_Manage ( vout_thread_t * );
85 static void vout_Render ( vout_thread_t *, picture_t * );
86 static void vout_Display ( vout_thread_t *, picture_t * );
88 static void RemoveAllVout ( vout_thread_t *p_vout );
90 /*****************************************************************************
91 * Functions exported as capabilities. They are declared as static so that
92 * we don't pollute the namespace too much.
93 *****************************************************************************/
94 static void vout_getfunctions( function_list_t * p_function_list )
96 p_function_list->functions.vout.pf_create = vout_Create;
97 p_function_list->functions.vout.pf_init = vout_Init;
98 p_function_list->functions.vout.pf_end = vout_End;
99 p_function_list->functions.vout.pf_destroy = vout_Destroy;
100 p_function_list->functions.vout.pf_manage = vout_Manage;
101 p_function_list->functions.vout.pf_render = vout_Render;
102 p_function_list->functions.vout.pf_display = vout_Display;
105 /*****************************************************************************
106 * vout_Create: allocates Clone video thread output method
107 *****************************************************************************
108 * This function allocates and initializes a Clone vout method.
109 *****************************************************************************/
110 static int vout_Create( vout_thread_t *p_vout )
112 char *psz_method, *psz_method_orig;
114 /* Allocate structure */
115 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
116 if( p_vout->p_sys == NULL )
118 intf_ErrMsg( "vout error: out of memory" );
122 /* Look what method was requested */
123 if( !(psz_method = psz_method_orig = config_GetPszVariable( "filter" )) )
125 intf_ErrMsg( "vout error: configuration variable %s empty", "filter" );
129 while( *psz_method && *psz_method != ':' )
136 p_vout->p_sys->i_clones = atoi( psz_method + 1 );
140 intf_ErrMsg( "vout error: "
141 "no valid clone count provided, using clone:2" );
142 p_vout->p_sys->i_clones = 2;
145 p_vout->p_sys->i_clones = __MAX( 1, __MIN( 99, p_vout->p_sys->i_clones ) );
147 intf_WarnMsg( 3, "vout info: spawning %i clone(s)",
148 p_vout->p_sys->i_clones );
150 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_clones *
151 sizeof(vout_thread_t *) );
152 if( p_vout->p_sys->pp_vout == NULL )
154 intf_ErrMsg( "vout error: out of memory" );
155 free( psz_method_orig );
156 free( p_vout->p_sys );
160 free( psz_method_orig );
165 /*****************************************************************************
166 * vout_Init: initialize Clone video thread output method
167 *****************************************************************************/
168 static int vout_Init( vout_thread_t *p_vout )
174 I_OUTPUTPICTURES = 0;
176 /* Initialize the output structure */
177 p_vout->output.i_chroma = p_vout->render.i_chroma;
178 p_vout->output.i_width = p_vout->render.i_width;
179 p_vout->output.i_height = p_vout->render.i_height;
180 p_vout->output.i_aspect = p_vout->render.i_aspect;
182 /* Try to open the real video output */
183 psz_filter = config_GetPszVariable( "filter" );
184 config_PutPszVariable( "filter", NULL );
186 intf_WarnMsg( 3, "vout info: spawning the real video outputs" );
188 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
190 p_vout->p_sys->pp_vout[ i_vout ] =
191 vout_CreateThread( NULL,
192 p_vout->render.i_width, p_vout->render.i_height,
193 p_vout->render.i_chroma, p_vout->render.i_aspect );
194 if( p_vout->p_sys->pp_vout[ i_vout ] == NULL )
196 intf_ErrMsg( "vout error: failed to clone %i vout threads",
197 p_vout->p_sys->i_clones );
198 p_vout->p_sys->i_clones = i_vout;
199 RemoveAllVout( p_vout );
200 config_PutPszVariable( "filter", psz_filter );
201 if( psz_filter ) free( psz_filter );
206 config_PutPszVariable( "filter", psz_filter );
207 if( psz_filter ) free( psz_filter );
209 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
214 /*****************************************************************************
215 * vout_End: terminate Clone video thread output method
216 *****************************************************************************/
217 static void vout_End( vout_thread_t *p_vout )
221 /* Free the fake output buffers we allocated */
222 for( i_index = I_OUTPUTPICTURES ; i_index ; )
225 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
229 /*****************************************************************************
230 * vout_Destroy: destroy Clone video thread output method
231 *****************************************************************************
232 * Terminate an output method created by CloneCreateOutputMethod
233 *****************************************************************************/
234 static void vout_Destroy( vout_thread_t *p_vout )
236 RemoveAllVout( p_vout );
238 free( p_vout->p_sys->pp_vout );
239 free( p_vout->p_sys );
242 /*****************************************************************************
243 * vout_Manage: handle Clone events
244 *****************************************************************************
245 * This function should be called regularly by video output thread. It manages
246 * console events. It returns a non null value on error.
247 *****************************************************************************/
248 static int vout_Manage( vout_thread_t *p_vout )
253 /*****************************************************************************
254 * vout_Render: displays previously rendered output
255 *****************************************************************************
256 * This function send the currently rendered image to Clone image, waits
257 * until it is displayed and switch the two rendering buffers, preparing next
259 *****************************************************************************/
260 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
262 picture_t *p_outpic = NULL;
265 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
268 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ], 0, 0, 0 )
271 if( p_vout->b_die || p_vout->b_error )
274 p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
278 msleep( VOUT_OUTMEM_SLEEP );
281 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ],
282 p_outpic, p_pic->date );
283 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
285 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
287 u8 *p_in, *p_in_end, *p_out;
288 int i_in_pitch = p_pic->p[i_plane].i_pitch;
289 const int i_out_pitch = p_outpic->p[i_plane].i_pitch;
291 p_in = p_pic->p[i_plane].p_pixels;
293 p_in_end = p_in + p_outpic->p[i_plane].i_lines
294 * p_pic->p[i_plane].i_pitch;
296 p_out = p_outpic->p[i_plane].p_pixels;
298 while( p_in < p_in_end )
300 FAST_MEMCPY( p_out, p_in, i_out_pitch );
302 p_out += i_out_pitch;
306 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
307 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
311 /*****************************************************************************
312 * vout_Display: displays previously rendered output
313 *****************************************************************************
314 * This function send the currently rendered image to Invert image, waits
315 * until it is displayed and switch the two rendering buffers, preparing next
317 *****************************************************************************/
318 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
323 /*****************************************************************************
324 * RemoveAllVout: destroy all the child video output threads
325 *****************************************************************************/
326 static void RemoveAllVout( vout_thread_t *p_vout )
328 while( p_vout->p_sys->i_clones )
330 --p_vout->p_sys->i_clones;
332 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_clones ], NULL );