1 /*****************************************************************************
2 * clone.c : Clone video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002, 2003 VideoLAN
5 * $Id: clone.c,v 1.5 2003/01/17 16:18:03 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 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
33 #include "filter_common.h"
35 /*****************************************************************************
37 *****************************************************************************/
38 static int Create ( vlc_object_t * );
39 static void Destroy ( vlc_object_t * );
41 static int Init ( vout_thread_t * );
42 static void End ( vout_thread_t * );
43 static void Render ( vout_thread_t *, picture_t * );
45 static void RemoveAllVout ( vout_thread_t *p_vout );
47 static int SendEvents( vlc_object_t *, char const *,
48 vlc_value_t, vlc_value_t, void * );
50 /*****************************************************************************
52 *****************************************************************************/
53 #define COUNT_TEXT N_("Number of clones")
54 #define COUNT_LONGTEXT N_("Select the number of video windows in which to "\
58 add_category_hint( N_("Miscellaneous"), NULL );
59 add_integer( "clone-count", 2, NULL, COUNT_TEXT, COUNT_LONGTEXT );
60 set_description( _("image clone video module") );
61 set_capability( "video filter", 0 );
62 add_shortcut( "clone" );
63 set_callbacks( Create, Destroy );
66 /*****************************************************************************
67 * vout_sys_t: Clone video output method descriptor
68 *****************************************************************************
69 * This structure is part of the video output thread descriptor.
70 * It describes the Clone specific properties of an output thread.
71 *****************************************************************************/
75 vout_thread_t **pp_vout;
78 /*****************************************************************************
79 * Create: allocates Clone video thread output method
80 *****************************************************************************
81 * This function allocates and initializes a Clone vout method.
82 *****************************************************************************/
83 static int Create( vlc_object_t *p_this )
85 vout_thread_t *p_vout = (vout_thread_t *)p_this;
87 /* Allocate structure */
88 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
89 if( p_vout->p_sys == NULL )
91 msg_Err( p_vout, "out of memory" );
95 p_vout->pf_init = Init;
97 p_vout->pf_manage = NULL;
98 p_vout->pf_render = Render;
99 p_vout->pf_display = NULL;
101 /* Look what method was requested */
102 p_vout->p_sys->i_clones = config_GetInt( p_vout, "clone-count" );
104 p_vout->p_sys->i_clones = __MAX( 1, __MIN( 99, p_vout->p_sys->i_clones ) );
106 msg_Dbg( p_vout, "spawning %i clone(s)", p_vout->p_sys->i_clones );
108 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_clones *
109 sizeof(vout_thread_t *) );
110 if( p_vout->p_sys->pp_vout == NULL )
112 msg_Err( p_vout, "out of memory" );
113 free( p_vout->p_sys );
120 /*****************************************************************************
121 * Init: initialize Clone video thread output method
122 *****************************************************************************/
123 static int Init( vout_thread_t *p_vout )
128 I_OUTPUTPICTURES = 0;
130 /* Initialize the output structure */
131 p_vout->output.i_chroma = p_vout->render.i_chroma;
132 p_vout->output.i_width = p_vout->render.i_width;
133 p_vout->output.i_height = p_vout->render.i_height;
134 p_vout->output.i_aspect = p_vout->render.i_aspect;
136 /* Try to open the real video output */
137 msg_Dbg( p_vout, "spawning the real video outputs" );
139 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
141 p_vout->p_sys->pp_vout[ i_vout ] = vout_Create( p_vout,
142 p_vout->render.i_width, p_vout->render.i_height,
143 p_vout->render.i_chroma, p_vout->render.i_aspect );
144 if( p_vout->p_sys->pp_vout[ i_vout ] == NULL )
146 msg_Err( p_vout, "failed to clone %i vout threads",
147 p_vout->p_sys->i_clones );
148 p_vout->p_sys->i_clones = i_vout;
149 RemoveAllVout( p_vout );
152 ADD_CALLBACKS( p_vout->p_sys->pp_vout[ i_vout ], SendEvents );
155 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
160 /*****************************************************************************
161 * End: terminate Clone video thread output method
162 *****************************************************************************/
163 static void End( vout_thread_t *p_vout )
167 /* Free the fake output buffers we allocated */
168 for( i_index = I_OUTPUTPICTURES ; i_index ; )
171 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
175 /*****************************************************************************
176 * Destroy: destroy Clone video thread output method
177 *****************************************************************************
178 * Terminate an output method created by CloneCreateOutputMethod
179 *****************************************************************************/
180 static void Destroy( vlc_object_t *p_this )
182 vout_thread_t *p_vout = (vout_thread_t *)p_this;
184 RemoveAllVout( p_vout );
186 free( p_vout->p_sys->pp_vout );
187 free( p_vout->p_sys );
190 /*****************************************************************************
191 * Render: displays previously rendered output
192 *****************************************************************************
193 * This function send the currently rendered image to Clone image, waits
194 * until it is displayed and switch the two rendering buffers, preparing next
196 *****************************************************************************/
197 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
199 picture_t *p_outpic = NULL;
202 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
205 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ], 0, 0, 0 )
208 if( p_vout->b_die || p_vout->b_error )
211 p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
215 msleep( VOUT_OUTMEM_SLEEP );
218 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ],
219 p_outpic, p_pic->date );
220 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
222 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
224 uint8_t *p_in, *p_in_end, *p_out;
225 int i_in_pitch = p_pic->p[i_plane].i_pitch;
226 const int i_out_pitch = p_outpic->p[i_plane].i_pitch;
227 const int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
229 p_in = p_pic->p[i_plane].p_pixels;
230 p_out = p_outpic->p[i_plane].p_pixels;
232 if( i_in_pitch == i_copy_pitch
233 && i_out_pitch == i_copy_pitch )
235 p_vout->p_vlc->pf_memcpy( p_out, p_in, i_in_pitch
236 * p_outpic->p[i_plane].i_lines );
240 p_in_end = p_in + i_in_pitch * p_outpic->p[i_plane].i_lines;
242 while( p_in < p_in_end )
244 p_vout->p_vlc->pf_memcpy( p_out, p_in, i_copy_pitch );
246 p_out += i_out_pitch;
251 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
252 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
256 /*****************************************************************************
257 * RemoveAllVout: destroy all the child video output threads
258 *****************************************************************************/
259 static void RemoveAllVout( vout_thread_t *p_vout )
261 while( p_vout->p_sys->i_clones )
263 --p_vout->p_sys->i_clones;
264 DEL_CALLBACKS( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones],
266 vout_Destroy( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones] );
270 /*****************************************************************************
271 * SendEvents: forward mouse and keyboard events to the parent p_vout
272 *****************************************************************************/
273 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
274 vlc_value_t oldval, vlc_value_t newval, void *p_data )
276 var_Set( (vlc_object_t *)p_data, psz_var, newval );