]> git.sesse.net Git - vlc/blob - modules/video_filter/mosaic.c
d54fecd9f5620d0432dbacd6a82d26ea00df8666
[vlc] / modules / video_filter / mosaic.c
1 /*****************************************************************************
2  * mosaic.c : Mosaic video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2004-2005 VideoLAN
5  * $Id$
6  *
7  * Authors: Antoine Cellerier <dionoea@via.ecp.fr>
8  *          Christophe Massiot <massiot@via.ecp.fr>
9  *
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.
14  *
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.
19  *
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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23 *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include <stdlib.h>                                      /* malloc(), free() */
29 #include <string.h>
30 #include <math.h>
31
32 #include <vlc/vlc.h>
33 #include <vlc/vout.h>
34
35 #include "vlc_filter.h"
36 #include "vlc_image.h"
37
38 #include "../video_output/picture.h"
39
40 /*****************************************************************************
41  * Local prototypes
42  *****************************************************************************/
43 static int  CreateFilter    ( vlc_object_t * );
44 static void DestroyFilter   ( vlc_object_t * );
45
46 static subpicture_t *Filter( filter_t *, mtime_t );
47
48 static int MosaicCallback( vlc_object_t *, char const *, vlc_value_t,
49                            vlc_value_t, void * );
50
51 /*****************************************************************************
52  * filter_sys_t : filter descriptor
53  *****************************************************************************/
54 struct filter_sys_t
55 {
56     image_handler_t *p_image;
57 #ifdef IMAGE_2PASSES
58     image_handler_t *p_image2;
59 #endif
60     picture_t *p_pic;
61
62     int i_position; /* mosaic positioning method */
63     vlc_bool_t b_ar; /* do we keep the aspect ratio ? */
64     vlc_bool_t b_keep; /* do we keep the original picture format ? */
65     int i_width, i_height; /* mosaic height and width */
66     int i_cols, i_rows; /* mosaic rows and cols */
67     int i_xoffset, i_yoffset; /* top left corner offset */
68     int i_vborder, i_hborder; /* border width/height between miniatures */
69     int i_alpha; /* subfilter alpha blending */
70
71     char **ppsz_order; /* list of picture-id */
72     int i_order_length;
73
74     mtime_t i_delay;
75 };
76
77 /*****************************************************************************
78  * Module descriptor
79  *****************************************************************************/
80 #define ALPHA_TEXT N_("Alpha blending")
81 #define ALPHA_LONGTEXT N_("Alpha blending (0 -> 255). Default is 255")
82
83 #define HEIGHT_TEXT N_("Height in pixels")
84 #define WIDTH_TEXT N_("Width in pixels")
85 #define XOFFSET_TEXT N_("Top left corner x coordinate")
86 #define YOFFSET_TEXT N_("Top left corner y coordinate")
87 #define VBORDER_TEXT N_("Vertical border width in pixels")
88 #define HBORDER_TEXT N_("Horizontal border width in pixels")
89
90 #define POS_TEXT N_("Positioning method")
91 #define POS_LONGTEXT N_("Positioning method. auto : automatically choose " \
92         "the best number of rows and columns. fixed : use the user-defined " \
93         "number of rows and columns.")
94 #define ROWS_TEXT N_("Number of rows")
95 #define COLS_TEXT N_("Number of columns")
96 #define AR_TEXT N_("Keep aspect ratio when resizing")
97 #define KEEP_TEXT N_("Keep original size")
98
99 #define ORDER_TEXT N_("Order as a comma separated list of picture-id(s)")
100
101 #define DELAY_TEXT N_("Delay")
102 #define DELAY_LONGTEXT N_("Pictures coming from the picture video outputs " \
103         "will be delayed accordingly (in milliseconds, >= 100 ms). For high " \
104         "values you will need to raise file-caching and others.")
105
106 static int pi_pos_values[] = { 0, 1 };
107 static char * ppsz_pos_descriptions[] =
108 { N_("auto"), N_("fixed") };
109
110
111 vlc_module_begin();
112     set_description( N_("Mosaic video sub filter") );
113     set_shortname( N_("Mosaic") );
114     set_capability( "sub filter", 0 );
115     set_callbacks( CreateFilter, DestroyFilter );
116
117     add_integer( "mosaic-alpha", 255, NULL, ALPHA_TEXT, ALPHA_LONGTEXT, VLC_FALSE );
118     add_integer( "mosaic-height", 100, NULL, HEIGHT_TEXT, HEIGHT_TEXT, VLC_FALSE );
119     add_integer( "mosaic-width", 100, NULL, WIDTH_TEXT, WIDTH_TEXT, VLC_FALSE );
120     add_integer( "mosaic-xoffset", 0, NULL, XOFFSET_TEXT, XOFFSET_TEXT, VLC_TRUE );
121     add_integer( "mosaic-yoffset", 0, NULL, YOFFSET_TEXT, YOFFSET_TEXT, VLC_TRUE );
122     add_integer( "mosaic-vborder", 0, NULL, VBORDER_TEXT, VBORDER_TEXT, VLC_TRUE );
123     add_integer( "mosaic-hborder", 0, NULL, HBORDER_TEXT, HBORDER_TEXT, VLC_TRUE );
124
125     add_integer( "mosaic-position", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
126         change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
127     add_integer( "mosaic-rows", 2, NULL, ROWS_TEXT, ROWS_TEXT, VLC_FALSE );
128     add_integer( "mosaic-cols", 2, NULL, COLS_TEXT, COLS_TEXT, VLC_FALSE );
129     add_bool( "mosaic-keep-aspect-ratio", 0, NULL, AR_TEXT, AR_TEXT, VLC_FALSE );
130     add_bool( "mosaic-keep-picture", 0, NULL, KEEP_TEXT, KEEP_TEXT, VLC_FALSE );
131     add_string( "mosaic-order", "", NULL, ORDER_TEXT, ORDER_TEXT, VLC_FALSE );
132
133     add_integer( "mosaic-delay", 100, NULL, DELAY_TEXT, DELAY_LONGTEXT,
134                  VLC_FALSE );
135 vlc_module_end();
136
137
138 /*****************************************************************************
139  * CreateFiler: allocate mosaic video filter
140  *****************************************************************************/
141 static int CreateFilter( vlc_object_t *p_this )
142 {
143     filter_t *p_filter = (filter_t *)p_this;
144     filter_sys_t *p_sys;
145     libvlc_t *p_libvlc = p_filter->p_libvlc;
146     char *psz_order;
147     int i_index;
148
149     /* Allocate structure */
150     p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
151     if( p_sys == NULL )
152     {
153         msg_Err( p_filter, "out of memory" );
154         return VLC_ENOMEM;
155     }
156
157     p_filter->pf_sub_filter = Filter;
158     p_sys->p_pic = NULL;
159
160 #define GET_VAR( name, min, max )                                           \
161     p_sys->i_##name = __MIN( max, __MAX( min,                               \
162                 var_CreateGetInteger( p_filter, "mosaic-" #name ) ) );      \
163     var_Destroy( p_filter, "mosaic-" #name );                               \
164     var_Create( p_libvlc, "mosaic-" #name, VLC_VAR_INTEGER );               \
165     var_SetInteger( p_libvlc, "mosaic-" #name, p_sys->i_##name );           \
166     var_AddCallback( p_libvlc, "mosaic-" #name, MosaicCallback, p_sys );
167
168     GET_VAR( width, 0, INT32_MAX );
169     GET_VAR( height, 0, INT32_MAX );
170     GET_VAR( xoffset, 0, INT32_MAX );
171     GET_VAR( yoffset, 0, INT32_MAX );
172     GET_VAR( vborder, 0, INT32_MAX );
173     GET_VAR( hborder, 0, INT32_MAX );
174     GET_VAR( rows, 1, INT32_MAX );
175     GET_VAR( cols, 1, INT32_MAX );
176     GET_VAR( alpha, 0, 255 );
177     GET_VAR( position, 0, 1 );
178     GET_VAR( delay, 100, INT32_MAX );
179     p_sys->i_delay *= 1000;
180
181     p_sys->b_ar = var_CreateGetBool( p_filter, "mosaic-keep-aspect-ratio" );
182     var_Destroy( p_filter, "mosaic-keep-aspect-ratio" );
183     var_Create( p_libvlc, "mosaic-keep-aspect-ratio", VLC_VAR_INTEGER );
184     var_SetBool( p_libvlc, "mosaic-keep-aspect-ratio", p_sys->b_ar );
185     var_AddCallback( p_libvlc, "mosaic-keep-aspect-ratio", MosaicCallback,
186                      p_sys );
187
188     p_sys->b_keep = var_CreateGetBool( p_filter, "mosaic-keep-picture" );
189     if ( !p_sys->b_keep )
190     {
191         p_sys->p_image = image_HandlerCreate( p_filter );
192 #ifdef IMAGE_2PASSES
193         p_sys->p_image2 = image_HandlerCreate( p_filter );
194 #endif
195     }
196
197     p_sys->i_order_length = 0;
198     p_sys->ppsz_order = NULL;
199     psz_order = var_CreateGetString( p_filter, "mosaic-order" );
200
201     if( psz_order[0] != 0 )
202     {
203         char *psz_end = NULL;
204         i_index = 0;
205         do
206         { 
207             psz_end = strchr( psz_order, ',' );
208             i_index++;
209             p_sys->ppsz_order = realloc( p_sys->ppsz_order,
210                                          i_index * sizeof(char *) );
211             p_sys->ppsz_order[i_index - 1] = strndup( psz_order,
212                                            psz_end - psz_order );
213             psz_order = psz_end+1;
214         } while( NULL !=  psz_end );
215         p_sys->i_order_length = i_index;
216     }
217
218     vlc_thread_set_priority( p_filter, VLC_THREAD_PRIORITY_OUTPUT );
219
220     return VLC_SUCCESS;
221 }
222
223 /*****************************************************************************
224  * DestroyFilter: destroy mosaic video filter
225  *****************************************************************************/
226 static void DestroyFilter( vlc_object_t *p_this )
227 {
228     filter_t *p_filter = (filter_t*)p_this;
229     filter_sys_t *p_sys = p_filter->p_sys;
230     libvlc_t *p_libvlc = p_filter->p_libvlc;
231     int i_index;
232
233     if( !p_sys->b_keep )
234     {
235         image_HandlerDelete( p_sys->p_image );
236 #ifdef IMAGE_2PASSES
237         image_HandlerDelete( p_sys->p_image2 );
238 #endif
239     }
240
241     if( p_sys->i_order_length )
242     {
243         for( i_index = 0; i_index < p_sys->i_order_length; i_index++ )
244         {
245             free( p_sys->ppsz_order[i_index] );
246         }
247         free( p_sys->ppsz_order );
248     }
249
250     var_Destroy( p_libvlc, "mosaic-alpha" );
251     var_Destroy( p_libvlc, "mosaic-height" );
252     var_Destroy( p_libvlc, "mosaic-width" );
253     var_Destroy( p_libvlc, "mosaic-xoffset" );
254     var_Destroy( p_libvlc, "mosaic-yoffset" );
255     var_Destroy( p_libvlc, "mosaic-vborder" );
256     var_Destroy( p_libvlc, "mosaic-hborder" );
257     var_Destroy( p_libvlc, "mosaic-position" );
258     var_Destroy( p_libvlc, "mosaic-rows" );
259     var_Destroy( p_libvlc, "mosaic-cols" );
260     var_Destroy( p_libvlc, "mosaic-keep-aspect-ratio" );
261
262     if( p_sys->p_pic ) p_sys->p_pic->pf_release( p_sys->p_pic );
263     free( p_sys );
264 }
265
266 /*****************************************************************************
267  * MosaicReleasePicture : Hack to avoid picture duplication
268  *****************************************************************************/
269 static void MosaicReleasePicture( picture_t *p_picture )
270 {
271     picture_t *p_original_pic = (picture_t *)p_picture->p_sys;
272
273     p_original_pic->pf_release( p_original_pic );
274 }
275
276 /*****************************************************************************
277  * Filter
278  *****************************************************************************/
279 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
280 {
281     filter_sys_t *p_sys = p_filter->p_sys;
282     libvlc_t *p_libvlc = p_filter->p_libvlc;
283
284     subpicture_t *p_spu;
285
286     int i_index, i_real_index, i_row, i_col;
287     int i_greatest_real_index_used = p_sys->i_order_length - 1;
288
289     subpicture_region_t *p_region;
290     subpicture_region_t *p_region_prev = NULL;
291
292     picture_vout_t *p_picture_vout;
293     vlc_value_t val, lockval;
294
295     /* Wait for the specified date. This is to avoid running too fast and
296      * take twice the same pictures. */
297     mwait( date - p_sys->i_delay );
298
299     if ( var_Get( p_libvlc, "picture-lock", &lockval ) )
300         return NULL;
301
302     vlc_mutex_lock( lockval.p_address );
303
304     if( var_Get( p_libvlc, "p_picture_vout", &val ) )
305     {
306         vlc_mutex_unlock( lockval.p_address );
307         return NULL;
308     }
309
310     p_picture_vout = val.p_address;
311
312     /* Allocate the subpicture internal data. */
313     p_spu = p_filter->pf_sub_buffer_new( p_filter );
314     if( !p_spu )
315     {
316         return NULL;
317     }
318
319     /* Initialize subpicture */
320     p_spu->i_channel = 0;
321     p_spu->i_start  = date;
322     p_spu->i_stop = 0;
323     p_spu->b_ephemer = VLC_TRUE;
324     p_spu->i_alpha = p_sys->i_alpha;
325
326     if( p_sys->i_position == 0 ) /* use automatic positioning */
327     {
328         int i_numpics = p_sys->i_order_length; /* keep slots and all */
329         for( i_index = 0;
330              i_index < p_picture_vout->i_picture_num;
331              i_index++ )
332         {
333             if( p_picture_vout->p_pic[i_index].i_status
334                            == PICTURE_VOUT_E_OCCUPIED )
335             {
336                 i_numpics ++;
337                 if( p_sys->i_order_length
338                     && p_picture_vout->p_pic[i_index].psz_id != 0 )
339                 {
340                     /* We also want to leave slots for images given in
341                      * mosaic-order that are not available in p_vout_picture */
342                     int i;
343                     for( i = 0; i < p_sys->i_order_length ; i++ )
344                     {
345                         if( !strcmp( p_sys->ppsz_order[i],
346                                      p_picture_vout->p_pic[i_index].psz_id ) )
347                         {
348                             i_numpics--;
349                             break;
350                         }
351                     }
352
353                 }
354             }
355         }
356         p_sys->i_rows = ((int)ceil(sqrt( (float)i_numpics )));
357         p_sys->i_cols = ( i_numpics % p_sys->i_rows == 0 ?
358                             i_numpics / p_sys->i_rows :
359                             i_numpics / p_sys->i_rows + 1 );
360     }
361
362     i_real_index = 0;
363
364     for( i_index = 0; i_index < p_picture_vout->i_picture_num; i_index++ )
365     {
366         picture_vout_e_t *p_pic = &p_picture_vout->p_pic[i_index];
367         video_format_t fmt_in = {0}, fmt_out = {0};
368         picture_t *p_converted;
369 #ifdef IMAGE_2PASSES
370         video_format_t fmt_middle = {0};
371         picture_t *p_middle;
372 #endif
373
374         if( p_pic->i_status == PICTURE_VOUT_E_AVAILABLE
375              || p_pic->p_picture == NULL )
376         {
377             continue;
378         }
379
380         if( p_sys->i_order_length == 0 )
381         {
382             i_real_index++;
383         }
384         else
385         {
386             int i;
387             for( i = 0; i <= p_sys->i_order_length; i++ )
388             {
389                 if( i == p_sys->i_order_length ) break;
390                 if( strcmp( p_pic->psz_id, p_sys->ppsz_order[i] ) == 0 )
391                 {
392                     i_real_index = i;
393                     break;
394                 }
395             }
396             if( i == p_sys->i_order_length )
397                 i_real_index = ++i_greatest_real_index_used;
398         }
399         i_row = ( i_real_index / p_sys->i_cols ) % p_sys->i_rows;
400         i_col = i_real_index % p_sys->i_cols ;
401
402         if( !p_sys->b_keep )
403         {
404             /* Convert the images */
405             fmt_in.i_chroma = p_pic->p_picture->format.i_chroma;
406             fmt_in.i_height = p_pic->p_picture->format.i_height;
407             fmt_in.i_width = p_pic->p_picture->format.i_width;
408
409             fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
410             fmt_out.i_width = fmt_in.i_width *
411                 ( ( p_sys->i_width - ( p_sys->i_cols - 1 ) * p_sys->i_vborder )
412                   / p_sys->i_cols ) / fmt_in.i_width;
413             fmt_out.i_height = fmt_in.i_height *
414                 ( ( p_sys->i_height - ( p_sys->i_rows - 1 ) * p_sys->i_hborder )
415                   / p_sys->i_rows ) / fmt_in.i_height;
416             if( p_sys->b_ar ) /* keep aspect ratio */
417             {
418                 if( (float)fmt_out.i_width / (float)fmt_out.i_height
419                       > (float)fmt_in.i_width / (float)fmt_in.i_height )
420                 {
421                     fmt_out.i_width = ( fmt_out.i_height * fmt_in.i_width )
422                                          / fmt_in.i_height ;
423                 }
424                 else
425                 {
426                     fmt_out.i_height = ( fmt_out.i_width * fmt_in.i_height )
427                                         / fmt_in.i_width ;
428                 }
429              }
430
431             fmt_out.i_visible_width = fmt_out.i_width;
432             fmt_out.i_visible_height = fmt_out.i_height;
433
434 #ifdef IMAGE_2PASSES
435             fmt_middle.i_chroma = fmt_in.i_chroma;
436             fmt_middle.i_visible_width = fmt_middle.i_width = fmt_out.i_width;
437             fmt_middle.i_visible_height = fmt_middle.i_height = fmt_out.i_height;
438
439             p_middle = image_Convert( p_sys->p_image2, p_pic->p_picture,
440                                       &fmt_in, &fmt_middle );
441             if( !p_middle )
442             {
443                 msg_Warn( p_filter, "image resizing failed" );
444                 continue;
445             }
446
447             p_converted = image_Convert( p_sys->p_image, p_middle,
448                                          &fmt_middle, &fmt_out );
449             p_middle->pf_release( p_middle );
450 #else
451             p_converted = image_Convert( p_sys->p_image, p_pic->p_picture,
452                                          &fmt_in, &fmt_out );
453 #endif
454             if( !p_converted )
455             {
456                 msg_Warn( p_filter, "image chroma conversion failed" );
457                 continue;
458             }
459         }
460         else
461         {
462             p_converted = p_pic->p_picture;
463             p_converted->i_refcount++;
464             fmt_in.i_width = fmt_out.i_width = p_converted->format.i_width;
465             fmt_in.i_height = fmt_out.i_height = p_converted->format.i_height;
466             fmt_in.i_chroma = fmt_out.i_chroma = p_converted->format.i_chroma;
467             fmt_out.i_visible_width = fmt_out.i_width;
468             fmt_out.i_visible_height = fmt_out.i_height;
469         }
470
471         p_region = p_spu->pf_make_region( VLC_OBJECT(p_filter), &fmt_out,
472                                           p_converted );
473         if( !p_region )
474         {
475             msg_Err( p_filter, "cannot allocate SPU region" );
476             p_filter->pf_sub_buffer_del( p_filter, p_spu );
477             vlc_mutex_unlock( lockval.p_address );
478             return NULL;
479         }
480
481         /* HACK ALERT : let's fix the pointers to avoid picture duplication.
482          * This is necessary because p_region->picture is not a pointer
483          * as it ought to be. */
484         if( !p_sys->b_keep )
485         {
486             free( p_converted );
487         }
488         else
489         {
490             /* Keep a pointer to the original picture (and its refcount...). */
491             p_region->picture.p_sys = (picture_sys_t *)p_converted;
492             p_region->picture.pf_release = MosaicReleasePicture;
493         }
494
495         if( p_sys->b_ar || p_sys->b_keep ) /* keep aspect ratio */
496         {
497             /* center the video in the dedicated rectangle */
498             p_region->i_x = p_sys->i_xoffset
499                         + i_col * ( p_sys->i_width / p_sys->i_cols )
500                         + ( i_col * p_sys->i_vborder ) / p_sys->i_cols
501                         + ( ( ( p_sys->i_width
502                                  - ( p_sys->i_cols - 1 ) * p_sys->i_vborder )
503                             / p_sys->i_cols ) - fmt_out.i_width ) / 2;
504             p_region->i_y = p_sys->i_yoffset
505                         + i_row * ( p_sys->i_height / p_sys->i_rows )
506                         + ( i_row * p_sys->i_hborder ) / p_sys->i_rows
507                         + ( ( ( p_sys->i_height
508                                  - ( p_sys->i_rows - 1 ) * p_sys->i_hborder )
509                             / p_sys->i_rows ) - fmt_out.i_height ) / 2;
510         }
511         else
512         {
513             /* we don't have to center the video since it takes the
514             whole rectangle area */
515             p_region->i_x = p_sys->i_xoffset
516                             + i_col * ( p_sys->i_width / p_sys->i_cols )
517                             + ( i_col * p_sys->i_vborder ) / p_sys->i_cols;
518             p_region->i_y = p_sys->i_yoffset
519                         + i_row * ( p_sys->i_height / p_sys->i_rows )
520                         + ( i_row * p_sys->i_hborder ) / p_sys->i_rows;
521         }
522
523         if( p_region_prev == NULL )
524         {
525             p_spu->p_region = p_region;
526         }
527         else
528         {
529             p_region_prev->p_next = p_region;
530         }
531
532         p_region_prev = p_region;
533     }
534
535     vlc_mutex_unlock( lockval.p_address );
536
537     return p_spu;
538 }
539
540 /*****************************************************************************
541 * Callback to update params on the fly
542 *****************************************************************************/
543 static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
544                             vlc_value_t oldval, vlc_value_t newval,
545                             void *p_data )
546 {
547     filter_sys_t *p_sys = (filter_sys_t *) p_data;
548     if( !strcmp( psz_var, "mosaic-alpha" ) )
549     {
550         msg_Dbg( p_this, "Changing alpha from %d/255 to %d/255",
551                          p_sys->i_alpha, newval.i_int);
552         p_sys->i_alpha = __MIN( __MAX( newval.i_int, 0 ), 255 );
553     }
554     else if( !strcmp( psz_var, "mosaic-height" ) )
555     {
556         msg_Dbg( p_this, "Changing height from %dpx to %dpx",
557                           p_sys->i_height, newval.i_int );
558         p_sys->i_height = __MAX( newval.i_int, 0 );
559     }
560     else if( !strcmp( psz_var, "mosaic-width" ) )
561     {
562         msg_Dbg( p_this, "Changing width from %dpx to %dpx",
563                          p_sys->i_width, newval.i_int );
564         p_sys->i_width = __MAX( newval.i_int, 0 );
565     }
566     else if( !strcmp( psz_var, "mosaic-xoffset" ) )
567     {
568         msg_Dbg( p_this, "Changing x offset from %dpx to %dpx",
569                          p_sys->i_xoffset, newval.i_int );
570         p_sys->i_xoffset = __MAX( newval.i_int, 0 );
571     }
572     else if( !strcmp( psz_var, "mosaic-yoffset" ) )
573     {
574         msg_Dbg( p_this, "Changing y offset from %dpx to %dpx",
575                          p_sys->i_yoffset, newval.i_int );
576         p_sys->i_yoffset = __MAX( newval.i_int, 0 );
577     }
578     else if( !strcmp( psz_var, "mosaic-vborder" ) )
579     {
580         msg_Dbg( p_this, "Changing vertical border from %dpx to %dpx",
581                          p_sys->i_vborder, newval.i_int );
582         p_sys->i_vborder = __MAX( newval.i_int, 0 );
583     }
584     else if( !strcmp( psz_var, "mosaic-hborder" ) )
585     {
586         msg_Dbg( p_this, "Changing horizontal border from %dpx to %dpx",
587                          p_sys->i_vborder, newval.i_int );
588         p_sys->i_hborder = __MAX( newval.i_int, 0 );
589     }
590     else if( !strcmp( psz_var, "mosaic-position" ) )
591     {
592         if( newval.i_int > 1 || newval.i_int < 0 )
593         {
594             msg_Err( p_this, "Position is either 0 (auto) or 1 (fixed)" );
595         }
596         else
597         {
598             msg_Dbg( p_this, "Changing position method from %d (%s) to %d (%s)",
599                              p_sys->i_position, ppsz_pos_descriptions[p_sys->i_position],
600                              newval.i_int, ppsz_pos_descriptions[newval.i_int]);
601             p_sys->i_position = newval.i_int;
602         }
603     }
604     else if( !strcmp( psz_var, "mosaic-rows" ) )
605     {
606         msg_Dbg( p_this, "Changing number of rows from %d to %d",
607                          p_sys->i_rows, newval.i_int );
608         p_sys->i_rows = __MAX( newval.i_int, 1 );
609     }
610     else if( !strcmp( psz_var, "mosaic-cols" ) )
611     {
612         msg_Dbg( p_this, "Changing number of columns from %d to %d",
613                          p_sys->i_cols, newval.i_int );
614         p_sys->i_cols = __MAX( newval.i_int, 1 );
615     }
616     else if( !strcmp( psz_var, "mosaic-keep-aspect-ratio" ) )
617     {
618         if( newval.i_int )
619         {
620             msg_Dbg( p_this, "Keep aspect ratio" );
621             p_sys->b_ar = 1;
622         }
623         else
624         {
625             msg_Dbg( p_this, "Don't keep aspect ratio" );
626             p_sys->b_ar = 0;
627         }
628     }
629     return VLC_SUCCESS;
630 }