1 /*****************************************************************************
2 * mosaic.c : Mosaic video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2004-2005 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 *****************************************************************************/
28 #include <stdlib.h> /* malloc(), free() */
36 # include <limits.h> /* INT_MAX */
39 #include "vlc_filter.h"
40 #include "vlc_image.h"
44 #define BLANK_DELAY I64C(1000000)
46 /*****************************************************************************
48 *****************************************************************************/
49 static int CreateFilter ( vlc_object_t * );
50 static void DestroyFilter ( vlc_object_t * );
52 static subpicture_t *Filter( filter_t *, mtime_t );
54 static int MosaicCallback( vlc_object_t *, char const *, vlc_value_t,
55 vlc_value_t, void * );
57 /*****************************************************************************
58 * filter_sys_t : filter descriptor
59 *****************************************************************************/
65 image_handler_t *p_image;
68 int i_position; /* mosaic positioning method */
69 vlc_bool_t b_ar; /* do we keep the aspect ratio ? */
70 vlc_bool_t b_keep; /* do we keep the original picture format ? */
71 int i_width, i_height; /* mosaic height and width */
72 int i_cols, i_rows; /* mosaic rows and cols */
73 int i_align; /* mosaic alignment in background video */
74 int i_xoffset, i_yoffset; /* top left corner offset */
75 int i_vborder, i_hborder; /* border width/height between miniatures */
76 int i_alpha; /* subfilter alpha blending */
78 vlc_bool_t b_bs; /* Bluescreen vars */
79 int i_bsu, i_bsv, i_bsut, i_bsvt;
81 char **ppsz_order; /* list of picture-id */
87 /*****************************************************************************
89 *****************************************************************************/
90 #define ALPHA_TEXT N_("Alpha blending")
91 #define ALPHA_LONGTEXT N_("Alpha blending (0 -> 255). Default is 255")
93 #define HEIGHT_TEXT N_("Height in pixels")
94 #define WIDTH_TEXT N_("Width in pixels")
95 #define XOFFSET_TEXT N_("Top left corner x coordinate")
96 #define YOFFSET_TEXT N_("Top left corner y coordinate")
97 #define VBORDER_TEXT N_("Vertical border width in pixels")
98 #define HBORDER_TEXT N_("Horizontal border width in pixels")
99 #define ALIGN_TEXT N_("Mosaic alignment")
101 #define POS_TEXT N_("Positioning method")
102 #define POS_LONGTEXT N_("Positioning method. auto: automatically choose " \
103 "the best number of rows and columns. fixed: use the user-defined " \
104 "number of rows and columns.")
105 #define ROWS_TEXT N_("Number of rows")
106 #define COLS_TEXT N_("Number of columns")
107 #define AR_TEXT N_("Keep aspect ratio when resizing")
108 #define KEEP_TEXT N_("Keep original size")
110 #define ORDER_TEXT N_("Order as a comma separated list of picture-id(s)")
112 #define DELAY_TEXT N_("Delay")
113 #define DELAY_LONGTEXT N_("Pictures coming from the picture video outputs " \
114 "will be delayed accordingly (in milliseconds). For high " \
115 "values you will need to raise file-caching and others.")
117 #define BLUESCREEN_TEXT N_("Enable bluescreen (aka greenscreen or chroma key) video background replacing")
118 #define BLUESCREENU_TEXT N_("Bluescreen chroma key U (0-255)")
119 #define BLUESCREENV_TEXT N_("Bluescreen chroma key V (0-255)")
120 #define BLUESCREENUTOL_TEXT N_("Bluescreen chroma key U tolerance")
121 #define BLUESCREENVTOL_TEXT N_("Bluescreen chroma key V tolerance")
123 static int pi_pos_values[] = { 0, 1 };
124 static char * ppsz_pos_descriptions[] =
125 { N_("auto"), N_("fixed") };
127 static int pi_align_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
128 static char *ppsz_align_descriptions[] =
129 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
130 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
134 set_description( N_("Mosaic video sub filter") );
135 set_shortname( N_("Mosaic") );
136 set_category( CAT_VIDEO );
137 set_subcategory( SUBCAT_VIDEO_SUBPIC);
138 set_capability( "sub filter", 0 );
139 set_callbacks( CreateFilter, DestroyFilter );
141 add_integer( "mosaic-alpha", 255, NULL, ALPHA_TEXT, ALPHA_LONGTEXT, VLC_FALSE );
142 add_integer( "mosaic-height", 100, NULL, HEIGHT_TEXT, HEIGHT_TEXT, VLC_FALSE );
143 add_integer( "mosaic-width", 100, NULL, WIDTH_TEXT, WIDTH_TEXT, VLC_FALSE );
144 add_integer( "mosaic-align", 5, NULL, ALIGN_TEXT, ALIGN_TEXT, VLC_TRUE);
145 change_integer_list( pi_align_values, ppsz_align_descriptions, 0 );
146 add_integer( "mosaic-xoffset", 0, NULL, XOFFSET_TEXT, XOFFSET_TEXT, VLC_TRUE );
147 add_integer( "mosaic-yoffset", 0, NULL, YOFFSET_TEXT, YOFFSET_TEXT, VLC_TRUE );
148 add_integer( "mosaic-vborder", 0, NULL, VBORDER_TEXT, VBORDER_TEXT, VLC_TRUE );
149 add_integer( "mosaic-hborder", 0, NULL, HBORDER_TEXT, HBORDER_TEXT, VLC_TRUE );
151 add_integer( "mosaic-position", 0, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
152 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
153 add_integer( "mosaic-rows", 2, NULL, ROWS_TEXT, ROWS_TEXT, VLC_FALSE );
154 add_integer( "mosaic-cols", 2, NULL, COLS_TEXT, COLS_TEXT, VLC_FALSE );
155 add_bool( "mosaic-keep-aspect-ratio", 0, NULL, AR_TEXT, AR_TEXT, VLC_FALSE );
156 add_bool( "mosaic-keep-picture", 0, NULL, KEEP_TEXT, KEEP_TEXT, VLC_FALSE );
157 add_string( "mosaic-order", "", NULL, ORDER_TEXT, ORDER_TEXT, VLC_FALSE );
159 add_integer( "mosaic-delay", 0, NULL, DELAY_TEXT, DELAY_LONGTEXT,
162 add_bool( "mosaic-bs", 0, NULL, BLUESCREEN_TEXT,
163 BLUESCREEN_TEXT, VLC_FALSE );
164 add_integer( "mosaic-bsu", 120, NULL, BLUESCREENU_TEXT,
165 BLUESCREENU_TEXT, VLC_FALSE );
166 add_integer( "mosaic-bsv", 90, NULL, BLUESCREENV_TEXT,
167 BLUESCREENV_TEXT, VLC_FALSE );
168 add_integer( "mosaic-bsut", 17, NULL, BLUESCREENUTOL_TEXT,
169 BLUESCREENUTOL_TEXT, VLC_FALSE );
170 add_integer( "mosaic-bsvt", 17, NULL, BLUESCREENVTOL_TEXT,
171 BLUESCREENVTOL_TEXT, VLC_FALSE );
173 var_Create( p_module->p_libvlc, "mosaic-lock", VLC_VAR_MUTEX );
177 /*****************************************************************************
178 * CreateFiler: allocate mosaic video filter
179 *****************************************************************************/
180 static int CreateFilter( vlc_object_t *p_this )
182 filter_t *p_filter = (filter_t *)p_this;
184 libvlc_t *p_libvlc = p_filter->p_libvlc;
189 /* The mosaic thread is more important than the decoder threads */
190 vlc_thread_set_priority( p_this, VLC_THREAD_PRIORITY_OUTPUT );
192 /* Allocate structure */
193 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
196 msg_Err( p_filter, "out of memory" );
200 p_filter->pf_sub_filter = Filter;
203 vlc_mutex_init( p_filter, &p_sys->lock );
204 vlc_mutex_lock( &p_sys->lock );
206 var_Get( p_libvlc, "mosaic-lock", &val );
207 p_sys->p_lock = val.p_address;
209 #define GET_VAR( name, min, max ) \
210 p_sys->i_##name = __MIN( max, __MAX( min, \
211 var_CreateGetInteger( p_filter, "mosaic-" #name ) ) ); \
212 var_Destroy( p_filter, "mosaic-" #name ); \
213 var_Create( p_libvlc, "mosaic-" #name, VLC_VAR_INTEGER ); \
214 var_SetInteger( p_libvlc, "mosaic-" #name, p_sys->i_##name ); \
215 var_AddCallback( p_libvlc, "mosaic-" #name, MosaicCallback, p_sys );
217 GET_VAR( width, 0, INT_MAX );
218 GET_VAR( height, 0, INT_MAX );
219 GET_VAR( xoffset, 0, INT_MAX );
220 GET_VAR( yoffset, 0, INT_MAX );
222 p_sys->i_align = __MIN( 10, __MAX( 0, var_CreateGetInteger( p_filter, "mosaic-align" ) ) );
223 if( p_sys->i_align == 3 || p_sys->i_align == 7 )
225 var_Destroy( p_filter, "mosaic-align" );
226 var_Create( p_libvlc, "mosaic-align", VLC_VAR_INTEGER );
227 var_SetInteger( p_libvlc, "mosaic-align", p_sys->i_align );
228 var_AddCallback( p_libvlc, "mosaic-align", MosaicCallback, p_sys );
230 GET_VAR( vborder, 0, INT_MAX );
231 GET_VAR( hborder, 0, INT_MAX );
232 GET_VAR( rows, 1, INT_MAX );
233 GET_VAR( cols, 1, INT_MAX );
234 GET_VAR( alpha, 0, 255 );
235 GET_VAR( position, 0, 1 );
236 GET_VAR( delay, 100, INT_MAX );
237 p_sys->i_delay *= 1000;
239 p_sys->b_ar = var_CreateGetBool( p_filter, "mosaic-keep-aspect-ratio" );
240 var_Destroy( p_filter, "mosaic-keep-aspect-ratio" );
241 var_Create( p_libvlc, "mosaic-keep-aspect-ratio", VLC_VAR_INTEGER );
242 var_SetBool( p_libvlc, "mosaic-keep-aspect-ratio", p_sys->b_ar );
243 var_AddCallback( p_libvlc, "mosaic-keep-aspect-ratio", MosaicCallback,
246 p_sys->b_keep = var_CreateGetBool( p_filter, "mosaic-keep-picture" );
247 if ( !p_sys->b_keep )
249 p_sys->p_image = image_HandlerCreate( p_filter );
252 p_sys->i_order_length = 0;
253 p_sys->ppsz_order = NULL;
254 psz_order = var_CreateGetString( p_filter, "mosaic-order" );
256 if( psz_order[0] != 0 )
258 char *psz_end = NULL;
262 psz_end = strchr( psz_order, ',' );
264 p_sys->ppsz_order = realloc( p_sys->ppsz_order,
265 i_index * sizeof(char *) );
266 p_sys->ppsz_order[i_index - 1] = strndup( psz_order,
267 psz_end - psz_order );
268 psz_order = psz_end+1;
269 } while( NULL != psz_end );
270 p_sys->i_order_length = i_index;
273 /* Bluescreen specific stuff */
274 GET_VAR( bsu, 0x00, 0xff );
275 GET_VAR( bsv, 0x00, 0xff );
276 GET_VAR( bsut, 0x00, 0xff );
277 GET_VAR( bsvt, 0x00, 0xff );
278 p_sys->b_bs = var_CreateGetBool( p_filter, "mosaic-bs" );
279 var_Destroy( p_filter, "mosaic-bs" );
280 var_Create( p_libvlc, "mosaic-bs", VLC_VAR_INTEGER );
281 var_SetBool( p_libvlc, "mosaic-bs", p_sys->b_bs );
282 var_AddCallback( p_libvlc, "mosaic-bs", MosaicCallback, p_sys );
283 if( p_sys->b_bs && p_sys->b_keep )
285 msg_Warn( p_filter, "mosaic-keep-picture needs to be disabled for"
286 " bluescreen to work" );
289 vlc_mutex_unlock( &p_sys->lock );
294 /*****************************************************************************
295 * DestroyFilter: destroy mosaic video filter
296 *****************************************************************************/
297 static void DestroyFilter( vlc_object_t *p_this )
299 filter_t *p_filter = (filter_t*)p_this;
300 filter_sys_t *p_sys = p_filter->p_sys;
301 libvlc_t *p_libvlc = p_filter->p_libvlc;
304 vlc_mutex_lock( &p_sys->lock );
308 image_HandlerDelete( p_sys->p_image );
311 if( p_sys->i_order_length )
313 for( i_index = 0; i_index < p_sys->i_order_length; i_index++ )
315 free( p_sys->ppsz_order[i_index] );
317 free( p_sys->ppsz_order );
320 var_Destroy( p_libvlc, "mosaic-alpha" );
321 var_Destroy( p_libvlc, "mosaic-height" );
322 var_Destroy( p_libvlc, "mosaic-align" );
323 var_Destroy( p_libvlc, "mosaic-width" );
324 var_Destroy( p_libvlc, "mosaic-xoffset" );
325 var_Destroy( p_libvlc, "mosaic-yoffset" );
326 var_Destroy( p_libvlc, "mosaic-vborder" );
327 var_Destroy( p_libvlc, "mosaic-hborder" );
328 var_Destroy( p_libvlc, "mosaic-position" );
329 var_Destroy( p_libvlc, "mosaic-rows" );
330 var_Destroy( p_libvlc, "mosaic-cols" );
331 var_Destroy( p_libvlc, "mosaic-keep-aspect-ratio" );
333 var_Destroy( p_libvlc, "mosaic-bsu" );
334 var_Destroy( p_libvlc, "mosaic-bsv" );
335 var_Destroy( p_libvlc, "mosaic-bsut" );
336 var_Destroy( p_libvlc, "mosaic-bsvt" );
337 var_Destroy( p_libvlc, "mosaic-bs" );
339 if( p_sys->p_pic ) p_sys->p_pic->pf_release( p_sys->p_pic );
340 vlc_mutex_unlock( &p_sys->lock );
341 vlc_mutex_destroy( &p_sys->lock );
345 /*****************************************************************************
346 * MosaicReleasePicture : Hack to avoid picture duplication
347 *****************************************************************************/
348 static void MosaicReleasePicture( picture_t *p_picture )
350 picture_t *p_original_pic = (picture_t *)p_picture->p_sys;
352 p_original_pic->pf_release( p_original_pic );
355 /*****************************************************************************
357 *****************************************************************************/
358 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
360 filter_sys_t *p_sys = p_filter->p_sys;
365 int i_index, i_real_index, i_row, i_col;
366 int i_greatest_real_index_used = p_sys->i_order_length - 1;
368 subpicture_region_t *p_region;
369 subpicture_region_t *p_region_prev = NULL;
371 /* Allocate the subpicture internal data. */
372 p_spu = p_filter->pf_sub_buffer_new( p_filter );
378 /* Initialize subpicture */
379 p_spu->i_channel = 0;
380 p_spu->i_start = date;
382 p_spu->b_ephemer = VLC_TRUE;
383 p_spu->i_alpha = p_sys->i_alpha;
384 p_spu->i_flags = p_sys->i_align;
385 p_spu->b_absolute = VLC_FALSE;
387 vlc_mutex_lock( &p_sys->lock );
388 vlc_mutex_lock( p_sys->p_lock );
390 p_bridge = GetBridge( p_filter );
391 if ( p_bridge == NULL )
393 vlc_mutex_unlock( p_sys->p_lock );
394 vlc_mutex_unlock( &p_sys->lock );
398 if ( p_sys->i_position == 0 ) /* use automatic positioning */
400 int i_numpics = p_sys->i_order_length; /* keep slots and all */
401 for ( i_index = 0; i_index < p_bridge->i_es_num; i_index++ )
403 bridged_es_t *p_es = p_bridge->pp_es[i_index];
404 if ( !p_es->b_empty )
407 if( p_sys->i_order_length && p_es->psz_id != 0 )
409 /* We also want to leave slots for images given in
410 * mosaic-order that are not available in p_vout_picture */
412 for( i = 0; i < p_sys->i_order_length ; i++ )
414 if( !strcmp( p_sys->ppsz_order[i], p_es->psz_id ) )
424 p_sys->i_rows = ((int)ceil(sqrt( (float)i_numpics )));
425 p_sys->i_cols = ( i_numpics % p_sys->i_rows == 0 ?
426 i_numpics / p_sys->i_rows :
427 i_numpics / p_sys->i_rows + 1 );
432 for ( i_index = 0; i_index < p_bridge->i_es_num; i_index++ )
434 bridged_es_t *p_es = p_bridge->pp_es[i_index];
435 video_format_t fmt_in = {0}, fmt_out = {0};
436 picture_t *p_converted;
441 while ( p_es->p_picture != NULL
442 && p_es->p_picture->date + p_sys->i_delay < date )
444 if ( p_es->p_picture->p_next != NULL )
446 picture_t *p_next = p_es->p_picture->p_next;
447 p_es->p_picture->pf_release( p_es->p_picture );
448 p_es->p_picture = p_next;
450 else if ( p_es->p_picture->date + p_sys->i_delay + BLANK_DELAY <
454 p_es->p_picture->pf_release( p_es->p_picture );
455 p_es->p_picture = NULL;
456 p_es->pp_last = &p_es->p_picture;
461 msg_Dbg( p_filter, "too late picture for %s (" I64Fd ")",
463 date - p_es->p_picture->date - p_sys->i_delay );
468 if ( p_es->p_picture == NULL )
471 if ( p_sys->i_order_length == 0 )
478 for ( i = 0; i <= p_sys->i_order_length; i++ )
480 if ( i == p_sys->i_order_length ) break;
481 if ( strcmp( p_es->psz_id, p_sys->ppsz_order[i] ) == 0 )
487 if ( i == p_sys->i_order_length )
488 i_real_index = ++i_greatest_real_index_used;
490 i_row = ( i_real_index / p_sys->i_cols ) % p_sys->i_rows;
491 i_col = i_real_index % p_sys->i_cols ;
493 if ( !p_sys->b_keep )
495 /* Convert the images */
496 fmt_in.i_chroma = p_es->p_picture->format.i_chroma;
497 fmt_in.i_height = p_es->p_picture->format.i_height;
498 fmt_in.i_width = p_es->p_picture->format.i_width;
500 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
501 fmt_out.i_width = fmt_in.i_width *
502 ( ( p_sys->i_width - ( p_sys->i_cols - 1 ) * p_sys->i_vborder )
503 / p_sys->i_cols ) / fmt_in.i_width;
504 fmt_out.i_height = fmt_in.i_height *
505 ( ( p_sys->i_height - ( p_sys->i_rows - 1 ) * p_sys->i_hborder )
506 / p_sys->i_rows ) / fmt_in.i_height;
507 if( p_sys->b_ar ) /* keep aspect ratio */
509 if( (float)fmt_out.i_width / (float)fmt_out.i_height
510 > (float)fmt_in.i_width / (float)fmt_in.i_height )
512 fmt_out.i_width = ( fmt_out.i_height * fmt_in.i_width )
517 fmt_out.i_height = ( fmt_out.i_width * fmt_in.i_height )
522 fmt_out.i_visible_width = fmt_out.i_width;
523 fmt_out.i_visible_height = fmt_out.i_height;
525 p_converted = image_Convert( p_sys->p_image, p_es->p_picture,
530 "image resizing and chroma conversion failed" );
534 /* Bluescreen stuff */
538 int i_lines = p_converted->p[ A_PLANE ].i_lines;
539 int i_pitch = p_converted->p[ A_PLANE ].i_pitch;
540 uint8_t *p_a = p_converted->p[ A_PLANE ].p_pixels;
541 uint8_t *p_at = malloc( i_lines * i_pitch * sizeof( uint8_t ) );
542 uint8_t *p_u = p_converted->p[ U_PLANE ].p_pixels;
543 uint8_t *p_v = p_converted->p[ V_PLANE ].p_pixels;
544 uint8_t umin, umax, vmin, vmax;
545 umin = p_sys->i_bsu - p_sys->i_bsut >= 0x00 ?
546 p_sys->i_bsu - p_sys->i_bsut : 0x00;
547 umax = p_sys->i_bsu + p_sys->i_bsut <= 0xff ?
548 p_sys->i_bsu + p_sys->i_bsut : 0xff;
549 vmin = p_sys->i_bsv - p_sys->i_bsvt >= 0x00 ?
550 p_sys->i_bsv - p_sys->i_bsvt : 0x00;
551 vmax = p_sys->i_bsv + p_sys->i_bsvt <= 0xff ?
552 p_sys->i_bsv + p_sys->i_bsvt : 0xff;
554 for( i = 0; i < i_lines*i_pitch; i++ )
568 /* Gaussian convolution to make it look cleaner */
569 memset( p_a, 0, 2 * i_pitch );
570 for( i = 2; i < i_lines - 2; i++ )
572 p_a[i*i_pitch] = 0x00;
573 p_a[i*i_pitch+1] = 0x00;
574 for( j = 2; j < i_pitch - 2; j ++ )
576 p_a[i*i_pitch+j] = (uint8_t)((
578 ( p_at[(i-2)*i_pitch+j-2]<<1 )
579 + ( p_at[(i-2)*i_pitch+j-1]<<2 )
580 + ( p_at[(i-2)*i_pitch+j]<<2 )
581 + ( p_at[(i-2)*i_pitch+j+1]<<2 )
582 + ( p_at[(i-2)*i_pitch+j+2]<<1 )
584 + ( p_at[(i-1)*i_pitch+j-1]<<3 )
585 + ( p_at[(i-1)*i_pitch+j-2]<<2 )
586 + ( p_at[(i-1)*i_pitch+j]*12 )
587 + ( p_at[(i-1)*i_pitch+j+1]<<3 )
588 + ( p_at[(i-1)*i_pitch+j+2]<<2 )
590 + ( p_at[i*i_pitch+j-2]<<2 )
591 + ( p_at[i*i_pitch+j-1]*12 )
592 + ( p_at[i*i_pitch+j]<<4 )
593 + ( p_at[i*i_pitch+j+1]*12 )
594 + ( p_at[i*i_pitch+j+2]<<2 )
596 + ( p_at[(i+1)*i_pitch+j-2]<<2 )
597 + ( p_at[(i+1)*i_pitch+j-1]<<3 )
598 + ( p_at[(i+1)*i_pitch+j]*12 )
599 + ( p_at[(i+1)*i_pitch+j+1]<<3 )
600 + ( p_at[(i+1)*i_pitch+j+2]<<2 )
602 + ( p_at[(i+2)*i_pitch+j-2]<<1 )
603 + ( p_at[(i+2)*i_pitch+j-1]<<2 )
604 + ( p_at[(i+2)*i_pitch+j]<<2 )
605 + ( p_at[(i+2)*i_pitch+j+1]<<2 )
606 + ( p_at[(i+2)*i_pitch+j+2]<<1 )
608 if( p_a[i*i_pitch+j] < 0xbf ) p_a[i*i_pitch+j] = 0x00;
615 p_converted = p_es->p_picture;
616 p_converted->i_refcount++;
617 fmt_in.i_width = fmt_out.i_width = p_converted->format.i_width;
618 fmt_in.i_height = fmt_out.i_height = p_converted->format.i_height;
619 fmt_in.i_chroma = fmt_out.i_chroma = p_converted->format.i_chroma;
620 fmt_out.i_visible_width = fmt_out.i_width;
621 fmt_out.i_visible_height = fmt_out.i_height;
624 p_region = p_spu->pf_make_region( VLC_OBJECT(p_filter), &fmt_out,
628 msg_Err( p_filter, "cannot allocate SPU region" );
629 p_filter->pf_sub_buffer_del( p_filter, p_spu );
630 vlc_mutex_unlock( &p_sys->lock );
631 vlc_mutex_unlock( p_sys->p_lock );
635 /* HACK ALERT : let's fix the pointers to avoid picture duplication.
636 * This is necessary because p_region->picture is not a pointer
637 * as it ought to be. */
644 /* Keep a pointer to the original picture (and its refcount...). */
645 p_region->picture.p_sys = (picture_sys_t *)p_converted;
646 p_region->picture.pf_release = MosaicReleasePicture;
649 if( p_sys->b_ar || p_sys->b_keep ) /* keep aspect ratio */
651 /* center the video in the dedicated rectangle */
652 p_region->i_x = p_sys->i_xoffset
653 + i_col * ( p_sys->i_width / p_sys->i_cols )
654 + ( i_col * p_sys->i_vborder ) / p_sys->i_cols
655 + ( ( ( p_sys->i_width
656 - ( p_sys->i_cols - 1 ) * p_sys->i_vborder )
657 / p_sys->i_cols ) - fmt_out.i_width ) / 2;
658 p_region->i_y = p_sys->i_yoffset
659 + i_row * ( p_sys->i_height / p_sys->i_rows )
660 + ( i_row * p_sys->i_hborder ) / p_sys->i_rows
661 + ( ( ( p_sys->i_height
662 - ( p_sys->i_rows - 1 ) * p_sys->i_hborder )
663 / p_sys->i_rows ) - fmt_out.i_height ) / 2;
667 /* we don't have to center the video since it takes the
668 whole rectangle area */
669 p_region->i_x = p_sys->i_xoffset
670 + i_col * ( p_sys->i_width / p_sys->i_cols )
671 + ( i_col * p_sys->i_vborder ) / p_sys->i_cols;
672 p_region->i_y = p_sys->i_yoffset
673 + i_row * ( p_sys->i_height / p_sys->i_rows )
674 + ( i_row * p_sys->i_hborder ) / p_sys->i_rows;
677 if( p_region_prev == NULL )
679 p_spu->p_region = p_region;
683 p_region_prev->p_next = p_region;
686 p_region_prev = p_region;
689 vlc_mutex_unlock( p_sys->p_lock );
690 vlc_mutex_unlock( &p_sys->lock );
695 /*****************************************************************************
696 * Callback to update params on the fly
697 *****************************************************************************/
698 static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
699 vlc_value_t oldval, vlc_value_t newval,
702 filter_sys_t *p_sys = (filter_sys_t *) p_data;
703 if( !strcmp( psz_var, "mosaic-alpha" ) )
705 vlc_mutex_lock( &p_sys->lock );
706 msg_Dbg( p_this, "Changing alpha from %d/255 to %d/255",
707 p_sys->i_alpha, newval.i_int);
708 p_sys->i_alpha = __MIN( __MAX( newval.i_int, 0 ), 255 );
709 vlc_mutex_unlock( &p_sys->lock );
711 else if( !strcmp( psz_var, "mosaic-height" ) )
713 vlc_mutex_lock( &p_sys->lock );
714 msg_Dbg( p_this, "Changing height from %dpx to %dpx",
715 p_sys->i_height, newval.i_int );
716 p_sys->i_height = __MAX( newval.i_int, 0 );
717 vlc_mutex_unlock( &p_sys->lock );
719 else if( !strcmp( psz_var, "mosaic-width" ) )
721 vlc_mutex_lock( &p_sys->lock );
722 msg_Dbg( p_this, "Changing width from %dpx to %dpx",
723 p_sys->i_width, newval.i_int );
724 p_sys->i_width = __MAX( newval.i_int, 0 );
725 vlc_mutex_unlock( &p_sys->lock );
727 else if( !strcmp( psz_var, "mosaic-xoffset" ) )
729 vlc_mutex_lock( &p_sys->lock );
730 msg_Dbg( p_this, "Changing x offset from %dpx to %dpx",
731 p_sys->i_xoffset, newval.i_int );
732 p_sys->i_xoffset = __MAX( newval.i_int, 0 );
733 vlc_mutex_unlock( &p_sys->lock );
735 else if( !strcmp( psz_var, "mosaic-yoffset" ) )
737 vlc_mutex_lock( &p_sys->lock );
738 msg_Dbg( p_this, "Changing y offset from %dpx to %dpx",
739 p_sys->i_yoffset, newval.i_int );
740 p_sys->i_yoffset = __MAX( newval.i_int, 0 );
741 vlc_mutex_unlock( &p_sys->lock );
743 else if( !strcmp( psz_var, "mosaic-align" ) )
745 int i_old = 0, i_new = 0;
746 vlc_mutex_lock( &p_sys->lock );
747 newval.i_int = __MIN( __MAX( newval.i_int, 0 ), 10 );
748 if( newval.i_int == 3 || newval.i_int == 7 )
750 while( pi_align_values[i_old] != p_sys->i_align ) i_old++;
751 while( pi_align_values[i_new] != newval.i_int ) i_new++;
752 msg_Dbg( p_this, "Changing alignment from %d (%s) to %d (%s)",
753 p_sys->i_align, ppsz_align_descriptions[i_old],
754 newval.i_int, ppsz_align_descriptions[i_new] );
755 p_sys->i_align = newval.i_int;
756 vlc_mutex_unlock( &p_sys->lock );
758 else if( !strcmp( psz_var, "mosaic-vborder" ) )
760 vlc_mutex_lock( &p_sys->lock );
761 msg_Dbg( p_this, "Changing vertical border from %dpx to %dpx",
762 p_sys->i_vborder, newval.i_int );
763 p_sys->i_vborder = __MAX( newval.i_int, 0 );
764 vlc_mutex_unlock( &p_sys->lock );
766 else if( !strcmp( psz_var, "mosaic-hborder" ) )
768 vlc_mutex_lock( &p_sys->lock );
769 msg_Dbg( p_this, "Changing horizontal border from %dpx to %dpx",
770 p_sys->i_vborder, newval.i_int );
771 p_sys->i_hborder = __MAX( newval.i_int, 0 );
772 vlc_mutex_unlock( &p_sys->lock );
774 else if( !strcmp( psz_var, "mosaic-position" ) )
776 if( newval.i_int > 1 || newval.i_int < 0 )
778 msg_Err( p_this, "Position is either 0 (auto) or 1 (fixed)" );
782 vlc_mutex_lock( &p_sys->lock );
783 msg_Dbg( p_this, "Changing position method from %d (%s) to %d (%s)",
784 p_sys->i_position, ppsz_pos_descriptions[p_sys->i_position],
785 newval.i_int, ppsz_pos_descriptions[newval.i_int]);
786 p_sys->i_position = newval.i_int;
787 vlc_mutex_unlock( &p_sys->lock );
790 else if( !strcmp( psz_var, "mosaic-rows" ) )
792 vlc_mutex_lock( &p_sys->lock );
793 msg_Dbg( p_this, "Changing number of rows from %d to %d",
794 p_sys->i_rows, newval.i_int );
795 p_sys->i_rows = __MAX( newval.i_int, 1 );
796 vlc_mutex_unlock( &p_sys->lock );
798 else if( !strcmp( psz_var, "mosaic-cols" ) )
800 vlc_mutex_lock( &p_sys->lock );
801 msg_Dbg( p_this, "Changing number of columns from %d to %d",
802 p_sys->i_cols, newval.i_int );
803 p_sys->i_cols = __MAX( newval.i_int, 1 );
804 vlc_mutex_unlock( &p_sys->lock );
806 else if( !strcmp( psz_var, "mosaic-keep-aspect-ratio" ) )
808 vlc_mutex_lock( &p_sys->lock );
811 msg_Dbg( p_this, "Keep aspect ratio" );
816 msg_Dbg( p_this, "Don't keep aspect ratio" );
819 vlc_mutex_unlock( &p_sys->lock );