]> git.sesse.net Git - vlc/blob - plugins/filter/wall.c
Some heavy changes today:
[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.3 2001/12/30 07:09:55 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_thread_s **pp_vout;
76
77 } vout_sys_t;
78
79 /*****************************************************************************
80  * Local prototypes
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 * );
89
90 static void RemoveAllVout  ( vout_thread_t *p_vout );
91
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 )
97 {
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;
106 }
107
108 /*****************************************************************************
109  * intf_Probe: return a score
110  *****************************************************************************/
111 static int vout_Probe( probedata_t *p_data )
112 {
113     return( 0 );
114 }
115
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 )
122 {
123     /* Allocate structure */
124     p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
125     if( p_vout->p_sys == NULL )
126     {
127         intf_ErrMsg("error: %s", strerror(ENOMEM) );
128         return( 1 );
129     }
130
131     p_vout->p_sys->i_col = 2;
132     p_vout->p_sys->i_row = 3;
133
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 )
138     {
139         intf_ErrMsg("error: %s", strerror(ENOMEM) );
140         free( p_vout->p_sys );
141         return( 1 );
142     }
143
144
145     return( 0 );
146 }
147
148 /*****************************************************************************
149  * vout_Init: initialize Wall video thread output method
150  *****************************************************************************/
151 static int vout_Init( vout_thread_t *p_vout )
152 {
153     int i_index;
154     char *psz_filter;
155     picture_t *p_pic;
156     
157     I_OUTPUTPICTURES = 0;
158
159     /* Initialize the output structure */
160     switch( p_vout->render.i_chroma )
161     {
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;
167             break;
168
169         default:
170             return( 0 ); /* unknown chroma */
171             break;
172     }
173
174     /* Try to open the real video output */
175     psz_filter = main_GetPszVariable( VOUT_FILTER_VAR, NULL );
176     main_PutPszVariable( VOUT_FILTER_VAR, "" );
177
178     intf_WarnMsg( 1, "filter: spawning the real video outputs" );
179
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++ )
183     {
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 )
192         {
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 );
196              return 0;
197         }
198     }
199
200     main_PutPszVariable( VOUT_FILTER_VAR, psz_filter );
201
202     ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
203
204     return( 0 );
205 }
206
207 /*****************************************************************************
208  * vout_End: terminate Wall video thread output method
209  *****************************************************************************/
210 static void vout_End( vout_thread_t *p_vout )
211 {
212     int i_index;
213
214     /* Free the fake output buffers we allocated */
215     for( i_index = I_OUTPUTPICTURES ; i_index ; )
216     {
217         i_index--;
218         free( PP_OUTPUTPICTURE[ i_index ]->planes[ 0 ].p_data );
219     }
220 }
221
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 )
228 {
229     RemoveAllVout( p_vout );
230
231     free( p_vout->p_sys->pp_vout );
232     free( p_vout->p_sys );
233 }
234
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 )
242 {
243     return( 0 );
244 }
245
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
251  * frame.
252  *****************************************************************************/
253 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
254 {
255     picture_t *p_outpic;
256     int i_col, i_row, i_vout, i_index;
257     mtime_t i_date = mdate() + 50000;
258
259     i_vout = 0;
260
261     for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
262     {
263         for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
264         {
265             while( ( p_outpic =
266                 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ], 0, 0, 0 )
267                    ) == NULL )
268             {
269                 if( p_vout->b_die || p_vout->b_error )
270                 {
271                     vout_DestroyPicture( p_vout->p_sys->pp_vout[ i_vout ], 
272                                          p_outpic );
273                     return;
274                 }
275
276                 msleep( VOUT_OUTMEM_SLEEP );
277             }
278
279             vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ],
280                               p_outpic, i_date );
281             vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ],
282                               p_outpic );
283
284             for( i_index = 0 ; i_index < p_pic->i_planes ; i_index++ )
285             {
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 );
290             }
291
292             vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ],
293                                 p_outpic );
294             vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ],
295                                  p_outpic );
296
297             i_vout++;
298         }
299     }
300 }
301
302 static void RemoveAllVout( vout_thread_t *p_vout )
303 {
304     while( p_vout->p_sys->i_vout )
305     {
306          --p_vout->p_sys->i_vout;
307          vout_DestroyThread( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ],
308                              NULL );
309     }
310 }
311