mosaic.c 21.9 KB
Newer Older
dionoea's avatar
dionoea committed
1
2
3
/*****************************************************************************
* mosaic.c : Mosaic video plugin for vlc
*****************************************************************************
dionoea's avatar
dionoea committed
4
* Copyright (C) 2004-2005 VideoLAN
5
* $Id$
dionoea's avatar
dionoea committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
*
* Authors: Antoine Cellerier <dionoea@via.ecp.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
*****************************************************************************/

/*****************************************************************************
* Preamble
*****************************************************************************/
#include <stdlib.h>                                      /* malloc(), free() */
#include <string.h>
#include <math.h>

#include <vlc/vlc.h>
#include <vlc/vout.h>

#include "vlc_filter.h"
#include "vlc_input.h"

#include "vlc_image.h"

/*****************************************************************************
* Local prototypes
*****************************************************************************/

static int  CreateFilter    ( vlc_object_t * );
static void DestroyFilter   ( vlc_object_t * );

static subpicture_t *Filter( filter_t *, mtime_t );

48
49
50
static int MosaicCallback( vlc_object_t *, char const *, vlc_value_t,
                            vlc_value_t, void * );

dionoea's avatar
dionoea committed
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*****************************************************************************
* filter_sys_t : filter desriptor
*****************************************************************************/

#include "../video_output/picture.h"

struct filter_sys_t
{

    image_handler_t *p_image;
    image_handler_t *p_image2;
    picture_t *p_pic;

    int i_pos; /* mosaic positioning method */
65
    int i_ar; /* do we keep aspect ratio ? */
dionoea's avatar
dionoea committed
66
67
68
69
70
71
    int i_width, i_height; /* mosaic height and width */
    int i_cols, i_rows; /* mosaic rows and cols */
    int i_xoffset, i_yoffset; /* top left corner offset */
    int i_vborder, i_hborder; /* border width/height between miniatures */
    int i_alpha; /* subfilter alpha blending */

72
73
74
    char **ppsz_order; /* list of picture-id */
    int i_order_length;

dionoea's avatar
dionoea committed
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
};

/*****************************************************************************
* Module descriptor
*****************************************************************************/

#define ALPHA_TEXT N_("Mosaic alpha blending (0 -> 255)")
#define ALPHA_LONGTEXT N_("Mosaic alpha blending (0 -> 255). default is 255")

#define HEIGHT_TEXT N_("Mosaic height in pixels")
#define WIDTH_TEXT N_("Mosaic width in pixels")
#define XOFFSET_TEXT N_("Mosaic top left corner x coordinate")
#define YOFFSET_TEXT N_("Mosaic top left corner y coordinate")
#define VBORDER_TEXT N_("Mosaic vertical border width in pixels")
#define HBORDER_TEXT N_("Mosaic horizontal border width in pixels")

#define POS_TEXT N_("Mosaic positioning method")
92
#define POS_LONGTEXT N_("Mosaic positioning method. auto : automatically chose the best number of rows and columns. fixed : used the user defined number of rows and columns.")
dionoea's avatar
dionoea committed
93
94
#define ROWS_TEXT N_("Mosaic number of rows")
#define COLS_TEXT N_("Mosaic number of columns")
95
#define AR_TEXT N_("Keep aspect ratio when resizing")
dionoea's avatar
dionoea committed
96

97
98
#define ORDER_TEXT N_("Order as a comma separated list of picture-id(s)")

dionoea's avatar
dionoea committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
static int pi_pos_values[] = { 0, 1 };
static char * ppsz_pos_descriptions[] =
{ N_("auto"), N_("fixed") };


vlc_module_begin();
    set_description( _("Mosaic video sub filter") );
    set_shortname( N_("Mosaic") );
    set_capability( "sub filter", 0 );
    set_callbacks( CreateFilter, DestroyFilter );

    add_integer( "mosaic-alpha", 255, NULL, ALPHA_TEXT, ALPHA_LONGTEXT, VLC_FALSE );
    add_integer( "mosaic-height", 100, NULL, HEIGHT_TEXT, HEIGHT_TEXT, VLC_FALSE );
    add_integer( "mosaic-width", 100, NULL, WIDTH_TEXT, WIDTH_TEXT, VLC_FALSE );
