1 /*****************************************************************************
2 * clone.c : Clone video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: clone.c,v 1.3 2002/11/28 17:35:00 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 /*****************************************************************************
49 *****************************************************************************/
50 #define COUNT_TEXT N_("Number of clones")
51 #define COUNT_LONGTEXT N_("Select the number of video windows in which to "\
55 add_category_hint( N_("Miscellaneous"), NULL );
56 add_integer( "clone-count", 2, NULL, COUNT_TEXT, COUNT_LONGTEXT );
57 set_description( _("image clone video module") );
58 set_capability( "video filter", 0 );
59 add_shortcut( "clone" );
60 set_callbacks( Create, Destroy );
63 /*****************************************************************************
64 * vout_sys_t: Clone video output method descriptor
65 *****************************************************************************
66 * This structure is part of the video output thread descriptor.
67 * It describes the Clone specific properties of an output thread.
68 *****************************************************************************/
72 vout_thread_t **pp_vout;
75 /*****************************************************************************
76 * Create: allocates Clone video thread output method
77 *****************************************************************************
78 * This function allocates and initializes a Clone vout method.
79 *****************************************************************************/
80 static int Create( vlc_object_t *p_this )
82 vout_thread_t *p_vout = (vout_thread_t *)p_this;
84 /* Allocate structure */
85 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
86 if( p_vout->p_sys == NULL )
88 msg_Err( p_vout, "out of memory" );
92 p_vout->pf_init = Init;
94 p_vout->pf_manage = NULL;
95 p_vout->pf_render = Render;
96 p_vout->pf_display = NULL;
98 /* Look what method was requested */
99 p_vout->p_sys->i_clones = config_GetInt( p_vout, "clone-count" );
101 p_vout->p_sys->i_clones = __MAX( 1, __MIN( 99, p_vout->p_sys->i_clones ) );
103 msg_Dbg( p_vout, "spawning %i clone(s)", p_vout->p_sys->i_clones );
105 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_clones *
106 sizeof(vout_thread_t *) );
107 if( p_vout->p_sys->pp_vout == NULL )
109 msg_Err( p_vout, "out of memory" );
110 free( p_vout->p_sys );
117 /*****************************************************************************
118 * Init: initialize Clone video thread output method
119 *****************************************************************************/
120 static int Init( vout_thread_t *p_vout )
125 I_OUTPUTPICTURES = 0;
127 /* Initialize the output structure */
128 p_vout->output.i_chroma = p_vout->render.i_chroma;
129 p_vout->output.i_width = p_vout->render.i_width;
130 p_vout->output.i_height = p_vout->render.i_height;
131 p_vout->output.i_aspect = p_vout->render.i_aspect;
133 /* Try to open the real video output */
134 msg_Dbg( p_vout, "spawning the real video outputs" );
136 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
138 p_vout->p_sys->pp_vout[ i_vout ] = vout_Create( p_vout,
139 p_vout->render.i_width, p_vout->render.i_height,
140 p_vout->render.i_chroma, p_vout->render.i_aspect );
141 if( p_vout->p_sys->pp_vout[ i_vout ] == NULL )
143 msg_Err( p_vout, "failed to clone %i vout threads",
144 p_vout->p_sys->i_clones );
145 p_vout->p_sys->i_clones = i_vout;
146 RemoveAllVout( p_vout );
151 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
156 /*****************************************************************************
157 * End: terminate Clone video thread output method
158 *****************************************************************************/
159 static void End( vout_thread_t *p_vout )
163 /* Free the fake output buffers we allocated */
164 for( i_index = I_OUTPUTPICTURES ; i_index ; )
167 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
171 /*****************************************************************************
172 * Destroy: destroy Clone video thread output method
173 *****************************************************************************
174 * Terminate an output method created by CloneCreateOutputMethod
175 *****************************************************************************/
176 static void Destroy( vlc_object_t *p_this )
178 vout_thread_t *p_vout = (vout_thread_t *)p_this;
180 RemoveAllVout( p_vout );
182 free( p_vout->p_sys->pp_vout );
183 free( p_vout->p_sys );
186 /*****************************************************************************
187 * Render: displays previously rendered output
188 *****************************************************************************
189 * This function send the currently rendered image to Clone image, waits
190 * until it is displayed and switch the two rendering buffers, preparing next
192 *****************************************************************************/
193 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
195 picture_t *p_outpic = NULL;
198 for( i_vout = 0; i_vout < p_vout->p_sys->i_clones; i_vout++ )
201 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ], 0, 0, 0 )
204 if( p_vout->b_die || p_vout->b_error )
207 p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
211 msleep( VOUT_OUTMEM_SLEEP );
214 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ],
215 p_outpic, p_pic->date );
216 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
218 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
220 u8 *p_in, *p_in_end, *p_out;
221 int i_in_pitch = p_pic->p[i_plane].i_pitch;
222 const int i_out_pitch = p_outpic->p[i_plane].i_pitch;
224 p_in = p_pic->p[i_plane].p_pixels;
226 p_in_end = p_in + p_outpic->p[i_plane].i_lines
227 * p_pic->p[i_plane].i_pitch;
229 p_out = p_outpic->p[i_plane].p_pixels;
231 while( p_in < p_in_end )
233 p_vout->p_vlc->pf_memcpy( p_out, p_in, i_out_pitch );
235 p_out += i_out_pitch;
239 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
240 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ], p_outpic );
244 /*****************************************************************************
245 * RemoveAllVout: destroy all the child video output threads
246 *****************************************************************************/
247 static void RemoveAllVout( vout_thread_t *p_vout )
249 while( p_vout->p_sys->i_clones )
251 --p_vout->p_sys->i_clones;
252 vout_Destroy( p_vout->p_sys->pp_vout[p_vout->p_sys->i_clones] );