1 /*****************************************************************************
2 * mosaic.c : Mosaic video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2004-2007 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea@via.ecp.fr>
8 * Christophe Massiot <massiot@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
34 # include <limits.h> /* INT_MAX */
37 #include "vlc_filter.h"
38 #include "vlc_image.h"
42 #define BLANK_DELAY I64C(1000000)
44 /*****************************************************************************
46 *****************************************************************************/
47 static int CreateFilter ( vlc_object_t * );
48 static void DestroyFilter ( vlc_object_t * );
49 static subpicture_t *Filter ( filter_t *, mtime_t );
51 static int MosaicCallback ( vlc_object_t *, char const *, vlc_value_t,
52 vlc_value_t, void * );
54 /*****************************************************************************
55 * filter_sys_t : filter descriptor
56 *****************************************************************************/
59 vlc_mutex_t lock; /* Internal filter lock */
60 vlc_mutex_t *p_lock; /* Pointer to mosaic bridge lock */
62 image_handler_t *p_image;
64 int i_position; /* Mosaic positioning method */
65 vlc_bool_t b_ar; /* Do we keep the aspect ratio ? */
66 vlc_bool_t b_keep; /* Do we keep the original picture format ? */
67 int i_width, i_height; /* Mosaic height and width */
68 int i_cols, i_rows; /* Mosaic rows and cols */
69 int i_align; /* Mosaic alignment in background video */
70 int i_xoffset, i_yoffset; /* Top left corner offset */
71 int i_borderw, i_borderh; /* Border width/height between miniatures */
72 int i_alpha; /* Subfilter alpha blending */
74 char **ppsz_order; /* List of picture-ids */
77 int *pi_x_offsets; /* List of substreams x offsets */
78 int *pi_y_offsets; /* List of substreams y offsets */
84 /*****************************************************************************
86 *****************************************************************************/
87 #define ALPHA_TEXT N_("Transparency")
88 #define ALPHA_LONGTEXT N_( \
89 "Transparency of the mosaic foreground pictures. " \
90 "0 means transparent, 255 opaque (default)." )
92 #define HEIGHT_TEXT N_("Height")
93 #define HEIGHT_LONGTEXT N_( "Total height of the mosaic, in pixels." )
94 #define WIDTH_TEXT N_("Width")
95 #define WIDTH_LONGTEXT N_( "Total width of the mosaic, in pixels." )
97 #define XOFFSET_TEXT N_("Top left corner X coordinate")
98 #define XOFFSET_LONGTEXT N_( \
99 "X Coordinate of the top-left corner of the mosaic.")
100 #define YOFFSET_TEXT N_("Top left corner Y coordinate")
101 #define YOFFSET_LONGTEXT N_( \
102 "Y Coordinate of the top-left corner of the mosaic.")
104 #define BORDERW_TEXT N_("Border width")
105 #define BORDERW_LONGTEXT N_( \
106 "Width in pixels of the border between miniatures." )
107 #define BORDERH_TEXT N_("Border height")
108 #define BORDERH_LONGTEXT N_( \
109 "Height in pixels of the border between miniatures." )
111 #define ALIGN_TEXT N_("Mosaic alignment" )
112 #define ALIGN_LONGTEXT N_( \
113 "You can enforce the mosaic alignment on the video " \
114 "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
115 "also use combinations of these values, eg 6 = top-right).")
117 #define POS_TEXT N_("Positioning method")
118 #define POS_LONGTEXT N_( \
119 "Positioning method for the mosaic. auto: " \
120 "automatically choose the best number of rows and columns. " \
121 "fixed: use the user-defined number of rows and columns. " \
122 "offsets: use the user-defined offsets for each image." )
124 #define ROWS_TEXT N_("Number of rows")
125 #define ROWS_LONGTEXT N_( \
126 "Number of image rows in the mosaic (only used if " \
127 "positionning method is set to \"fixed\")." )
129 #define COLS_TEXT N_("Number of columns")
130 #define COLS_LONGTEXT N_( \
131 "Number of image columns in the mosaic (only used if " \
132 "positionning method is set to \"fixed\"." )
134 #define AR_TEXT N_("Keep aspect ratio")
135 #define AR_LONGTEXT N_( \
136 "Keep the original aspect ratio when resizing " \
138 #define KEEP_TEXT N_("Keep original size")
139 #define KEEP_LONGTEXT N_( \
140 "Keep the original size of mosaic elements." )
142 #define ORDER_TEXT N_("Elements order" )
143 #define ORDER_LONGTEXT N_( \
144 "You can enforce the order of the elements on " \
145 "the mosaic. You must give a comma-separated list of picture ID(s)." \
146 "These IDs are assigned in the \"mosaic-bridge\" module." )
148 #define OFFSETS_TEXT N_("Offsets in order" )
149 #define OFFSETS_LONGTEXT N_( \
150 "You can enforce the (x,y) offsets of the elements on the mosaic " \
151 "(only used if positioning method is set to \"offsets\"). You " \
152 "must give a comma-separated list of coordinates (eg: 10,10,150,10)." )
154 #define DELAY_TEXT N_("Delay")
155 #define DELAY_LONGTEXT N_( \
156 "Pictures coming from the mosaic elements will be delayed " \
157 "according to this value (in milliseconds). For high " \
158 "values you will need to raise caching at input.")
162 position_auto = 0, position_fixed = 1, position_offsets = 2
164 static int pi_pos_values[] = { 0, 1, 2 };
165 static const char *ppsz_pos_descriptions[] =
166 { N_("auto"), N_("fixed"), N_("offsets") };
168 static int pi_align_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
169 static const char *ppsz_align_descriptions[] =
170 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
171 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
173 #define CFG_PREFIX "mosaic-"
176 set_description( _("Mosaic video sub filter") );
177 set_shortname( _("Mosaic") );
178 set_category( CAT_VIDEO );
179 set_subcategory( SUBCAT_VIDEO_SUBPIC);
180 set_capability( "sub filter", 0 );
181 set_callbacks( CreateFilter, DestroyFilter );
183 add_integer( CFG_PREFIX "alpha", 255, NULL,
184 ALPHA_TEXT, ALPHA_LONGTEXT, VLC_FALSE );
187 add_integer( CFG_PREFIX "height", 100, NULL,
188 HEIGHT_TEXT, HEIGHT_LONGTEXT, VLC_FALSE );
190 add_integer( CFG_PREFIX "width", 100, NULL,
191 WIDTH_TEXT, WIDTH_LONGTEXT, VLC_FALSE );
194 add_integer( CFG_PREFIX "align", 5, NULL,
195 ALIGN_TEXT, ALIGN_LONGTEXT, VLC_TRUE);
197 change_integer_list( pi_align_values, ppsz_align_descriptions, 0 );
199 add_integer( CFG_PREFIX "xoffset", 0, NULL,
200 XOFFSET_TEXT, XOFFSET_LONGTEXT, VLC_TRUE );
202 add_integer( CFG_PREFIX "yoffset", 0, NULL,
203 YOFFSET_TEXT, YOFFSET_LONGTEXT, VLC_TRUE );
206 add_integer( CFG_PREFIX "borderw", 0, NULL,
207 BORDERW_TEXT, BORDERW_LONGTEXT, VLC_TRUE );
209 add_deprecated_alias( CFG_PREFIX "vborder" );
210 add_integer( CFG_PREFIX "borderh", 0, NULL,
211 BORDERH_TEXT, BORDERH_LONGTEXT, VLC_TRUE );
213 add_deprecated_alias( CFG_PREFIX "hborder" );
215 add_integer( CFG_PREFIX "position", 0, NULL,
216 POS_TEXT, POS_LONGTEXT, VLC_FALSE );
218 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
219 add_integer( CFG_PREFIX "rows", 2, NULL,
220 ROWS_TEXT, ROWS_LONGTEXT, VLC_FALSE );
222 add_integer( CFG_PREFIX "cols", 2, NULL,
223 COLS_TEXT, COLS_LONGTEXT, VLC_FALSE );
226 add_bool( CFG_PREFIX "keep-aspect-ratio", 0, NULL,
227 AR_TEXT, AR_LONGTEXT, VLC_FALSE );
229 add_bool( CFG_PREFIX "keep-picture", 0, NULL,
230 KEEP_TEXT, KEEP_LONGTEXT, VLC_FALSE );
233 add_string( CFG_PREFIX "order", "", NULL,
234 ORDER_TEXT, ORDER_LONGTEXT, VLC_FALSE );
237 add_string( CFG_PREFIX "offsets", "", NULL,
238 OFFSETS_TEXT, OFFSETS_LONGTEXT, VLC_FALSE );
241 add_integer( CFG_PREFIX "delay", 0, NULL, DELAY_TEXT, DELAY_LONGTEXT,
246 static const char *ppsz_filter_options[] = {
247 "alpha", "height", "width", "align", "xoffset", "yoffset",
248 "borderw", "borderh", "position", "rows", "cols",
249 "keep-aspect-ratio", "keep-picture", "order", "offsets",
253 /*****************************************************************************
254 * mosaic_ParseSetOffsets:
255 * parse the "--mosaic-offsets x1,y1,x2,y2,x3,y3" parameter
256 * and set the corresponding struct filter_sys_t entries.
257 *****************************************************************************/
258 #define mosaic_ParseSetOffsets( a, b, c ) \
259 __mosaic_ParseSetOffsets( VLC_OBJECT( a ), b, c )
260 static void __mosaic_ParseSetOffsets( vlc_object_t *p_this,
266 char *psz_end = NULL;
272 p_sys->pi_x_offsets =
273 realloc( p_sys->pi_x_offsets, i_index * sizeof(int) );
274 p_sys->pi_x_offsets[i_index - 1] = atoi( psz_offsets );
275 psz_end = strchr( psz_offsets, ',' );
276 psz_offsets = psz_end + 1;
278 p_sys->pi_y_offsets =
279 realloc( p_sys->pi_y_offsets, i_index * sizeof(int) );
280 p_sys->pi_y_offsets[i_index - 1] = atoi( psz_offsets );
281 psz_end = strchr( psz_offsets, ',' );
282 psz_offsets = psz_end + 1;
284 msg_Dbg( p_this, CFG_PREFIX "offset: id %d, x=%d, y=%d",
285 i_index, p_sys->pi_x_offsets[i_index - 1],
286 p_sys->pi_y_offsets[i_index - 1] );
289 p_sys->i_offsets_length = i_index;
293 /*****************************************************************************
294 * CreateFiler: allocate mosaic video filter
295 *****************************************************************************/
296 static int CreateFilter( vlc_object_t *p_this )
298 filter_t *p_filter = (filter_t *)p_this;
300 vlc_object_t *p_libvlc = VLC_OBJECT( p_filter->p_libvlc );
306 /* The mosaic thread is more important than the decoder threads */
307 vlc_thread_set_priority( p_this, VLC_THREAD_PRIORITY_OUTPUT );
309 /* Allocate structure */
310 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
313 msg_Err( p_filter, "out of memory" );
317 p_filter->pf_sub_filter = Filter;
319 vlc_mutex_init( p_filter, &p_sys->lock );
320 vlc_mutex_lock( &p_sys->lock );
322 var_Create( p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
323 var_Get( p_libvlc, "mosaic-lock", &val );
324 p_sys->p_lock = val.p_address;
326 config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
329 #define GET_VAR( name, min, max ) \
330 p_sys->i_##name = __MIN( max, __MAX( min, \
331 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX #name ) ) ); \
332 var_AddCallback( p_filter, CFG_PREFIX #name, MosaicCallback, p_sys );
334 GET_VAR( width, 0, INT_MAX );
335 GET_VAR( height, 0, INT_MAX );
336 GET_VAR( xoffset, 0, INT_MAX );
337 GET_VAR( yoffset, 0, INT_MAX );
339 GET_VAR( align, 0, 10 );
340 if( p_sys->i_align == 3 || p_sys->i_align == 7 )
343 GET_VAR( borderw, 0, INT_MAX );
344 GET_VAR( borderh, 0, INT_MAX );
345 GET_VAR( rows, 1, INT_MAX );
346 GET_VAR( cols, 1, INT_MAX );
347 GET_VAR( alpha, 0, 255 );
348 GET_VAR( position, 0, 2 );
349 GET_VAR( delay, 100, INT_MAX );
350 p_sys->i_delay *= 1000;
352 p_sys->b_ar = var_CreateGetBoolCommand( p_filter,
353 CFG_PREFIX "keep-aspect-ratio" );
354 var_AddCallback( p_filter, CFG_PREFIX "keep-aspect-ratio", MosaicCallback,
357 p_sys->b_keep = var_CreateGetBoolCommand( p_filter,
358 CFG_PREFIX "keep-picture" );
359 if ( !p_sys->b_keep )
361 p_sys->p_image = image_HandlerCreate( p_filter );
364 p_sys->i_order_length = 0;
365 p_sys->ppsz_order = NULL;
366 psz_order = var_CreateGetStringCommand( p_filter, CFG_PREFIX "order" );
367 var_AddCallback( p_filter, CFG_PREFIX "order", MosaicCallback, p_sys );
371 char *psz_end = NULL;
375 psz_end = strchr( psz_order, ',' );
377 p_sys->ppsz_order = realloc( p_sys->ppsz_order,
378 i_index * sizeof(char *) );
379 p_sys->ppsz_order[i_index - 1] = strndup( psz_order,
380 psz_end - psz_order );
381 psz_order = psz_end+1;
383 p_sys->i_order_length = i_index;
386 /* Manage specific offsets for substreams */
387 psz_offsets = var_CreateGetStringCommand( p_filter, CFG_PREFIX "offsets" );
388 p_sys->i_offsets_length = 0;
389 p_sys->pi_x_offsets = NULL;
390 p_sys->pi_y_offsets = NULL;
391 mosaic_ParseSetOffsets( p_filter, p_sys, psz_offsets );
392 var_AddCallback( p_filter, CFG_PREFIX "offsets", MosaicCallback, p_sys );
394 vlc_mutex_unlock( &p_sys->lock );
399 /*****************************************************************************
400 * DestroyFilter: destroy mosaic video filter
401 *****************************************************************************/
402 static void DestroyFilter( vlc_object_t *p_this )
404 filter_t *p_filter = (filter_t*)p_this;
405 filter_sys_t *p_sys = p_filter->p_sys;
408 vlc_mutex_lock( &p_sys->lock );
412 image_HandlerDelete( p_sys->p_image );
415 if( p_sys->i_order_length )
417 for( i_index = 0; i_index < p_sys->i_order_length; i_index++ )
419 free( p_sys->ppsz_order[i_index] );
421 free( p_sys->ppsz_order );
423 if( p_sys->i_offsets_length )
425 free( p_sys->pi_x_offsets );
426 free( p_sys->pi_y_offsets );
427 p_sys->i_offsets_length = 0;
430 vlc_mutex_unlock( &p_sys->lock );
431 vlc_mutex_destroy( &p_sys->lock );
435 /*****************************************************************************
436 * MosaicReleasePicture : Hack to avoid picture duplication
437 *****************************************************************************/
438 static void MosaicReleasePicture( picture_t *p_picture )
440 picture_t *p_original_pic = (picture_t *)p_picture->p_sys;
442 p_original_pic->pf_release( p_original_pic );
445 /*****************************************************************************
447 *****************************************************************************/
448 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
450 filter_sys_t *p_sys = p_filter->p_sys;
455 int i_index, i_real_index, i_row, i_col;
456 int i_greatest_real_index_used = p_sys->i_order_length - 1;
458 unsigned int col_inner_width, row_inner_height;
460 subpicture_region_t *p_region;
461 subpicture_region_t *p_region_prev = NULL;
463 /* Allocate the subpicture internal data. */
464 p_spu = p_filter->pf_sub_buffer_new( p_filter );
470 /* Initialize subpicture */
471 p_spu->i_channel = 0;
472 p_spu->i_start = date;
474 p_spu->b_ephemer = VLC_TRUE;
475 p_spu->i_alpha = p_sys->i_alpha;
476 p_spu->i_flags = p_sys->i_align;
477 p_spu->b_absolute = VLC_FALSE;
479 vlc_mutex_lock( &p_sys->lock );
480 vlc_mutex_lock( p_sys->p_lock );
482 p_bridge = GetBridge( p_filter );
483 if ( p_bridge == NULL )
485 vlc_mutex_unlock( p_sys->p_lock );
486 vlc_mutex_unlock( &p_sys->lock );
490 if ( p_sys->i_position == position_offsets )
492 /* If we have either too much or not enough offsets, fall-back
493 * to automatic positioning. */
494 if ( p_sys->i_offsets_length != p_sys->i_order_length )
497 "Number of specified offsets (%d) does not match number "
498 "of input substreams in mosaic-order (%d), falling back "
499 "to mosaic-position=0",
500 p_sys->i_offsets_length, p_sys->i_order_length );
501 p_sys->i_position = position_auto;
505 if ( p_sys->i_position == position_auto )
507 int i_numpics = p_sys->i_order_length; /* keep slots and all */
508 for ( i_index = 0; i_index < p_bridge->i_es_num; i_index++ )
510 bridged_es_t *p_es = p_bridge->pp_es[i_index];
511 if ( !p_es->b_empty )
514 if( p_sys->i_order_length && p_es->psz_id != 0 )
516 /* We also want to leave slots for images given in
517 * mosaic-order that are not available in p_vout_picture */
519 for( i = 0; i < p_sys->i_order_length ; i++ )
521 if( !strcmp( p_sys->ppsz_order[i], p_es->psz_id ) )
531 p_sys->i_rows = ceil(sqrt( (double)i_numpics ));
532 p_sys->i_cols = ( i_numpics % p_sys->i_rows == 0 ?
533 i_numpics / p_sys->i_rows :
534 i_numpics / p_sys->i_rows + 1 );
537 col_inner_width = ( ( p_sys->i_width - ( p_sys->i_cols - 1 )
538 * p_sys->i_borderw ) / p_sys->i_cols );
539 row_inner_height = ( ( p_sys->i_height - ( p_sys->i_rows - 1 )
540 * p_sys->i_borderh ) / p_sys->i_rows );
544 for ( i_index = 0; i_index < p_bridge->i_es_num; i_index++ )
546 bridged_es_t *p_es = p_bridge->pp_es[i_index];
547 video_format_t fmt_in, fmt_out;
548 picture_t *p_converted;
550 memset( &fmt_in, 0, sizeof( video_format_t ) );
551 memset( &fmt_out, 0, sizeof( video_format_t ) );
556 while ( p_es->p_picture != NULL
557 && p_es->p_picture->date + p_sys->i_delay < date )
559 if ( p_es->p_picture->p_next != NULL )
561 picture_t *p_next = p_es->p_picture->p_next;
562 p_es->p_picture->pf_release( p_es->p_picture );
563 p_es->p_picture = p_next;
565 else if ( p_es->p_picture->date + p_sys->i_delay + BLANK_DELAY <
569 p_es->p_picture->pf_release( p_es->p_picture );
570 p_es->p_picture = NULL;
571 p_es->pp_last = &p_es->p_picture;
576 msg_Dbg( p_filter, "too late picture for %s (" I64Fd ")",
578 date - p_es->p_picture->date - p_sys->i_delay );
583 if ( p_es->p_picture == NULL )
586 if ( p_sys->i_order_length == 0 )
593 for ( i = 0; i <= p_sys->i_order_length; i++ )
595 if ( i == p_sys->i_order_length ) break;
596 if ( strcmp( p_es->psz_id, p_sys->ppsz_order[i] ) == 0 )
602 if ( i == p_sys->i_order_length )
603 i_real_index = ++i_greatest_real_index_used;
605 i_row = ( i_real_index / p_sys->i_cols ) % p_sys->i_rows;
606 i_col = i_real_index % p_sys->i_cols ;
608 if ( !p_sys->b_keep )
610 /* Convert the images */
611 fmt_in.i_chroma = p_es->p_picture->format.i_chroma;
612 fmt_in.i_height = p_es->p_picture->format.i_height;
613 fmt_in.i_width = p_es->p_picture->format.i_width;
615 fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
616 fmt_out.i_width = col_inner_width;
617 fmt_out.i_height = row_inner_height;
619 if( p_sys->b_ar ) /* keep aspect ratio */
621 if( (float)fmt_out.i_width / (float)fmt_out.i_height
622 > (float)fmt_in.i_width / (float)fmt_in.i_height )
624 fmt_out.i_width = ( fmt_out.i_height * fmt_in.i_width )
629 fmt_out.i_height = ( fmt_out.i_width * fmt_in.i_height )
634 fmt_out.i_visible_width = fmt_out.i_width;
635 fmt_out.i_visible_height = fmt_out.i_height;
637 p_converted = image_Convert( p_sys->p_image, p_es->p_picture,
642 "image resizing and chroma conversion failed" );
648 p_converted = p_es->p_picture;
649 p_converted->i_refcount++;
650 fmt_in.i_width = fmt_out.i_width = p_converted->format.i_width;
651 fmt_in.i_height = fmt_out.i_height = p_converted->format.i_height;
652 fmt_in.i_chroma = fmt_out.i_chroma = p_converted->format.i_chroma;
653 fmt_out.i_visible_width = fmt_out.i_width;
654 fmt_out.i_visible_height = fmt_out.i_height;
657 p_region = p_spu->pf_make_region( VLC_OBJECT(p_filter), &fmt_out,
661 msg_Err( p_filter, "cannot allocate SPU region" );
662 p_filter->pf_sub_buffer_del( p_filter, p_spu );
663 vlc_mutex_unlock( &p_sys->lock );
664 vlc_mutex_unlock( p_sys->p_lock );
668 /* HACK ALERT: let's fix the pointers to avoid picture duplication.
669 * This is necessary because p_region->picture is not a pointer
670 * as it ought to be. */
677 /* Keep a pointer to the original picture (and its refcount...). */
678 p_region->picture.p_sys = (picture_sys_t *)p_converted;
679 p_region->picture.pf_release = MosaicReleasePicture;
682 if( p_sys->i_position == position_offsets )
684 p_region->i_x = p_sys->pi_x_offsets[i_real_index];
686 else if( fmt_out.i_width > col_inner_width ||
687 p_sys->b_ar || p_sys->b_keep )
689 /* we don't have to center the video since it takes the
690 whole rectangle area or it's larger than the rectangle */
691 p_region->i_x = p_sys->i_xoffset
692 + i_col * ( p_sys->i_width / p_sys->i_cols )
693 + ( i_col * p_sys->i_borderw ) / p_sys->i_cols;
697 /* center the video in the dedicated rectangle */
698 p_region->i_x = p_sys->i_xoffset
699 + i_col * ( p_sys->i_width / p_sys->i_cols )
700 + ( i_col * p_sys->i_borderw ) / p_sys->i_cols
701 + ( col_inner_width - fmt_out.i_width ) / 2;
704 if( p_sys->i_position == position_offsets )
706 p_region->i_y = p_sys->pi_y_offsets[i_real_index];
708 else if( fmt_out.i_height < row_inner_height
709 || p_sys->b_ar || p_sys->b_keep )
711 /* we don't have to center the video since it takes the
712 whole rectangle area or it's taller than the rectangle */
713 p_region->i_y = p_sys->i_yoffset
714 + i_row * ( p_sys->i_height / p_sys->i_rows )
715 + ( i_row * p_sys->i_borderh ) / p_sys->i_rows;
719 /* center the video in the dedicated rectangle */
720 p_region->i_y = p_sys->i_yoffset
721 + i_row * ( p_sys->i_height / p_sys->i_rows )
722 + ( i_row * p_sys->i_borderh ) / p_sys->i_rows
723 + ( row_inner_height - fmt_out.i_height ) / 2;
725 p_region->i_align = p_sys->i_align;
727 if( p_region_prev == NULL )
729 p_spu->p_region = p_region;
733 p_region_prev->p_next = p_region;
736 p_region_prev = p_region;
739 vlc_mutex_unlock( p_sys->p_lock );
740 vlc_mutex_unlock( &p_sys->lock );
745 /*****************************************************************************
746 * Callback to update params on the fly
747 *****************************************************************************/
748 static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
749 vlc_value_t oldval, vlc_value_t newval,
752 filter_sys_t *p_sys = (filter_sys_t *) p_data;
754 #define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
755 if( VAR_IS( "alpha" ) )
757 vlc_mutex_lock( &p_sys->lock );
758 msg_Dbg( p_this, "changing alpha from %d/255 to %d/255",
759 p_sys->i_alpha, newval.i_int);
760 p_sys->i_alpha = __MIN( __MAX( newval.i_int, 0 ), 255 );
761 vlc_mutex_unlock( &p_sys->lock );
763 else if( VAR_IS( "height" ) )
765 vlc_mutex_lock( &p_sys->lock );
766 msg_Dbg( p_this, "changing height from %dpx to %dpx",
767 p_sys->i_height, newval.i_int );
768 p_sys->i_height = __MAX( newval.i_int, 0 );
769 vlc_mutex_unlock( &p_sys->lock );
771 else if( VAR_IS( "width" ) )
773 vlc_mutex_lock( &p_sys->lock );
774 msg_Dbg( p_this, "changing width from %dpx to %dpx",
775 p_sys->i_width, newval.i_int );
776 p_sys->i_width = __MAX( newval.i_int, 0 );
777 vlc_mutex_unlock( &p_sys->lock );
779 else if( VAR_IS( "xoffset" ) )
781 vlc_mutex_lock( &p_sys->lock );
782 msg_Dbg( p_this, "changing x offset from %dpx to %dpx",
783 p_sys->i_xoffset, newval.i_int );
784 p_sys->i_xoffset = __MAX( newval.i_int, 0 );
785 vlc_mutex_unlock( &p_sys->lock );
787 else if( VAR_IS( "yoffset" ) )
789 vlc_mutex_lock( &p_sys->lock );
790 msg_Dbg( p_this, "changing y offset from %dpx to %dpx",
791 p_sys->i_yoffset, newval.i_int );
792 p_sys->i_yoffset = __MAX( newval.i_int, 0 );
793 vlc_mutex_unlock( &p_sys->lock );
795 else if( VAR_IS( "align" ) )
797 int i_old = 0, i_new = 0;
798 vlc_mutex_lock( &p_sys->lock );
799 newval.i_int = __MIN( __MAX( newval.i_int, 0 ), 10 );
800 if( newval.i_int == 3 || newval.i_int == 7 )
802 while( pi_align_values[i_old] != p_sys->i_align ) i_old++;
803 while( pi_align_values[i_new] != newval.i_int ) i_new++;
804 msg_Dbg( p_this, "changing alignment from %d (%s) to %d (%s)",
805 p_sys->i_align, ppsz_align_descriptions[i_old],
806 newval.i_int, ppsz_align_descriptions[i_new] );
807 p_sys->i_align = newval.i_int;
808 vlc_mutex_unlock( &p_sys->lock );
810 else if( VAR_IS( "borderw" ) )
812 vlc_mutex_lock( &p_sys->lock );
813 msg_Dbg( p_this, "changing border width from %dpx to %dpx",
814 p_sys->i_borderw, newval.i_int );
815 p_sys->i_borderw = __MAX( newval.i_int, 0 );
816 vlc_mutex_unlock( &p_sys->lock );
818 else if( VAR_IS( "borderh" ) )
820 vlc_mutex_lock( &p_sys->lock );
821 msg_Dbg( p_this, "changing border height from %dpx to %dpx",
822 p_sys->i_borderh, newval.i_int );
823 p_sys->i_borderh = __MAX( newval.i_int, 0 );
824 vlc_mutex_unlock( &p_sys->lock );
826 else if( VAR_IS( "position" ) )
828 if( newval.i_int > 2 || newval.i_int < 0 )
831 "Position is either 0 (%s), 1 (%s) or 2 (%s)",
832 ppsz_pos_descriptions[0],
833 ppsz_pos_descriptions[1],
834 ppsz_pos_descriptions[2] );
838 vlc_mutex_lock( &p_sys->lock );
839 msg_Dbg( p_this, "changing position method from %d (%s) to %d (%s)",
840 p_sys->i_position, ppsz_pos_descriptions[p_sys->i_position],
841 newval.i_int, ppsz_pos_descriptions[newval.i_int]);
842 p_sys->i_position = newval.i_int;
843 vlc_mutex_unlock( &p_sys->lock );
846 else if( VAR_IS( "rows" ) )
848 vlc_mutex_lock( &p_sys->lock );
849 msg_Dbg( p_this, "changing number of rows from %d to %d",
850 p_sys->i_rows, newval.i_int );
851 p_sys->i_rows = __MAX( newval.i_int, 1 );
852 vlc_mutex_unlock( &p_sys->lock );
854 else if( VAR_IS( "cols" ) )
856 vlc_mutex_lock( &p_sys->lock );
857 msg_Dbg( p_this, "changing number of columns from %d to %d",
858 p_sys->i_cols, newval.i_int );
859 p_sys->i_cols = __MAX( newval.i_int, 1 );
860 vlc_mutex_unlock( &p_sys->lock );
862 else if( VAR_IS( "order" ) )
866 vlc_mutex_lock( &p_sys->lock );
867 msg_Dbg( p_this, "Changing mosaic order to %s", newval.psz_string );
869 psz_order = newval.psz_string;
871 while( p_sys->i_order_length-- )
873 free( p_sys->ppsz_order[p_sys->i_order_length] );
875 free( p_sys->ppsz_order );
876 p_sys->ppsz_order = NULL;
880 char *psz_end = NULL;
884 psz_end = strchr( psz_order, ',' );
886 p_sys->ppsz_order = realloc( p_sys->ppsz_order,
887 i_index * sizeof(char *) );
888 p_sys->ppsz_order[i_index - 1] = strndup( psz_order,
889 psz_end - psz_order );
890 psz_order = psz_end+1;
892 p_sys->i_order_length = i_index;
895 vlc_mutex_unlock( &p_sys->lock );
897 else if( VAR_IS( "offsets" ) )
899 vlc_mutex_lock( &p_sys->lock );
900 msg_Info( p_this, "Changing mosaic-offsets to %s", newval.psz_string );
902 if( p_sys->i_offsets_length != 0 )
904 p_sys->i_offsets_length = 0;
905 free( p_sys->pi_x_offsets );
906 free( p_sys->pi_y_offsets );
907 p_sys->pi_x_offsets = NULL;
908 p_sys->pi_y_offsets = NULL;
911 mosaic_ParseSetOffsets( p_this, p_sys, newval.psz_string );
913 vlc_mutex_unlock( &p_sys->lock );
915 else if( VAR_IS( "keep-aspect-ratio" ) )
917 vlc_mutex_lock( &p_sys->lock );
920 msg_Dbg( p_this, "keeping aspect ratio" );
925 msg_Dbg( p_this, "won't keep aspect ratio" );
928 vlc_mutex_unlock( &p_sys->lock );
930 else if( VAR_IS( "keep-picture" ) )
932 vlc_mutex_lock( &p_sys->lock );
933 p_sys->b_keep = newval.b_bool;
934 if ( !p_sys->b_keep && !p_sys->p_image )
936 p_sys->p_image = image_HandlerCreate( p_this );
938 vlc_mutex_unlock( &p_sys->lock );