113
114
115
116
    add_integer( "mosaic-xoffset", 0, NULL, XOFFSET_TEXT, XOFFSET_TEXT, VLC_TRUE );
    add_integer( "mosaic-yoffset", 0, NULL, YOFFSET_TEXT, YOFFSET_TEXT, VLC_TRUE );
    add_integer( "mosaic-vborder", 0, NULL, VBORDER_TEXT, VBORDER_TEXT, VLC_TRUE );
    add_integer( "mosaic-hborder", 0, NULL, HBORDER_TEXT, HBORDER_TEXT, VLC_TRUE );
dionoea's avatar
dionoea committed
117

118
    add_integer( "mosaic-position", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
dionoea's avatar
dionoea committed
119
120
121
        change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
    add_integer( "mosaic-rows", 2, NULL, ROWS_TEXT, ROWS_TEXT, VLC_FALSE );
    add_integer( "mosaic-cols", 2, NULL, COLS_TEXT, COLS_TEXT, VLC_FALSE );
122
    add_bool( "mosaic-keep-aspect-ratio", 0, NULL, AR_TEXT, AR_TEXT, VLC_FALSE );
123
    add_string( "mosaic-order", "", NULL, ORDER_TEXT, ORDER_TEXT, VLC_FALSE );
dionoea's avatar
dionoea committed
124
125
126
127
128
129
130
131
132
133
134
vlc_module_end();


/*****************************************************************************
* CreateFiler: allocates mosaic video filter
*****************************************************************************/

static int CreateFilter( vlc_object_t *p_this )
{
    filter_t *p_filter = (filter_t *)p_this;
    filter_sys_t *p_sys;
135
136
    char *psz_order;
    int i_index;
dionoea's avatar
dionoea committed
137
138
139
140
141
142
143
144
145
146
147
148
149
150

    /* Allocate structure */
    p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
    if( p_sys == NULL )
    {
        msg_Err( p_filter, "out of memory" );
        return VLC_ENOMEM;
    }
    p_sys->p_image = image_HandlerCreate( p_filter );
    p_sys->p_image2 = image_HandlerCreate( p_filter );

    p_filter->pf_sub_filter = Filter;
    p_sys->p_pic = NULL;

151
152
    p_sys->i_width = __MAX( 0, var_CreateGetInteger( p_filter->p_libvlc, "mosaic-width" ) );
    p_sys->i_height = __MAX( 0, var_CreateGetInteger( p_filter->p_libvlc, "mosaic-height" ) );
dionoea's avatar
dionoea committed
153

154
155
    p_sys->i_xoffset = __MAX( 0, var_CreateGetInteger( p_filter->p_libvlc, "mosaic-xoffset" ) );
    p_sys->i_yoffset = __MAX( 0, var_CreateGetInteger( p_filter->p_libvlc, "mosaic-yoffset" ) );
dionoea's avatar
dionoea committed
156

157
158
    p_sys->i_vborder = __MAX( 0, var_CreateGetInteger( p_filter->p_libvlc, "mosaic-vborder" ) );
    p_sys->i_hborder = __MAX( 0, var_CreateGetInteger( p_filter->p_libvlc, "mosaic-hborder" ) );
dionoea's avatar
dionoea committed
159

160
161
    p_sys->i_rows = __MAX( 1, var_CreateGetInteger( p_filter->p_libvlc, "mosaic-rows") );
    p_sys->i_cols = __MAX( 1, var_CreateGetInteger( p_filter->p_libvlc, "mosaic-cols") );
dionoea's avatar
dionoea committed
162

163
    p_sys->i_alpha = var_CreateGetInteger( p_filter->p_libvlc, "mosaic-alpha" );
dionoea's avatar
dionoea committed
164
165
    p_sys->i_alpha = __MIN( 255, __MAX( 0, p_sys->i_alpha ) );

166
    p_sys->i_pos = var_CreateGetInteger( p_filter->p_libvlc, "mosaic-position" );
dionoea's avatar
dionoea committed
167
168
    if( p_sys->i_pos > 1 || p_sys->i_pos < 0 ) p_sys->i_pos = 0;

169
170
    p_sys->i_ar = var_CreateGetInteger( p_filter->p_libvlc, "mosaic-keep-aspect-ratio" );

171
172
173
174
175
176
177
    p_sys->i_order_length = 0;
    p_sys->ppsz_order = NULL;
    psz_order = var_CreateGetString( p_filter->p_libvlc, "mosaic-order" );

    if( psz_order[0] != 0 )
    {
        char* psz_end=NULL;
178
        i_index = 0;
179
180
181
182
183
184
185
186
187
188
189
190
191
        do
        { 
            psz_end = strchr( psz_order, ',' );
            i_index++;
            p_sys->ppsz_order = realloc( p_sys->ppsz_order,
                                         i_index * sizeof(char *) );
            p_sys->ppsz_order[i_index - 1] = strndup( psz_order,
                                           psz_end - psz_order );
            psz_order = psz_end+1;
        } while( NULL !=  psz_end );
        p_sys->i_order_length = i_index;
    }

192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
    var_AddCallback( p_filter->p_libvlc, "mosaic-alpha",
                     MosaicCallback, p_sys );
    var_AddCallback( p_filter->p_libvlc, "mosaic-height",
                     MosaicCallback, p_sys );
    var_AddCallback( p_filter->p_libvlc, "mosaic-width",
                     MosaicCallback, p_sys );
    var_AddCallback( p_filter->p_libvlc, "mosaic-xoffset",
                     MosaicCallback, p_sys );
    var_AddCallback( p_filter->p_libvlc, "mosaic-yoffset",
                     MosaicCallback, p_sys );
    var_AddCallback( p_filter->p_libvlc, "mosaic-vborder",
                     MosaicCallback, p_sys );
    var_AddCallback( p_filter->p_libvlc, "mosaic-hborder",
                     MosaicCallback, p_sys );
    var_AddCallback( p_filter->p_libvlc, "mosaic-position",
                     MosaicCallback, p_sys );
    var_AddCallback( p_filter->p_libvlc, "mosaic-rows",
                     MosaicCallback, p_sys );
    var_AddCallback( p_filter->p_libvlc, "mosaic-cols",
                     MosaicCallback, p_sys );
    var_AddCallback( p_filter->p_libvlc, "mosaic-keep-aspect-ratio",
                     MosaicCallback, p_sys );
214

dionoea's avatar
dionoea committed
215
216
217
218
219
220
221
222
223
224
225
    return VLC_SUCCESS;
}

/*****************************************************************************
* DestroyFilter: destroy mosaic video filter
*****************************************************************************/

static void DestroyFilter( vlc_object_t *p_this )
{
    filter_t *p_filter = (filter_t*)p_this;
    filter_sys_t *p_sys = p_filter->p_sys;
226
    int i_index;
dionoea's avatar
dionoea committed
227
228
229
230

    image_HandlerDelete( p_sys->p_image );
    image_HandlerDelete( p_sys->p_image2 );

231
232
233
234
235
236
237
238
239
    if( p_sys->i_order_length )
    {
        for( i_index = 0; i_index < p_sys->i_order_length; i_index++ )
        {
            free( p_sys->ppsz_order[i_index] );
        }
        free( p_sys->ppsz_order );
    }

240
241
242
243
244
245
246
247
248
249
250
    var_Destroy( p_filter->p_libvlc, "mosaic-alpha" );
    var_Destroy( p_filter->p_libvlc, "mosaic-height" );
    var_Destroy( p_filter->p_libvlc, "mosaic-width" );
    var_Destroy( p_filter->p_libvlc, "mosaic-xoffset" );
    var_Destroy( p_filter->p_libvlc, "mosaic-yoffset" );
    var_Destroy( p_filter->p_libvlc, "mosaic-vborder" );
    var_Destroy( p_filter->p_libvlc, "mosaic-hborder" );
    var_Destroy( p_filter->p_libvlc, "mosaic-position" );
    var_Destroy( p_filter->p_libvlc, "mosaic-rows" );
    var_Destroy( p_filter->p_libvlc, "mosaic-cols" );
    var_Destroy( p_filter->p_libvlc, "mosaic-keep-aspect-ratio" );
dionoea's avatar
dionoea committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
    if( p_sys->p_pic ) p_sys->p_pic->pf_release( p_sys->p_pic );
    free( p_sys );
}

/*****************************************************************************
* Filter
*****************************************************************************/

static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
{

    filter_sys_t *p_sys = p_filter->p_sys;
    subpicture_t *p_spu;

    libvlc_t *p_libvlc = p_filter->p_libvlc;
    vlc_value_t val;
267
    int i_index, i_real_index, i_row, i_col;
268
    int i_greatest_real_index_used = p_sys->i_order_length - 1;
dionoea's avatar
dionoea committed
269
270
271
272
273
274
275
276
277
278
279

    subpicture_region_t *p_region;
    subpicture_region_t *p_region_prev = NULL;

    struct picture_vout_t *p_picture_vout;

    if( var_Get( p_libvlc, "p_picture_vout", &val ) )
    {
        return NULL;
    }

280
281
    p_picture_vout = val.p_address;

dionoea's avatar
dionoea committed
282
283
284
285
286
287
288
    /* Allocate the subpicture internal data. */
    p_spu = p_filter->pf_sub_buffer_new( p_filter );
    if( !p_spu )
    {
        return NULL;
    }

289
290
291
292
293
294
    /* Initialize subpicture */
    p_spu->i_channel = 0;
    p_spu->i_start  = date;
    p_spu->i_stop = 0;
    p_spu->b_ephemer = VLC_TRUE;
    p_spu->i_alpha = p_sys->i_alpha;
dionoea's avatar
dionoea committed
295
296
297
298
299

    vlc_mutex_lock( &p_picture_vout->lock );

    if( p_sys->i_pos == 0 ) /* use automatic positioning */
    {
300
        int i_numpics = p_sys->i_order_length; /* keep slots and all */
dionoea's avatar
dionoea committed
301
302
303
304
305
306
307
        for( i_index = 0 ;
             i_index < p_picture_vout->i_picture_num ;
             i_index ++ )
        {
            if( p_picture_vout->p_pic[i_index].i_status
                           == PICTURE_VOUT_E_OCCUPIED ) {
                i_numpics ++;
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
                if( p_sys->i_order_length
                    && p_picture_vout->p_pic[i_index].psz_id != 0 ){
                /* we also want to leave slots for images given in mosaic-order
                that are not available in p_vout_picture */
                    int i;
                    for( i = 0; i < p_sys->i_order_length ; i++ )
                    {
                        if( ! strcmp( p_sys->ppsz_order[i],
                                    p_picture_vout->p_pic[i_index].psz_id ) )
                        {
                            i_numpics --;
                            break;
                        }
                    }

                }
dionoea's avatar
dionoea committed
324
325
326
327
328
329
330
331
            }
        }
        p_sys->i_rows = ((int)ceil(sqrt( (float)i_numpics )));
        p_sys->i_cols = ( i_numpics%p_sys->i_rows == 0 ?
                            i_numpics/p_sys->i_rows :
                            i_numpics/p_sys->i_rows + 1 );
    }

332
333
    i_real_index = 0;

dionoea's avatar
dionoea committed
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
    for( i_index = 0 ; i_index < p_picture_vout->i_picture_num ; i_index ++ )
    {

        video_format_t fmt_in = {0}, fmt_middle = {0}, fmt_out = {0};

        picture_t *p_converted, *p_middle;

        if(  p_picture_vout->p_pic[i_index].p_picture == NULL )
        {
            break;
        }

        if(  p_picture_vout->p_pic[i_index].i_status
               == PICTURE_VOUT_E_AVAILABLE )
        {
            msg_Dbg( p_filter, "Picture Vout Element is empty");
            break;
        }
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
        if( p_sys->i_order_length == 0 )
            i_real_index ++;
        else
        {
            int i;
            for( i =0; i <= p_sys->i_order_length; i++ )
            {
                if( i == p_sys->i_order_length ) break;
                if( strcmp( p_picture_vout->p_pic[i_index].psz_id,
                    p_sys->ppsz_order[ i ] ) == 0 )
                {
                    i_real_index = i;
                    break;
                }
            }
            if( i == p_sys->i_order_length )
                i_real_index = ++i_greatest_real_index_used;
        }
370
371
372
        i_row = ( i_real_index / p_sys->i_cols ) % p_sys->i_rows ;
        i_col = i_real_index % p_sys->i_cols ;

dionoea's avatar
dionoea committed
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
        /* Convert the images */
/*        fprintf (stderr, "Input image %ix%i %4.4s\n",
                  p_picture_vout->p_pic[i_index].p_picture->format.i_width,
                  p_picture_vout->p_pic[i_index].p_picture->format.i_height,
                  (char *)&p_picture_vout->p_pic[i_index].p_picture->format.i_chroma );*/

        fmt_in.i_chroma = p_picture_vout->p_pic[i_index].
                                                p_picture->format.i_chroma;
        fmt_in.i_height = p_picture_vout->p_pic[i_index].
                                                p_picture->format.i_height;
        fmt_in.i_width = p_picture_vout->p_pic[i_index].
                                                p_picture->format.i_width;


        fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
388
389
390
391
392
393
        fmt_out.i_width = fmt_in.i_width *
            ( ( p_sys->i_width - ( p_sys->i_cols - 1 ) * p_sys->i_vborder )
              / p_sys->i_cols ) / fmt_in.i_width;
        fmt_out.i_height = fmt_in.i_height *
            ( ( p_sys->i_height - ( p_sys->i_rows - 1 ) * p_sys->i_hborder )
              / p_sys->i_rows ) / fmt_in.i_height;
394
395
396
397
398
399
400
401
402
403
404
        if( p_sys->i_ar ) /* keep aspect ratio */
        {
            if( (float)fmt_out.i_width/(float)fmt_out.i_height
                > (float)fmt_in.i_width/(float)fmt_in.i_height )
            {
                fmt_out.i_width = ( fmt_out.i_height * fmt_in.i_width ) / fmt_in.i_height ;
            } else {
                fmt_out.i_height = ( fmt_out.i_width * fmt_in.i_height ) / fmt_in.i_width ;
            }
         }

dionoea's avatar
dionoea committed
405
406
407
408
409
410
411
412
413
414
415
        fmt_out.i_visible_width = fmt_out.i_width;
        fmt_out.i_visible_height = fmt_out.i_height;

        fmt_middle.i_chroma = fmt_in.i_chroma;
        fmt_middle.i_visible_width = fmt_middle.i_width = fmt_out.i_width;
        fmt_middle.i_visible_height = fmt_middle.i_height = fmt_out.i_height;

        p_middle = image_Convert( p_sys->p_image,
            p_picture_vout->p_pic[i_index].p_picture, &fmt_in, &fmt_middle );
        if( !p_middle )
        {
416
417
            msg_Err( p_filter, "image resizing failed" );
            p_filter->pf_sub_buffer_del( p_filter, p_spu );
dionoea's avatar
dionoea committed
418
419
420
421
422
423
424
425
            vlc_mutex_unlock( &p_picture_vout->lock );
            return NULL;
        }

        p_converted = image_Convert( p_sys->p_image2,
                 p_middle, &fmt_middle, &fmt_out );
        if( !p_converted )
        {
426
427
            msg_Err( p_filter, "image chroma convertion failed" );
            p_filter->pf_sub_buffer_del( p_filter, p_spu );
dionoea's avatar
dionoea committed
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
            vlc_mutex_unlock( &p_picture_vout->lock );
            return NULL;
        }

/*        fprintf( stderr, "Converted %ix%i %4.4s\n", p_converted->format.i_width, p_converted->format.i_height, (char *)&p_converted->format.i_chroma);*/


        p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt_out);
        if( !p_region )
        {
            msg_Err( p_filter, "cannot allocate SPU region" );
            p_filter->pf_sub_buffer_del( p_filter, p_spu );
            vlc_mutex_unlock( &p_picture_vout->lock );
            return NULL;
        }

444
445
446
        if( p_sys->i_ar ) /* keep aspect ratio */
        {
            /* center the video in the dedicated rectangle */
447
448
449
450
451
452
            p_region->i_x = p_sys->i_xoffset
                            + i_col * ( p_sys->i_width / p_sys->i_cols )
                            + ( i_col * p_sys->i_vborder ) / p_sys->i_cols
                        + ( fmt_in.i_width *
            ( ( p_sys->i_width - ( p_sys->i_cols - 1 ) * p_sys->i_vborder )
              / p_sys->i_cols ) / fmt_in.i_width - fmt_out.i_width ) / 2;
453
            p_region->i_y = p_sys->i_yoffset
454
455
456
457
458
                        + i_row * ( p_sys->i_height / p_sys->i_rows )
                        + ( i_row * p_sys->i_hborder ) / p_sys->i_rows
                        + ( fmt_in.i_height *
            ( ( p_sys->i_height - ( p_sys->i_rows - 1 ) * p_sys->i_hborder )
              / p_sys->i_rows ) / fmt_in.i_height - fmt_out.i_height ) / 2;
459
460
461
        } else {
            /* we don't have to center the video since it takes the
            whole rectangle area */
462
463
464
            p_region->i_x = p_sys->i_xoffset
                            + i_col * ( p_sys->i_width / p_sys->i_cols )
                            + ( i_col * p_sys->i_vborder ) / p_sys->i_cols;
465
            p_region->i_y = p_sys->i_yoffset
466
467
                        + i_row * ( p_sys->i_height / p_sys->i_rows )
                        + ( i_row * p_sys->i_hborder ) / p_sys->i_rows;
468
469
        }

dionoea's avatar
dionoea committed
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
        if( p_region_prev == NULL ){
            p_spu->p_region = p_region;
        } else {
            p_region_prev->p_next = p_region;
        }

        p_region_prev = p_region;

        vout_CopyPicture( p_filter, &p_region->picture, p_converted );

        p_middle->pf_release( p_middle );
        p_converted->pf_release( p_converted );
    }

    vlc_mutex_unlock( &p_picture_vout->lock );

    return p_spu;
}
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580

