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") );
125 add_shortcut( "logo" );
128 static const char *ppsz_filter_options[] = {
129 "file", "x", "y", "delay", "repeat", "transparency", "position", NULL
132 /*****************************************************************************
133 * Structure to hold the set of individual logo image names, times,
135 ****************************************************************************/
138 char *psz_file; /* candidate for deletion -- not needed */
139 int i_delay; /* -1 means use default delay */
140 int i_alpha; /* -1 means use default alpha */
145 /*****************************************************************************
146 * Logo list structure. Common to both the vout and sub picture filter
147 ****************************************************************************/
150 logo_t *p_logo; /* the parsing's result */
151 unsigned int i_count; /* the number of logo images to be displayed */
153 int i_repeat; /* how often to repeat the images, image time in ms */
154 mtime_t i_next_pic; /* when to bring up a new logo image */
156 unsigned int i_counter; /* index into the list of logo images */
158 int i_delay; /* default delay (0 - 60000 ms) */
159 int i_alpha; /* default alpha */
161 char *psz_filename; /* --logo-file string ( is it really useful
167 /*****************************************************************************
168 * LoadImage: loads the logo image into memory
169 *****************************************************************************/
170 static picture_t *LoadImage( vlc_object_t *p_this, char *psz_filename )
173 image_handler_t *p_image;
174 video_format_t fmt_in = {0}, fmt_out = {0};
176 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
177 p_image = image_HandlerCreate( p_this );
178 p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
179 image_HandlerDelete( p_image );
184 /*****************************************************************************
185 * LoadLogoList: loads the logo images into memory
186 *****************************************************************************
187 * Read the logo-file input switch, obtaining a list of images and associated
188 * durations and transparencies. Store the image(s), and times. An image
189 * without a stated time or transparency will use the logo-delay and
190 * logo-transparency values.
191 *****************************************************************************/
192 #define LoadLogoList( a, b ) __LoadLogoList( VLC_OBJECT( a ), b )
193 static void __LoadLogoList( vlc_object_t *p_this, logo_list_t *p_logo_list )
195 char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */
197 logo_t *p_logo; /* the parsing's result */
199 p_logo_list->i_counter = 0;
200 p_logo_list->i_next_pic = 0;
202 psz_list = strdup( p_logo_list->psz_filename );
204 /* Count the number logos == number of ';' + 1 */
205 p_logo_list->i_count = 1;
206 for( i = 0; i < strlen( psz_list ); i++ )
208 if( psz_list[i] == ';' ) p_logo_list->i_count++;
211 p_logo_list->p_logo = p_logo =
212 (logo_t *)malloc( p_logo_list->i_count * sizeof(logo_t) );
215 for( i = 0; i < p_logo_list->i_count; i++ )
219 p_c = strchr( psz_list, ';' );
220 p_c2 = strchr( psz_list, ',' );
222 p_logo[i].i_alpha = -1; /* use default settings */
223 p_logo[i].i_delay = -1; /* use default settings */
225 if( p_c2 && ( p_c2 < p_c || !p_c ) )
227 /* <logo>,<delay>[,<alpha>] type */
228 if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' )
229 p_logo[i].i_delay = atoi( p_c2+1 );
231 if( ( p_c2 = strchr( p_c2+1, ',' ) )
232 && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' )
233 p_logo[i].i_alpha = atoi( p_c2 + 1 );
238 if( p_c ) *p_c = '\0';
241 p_logo[i].psz_file = strdup( psz_list );
242 p_logo[i].p_pic = LoadImage( p_this, p_logo[i].psz_file );
244 if( !p_logo[i].p_pic )
246 msg_Warn( p_this, "error while loading logo %s, will be skipped",
247 p_logo[i].psz_file );
250 if( p_c ) psz_list = p_c + 1;
253 for( i = 0; i < p_logo_list->i_count; i++ )
255 msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d",
256 p_logo[i].psz_file, p_logo[i].i_delay, p_logo[i].i_alpha );
259 /* initialize so that on the first update it will wrap back to 0 */
260 p_logo_list->i_counter = p_logo_list->i_count;
263 /*****************************************************************************
265 *****************************************************************************/
266 static void FreeLogoList( logo_list_t *p_logo_list )
269 FREENULL( p_logo_list->psz_filename );
270 for( i = 0; i < p_logo_list->i_count; i++ )
272 logo_t *p_logo = &p_logo_list->p_logo[i];
273 FREENULL( p_logo->psz_file );
276 p_logo->p_pic->pf_release( p_logo->p_pic );
277 p_logo->p_pic = NULL;
282 /*****************************************************************************
283 * vout_sys_t: logo video output method descriptor
284 *****************************************************************************
285 * This structure is part of the video output thread descriptor.
286 * It describes the Invert specific properties of an output thread.
287 *****************************************************************************/
290 logo_list_t *p_logo_list;
292 vout_thread_t *p_vout;
296 int i_width, i_height;
300 /*****************************************************************************
301 * Create: allocates logo video thread output method
302 *****************************************************************************/
303 static int Create( vlc_object_t *p_this )
305 vout_thread_t *p_vout = (vout_thread_t *)p_this;
307 logo_list_t *p_logo_list;
309 /* Allocate structure */
310 p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
313 msg_Err( p_vout, "out of memory" );
316 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
317 if( p_logo_list == NULL )
319 msg_Err( p_vout, "out of memory" );
324 p_vout->pf_init = Init;
325 p_vout->pf_end = End;
326 p_vout->pf_manage = NULL;
327 p_vout->pf_render = Render;
328 p_vout->pf_display = NULL;
329 p_vout->pf_control = Control;
331 config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options,
334 p_logo_list->psz_filename = var_CreateGetStringCommand( p_vout,
336 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
338 msg_Err( p_vout, "logo file not specified" );
342 p_sys->pos = var_CreateGetIntegerCommand( p_vout, "logo-position" );
343 p_sys->posx = var_CreateGetIntegerCommand( p_vout, "logo-x" );
344 p_sys->posy = var_CreateGetIntegerCommand( p_vout, "logo-y" );
345 p_logo_list->i_delay = __MAX( __MIN(
346 var_CreateGetIntegerCommand( p_vout, "logo-delay" ) , 60000 ), 0 );
347 p_logo_list->i_repeat = var_CreateGetIntegerCommand( p_vout, "logo-repeat");
348 p_logo_list->i_alpha = __MAX( __MIN(
349 var_CreateGetIntegerCommand( p_vout, "logo-transparency" ), 255 ), 0 );
351 LoadLogoList( p_vout, p_logo_list );
356 /*****************************************************************************
357 * Init: initialize logo video thread output method
358 *****************************************************************************/
359 static int Init( vout_thread_t *p_vout )
361 vout_sys_t *p_sys = p_vout->p_sys;
364 video_format_t fmt = {0};
366 logo_list_t *p_logo_list = p_sys->p_logo_list;
368 I_OUTPUTPICTURES = 0;
370 /* adjust index to the next logo */
371 p_logo_list->i_counter =
372 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
374 p_pic = p_logo_list->p_logo[p_logo_list->i_counter].p_pic;
375 /* Initialize the output structure */
376 p_vout->output.i_chroma = p_vout->render.i_chroma;
377 p_vout->output.i_width = p_vout->render.i_width;
378 p_vout->output.i_height = p_vout->render.i_height;
379 p_vout->output.i_aspect = p_vout->render.i_aspect;
380 p_vout->fmt_out = p_vout->fmt_in;
381 fmt = p_vout->fmt_out;
383 /* Load the video blending filter */
384 p_sys->p_blend = vlc_object_create( p_vout, sizeof(filter_t) );
385 vlc_object_attach( p_sys->p_blend, p_vout );
386 p_sys->p_blend->fmt_out.video.i_x_offset =
387 p_sys->p_blend->fmt_out.video.i_y_offset = 0;
388 p_sys->p_blend->fmt_in.video.i_x_offset =
389 p_sys->p_blend->fmt_in.video.i_y_offset = 0;
390 p_sys->p_blend->fmt_out.video.i_aspect = p_vout->render.i_aspect;
391 p_sys->p_blend->fmt_out.video.i_chroma = p_vout->output.i_chroma;
392 p_sys->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','A');
393 p_sys->p_blend->fmt_in.video.i_aspect = VOUT_ASPECT_FACTOR;
395 p_sys->p_blend->fmt_in.video.i_width =
396 p_sys->p_blend->fmt_in.video.i_visible_width =
397 p_pic ? p_pic->p[Y_PLANE].i_visible_pitch : 0;
399 p_sys->p_blend->fmt_in.video.i_height =
400 p_sys->p_blend->fmt_in.video.i_visible_height =
401 p_pic ? p_pic->p[Y_PLANE].i_visible_lines : 0;
402 p_sys->p_blend->fmt_out.video.i_width =
403 p_sys->p_blend->fmt_out.video.i_visible_width =
404 p_vout->output.i_width;
405 p_sys->p_blend->fmt_out.video.i_height =
406 p_sys->p_blend->fmt_out.video.i_visible_height =
407 p_vout->output.i_height;
409 p_sys->p_blend->p_module =
410 module_Need( p_sys->p_blend, "video blending", 0, 0 );
411 if( !p_sys->p_blend->p_module )
413 msg_Err( p_vout, "can't open blending filter, aborting" );
414 vlc_object_detach( p_sys->p_blend );
415 vlc_object_destroy( p_sys->p_blend );
419 if( p_sys->posx < 0 || p_sys->posy < 0 )
421 p_sys->posx = 0; p_sys->posy = 0;
423 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
425 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
427 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
429 p_sys->posy = p_vout->render.i_height / 2 - p_sys->i_height / 2;
432 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
434 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
436 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
438 p_sys->posx = p_vout->render.i_width / 2 - p_sys->i_width / 2;
446 /* Try to open the real video output */
447 msg_Dbg( p_vout, "spawning the real video output" );
449 p_sys->p_vout = vout_Create( p_vout, &fmt );
451 /* Everything failed */
452 if( p_sys->p_vout == NULL )
454 msg_Err( p_vout, "can't open vout, aborting" );
458 var_AddCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
459 var_AddCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
461 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
462 ADD_CALLBACKS( p_sys->p_vout, SendEvents );
463 ADD_PARENT_CALLBACKS( SendEventsToChild );
468 /*****************************************************************************
469 * End: terminate logo video thread output method
470 *****************************************************************************/
471 static void End( vout_thread_t *p_vout )
473 vout_sys_t *p_sys = p_vout->p_sys;
476 /* Free the fake output buffers we allocated */
477 for( i_index = I_OUTPUTPICTURES ; i_index ; )
480 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
483 var_DelCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
484 var_DelCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
488 DEL_CALLBACKS( p_sys->p_vout, SendEvents );
489 vlc_object_detach( p_sys->p_vout );
490 vout_Destroy( p_sys->p_vout );
493 if( p_sys->p_blend->p_module )
494 module_Unneed( p_sys->p_blend, p_sys->p_blend->p_module );
495 vlc_object_detach( p_sys->p_blend );
496 vlc_object_destroy( p_sys->p_blend );
499 /*****************************************************************************
500 * Destroy: destroy logo video thread output method
501 *****************************************************************************/
502 static void Destroy( vlc_object_t *p_this )
504 vout_thread_t *p_vout = (vout_thread_t *)p_this;
505 vout_sys_t *p_sys = p_vout->p_sys;
507 DEL_PARENT_CALLBACKS( SendEventsToChild );
509 FreeLogoList( p_sys->p_logo_list );
510 free( p_sys->p_logo_list );
515 /*****************************************************************************
516 * Render: render the logo onto the video
517 *****************************************************************************/
518 static void Render( vout_thread_t *p_vout, picture_t *p_inpic )
520 vout_sys_t *p_sys = p_vout->p_sys;
523 logo_list_t *p_logo_list;
526 p_logo_list = p_sys->p_logo_list;
528 if( p_logo_list->i_next_pic < p_inpic->date )
530 /* It's time to use a new logo */
531 p_logo_list->i_counter =
532 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
533 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
534 p_pic = p_logo->p_pic;
535 p_logo_list->i_next_pic = p_inpic->date + ( p_logo->i_delay != -1 ?
536 p_logo->i_delay : p_logo_list->i_delay ) * 1000;
541 p_sys->p_blend->fmt_in.video.i_width =
542 p_sys->p_blend->fmt_in.video.i_visible_width =
543 p_pic->p[Y_PLANE].i_visible_pitch;
545 p_sys->p_blend->fmt_in.video.i_height =
546 p_sys->p_blend->fmt_in.video.i_visible_height =
547 p_pic->p[Y_PLANE].i_visible_lines;
551 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
553 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
555 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
557 p_sys->posy = p_vout->render.i_height/2 - p_sys->i_height/2;
559 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
561 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
563 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
565 p_sys->posx = p_vout->render.i_width/2 - p_sys->i_width/2;
573 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
574 p_pic = p_logo->p_pic;
577 /* This is a new frame. Get a structure from the video_output. */
578 while( !(p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 )) )
580 if( p_vout->b_die || p_vout->b_error ) return;
581 msleep( VOUT_OUTMEM_SLEEP );
584 vout_CopyPicture( p_vout, p_outpic, p_inpic );
585 vout_DatePicture( p_sys->p_vout, p_outpic, p_inpic->date );
588 p_sys->p_blend->pf_video_blend( p_sys->p_blend, p_outpic, p_outpic,
589 p_pic, p_sys->posx, p_sys->posy,
590 p_logo->i_alpha != -1 ? p_logo->i_alpha
591 : p_logo_list->i_alpha );
593 vout_DisplayPicture( p_sys->p_vout, p_outpic );
596 /*****************************************************************************
597 * SendEvents: forward mouse and keyboard events to the parent p_vout
598 *****************************************************************************/
599 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
600 vlc_value_t oldval, vlc_value_t newval, void *p_data )
602 var_Set( (vlc_object_t *)p_data, psz_var, newval );
606 /*****************************************************************************
607 * MouseEvent: callback for mouse events
608 *****************************************************************************/
609 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
610 vlc_value_t oldval, vlc_value_t newval, void *p_data )
612 vout_thread_t *p_vout = (vout_thread_t*)p_data;
613 vout_sys_t *p_sys = p_vout->p_sys;
617 var_Get( p_vout->p_sys->p_vout, "mouse-button-down", &valb );
619 i_delta = newval.i_int - oldval.i_int;
621 if( (valb.i_int & 0x1) == 0 )
626 if( psz_var[6] == 'x' )
629 var_Get( p_vout->p_sys->p_vout, "mouse-y", &valy );
630 if( newval.i_int >= (int)p_sys->posx &&
631 valy.i_int >= (int)p_sys->posy &&
632 newval.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
633 valy.i_int <= (int)(p_sys->posy + p_sys->i_height) )
635 p_sys->posx = __MIN( __MAX( p_sys->posx + i_delta, 0 ),
636 p_vout->output.i_width - p_sys->i_width );
639 else if( psz_var[6] == 'y' )
642 var_Get( p_vout->p_sys->p_vout, "mouse-x", &valx );
643 if( valx.i_int >= (int)p_sys->posx &&
644 newval.i_int >= (int)p_sys->posy &&
645 valx.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
646 newval.i_int <= (int)(p_sys->posy + p_sys->i_height) )
648 p_sys->posy = __MIN( __MAX( p_sys->posy + i_delta, 0 ),
649 p_vout->output.i_height - p_sys->i_height );
656 /*****************************************************************************
657 * Control: control facility for the vout (forwards to child vout)
658 *****************************************************************************/
659 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
661 return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
664 /*****************************************************************************
665 * SendEventsToChild: forward events to the child/children vout
666 *****************************************************************************/
667 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
668 vlc_value_t oldval, vlc_value_t newval, void *p_data )
670 vout_thread_t *p_vout = (vout_thread_t *)p_this;
671 var_Set( p_vout->p_sys->p_vout, psz_var, newval );
675 /*****************************************************************************
676 * filter_sys_t: logo filter descriptor
677 *****************************************************************************/
680 logo_list_t *p_logo_list;
684 vlc_bool_t b_absolute;
687 /* On the fly control variable */
688 vlc_bool_t b_need_update;
691 static subpicture_t *Filter( filter_t *, mtime_t );
693 /*****************************************************************************
694 * CreateFilter: allocates logo video filter
695 *****************************************************************************/
696 static int CreateFilter( vlc_object_t *p_this )
698 filter_t *p_filter = (filter_t *)p_this;
700 logo_list_t *p_logo_list;
702 /* Allocate structure */
703 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
706 msg_Err( p_filter, "out of memory" );
709 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
710 if( p_logo_list == NULL )
712 msg_Err( p_filter, "out of memory" );
717 config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
720 /* Hook used for callback variables */
721 p_logo_list->psz_filename =
722 var_CreateGetStringCommand( p_filter, "logo-file" );
723 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
725 msg_Err( p_this, "logo file not specified" );
731 p_sys->posx = var_CreateGetIntegerCommand( p_filter, "logo-x" );
732 p_sys->posy = var_CreateGetIntegerCommand( p_filter, "logo-y" );
733 p_sys->pos = var_CreateGetIntegerCommand( p_filter, "logo-position" );
734 p_logo_list->i_alpha = __MAX( __MIN( var_CreateGetIntegerCommand(
735 p_filter, "logo-transparency"), 255 ), 0 );
736 p_logo_list->i_delay =
737 var_CreateGetIntegerCommand( p_filter, "logo-delay" );
738 p_logo_list->i_repeat =
739 var_CreateGetIntegerCommand( p_filter, "logo-repeat" );
741 var_AddCallback( p_filter->p_libvlc_global, "logo-file", LogoCallback, p_sys );
742 var_AddCallback( p_filter->p_libvlc_global, "logo-x", LogoCallback, p_sys );
743 var_AddCallback( p_filter->p_libvlc_global, "logo-y", LogoCallback, p_sys );
744 var_AddCallback( p_filter->p_libvlc_global, "logo-position", LogoCallback, p_sys );
745 var_AddCallback( p_filter->p_libvlc_global, "logo-transparency", LogoCallback, p_sys );
746 var_AddCallback( p_filter->p_libvlc_global, "logo-repeat", LogoCallback, p_sys );
748 vlc_mutex_init( p_filter, &p_logo_list->lock );
749 vlc_mutex_lock( &p_logo_list->lock );
751 LoadLogoList( p_this, p_logo_list );
753 vlc_mutex_unlock( &p_logo_list->lock );
756 p_filter->pf_sub_filter = Filter;
757 p_sys->b_need_update = VLC_TRUE;
759 p_sys->i_last_date = 0;
764 /*****************************************************************************
765 * DestroyFilter: destroy logo video filter
766 *****************************************************************************/
767 static void DestroyFilter( vlc_object_t *p_this )
769 filter_t *p_filter = (filter_t *)p_this;
770 filter_sys_t *p_sys = p_filter->p_sys;
772 vlc_mutex_destroy( &p_sys->p_logo_list->lock );
773 FreeLogoList( p_sys->p_logo_list );
774 free( p_sys->p_logo_list );
777 /* Delete the logo variables from INPUT */
778 var_Destroy( p_filter->p_libvlc_global , "logo-file" );
779 var_Destroy( p_filter->p_libvlc_global , "logo-x" );
780 var_Destroy( p_filter->p_libvlc_global , "logo-y" );
781 var_Destroy( p_filter->p_libvlc_global , "logo-delay" );
782 var_Destroy( p_filter->p_libvlc_global , "logo-repeat" );
783 var_Destroy( p_filter->p_libvlc_global , "logo-position" );
784 var_Destroy( p_filter->p_libvlc_global , "logo-transparency" );
787 /*****************************************************************************
788 * Filter: the whole thing
789 *****************************************************************************
790 * This function outputs subpictures at regular time intervals.
791 *****************************************************************************/
792 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
794 filter_sys_t *p_sys = p_filter->p_sys;
795 logo_list_t *p_logo_list = p_sys->p_logo_list;
797 subpicture_region_t *p_region;
802 vlc_mutex_lock( &p_logo_list->lock );
803 /* Basic test: b_need_update occurs on a dynamic change,
804 & i_next_pic is the general timer, when to
805 look at updating the logo image */
807 if( ( ( !p_sys->b_need_update ) && ( p_logo_list->i_next_pic > date ) )
808 || !p_logo_list->i_repeat )
810 vlc_mutex_unlock( &p_logo_list->lock );
813 /* prior code tested on && p_sys->i_last_date +5000000 > date ) return 0; */
815 /* adjust index to the next logo */
816 p_logo_list->i_counter =
817 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
819 p_logo = &p_logo_list->p_logo[p_logo_list->i_counter];
820 p_pic = p_logo->p_pic;
822 /* Allocate the subpicture internal data. */
823 p_spu = p_filter->pf_sub_buffer_new( p_filter );
826 vlc_mutex_unlock( &p_logo_list->lock );
830 p_spu->b_absolute = p_sys->b_absolute;
831 p_spu->i_start = p_sys->i_last_date = date;
833 p_spu->b_ephemer = VLC_TRUE;
835 p_sys->b_need_update = VLC_FALSE;
836 p_logo_list->i_next_pic = date +
837 ( p_logo->i_delay != -1 ? p_logo->i_delay : p_logo_list->i_delay ) * 1000;
839 if( p_logo_list->i_repeat != -1
840 && p_logo_list->i_counter == 0 )
842 p_logo_list->i_repeat--;
843 if( p_logo_list->i_repeat == 0 )
845 vlc_mutex_unlock( &p_logo_list->lock );
850 if( !p_pic || !p_logo->i_alpha
851 || ( p_logo->i_alpha == -1 && !p_logo_list->i_alpha ) )
853 /* Send an empty subpicture to clear the display */
854 vlc_mutex_unlock( &p_logo_list->lock );
858 /* Create new SPU region */
859 memset( &fmt, 0, sizeof(video_format_t) );
860 fmt.i_chroma = VLC_FOURCC('Y','U','V','A');
861 fmt.i_aspect = VOUT_ASPECT_FACTOR;
862 fmt.i_sar_num = fmt.i_sar_den = 1;
863 fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
864 fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
865 fmt.i_x_offset = fmt.i_y_offset = 0;
866 p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
869 msg_Err( p_filter, "cannot allocate SPU region" );
870 p_filter->pf_sub_buffer_del( p_filter, p_spu );
871 vlc_mutex_unlock( &p_logo_list->lock );
875 vout_CopyPicture( p_filter, &p_region->picture, p_pic );
876 vlc_mutex_unlock( &p_logo_list->lock );
878 /* where to locate the logo: */
879 if( p_sys->posx < 0 || p_sys->posy < 0 )
880 { /* set to one of the 9 relative locations */
881 p_spu->i_flags = p_sys->pos;
884 p_spu->b_absolute = VLC_FALSE;
887 { /* set to an absolute xy, referenced to upper left corner */
888 p_spu->i_flags = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
889 p_spu->i_x = p_sys->posx;
890 p_spu->i_y = p_sys->posy;
891 p_spu->b_absolute = VLC_TRUE;
894 p_spu->p_region = p_region;
896 p_spu->i_alpha = ( p_logo->i_alpha != -1 ?
897 p_logo->i_alpha : p_logo_list->i_alpha );
902 /*****************************************************************************
903 * Callback to update params on the fly
904 *****************************************************************************/
905 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
906 vlc_value_t oldval, vlc_value_t newval, void *p_data )
908 filter_sys_t *p_sys = (filter_sys_t *)p_data;
909 logo_list_t *p_logo_list = p_sys->p_logo_list;
911 if( !strncmp( psz_var, "logo-file", 6 ) )
913 vlc_mutex_lock( &p_logo_list->lock );
914 FreeLogoList( p_logo_list );
915 p_logo_list->psz_filename = strdup( newval.psz_string );
916 LoadLogoList( p_this, p_logo_list );
917 vlc_mutex_unlock( &p_logo_list->lock );
918 p_sys->b_need_update = VLC_TRUE;
920 else if ( !strncmp( psz_var, "logo-x", 6 ) )
922 p_sys->posx = newval.i_int;
924 else if ( !strncmp( psz_var, "logo-y", 6 ) )
926 p_sys->posy = newval.i_int;
928 else if ( !strncmp( psz_var, "logo-position", 12 ) )
930 p_sys->pos = newval.i_int;
932 else if ( !strncmp( psz_var, "logo-transparency", 9 ) )
934 vlc_mutex_lock( &p_logo_list->lock );
935 p_logo_list->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
936 vlc_mutex_unlock( &p_logo_list->lock );
938 else if ( !strncmp( psz_var, "logo-repeat", 11 ) )
940 vlc_mutex_lock( &p_logo_list->lock );
941 p_logo_list->i_repeat = newval.i_int;
942 vlc_mutex_unlock( &p_logo_list->lock );
944 p_sys->b_need_update = VLC_TRUE;