1 /*****************************************************************************
2 * wall.c : Wall video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: wall.c,v 1.5 2002/01/02 14:37:42 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_Display ( vout_thread_t *, struct picture_s * );
95 static void RemoveAllVout ( vout_thread_t *p_vout );
97 /*****************************************************************************
98 * Functions exported as capabilities. They are declared as static so that
99 * we don't pollute the namespace too much.
100 *****************************************************************************/
101 static void vout_getfunctions( function_list_t * p_function_list )
103 p_function_list->pf_probe = vout_Probe;
104 p_function_list->functions.vout.pf_create = vout_Create;
105 p_function_list->functions.vout.pf_init = vout_Init;
106 p_function_list->functions.vout.pf_end = vout_End;
107 p_function_list->functions.vout.pf_destroy = vout_Destroy;
108 p_function_list->functions.vout.pf_manage = vout_Manage;
109 p_function_list->functions.vout.pf_display = vout_Display;
110 p_function_list->functions.vout.pf_setpalette = NULL;
113 /*****************************************************************************
114 * intf_Probe: return a score
115 *****************************************************************************/
116 static int vout_Probe( probedata_t *p_data )
121 /*****************************************************************************
122 * vout_Create: allocates Wall video thread output method
123 *****************************************************************************
124 * This function allocates and initializes a Wall vout method.
125 *****************************************************************************/
126 static int vout_Create( vout_thread_t *p_vout )
128 /* Allocate structure */
129 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
130 if( p_vout->p_sys == NULL )
132 intf_ErrMsg("error: %s", strerror(ENOMEM) );
136 p_vout->p_sys->i_col = 3;
137 p_vout->p_sys->i_row = 2;
139 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_row *
140 p_vout->p_sys->i_col *
141 sizeof(struct vout_list_s) );
142 if( p_vout->p_sys->pp_vout == NULL )
144 intf_ErrMsg("error: %s", strerror(ENOMEM) );
145 free( p_vout->p_sys );
153 /*****************************************************************************
154 * vout_Init: initialize Wall video thread output method
155 *****************************************************************************/
156 static int vout_Init( vout_thread_t *p_vout )
158 int i_index, i_row, i_col, i_width, i_height;
162 I_OUTPUTPICTURES = 0;
164 /* Initialize the output structure */
165 switch( p_vout->render.i_chroma )
172 p_vout->output.i_chroma = p_vout->render.i_chroma;
173 p_vout->output.i_width = p_vout->render.i_width;
174 p_vout->output.i_height = p_vout->render.i_height;
175 p_vout->output.i_aspect = p_vout->render.i_aspect;
179 return( 0 ); /* unknown chroma */
183 /* Try to open the real video output */
184 psz_filter = main_GetPszVariable( VOUT_FILTER_VAR, NULL );
185 main_PutPszVariable( VOUT_FILTER_VAR, "" );
187 intf_WarnMsg( 1, "filter: spawning the real video outputs" );
189 p_vout->p_sys->i_vout = 0;
191 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
193 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
195 if( i_col + 1 < p_vout->p_sys->i_col )
197 i_width = ( p_vout->render.i_width
198 / p_vout->p_sys->i_col ) & ~0xf;
202 i_width = p_vout->render.i_width
203 - ( ( p_vout->render.i_width
204 / p_vout->p_sys->i_col ) & ~0xf ) * i_col;
207 if( i_row + 1 < p_vout->p_sys->i_row )
209 i_height = p_vout->render.i_height / p_vout->p_sys->i_row;
213 i_height = p_vout->render.i_height
214 - p_vout->render.i_height
215 / p_vout->p_sys->i_row * i_row;
218 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout =
219 vout_CreateThread( NULL, i_width, i_height,
220 p_vout->render.i_chroma,
221 p_vout->render.i_aspect
222 * p_vout->render.i_height / i_height
223 * i_width / p_vout->render.i_width );
224 if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout == NULL )
226 intf_ErrMsg( "vout error: failed to get %ix%i vout threads",
227 p_vout->p_sys->i_col, p_vout->p_sys->i_row );
228 RemoveAllVout( p_vout );
232 p_vout->p_sys->i_vout++;
236 main_PutPszVariable( VOUT_FILTER_VAR, psz_filter );
238 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
243 /*****************************************************************************
244 * vout_End: terminate Wall video thread output method
245 *****************************************************************************/
246 static void vout_End( vout_thread_t *p_vout )
250 /* Free the fake output buffers we allocated */
251 for( i_index = I_OUTPUTPICTURES ; i_index ; )
254 free( PP_OUTPUTPICTURE[ i_index ]->planes[ 0 ].p_data );
258 /*****************************************************************************
259 * vout_Destroy: destroy Wall video thread output method
260 *****************************************************************************
261 * Terminate an output method created by WallCreateOutputMethod
262 *****************************************************************************/
263 static void vout_Destroy( vout_thread_t *p_vout )
265 RemoveAllVout( p_vout );
267 free( p_vout->p_sys->pp_vout );
268 free( p_vout->p_sys );
271 /*****************************************************************************
272 * vout_Manage: handle Wall events
273 *****************************************************************************
274 * This function should be called regularly by video output thread. It manages
275 * console events. It returns a non null value on error.
276 *****************************************************************************/
277 static int vout_Manage( vout_thread_t *p_vout )
282 /*****************************************************************************
283 * vout_Display: displays previously rendered output
284 *****************************************************************************
285 * This function send the currently rendered image to Wall image, waits
286 * until it is displayed and switch the two rendering buffers, preparing next
288 *****************************************************************************/
289 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
292 int i_col, i_row, i_vout, i_index;
293 mtime_t i_date = mdate() + 50000;
297 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
299 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
302 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
306 if( p_vout->b_die || p_vout->b_error )
309 p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
313 msleep( VOUT_OUTMEM_SLEEP );
316 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
318 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
321 for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
323 yuv_data_t *p_in, *p_in_end, *p_out;
324 int i_out_bytes, i_offset;
326 /* XXX: beware, it's p_outpic ! */
327 i_out_bytes = p_outpic->planes[ i_index ].i_line_bytes;
329 if( i_col + 1 < p_vout->p_sys->i_col )
331 i_offset = i_out_bytes * i_col;
335 i_offset = p_pic->planes[ i_index ].i_line_bytes
339 p_in = p_pic->planes[ i_index ].p_data
340 + p_pic->planes[ i_index ].i_bytes
341 / p_vout->p_sys->i_row * i_row
344 if( i_row + 1 < p_vout->p_sys->i_row )
347 + p_pic->planes[ i_index ].i_bytes
348 / p_vout->p_sys->i_row;
352 p_in_end = p_pic->planes[ i_index ].p_data
353 + p_pic->planes[ i_index ].i_bytes
357 p_out = p_outpic->planes[ i_index ].p_data;
359 while( p_in < p_in_end )
361 FAST_MEMCPY( p_out, p_in, i_out_bytes );
362 p_in += p_pic->planes[ i_index ].i_line_bytes;
363 p_out += i_out_bytes;
367 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
369 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
377 static void RemoveAllVout( vout_thread_t *p_vout )
379 while( p_vout->p_sys->i_vout )
381 --p_vout->p_sys->i_vout;
383 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout, NULL );