1 /*****************************************************************************
2 * wall.c : Wall video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001 VideoLAN
5 * $Id: wall.c,v 1.3 2001/12/30 07:09:55 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
75 struct vout_thread_s **pp_vout;
79 /*****************************************************************************
81 *****************************************************************************/
82 static int vout_Probe ( probedata_t *p_data );
83 static int vout_Create ( vout_thread_t * );
84 static int vout_Init ( vout_thread_t * );
85 static void vout_End ( vout_thread_t * );
86 static void vout_Destroy ( vout_thread_t * );
87 static int vout_Manage ( vout_thread_t * );
88 static void vout_Display ( vout_thread_t *, struct picture_s * );
90 static void RemoveAllVout ( vout_thread_t *p_vout );
92 /*****************************************************************************
93 * Functions exported as capabilities. They are declared as static so that
94 * we don't pollute the namespace too much.
95 *****************************************************************************/
96 static void vout_getfunctions( function_list_t * p_function_list )
98 p_function_list->pf_probe = vout_Probe;
99 p_function_list->functions.vout.pf_create = vout_Create;
100 p_function_list->functions.vout.pf_init = vout_Init;
101 p_function_list->functions.vout.pf_end = vout_End;
102 p_function_list->functions.vout.pf_destroy = vout_Destroy;
103 p_function_list->functions.vout.pf_manage = vout_Manage;
104 p_function_list->functions.vout.pf_display = vout_Display;
105 p_function_list->functions.vout.pf_setpalette = NULL;
108 /*****************************************************************************
109 * intf_Probe: return a score
110 *****************************************************************************/
111 static int vout_Probe( probedata_t *p_data )
116 /*****************************************************************************
117 * vout_Create: allocates Wall video thread output method
118 *****************************************************************************
119 * This function allocates and initializes a Wall vout method.
120 *****************************************************************************/
121 static int vout_Create( vout_thread_t *p_vout )
123 /* Allocate structure */
124 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
125 if( p_vout->p_sys == NULL )
127 intf_ErrMsg("error: %s", strerror(ENOMEM) );
131 p_vout->p_sys->i_col = 2;
132 p_vout->p_sys->i_row = 3;
134 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_row *
135 p_vout->p_sys->i_col *
136 sizeof(vout_thread_t*) );
137 if( p_vout->p_sys->pp_vout == NULL )
139 intf_ErrMsg("error: %s", strerror(ENOMEM) );
140 free( p_vout->p_sys );
148 /*****************************************************************************
149 * vout_Init: initialize Wall video thread output method
150 *****************************************************************************/
151 static int vout_Init( vout_thread_t *p_vout )
157 I_OUTPUTPICTURES = 0;
159 /* Initialize the output structure */
160 switch( p_vout->render.i_chroma )
162 case YUV_420_PICTURE:
163 p_vout->output.i_chroma = p_vout->render.i_chroma;
164 p_vout->output.i_width = p_vout->render.i_width;
165 p_vout->output.i_height = p_vout->render.i_height;
166 p_vout->output.i_aspect = p_vout->render.i_aspect;
170 return( 0 ); /* unknown chroma */
174 /* Try to open the real video output */
175 psz_filter = main_GetPszVariable( VOUT_FILTER_VAR, NULL );
176 main_PutPszVariable( VOUT_FILTER_VAR, "" );
178 intf_WarnMsg( 1, "filter: spawning the real video outputs" );
180 for( p_vout->p_sys->i_vout = 0;
181 p_vout->p_sys->i_vout < p_vout->p_sys->i_row * p_vout->p_sys->i_col;
182 p_vout->p_sys->i_vout++ )
184 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ] =
185 vout_CreateThread( NULL,
186 p_vout->render.i_width / p_vout->p_sys->i_col,
187 p_vout->render.i_height / p_vout->p_sys->i_row,
188 p_vout->render.i_chroma,
189 p_vout->render.i_aspect * p_vout->p_sys->i_row
190 / p_vout->p_sys->i_col );
191 if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ] == NULL )
193 intf_ErrMsg( "vout error: failed to get %ix%i vout threads",
194 p_vout->p_sys->i_col, p_vout->p_sys->i_row );
195 RemoveAllVout( p_vout );
200 main_PutPszVariable( VOUT_FILTER_VAR, psz_filter );
202 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
207 /*****************************************************************************
208 * vout_End: terminate Wall video thread output method
209 *****************************************************************************/
210 static void vout_End( vout_thread_t *p_vout )
214 /* Free the fake output buffers we allocated */
215 for( i_index = I_OUTPUTPICTURES ; i_index ; )
218 free( PP_OUTPUTPICTURE[ i_index ]->planes[ 0 ].p_data );
222 /*****************************************************************************
223 * vout_Destroy: destroy Wall video thread output method
224 *****************************************************************************
225 * Terminate an output method created by WallCreateOutputMethod
226 *****************************************************************************/
227 static void vout_Destroy( vout_thread_t *p_vout )
229 RemoveAllVout( p_vout );
231 free( p_vout->p_sys->pp_vout );
232 free( p_vout->p_sys );
235 /*****************************************************************************
236 * vout_Manage: handle Wall events
237 *****************************************************************************
238 * This function should be called regularly by video output thread. It manages
239 * console events. It returns a non null value on error.
240 *****************************************************************************/
241 static int vout_Manage( vout_thread_t *p_vout )
246 /*****************************************************************************
247 * vout_Display: displays previously rendered output
248 *****************************************************************************
249 * This function send the currently rendered image to Wall image, waits
250 * until it is displayed and switch the two rendering buffers, preparing next
252 *****************************************************************************/
253 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
256 int i_col, i_row, i_vout, i_index;
257 mtime_t i_date = mdate() + 50000;
261 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
263 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
266 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ], 0, 0, 0 )
269 if( p_vout->b_die || p_vout->b_error )
271 vout_DestroyPicture( p_vout->p_sys->pp_vout[ i_vout ],
276 msleep( VOUT_OUTMEM_SLEEP );
279 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ],
281 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ],
284 for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
286 FAST_MEMCPY( p_outpic->planes[ i_index ].p_data,
287 p_pic->planes[ i_index ].p_data
288 + p_pic->planes[ i_index ].i_bytes / 2,
289 p_outpic->planes[ i_index ].i_bytes );
292 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ],
294 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ],
302 static void RemoveAllVout( vout_thread_t *p_vout )
304 while( p_vout->p_sys->i_vout )
306 --p_vout->p_sys->i_vout;
307 vout_DestroyThread( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ],