1 /*****************************************************************************
2 * clone.c : Clone video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: clone.c,v 1.1 2002/08/04 17:23:43 sam 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 /*****************************************************************************
38 *****************************************************************************/
39 static int Create ( vlc_object_t * );
40 static void Destroy ( vlc_object_t * );
42 static int Init ( vout_thread_t * );
43 static void End ( vout_thread_t * );
44 static void Render ( vout_thread_t *, picture_t * );
46 static void RemoveAllVout ( vout_thread_t *p_vout );
48 /*****************************************************************************
50 *****************************************************************************/
51 #define COUNT_TEXT N_("Number of clones")
52 #define COUNT_LONGTEXT N_("Select the number of video windows in which to "\
56 add_category_hint( N_("Miscellaneous"), NULL );
57 add_integer( "clone-count", 2, NULL, COUNT_TEXT, COUNT_LONGTEXT );
58 set_description( _("image clone video module") );
59 set_capability( "video filter", 0 );
60 add_shortcut( "clone" );
61 set_callbacks( Create, Destroy );
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 *****************************************************************************/
73 vout_thread_t **pp_vout;
76 /*****************************************************************************
77 * Create: allocates Clone video thread output method
78 *****************************************************************************
79 * This function allocates and initializes a Clone vout method.
80 *****************************************************************************/
81 static int Create( vlc_object_t *p_this )
83 vout_thread_t *p_vout = (vout_thread_t *)p_this;
85 /* Allocate structure */
86 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
87 if( p_vout->p_sys == NULL )
89 msg_Err( p_vout, "out of memory" );
93 p_vout->pf_init = Init;
95 p_vout->pf_manage = NULL;
96 p_vout->pf_render = Render;
97 p_vout->pf_display = NULL;
99 /* Look what method was requested */
100 p_vout->p_sys->i_clones = config_GetInt( p_vout, "clone-count" );
102 p_vout->p_sys->i_clones = __MAX( 1, __MIN( 99, p_vout->p_sys->i_clones ) );
104 msg_Dbg( p_vout, "spawning %i clone(s)", p_vout->p_sys->i_clones );
106 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_clones *
107 sizeof(vout_thread_t *) );
108 if( p_vout->p_sys->pp_vout == NULL )
110 msg_Err( p_vout, "out of memory" );
111 free( p_vout->p_sys );
118 /*****************************************************************************
119 * Init: initialize Clone video thread output method
120 *****************************************************************************/
121 static int Init( vout_thread_t *p_vout )
126 I_OUTPUTPICTURES = 0;
128 /* Initialize the output structure */
129 p_vout->output.i_chroma = p_vout->render.i_chroma;
130 p_vout->output.i_width = p_vout->render.i_width;
131 p_vout->output.i_height = p_vout->render.i_height;
132 p_vout->output.i_aspect = p_vout->render.i_aspect;
134 /* Try to open the real video output */
135 msg_Dbg( p_vout, "spawning the real video outputs" );
137 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
139 p_vout->p_sys->pp_vout[ i_vout ] =
140 vout_CreateThread( p_vout,
141 p_vout->render.i_width, p_vout->render.i_height,
142 p_vout->render.i_chroma, p_vout->render.i_aspect );
143 if( p_vout->p_sys->pp_vout[ i_vout ] == NULL )
145 msg_Err( p_vout, "failed to clone %i vout threads",
146 p_vout->p_sys->i_clones );
147 p_vout->p_sys->i_clones = i_vout;
148 RemoveAllVout( p_vout );
153 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
158 /*****************************************************************************
159 * End: terminate Clone video thread output method
160 *****************************************************************************/
161 static void End( vout_thread_t *p_vout )
165 /* Free the fake output buffers we allocated */
166 for( i_index = I_OUTPUTPICTURES ; i_index ; )
169 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
173 /*****************************************************************************
174 * Destroy: destroy Clone video thread output method
175 *****************************************************************************
176 * Terminate an output method created by CloneCreateOutputMethod
177 *****************************************************************************/
178 static void Destroy( vlc_object_t *p_this )
180 vout_thread_t *p_vout = (vout_thread_t *)p_this;
182 RemoveAllVout( p_vout );
184 free( p_vout->p_sys->pp_vout );
185 free( p_vout->p_sys );
188 /*****************************************************************************
189 * Render: displays previously rendered output
190 *****************************************************************************
191 * This function send the currently rendered image to Clone image, waits
192 * until it is displayed and switch the two rendering buffers, preparing next
194 *****************************************************************************/
195 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
197 picture_t *p_outpic = NULL;
200 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
203 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ], 0, 0, 0 )
206 if( p_vout->b_die || p_vout->b_error )
209 p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
213 msleep( VOUT_OUTMEM_SLEEP );
216 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ],
217 p_outpic, p_pic->date );
218 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
220 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
222 u8 *p_in, *p_in_end, *p_out;
223 int i_in_pitch = p_pic->p[i_plane].i_pitch;
224 const int i_out_pitch = p_outpic->p[i_plane].i_pitch;
226 p_in = p_pic->p[i_plane].p_pixels;
228 p_in_end = p_in + p_outpic->p[i_plane].i_lines
229 * p_pic->p[i_plane].i_pitch;
231 p_out = p_outpic->p[i_plane].p_pixels;
233 while( p_in < p_in_end )
235 p_vout->p_vlc->pf_memcpy( p_out, p_in, i_out_pitch );
237 p_out += i_out_pitch;
241 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
242 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
246 /*****************************************************************************
247 * RemoveAllVout: destroy all the child video output threads
248 *****************************************************************************/
249 static void RemoveAllVout( vout_thread_t *p_vout )
251 while( p_vout->p_sys->i_clones )
253 --p_vout->p_sys->i_clones;
254 vout_DestroyThread( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones] );