1 /*****************************************************************************
2 * wall.c : Wall video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001, 2002, 2003 VideoLAN
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 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
33 #include "filter_common.h"
35 /*****************************************************************************
37 *****************************************************************************/
38 static int Create ( vlc_object_t * );
39 static void Destroy ( vlc_object_t * );
41 static int Init ( vout_thread_t * );
42 static void End ( vout_thread_t * );
43 static void Render ( vout_thread_t *, picture_t * );
45 static void RemoveAllVout ( vout_thread_t *p_vout );
47 static int SendEvents( vlc_object_t *, char const *,
48 vlc_value_t, vlc_value_t, void * );
50 /*****************************************************************************
52 *****************************************************************************/
53 #define COLS_TEXT N_("Number of columns")
54 #define COLS_LONGTEXT N_("Select the number of horizontal video windows in " \
55 "which to split the video.")
57 #define ROWS_TEXT N_("Number of rows")
58 #define ROWS_LONGTEXT N_("Select the number of vertical video windows in " \
59 "which to split the video.")
61 #define ACTIVE_TEXT N_("Active windows")
62 #define ACTIVE_LONGTEXT N_("Comma separated list of active windows, " \
65 #define ASPECT_TEXT N_("Element aspect ratio")
66 #define ASPECT_LONGTEXT N_("The aspect ratio of the individual displays building the display wall")
69 set_description( _("Wall video filter") );
70 set_shortname( N_("Image wall" ));
71 set_capability( "video filter", 0 );
72 set_category( CAT_VIDEO );
73 set_subcategory( SUBCAT_VIDEO_VFILTER );
75 add_integer( "wall-cols", 3, NULL, COLS_TEXT, COLS_LONGTEXT, VLC_FALSE );
76 add_integer( "wall-rows", 3, NULL, ROWS_TEXT, ROWS_LONGTEXT, VLC_FALSE );
77 add_string( "wall-active", NULL, NULL, ACTIVE_TEXT, ACTIVE_LONGTEXT, VLC_FALSE );
78 add_string( "wall-element-aspect", "4:3", NULL, ASPECT_TEXT, ASPECT_LONGTEXT, VLC_FALSE );
80 add_shortcut( "wall" );
81 set_callbacks( Create, Destroy );
84 /*****************************************************************************
85 * vout_sys_t: Wall video output method descriptor
86 *****************************************************************************
87 * This structure is part of the video output thread descriptor.
88 * It describes the Wall specific properties of an output thread.
89 *****************************************************************************/
102 vout_thread_t *p_vout;
106 /*****************************************************************************
107 * Control: control facility for the vout (forwards to child vout)
108 *****************************************************************************/
109 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
111 int i_row, i_col, i_vout = 0;
113 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
115 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
117 vout_vaControl( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
125 /*****************************************************************************
126 * Create: allocates Wall video thread output method
127 *****************************************************************************
128 * This function allocates and initializes a Wall vout method.
129 *****************************************************************************/
130 static int Create( vlc_object_t *p_this )
132 vout_thread_t *p_vout = (vout_thread_t *)p_this;
133 char *psz_method, *psz_tmp, *psz_method_tmp;
136 /* Allocate structure */
137 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
138 if( p_vout->p_sys == NULL )
140 msg_Err( p_vout, "out of memory" );
144 p_vout->pf_init = Init;
145 p_vout->pf_end = End;
146 p_vout->pf_manage = NULL;
147 p_vout->pf_render = Render;
148 p_vout->pf_display = NULL;
149 p_vout->pf_control = Control;
151 /* Look what method was requested */
152 p_vout->p_sys->i_col = config_GetInt( p_vout, "wall-cols" );
153 p_vout->p_sys->i_row = config_GetInt( p_vout, "wall-rows" );
155 p_vout->p_sys->i_col = __MAX( 1, __MIN( 15, p_vout->p_sys->i_col ) );
156 p_vout->p_sys->i_row = __MAX( 1, __MIN( 15, p_vout->p_sys->i_row ) );
158 msg_Dbg( p_vout, "opening a %i x %i wall",
159 p_vout->p_sys->i_col, p_vout->p_sys->i_row );
161 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_row *
162 p_vout->p_sys->i_col *
163 sizeof(struct vout_list_t) );
164 if( p_vout->p_sys->pp_vout == NULL )
166 msg_Err( p_vout, "out of memory" );
167 free( p_vout->p_sys );
171 psz_method_tmp = psz_method = config_GetPsz( p_vout, "wall-active" );
173 /* If no trailing vout are specified, take them all */
174 if( psz_method == NULL )
176 for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
179 p_vout->p_sys->pp_vout[i_vout].b_active = 1;
182 /* If trailing vout are specified, activate only the requested ones */
185 for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
188 p_vout->p_sys->pp_vout[i_vout].b_active = 0;
193 psz_tmp = psz_method;
194 while( *psz_tmp && *psz_tmp != ',' )
202 i_vout = atoi( psz_method );
203 psz_method = psz_tmp + 1;
207 i_vout = atoi( psz_method );
208 psz_method = psz_tmp;
212 i_vout < p_vout->p_sys->i_row * p_vout->p_sys->i_col )
214 p_vout->p_sys->pp_vout[i_vout].b_active = 1;
219 free( psz_method_tmp );
224 /*****************************************************************************
225 * Init: initialize Wall video thread output method
226 *****************************************************************************/
227 static int Init( vout_thread_t *p_vout )
229 int i_index, i_row, i_col, i_width, i_height, i_left, i_top;
230 unsigned int i_target_width,i_target_height;
232 int i_aspect = 4*VOUT_ASPECT_FACTOR/3;
234 unsigned int i_hstart, i_hend, i_vstart, i_vend;
235 unsigned int w1,h1,w2,h2;
237 int i_vstart_rounded = 0, i_hstart_rounded = 0;
240 psz_aspect = config_GetPsz( p_vout, "wall-element-aspect" );
241 if( psz_aspect && *psz_aspect )
243 char *psz_parser = strchr( psz_aspect, ':' );
246 *psz_parser++ = '\0';
247 i_aspect = atoi( psz_aspect ) * VOUT_ASPECT_FACTOR
248 / atoi( psz_parser );
252 msg_Warn( p_vout, "invalid aspect ratio specification" );
258 i_xpos = var_CreateGetInteger( p_vout, "video-x" );
259 i_ypos = var_CreateGetInteger( p_vout, "video-y" );
260 if( i_xpos < 0 ) i_xpos = 0;
261 if( i_ypos < 0 ) i_ypos = 0;
263 I_OUTPUTPICTURES = 0;
265 /* Initialize the output structure */
266 p_vout->output.i_chroma = p_vout->render.i_chroma;
267 p_vout->output.i_width = p_vout->render.i_width;
268 p_vout->output.i_height = p_vout->render.i_height;
269 p_vout->output.i_aspect = p_vout->render.i_aspect;
270 var_Create( p_vout, "align", VLC_VAR_INTEGER );
272 w1 = p_vout->output.i_width / p_vout->p_sys->i_col;
274 h1 = w1 * VOUT_ASPECT_FACTOR / i_aspect&~1;
277 h2 = p_vout->output.i_height / p_vout->p_sys->i_row&~1;
279 w2 = h2 * i_aspect / VOUT_ASPECT_FACTOR&~1;
282 if ( h1 * p_vout->p_sys->i_row < p_vout->output.i_height )
286 i_target_height = h2;
288 i_vend = p_vout->output.i_height;
289 i_tmp = i_target_width * p_vout->p_sys->i_col;
290 while( i_tmp < p_vout->output.i_width ) i_tmp += p_vout->p_sys->i_col;
291 i_hstart = (( i_tmp - p_vout->output.i_width ) / 2)&~1;
292 i_hstart_rounded = ( ( i_tmp - p_vout->output.i_width ) % 2 ) ||
293 ( ( ( i_tmp - p_vout->output.i_width ) / 2 ) & 1 );
294 i_hend = i_hstart + p_vout->output.i_width;
299 i_target_height = h1;
302 i_hend = p_vout->output.i_width;
303 i_tmp = i_target_height * p_vout->p_sys->i_row;
304 while( i_tmp < p_vout->output.i_height ) i_tmp += p_vout->p_sys->i_row;
305 i_vstart = ( ( i_tmp - p_vout->output.i_height ) / 2 ) & ~1;
306 i_vstart_rounded = ( ( i_tmp - p_vout->output.i_height ) % 2 ) ||
307 ( ( ( i_tmp - p_vout->output.i_height ) / 2 ) & 1 );
308 i_vend = i_vstart + p_vout->output.i_height;
310 msg_Dbg( p_vout, "target resolution %dx%d", i_target_width, i_target_height );
312 /* Try to open the real video output */
313 msg_Dbg( p_vout, "spawning the real video outputs" );
315 p_vout->p_sys->i_vout = 0;
316 msg_Dbg( p_vout, "target window (%d,%d)-(%d,%d)", i_hstart,i_vstart,i_hend,i_vend );
321 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
325 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
329 if( i_col*i_target_width >= i_hstart &&
330 (i_col+1)*i_target_width <= i_hend )
332 i_width = i_target_width;
334 else if( ( i_col + 1 ) * i_target_width < i_hstart ||
335 ( i_col * i_target_width ) > i_hend )
341 i_width = ( i_target_width - i_hstart % i_target_width );
342 if( i_col > ( p_vout->p_sys->i_col / 2 ) )
344 i_align |= VOUT_ALIGN_LEFT;
345 i_width -= i_hstart_rounded ? 2: 0;
349 i_align |= VOUT_ALIGN_RIGHT;
353 if( i_row * i_target_height >= i_vstart &&
354 ( i_row + 1 ) * i_target_height <= i_vend )
356 i_height = i_target_height;
358 else if( ( i_row + 1 ) * i_target_height < i_vstart ||
359 ( i_row * i_target_height ) > i_vend )
365 i_height = ( i_target_height -
366 i_vstart%i_target_height );
367 if( i_row > ( p_vout->p_sys->i_row / 2 ) )
369 i_align |= VOUT_ALIGN_TOP;
370 i_height -= i_vstart_rounded ? 2: 0;
374 i_align |= VOUT_ALIGN_BOTTOM;
377 if( i_height == 0 || i_width == 0 )
379 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active = VLC_FALSE;
382 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_width = i_width;
383 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_height = i_height;
384 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_left = i_left;
385 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_top = i_top;
388 if( !p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active )
390 p_vout->p_sys->i_vout++;
393 var_SetInteger( p_vout, "align", i_align );
394 var_SetInteger( p_vout, "video-x", i_left + i_xpos - i_width);
395 var_SetInteger( p_vout, "video-y", i_top + i_ypos );
397 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout =
398 vout_Create( p_vout, i_width, i_height,
399 p_vout->render.i_chroma,
400 i_aspect * i_target_height / i_height *
401 i_width / i_target_width );
402 if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout == NULL )
404 msg_Err( p_vout, "failed to get %ix%i vout threads",
405 p_vout->p_sys->i_col, p_vout->p_sys->i_row );
406 RemoveAllVout( p_vout );
410 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout,
412 p_vout->p_sys->i_vout++;
416 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
418 ADD_PARENT_CALLBACKS( SendEventsToChild );
423 /*****************************************************************************
424 * End: terminate Wall video thread output method
425 *****************************************************************************/
426 static void End( vout_thread_t *p_vout )
430 /* Free the fake output buffers we allocated */
431 for( i_index = I_OUTPUTPICTURES ; i_index ; )
434 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
438 /*****************************************************************************
439 * Destroy: destroy Wall video thread output method
440 *****************************************************************************
441 * Terminate an output method created by WallCreateOutputMethod
442 *****************************************************************************/
443 static void Destroy( vlc_object_t *p_this )
445 vout_thread_t *p_vout = (vout_thread_t *)p_this;
447 RemoveAllVout( p_vout );
449 DEL_PARENT_CALLBACKS( SendEventsToChild );
451 free( p_vout->p_sys->pp_vout );
452 free( p_vout->p_sys );
455 /*****************************************************************************
456 * Render: displays previously rendered output
457 *****************************************************************************
458 * This function send the currently rendered image to Wall image, waits
459 * until it is displayed and switch the two rendering buffers, preparing next
461 *****************************************************************************/
462 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
464 picture_t *p_outpic = NULL;
465 int i_col, i_row, i_vout, i_plane;
466 int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
470 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
472 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
474 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
476 pi_left_skip[i_plane] = p_vout->p_sys->pp_vout[ i_vout ].i_left * p_pic->p[ i_plane ].i_pitch / p_vout->output.i_width;
477 pi_top_skip[i_plane] = (p_vout->p_sys->pp_vout[ i_vout ].i_top * p_pic->p[ i_plane ].i_lines / p_vout->output.i_height)*p_pic->p[i_plane].i_pitch;
480 if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
487 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
491 if( p_vout->b_die || p_vout->b_error )
494 p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
498 msleep( VOUT_OUTMEM_SLEEP );
501 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
502 p_outpic, p_pic->date );
503 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
506 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
508 uint8_t *p_in, *p_in_end, *p_out;
509 int i_in_pitch = p_pic->p[i_plane].i_pitch;
510 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
511 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
513 p_in = p_pic->p[i_plane].p_pixels
514 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
516 p_in_end = p_in + p_outpic->p[i_plane].i_visible_lines
517 * p_pic->p[i_plane].i_pitch;
519 p_out = p_outpic->p[i_plane].p_pixels;
521 while( p_in < p_in_end )
523 p_vout->p_vlc->pf_memcpy( p_out, p_in, i_copy_pitch );
525 p_out += i_out_pitch;
528 // pi_left_skip[i_plane] += i_copy_pitch;
531 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
533 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
539 /* for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ ) */
541 /* pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout ].i_height */
542 /* * p_pic->p[i_plane].i_visible_lines */
543 /* / p_vout->output.i_height */
544 /* * p_pic->p[i_plane].i_pitch; */
549 /*****************************************************************************
550 * RemoveAllVout: destroy all the child video output threads
551 *****************************************************************************/
552 static void RemoveAllVout( vout_thread_t *p_vout )
554 while( p_vout->p_sys->i_vout )
556 --p_vout->p_sys->i_vout;
557 if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active )
560 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout,
563 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout );
565 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout );
570 /*****************************************************************************
571 * SendEvents: forward mouse and keyboard events to the parent p_vout
572 *****************************************************************************/
573 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
574 vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
576 vout_thread_t *p_vout = (vout_thread_t *)_p_vout;
578 vlc_value_t sentval = newval;
580 /* Find the video output index */
581 for( i_vout = 0; i_vout < p_vout->p_sys->i_vout; i_vout++ )
583 if( p_this == (vlc_object_t *)p_vout->p_sys->pp_vout[ i_vout ].p_vout )
589 if( i_vout == p_vout->p_sys->i_vout )
594 /* Translate the mouse coordinates */
595 if( !strcmp( psz_var, "mouse-x" ) )
597 sentval.i_int += p_vout->output.i_width
598 * (i_vout % p_vout->p_sys->i_col)
599 / p_vout->p_sys->i_col;
601 else if( !strcmp( psz_var, "mouse-y" ) )
603 sentval.i_int += p_vout->output.i_height
604 * (i_vout / p_vout->p_sys->i_row)
605 / p_vout->p_sys->i_row;
608 var_Set( p_vout, psz_var, sentval );
613 /*****************************************************************************
614 * SendEventsToChild: forward events to the child/children vout
615 *****************************************************************************/
616 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
617 vlc_value_t oldval, vlc_value_t newval, void *p_data )
619 vout_thread_t *p_vout = (vout_thread_t *)p_this;
620 int i_row, i_col, i_vout = 0;
622 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
624 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
626 var_Set( p_vout->p_sys->pp_vout[ i_vout ].p_vout, psz_var, newval);
627 if( !strcmp( psz_var, "fullscreen" ) ) break;