]> git.sesse.net Git - vlc/blob - plugins/filter/wall.c
* ./include/modules_inner.h: replaced _X with __VLC_SYMBOL because _X was
[vlc] / plugins / filter / wall.c
1 /*****************************************************************************
2  * wall.c : Wall video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000, 2001 VideoLAN
5  * $Id: wall.c,v 1.10 2002/01/09 02:01:14 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <errno.h>
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <string.h>
30
31 #include <videolan/vlc.h>
32
33 #include "video.h"
34 #include "video_output.h"
35
36 #include "filter_common.h"
37
38 /*****************************************************************************
39  * Capabilities defined in the other files.
40  *****************************************************************************/
41 static void vout_getfunctions( function_list_t * p_function_list );
42
43 /*****************************************************************************
44  * Build configuration tree.
45  *****************************************************************************/
46 MODULE_CONFIG_START
47 MODULE_CONFIG_STOP
48
49 MODULE_INIT_START
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" )
55 MODULE_INIT_STOP
56
57 MODULE_ACTIVATE_START
58     vout_getfunctions( &p_module->p_functions->vout );
59 MODULE_ACTIVATE_STOP
60
61 MODULE_DEACTIVATE_START
62 MODULE_DEACTIVATE_STOP
63
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
71 {
72     int    i_col;
73     int    i_row;
74     int    i_vout;
75     struct vout_list_s
76     {
77         int i_width;
78         int i_height;
79         struct vout_thread_s *p_vout;
80     } *pp_vout;
81
82 } vout_sys_t;
83
84 /*****************************************************************************
85  * Local prototypes
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 * );
95
96 static void RemoveAllVout  ( vout_thread_t *p_vout );
97
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 )
103 {
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 }
113
114 /*****************************************************************************
115  * intf_Probe: return a score
116  *****************************************************************************/
117 static int vout_Probe( probedata_t *p_data )
118 {
119     return( 0 );
120 }
121
122 /*****************************************************************************
123  * vout_Create: allocates Wall video thread output method
124  *****************************************************************************
125  * This function allocates and initializes a Wall vout method.
126  *****************************************************************************/
127 static int vout_Create( vout_thread_t *p_vout )
128 {
129     /* Allocate structure */
130     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
131     if( p_vout->p_sys == NULL )
132     {
133         intf_ErrMsg("error: %s", strerror(ENOMEM) );
134         return( 1 );
135     }
136
137     p_vout->p_sys->i_col = 6;
138     p_vout->p_sys->i_row = 6;
139
140     p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_row *
141                                      p_vout->p_sys->i_col *
142                                      sizeof(struct vout_list_s) );
143     if( p_vout->p_sys->pp_vout == NULL )
144     {
145         intf_ErrMsg("error: %s", strerror(ENOMEM) );
146         free( p_vout->p_sys );
147         return( 1 );
148     }
149
150
151     return( 0 );
152 }
153
154 /*****************************************************************************
155  * vout_Init: initialize Wall video thread output method
156  *****************************************************************************/
157 static int vout_Init( vout_thread_t *p_vout )
158 {
159     int i_index, i_row, i_col, i_width, i_height;
160     char *psz_filter;
161     picture_t *p_pic;
162     
163     I_OUTPUTPICTURES = 0;
164
165     /* Initialize the output structure */
166     p_vout->output.i_chroma = p_vout->render.i_chroma;
167     p_vout->output.i_width  = p_vout->render.i_width;
168     p_vout->output.i_height = p_vout->render.i_height;
169     p_vout->output.i_aspect = p_vout->render.i_aspect;
170
171     /* Try to open the real video output */
172     psz_filter = main_GetPszVariable( VOUT_FILTER_VAR, NULL );
173     main_PutPszVariable( VOUT_FILTER_VAR, "" );
174
175     intf_WarnMsg( 1, "filter: spawning the real video outputs" );
176
177     p_vout->p_sys->i_vout = 0;
178
179     /* FIXME: use bresenham instead of those ugly divisions */
180     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
181     {
182         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
183         {
184             if( i_col + 1 < p_vout->p_sys->i_col )
185             {
186                 i_width = ( p_vout->render.i_width
187                              / p_vout->p_sys->i_col ) & ~0x1;
188             }
189             else
190             {
191                 i_width = p_vout->render.i_width
192                            - ( ( p_vout->render.i_width
193                                   / p_vout->p_sys->i_col ) & ~0x1 ) * i_col;
194             }
195
196             if( i_row + 1 < p_vout->p_sys->i_row )
197             {
198                 i_height = ( p_vout->render.i_height
199                               / p_vout->p_sys->i_row ) & ~0x3;
200             }
201             else
202             {
203                 i_height = p_vout->render.i_height
204                             - ( ( p_vout->render.i_height
205                                    / p_vout->p_sys->i_row ) & ~0x3 ) * i_row;
206             }
207
208             p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout =
209                 vout_CreateThread( NULL, i_width, i_height,
210                                    p_vout->render.i_chroma,
211                                    p_vout->render.i_aspect
212                                     * p_vout->render.i_height / i_height
213                                     * i_width / p_vout->render.i_width );
214             if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout == NULL )
215             {
216                 intf_ErrMsg( "vout error: failed to get %ix%i vout threads",
217                              p_vout->p_sys->i_col, p_vout->p_sys->i_row );
218                 RemoveAllVout( p_vout );
219                 return 0;
220             }
221
222             p_vout->p_sys->i_vout++;
223         }
224     }
225
226     main_PutPszVariable( VOUT_FILTER_VAR, psz_filter );
227
228     ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
229
230     return( 0 );
231 }
232
233 /*****************************************************************************
234  * vout_End: terminate Wall video thread output method
235  *****************************************************************************/
236 static void vout_End( vout_thread_t *p_vout )
237 {
238     int i_index;
239
240     /* Free the fake output buffers we allocated */
241     for( i_index = I_OUTPUTPICTURES ; i_index ; )
242     {
243         i_index--;
244         free( PP_OUTPUTPICTURE[ i_index ]->p_data );
245     }
246 }
247
248 /*****************************************************************************
249  * vout_Destroy: destroy Wall video thread output method
250  *****************************************************************************
251  * Terminate an output method created by WallCreateOutputMethod
252  *****************************************************************************/
253 static void vout_Destroy( vout_thread_t *p_vout )
254 {
255     RemoveAllVout( p_vout );
256
257     free( p_vout->p_sys->pp_vout );
258     free( p_vout->p_sys );
259 }
260
261 /*****************************************************************************
262  * vout_Manage: handle Wall events
263  *****************************************************************************
264  * This function should be called regularly by video output thread. It manages
265  * console events. It returns a non null value on error.
266  *****************************************************************************/
267 static int vout_Manage( vout_thread_t *p_vout )
268 {
269     return( 0 );
270 }
271
272 /*****************************************************************************
273  * vout_Render: displays previously rendered output
274  *****************************************************************************
275  * This function send the currently rendered image to Wall image, waits
276  * until it is displayed and switch the two rendering buffers, preparing next
277  * frame.
278  *****************************************************************************/
279 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
280 {
281     picture_t *p_outpic = NULL;
282     int i_col, i_row, i_vout, i_plane;
283     int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
284
285     i_vout = 0;
286
287     for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
288     {
289         pi_top_skip[i_plane] = 0;
290     }
291
292     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
293     {
294         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
295         {
296             pi_left_skip[i_plane] = 0;
297         }
298
299         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
300         {
301             while( ( p_outpic =
302                 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
303                                     0, 0, 0 )
304                    ) == NULL )
305             {
306                 if( p_vout->b_die || p_vout->b_error )
307                 {
308                     vout_DestroyPicture(
309                         p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
310                     return;
311                 }
312
313                 msleep( VOUT_OUTMEM_SLEEP );
314             }
315
316             vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
317                               p_outpic, p_pic->date );
318             vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
319                               p_outpic );
320
321             for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
322             {
323                 u8 *p_in, *p_in_end, *p_out;
324                 int i_in_pitch = p_pic->p[i_plane].i_pitch;
325                 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
326
327                 p_in = p_pic->p[i_plane].p_pixels
328                         + pi_top_skip[i_plane] + pi_left_skip[i_plane];
329
330                 p_in_end = p_in + p_outpic->p[i_plane].i_lines
331                                    * p_pic->p[i_plane].i_pitch;
332
333                 p_out = p_outpic->p[i_plane].p_pixels;
334
335                 while( p_in < p_in_end )
336                 {
337                     FAST_MEMCPY( p_out, p_in, i_out_pitch );
338                     p_in += i_in_pitch;
339                     p_out += i_out_pitch;
340                 }
341
342                 pi_left_skip[i_plane] += p_outpic->p[i_plane].i_pitch;
343             }
344
345             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
346                                 p_outpic );
347             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
348                                  p_outpic );
349
350             i_vout++;
351         }
352
353         for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
354         {
355             pi_top_skip[i_plane] += p_outpic->p[i_plane].i_lines
356                                      * p_pic->p[i_plane].i_pitch;
357         }
358     }
359 }
360
361 /*****************************************************************************
362  * vout_Display: displays previously rendered output
363  *****************************************************************************
364  * This function send the currently rendered image to Invert image, waits
365  * until it is displayed and switch the two rendering buffers, preparing next
366  * frame.
367  *****************************************************************************/
368 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
369 {
370     ;
371 }
372
373 static void RemoveAllVout( vout_thread_t *p_vout )
374 {
375     while( p_vout->p_sys->i_vout )
376     {
377          --p_vout->p_sys->i_vout;
378          vout_DestroyThread(
379              p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout, NULL );
380     }
381 }
382