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_common.h>
34 #include <vlc_plugin.h>
38 #include "vlc_filter.h"
39 #include "filter_common.h"
40 #include "vlc_image.h"
47 /*****************************************************************************
49 *****************************************************************************/
50 static int Create ( vlc_object_t * );
51 static void Destroy ( vlc_object_t * );
53 static int Init ( vout_thread_t * );
54 static void End ( vout_thread_t * );
55 static void Render ( vout_thread_t *, picture_t * );
57 static int MouseEvent( vlc_object_t *, char const *,
58 vlc_value_t , vlc_value_t , void * );
59 static int Control ( vout_thread_t *, int, va_list );
61 static int CreateFilter ( vlc_object_t * );
62 static void DestroyFilter( vlc_object_t * );
64 static int LogoCallback( vlc_object_t *, char const *,
65 vlc_value_t, vlc_value_t, void * );
67 /*****************************************************************************
69 *****************************************************************************/
70 #define FILE_TEXT N_("Logo filenames")
71 #define FILE_LONGTEXT N_("Full path of the image files to use. Format is " \
72 "<image>[,<delay in ms>[,<alpha>]][;<image>[,<delay>[,<alpha>]]][;...]. " \
73 "If you only have one file, simply enter its filename.")
74 #define REPEAT_TEXT N_("Logo animation # of loops")
75 #define REPEAT_LONGTEXT N_("Number of loops for the logo animation." \
76 "-1 = continuous, 0 = disabled")
77 #define DELAY_TEXT N_("Logo individual image time in ms")
78 #define DELAY_LONGTEXT N_("Individual image display time of 0 - 60000 ms.")
80 #define POSX_TEXT N_("X coordinate")
81 #define POSX_LONGTEXT N_("X coordinate of the logo. You can move the logo " \
82 "by left-clicking it." )
83 #define POSY_TEXT N_("Y coordinate")
84 #define POSY_LONGTEXT N_("Y coordinate of the logo. You can move the logo " \
85 "by left-clicking it." )
86 #define TRANS_TEXT N_("Transparency of the logo")
87 #define TRANS_LONGTEXT N_("Logo transparency value " \
88 "(from 0 for full transparency to 255 for full opacity)." )
89 #define POS_TEXT N_("Logo position")
90 #define POS_LONGTEXT N_( \
91 "Enforce the logo position on the video " \
92 "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
93 "also use combinations of these values, eg 6 = top-right).")
95 #define CFG_PREFIX "logo-"
97 static const int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
98 static const char *const ppsz_pos_descriptions[] =
99 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
100 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
103 set_capability( "sub filter", 0 )
104 set_callbacks( CreateFilter, DestroyFilter )
105 set_description( N_("Logo sub filter") )
106 set_shortname( N_("Logo overlay") )
107 set_category( CAT_VIDEO )
108 set_subcategory( SUBCAT_VIDEO_SUBPIC )
109 add_shortcut( "logo" )
111 add_file( CFG_PREFIX "file", NULL, NULL, FILE_TEXT, FILE_LONGTEXT, false )
112 add_integer( CFG_PREFIX "x", 0, NULL, POSX_TEXT, POSX_LONGTEXT, true )
113 add_integer( CFG_PREFIX "y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, true )
114 /* default to 1000 ms per image, continuously cycle through them */
115 add_integer( CFG_PREFIX "delay", 1000, NULL, DELAY_TEXT, DELAY_LONGTEXT, true )
116 add_integer( CFG_PREFIX "repeat", -1, NULL, REPEAT_TEXT, REPEAT_LONGTEXT, true )
117 add_integer_with_range( CFG_PREFIX "transparency", 255, 0, 255, NULL,
118 TRANS_TEXT, TRANS_LONGTEXT, false )
119 add_integer( CFG_PREFIX "position", -1, NULL, POS_TEXT, POS_LONGTEXT, false )
120 change_integer_list( pi_pos_values, ppsz_pos_descriptions, NULL )
122 /* video output filter submodule */
124 set_capability( "video filter", 0 )
125 set_callbacks( Create, Destroy )
126 set_description( N_("Logo video filter") )
129 static const char *const ppsz_filter_options[] = {
130 "file", "x", "y", "delay", "repeat", "transparency", "position", NULL
133 /*****************************************************************************
134 * Structure to hold the set of individual logo image names, times,
136 ****************************************************************************/
139 char *psz_file; /* candidate for deletion -- not needed */
140 int i_delay; /* -1 means use default delay */
141 int i_alpha; /* -1 means use default alpha */
146 /*****************************************************************************
147 * Logo list structure. Common to both the vout and sub picture filter
148 ****************************************************************************/
151 logo_t *p_logo; /* the parsing's result */
152 unsigned int i_count; /* the number of logo images to be displayed */
154 int i_repeat; /* how often to repeat the images, image time in ms */
155 mtime_t i_next_pic; /* when to bring up a new logo image */
157 unsigned int i_counter; /* index into the list of logo images */
159 int i_delay; /* default delay (0 - 60000 ms) */
160 int i_alpha; /* default alpha */
162 char *psz_filename; /* --logo-file string ( is it really useful
168 /*****************************************************************************
169 * LoadImage: loads the logo image into memory
170 *****************************************************************************/
171 static picture_t *LoadImage( vlc_object_t *p_this, char *psz_filename )
174 image_handler_t *p_image;
175 video_format_t fmt_in;
176 video_format_t fmt_out;
178 memset( &fmt_in, 0, sizeof(video_format_t) );
179 memset( &fmt_out, 0, sizeof(video_format_t) );
181 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
182 p_image = image_HandlerCreate( p_this );
183 p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
184 image_HandlerDelete( p_image );
189 /*****************************************************************************
190 * LoadLogoList: loads the logo images into memory
191 *****************************************************************************
192 * Read the logo-file input switch, obtaining a list of images and associated
193 * durations and transparencies. Store the image(s), and times. An image
194 * without a stated time or transparency will use the logo-delay and
195 * logo-transparency values.
196 *****************************************************************************/
197 #define LoadLogoList( a, b ) __LoadLogoList( VLC_OBJECT( a ), b )
198 static void __LoadLogoList( vlc_object_t *p_this, logo_list_t *p_logo_list )
200 char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */
202 logo_t *p_logo; /* the parsing's result */
204 p_logo_list->i_counter = 0;
205 p_logo_list->i_next_pic = 0;
207 psz_list = strdup( p_logo_list->psz_filename );
209 /* Count the number logos == number of ';' + 1 */
210 p_logo_list->i_count = 1;
211 for( i = 0; i < strlen( psz_list ); i++ )
213 if( psz_list[i] == ';' ) p_logo_list->i_count++;
216 p_logo_list->p_logo = p_logo =
217 (logo_t *)malloc( p_logo_list->i_count * sizeof(logo_t) );
220 for( i = 0; i < p_logo_list->i_count; i++ )
224 p_c = strchr( psz_list, ';' );
225 p_c2 = strchr( psz_list, ',' );
227 p_logo[i].i_alpha = -1; /* use default settings */
228 p_logo[i].i_delay = -1; /* use default settings */
230 if( p_c2 && ( p_c2 < p_c || !p_c ) )
232 /* <logo>,<delay>[,<alpha>] type */
233 if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' )
234 p_logo[i].i_delay = atoi( p_c2+1 );
236 if( ( p_c2 = strchr( p_c2+1, ',' ) )
237 && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' )
238 p_logo[i].i_alpha = atoi( p_c2 + 1 );
243 if( p_c ) *p_c = '\0';
246 p_logo[i].psz_file = strdup( psz_list );
247 p_logo[i].p_pic = LoadImage( p_this, p_logo[i].psz_file );
249 if( !p_logo[i].p_pic )
251 msg_Warn( p_this, "error while loading logo %s, will be skipped",
252 p_logo[i].psz_file );
255 if( p_c ) psz_list = p_c + 1;
258 for( i = 0; i < p_logo_list->i_count; i++ )
260 msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d",
261 p_logo[i].psz_file, p_logo[i].i_delay, p_logo[i].i_alpha );
264 /* initialize so that on the first update it will wrap back to 0 */
265 p_logo_list->i_counter = p_logo_list->i_count;
268 /*****************************************************************************
270 *****************************************************************************/
271 static void FreeLogoList( logo_list_t *p_logo_list )
274 FREENULL( p_logo_list->psz_filename );
275 for( i = 0; i < p_logo_list->i_count; i++ )
277 logo_t *p_logo = &p_logo_list->p_logo[i];
278 FREENULL( p_logo->psz_file );
281 picture_Release( p_logo->p_pic );
282 p_logo->p_pic = NULL;
287 /*****************************************************************************
288 * vout_sys_t: logo video output method descriptor
289 *****************************************************************************
290 * This structure is part of the video output thread descriptor.
291 * It describes the Invert specific properties of an output thread.
292 *****************************************************************************/
295 logo_list_t *p_logo_list;
297 vout_thread_t *p_vout;
301 int i_width, i_height;
305 /*****************************************************************************
306 * Create: allocates logo video thread output method
307 *****************************************************************************/
308 static int Create( vlc_object_t *p_this )
310 vout_thread_t *p_vout = (vout_thread_t *)p_this;
312 logo_list_t *p_logo_list;
314 /* Allocate structure */
315 p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
318 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
319 if( p_logo_list == NULL )
325 config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options,
328 p_logo_list->psz_filename = var_CreateGetStringCommand( p_vout,
330 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
332 msg_Err( p_vout, "logo file not specified" );
333 free( p_logo_list->psz_filename );
338 p_vout->pf_init = Init;
339 p_vout->pf_end = End;
340 p_vout->pf_manage = NULL;
341 p_vout->pf_render = Render;
342 p_vout->pf_display = NULL;
343 p_vout->pf_control = Control;
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;
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", NULL, false );
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_release( 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 vout_filter_AllocateDirectBuffers( p_vout, VOUT_MAX_PICTURES );
462 vout_filter_AddChild( p_vout, p_sys->p_vout, MouseEvent );
467 /*****************************************************************************
468 * End: terminate logo video thread output method
469 *****************************************************************************/
470 static void End( vout_thread_t *p_vout )
472 vout_sys_t *p_sys = p_vout->p_sys;
474 vout_filter_DelChild( p_vout, p_sys->p_vout, MouseEvent );
475 vout_CloseAndRelease( p_sys->p_vout );
477 vout_filter_ReleaseDirectBuffers( p_vout );
479 if( p_sys->p_blend->p_module )
480 module_unneed( p_sys->p_blend, p_sys->p_blend->p_module );
481 vlc_object_detach( p_sys->p_blend );
482 vlc_object_release( p_sys->p_blend );
485 /*****************************************************************************
486 * Destroy: destroy logo video thread output method
487 *****************************************************************************/
488 static void Destroy( vlc_object_t *p_this )
490 vout_thread_t *p_vout = (vout_thread_t *)p_this;
491 vout_sys_t *p_sys = p_vout->p_sys;
494 FreeLogoList( p_sys->p_logo_list );
495 free( p_sys->p_logo_list );
500 /*****************************************************************************
501 * Render: render the logo onto the video
502 *****************************************************************************/
503 static void Render( vout_thread_t *p_vout, picture_t *p_inpic )
505 vout_sys_t *p_sys = p_vout->p_sys;
508 logo_list_t *p_logo_list;
511 p_logo_list = p_sys->p_logo_list;
513 if( p_logo_list->i_next_pic < p_inpic->date )
515 /* It's time to use a new logo */
516 p_logo_list->i_counter =
517 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
518 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
519 p_pic = p_logo->p_pic;
520 p_logo_list->i_next_pic = p_inpic->date + ( p_logo->i_delay != -1 ?
521 p_logo->i_delay : p_logo_list->i_delay ) * 1000;
526 p_sys->p_blend->fmt_in.video.i_width =
527 p_sys->p_blend->fmt_in.video.i_visible_width =
528 p_pic->p[Y_PLANE].i_visible_pitch;
530 p_sys->p_blend->fmt_in.video.i_height =
531 p_sys->p_blend->fmt_in.video.i_visible_height =
532 p_pic->p[Y_PLANE].i_visible_lines;
536 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
538 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
540 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
542 p_sys->posy = p_vout->render.i_height/2 - p_sys->i_height/2;
544 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
546 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
548 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
550 p_sys->posx = p_vout->render.i_width/2 - p_sys->i_width/2;
558 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
559 p_pic = p_logo->p_pic;
562 /* This is a new frame. Get a structure from the video_output. */
563 while( !(p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 )) )
565 if( !vlc_object_alive (p_vout) || p_vout->b_error ) return;
566 msleep( VOUT_OUTMEM_SLEEP );
569 picture_Copy( p_outpic, p_inpic );
572 p_sys->p_blend->pf_video_blend( p_sys->p_blend, p_outpic,
573 p_pic, p_sys->posx, p_sys->posy,
574 p_logo->i_alpha != -1 ? p_logo->i_alpha
575 : p_logo_list->i_alpha );
577 vout_DisplayPicture( p_sys->p_vout, p_outpic );
580 /*****************************************************************************
581 * MouseEvent: callback for mouse events
582 *****************************************************************************/
583 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
584 vlc_value_t oldval, vlc_value_t newval, void *p_data )
586 vout_thread_t *p_vout = p_data;
587 assert( p_this == VLC_OBJECT(p_vout->p_sys->p_vout) );
590 vout_sys_t *p_sys = p_vout->p_sys;
591 const int i_delta = newval.i_int - oldval.i_int;
592 const int i_bdown = var_GetInteger( p_sys->p_vout, "mouse-button-down" );
594 if( (i_bdown & 0x1) == 0 )
600 if( psz_var[6] == 'x' )
602 i_y = var_GetInteger( p_sys->p_vout, "mouse-y" );
606 else if( psz_var[6] == 'y' )
609 i_x = var_GetInteger( p_sys->p_vout, "mouse-x" );
617 /* FIXME missing lock */
618 if( i_x < (int)p_sys->posx ||
619 i_y < (int)p_sys->posy ||
620 i_x > (int)(p_sys->posx + p_sys->i_width) ||
621 i_y > (int)(p_sys->posy + p_sys->i_height) )
624 p_sys->posx = __MIN( __MAX( p_sys->posx + i_dx, 0 ),
625 p_vout->output.i_width - p_sys->i_width );
626 p_sys->posy = __MIN( __MAX( p_sys->posy + i_dy, 0 ),
627 p_vout->output.i_height - p_sys->i_height );
631 return var_Set( p_vout, psz_var, newval );
634 /*****************************************************************************
635 * Control: control facility for the vout (forwards to child vout)
636 *****************************************************************************/
637 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
639 return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
642 /*****************************************************************************
643 * filter_sys_t: logo filter descriptor
644 *****************************************************************************/
647 logo_list_t *p_logo_list;
654 /* On the fly control variable */
658 static subpicture_t *Filter( filter_t *, mtime_t );
660 /*****************************************************************************
661 * CreateFilter: allocates logo video filter
662 *****************************************************************************/
663 static int CreateFilter( vlc_object_t *p_this )
665 filter_t *p_filter = (filter_t *)p_this;
667 logo_list_t *p_logo_list;
669 /* Allocate structure */
670 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
673 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
674 if( p_logo_list == NULL )
680 config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
683 /* Hook used for callback variables */
684 p_logo_list->psz_filename =
685 var_CreateGetStringCommand( p_filter, "logo-file" );
686 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
688 msg_Err( p_this, "logo file not specified" );
694 p_sys->posx = var_CreateGetIntegerCommand( p_filter, "logo-x" );
695 p_sys->posy = var_CreateGetIntegerCommand( p_filter, "logo-y" );
696 p_sys->pos = var_CreateGetIntegerCommand( p_filter, "logo-position" );
697 p_logo_list->i_alpha = __MAX( __MIN( var_CreateGetIntegerCommand(
698 p_filter, "logo-transparency"), 255 ), 0 );
699 p_logo_list->i_delay =
700 var_CreateGetIntegerCommand( p_filter, "logo-delay" );
701 p_logo_list->i_repeat =
702 var_CreateGetIntegerCommand( p_filter, "logo-repeat" );
704 var_AddCallback( p_filter, "logo-file", LogoCallback, p_sys );
705 var_AddCallback( p_filter, "logo-x", LogoCallback, p_sys );
706 var_AddCallback( p_filter, "logo-y", LogoCallback, p_sys );
707 var_AddCallback( p_filter, "logo-position", LogoCallback, p_sys );
708 var_AddCallback( p_filter, "logo-transparency", LogoCallback, p_sys );
709 var_AddCallback( p_filter, "logo-repeat", LogoCallback, p_sys );
711 vlc_mutex_init( &p_logo_list->lock );
712 vlc_mutex_lock( &p_logo_list->lock );
714 LoadLogoList( p_this, p_logo_list );
716 vlc_mutex_unlock( &p_logo_list->lock );
719 p_filter->pf_sub_filter = Filter;
720 p_sys->b_need_update = true;
722 p_sys->i_last_date = 0;
727 /*****************************************************************************
728 * DestroyFilter: destroy logo video filter
729 *****************************************************************************/
730 static void DestroyFilter( vlc_object_t *p_this )
732 filter_t *p_filter = (filter_t *)p_this;
733 filter_sys_t *p_sys = p_filter->p_sys;
735 /* Delete the logo variables from INPUT */
736 var_Destroy( p_filter->p_libvlc, "logo-file" );
737 var_Destroy( p_filter->p_libvlc, "logo-x" );
738 var_Destroy( p_filter->p_libvlc, "logo-y" );
739 var_Destroy( p_filter->p_libvlc, "logo-delay" );
740 var_Destroy( p_filter->p_libvlc, "logo-repeat" );
741 var_Destroy( p_filter->p_libvlc, "logo-position" );
742 var_Destroy( p_filter->p_libvlc, "logo-transparency" );
744 vlc_mutex_destroy( &p_sys->p_logo_list->lock );
745 FreeLogoList( p_sys->p_logo_list );
746 free( p_sys->p_logo_list );
750 /*****************************************************************************
751 * Filter: the whole thing
752 *****************************************************************************
753 * This function outputs subpictures at regular time intervals.
754 *****************************************************************************/
755 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
757 filter_sys_t *p_sys = p_filter->p_sys;
758 logo_list_t *p_logo_list = p_sys->p_logo_list;
760 subpicture_region_t *p_region;
765 vlc_mutex_lock( &p_logo_list->lock );
766 /* Basic test: b_need_update occurs on a dynamic change,
767 & i_next_pic is the general timer, when to
768 look at updating the logo image */
770 if( ( ( !p_sys->b_need_update ) && ( p_logo_list->i_next_pic > date ) )
771 || !p_logo_list->i_repeat )
773 vlc_mutex_unlock( &p_logo_list->lock );
776 /* prior code tested on && p_sys->i_last_date +5000000 > date ) return 0; */
778 /* adjust index to the next logo */
779 p_logo_list->i_counter =
780 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
782 p_logo = &p_logo_list->p_logo[p_logo_list->i_counter];
783 p_pic = p_logo->p_pic;
785 /* Allocate the subpicture internal data. */
786 p_spu = filter_NewSubpicture( p_filter );
789 vlc_mutex_unlock( &p_logo_list->lock );
793 p_spu->b_absolute = p_sys->b_absolute;
794 p_spu->i_start = p_sys->i_last_date = date;
796 p_spu->b_ephemer = true;
798 p_sys->b_need_update = false;
799 p_logo_list->i_next_pic = date +
800 ( p_logo->i_delay != -1 ? p_logo->i_delay : p_logo_list->i_delay ) * 1000;
802 if( p_logo_list->i_repeat != -1
803 && p_logo_list->i_counter == 0 )
805 p_logo_list->i_repeat--;
806 if( p_logo_list->i_repeat == 0 )
808 vlc_mutex_unlock( &p_logo_list->lock );
813 if( !p_pic || !p_logo->i_alpha
814 || ( p_logo->i_alpha == -1 && !p_logo_list->i_alpha ) )
816 /* Send an empty subpicture to clear the display */
817 vlc_mutex_unlock( &p_logo_list->lock );
821 /* Create new SPU region */
822 memset( &fmt, 0, sizeof(video_format_t) );
823 fmt.i_chroma = VLC_FOURCC('Y','U','V','A');
824 fmt.i_aspect = VOUT_ASPECT_FACTOR;
825 fmt.i_sar_num = fmt.i_sar_den = 1;
826 fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
827 fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
828 fmt.i_x_offset = fmt.i_y_offset = 0;
829 p_region = subpicture_region_New( &fmt );
832 msg_Err( p_filter, "cannot allocate SPU region" );
833 p_filter->pf_sub_buffer_del( p_filter, p_spu );
834 vlc_mutex_unlock( &p_logo_list->lock );
838 /* FIXME the copy is probably not needed anymore */
839 picture_Copy( p_region->p_picture, p_pic );
840 vlc_mutex_unlock( &p_logo_list->lock );
842 /* where to locate the logo: */
844 { /* set to an absolute xy */
845 p_region->i_align = OSD_ALIGN_RIGHT | OSD_ALIGN_TOP;
846 p_spu->b_absolute = true;
849 { /* set to one of the 9 relative locations */
850 p_region->i_align = p_sys->pos;
851 p_spu->b_absolute = false;
854 p_region->i_x = p_sys->posx;
855 p_region->i_y = p_sys->posy;
857 p_spu->p_region = p_region;
859 p_spu->i_alpha = ( p_logo->i_alpha != -1 ?
860 p_logo->i_alpha : p_logo_list->i_alpha );
865 /*****************************************************************************
866 * Callback to update params on the fly
867 *****************************************************************************/
868 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
869 vlc_value_t oldval, vlc_value_t newval, void *p_data )
872 filter_sys_t *p_sys = (filter_sys_t *)p_data;
873 logo_list_t *p_logo_list = p_sys->p_logo_list;
875 if( !strcmp( psz_var, "logo-file" ) )
877 vlc_mutex_lock( &p_logo_list->lock );
878 FreeLogoList( p_logo_list );
879 p_logo_list->psz_filename = strdup( newval.psz_string );
880 LoadLogoList( p_this, p_logo_list );
881 vlc_mutex_unlock( &p_logo_list->lock );
883 else if ( !strcmp( psz_var, "logo-x" ) )
885 p_sys->posx = newval.i_int;
887 else if ( !strcmp( psz_var, "logo-y" ) )
889 p_sys->posy = newval.i_int;
891 else if ( !strcmp( psz_var, "logo-position" ) )
893 p_sys->pos = newval.i_int;
895 else if ( !strcmp( psz_var, "logo-transparency" ) )
897 vlc_mutex_lock( &p_logo_list->lock );
898 p_logo_list->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
899 vlc_mutex_unlock( &p_logo_list->lock );
901 else if ( !strcmp( psz_var, "logo-repeat" ) )
903 vlc_mutex_lock( &p_logo_list->lock );
904 p_logo_list->i_repeat = newval.i_int;
905 vlc_mutex_unlock( &p_logo_list->lock );
907 p_sys->b_need_update = true;