1 /*****************************************************************************
2 * wall.c : Wall video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: wall.c,v 1.6 2002/01/04 14:01:34 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() */
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 wall 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( "wall" )
58 vout_getfunctions( &p_module->p_functions->vout );
61 MODULE_DEACTIVATE_START
62 MODULE_DEACTIVATE_STOP
64 /*****************************************************************************
65 * vout_sys_t: Wall video output method descriptor
66 *****************************************************************************
67 * This structure is part of the video output thread descriptor.
68 * It describes the Wall specific properties of an output thread.
69 *****************************************************************************/
70 typedef struct vout_sys_s
79 struct vout_thread_s *p_vout;
84 /*****************************************************************************
86 *****************************************************************************/
87 static int vout_Probe ( probedata_t *p_data );
88 static int vout_Create ( vout_thread_t * );
89 static int vout_Init ( vout_thread_t * );
90 static void vout_End ( vout_thread_t * );
91 static void vout_Destroy ( vout_thread_t * );
92 static int vout_Manage ( vout_thread_t * );
93 static void vout_Render ( vout_thread_t *, struct picture_s * );
94 static void vout_Display ( vout_thread_t *, struct picture_s * );
96 static void RemoveAllVout ( vout_thread_t *p_vout );
98 /*****************************************************************************
99 * Functions exported as capabilities. They are declared as static so that
100 * we don't pollute the namespace too much.
101 *****************************************************************************/
102 static void vout_getfunctions( function_list_t * p_function_list )
104 p_function_list->pf_probe = vout_Probe;
105 p_function_list->functions.vout.pf_create = vout_Create;
106 p_function_list->functions.vout.pf_init = vout_Init;
107 p_function_list->functions.vout.pf_end = vout_End;
108 p_function_list->functions.vout.pf_destroy = vout_Destroy;
109 p_function_list->functions.vout.pf_manage = vout_Manage;
110 p_function_list->functions.vout.pf_render = vout_Render;
111 p_function_list->functions.vout.pf_display = vout_Display;
112 p_function_list->functions.vout.pf_setpalette = NULL;
115 /*****************************************************************************
116 * intf_Probe: return a score
117 *****************************************************************************/
118 static int vout_Probe( probedata_t *p_data )
123 /*****************************************************************************
124 * vout_Create: allocates Wall video thread output method
125 *****************************************************************************
126 * This function allocates and initializes a Wall vout method.
127 *****************************************************************************/
128 static int vout_Create( vout_thread_t *p_vout )
130 /* Allocate structure */
131 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
132 if( p_vout->p_sys == NULL )
134 intf_ErrMsg("error: %s", strerror(ENOMEM) );
138 p_vout->p_sys->i_col = 3;
139 p_vout->p_sys->i_row = 3;
141 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_row *
142 p_vout->p_sys->i_col *
143 sizeof(struct vout_list_s) );
144 if( p_vout->p_sys->pp_vout == NULL )
146 intf_ErrMsg("error: %s", strerror(ENOMEM) );
147 free( p_vout->p_sys );
155 /*****************************************************************************
156 * vout_Init: initialize Wall video thread output method
157 *****************************************************************************/
158 static int vout_Init( vout_thread_t *p_vout )
160 int i_index, i_row, i_col, i_width, i_height;
164 I_OUTPUTPICTURES = 0;
166 /* Initialize the output structure */
167 p_vout->output.i_chroma = p_vout->render.i_chroma;
168 p_vout->output.i_width = p_vout->render.i_width;
169 p_vout->output.i_height = p_vout->render.i_height;
170 p_vout->output.i_aspect = p_vout->render.i_aspect;
172 /* Try to open the real video output */
173 psz_filter = main_GetPszVariable( VOUT_FILTER_VAR, NULL );
174 main_PutPszVariable( VOUT_FILTER_VAR, "" );
176 intf_WarnMsg( 1, "filter: spawning the real video outputs" );
178 p_vout->p_sys->i_vout = 0;
180 /* FIXME: use bresenham instead of those ugly divisions */
181 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
183 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
185 if( i_col + 1 < p_vout->p_sys->i_col )
187 i_width = ( p_vout->render.i_width
188 / p_vout->p_sys->i_col ) & ~0x1;
192 i_width = p_vout->render.i_width
193 - ( ( p_vout->render.i_width
194 / p_vout->p_sys->i_col ) & ~0x1 ) * i_col;
197 if( i_row + 1 < p_vout->p_sys->i_row )
199 i_height = ( p_vout->render.i_height
200 / p_vout->p_sys->i_row ) & ~0x3;
204 i_height = p_vout->render.i_height
205 - ( ( p_vout->render.i_height
206 / p_vout->p_sys->i_row ) & ~0x3 ) * i_row;
209 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout =
210 vout_CreateThread( NULL, i_width, i_height,
211 p_vout->render.i_chroma,
212 p_vout->render.i_aspect
213 * p_vout->render.i_height / i_height
214 * i_width / p_vout->render.i_width );
215 if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout == NULL )
217 intf_ErrMsg( "vout error: failed to get %ix%i vout threads",
218 p_vout->p_sys->i_col, p_vout->p_sys->i_row );
219 RemoveAllVout( p_vout );
223 p_vout->p_sys->i_vout++;
227 main_PutPszVariable( VOUT_FILTER_VAR, psz_filter );
229 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
234 /*****************************************************************************
235 * vout_End: terminate Wall video thread output method
236 *****************************************************************************/
237 static void vout_End( vout_thread_t *p_vout )
241 /* Free the fake output buffers we allocated */
242 for( i_index = I_OUTPUTPICTURES ; i_index ; )
245 free( PP_OUTPUTPICTURE[ i_index ]->p_data );
249 /*****************************************************************************
250 * vout_Destroy: destroy Wall video thread output method
251 *****************************************************************************
252 * Terminate an output method created by WallCreateOutputMethod
253 *****************************************************************************/
254 static void vout_Destroy( vout_thread_t *p_vout )
256 RemoveAllVout( p_vout );
258 free( p_vout->p_sys->pp_vout );
259 free( p_vout->p_sys );
262 /*****************************************************************************
263 * vout_Manage: handle Wall events
264 *****************************************************************************
265 * This function should be called regularly by video output thread. It manages
266 * console events. It returns a non null value on error.
267 *****************************************************************************/
268 static int vout_Manage( vout_thread_t *p_vout )
273 /*****************************************************************************
274 * vout_Render: displays previously rendered output
275 *****************************************************************************
276 * This function send the currently rendered image to Wall image, waits
277 * until it is displayed and switch the two rendering buffers, preparing next
279 *****************************************************************************/
280 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
282 picture_t *p_outpic = NULL;
283 int i_col, i_row, i_vout, i_plane;
284 int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
288 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
290 pi_top_skip[i_plane] = 0;
293 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
295 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
297 pi_left_skip[i_plane] = 0;
300 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
303 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
307 if( p_vout->b_die || p_vout->b_error )
310 p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
314 msleep( VOUT_OUTMEM_SLEEP );
317 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
318 p_outpic, p_pic->date );
319 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
322 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
324 u8 *p_in, *p_in_end, *p_out;
325 int i_in_pitch = p_pic->p[i_plane].i_pitch;
326 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
328 p_in = p_pic->p[i_plane].p_pixels
329 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
331 p_in_end = p_in + p_outpic->p[i_plane].i_lines
332 * p_pic->p[i_plane].i_pitch;
334 p_out = p_outpic->p[i_plane].p_pixels;
336 while( p_in < p_in_end )
338 FAST_MEMCPY( p_out, p_in, i_out_pitch );
340 p_out += i_out_pitch;
343 pi_left_skip[i_plane] += p_outpic->p[i_plane].i_pitch;
346 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
348 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
354 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
356 pi_top_skip[i_plane] += p_outpic->p[i_plane].i_lines
357 * p_pic->p[i_plane].i_pitch;
362 /*****************************************************************************
363 * vout_Display: displays previously rendered output
364 *****************************************************************************
365 * This function send the currently rendered image to Invert image, waits
366 * until it is displayed and switch the two rendering buffers, preparing next
368 *****************************************************************************/
369 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
374 static void RemoveAllVout( vout_thread_t *p_vout )
376 while( p_vout->p_sys->i_vout )
378 --p_vout->p_sys->i_vout;
380 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout, NULL );