1 /*****************************************************************************
2 * mosaic.c : Mosaic video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2004-2008 the VideoLAN team
7 * Authors: Antoine Cellerier <dionoea at videolan dot org>
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 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
37 #include <limits.h> /* INT_MAX */
39 #include "vlc_filter.h"
40 #include "vlc_image.h"
44 #define BLANK_DELAY INT64_C(1000000)
46 /*****************************************************************************
48 *****************************************************************************/
49 static int CreateFilter ( vlc_object_t * );
50 static void DestroyFilter ( vlc_object_t * );
51 static subpicture_t *Filter ( filter_t *, mtime_t );
53 static int MosaicCallback ( vlc_object_t *, char const *, vlc_value_t,
54 vlc_value_t, void * );
56 /*****************************************************************************
57 * filter_sys_t : filter descriptor
58 *****************************************************************************/
61 vlc_mutex_t lock; /* Internal filter lock */
62 vlc_mutex_t *p_lock; /* Pointer to mosaic bridge lock */
64 image_handler_t *p_image;
66 int i_position; /* Mosaic positioning method */
67 bool b_ar; /* Do we keep the aspect ratio ? */
68 bool b_keep; /* Do we keep the original picture format ? */
69 int i_width, i_height; /* Mosaic height and width */
70 int i_cols, i_rows; /* Mosaic rows and cols */
71 int i_align; /* Mosaic alignment in background video */
72 int i_xoffset, i_yoffset; /* Top left corner offset */
73 int i_borderw, i_borderh; /* Border width/height between miniatures */
74 int i_alpha; /* Subfilter alpha blending */
76 char **ppsz_order; /* List of picture-ids */
79 int *pi_x_offsets; /* List of substreams x offsets */
80 int *pi_y_offsets; /* List of substreams y offsets */
86 /*****************************************************************************
88 *****************************************************************************/
89 #define ALPHA_TEXT N_("Transparency")
90 #define ALPHA_LONGTEXT N_( \
91 "Transparency of the mosaic foreground pictures. " \
92 "0 means transparent, 255 opaque (default)." )
94 #define HEIGHT_TEXT N_("Height")
95 #define HEIGHT_LONGTEXT N_( "Total height of the mosaic, in pixels." )
96 #define WIDTH_TEXT N_("Width")
97 #define WIDTH_LONGTEXT N_( "Total width of the mosaic, in pixels." )
99 #define XOFFSET_TEXT N_("Top left corner X coordinate")
100 #define XOFFSET_LONGTEXT N_( \
101 "X Coordinate of the top-left corner of the mosaic.")
102 #define YOFFSET_TEXT N_("Top left corner Y coordinate")
103 #define YOFFSET_LONGTEXT N_( \
104 "Y Coordinate of the top-left corner of the mosaic.")
106 #define BORDERW_TEXT N_("Border width")
107 #define BORDERW_LONGTEXT N_( \
108 "Width in pixels of the border between miniatures." )
109 #define BORDERH_TEXT N_("Border height")
110 #define BORDERH_LONGTEXT N_( \
111 "Height in pixels of the border between miniatures." )
113 #define ALIGN_TEXT N_("Mosaic alignment" )
114 #define ALIGN_LONGTEXT N_( \
115 "You can enforce the mosaic alignment on the video " \
116 "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
117 "also use combinations of these values, eg 6 = top-right).")
119 #define POS_TEXT N_("Positioning method")
120 #define POS_LONGTEXT N_( \
121 "Positioning method for the mosaic. auto: " \
122 "automatically choose the best number of rows and columns. " \
123 "fixed: use the user-defined number of rows and columns. " \
124 "offsets: use the user-defined offsets for each image." )
126 #define ROWS_TEXT N_("Number of rows")
127 #define ROWS_LONGTEXT N_( \
128 "Number of image rows in the mosaic (only used if " \
129 "positionning method is set to \"fixed\")." )
131 #define COLS_TEXT N_("Number of columns")
132 #define COLS_LONGTEXT N_( \
133 "Number of image columns in the mosaic (only used if " \
134 "positionning method is set to \"fixed\"." )
136 #define AR_TEXT N_("Keep aspect ratio")
137 #define AR_LONGTEXT N_( \
138 "Keep the original aspect ratio when resizing " \
140 #define KEEP_TEXT N_("Keep original size")
141 #define KEEP_LONGTEXT N_( \
142 "Keep the original size of mosaic elements." )
144 #define ORDER_TEXT N_("Elements order" )
145 #define ORDER_LONGTEXT N_( \
146 "You can enforce the order of the elements on " \
147 "the mosaic. You must give a comma-separated list of picture ID(s)." \
148 "These IDs are assigned in the \"mosaic-bridge\" module." )
150 #define OFFSETS_TEXT N_("Offsets in order" )
151 #define OFFSETS_LONGTEXT N_( \
152 "You can enforce the (x,y) offsets of the elements on the mosaic " \
153 "(only used if positioning method is set to \"offsets\"). You " \
154 "must give a comma-separated list of coordinates (eg: 10,10,150,10)." )
156 #define DELAY_TEXT N_("Delay")
157 #define DELAY_LONGTEXT N_( \
158 "Pictures coming from the mosaic elements will be delayed " \
159 "according to this value (in milliseconds). For high " \
160 "values you will need to raise caching at input.")
164 position_auto = 0, position_fixed = 1, position_offsets = 2
166 static const int pi_pos_values[] = { 0, 1, 2 };
167 static const char *const ppsz_pos_descriptions[] =
168 { N_("auto"), N_("fixed"), N_("offsets") };
170 static const int pi_align_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
171 static const char *const ppsz_align_descriptions[] =
172 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
173 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
175 #define CFG_PREFIX "mosaic-"
178 set_description( N_("Mosaic video sub filter") );
179 set_shortname( N_("Mosaic") );
180 set_category( CAT_VIDEO );
181 set_subcategory( SUBCAT_VIDEO_SUBPIC);
182 set_capability( "sub filter", 0 );
183 set_callbacks( CreateFilter, DestroyFilter );
185 add_integer_with_range( CFG_PREFIX "alpha", 255, 0, 255, NULL,
186 ALPHA_TEXT, ALPHA_LONGTEXT, false );
188 add_integer( CFG_PREFIX "height", 100, NULL,
189 HEIGHT_TEXT, HEIGHT_LONGTEXT, false );
190 add_integer( CFG_PREFIX "width", 100, NULL,
191 WIDTH_TEXT, WIDTH_LONGTEXT, false );
193 add_integer( CFG_PREFIX "align", 5, NULL,
194 ALIGN_TEXT, ALIGN_LONGTEXT, true);
195 change_integer_list( pi_align_values, ppsz_align_descriptions, 0 );
197 add_integer( CFG_PREFIX "xoffset", 0, NULL,
198 XOFFSET_TEXT, XOFFSET_LONGTEXT, true );
199 add_integer( CFG_PREFIX "yoffset", 0, NULL,
200 YOFFSET_TEXT, YOFFSET_LONGTEXT, true );
202 add_integer( CFG_PREFIX "borderw", 0, NULL,
203 BORDERW_TEXT, BORDERW_LONGTEXT, true );
204 add_deprecated_alias( CFG_PREFIX "vborder" );
205 add_integer( CFG_PREFIX "borderh", 0, NULL,
206 BORDERH_TEXT, BORDERH_LONGTEXT, true );
207 add_deprecated_alias( CFG_PREFIX "hborder" );
209 add_integer( CFG_PREFIX "position", 0, NULL,
210 POS_TEXT, POS_LONGTEXT, false );
211 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
212 add_integer( CFG_PREFIX "rows", 2, NULL,
213 ROWS_TEXT, ROWS_LONGTEXT, false );
214 add_integer( CFG_PREFIX "cols", 2, NULL,
215 COLS_TEXT, COLS_LONGTEXT, false );
217 add_bool( CFG_PREFIX "keep-aspect-ratio", 0, NULL,
218 AR_TEXT, AR_LONGTEXT, false );
219 add_bool( CFG_PREFIX "keep-picture", 0, NULL,
220 KEEP_TEXT, KEEP_LONGTEXT, false );
222 add_string( CFG_PREFIX "order", "", NULL,
223 ORDER_TEXT, ORDER_LONGTEXT, false );
225 add_string( CFG_PREFIX "offsets", "", NULL,
226 OFFSETS_TEXT, OFFSETS_LONGTEXT, false );
228 add_integer( CFG_PREFIX "delay", 0, NULL, DELAY_TEXT, DELAY_LONGTEXT,
232 static const char *const ppsz_filter_options[] = {
233 "alpha", "height", "width", "align", "xoffset", "yoffset",
234 "borderw", "borderh", "position", "rows", "cols",
235 "keep-aspect-ratio", "keep-picture", "order", "offsets",
239 /*****************************************************************************
240 * mosaic_ParseSetOffsets:
241 * parse the "--mosaic-offsets x1,y1,x2,y2,x3,y3" parameter
242 * and set the corresponding struct filter_sys_t entries.
243 *****************************************************************************/
244 #define mosaic_ParseSetOffsets( a, b, c ) \
245 __mosaic_ParseSetOffsets( VLC_OBJECT( a ), b, c )
246 static void __mosaic_ParseSetOffsets( vlc_object_t *p_this,
252 char *psz_end = NULL;
258 p_sys->pi_x_offsets =
259 realloc( p_sys->pi_x_offsets, i_index * sizeof(int) );
260 p_sys->pi_x_offsets[i_index - 1] = atoi( psz_offsets );
261 psz_end = strchr( psz_offsets, ',' );
262 psz_offsets = psz_end + 1;
264 p_sys->pi_y_offsets =
265 realloc( p_sys->pi_y_offsets, i_index * sizeof(int) );
266 p_sys->pi_y_offsets[i_index - 1] = atoi( psz_offsets );
267 psz_end = strchr( psz_offsets, ',' );
268 psz_offsets = psz_end + 1;
270 msg_Dbg( p_this, CFG_PREFIX "offset: id %d, x=%d, y=%d",
271 i_index, p_sys->pi_x_offsets[i_index - 1],
272 p_sys->pi_y_offsets[i_index - 1] );
275 p_sys->i_offsets_length = i_index;
279 /*****************************************************************************
280 * CreateFiler: allocate mosaic video filter
281 *****************************************************************************/
282 static int CreateFilter( vlc_object_t *p_this )
284 filter_t *p_filter = (filter_t *)p_this;
286 vlc_object_t *p_libvlc = VLC_OBJECT( p_filter->p_libvlc );
287 char *psz_order, *_psz_order;
292 /* The mosaic thread is more important than the decoder threads */
293 vlc_thread_set_priority( p_this, VLC_THREAD_PRIORITY_OUTPUT );
295 /* Allocate structure */
296 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
299 msg_Err( p_filter, "out of memory" );
303 p_filter->pf_sub_filter = Filter;
305 vlc_mutex_init( &p_sys->lock );
306 vlc_mutex_lock( &p_sys->lock );
308 var_Create( p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
309 var_Get( p_libvlc, "mosaic-lock", &val );
310 p_sys->p_lock = val.p_address;
312 config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
315 #define GET_VAR( name, min, max ) \
316 p_sys->i_##name = __MIN( max, __MAX( min, \
317 var_CreateGetIntegerCommand( p_filter, CFG_PREFIX #name ) ) ); \
318 var_AddCallback( p_filter, CFG_PREFIX #name, MosaicCallback, p_sys );
320 GET_VAR( width, 0, INT_MAX );
321 GET_VAR( height, 0, INT_MAX );
322 GET_VAR( xoffset, 0, INT_MAX );
323 GET_VAR( yoffset, 0, INT_MAX );
325 GET_VAR( align, 0, 10 );
326 if( p_sys->i_align == 3 || p_sys->i_align == 7 )
329 GET_VAR( borderw, 0, INT_MAX );
330 GET_VAR( borderh, 0, INT_MAX );
331 GET_VAR( rows, 1, INT_MAX );
332 GET_VAR( cols, 1, INT_MAX );
333 GET_VAR( alpha, 0, 255 );
334 GET_VAR( position, 0, 2 );
335 GET_VAR( delay, 100, INT_MAX );
336 p_sys->i_delay *= 1000;
338 p_sys->b_ar = var_CreateGetBoolCommand( p_filter,
339 CFG_PREFIX "keep-aspect-ratio" );
340 var_AddCallback( p_filter, CFG_PREFIX "keep-aspect-ratio", MosaicCallback,
343 p_sys->b_keep = var_CreateGetBoolCommand( p_filter,
344 CFG_PREFIX "keep-picture" );
345 if ( !p_sys->b_keep )
347 p_sys->p_image = image_HandlerCreate( p_filter );
350 p_sys->i_order_length = 0;
351 p_sys->ppsz_order = NULL;
352 psz_order = var_CreateGetStringCommand( p_filter, CFG_PREFIX "order" );
353 _psz_order = psz_order;
354 var_AddCallback( p_filter, CFG_PREFIX "order", MosaicCallback, p_sys );
358 char *psz_end = NULL;
362 psz_end = strchr( psz_order, ',' );
364 p_sys->ppsz_order = realloc( p_sys->ppsz_order,
365 i_index * sizeof(char *) );
366 p_sys->ppsz_order[i_index - 1] = strndup( psz_order,
367 psz_end - psz_order );
368 psz_order = psz_end+1;
370 p_sys->i_order_length = i_index;
375 /* Manage specific offsets for substreams */
376 psz_offsets = var_CreateGetStringCommand( p_filter, CFG_PREFIX "offsets" );
377 p_sys->i_offsets_length = 0;
378 p_sys->pi_x_offsets = NULL;
379 p_sys->pi_y_offsets = NULL;
380 mosaic_ParseSetOffsets( p_filter, p_sys, psz_offsets );
382 var_AddCallback( p_filter, CFG_PREFIX "offsets", MosaicCallback, p_sys );
384 vlc_mutex_unlock( &p_sys->lock );
389 /*****************************************************************************
390 * DestroyFilter: destroy mosaic video filter
391 *****************************************************************************/
392 static void DestroyFilter( vlc_object_t *p_this )
394 filter_t *p_filter = (filter_t*)p_this;
395 filter_sys_t *p_sys = p_filter->p_sys;
398 vlc_mutex_lock( &p_sys->lock );
402 image_HandlerDelete( p_sys->p_image );
405 if( p_sys->i_order_length )
407 for( i_index = 0; i_index < p_sys->i_order_length; i_index++ )
409 free( p_sys->ppsz_order[i_index] );
411 free( p_sys->ppsz_order );
413 if( p_sys->i_offsets_length )
415 free( p_sys->pi_x_offsets );
416 free( p_sys->pi_y_offsets );
417 p_sys->i_offsets_length = 0;
420 vlc_mutex_unlock( &p_sys->lock );
421 vlc_mutex_destroy( &p_sys->lock );
425 /*****************************************************************************
426 * MosaicReleasePicture : Hack to avoid picture duplication
427 *****************************************************************************/
428 static void MosaicReleasePicture( picture_t *p_picture )
430 picture_t *p_original_pic = (picture_t *)p_picture->p_sys;
432 p_original_pic->pf_release( p_original_pic );
435 /*****************************************************************************
437 *****************************************************************************/
438 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
440 filter_sys_t *p_sys = p_filter->p_sys;
445 int i_index, i_real_index, i_row, i_col;
446 int i_greatest_real_index_used = p_sys->i_order_length - 1;
448 unsigned int col_inner_width, row_inner_height;
450 subpicture_region_t *p_region;
451 subpicture_region_t *p_region_prev = NULL;
453 /* Allocate the subpicture internal data. */
454 p_spu = p_filter->pf_sub_buffer_new( p_filter );
460 /* Initialize subpicture */
461 p_spu->i_channel = 0;
462 p_spu->i_start = date;
464 p_spu->b_ephemer = true;
465 p_spu->i_alpha = p_sys->i_alpha;
466 p_spu->i_flags = p_sys->i_align;
467 p_spu->b_absolute = false;
469 vlc_mutex_lock( &p_sys->lock );
470 vlc_mutex_lock( p_sys->p_lock );
472 p_bridge = GetBridge( p_filter );
473 if ( p_bridge == NULL )
475 vlc_mutex_unlock( p_sys->p_lock );
476 vlc_mutex_unlock( &p_sys->lock );
480 if ( p_sys->i_position == position_offsets )
482 /* If we have either too much or not enough offsets, fall-back
483 * to automatic positioning. */
484 if ( p_sys->i_offsets_length != p_sys->i_order_length )
487 "Number of specified offsets (%d) does not match number "
488 "of input substreams in mosaic-order (%d), falling back "
489 "to mosaic-position=0",
490 p_sys->i_offsets_length, p_sys->i_order_length );
491 p_sys->i_position = position_auto;
495 if ( p_sys->i_position == position_auto )
497 int i_numpics = p_sys->i_order_length; /* keep slots and all */
498 for ( i_index = 0; i_index < p_bridge->i_es_num; i_index++ )
500 bridged_es_t *p_es = p_bridge->pp_es[i_index];
501 if ( !p_es->b_empty )
504 if( p_sys->i_order_length && p_es->psz_id != 0 )
506 /* We also want to leave slots for images given in
507 * mosaic-order that are not available in p_vout_picture */
509 for( i = 0; i < p_sys->i_order_length ; i++ )
511 if( !strcmp( p_sys->ppsz_order[i], p_es->psz_id ) )
521 p_sys->i_rows = ceil(sqrt( (double)i_numpics ));
522 p_sys->i_cols = ( i_numpics % p_sys->i_rows == 0 ?
523 i_numpics / p_sys->i_rows :
524 i_numpics / p_sys->i_rows + 1 );
527 col_inner_width = ( ( p_sys->i_width - ( p_sys->i_cols - 1 )
528 * p_sys->i_borderw ) / p_sys->i_cols );
529 row_inner_height = ( ( p_sys->i_height - ( p_sys->i_rows - 1 )
530 * p_sys->i_borderh ) / p_sys->i_rows );
534 for ( i_index = 0; i_index < p_bridge->i_es_num; i_index++ )
536 bridged_es_t *p_es = p_bridge->pp_es[i_index];
537 video_format_t fmt_in, fmt_out;
538 picture_t *p_converted;
540 memset( &fmt_in, 0, sizeof( video_format_t ) );
541 memset( &fmt_out, 0, sizeof( video_format_t ) );
546 while ( p_es->p_picture != NULL
547 && p_es->p_picture->date + p_sys->i_delay < date )
549 if ( p_es->p_picture->p_next != NULL )
551 picture_t *p_next = p_es->p_picture->p_next;
552 p_es->p_picture->pf_release( p_es->p_picture );
553 p_es->p_picture = p_next;
555 else if ( p_es->p_picture->date + p_sys->i_delay + BLANK_DELAY <
559 p_es->p_picture->pf_release( p_es->p_picture );
560 p_es->p_picture = NULL;
561 p_es->pp_last = &p_es->p_picture;
566 msg_Dbg( p_filter, "too late picture for %s (%"PRId64 ")",
568 date - p_es->p_picture->date - p_sys->i_delay );
573 if ( p_es->p_picture == NULL )
576 if ( p_sys->i_order_length == 0 )
583 for ( i = 0; i <= p_sys->i_order_length; i++ )
585 if ( i == p_sys->i_order_length ) break;
586 if ( strcmp( p_es->psz_id, p_sys->ppsz_order[i] ) == 0 )
592 if ( i == p_sys->i_order_length )
593 i_real_index = ++i_greatest_real_index_used;
595 i_row = ( i_real_index / p_sys->i_cols ) % p_sys->i_rows;
596 i_col = i_real_index % p_sys->i_cols ;
598 if ( !p_sys->b_keep )
600 /* Convert the images */
601 fmt_in.i_chroma = p_es->p_picture->format.i_chroma;
602 fmt_in.i_height = p_es->p_picture->format.i_height;
603 fmt_in.i_width = p_es->p_picture->format.i_width;
605 fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
606 fmt_out.i_width = col_inner_width;
607 fmt_out.i_height = row_inner_height;
609 if( p_sys->b_ar ) /* keep aspect ratio */
611 if( (float)fmt_out.i_width / (float)fmt_out.i_height
612 > (float)fmt_in.i_width / (float)fmt_in.i_height )
614 fmt_out.i_width = ( fmt_out.i_height * fmt_in.i_width )
619 fmt_out.i_height = ( fmt_out.i_width * fmt_in.i_height )
624 fmt_out.i_visible_width = fmt_out.i_width;
625 fmt_out.i_visible_height = fmt_out.i_height;
627 p_converted = image_Convert( p_sys->p_image, p_es->p_picture,
632 "image resizing and chroma conversion failed" );
638 p_converted = p_es->p_picture;
639 p_converted->i_refcount++;
640 fmt_in.i_width = fmt_out.i_width = p_converted->format.i_width;
641 fmt_in.i_height = fmt_out.i_height = p_converted->format.i_height;
642 fmt_in.i_chroma = fmt_out.i_chroma = p_converted->format.i_chroma;
643 fmt_out.i_visible_width = fmt_out.i_width;
644 fmt_out.i_visible_height = fmt_out.i_height;
647 p_region = p_spu->pf_make_region( VLC_OBJECT(p_filter), &fmt_out,
651 msg_Err( p_filter, "cannot allocate SPU region" );
652 p_filter->pf_sub_buffer_del( p_filter, p_spu );
653 vlc_mutex_unlock( &p_sys->lock );
654 vlc_mutex_unlock( p_sys->p_lock );
658 /* HACK ALERT: let's fix the pointers to avoid picture duplication.
659 * This is necessary because p_region->picture is not a pointer
660 * as it ought to be. */
667 /* Keep a pointer to the original picture (and its refcount...). */
668 p_region->picture.p_sys = (picture_sys_t *)p_converted;
669 p_region->picture.pf_release = MosaicReleasePicture;
672 if( p_es->i_x >= 0 && p_es->i_y >= 0 )
674 p_region->i_x = p_es->i_x;
675 p_region->i_y = p_es->i_y;
677 else if( p_sys->i_position == position_offsets )
679 p_region->i_x = p_sys->pi_x_offsets[i_real_index];
680 p_region->i_y = p_sys->pi_y_offsets[i_real_index];
684 if( fmt_out.i_width > col_inner_width ||
685 p_sys->b_ar || p_sys->b_keep )
687 /* we don't have to center the video since it takes the
688 whole rectangle area or it's larger than the rectangle */
689 p_region->i_x = p_sys->i_xoffset
690 + i_col * ( p_sys->i_width / p_sys->i_cols )
691 + ( i_col * p_sys->i_borderw ) / p_sys->i_cols;
695 /* center the video in the dedicated rectangle */
696 p_region->i_x = p_sys->i_xoffset
697 + i_col * ( p_sys->i_width / p_sys->i_cols )
698 + ( i_col * p_sys->i_borderw ) / p_sys->i_cols
699 + ( col_inner_width - fmt_out.i_width ) / 2;
702 if( fmt_out.i_height > row_inner_height
703 || p_sys->b_ar || p_sys->b_keep )
705 /* we don't have to center the video since it takes the
706 whole rectangle area or it's taller than the rectangle */
707 p_region->i_y = p_sys->i_yoffset
708 + i_row * ( p_sys->i_height / p_sys->i_rows )
709 + ( i_row * p_sys->i_borderh ) / p_sys->i_rows;
713 /* center the video in the dedicated rectangle */
714 p_region->i_y = p_sys->i_yoffset
715 + i_row * ( p_sys->i_height / p_sys->i_rows )
716 + ( i_row * p_sys->i_borderh ) / p_sys->i_rows
717 + ( row_inner_height - fmt_out.i_height ) / 2;
720 p_region->i_align = p_sys->i_align;
721 p_region->i_alpha = p_es->i_alpha;
723 if( p_region_prev == NULL )
725 p_spu->p_region = p_region;
729 p_region_prev->p_next = p_region;
732 p_region_prev = p_region;
735 vlc_mutex_unlock( p_sys->p_lock );
736 vlc_mutex_unlock( &p_sys->lock );
741 /*****************************************************************************
742 * Callback to update params on the fly
743 *****************************************************************************/
744 static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
745 vlc_value_t oldval, vlc_value_t newval,
749 filter_sys_t *p_sys = (filter_sys_t *) p_data;
751 #define VAR_IS( a ) !strcmp( psz_var, CFG_PREFIX a )
752 if( VAR_IS( "alpha" ) )
754 vlc_mutex_lock( &p_sys->lock );
755 msg_Dbg( p_this, "changing alpha from %d/255 to %d/255",
756 p_sys->i_alpha, newval.i_int);
757 p_sys->i_alpha = __MIN( __MAX( newval.i_int, 0 ), 255 );
758 vlc_mutex_unlock( &p_sys->lock );
760 else if( VAR_IS( "height" ) )
762 vlc_mutex_lock( &p_sys->lock );
763 msg_Dbg( p_this, "changing height from %dpx to %dpx",
764 p_sys->i_height, newval.i_int );
765 p_sys->i_height = __MAX( newval.i_int, 0 );
766 vlc_mutex_unlock( &p_sys->lock );
768 else if( VAR_IS( "width" ) )
770 vlc_mutex_lock( &p_sys->lock );
771 msg_Dbg( p_this, "changing width from %dpx to %dpx",
772 p_sys->i_width, newval.i_int );
773 p_sys->i_width = __MAX( newval.i_int, 0 );
774 vlc_mutex_unlock( &p_sys->lock );
776 else if( VAR_IS( "xoffset" ) )
778 vlc_mutex_lock( &p_sys->lock );
779 msg_Dbg( p_this, "changing x offset from %dpx to %dpx",
780 p_sys->i_xoffset, newval.i_int );
781 p_sys->i_xoffset = __MAX( newval.i_int, 0 );
782 vlc_mutex_unlock( &p_sys->lock );
784 else if( VAR_IS( "yoffset" ) )
786 vlc_mutex_lock( &p_sys->lock );
787 msg_Dbg( p_this, "changing y offset from %dpx to %dpx",
788 p_sys->i_yoffset, newval.i_int );
789 p_sys->i_yoffset = __MAX( newval.i_int, 0 );
790 vlc_mutex_unlock( &p_sys->lock );
792 else if( VAR_IS( "align" ) )
794 int i_old = 0, i_new = 0;
795 vlc_mutex_lock( &p_sys->lock );
796 newval.i_int = __MIN( __MAX( newval.i_int, 0 ), 10 );
797 if( newval.i_int == 3 || newval.i_int == 7 )
799 while( pi_align_values[i_old] != p_sys->i_align ) i_old++;
800 while( pi_align_values[i_new] != newval.i_int ) i_new++;
801 msg_Dbg( p_this, "changing alignment from %d (%s) to %d (%s)",
802 p_sys->i_align, ppsz_align_descriptions[i_old],
803 newval.i_int, ppsz_align_descriptions[i_new] );
804 p_sys->i_align = newval.i_int;
805 vlc_mutex_unlock( &p_sys->lock );
807 else if( VAR_IS( "borderw" ) )
809 vlc_mutex_lock( &p_sys->lock );
810 msg_Dbg( p_this, "changing border width from %dpx to %dpx",
811 p_sys->i_borderw, newval.i_int );
812 p_sys->i_borderw = __MAX( newval.i_int, 0 );
813 vlc_mutex_unlock( &p_sys->lock );
815 else if( VAR_IS( "borderh" ) )
817 vlc_mutex_lock( &p_sys->lock );
818 msg_Dbg( p_this, "changing border height from %dpx to %dpx",
819 p_sys->i_borderh, newval.i_int );
820 p_sys->i_borderh = __MAX( newval.i_int, 0 );
821 vlc_mutex_unlock( &p_sys->lock );
823 else if( VAR_IS( "position" ) )
825 if( newval.i_int > 2 || newval.i_int < 0 )
828 "Position is either 0 (%s), 1 (%s) or 2 (%s)",
829 ppsz_pos_descriptions[0],
830 ppsz_pos_descriptions[1],
831 ppsz_pos_descriptions[2] );
835 vlc_mutex_lock( &p_sys->lock );
836 msg_Dbg( p_this, "changing position method from %d (%s) to %d (%s)",
837 p_sys->i_position, ppsz_pos_descriptions[p_sys->i_position],
838 newval.i_int, ppsz_pos_descriptions[newval.i_int]);
839 p_sys->i_position = newval.i_int;
840 vlc_mutex_unlock( &p_sys->lock );
843 else if( VAR_IS( "rows" ) )
845 vlc_mutex_lock( &p_sys->lock );
846 msg_Dbg( p_this, "changing number of rows from %d to %d",
847 p_sys->i_rows, newval.i_int );
848 p_sys->i_rows = __MAX( newval.i_int, 1 );
849 vlc_mutex_unlock( &p_sys->lock );
851 else if( VAR_IS( "cols" ) )
853 vlc_mutex_lock( &p_sys->lock );
854 msg_Dbg( p_this, "changing number of columns from %d to %d",
855 p_sys->i_cols, newval.i_int );
856 p_sys->i_cols = __MAX( newval.i_int, 1 );
857 vlc_mutex_unlock( &p_sys->lock );
859 else if( VAR_IS( "order" ) )
863 vlc_mutex_lock( &p_sys->lock );
864 msg_Dbg( p_this, "Changing mosaic order to %s", newval.psz_string );
866 psz_order = newval.psz_string;
868 while( p_sys->i_order_length-- )
870 free( p_sys->ppsz_order[p_sys->i_order_length] );
872 free( p_sys->ppsz_order );
873 p_sys->ppsz_order = NULL;
877 char *psz_end = NULL;
881 psz_end = strchr( psz_order, ',' );
883 p_sys->ppsz_order = realloc( p_sys->ppsz_order,
884 i_index * sizeof(char *) );
885 p_sys->ppsz_order[i_index - 1] = strndup( psz_order,
886 psz_end - psz_order );
887 psz_order = psz_end+1;
889 p_sys->i_order_length = i_index;
892 vlc_mutex_unlock( &p_sys->lock );
894 else if( VAR_IS( "offsets" ) )
896 vlc_mutex_lock( &p_sys->lock );
897 msg_Info( p_this, "Changing mosaic-offsets to %s", newval.psz_string );
899 if( p_sys->i_offsets_length != 0 )
901 p_sys->i_offsets_length = 0;
902 free( p_sys->pi_x_offsets );
903 free( p_sys->pi_y_offsets );
904 p_sys->pi_x_offsets = NULL;
905 p_sys->pi_y_offsets = NULL;
908 mosaic_ParseSetOffsets( p_this, p_sys, newval.psz_string );
910 vlc_mutex_unlock( &p_sys->lock );
912 else if( VAR_IS( "keep-aspect-ratio" ) )
914 vlc_mutex_lock( &p_sys->lock );
917 msg_Dbg( p_this, "keeping aspect ratio" );
922 msg_Dbg( p_this, "won't keep aspect ratio" );
925 vlc_mutex_unlock( &p_sys->lock );
927 else if( VAR_IS( "keep-picture" ) )
929 vlc_mutex_lock( &p_sys->lock );
930 p_sys->b_keep = newval.b_bool;
931 if ( !p_sys->b_keep && !p_sys->p_image )
933 p_sys->p_image = image_HandlerCreate( p_this );
935 vlc_mutex_unlock( &p_sys->lock );