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 *****************************************************************************/
33 #include "vlc_filter.h"
34 #include "filter_common.h"
35 #include "vlc_image.h"
42 /*****************************************************************************
44 *****************************************************************************/
45 static int Create ( vlc_object_t * );
46 static void Destroy ( vlc_object_t * );
48 static int Init ( vout_thread_t * );
49 static void End ( vout_thread_t * );
50 static void Render ( vout_thread_t *, picture_t * );
52 static int SendEvents( vlc_object_t *, char const *,
53 vlc_value_t, vlc_value_t, void * );
54 static int MouseEvent( vlc_object_t *, char const *,
55 vlc_value_t , vlc_value_t , void * );
56 static int Control ( vout_thread_t *, int, va_list );
58 static int CreateFilter ( vlc_object_t * );
59 static void DestroyFilter( vlc_object_t * );
61 static int LogoCallback( vlc_object_t *, char const *,
62 vlc_value_t, vlc_value_t, void * );
64 /*****************************************************************************
66 *****************************************************************************/
67 #define FILE_TEXT N_("Logo filenames")
68 #define FILE_LONGTEXT N_("Full path of the image files to use. Format is " \
69 "<image>[,<delay in ms>[,<alpha>]][;<image>[,<delay>[,<alpha>]]][;...]. " \
70 "If you only have one file, simply enter its filename.")
71 #define REPEAT_TEXT N_("Logo animation # of loops")
72 #define REPEAT_LONGTEXT N_("Number of loops for the logo animation." \
73 "-1 = continuous, 0 = disabled")
74 #define DELAY_TEXT N_("Logo individual image time in ms")
75 #define DELAY_LONGTEXT N_("Individual image display time of 0 - 60000 ms.")
77 #define POSX_TEXT N_("X coordinate")
78 #define POSX_LONGTEXT N_("X coordinate of the logo. You can move the logo " \
79 "by left-clicking it." )
80 #define POSY_TEXT N_("Y coordinate")
81 #define POSY_LONGTEXT N_("Y coordinate of the logo. You can move the logo " \
82 "by left-clicking it." )
83 #define TRANS_TEXT N_("Transparency of the logo")
84 #define TRANS_LONGTEXT N_("Logo transparency value " \
85 "(from 0 for full transparency to 255 for full opacity)." )
86 #define POS_TEXT N_("Logo position")
87 #define POS_LONGTEXT N_( \
88 "Enforce the logo position on the video " \
89 "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
90 "also use combinations of these values, eg 6 = top-right).")
92 #define CFG_PREFIX "logo-"
94 static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
95 static const char *ppsz_pos_descriptions[] =
96 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
97 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
100 set_description( _("Logo video filter") );
101 set_capability( "video filter", 0 );
102 set_shortname( _("Logo overlay") );
103 set_category( CAT_VIDEO );
104 set_subcategory( SUBCAT_VIDEO_SUBPIC );
105 add_shortcut( "logo" );
106 set_callbacks( Create, Destroy );
108 add_file( CFG_PREFIX "file", NULL, NULL, FILE_TEXT, FILE_LONGTEXT, VLC_FALSE );
109 add_integer( CFG_PREFIX "x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_TRUE );
110 add_integer( CFG_PREFIX "y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_TRUE );
111 /* default to 1000 ms per image, continuously cycle through them */
112 add_integer( CFG_PREFIX "delay", 1000, NULL, DELAY_TEXT, DELAY_LONGTEXT, VLC_TRUE );
113 add_integer( CFG_PREFIX "repeat", -1, NULL, REPEAT_TEXT, REPEAT_LONGTEXT, VLC_TRUE );
114 add_integer_with_range( CFG_PREFIX "transparency", 255, 0, 255, NULL,
115 TRANS_TEXT, TRANS_LONGTEXT, VLC_FALSE );
116 add_integer( CFG_PREFIX "position", 6, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
117 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
119 /* subpicture filter submodule */
121 set_capability( "sub filter", 0 );
122 set_callbacks( CreateFilter, DestroyFilter );
123 set_description( _("Logo sub filter") );
126 static const char *ppsz_filter_options[] = {
127 "file", "x", "y", "delay", "repeat", "transparency", "position", NULL
130 /*****************************************************************************
131 * Structure to hold the set of individual logo image names, times,
133 ****************************************************************************/
136 char *psz_file; /* candidate for deletion -- not needed */
137 int i_delay; /* -1 means use default delay */
138 int i_alpha; /* -1 means use default alpha */
143 /*****************************************************************************
144 * Logo list structure. Common to both the vout and sub picture filter
145 ****************************************************************************/
148 logo_t *p_logo; /* the parsing's result */
149 unsigned int i_count; /* the number of logo images to be displayed */
151 int i_repeat; /* how often to repeat the images, image time in ms */
152 mtime_t i_next_pic; /* when to bring up a new logo image */
154 unsigned int i_counter; /* index into the list of logo images */
156 int i_delay; /* default delay (0 - 60000 ms) */
157 int i_alpha; /* default alpha */
159 char *psz_filename; /* --logo-file string ( is it really useful
165 /*****************************************************************************
166 * LoadImage: loads the logo image into memory
167 *****************************************************************************/
168 static picture_t *LoadImage( vlc_object_t *p_this, char *psz_filename )
171 image_handler_t *p_image;
172 video_format_t fmt_in;
173 video_format_t fmt_out;
175 memset( &fmt_in, 0, sizeof(video_format_t) );
176 memset( &fmt_out, 0, sizeof(video_format_t) );
178 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
179 p_image = image_HandlerCreate( p_this );
180 p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
181 image_HandlerDelete( p_image );
186 /*****************************************************************************
187 * LoadLogoList: loads the logo images into memory
188 *****************************************************************************
189 * Read the logo-file input switch, obtaining a list of images and associated
190 * durations and transparencies. Store the image(s), and times. An image
191 * without a stated time or transparency will use the logo-delay and
192 * logo-transparency values.
193 *****************************************************************************/
194 #define LoadLogoList( a, b ) __LoadLogoList( VLC_OBJECT( a ), b )
195 static void __LoadLogoList( vlc_object_t *p_this, logo_list_t *p_logo_list )
197 char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */
199 logo_t *p_logo; /* the parsing's result */
201 p_logo_list->i_counter = 0;
202 p_logo_list->i_next_pic = 0;
204 psz_list = strdup( p_logo_list->psz_filename );
206 /* Count the number logos == number of ';' + 1 */
207 p_logo_list->i_count = 1;
208 for( i = 0; i < strlen( psz_list ); i++ )
210 if( psz_list[i] == ';' ) p_logo_list->i_count++;
213 p_logo_list->p_logo = p_logo =
214 (logo_t *)malloc( p_logo_list->i_count * sizeof(logo_t) );
217 for( i = 0; i < p_logo_list->i_count; i++ )
221 p_c = strchr( psz_list, ';' );
222 p_c2 = strchr( psz_list, ',' );
224 p_logo[i].i_alpha = -1; /* use default settings */
225 p_logo[i].i_delay = -1; /* use default settings */
227 if( p_c2 && ( p_c2 < p_c || !p_c ) )
229 /* <logo>,<delay>[,<alpha>] type */
230 if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' )
231 p_logo[i].i_delay = atoi( p_c2+1 );
233 if( ( p_c2 = strchr( p_c2+1, ',' ) )
234 && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' )
235 p_logo[i].i_alpha = atoi( p_c2 + 1 );
240 if( p_c ) *p_c = '\0';
243 p_logo[i].psz_file = strdup( psz_list );
244 p_logo[i].p_pic = LoadImage( p_this, p_logo[i].psz_file );
246 if( !p_logo[i].p_pic )
248 msg_Warn( p_this, "error while loading logo %s, will be skipped",
249 p_logo[i].psz_file );
252 if( p_c ) psz_list = p_c + 1;
255 for( i = 0; i < p_logo_list->i_count; i++ )
257 msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d",
258 p_logo[i].psz_file, p_logo[i].i_delay, p_logo[i].i_alpha );
261 /* initialize so that on the first update it will wrap back to 0 */
262 p_logo_list->i_counter = p_logo_list->i_count;
265 /*****************************************************************************
267 *****************************************************************************/
268 static void FreeLogoList( logo_list_t *p_logo_list )
271 FREENULL( p_logo_list->psz_filename );
272 for( i = 0; i < p_logo_list->i_count; i++ )
274 logo_t *p_logo = &p_logo_list->p_logo[i];
275 FREENULL( p_logo->psz_file );
278 p_logo->p_pic->pf_release( p_logo->p_pic );
279 p_logo->p_pic = NULL;
284 /*****************************************************************************
285 * vout_sys_t: logo video output method descriptor
286 *****************************************************************************
287 * This structure is part of the video output thread descriptor.
288 * It describes the Invert specific properties of an output thread.
289 *****************************************************************************/
292 logo_list_t *p_logo_list;
294 vout_thread_t *p_vout;
298 int i_width, i_height;
302 /*****************************************************************************
303 * Create: allocates logo video thread output method
304 *****************************************************************************/
305 static int Create( vlc_object_t *p_this )
307 vout_thread_t *p_vout = (vout_thread_t *)p_this;
309 logo_list_t *p_logo_list;
311 /* Allocate structure */
312 p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
315 msg_Err( p_vout, "out of memory" );
318 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
319 if( p_logo_list == NULL )
321 msg_Err( p_vout, "out of memory" );
326 p_vout->pf_init = Init;
327 p_vout->pf_end = End;
328 p_vout->pf_manage = NULL;
329 p_vout->pf_render = Render;
330 p_vout->pf_display = NULL;
331 p_vout->pf_control = Control;
333 config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options,
336 p_logo_list->psz_filename = var_CreateGetStringCommand( p_vout,
338 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
340 msg_Err( p_vout, "logo file not specified" );
344 p_sys->pos = var_CreateGetIntegerCommand( p_vout, "logo-position" );
345 p_sys->posx = var_CreateGetIntegerCommand( p_vout, "logo-x" );
346 p_sys->posy = var_CreateGetIntegerCommand( p_vout, "logo-y" );
347 p_logo_list->i_delay = __MAX( __MIN(
348 var_CreateGetIntegerCommand( p_vout, "logo-delay" ) , 60000 ), 0 );
349 p_logo_list->i_repeat = var_CreateGetIntegerCommand( p_vout, "logo-repeat");
350 p_logo_list->i_alpha = __MAX( __MIN(
351 var_CreateGetIntegerCommand( p_vout, "logo-transparency" ), 255 ), 0 );
353 LoadLogoList( p_vout, p_logo_list );
358 /*****************************************************************************
359 * Init: initialize logo video thread output method
360 *****************************************************************************/
361 static int Init( vout_thread_t *p_vout )
363 vout_sys_t *p_sys = p_vout->p_sys;
367 logo_list_t *p_logo_list = p_sys->p_logo_list;
369 I_OUTPUTPICTURES = 0;
370 memset( &fmt, 0, sizeof(video_format_t) );
372 /* adjust index to the next logo */
373 p_logo_list->i_counter =
374 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
376 p_pic = p_logo_list->p_logo[p_logo_list->i_counter].p_pic;
377 /* Initialize the output structure */
378 p_vout->output.i_chroma = p_vout->render.i_chroma;
379 p_vout->output.i_width = p_vout->render.i_width;
380 p_vout->output.i_height = p_vout->render.i_height;
381 p_vout->output.i_aspect = p_vout->render.i_aspect;
382 p_vout->fmt_out = p_vout->fmt_in;
383 fmt = p_vout->fmt_out;
385 /* Load the video blending filter */
386 p_sys->p_blend = vlc_object_create( p_vout, sizeof(filter_t) );
387 vlc_object_attach( p_sys->p_blend, p_vout );
388 p_sys->p_blend->fmt_out.video.i_x_offset =
389 p_sys->p_blend->fmt_out.video.i_y_offset = 0;
390 p_sys->p_blend->fmt_in.video.i_x_offset =
391 p_sys->p_blend->fmt_in.video.i_y_offset = 0;
392 p_sys->p_blend->fmt_out.video.i_aspect = p_vout->render.i_aspect;
393 p_sys->p_blend->fmt_out.video.i_chroma = p_vout->output.i_chroma;
394 p_sys->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','A');
395 p_sys->p_blend->fmt_in.video.i_aspect = VOUT_ASPECT_FACTOR;
397 p_sys->p_blend->fmt_in.video.i_width =
398 p_sys->p_blend->fmt_in.video.i_visible_width =
399 p_pic ? p_pic->p[Y_PLANE].i_visible_pitch : 0;
401 p_sys->p_blend->fmt_in.video.i_height =
402 p_sys->p_blend->fmt_in.video.i_visible_height =
403 p_pic ? p_pic->p[Y_PLANE].i_visible_lines : 0;
404 p_sys->p_blend->fmt_out.video.i_width =
405 p_sys->p_blend->fmt_out.video.i_visible_width =
406 p_vout->output.i_width;
407 p_sys->p_blend->fmt_out.video.i_height =
408 p_sys->p_blend->fmt_out.video.i_visible_height =
409 p_vout->output.i_height;
411 p_sys->p_blend->p_module =
412 module_Need( p_sys->p_blend, "video blending", 0, 0 );
413 if( !p_sys->p_blend->p_module )
415 msg_Err( p_vout, "can't open blending filter, aborting" );
416 vlc_object_detach( p_sys->p_blend );
417 vlc_object_destroy( p_sys->p_blend );
421 if( p_sys->posx < 0 || p_sys->posy < 0 )
423 p_sys->posx = 0; p_sys->posy = 0;
425 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
427 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
429 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
431 p_sys->posy = p_vout->render.i_height / 2 - p_sys->i_height / 2;
434 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
436 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
438 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
440 p_sys->posx = p_vout->render.i_width / 2 - p_sys->i_width / 2;
448 /* Try to open the real video output */
449 msg_Dbg( p_vout, "spawning the real video output" );
451 p_sys->p_vout = vout_Create( p_vout, &fmt );
453 /* Everything failed */
454 if( p_sys->p_vout == NULL )
456 msg_Err( p_vout, "can't open vout, aborting" );
460 var_AddCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
461 var_AddCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
463 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
464 ADD_CALLBACKS( p_sys->p_vout, SendEvents );
465 ADD_PARENT_CALLBACKS( SendEventsToChild );
470 /*****************************************************************************
471 * End: terminate logo video thread output method
472 *****************************************************************************/
473 static void End( vout_thread_t *p_vout )
475 vout_sys_t *p_sys = p_vout->p_sys;
478 /* Free the fake output buffers we allocated */
479 for( i_index = I_OUTPUTPICTURES ; i_index ; )
482 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
485 var_DelCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
486 var_DelCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
490 DEL_CALLBACKS( p_sys->p_vout, SendEvents );
491 vlc_object_detach( p_sys->p_vout );
492 vout_Destroy( p_sys->p_vout );
495 if( p_sys->p_blend->p_module )
496 module_Unneed( p_sys->p_blend, p_sys->p_blend->p_module );
497 vlc_object_detach( p_sys->p_blend );
498 vlc_object_destroy( p_sys->p_blend );
501 /*****************************************************************************
502 * Destroy: destroy logo video thread output method
503 *****************************************************************************/
504 static void Destroy( vlc_object_t *p_this )
506 vout_thread_t *p_vout = (vout_thread_t *)p_this;
507 vout_sys_t *p_sys = p_vout->p_sys;
509 DEL_PARENT_CALLBACKS( SendEventsToChild );
511 FreeLogoList( p_sys->p_logo_list );
512 free( p_sys->p_logo_list );
517 /*****************************************************************************
518 * Render: render the logo onto the video
519 *****************************************************************************/
520 static void Render( vout_thread_t *p_vout, picture_t *p_inpic )
522 vout_sys_t *p_sys = p_vout->p_sys;
525 logo_list_t *p_logo_list;
528 p_logo_list = p_sys->p_logo_list;
530 if( p_logo_list->i_next_pic < p_inpic->date )
532 /* It's time to use a new logo */
533 p_logo_list->i_counter =
534 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
535 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
536 p_pic = p_logo->p_pic;
537 p_logo_list->i_next_pic = p_inpic->date + ( p_logo->i_delay != -1 ?
538 p_logo->i_delay : p_logo_list->i_delay ) * 1000;
543 p_sys->p_blend->fmt_in.video.i_width =
544 p_sys->p_blend->fmt_in.video.i_visible_width =
545 p_pic->p[Y_PLANE].i_visible_pitch;
547 p_sys->p_blend->fmt_in.video.i_height =
548 p_sys->p_blend->fmt_in.video.i_visible_height =
549 p_pic->p[Y_PLANE].i_visible_lines;
553 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
555 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
557 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
559 p_sys->posy = p_vout->render.i_height/2 - p_sys->i_height/2;
561 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
563 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
565 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
567 p_sys->posx = p_vout->render.i_width/2 - p_sys->i_width/2;
575 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
576 p_pic = p_logo->p_pic;
579 /* This is a new frame. Get a structure from the video_output. */
580 while( !(p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 )) )
582 if( p_vout->b_die || p_vout->b_error ) return;
583 msleep( VOUT_OUTMEM_SLEEP );
586 vout_CopyPicture( p_vout, p_outpic, p_inpic );
587 vout_DatePicture( p_sys->p_vout, p_outpic, p_inpic->date );
590 p_sys->p_blend->pf_video_blend( p_sys->p_blend, p_outpic, p_outpic,
591 p_pic, p_sys->posx, p_sys->posy,
592 p_logo->i_alpha != -1 ? p_logo->i_alpha
593 : p_logo_list->i_alpha );
595 vout_DisplayPicture( p_sys->p_vout, p_outpic );
598 /*****************************************************************************
599 * SendEvents: forward mouse and keyboard events to the parent p_vout
600 *****************************************************************************/
601 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
602 vlc_value_t oldval, vlc_value_t newval, void *p_data )
604 var_Set( (vlc_object_t *)p_data, psz_var, newval );
608 /*****************************************************************************
609 * MouseEvent: callback for mouse events
610 *****************************************************************************/
611 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
612 vlc_value_t oldval, vlc_value_t newval, void *p_data )
614 vout_thread_t *p_vout = (vout_thread_t*)p_data;
615 vout_sys_t *p_sys = p_vout->p_sys;
619 var_Get( p_vout->p_sys->p_vout, "mouse-button-down", &valb );
621 i_delta = newval.i_int - oldval.i_int;
623 if( (valb.i_int & 0x1) == 0 )
628 if( psz_var[6] == 'x' )
631 var_Get( p_vout->p_sys->p_vout, "mouse-y", &valy );
632 if( newval.i_int >= (int)p_sys->posx &&
633 valy.i_int >= (int)p_sys->posy &&
634 newval.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
635 valy.i_int <= (int)(p_sys->posy + p_sys->i_height) )
637 p_sys->posx = __MIN( __MAX( p_sys->posx + i_delta, 0 ),
638 p_vout->output.i_width - p_sys->i_width );
641 else if( psz_var[6] == 'y' )
644 var_Get( p_vout->p_sys->p_vout, "mouse-x", &valx );
645 if( valx.i_int >= (int)p_sys->posx &&
646 newval.i_int >= (int)p_sys->posy &&
647 valx.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
648 newval.i_int <= (int)(p_sys->posy + p_sys->i_height) )
650 p_sys->posy = __MIN( __MAX( p_sys->posy + i_delta, 0 ),
651 p_vout->output.i_height - p_sys->i_height );
658 /*****************************************************************************
659 * Control: control facility for the vout (forwards to child vout)
660 *****************************************************************************/
661 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
663 return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
666 /*****************************************************************************
667 * SendEventsToChild: forward events to the child/children vout
668 *****************************************************************************/
669 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
670 vlc_value_t oldval, vlc_value_t newval, void *p_data )
672 vout_thread_t *p_vout = (vout_thread_t *)p_this;
673 var_Set( p_vout->p_sys->p_vout, psz_var, newval );
677 /*****************************************************************************
678 * filter_sys_t: logo filter descriptor
679 *****************************************************************************/
682 logo_list_t *p_logo_list;
686 vlc_bool_t b_absolute;
689 /* On the fly control variable */
690 vlc_bool_t b_need_update;
693 static subpicture_t *Filter( filter_t *, mtime_t );
695 /*****************************************************************************
696 * CreateFilter: allocates logo video filter
697 *****************************************************************************/
698 static int CreateFilter( vlc_object_t *p_this )
700 filter_t *p_filter = (filter_t *)p_this;
702 logo_list_t *p_logo_list;
704 /* Allocate structure */
705 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
708 msg_Err( p_filter, "out of memory" );
711 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
712 if( p_logo_list == NULL )
714 msg_Err( p_filter, "out of memory" );
719 config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
722 /* Hook used for callback variables */
723 p_logo_list->psz_filename =
724 var_CreateGetStringCommand( p_filter, "logo-file" );
725 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
727 msg_Err( p_this, "logo file not specified" );
733 p_sys->posx = var_CreateGetIntegerCommand( p_filter, "logo-x" );
734 p_sys->posy = var_CreateGetIntegerCommand( p_filter, "logo-y" );
735 p_sys->pos = var_CreateGetIntegerCommand( p_filter, "logo-position" );
736 p_logo_list->i_alpha = __MAX( __MIN( var_CreateGetIntegerCommand(
737 p_filter, "logo-transparency"), 255 ), 0 );
738 p_logo_list->i_delay =
739 var_CreateGetIntegerCommand( p_filter, "logo-delay" );
740 p_logo_list->i_repeat =
741 var_CreateGetIntegerCommand( p_filter, "logo-repeat" );
743 var_AddCallback( p_filter, "logo-file", LogoCallback, p_sys );
744 var_AddCallback( p_filter, "logo-x", LogoCallback, p_sys );
745 var_AddCallback( p_filter, "logo-y", LogoCallback, p_sys );
746 var_AddCallback( p_filter, "logo-position", LogoCallback, p_sys );
747 var_AddCallback( p_filter, "logo-transparency", LogoCallback, p_sys );
748 var_AddCallback( p_filter, "logo-repeat", LogoCallback, p_sys );
750 vlc_mutex_init( p_filter, &p_logo_list->lock );
751 vlc_mutex_lock( &p_logo_list->lock );
753 LoadLogoList( p_this, p_logo_list );
755 vlc_mutex_unlock( &p_logo_list->lock );
758 p_filter->pf_sub_filter = Filter;
759 p_sys->b_need_update = VLC_TRUE;
761 p_sys->i_last_date = 0;
766 /*****************************************************************************
767 * DestroyFilter: destroy logo video filter
768 *****************************************************************************/
769 static void DestroyFilter( vlc_object_t *p_this )
771 filter_t *p_filter = (filter_t *)p_this;
772 filter_sys_t *p_sys = p_filter->p_sys;
774 vlc_mutex_destroy( &p_sys->p_logo_list->lock );
775 FreeLogoList( p_sys->p_logo_list );
776 free( p_sys->p_logo_list );
779 /* Delete the logo variables from INPUT */
780 var_Destroy( p_filter->p_libvlc, "logo-file" );
781 var_Destroy( p_filter->p_libvlc, "logo-x" );
782 var_Destroy( p_filter->p_libvlc, "logo-y" );
783 var_Destroy( p_filter->p_libvlc, "logo-delay" );
784 var_Destroy( p_filter->p_libvlc, "logo-repeat" );
785 var_Destroy( p_filter->p_libvlc, "logo-position" );
786 var_Destroy( p_filter->p_libvlc, "logo-transparency" );
789 /*****************************************************************************
790 * Filter: the whole thing
791 *****************************************************************************
792 * This function outputs subpictures at regular time intervals.
793 *****************************************************************************/
794 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
796 filter_sys_t *p_sys = p_filter->p_sys;
797 logo_list_t *p_logo_list = p_sys->p_logo_list;
799 subpicture_region_t *p_region;
804 vlc_mutex_lock( &p_logo_list->lock );
805 /* Basic test: b_need_update occurs on a dynamic change,
806 & i_next_pic is the general timer, when to
807 look at updating the logo image */
809 if( ( ( !p_sys->b_need_update ) && ( p_logo_list->i_next_pic > date ) )
810 || !p_logo_list->i_repeat )
812 vlc_mutex_unlock( &p_logo_list->lock );
815 /* prior code tested on && p_sys->i_last_date +5000000 > date ) return 0; */
817 /* adjust index to the next logo */
818 p_logo_list->i_counter =
819 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
821 p_logo = &p_logo_list->p_logo[p_logo_list->i_counter];
822 p_pic = p_logo->p_pic;
824 /* Allocate the subpicture internal data. */
825 p_spu = p_filter->pf_sub_buffer_new( p_filter );
828 vlc_mutex_unlock( &p_logo_list->lock );
832 p_spu->b_absolute = p_sys->b_absolute;
833 p_spu->i_start = p_sys->i_last_date = date;
835 p_spu->b_ephemer = VLC_TRUE;
837 p_sys->b_need_update = VLC_FALSE;
838 p_logo_list->i_next_pic = date +
839 ( p_logo->i_delay != -1 ? p_logo->i_delay : p_logo_list->i_delay ) * 1000;
841 if( p_logo_list->i_repeat != -1
842 && p_logo_list->i_counter == 0 )
844 p_logo_list->i_repeat--;
845 if( p_logo_list->i_repeat == 0 )
847 vlc_mutex_unlock( &p_logo_list->lock );
852 if( !p_pic || !p_logo->i_alpha
853 || ( p_logo->i_alpha == -1 && !p_logo_list->i_alpha ) )
855 /* Send an empty subpicture to clear the display */
856 vlc_mutex_unlock( &p_logo_list->lock );
860 /* Create new SPU region */
861 memset( &fmt, 0, sizeof(video_format_t) );
862 fmt.i_chroma = VLC_FOURCC('Y','U','V','A');
863 fmt.i_aspect = VOUT_ASPECT_FACTOR;
864 fmt.i_sar_num = fmt.i_sar_den = 1;
865 fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
866 fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
867 fmt.i_x_offset = fmt.i_y_offset = 0;
868 p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
871 msg_Err( p_filter, "cannot allocate SPU region" );
872 p_filter->pf_sub_buffer_del( p_filter, p_spu );
873 vlc_mutex_unlock( &p_logo_list->lock );
877 vout_CopyPicture( p_filter, &p_region->picture, p_pic );
878 vlc_mutex_unlock( &p_logo_list->lock );
880 /* where to locate the logo: */
881 if( p_sys->posx < 0 || p_sys->posy < 0 )
882 { /* set to one of the 9 relative locations */
883 p_region->i_align = p_sys->pos;
886 p_spu->b_absolute = VLC_FALSE;
889 { /* set to an absolute xy, referenced to upper left corner */
890 p_region->i_align = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
891 p_spu->i_x = p_sys->posx;
892 p_spu->i_y = p_sys->posy;
893 p_spu->b_absolute = VLC_TRUE;
896 p_spu->p_region = p_region;
898 p_spu->i_alpha = ( p_logo->i_alpha != -1 ?
899 p_logo->i_alpha : p_logo_list->i_alpha );
904 /*****************************************************************************
905 * Callback to update params on the fly
906 *****************************************************************************/
907 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
908 vlc_value_t oldval, vlc_value_t newval, void *p_data )
910 filter_sys_t *p_sys = (filter_sys_t *)p_data;
911 logo_list_t *p_logo_list = p_sys->p_logo_list;
913 if( !strncmp( psz_var, "logo-file", 6 ) )
915 vlc_mutex_lock( &p_logo_list->lock );
916 FreeLogoList( p_logo_list );
917 p_logo_list->psz_filename = strdup( newval.psz_string );
918 LoadLogoList( p_this, p_logo_list );
919 vlc_mutex_unlock( &p_logo_list->lock );
920 p_sys->b_need_update = VLC_TRUE;
922 else if ( !strncmp( psz_var, "logo-x", 6 ) )
924 p_sys->posx = newval.i_int;
926 else if ( !strncmp( psz_var, "logo-y", 6 ) )
928 p_sys->posy = newval.i_int;
930 else if ( !strncmp( psz_var, "logo-position", 12 ) )
932 p_sys->pos = newval.i_int;
934 else if ( !strncmp( psz_var, "logo-transparency", 9 ) )
936 vlc_mutex_lock( &p_logo_list->lock );
937 p_logo_list->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
938 vlc_mutex_unlock( &p_logo_list->lock );
940 else if ( !strncmp( psz_var, "logo-repeat", 11 ) )
942 vlc_mutex_lock( &p_logo_list->lock );
943 p_logo_list->i_repeat = newval.i_int;
944 vlc_mutex_unlock( &p_logo_list->lock );
946 p_sys->b_need_update = VLC_TRUE;