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;
175 video_format_t fmt_out;
177 memset( &fmt_in, 0, sizeof(video_format_t) );
178 memset( &fmt_out, 0, sizeof(video_format_t) );
180 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
181 p_image = image_HandlerCreate( p_this );
182 p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
183 image_HandlerDelete( p_image );
188 /*****************************************************************************
189 * LoadLogoList: loads the logo images into memory
190 *****************************************************************************
191 * Read the logo-file input switch, obtaining a list of images and associated
192 * durations and transparencies. Store the image(s), and times. An image
193 * without a stated time or transparency will use the logo-delay and
194 * logo-transparency values.
195 *****************************************************************************/
196 #define LoadLogoList( a, b ) __LoadLogoList( VLC_OBJECT( a ), b )
197 static void __LoadLogoList( vlc_object_t *p_this, logo_list_t *p_logo_list )
199 char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */
201 logo_t *p_logo; /* the parsing's result */
203 p_logo_list->i_counter = 0;
204 p_logo_list->i_next_pic = 0;
206 psz_list = strdup( p_logo_list->psz_filename );
208 /* Count the number logos == number of ';' + 1 */
209 p_logo_list->i_count = 1;
210 for( i = 0; i < strlen( psz_list ); i++ )
212 if( psz_list[i] == ';' ) p_logo_list->i_count++;
215 p_logo_list->p_logo = p_logo =
216 (logo_t *)malloc( p_logo_list->i_count * sizeof(logo_t) );
219 for( i = 0; i < p_logo_list->i_count; i++ )
223 p_c = strchr( psz_list, ';' );
224 p_c2 = strchr( psz_list, ',' );
226 p_logo[i].i_alpha = -1; /* use default settings */
227 p_logo[i].i_delay = -1; /* use default settings */
229 if( p_c2 && ( p_c2 < p_c || !p_c ) )
231 /* <logo>,<delay>[,<alpha>] type */
232 if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' )
233 p_logo[i].i_delay = atoi( p_c2+1 );
235 if( ( p_c2 = strchr( p_c2+1, ',' ) )
236 && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' )
237 p_logo[i].i_alpha = atoi( p_c2 + 1 );
242 if( p_c ) *p_c = '\0';
245 p_logo[i].psz_file = strdup( psz_list );
246 p_logo[i].p_pic = LoadImage( p_this, p_logo[i].psz_file );
248 if( !p_logo[i].p_pic )
250 msg_Warn( p_this, "error while loading logo %s, will be skipped",
251 p_logo[i].psz_file );
254 if( p_c ) psz_list = p_c + 1;
257 for( i = 0; i < p_logo_list->i_count; i++ )
259 msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d",
260 p_logo[i].psz_file, p_logo[i].i_delay, p_logo[i].i_alpha );
263 /* initialize so that on the first update it will wrap back to 0 */
264 p_logo_list->i_counter = p_logo_list->i_count;
267 /*****************************************************************************
269 *****************************************************************************/
270 static void FreeLogoList( logo_list_t *p_logo_list )
273 FREENULL( p_logo_list->psz_filename );
274 for( i = 0; i < p_logo_list->i_count; i++ )
276 logo_t *p_logo = &p_logo_list->p_logo[i];
277 FREENULL( p_logo->psz_file );
280 p_logo->p_pic->pf_release( p_logo->p_pic );
281 p_logo->p_pic = NULL;
286 /*****************************************************************************
287 * vout_sys_t: logo video output method descriptor
288 *****************************************************************************
289 * This structure is part of the video output thread descriptor.
290 * It describes the Invert specific properties of an output thread.
291 *****************************************************************************/
294 logo_list_t *p_logo_list;
296 vout_thread_t *p_vout;
300 int i_width, i_height;
304 /*****************************************************************************
305 * Create: allocates logo video thread output method
306 *****************************************************************************/
307 static int Create( vlc_object_t *p_this )
309 vout_thread_t *p_vout = (vout_thread_t *)p_this;
311 logo_list_t *p_logo_list;
313 /* Allocate structure */
314 p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
317 msg_Err( p_vout, "out of memory" );
320 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
321 if( p_logo_list == NULL )
323 msg_Err( p_vout, "out of memory" );
328 p_vout->pf_init = Init;
329 p_vout->pf_end = End;
330 p_vout->pf_manage = NULL;
331 p_vout->pf_render = Render;
332 p_vout->pf_display = NULL;
333 p_vout->pf_control = Control;
335 config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options,
338 p_logo_list->psz_filename = var_CreateGetStringCommand( p_vout,
340 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
342 msg_Err( p_vout, "logo file not specified" );
346 p_sys->pos = var_CreateGetIntegerCommand( p_vout, "logo-position" );
347 p_sys->posx = var_CreateGetIntegerCommand( p_vout, "logo-x" );
348 p_sys->posy = var_CreateGetIntegerCommand( p_vout, "logo-y" );
349 p_logo_list->i_delay = __MAX( __MIN(
350 var_CreateGetIntegerCommand( p_vout, "logo-delay" ) , 60000 ), 0 );
351 p_logo_list->i_repeat = var_CreateGetIntegerCommand( p_vout, "logo-repeat");
352 p_logo_list->i_alpha = __MAX( __MIN(
353 var_CreateGetIntegerCommand( p_vout, "logo-transparency" ), 255 ), 0 );
355 LoadLogoList( p_vout, p_logo_list );
360 /*****************************************************************************
361 * Init: initialize logo video thread output method
362 *****************************************************************************/
363 static int Init( vout_thread_t *p_vout )
365 vout_sys_t *p_sys = p_vout->p_sys;
369 logo_list_t *p_logo_list = p_sys->p_logo_list;
371 I_OUTPUTPICTURES = 0;
372 memset( &fmt, 0, sizeof(video_format_t) );
374 /* adjust index to the next logo */
375 p_logo_list->i_counter =
376 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
378 p_pic = p_logo_list->p_logo[p_logo_list->i_counter].p_pic;
379 /* Initialize the output structure */
380 p_vout->output.i_chroma = p_vout->render.i_chroma;
381 p_vout->output.i_width = p_vout->render.i_width;
382 p_vout->output.i_height = p_vout->render.i_height;
383 p_vout->output.i_aspect = p_vout->render.i_aspect;
384 p_vout->fmt_out = p_vout->fmt_in;
385 fmt = p_vout->fmt_out;
387 /* Load the video blending filter */
388 p_sys->p_blend = vlc_object_create( p_vout, sizeof(filter_t) );
389 vlc_object_attach( p_sys->p_blend, p_vout );
390 p_sys->p_blend->fmt_out.video.i_x_offset =
391 p_sys->p_blend->fmt_out.video.i_y_offset = 0;
392 p_sys->p_blend->fmt_in.video.i_x_offset =
393 p_sys->p_blend->fmt_in.video.i_y_offset = 0;
394 p_sys->p_blend->fmt_out.video.i_aspect = p_vout->render.i_aspect;
395 p_sys->p_blend->fmt_out.video.i_chroma = p_vout->output.i_chroma;
396 p_sys->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','A');
397 p_sys->p_blend->fmt_in.video.i_aspect = VOUT_ASPECT_FACTOR;
399 p_sys->p_blend->fmt_in.video.i_width =
400 p_sys->p_blend->fmt_in.video.i_visible_width =
401 p_pic ? p_pic->p[Y_PLANE].i_visible_pitch : 0;
403 p_sys->p_blend->fmt_in.video.i_height =
404 p_sys->p_blend->fmt_in.video.i_visible_height =
405 p_pic ? p_pic->p[Y_PLANE].i_visible_lines : 0;
406 p_sys->p_blend->fmt_out.video.i_width =
407 p_sys->p_blend->fmt_out.video.i_visible_width =
408 p_vout->output.i_width;
409 p_sys->p_blend->fmt_out.video.i_height =
410 p_sys->p_blend->fmt_out.video.i_visible_height =
411 p_vout->output.i_height;
413 p_sys->p_blend->p_module =
414 module_Need( p_sys->p_blend, "video blending", 0, 0 );
415 if( !p_sys->p_blend->p_module )
417 msg_Err( p_vout, "can't open blending filter, aborting" );
418 vlc_object_detach( p_sys->p_blend );
419 vlc_object_destroy( p_sys->p_blend );
423 if( p_sys->posx < 0 || p_sys->posy < 0 )
425 p_sys->posx = 0; p_sys->posy = 0;
427 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
429 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
431 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
433 p_sys->posy = p_vout->render.i_height / 2 - p_sys->i_height / 2;
436 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
438 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
440 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
442 p_sys->posx = p_vout->render.i_width / 2 - p_sys->i_width / 2;
450 /* Try to open the real video output */
451 msg_Dbg( p_vout, "spawning the real video output" );
453 p_sys->p_vout = vout_Create( p_vout, &fmt );
455 /* Everything failed */
456 if( p_sys->p_vout == NULL )
458 msg_Err( p_vout, "can't open vout, aborting" );
462 var_AddCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
463 var_AddCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
465 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
466 ADD_CALLBACKS( p_sys->p_vout, SendEvents );
467 ADD_PARENT_CALLBACKS( SendEventsToChild );
472 /*****************************************************************************
473 * End: terminate logo video thread output method
474 *****************************************************************************/
475 static void End( vout_thread_t *p_vout )
477 vout_sys_t *p_sys = p_vout->p_sys;
480 /* Free the fake output buffers we allocated */
481 for( i_index = I_OUTPUTPICTURES ; i_index ; )
484 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
487 var_DelCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
488 var_DelCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
492 DEL_CALLBACKS( p_sys->p_vout, SendEvents );
493 vlc_object_detach( p_sys->p_vout );
494 vout_Destroy( p_sys->p_vout );
497 if( p_sys->p_blend->p_module )
498 module_Unneed( p_sys->p_blend, p_sys->p_blend->p_module );
499 vlc_object_detach( p_sys->p_blend );
500 vlc_object_destroy( p_sys->p_blend );
503 /*****************************************************************************
504 * Destroy: destroy logo video thread output method
505 *****************************************************************************/
506 static void Destroy( vlc_object_t *p_this )
508 vout_thread_t *p_vout = (vout_thread_t *)p_this;
509 vout_sys_t *p_sys = p_vout->p_sys;
511 DEL_PARENT_CALLBACKS( SendEventsToChild );
513 FreeLogoList( p_sys->p_logo_list );
514 free( p_sys->p_logo_list );
519 /*****************************************************************************
520 * Render: render the logo onto the video
521 *****************************************************************************/
522 static void Render( vout_thread_t *p_vout, picture_t *p_inpic )
524 vout_sys_t *p_sys = p_vout->p_sys;
527 logo_list_t *p_logo_list;
530 p_logo_list = p_sys->p_logo_list;
532 if( p_logo_list->i_next_pic < p_inpic->date )
534 /* It's time to use a new logo */
535 p_logo_list->i_counter =
536 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
537 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
538 p_pic = p_logo->p_pic;
539 p_logo_list->i_next_pic = p_inpic->date + ( p_logo->i_delay != -1 ?
540 p_logo->i_delay : p_logo_list->i_delay ) * 1000;
545 p_sys->p_blend->fmt_in.video.i_width =
546 p_sys->p_blend->fmt_in.video.i_visible_width =
547 p_pic->p[Y_PLANE].i_visible_pitch;
549 p_sys->p_blend->fmt_in.video.i_height =
550 p_sys->p_blend->fmt_in.video.i_visible_height =
551 p_pic->p[Y_PLANE].i_visible_lines;
555 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
557 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
559 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
561 p_sys->posy = p_vout->render.i_height/2 - p_sys->i_height/2;
563 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
565 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
567 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
569 p_sys->posx = p_vout->render.i_width/2 - p_sys->i_width/2;
577 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
578 p_pic = p_logo->p_pic;
581 /* This is a new frame. Get a structure from the video_output. */
582 while( !(p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 )) )
584 if( p_vout->b_die || p_vout->b_error ) return;
585 msleep( VOUT_OUTMEM_SLEEP );
588 vout_CopyPicture( p_vout, p_outpic, p_inpic );
589 vout_DatePicture( p_sys->p_vout, p_outpic, p_inpic->date );
592 p_sys->p_blend->pf_video_blend( p_sys->p_blend, p_outpic, p_outpic,
593 p_pic, p_sys->posx, p_sys->posy,
594 p_logo->i_alpha != -1 ? p_logo->i_alpha
595 : p_logo_list->i_alpha );
597 vout_DisplayPicture( p_sys->p_vout, p_outpic );
600 /*****************************************************************************
601 * SendEvents: forward mouse and keyboard events to the parent p_vout
602 *****************************************************************************/
603 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
604 vlc_value_t oldval, vlc_value_t newval, void *p_data )
606 var_Set( (vlc_object_t *)p_data, psz_var, newval );
610 /*****************************************************************************
611 * MouseEvent: callback for mouse events
612 *****************************************************************************/
613 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
614 vlc_value_t oldval, vlc_value_t newval, void *p_data )
616 vout_thread_t *p_vout = (vout_thread_t*)p_data;
617 vout_sys_t *p_sys = p_vout->p_sys;
621 var_Get( p_vout->p_sys->p_vout, "mouse-button-down", &valb );
623 i_delta = newval.i_int - oldval.i_int;
625 if( (valb.i_int & 0x1) == 0 )
630 if( psz_var[6] == 'x' )
633 var_Get( p_vout->p_sys->p_vout, "mouse-y", &valy );
634 if( newval.i_int >= (int)p_sys->posx &&
635 valy.i_int >= (int)p_sys->posy &&
636 newval.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
637 valy.i_int <= (int)(p_sys->posy + p_sys->i_height) )
639 p_sys->posx = __MIN( __MAX( p_sys->posx + i_delta, 0 ),
640 p_vout->output.i_width - p_sys->i_width );
643 else if( psz_var[6] == 'y' )
646 var_Get( p_vout->p_sys->p_vout, "mouse-x", &valx );
647 if( valx.i_int >= (int)p_sys->posx &&
648 newval.i_int >= (int)p_sys->posy &&
649 valx.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
650 newval.i_int <= (int)(p_sys->posy + p_sys->i_height) )
652 p_sys->posy = __MIN( __MAX( p_sys->posy + i_delta, 0 ),
653 p_vout->output.i_height - p_sys->i_height );
660 /*****************************************************************************
661 * Control: control facility for the vout (forwards to child vout)
662 *****************************************************************************/
663 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
665 return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
668 /*****************************************************************************
669 * SendEventsToChild: forward events to the child/children vout
670 *****************************************************************************/
671 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
672 vlc_value_t oldval, vlc_value_t newval, void *p_data )
674 vout_thread_t *p_vout = (vout_thread_t *)p_this;
675 var_Set( p_vout->p_sys->p_vout, psz_var, newval );
679 /*****************************************************************************
680 * filter_sys_t: logo filter descriptor
681 *****************************************************************************/
684 logo_list_t *p_logo_list;
688 vlc_bool_t b_absolute;
691 /* On the fly control variable */
692 vlc_bool_t b_need_update;
695 static subpicture_t *Filter( filter_t *, mtime_t );
697 /*****************************************************************************
698 * CreateFilter: allocates logo video filter
699 *****************************************************************************/
700 static int CreateFilter( vlc_object_t *p_this )
702 filter_t *p_filter = (filter_t *)p_this;
704 logo_list_t *p_logo_list;
706 /* Allocate structure */
707 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
710 msg_Err( p_filter, "out of memory" );
713 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
714 if( p_logo_list == NULL )
716 msg_Err( p_filter, "out of memory" );
721 config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
724 /* Hook used for callback variables */
725 p_logo_list->psz_filename =
726 var_CreateGetStringCommand( p_filter, "logo-file" );
727 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
729 msg_Err( p_this, "logo file not specified" );
735 p_sys->posx = var_CreateGetIntegerCommand( p_filter, "logo-x" );
736 p_sys->posy = var_CreateGetIntegerCommand( p_filter, "logo-y" );
737 p_sys->pos = var_CreateGetIntegerCommand( p_filter, "logo-position" );
738 p_logo_list->i_alpha = __MAX( __MIN( var_CreateGetIntegerCommand(
739 p_filter, "logo-transparency"), 255 ), 0 );
740 p_logo_list->i_delay =
741 var_CreateGetIntegerCommand( p_filter, "logo-delay" );
742 p_logo_list->i_repeat =
743 var_CreateGetIntegerCommand( p_filter, "logo-repeat" );
745 var_AddCallback( p_filter, "logo-file", LogoCallback, p_sys );
746 var_AddCallback( p_filter, "logo-x", LogoCallback, p_sys );
747 var_AddCallback( p_filter, "logo-y", LogoCallback, p_sys );
748 var_AddCallback( p_filter, "logo-position", LogoCallback, p_sys );
749 var_AddCallback( p_filter, "logo-transparency", LogoCallback, p_sys );
750 var_AddCallback( p_filter, "logo-repeat", LogoCallback, p_sys );
752 vlc_mutex_init( p_filter, &p_logo_list->lock );
753 vlc_mutex_lock( &p_logo_list->lock );
755 LoadLogoList( p_this, p_logo_list );
757 vlc_mutex_unlock( &p_logo_list->lock );
760 p_filter->pf_sub_filter = Filter;
761 p_sys->b_need_update = VLC_TRUE;
763 p_sys->i_last_date = 0;
768 /*****************************************************************************
769 * DestroyFilter: destroy logo video filter
770 *****************************************************************************/
771 static void DestroyFilter( vlc_object_t *p_this )
773 filter_t *p_filter = (filter_t *)p_this;
774 filter_sys_t *p_sys = p_filter->p_sys;
776 vlc_mutex_destroy( &p_sys->p_logo_list->lock );
777 FreeLogoList( p_sys->p_logo_list );
778 free( p_sys->p_logo_list );
781 /* Delete the logo variables from INPUT */
782 var_Destroy( p_filter->p_libvlc_global , "logo-file" );
783 var_Destroy( p_filter->p_libvlc_global , "logo-x" );
784 var_Destroy( p_filter->p_libvlc_global , "logo-y" );
785 var_Destroy( p_filter->p_libvlc_global , "logo-delay" );
786 var_Destroy( p_filter->p_libvlc_global , "logo-repeat" );
787 var_Destroy( p_filter->p_libvlc_global , "logo-position" );
788 var_Destroy( p_filter->p_libvlc_global , "logo-transparency" );
791 /*****************************************************************************
792 * Filter: the whole thing
793 *****************************************************************************
794 * This function outputs subpictures at regular time intervals.
795 *****************************************************************************/
796 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
798 filter_sys_t *p_sys = p_filter->p_sys;
799 logo_list_t *p_logo_list = p_sys->p_logo_list;
801 subpicture_region_t *p_region;
806 vlc_mutex_lock( &p_logo_list->lock );
807 /* Basic test: b_need_update occurs on a dynamic change,
808 & i_next_pic is the general timer, when to
809 look at updating the logo image */
811 if( ( ( !p_sys->b_need_update ) && ( p_logo_list->i_next_pic > date ) )
812 || !p_logo_list->i_repeat )
814 vlc_mutex_unlock( &p_logo_list->lock );
817 /* prior code tested on && p_sys->i_last_date +5000000 > date ) return 0; */
819 /* adjust index to the next logo */
820 p_logo_list->i_counter =
821 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
823 p_logo = &p_logo_list->p_logo[p_logo_list->i_counter];
824 p_pic = p_logo->p_pic;
826 /* Allocate the subpicture internal data. */
827 p_spu = p_filter->pf_sub_buffer_new( p_filter );
830 vlc_mutex_unlock( &p_logo_list->lock );
834 p_spu->b_absolute = p_sys->b_absolute;
835 p_spu->i_start = p_sys->i_last_date = date;
837 p_spu->b_ephemer = VLC_TRUE;
839 p_sys->b_need_update = VLC_FALSE;
840 p_logo_list->i_next_pic = date +
841 ( p_logo->i_delay != -1 ? p_logo->i_delay : p_logo_list->i_delay ) * 1000;
843 if( p_logo_list->i_repeat != -1
844 && p_logo_list->i_counter == 0 )
846 p_logo_list->i_repeat--;
847 if( p_logo_list->i_repeat == 0 )
849 vlc_mutex_unlock( &p_logo_list->lock );
854 if( !p_pic || !p_logo->i_alpha
855 || ( p_logo->i_alpha == -1 && !p_logo_list->i_alpha ) )
857 /* Send an empty subpicture to clear the display */
858 vlc_mutex_unlock( &p_logo_list->lock );
862 /* Create new SPU region */
863 memset( &fmt, 0, sizeof(video_format_t) );
864 fmt.i_chroma = VLC_FOURCC('Y','U','V','A');
865 fmt.i_aspect = VOUT_ASPECT_FACTOR;
866 fmt.i_sar_num = fmt.i_sar_den = 1;
867 fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
868 fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
869 fmt.i_x_offset = fmt.i_y_offset = 0;
870 p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
873 msg_Err( p_filter, "cannot allocate SPU region" );
874 p_filter->pf_sub_buffer_del( p_filter, p_spu );
875 vlc_mutex_unlock( &p_logo_list->lock );
879 vout_CopyPicture( p_filter, &p_region->picture, p_pic );
880 vlc_mutex_unlock( &p_logo_list->lock );
882 /* where to locate the logo: */
883 if( p_sys->posx < 0 || p_sys->posy < 0 )
884 { /* set to one of the 9 relative locations */
885 p_spu->i_flags = p_sys->pos;
888 p_spu->b_absolute = VLC_FALSE;
891 { /* set to an absolute xy, referenced to upper left corner */
892 p_spu->i_flags = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
893 p_spu->i_x = p_sys->posx;
894 p_spu->i_y = p_sys->posy;
895 p_spu->b_absolute = VLC_TRUE;
898 p_spu->p_region = p_region;
900 p_spu->i_alpha = ( p_logo->i_alpha != -1 ?
901 p_logo->i_alpha : p_logo_list->i_alpha );
906 /*****************************************************************************
907 * Callback to update params on the fly
908 *****************************************************************************/
909 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
910 vlc_value_t oldval, vlc_value_t newval, void *p_data )
912 filter_sys_t *p_sys = (filter_sys_t *)p_data;
913 logo_list_t *p_logo_list = p_sys->p_logo_list;
915 if( !strncmp( psz_var, "logo-file", 6 ) )
917 vlc_mutex_lock( &p_logo_list->lock );
918 FreeLogoList( p_logo_list );
919 p_logo_list->psz_filename = strdup( newval.psz_string );
920 LoadLogoList( p_this, p_logo_list );
921 vlc_mutex_unlock( &p_logo_list->lock );
922 p_sys->b_need_update = VLC_TRUE;
924 else if ( !strncmp( psz_var, "logo-x", 6 ) )
926 p_sys->posx = newval.i_int;
928 else if ( !strncmp( psz_var, "logo-y", 6 ) )
930 p_sys->posy = newval.i_int;
932 else if ( !strncmp( psz_var, "logo-position", 12 ) )
934 p_sys->pos = newval.i_int;
936 else if ( !strncmp( psz_var, "logo-transparency", 9 ) )
938 vlc_mutex_lock( &p_logo_list->lock );
939 p_logo_list->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
940 vlc_mutex_unlock( &p_logo_list->lock );
942 else if ( !strncmp( psz_var, "logo-repeat", 11 ) )
944 vlc_mutex_lock( &p_logo_list->lock );
945 p_logo_list->i_repeat = newval.i_int;
946 vlc_mutex_unlock( &p_logo_list->lock );
948 p_sys->b_need_update = VLC_TRUE;