1 /*****************************************************************************
2 * wall.c : Wall video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2000, 2001, 2002, 2003 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
36 #include "filter_common.h"
38 /*****************************************************************************
40 *****************************************************************************/
41 static int Create ( vlc_object_t * );
42 static void Destroy ( vlc_object_t * );
44 static int Init ( vout_thread_t * );
45 static void End ( vout_thread_t * );
46 static void Render ( vout_thread_t *, picture_t * );
48 static void RemoveAllVout ( vout_thread_t *p_vout );
50 static int SendEvents( vlc_object_t *, char const *,
51 vlc_value_t, vlc_value_t, void * );
53 /*****************************************************************************
55 *****************************************************************************/
56 #define COLS_TEXT N_("Number of columns")
57 #define COLS_LONGTEXT N_("Number of horizontal windows in " \
58 "which to split the video.")
60 #define ROWS_TEXT N_("Number of rows")
61 #define ROWS_LONGTEXT N_("Number of vertical windows in " \
62 "which to split the video.")
64 #define ACTIVE_TEXT N_("Active windows")
65 #define ACTIVE_LONGTEXT N_("Comma-separated list of active windows, " \
68 #define ASPECT_TEXT N_("Element aspect ratio")
69 #define ASPECT_LONGTEXT N_("Aspect ratio of the individual displays " \
72 #define CFG_PREFIX "wall-"
75 set_description( N_("Wall video filter") );
76 set_shortname( N_("Image wall" ));
77 set_capability( "video filter", 0 );
78 set_category( CAT_VIDEO );
79 set_subcategory( SUBCAT_VIDEO_VFILTER );
81 add_integer( CFG_PREFIX "cols", 3, NULL, COLS_TEXT, COLS_LONGTEXT, false );
82 add_integer( CFG_PREFIX "rows", 3, NULL, ROWS_TEXT, ROWS_LONGTEXT, false );
83 add_string( CFG_PREFIX "active", NULL, NULL, ACTIVE_TEXT, ACTIVE_LONGTEXT,
85 add_string( CFG_PREFIX "element-aspect", "4:3", NULL, ASPECT_TEXT, ASPECT_LONGTEXT, false );
87 add_shortcut( "wall" );
88 set_callbacks( Create, Destroy );
91 static const char *const ppsz_filter_options[] = {
92 "cols", "rows", "active", "element-aspect", NULL
95 /*****************************************************************************
96 * vout_sys_t: Wall video output method descriptor
97 *****************************************************************************
98 * This structure is part of the video output thread descriptor.
99 * It describes the Wall specific properties of an output thread.
100 *****************************************************************************/
113 vout_thread_t *p_vout;
117 /*****************************************************************************
118 * Control: control facility for the vout (forwards to child vout)
119 *****************************************************************************/
120 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
122 int i_row, i_col, i_vout = 0;
124 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
126 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
128 vout_vaControl( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
136 /*****************************************************************************
137 * Create: allocates Wall video thread output method
138 *****************************************************************************
139 * This function allocates and initializes a Wall vout method.
140 *****************************************************************************/
141 static int Create( vlc_object_t *p_this )
143 vout_thread_t *p_vout = (vout_thread_t *)p_this;
144 char *psz_method, *psz_tmp, *psz_method_tmp;
147 /* Allocate structure */
148 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
149 if( p_vout->p_sys == NULL )
152 p_vout->pf_init = Init;
153 p_vout->pf_end = End;
154 p_vout->pf_manage = NULL;
155 p_vout->pf_render = Render;
156 p_vout->pf_display = NULL;
157 p_vout->pf_control = Control;
159 config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options,
162 /* Look what method was requested */
163 p_vout->p_sys->i_col = var_CreateGetInteger( p_vout, CFG_PREFIX "cols" );
164 p_vout->p_sys->i_row = var_CreateGetInteger( p_vout, CFG_PREFIX "rows" );
166 p_vout->p_sys->i_col = __MAX( 1, __MIN( 15, p_vout->p_sys->i_col ) );
167 p_vout->p_sys->i_row = __MAX( 1, __MIN( 15, p_vout->p_sys->i_row ) );
169 msg_Dbg( p_vout, "opening a %i x %i wall",
170 p_vout->p_sys->i_col, p_vout->p_sys->i_row );
172 p_vout->p_sys->pp_vout = malloc( p_vout->p_sys->i_row *
173 p_vout->p_sys->i_col *
174 sizeof(struct vout_list_t) );
175 if( p_vout->p_sys->pp_vout == NULL )
177 free( p_vout->p_sys );
182 psz_method = var_CreateGetNonEmptyString( p_vout, CFG_PREFIX "active" );
184 /* If no trailing vout are specified, take them all */
185 if( psz_method == NULL )
187 for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
190 p_vout->p_sys->pp_vout[i_vout].b_active = 1;
193 /* If trailing vout are specified, activate only the requested ones */
196 for( i_vout = p_vout->p_sys->i_row * p_vout->p_sys->i_col;
199 p_vout->p_sys->pp_vout[i_vout].b_active = 0;
204 psz_tmp = psz_method;
205 while( *psz_tmp && *psz_tmp != ',' )
213 i_vout = atoi( psz_method );
214 psz_method = psz_tmp + 1;
218 i_vout = atoi( psz_method );
219 psz_method = psz_tmp;
223 i_vout < p_vout->p_sys->i_row * p_vout->p_sys->i_col )
225 p_vout->p_sys->pp_vout[i_vout].b_active = 1;
230 free( psz_method_tmp );
235 /*****************************************************************************
236 * Init: initialize Wall video thread output method
237 *****************************************************************************/
238 static int Init( vout_thread_t *p_vout )
240 int i_index, i_row, i_col, i_width, i_height, i_left, i_top;
241 unsigned int i_target_width,i_target_height;
244 int i_aspect = 4*VOUT_ASPECT_FACTOR/3;
246 unsigned int i_hstart, i_hend, i_vstart, i_vend;
247 unsigned int w1,h1,w2,h2;
249 int i_vstart_rounded = 0, i_hstart_rounded = 0;
252 memset( &fmt, 0, sizeof(video_format_t) );
254 psz_aspect = var_CreateGetNonEmptyString( p_vout,
255 CFG_PREFIX "element-aspect" );
256 if( psz_aspect && *psz_aspect )
258 char *psz_parser = strchr( psz_aspect, ':' );
261 *psz_parser++ = '\0';
262 i_aspect = atoi( psz_aspect ) * VOUT_ASPECT_FACTOR
263 / atoi( psz_parser );
267 msg_Warn( p_vout, "invalid aspect ratio specification" );
272 i_xpos = var_CreateGetInteger( p_vout, "video-x" );
273 i_ypos = var_CreateGetInteger( p_vout, "video-y" );
274 if( i_xpos < 0 ) i_xpos = 0;
275 if( i_ypos < 0 ) i_ypos = 0;
277 I_OUTPUTPICTURES = 0;
279 /* Initialize the output structure */
280 p_vout->output.i_chroma = p_vout->render.i_chroma;
281 p_vout->output.i_width = p_vout->render.i_width;
282 p_vout->output.i_height = p_vout->render.i_height;
283 p_vout->output.i_aspect = p_vout->render.i_aspect;
284 var_Create( p_vout, "align", VLC_VAR_INTEGER );
286 fmt.i_width = fmt.i_visible_width = p_vout->render.i_width;
287 fmt.i_height = fmt.i_visible_height = p_vout->render.i_height;
288 fmt.i_x_offset = fmt.i_y_offset = 0;
289 fmt.i_chroma = p_vout->render.i_chroma;
290 fmt.i_aspect = p_vout->render.i_aspect;
291 fmt.i_sar_num = p_vout->render.i_aspect * fmt.i_height / fmt.i_width;
292 fmt.i_sar_den = VOUT_ASPECT_FACTOR;
294 w1 = p_vout->output.i_width / p_vout->p_sys->i_col;
296 h1 = w1 * VOUT_ASPECT_FACTOR / i_aspect&~1;
299 h2 = p_vout->output.i_height / p_vout->p_sys->i_row&~1;
301 w2 = h2 * i_aspect / VOUT_ASPECT_FACTOR&~1;
304 if ( h1 * p_vout->p_sys->i_row < p_vout->output.i_height )
308 i_target_height = h2;
310 i_vend = p_vout->output.i_height;
311 i_tmp = i_target_width * p_vout->p_sys->i_col;
312 while( i_tmp < p_vout->output.i_width ) i_tmp += p_vout->p_sys->i_col;
313 i_hstart = (( i_tmp - p_vout->output.i_width ) / 2)&~1;
314 i_hstart_rounded = ( ( i_tmp - p_vout->output.i_width ) % 2 ) ||
315 ( ( ( i_tmp - p_vout->output.i_width ) / 2 ) & 1 );
316 i_hend = i_hstart + p_vout->output.i_width;
321 i_target_height = h1;
324 i_hend = p_vout->output.i_width;
325 i_tmp = i_target_height * p_vout->p_sys->i_row;
326 while( i_tmp < p_vout->output.i_height ) i_tmp += p_vout->p_sys->i_row;
327 i_vstart = ( ( i_tmp - p_vout->output.i_height ) / 2 ) & ~1;
328 i_vstart_rounded = ( ( i_tmp - p_vout->output.i_height ) % 2 ) ||
329 ( ( ( i_tmp - p_vout->output.i_height ) / 2 ) & 1 );
330 i_vend = i_vstart + p_vout->output.i_height;
332 msg_Dbg( p_vout, "target resolution %dx%d", i_target_width, i_target_height );
334 /* Try to open the real video output */
335 msg_Dbg( p_vout, "spawning the real video outputs" );
337 p_vout->p_sys->i_vout = 0;
338 msg_Dbg( p_vout, "target window (%d,%d)-(%d,%d)", i_hstart,i_vstart,i_hend,i_vend );
343 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
347 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
351 if( i_col*i_target_width >= i_hstart &&
352 (i_col+1)*i_target_width <= i_hend )
354 i_width = i_target_width;
356 else if( ( i_col + 1 ) * i_target_width < i_hstart ||
357 ( i_col * i_target_width ) > i_hend )
363 i_width = ( i_target_width - i_hstart % i_target_width );
364 if( i_col >= ( p_vout->p_sys->i_col / 2 ) )
366 i_align |= VOUT_ALIGN_LEFT;
367 i_width -= i_hstart_rounded ? 2: 0;
371 i_align |= VOUT_ALIGN_RIGHT;
375 if( i_row * i_target_height >= i_vstart &&
376 ( i_row + 1 ) * i_target_height <= i_vend )
378 i_height = i_target_height;
380 else if( ( i_row + 1 ) * i_target_height < i_vstart ||
381 ( i_row * i_target_height ) > i_vend )
387 i_height = ( i_target_height -
388 i_vstart%i_target_height );
389 if( i_row >= ( p_vout->p_sys->i_row / 2 ) )
391 i_align |= VOUT_ALIGN_TOP;
392 i_height -= i_vstart_rounded ? 2: 0;
396 i_align |= VOUT_ALIGN_BOTTOM;
399 if( i_height == 0 || i_width == 0 )
401 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active = false;
404 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_width = i_width;
405 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_height = i_height;
406 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_left = i_left;
407 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].i_top = i_top;
410 if( !p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active )
412 p_vout->p_sys->i_vout++;
415 var_SetInteger( p_vout, "align", i_align );
416 var_SetInteger( p_vout, "video-x", i_left + i_xpos - i_width);
417 var_SetInteger( p_vout, "video-y", i_top + i_ypos );
419 fmt.i_width = fmt.i_visible_width = i_width;
420 fmt.i_height = fmt.i_visible_height = i_height;
421 fmt.i_aspect = i_aspect * i_target_height / i_height *
422 i_width / i_target_width;
424 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout =
425 vout_Create( p_vout, &fmt );
426 if( !p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout )
428 msg_Err( p_vout, "failed to get %ix%i vout threads",
429 p_vout->p_sys->i_col, p_vout->p_sys->i_row );
430 RemoveAllVout( p_vout );
434 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout,
436 p_vout->p_sys->i_vout++;
440 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
442 ADD_PARENT_CALLBACKS( SendEventsToChild );
447 /*****************************************************************************
448 * End: terminate Wall video thread output method
449 *****************************************************************************/
450 static void End( vout_thread_t *p_vout )
454 DEL_PARENT_CALLBACKS( SendEventsToChild );
456 /* Free the fake output buffers we allocated */
457 for( i_index = I_OUTPUTPICTURES ; i_index ; )
460 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
463 RemoveAllVout( p_vout );
466 /*****************************************************************************
467 * Destroy: destroy Wall video thread output method
468 *****************************************************************************
469 * Terminate an output method created by WallCreateOutputMethod
470 *****************************************************************************/
471 static void Destroy( vlc_object_t *p_this )
473 vout_thread_t *p_vout = (vout_thread_t *)p_this;
476 free( p_vout->p_sys->pp_vout );
477 free( p_vout->p_sys );
480 /*****************************************************************************
481 * Render: displays previously rendered output
482 *****************************************************************************
483 * This function send the currently rendered image to Wall image, waits
484 * until it is displayed and switch the two rendering buffers, preparing next
486 *****************************************************************************/
487 static void Render( vout_thread_t *p_vout, picture_t *p_pic )
489 picture_t *p_outpic = NULL;
490 int i_col, i_row, i_vout, i_plane;
491 int pi_left_skip[VOUT_MAX_PLANES], pi_top_skip[VOUT_MAX_PLANES];
495 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
497 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
499 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
501 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;
502 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;
505 if( !p_vout->p_sys->pp_vout[ i_vout ].b_active )
512 vout_CreatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
516 if( !vlc_object_alive (p_vout) || p_vout->b_error )
519 p_vout->p_sys->pp_vout[ i_vout ].p_vout, p_outpic );
523 msleep( VOUT_OUTMEM_SLEEP );
526 vout_DatePicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
527 p_outpic, p_pic->date );
528 vout_LinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
531 for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
533 uint8_t *p_in, *p_in_end, *p_out;
534 int i_in_pitch = p_pic->p[i_plane].i_pitch;
535 int i_out_pitch = p_outpic->p[i_plane].i_pitch;
536 int i_copy_pitch = p_outpic->p[i_plane].i_visible_pitch;
538 p_in = p_pic->p[i_plane].p_pixels
539 + pi_top_skip[i_plane] + pi_left_skip[i_plane];
541 p_in_end = p_in + p_outpic->p[i_plane].i_visible_lines
542 * p_pic->p[i_plane].i_pitch;
544 p_out = p_outpic->p[i_plane].p_pixels;
546 while( p_in < p_in_end )
548 vlc_memcpy( p_out, p_in, i_copy_pitch );
550 p_out += i_out_pitch;
553 // pi_left_skip[i_plane] += i_copy_pitch;
556 vout_UnlinkPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
558 vout_DisplayPicture( p_vout->p_sys->pp_vout[ i_vout ].p_vout,
564 /* for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ ) */
566 /* pi_top_skip[i_plane] += p_vout->p_sys->pp_vout[ i_vout ].i_height */
567 /* * p_pic->p[i_plane].i_visible_lines */
568 /* / p_vout->output.i_height */
569 /* * p_pic->p[i_plane].i_pitch; */
574 /*****************************************************************************
575 * RemoveAllVout: destroy all the child video output threads
576 *****************************************************************************/
577 static void RemoveAllVout( vout_thread_t *p_vout )
579 while( p_vout->p_sys->i_vout )
581 --p_vout->p_sys->i_vout;
582 if( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].b_active )
585 p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout,
587 vout_CloseAndRelease( p_vout->p_sys->pp_vout[ p_vout->p_sys->i_vout ].p_vout );
592 /*****************************************************************************
593 * SendEvents: forward mouse and keyboard events to the parent p_vout
594 *****************************************************************************/
595 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
596 vlc_value_t oldval, vlc_value_t newval, void *_p_vout )
599 vout_thread_t *p_vout = (vout_thread_t *)_p_vout;
601 vlc_value_t sentval = newval;
603 /* Find the video output index */
604 for( i_vout = 0; i_vout < p_vout->p_sys->i_vout; i_vout++ )
606 if( p_this == (vlc_object_t *)p_vout->p_sys->pp_vout[ i_vout ].p_vout )
612 if( i_vout == p_vout->p_sys->i_vout )
617 /* Translate the mouse coordinates */
618 if( !strcmp( psz_var, "mouse-x" ) )
620 sentval.i_int += p_vout->output.i_width
621 * (i_vout % p_vout->p_sys->i_col)
622 / p_vout->p_sys->i_col;
624 else if( !strcmp( psz_var, "mouse-y" ) )
626 sentval.i_int += p_vout->output.i_height
627 * (i_vout / p_vout->p_sys->i_row)
628 / p_vout->p_sys->i_row;
631 var_Set( p_vout, psz_var, sentval );
636 /*****************************************************************************
637 * SendEventsToChild: forward events to the child/children vout
638 *****************************************************************************/
639 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
640 vlc_value_t oldval, vlc_value_t newval, void *p_data )
642 VLC_UNUSED(p_data); VLC_UNUSED(oldval);
643 vout_thread_t *p_vout = (vout_thread_t *)p_this;
644 int i_row, i_col, i_vout = 0;
646 for( i_row = 0; i_row < p_vout->p_sys->i_row; i_row++ )
648 for( i_col = 0; i_col < p_vout->p_sys->i_col; i_col++ )
650 var_Set( p_vout->p_sys->pp_vout[ i_vout ].p_vout, psz_var, newval);
651 if( !strcmp( psz_var, "fullscreen" ) ) break;