/*****************************************************************************
* Callback to update params on the fly
*****************************************************************************/

static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
                            vlc_value_t oldval, vlc_value_t newval,
                            void *p_data )
{
    filter_sys_t *p_sys = (filter_sys_t *) p_data;
    if( !strcmp( psz_var, "mosaic-alpha" ) )
    {
        msg_Dbg( p_this, "Changing alpha from %d/255 to %d/255",
                         p_sys->i_alpha, newval.i_int);
        p_sys->i_alpha = __MIN( __MAX( newval.i_int, 0 ), 255 );
    }
    else if( !strcmp( psz_var, "mosaic-height" ) )
    {
        msg_Dbg( p_this, "Changing height from %dpx to %dpx",
                          p_sys->i_height, newval.i_int );
        p_sys->i_height = __MAX( newval.i_int, 0 );
    }
    else if( !strcmp( psz_var, "mosaic-width" ) )
    {
        msg_Dbg( p_this, "Changing width from %dpx to %dpx",
                         p_sys->i_width, newval.i_int );
        p_sys->i_width = __MAX( newval.i_int, 0 );
    }
    else if( !strcmp( psz_var, "mosaic-xoffset" ) )
    {
        msg_Dbg( p_this, "Changing x offset from %dpx to %dpx",
                         p_sys->i_xoffset, newval.i_int );
        p_sys->i_xoffset = __MAX( newval.i_int, 0 );
    }
    else if( !strcmp( psz_var, "mosaic-yoffset" ) )
    {
        msg_Dbg( p_this, "Changing y offset from %dpx to %dpx",
                         p_sys->i_yoffset, newval.i_int );
        p_sys->i_yoffset = __MAX( newval.i_int, 0 );
    }
    else if( !strcmp( psz_var, "mosaic-vborder" ) )
    {
        msg_Dbg( p_this, "Changing vertical border from %dpx to %dpx",
                         p_sys->i_vborder, newval.i_int );
        p_sys->i_vborder = __MAX( newval.i_int, 0 );
    }
    else if( !strcmp( psz_var, "mosaic-hborder" ) )
    {
        msg_Dbg( p_this, "Changing horizontal border from %dpx to %dpx",
                         p_sys->i_vborder, newval.i_int );
        p_sys->i_hborder = __MAX( newval.i_int, 0 );
    }
    else if( !strcmp( psz_var, "mosaic-position" ) )
    {
        if( newval.i_int > 1 || newval.i_int < 0 )
        {
            msg_Err( p_this, "Position is either 0 (auto) or 1 (fixed)" );
        }
        else
        {
            msg_Dbg( p_this, "Changing position method from %d (%s) to %d (%s)",
                             p_sys->i_pos, ppsz_pos_descriptions[p_sys->i_pos],
                             newval.i_int, ppsz_pos_descriptions[newval.i_int]);
            p_sys->i_pos = newval.i_int;
        }
    }
    else if( !strcmp( psz_var, "mosaic-rows" ) )
    {
        msg_Dbg( p_this, "Changing number of rows from %d to %d",
                         p_sys->i_rows, newval.i_int );
        p_sys->i_rows = __MAX( newval.i_int, 1 );
    }
    else if( !strcmp( psz_var, "mosaic-cols" ) )
    {
        msg_Dbg( p_this, "Changing number of columns from %d to %d",
                         p_sys->i_cols, newval.i_int );
        p_sys->i_cols = __MAX( newval.i_int, 1 );
    }
    else if( !strcmp( psz_var, "mosaic-keep-aspect-ratio" ) )
    {
        if( newval.i_int )
        {
            msg_Dbg( p_this, "Keep aspect ratio" );
            p_sys->i_ar = 1;
        }
        else
        {
            msg_Dbg( p_this, "Don't keep aspect ratio" );
            p_sys->i_ar = 0;
        }
    }
    return VLC_SUCCESS;
}