1 /*****************************************************************************
2 * logo.c : logo video plugin for vlc
3 *****************************************************************************
4 * Copyright (C) 2003-2006 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * Simon Latapie <garf@videolan.org>
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() */
34 #include "vlc_filter.h"
35 #include "filter_common.h"
36 #include "vlc_image.h"
43 /*****************************************************************************
45 *****************************************************************************/
46 static int Create ( vlc_object_t * );
47 static void Destroy ( vlc_object_t * );
49 static int Init ( vout_thread_t * );
50 static void End ( vout_thread_t * );
51 static void Render ( vout_thread_t *, picture_t * );
53 static int SendEvents( vlc_object_t *, char const *,
54 vlc_value_t, vlc_value_t, void * );
55 static int MouseEvent( vlc_object_t *, char const *,
56 vlc_value_t , vlc_value_t , void * );
57 static int Control ( vout_thread_t *, int, va_list );
59 static int CreateFilter ( vlc_object_t * );
60 static void DestroyFilter( vlc_object_t * );
62 static int LogoCallback( vlc_object_t *, char const *,
63 vlc_value_t, vlc_value_t, void * );
65 /*****************************************************************************
67 *****************************************************************************/
68 #define FILE_TEXT N_("Logo filenames")
69 #define FILE_LONGTEXT N_("Full path of the image files to use. Format is " \
70 "<image>[,<delay in ms>[,<alpha>]][;<image>[,<delay>[,<alpha>]]][;...]. " \
71 "If you only have one file, simply enter its filename.")
72 #define REPEAT_TEXT N_("Logo animation # of loops")
73 #define REPEAT_LONGTEXT N_("Number of loops for the logo animation." \
74 "-1 = continuous, 0 = disabled")
75 #define DELAY_TEXT N_("Logo individual image time in ms")
76 #define DELAY_LONGTEXT N_("Individual image display time of 0 - 60000 ms.")
78 #define POSX_TEXT N_("X coordinate")
79 #define POSX_LONGTEXT N_("X coordinate of the logo. You can move the logo " \
80 "by left-clicking it." )
81 #define POSY_TEXT N_("Y coordinate")
82 #define POSY_LONGTEXT N_("Y coordinate of the logo. You can move the logo " \
83 "by left-clicking it." )
84 #define TRANS_TEXT N_("Transparency of the logo")
85 #define TRANS_LONGTEXT N_("Logo transparency value " \
86 "(from 0 for full transparency to 255 for full opacity)." )
87 #define POS_TEXT N_("Logo position")
88 #define POS_LONGTEXT N_( \
89 "Enforce the logo position on the video " \
90 "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
91 "also use combinations of these values, eg 6 = top-right).")
93 #define CFG_PREFIX "logo-"
95 static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
96 static const char *ppsz_pos_descriptions[] =
97 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
98 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
101 set_description( _("Logo video filter") );
102 set_capability( "video filter", 0 );
103 set_shortname( _("Logo overlay") );
104 set_category( CAT_VIDEO );
105 set_subcategory( SUBCAT_VIDEO_SUBPIC );
106 add_shortcut( "logo" );
107 set_callbacks( Create, Destroy );
109 add_file( CFG_PREFIX "file", NULL, NULL, FILE_TEXT, FILE_LONGTEXT, VLC_FALSE );
110 add_integer( CFG_PREFIX "x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_TRUE );
111 add_integer( CFG_PREFIX "y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_TRUE );
112 /* default to 1000 ms per image, continuously cycle through them */
113 add_integer( CFG_PREFIX "delay", 1000, NULL, DELAY_TEXT, DELAY_LONGTEXT, VLC_TRUE );
114 add_integer( CFG_PREFIX "repeat", -1, NULL, REPEAT_TEXT, REPEAT_LONGTEXT, VLC_TRUE );
115 add_integer_with_range( CFG_PREFIX "transparency", 255, 0, 255, NULL,
116 TRANS_TEXT, TRANS_LONGTEXT, VLC_FALSE );
117 add_integer( CFG_PREFIX "position", 6, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
118 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
120 /* subpicture filter submodule */
122 set_capability( "sub filter", 0 );
123 set_callbacks( CreateFilter, DestroyFilter );
124 set_description( _("Logo sub filter") );
127 static const char *ppsz_filter_options[] = {
128 "file", "x", "y", "delay", "repeat", "transparency", "position", NULL
131 /*****************************************************************************
132 * Structure to hold the set of individual logo image names, times,
134 ****************************************************************************/
137 char *psz_file; /* candidate for deletion -- not needed */
138 int i_delay; /* -1 means use default delay */
139 int i_alpha; /* -1 means use default alpha */
144 /*****************************************************************************
145 * Logo list structure. Common to both the vout and sub picture filter
146 ****************************************************************************/
149 logo_t *p_logo; /* the parsing's result */
150 unsigned int i_count; /* the number of logo images to be displayed */
152 int i_repeat; /* how often to repeat the images, image time in ms */
153 mtime_t i_next_pic; /* when to bring up a new logo image */
155 unsigned int i_counter; /* index into the list of logo images */
157 int i_delay; /* default delay (0 - 60000 ms) */
158 int i_alpha; /* default alpha */
160 char *psz_filename; /* --logo-file string ( is it really useful
166 /*****************************************************************************
167 * LoadImage: loads the logo image into memory
168 *****************************************************************************/
169 static picture_t *LoadImage( vlc_object_t *p_this, char *psz_filename )
172 image_handler_t *p_image;
173 video_format_t fmt_in;
174 video_format_t fmt_out;
176 memset( &fmt_in, 0, sizeof(video_format_t) );
177 memset( &fmt_out, 0, sizeof(video_format_t) );
179 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
180 p_image = image_HandlerCreate( p_this );
181 p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
182 image_HandlerDelete( p_image );
187 /*****************************************************************************
188 * LoadLogoList: loads the logo images into memory
189 *****************************************************************************
190 * Read the logo-file input switch, obtaining a list of images and associated
191 * durations and transparencies. Store the image(s), and times. An image
192 * without a stated time or transparency will use the logo-delay and
193 * logo-transparency values.
194 *****************************************************************************/
195 #define LoadLogoList( a, b ) __LoadLogoList( VLC_OBJECT( a ), b )
196 static void __LoadLogoList( vlc_object_t *p_this, logo_list_t *p_logo_list )
198 char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */
200 logo_t *p_logo; /* the parsing's result */
202 p_logo_list->i_counter = 0;
203 p_logo_list->i_next_pic = 0;
205 psz_list = strdup( p_logo_list->psz_filename );
207 /* Count the number logos == number of ';' + 1 */
208 p_logo_list->i_count = 1;
209 for( i = 0; i < strlen( psz_list ); i++ )
211 if( psz_list[i] == ';' ) p_logo_list->i_count++;
214 p_logo_list->p_logo = p_logo =
215 (logo_t *)malloc( p_logo_list->i_count * sizeof(logo_t) );
218 for( i = 0; i < p_logo_list->i_count; i++ )
222 p_c = strchr( psz_list, ';' );
223 p_c2 = strchr( psz_list, ',' );
225 p_logo[i].i_alpha = -1; /* use default settings */
226 p_logo[i].i_delay = -1; /* use default settings */
228 if( p_c2 && ( p_c2 < p_c || !p_c ) )
230 /* <logo>,<delay>[,<alpha>] type */
231 if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' )
232 p_logo[i].i_delay = atoi( p_c2+1 );
234 if( ( p_c2 = strchr( p_c2+1, ',' ) )
235 && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' )
236 p_logo[i].i_alpha = atoi( p_c2 + 1 );
241 if( p_c ) *p_c = '\0';
244 p_logo[i].psz_file = strdup( psz_list );
245 p_logo[i].p_pic = LoadImage( p_this, p_logo[i].psz_file );
247 if( !p_logo[i].p_pic )
249 msg_Warn( p_this, "error while loading logo %s, will be skipped",
250 p_logo[i].psz_file );
253 if( p_c ) psz_list = p_c + 1;
256 for( i = 0; i < p_logo_list->i_count; i++ )
258 msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d",
259 p_logo[i].psz_file, p_logo[i].i_delay, p_logo[i].i_alpha );
262 /* initialize so that on the first update it will wrap back to 0 */
263 p_logo_list->i_counter = p_logo_list->i_count;
266 /*****************************************************************************
268 *****************************************************************************/
269 static void FreeLogoList( logo_list_t *p_logo_list )
272 FREENULL( p_logo_list->psz_filename );
273 for( i = 0; i < p_logo_list->i_count; i++ )
275 logo_t *p_logo = &p_logo_list->p_logo[i];
276 FREENULL( p_logo->psz_file );
279 p_logo->p_pic->pf_release( p_logo->p_pic );
280 p_logo->p_pic = NULL;
285 /*****************************************************************************
286 * vout_sys_t: logo video output method descriptor
287 *****************************************************************************
288 * This structure is part of the video output thread descriptor.
289 * It describes the Invert specific properties of an output thread.
290 *****************************************************************************/
293 logo_list_t *p_logo_list;
295 vout_thread_t *p_vout;
299 int i_width, i_height;
303 /*****************************************************************************
304 * Create: allocates logo video thread output method
305 *****************************************************************************/
306 static int Create( vlc_object_t *p_this )
308 vout_thread_t *p_vout = (vout_thread_t *)p_this;
310 logo_list_t *p_logo_list;
312 /* Allocate structure */
313 p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
316 msg_Err( p_vout, "out of memory" );
319 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
320 if( p_logo_list == NULL )
322 msg_Err( p_vout, "out of memory" );
327 p_vout->pf_init = Init;
328 p_vout->pf_end = End;
329 p_vout->pf_manage = NULL;
330 p_vout->pf_render = Render;
331 p_vout->pf_display = NULL;
332 p_vout->pf_control = Control;
334 config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options,
337 p_logo_list->psz_filename = var_CreateGetStringCommand( p_vout,
339 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
341 msg_Err( p_vout, "logo file not specified" );
345 p_sys->pos = var_CreateGetIntegerCommand( p_vout, "logo-position" );
346 p_sys->posx = var_CreateGetIntegerCommand( p_vout, "logo-x" );
347 p_sys->posy = var_CreateGetIntegerCommand( p_vout, "logo-y" );
348 p_logo_list->i_delay = __MAX( __MIN(
349 var_CreateGetIntegerCommand( p_vout, "logo-delay" ) , 60000 ), 0 );
350 p_logo_list->i_repeat = var_CreateGetIntegerCommand( p_vout, "logo-repeat");
351 p_logo_list->i_alpha = __MAX( __MIN(
352 var_CreateGetIntegerCommand( p_vout, "logo-transparency" ), 255 ), 0 );
354 LoadLogoList( p_vout, p_logo_list );
359 /*****************************************************************************
360 * Init: initialize logo video thread output method
361 *****************************************************************************/
362 static int Init( vout_thread_t *p_vout )
364 vout_sys_t *p_sys = p_vout->p_sys;
368 logo_list_t *p_logo_list = p_sys->p_logo_list;
370 I_OUTPUTPICTURES = 0;
371 memset( &fmt, 0, sizeof(video_format_t) );
373 /* adjust index to the next logo */
374 p_logo_list->i_counter =
375 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
377 p_pic = p_logo_list->p_logo[p_logo_list->i_counter].p_pic;
378 /* Initialize the output structure */
379 p_vout->output.i_chroma = p_vout->render.i_chroma;
380 p_vout->output.i_width = p_vout->render.i_width;
381 p_vout->output.i_height = p_vout->render.i_height;
382 p_vout->output.i_aspect = p_vout->render.i_aspect;
383 p_vout->fmt_out = p_vout->fmt_in;
384 fmt = p_vout->fmt_out;
386 /* Load the video blending filter */
387 p_sys->p_blend = vlc_object_create( p_vout, sizeof(filter_t) );
388 vlc_object_attach( p_sys->p_blend, p_vout );
389 p_sys->p_blend->fmt_out.video.i_x_offset =
390 p_sys->p_blend->fmt_out.video.i_y_offset = 0;
391 p_sys->p_blend->fmt_in.video.i_x_offset =
392 p_sys->p_blend->fmt_in.video.i_y_offset = 0;
393 p_sys->p_blend->fmt_out.video.i_aspect = p_vout->render.i_aspect;
394 p_sys->p_blend->fmt_out.video.i_chroma = p_vout->output.i_chroma;
395 p_sys->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','A');
396 p_sys->p_blend->fmt_in.video.i_aspect = VOUT_ASPECT_FACTOR;
398 p_sys->p_blend->fmt_in.video.i_width =
399 p_sys->p_blend->fmt_in.video.i_visible_width =
400 p_pic ? p_pic->p[Y_PLANE].i_visible_pitch : 0;
402 p_sys->p_blend->fmt_in.video.i_height =
403 p_sys->p_blend->fmt_in.video.i_visible_height =
404 p_pic ? p_pic->p[Y_PLANE].i_visible_lines : 0;
405 p_sys->p_blend->fmt_out.video.i_width =
406 p_sys->p_blend->fmt_out.video.i_visible_width =
407 p_vout->output.i_width;
408 p_sys->p_blend->fmt_out.video.i_height =
409 p_sys->p_blend->fmt_out.video.i_visible_height =
410 p_vout->output.i_height;
412 p_sys->p_blend->p_module =
413 module_Need( p_sys->p_blend, "video blending", 0, 0 );
414 if( !p_sys->p_blend->p_module )
416 msg_Err( p_vout, "can't open blending filter, aborting" );
417 vlc_object_detach( p_sys->p_blend );
418 vlc_object_destroy( p_sys->p_blend );
422 if( p_sys->posx < 0 || p_sys->posy < 0 )
424 p_sys->posx = 0; p_sys->posy = 0;
426 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
428 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
430 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
432 p_sys->posy = p_vout->render.i_height / 2 - p_sys->i_height / 2;
435 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
437 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
439 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
441 p_sys->posx = p_vout->render.i_width / 2 - p_sys->i_width / 2;
449 /* Try to open the real video output */
450 msg_Dbg( p_vout, "spawning the real video output" );
452 p_sys->p_vout = vout_Create( p_vout, &fmt );
454 /* Everything failed */
455 if( p_sys->p_vout == NULL )
457 msg_Err( p_vout, "can't open vout, aborting" );
461 var_AddCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
462 var_AddCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
464 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
465 ADD_CALLBACKS( p_sys->p_vout, SendEvents );
466 ADD_PARENT_CALLBACKS( SendEventsToChild );
471 /*****************************************************************************
472 * End: terminate logo video thread output method
473 *****************************************************************************/
474 static void End( vout_thread_t *p_vout )
476 vout_sys_t *p_sys = p_vout->p_sys;
479 /* Free the fake output buffers we allocated */
480 for( i_index = I_OUTPUTPICTURES ; i_index ; )
483 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
486 var_DelCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
487 var_DelCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
491 DEL_CALLBACKS( p_sys->p_vout, SendEvents );
492 vlc_object_detach( p_sys->p_vout );
493 vout_Destroy( p_sys->p_vout );
496 if( p_sys->p_blend->p_module )
497 module_Unneed( p_sys->p_blend, p_sys->p_blend->p_module );
498 vlc_object_detach( p_sys->p_blend );
499 vlc_object_destroy( p_sys->p_blend );
502 /*****************************************************************************
503 * Destroy: destroy logo video thread output method
504 *****************************************************************************/
505 static void Destroy( vlc_object_t *p_this )
507 vout_thread_t *p_vout = (vout_thread_t *)p_this;
508 vout_sys_t *p_sys = p_vout->p_sys;
510 DEL_PARENT_CALLBACKS( SendEventsToChild );
512 FreeLogoList( p_sys->p_logo_list );
513 free( p_sys->p_logo_list );
518 /*****************************************************************************
519 * Render: render the logo onto the video
520 *****************************************************************************/
521 static void Render( vout_thread_t *p_vout, picture_t *p_inpic )
523 vout_sys_t *p_sys = p_vout->p_sys;
526 logo_list_t *p_logo_list;
529 p_logo_list = p_sys->p_logo_list;
531 if( p_logo_list->i_next_pic < p_inpic->date )
533 /* It's time to use a new logo */
534 p_logo_list->i_counter =
535 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
536 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
537 p_pic = p_logo->p_pic;
538 p_logo_list->i_next_pic = p_inpic->date + ( p_logo->i_delay != -1 ?
539 p_logo->i_delay : p_logo_list->i_delay ) * 1000;
544 p_sys->p_blend->fmt_in.video.i_width =
545 p_sys->p_blend->fmt_in.video.i_visible_width =
546 p_pic->p[Y_PLANE].i_visible_pitch;
548 p_sys->p_blend->fmt_in.video.i_height =
549 p_sys->p_blend->fmt_in.video.i_visible_height =
550 p_pic->p[Y_PLANE].i_visible_lines;
554 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
556 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
558 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
560 p_sys->posy = p_vout->render.i_height/2 - p_sys->i_height/2;
562 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
564 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
566 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
568 p_sys->posx = p_vout->render.i_width/2 - p_sys->i_width/2;
576 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
577 p_pic = p_logo->p_pic;
580 /* This is a new frame. Get a structure from the video_output. */
581 while( !(p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 )) )
583 if( p_vout->b_die || p_vout->b_error ) return;
584 msleep( VOUT_OUTMEM_SLEEP );
587 vout_CopyPicture( p_vout, p_outpic, p_inpic );
588 vout_DatePicture( p_sys->p_vout, p_outpic, p_inpic->date );
591 p_sys->p_blend->pf_video_blend( p_sys->p_blend, p_outpic, p_outpic,
592 p_pic, p_sys->posx, p_sys->posy,
593 p_logo->i_alpha != -1 ? p_logo->i_alpha
594 : p_logo_list->i_alpha );
596 vout_DisplayPicture( p_sys->p_vout, p_outpic );
599 /*****************************************************************************
600 * SendEvents: forward mouse and keyboard events to the parent p_vout
601 *****************************************************************************/
602 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
603 vlc_value_t oldval, vlc_value_t newval, void *p_data )
605 var_Set( (vlc_object_t *)p_data, psz_var, newval );
609 /*****************************************************************************
610 * MouseEvent: callback for mouse events
611 *****************************************************************************/
612 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
613 vlc_value_t oldval, vlc_value_t newval, void *p_data )
615 vout_thread_t *p_vout = (vout_thread_t*)p_data;
616 vout_sys_t *p_sys = p_vout->p_sys;
620 var_Get( p_vout->p_sys->p_vout, "mouse-button-down", &valb );
622 i_delta = newval.i_int - oldval.i_int;
624 if( (valb.i_int & 0x1) == 0 )
629 if( psz_var[6] == 'x' )
632 var_Get( p_vout->p_sys->p_vout, "mouse-y", &valy );
633 if( newval.i_int >= (int)p_sys->posx &&
634 valy.i_int >= (int)p_sys->posy &&
635 newval.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
636 valy.i_int <= (int)(p_sys->posy + p_sys->i_height) )
638 p_sys->posx = __MIN( __MAX( p_sys->posx + i_delta, 0 ),
639 p_vout->output.i_width - p_sys->i_width );
642 else if( psz_var[6] == 'y' )
645 var_Get( p_vout->p_sys->p_vout, "mouse-x", &valx );
646 if( valx.i_int >= (int)p_sys->posx &&
647 newval.i_int >= (int)p_sys->posy &&
648 valx.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
649 newval.i_int <= (int)(p_sys->posy + p_sys->i_height) )
651 p_sys->posy = __MIN( __MAX( p_sys->posy + i_delta, 0 ),
652 p_vout->output.i_height - p_sys->i_height );
659 /*****************************************************************************
660 * Control: control facility for the vout (forwards to child vout)
661 *****************************************************************************/
662 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
664 return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
667 /*****************************************************************************
668 * SendEventsToChild: forward events to the child/children vout
669 *****************************************************************************/
670 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
671 vlc_value_t oldval, vlc_value_t newval, void *p_data )
673 vout_thread_t *p_vout = (vout_thread_t *)p_this;
674 var_Set( p_vout->p_sys->p_vout, psz_var, newval );
678 /*****************************************************************************
679 * filter_sys_t: logo filter descriptor
680 *****************************************************************************/
683 logo_list_t *p_logo_list;
687 vlc_bool_t b_absolute;
690 /* On the fly control variable */
691 vlc_bool_t b_need_update;
694 static subpicture_t *Filter( filter_t *, mtime_t );
696 /*****************************************************************************
697 * CreateFilter: allocates logo video filter
698 *****************************************************************************/
699 static int CreateFilter( vlc_object_t *p_this )
701 filter_t *p_filter = (filter_t *)p_this;
703 logo_list_t *p_logo_list;
705 /* Allocate structure */
706 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
709 msg_Err( p_filter, "out of memory" );
712 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
713 if( p_logo_list == NULL )
715 msg_Err( p_filter, "out of memory" );
720 config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
723 /* Hook used for callback variables */
724 p_logo_list->psz_filename =
725 var_CreateGetStringCommand( p_filter, "logo-file" );
726 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
728 msg_Err( p_this, "logo file not specified" );
734 p_sys->posx = var_CreateGetIntegerCommand( p_filter, "logo-x" );
735 p_sys->posy = var_CreateGetIntegerCommand( p_filter, "logo-y" );
736 p_sys->pos = var_CreateGetIntegerCommand( p_filter, "logo-position" );
737 p_logo_list->i_alpha = __MAX( __MIN( var_CreateGetIntegerCommand(
738 p_filter, "logo-transparency"), 255 ), 0 );
739 p_logo_list->i_delay =
740 var_CreateGetIntegerCommand( p_filter, "logo-delay" );
741 p_logo_list->i_repeat =
742 var_CreateGetIntegerCommand( p_filter, "logo-repeat" );
744 var_AddCallback( p_filter, "logo-file", LogoCallback, p_sys );
745 var_AddCallback( p_filter, "logo-x", LogoCallback, p_sys );
746 var_AddCallback( p_filter, "logo-y", LogoCallback, p_sys );
747 var_AddCallback( p_filter, "logo-position", LogoCallback, p_sys );
748 var_AddCallback( p_filter, "logo-transparency", LogoCallback, p_sys );
749 var_AddCallback( p_filter, "logo-repeat", LogoCallback, p_sys );
751 vlc_mutex_init( p_filter, &p_logo_list->lock );
752 vlc_mutex_lock( &p_logo_list->lock );
754 LoadLogoList( p_this, p_logo_list );
756 vlc_mutex_unlock( &p_logo_list->lock );
759 p_filter->pf_sub_filter = Filter;
760 p_sys->b_need_update = VLC_TRUE;
762 p_sys->i_last_date = 0;
767 /*****************************************************************************
768 * DestroyFilter: destroy logo video filter
769 *****************************************************************************/
770 static void DestroyFilter( vlc_object_t *p_this )
772 filter_t *p_filter = (filter_t *)p_this;
773 filter_sys_t *p_sys = p_filter->p_sys;
775 vlc_mutex_destroy( &p_sys->p_logo_list->lock );
776 FreeLogoList( p_sys->p_logo_list );
777 free( p_sys->p_logo_list );
780 /* Delete the logo variables from INPUT */
781 var_Destroy( p_filter->p_libvlc, "logo-file" );
782 var_Destroy( p_filter->p_libvlc, "logo-x" );
783 var_Destroy( p_filter->p_libvlc, "logo-y" );
784 var_Destroy( p_filter->p_libvlc, "logo-delay" );
785 var_Destroy( p_filter->p_libvlc, "logo-repeat" );
786 var_Destroy( p_filter->p_libvlc, "logo-position" );
787 var_Destroy( p_filter->p_libvlc, "logo-transparency" );
790 /*****************************************************************************
791 * Filter: the whole thing
792 *****************************************************************************
793 * This function outputs subpictures at regular time intervals.
794 *****************************************************************************/
795 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
797 filter_sys_t *p_sys = p_filter->p_sys;
798 logo_list_t *p_logo_list = p_sys->p_logo_list;
800 subpicture_region_t *p_region;
805 vlc_mutex_lock( &p_logo_list->lock );
806 /* Basic test: b_need_update occurs on a dynamic change,
807 & i_next_pic is the general timer, when to
808 look at updating the logo image */
810 if( ( ( !p_sys->b_need_update ) && ( p_logo_list->i_next_pic > date ) )
811 || !p_logo_list->i_repeat )
813 vlc_mutex_unlock( &p_logo_list->lock );
816 /* prior code tested on && p_sys->i_last_date +5000000 > date ) return 0; */
818 /* adjust index to the next logo */
819 p_logo_list->i_counter =
820 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
822 p_logo = &p_logo_list->p_logo[p_logo_list->i_counter];
823 p_pic = p_logo->p_pic;
825 /* Allocate the subpicture internal data. */
826 p_spu = p_filter->pf_sub_buffer_new( p_filter );
829 vlc_mutex_unlock( &p_logo_list->lock );
833 p_spu->b_absolute = p_sys->b_absolute;
834 p_spu->i_start = p_sys->i_last_date = date;
836 p_spu->b_ephemer = VLC_TRUE;
838 p_sys->b_need_update = VLC_FALSE;
839 p_logo_list->i_next_pic = date +
840 ( p_logo->i_delay != -1 ? p_logo->i_delay : p_logo_list->i_delay ) * 1000;
842 if( p_logo_list->i_repeat != -1
843 && p_logo_list->i_counter == 0 )
845 p_logo_list->i_repeat--;
846 if( p_logo_list->i_repeat == 0 )
848 vlc_mutex_unlock( &p_logo_list->lock );
853 if( !p_pic || !p_logo->i_alpha
854 || ( p_logo->i_alpha == -1 && !p_logo_list->i_alpha ) )
856 /* Send an empty subpicture to clear the display */
857 vlc_mutex_unlock( &p_logo_list->lock );
861 /* Create new SPU region */
862 memset( &fmt, 0, sizeof(video_format_t) );
863 fmt.i_chroma = VLC_FOURCC('Y','U','V','A');
864 fmt.i_aspect = VOUT_ASPECT_FACTOR;
865 fmt.i_sar_num = fmt.i_sar_den = 1;
866 fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
867 fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
868 fmt.i_x_offset = fmt.i_y_offset = 0;
869 p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
872 msg_Err( p_filter, "cannot allocate SPU region" );
873 p_filter->pf_sub_buffer_del( p_filter, p_spu );
874 vlc_mutex_unlock( &p_logo_list->lock );
878 vout_CopyPicture( p_filter, &p_region->picture, p_pic );
879 vlc_mutex_unlock( &p_logo_list->lock );
881 /* where to locate the logo: */
882 if( p_sys->posx < 0 || p_sys->posy < 0 )
883 { /* set to one of the 9 relative locations */
884 p_region->i_align = p_sys->pos;
887 p_spu->b_absolute = VLC_FALSE;
890 { /* set to an absolute xy, referenced to upper left corner */
891 p_region->i_align = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
892 p_spu->i_x = p_sys->posx;
893 p_spu->i_y = p_sys->posy;
894 p_spu->b_absolute = VLC_TRUE;
897 p_spu->p_region = p_region;
899 p_spu->i_alpha = ( p_logo->i_alpha != -1 ?
900 p_logo->i_alpha : p_logo_list->i_alpha );
905 /*****************************************************************************
906 * Callback to update params on the fly
907 *****************************************************************************/
908 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
909 vlc_value_t oldval, vlc_value_t newval, void *p_data )
911 filter_sys_t *p_sys = (filter_sys_t *)p_data;
912 logo_list_t *p_logo_list = p_sys->p_logo_list;
914 if( !strncmp( psz_var, "logo-file", 6 ) )
916 vlc_mutex_lock( &p_logo_list->lock );
917 FreeLogoList( p_logo_list );
918 p_logo_list->psz_filename = strdup( newval.psz_string );
919 LoadLogoList( p_this, p_logo_list );
920 vlc_mutex_unlock( &p_logo_list->lock );
921 p_sys->b_need_update = VLC_TRUE;
923 else if ( !strncmp( psz_var, "logo-x", 6 ) )
925 p_sys->posx = newval.i_int;
927 else if ( !strncmp( psz_var, "logo-y", 6 ) )
929 p_sys->posy = newval.i_int;
931 else if ( !strncmp( psz_var, "logo-position", 12 ) )
933 p_sys->pos = newval.i_int;
935 else if ( !strncmp( psz_var, "logo-transparency", 9 ) )
937 vlc_mutex_lock( &p_logo_list->lock );
938 p_logo_list->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
939 vlc_mutex_unlock( &p_logo_list->lock );
941 else if ( !strncmp( psz_var, "logo-repeat", 11 ) )
943 vlc_mutex_lock( &p_logo_list->lock );
944 p_logo_list->i_repeat = newval.i_int;
945 vlc_mutex_unlock( &p_logo_list->lock );
947 p_sys->b_need_update = VLC_TRUE;