1 /*****************************************************************************
2 * wall.c : Wall video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: wall.c,v 1.22 2002/06/01 18:04:48 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 /*****************************************************************************
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 *****************************************************************************/
45 ADD_CATEGORY_HINT( N_("Miscellaneous"), NULL )
46 ADD_INTEGER ( "wall-cols", 3, NULL, N_("Number of columns"),
47 N_("Select the number of horizontal videowindows in which "
48 "to split the video") )
49 ADD_INTEGER ( "wall-rows", 3, NULL, N_("Number of rows"),
50 N_("Select the number of vertical videowindows in which "
51 "to split the video") )
52 ADD_STRING ( "wall-active", NULL, NULL, N_("Active windows"),
53 N_("comma separated list of active windows, defaults to all") )
57 SET_DESCRIPTION( _("image wall video module") )
58 /* Capability score set to 0 because we don't want to be spawned
59 * as a video output unless explicitly requested to */
60 ADD_CAPABILITY( VOUT, 0 )
61 ADD_SHORTCUT( "wall" )
65 vout_getfunctions( &p_module->p_functions->vout );
68 MODULE_DEACTIVATE_START
69 MODULE_DEACTIVATE_STOP
71 /*****************************************************************************
72 * vout_sys_t: Wall video output method descriptor
73 *****************************************************************************
74 * This structure is part of the video output thread descriptor.
75 * It describes the Wall specific properties of an output thread.
76 *****************************************************************************/
87 vout_thread_t *p_vout;
91 /*****************************************************************************
93 *****************************************************************************/
94 static int vout_Create ( vout_thread_t * );
95 static int vout_Init ( vout_thread_t * );
96 static void vout_End ( vout_thread_t * );
97 static void vout_Destroy ( vout_thread_t * );
98 static int vout_Manage ( vout_thread_t * );
99 static void vout_Render ( vout_thread_t *, picture_t * );
100 static void vout_Display ( vout_thread_t *, picture_t * );
102 static void RemoveAllVout ( vout_thread_t *p_vout );
104 /*****************************************************************************
105 * Functions exported as capabilities. They are declared as static so that
106 * we don't pollute the namespace too much.
107 *****************************************************************************/
108 static void vout_getfunctions( function_list_t * p_function_list )
110 p_function_list->functions.vout.pf_create = vout_Create;
111 p_function_list->functions.vout.pf_init = vout_Init;
112 p_function_list->functions.vout.pf_end = vout_End;
113 p_function_list->functions.vout.pf_destroy = vout_Destroy;
114 p_function_list->functions.vout.pf_manage = vout_Manage;
115 p_function_list->functions.vout.pf_render = vout_Render;
116 p_function_list->functions.vout.pf_display = vout_Display;
119 /*****************************************************************************
120 * vout_Create: allocates Wall video thread output method
121 *****************************************************************************
122 * This function allocates and initializes a Wall vout method.
123 *****************************************************************************/
124 static int vout_Create( vout_thread_t *p_vout )
126 char *psz_method, *psz_tmp, *psz_method_tmp;
129 /* Allocate structure */
130 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
131 if( p_vout->p_sys == NULL )
133 msg_Err( p_vout, "out of memory" );
137 /* Look what method was requested */
138 p_vout->p_sys->i_col = config_GetInt( p_vout, "wall-cols" );
139 p_vout->p_sys->i_row = config_GetInt( p_vout, "wall-rows" );
141 p_vout->p_sys->i_col = __MAX( 1, __MIN( 15, p_vout->p_sys->i_col ) );
142 p_vout->p_sys->i_row = __MAX( 1, __MIN( 15, p_vout->p_sys->i_row ) );
144 msg_Dbg( p_vout, "opening a %i x %i wall",
145 p_vout->p_sys->i_col, p_vout->p_sys->i_row );
147 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_row *
148 p_vout->p_sys->i_col *
149 sizeof(struct vout_list_s) );
150 if( p_vout->p_sys->pp_vout == NULL )
152 msg_Err( p_vout, "out of memory" );
153 free( p_vout->p_sys );
157 psz_method_tmp = psz_method = config_GetPsz( p_vout, "wall-active" );
159 /* If no trailing vout are specified, take them all */
160 if( psz_method == NULL )
162 for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
165 p_vout->p_sys->pp_vout[i_vout].b_active = 1;
168 /* If trailing vout are specified, activate only the requested ones */
171 for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
174 p_vout->p_sys->pp_vout[i_vout].b_active = 0;
179 psz_tmp = psz_method;
180 while( *psz_tmp && *psz_tmp != ',' )
188 i_vout = atoi( psz_method );
189 psz_method = psz_tmp + 1;
193 i_vout = atoi( psz_method );
194 psz_method = psz_tmp;
198 i_vout < p_vout->p_sys->i_row * p_vout->p_sys->i_col )
200 p_vout->p_sys->pp_vout[i_vout].b_active = 1;
205 free( psz_method_tmp );
210 /*****************************************************************************
211 * vout_Init: initialize Wall video thread output method
212 *****************************************************************************/
213 static int vout_Init( vout_thread_t *p_vout )
215 int i_index, i_row, i_col, i_width, i_height;
219 I_OUTPUTPICTURES = 0;
221 /* Initialize the output structure */
222 p_vout->output.i_chroma = p_vout->render.i_chroma;
223 p_vout->output.i_width = p_vout->render.i_width;
224 p_vout->output.i_height = p_vout->render.i_height;
225 p_vout->output.i_aspect = p_vout->render.i_aspect;
227 /* Try to open the real video output */
228 psz_filter = config_GetPsz( p_vout, "filter" );
229 config_PutPsz( p_vout, "filter", NULL );
231 msg_Dbg( p_vout, "spawning the real video outputs" );
233 p_vout->p_sys->i_vout = 0;
235 /* FIXME: use bresenham instead of those ugly divisions */
236 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
238 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
240 if( i_col + 1 < p_vout->p_sys->i_col )
242 i_width = ( p_vout->render.i_width
243 / p_vout->p_sys->i_col ) & ~0x1;
247 i_width = p_vout->render.i_width
248 - ( ( p_vout->render.i_width
249 / p_vout->p_sys->i_col ) & ~0x1 ) * i_col;
252 if( i_row + 1 < p_vout->p_sys->i_row )
254 i_height = ( p_vout->render.i_height
255 / p_vout->p_sys->i_row ) & ~0x3;
259 i_height = p_vout->render.i_height
260 - ( ( p_vout->render.i_height
261 / p_vout->p_sys->i_row ) & ~0x3 ) * i_row;
264 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_width = i_width;
265 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_height = i_height;
267 if( !p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active )
269 p_vout->p_sys->i_vout++;
273 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout =
274 vout_CreateThread( p_vout, i_width, i_height,
275 p_vout->render.i_chroma,
276 p_vout->render.i_aspect
277 * p_vout->render.i_height / i_height
278 * i_width / p_vout->render.i_width );
279 if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout == NULL )
281 msg_Err( p_vout, "failed to get %ix%i vout threads",
282 p_vout->p_sys->i_col, p_vout->p_sys->i_row );
283 RemoveAllVout( p_vout );
284 config_PutPsz( p_vout, "filter", psz_filter );
285 if( psz_filter ) free( psz_filter );
289 p_vout->p_sys->i_vout++;
293 config_PutPsz( p_vout, "filter", psz_filter );
294 if( psz_filter ) free( psz_filter );
296 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
301 /*****************************************************************************
302 * vout_End: terminate Wall video thread output method
303 *****************************************************************************/
304 static void vout_End( vout_thread_t *p_vout )
308 /* Free the fake output buffers we allocated */
309 for( i_index = I_OUTPUTPICTURES ; i_index ; )
312 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
316 /*****************************************************************************
317 * vout_Destroy: destroy Wall video thread output method
318 *****************************************************************************
319 * Terminate an output method created by WallCreateOutputMethod
320 *****************************************************************************/
321 static void vout_Destroy( vout_thread_t *p_vout )
323 RemoveAllVout( p_vout );
325 free( p_vout->p_sys->pp_vout );
326 free( p_vout->p_sys );
329 /*****************************************************************************
330 * vout_Manage: handle Wall events
331 *****************************************************************************
332 * This function should be called regularly by video output thread. It manages
333 * console events. It returns a non null value on error.
334 *****************************************************************************/
335 static int vout_Manage( vout_thread_t *p_vout )
340 /*****************************************************************************
341 * vout_Render: displays previously rendered output
342 *****************************************************************************
343 * This function send the currently rendered image to Wall image, waits
344 * until it is displayed and switch the two rendering buffers, preparing next
346 *****************************************************************************/
347 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
349 picture_t *p_outpic = NULL;
350 int i_col, i_row, i_vout, i_plane;
351 int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
355 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
357 pi_top_skip[i_plane] = 0;
360 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
362 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
364 pi_left_skip[i_plane] = 0;
367 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
369 if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
371 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
373 pi_left_skip[i_plane] +=
374 p_vout->p_sys->pp_vout[ i_vout ].i_width
375 * p_pic->p[i_plane].i_pitch / p_vout->output.i_width;
382 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
386 if( p_vout->b_die || p_vout->b_error )
389 p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
393 msleep( VOUT_OUTMEM_SLEEP );
396 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
397 p_outpic, p_pic->date );
398 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
401 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
403 u8 *p_in, *p_in_end, *p_out;
404 int i_in_pitch = p_pic->p[i_plane].i_pitch;
405 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
407 p_in = p_pic->p[i_plane].p_pixels
408 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
410 p_in_end = p_in + p_outpic->p[i_plane].i_lines
411 * p_pic->p[i_plane].i_pitch;
413 p_out = p_outpic->p[i_plane].p_pixels;
415 while( p_in < p_in_end )
417 p_vout->p_vlc->pf_memcpy( p_out, p_in, i_out_pitch );
419 p_out += i_out_pitch;
422 pi_left_skip[i_plane] += i_out_pitch;
425 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
427 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
433 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
435 pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout ].i_height
436 * p_pic->p[i_plane].i_lines
437 / p_vout->output.i_height
438 * p_pic->p[i_plane].i_pitch;
443 /*****************************************************************************
444 * vout_Display: displays previously rendered output
445 *****************************************************************************
446 * This function send the currently rendered image to Invert image, waits
447 * until it is displayed and switch the two rendering buffers, preparing next
449 *****************************************************************************/
450 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
455 /*****************************************************************************
456 * RemoveAllVout: destroy all the child video output threads
457 *****************************************************************************/
458 static void RemoveAllVout( vout_thread_t *p_vout )
460 while( p_vout->p_sys->i_vout )
462 --p_vout->p_sys->i_vout;
463 if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active )
466 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout );