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 <image>[,<delay in ms>[,<alpha>]][;<image>[,<delay>[,<alpha>]]][;...] .")
70 #define REPEAT_TEXT N_("Logo animation # of loops")
71 #define REPEAT_LONGTEXT N_("How many times to animate the logo images, -1 = continuous, 0 = disabled")
72 #define DELAY_TEXT N_("Logo individual image time in ms")
73 #define DELAY_LONGTEXT N_("Individual image display time of 0 - 60000 ms")
75 #define POSX_TEXT N_("X coordinate of the logo")
76 #define POSX_LONGTEXT N_("You can move the logo by left-clicking on it." )
77 #define POSY_TEXT N_("Y coordinate of the logo")
78 #define POSY_LONGTEXT N_("You can move the logo by left-clicking on it." )
79 #define TRANS_TEXT N_("Transparency of the logo")
80 #define TRANS_LONGTEXT N_("You can set the logo transparency value here " \
81 "(from 0 for full transparency to 255 for full opacity)." )
82 #define POS_TEXT N_("Logo position")
83 #define POS_LONGTEXT N_( \
84 "You can enforce the logo position on the video " \
85 "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
86 "also use combinations of these values).")
88 static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
89 static char *ppsz_pos_descriptions[] =
90 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
91 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
94 set_description( _("Logo video filter") );
95 set_capability( "video filter", 0 );
96 set_shortname( N_("Logo overlay") );
97 set_category( CAT_VIDEO );
98 set_subcategory( SUBCAT_VIDEO_SUBPIC );
99 add_shortcut( "logo" );
100 set_callbacks( Create, Destroy );
102 add_file( "logo-file", NULL, NULL, FILE_TEXT, FILE_LONGTEXT, VLC_FALSE );
103 add_integer( "logo-x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_TRUE );
104 add_integer( "logo-y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_TRUE );
105 /* default to 1000 ms per image, continuously cycle through them */
106 add_integer( "logo-delay", 1000, NULL, DELAY_TEXT, DELAY_LONGTEXT, VLC_TRUE );
107 add_integer( "logo-repeat", -1, NULL, REPEAT_TEXT, REPEAT_LONGTEXT, VLC_TRUE );
108 add_integer_with_range( "logo-transparency", 255, 0, 255, NULL,
109 TRANS_TEXT, TRANS_LONGTEXT, VLC_FALSE );
110 add_integer( "logo-position", 6, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
111 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
113 /* subpicture filter submodule */
115 set_capability( "sub filter", 0 );
116 set_callbacks( CreateFilter, DestroyFilter );
117 set_description( _("Logo sub filter") );
118 add_shortcut( "logo" );
121 /*****************************************************************************
122 * Structure to hold the set of individual logo image names, times,
124 ****************************************************************************/
127 char *psz_file; /* candidate for deletion -- not needed */
128 int i_delay; /* -1 means use default delay */
129 int i_alpha; /* -1 means use default alpha */
134 /*****************************************************************************
135 * Logo list structure. Common to both the vout and sub picture filter
136 ****************************************************************************/
139 logo_t *p_logo; /* the parsing's result */
140 unsigned int i_count; /* the number of logo images to be displayed */
142 int i_repeat; /* how often to repeat the images, image time in ms */
143 mtime_t i_next_pic; /* when to bring up a new logo image */
145 unsigned int i_counter; /* index into the list of logo images */
147 int i_delay; /* default delay (0 - 60000 ms) */
148 int i_alpha; /* default alpha */
150 char *psz_filename; /* --logo-file string ( is it really useful
156 /*****************************************************************************
157 * LoadImage: loads the logo image into memory
158 *****************************************************************************/
159 static picture_t *LoadImage( vlc_object_t *p_this, char *psz_filename )
162 image_handler_t *p_image;
163 video_format_t fmt_in = {0}, fmt_out = {0};
165 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
166 p_image = image_HandlerCreate( p_this );
167 p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
168 image_HandlerDelete( p_image );
173 /*****************************************************************************
174 * LoadLogoList: loads the logo images into memory
175 *****************************************************************************
176 * Read the logo-file input switch, obtaining a list of images and associated
177 * durations and transparencies. Store the image(s), and times. An image
178 * without a stated time or transparency will use the logo-delay and
179 * logo-transparency values.
180 *****************************************************************************/
181 #define LoadLogoList( a, b ) __LoadLogoList( VLC_OBJECT( a ), b )
182 void __LoadLogoList( vlc_object_t *p_this, logo_list_t *p_logo_list )
184 char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */
186 logo_t *p_logo; /* the parsing's result */
188 p_logo_list->i_counter = 0;
189 p_logo_list->i_next_pic = 0;
191 psz_list = strdup( p_logo_list->psz_filename );
193 /* Count the number logos == number of ';' + 1 */
194 p_logo_list->i_count = 1;
195 for( i = 0; i < strlen( psz_list ); i++ )
197 if( psz_list[i] == ';' ) p_logo_list->i_count++;
200 p_logo_list->p_logo = p_logo =
201 (logo_t *)malloc( p_logo_list->i_count * sizeof(logo_t) );
204 for( i = 0; i < p_logo_list->i_count; i++ )
208 p_c = strchr( psz_list, ';' );
209 p_c2 = strchr( psz_list, ',' );
211 p_logo[i].i_alpha = -1; /* use default settings */
212 p_logo[i].i_delay = -1; /* use default settings */
214 if( p_c2 && ( p_c2 < p_c || !p_c ) )
216 /* <logo>,<delay>[,<alpha>] type */
217 if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' )
218 p_logo[i].i_delay = atoi( p_c2+1 );
220 if( ( p_c2 = strchr( p_c2+1, ',' ) )
221 && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' )
222 p_logo[i].i_alpha = atoi( p_c2 + 1 );
227 if( p_c ) *p_c = '\0';
230 p_logo[i].psz_file = strdup( psz_list );
231 p_logo[i].p_pic = LoadImage( p_this, p_logo[i].psz_file );
233 if( !p_logo[i].p_pic )
235 msg_Warn( p_this, "Error while loading logo %s. It will be skipped",
236 p_logo[i].psz_file );
239 if( p_c ) psz_list = p_c + 1;
242 for( i = 0; i < p_logo_list->i_count; i++ )
244 msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d",
245 p_logo[i].psz_file, p_logo[i].i_delay, p_logo[i].i_alpha );
248 /* initialize so that on the first update it will wrap back to 0 */
249 p_logo_list->i_counter = p_logo_list->i_count;
252 /*****************************************************************************
254 *****************************************************************************/
255 #define FREE( a ) free(a);a=NULL;
256 void FreeLogoList( logo_list_t *p_logo_list )
259 if( p_logo_list->psz_filename ) FREE( p_logo_list->psz_filename );
260 for( i = 0; i < p_logo_list->i_count; i++ )
262 logo_t *p_logo = &p_logo_list->p_logo[i];
263 if( p_logo[i].psz_file ) FREE( p_logo[i].psz_file );
264 if( p_logo[i].p_pic )
266 p_logo[i].p_pic->pf_release( p_logo[i].p_pic );
267 p_logo[i].p_pic = NULL;
273 /*****************************************************************************
274 * vout_sys_t: logo video output method descriptor
275 *****************************************************************************
276 * This structure is part of the video output thread descriptor.
277 * It describes the Invert specific properties of an output thread.
278 *****************************************************************************/
281 logo_list_t *p_logo_list;
283 vout_thread_t *p_vout;
287 int i_width, i_height;
291 /*****************************************************************************
292 * Create: allocates logo video thread output method
293 *****************************************************************************/
294 static int Create( vlc_object_t *p_this )
296 vout_thread_t *p_vout = (vout_thread_t *)p_this;
299 logo_list_t *p_logo_list;
301 /* Allocate structure */
302 p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
305 msg_Err( p_vout, "out of memory" );
308 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
309 if( p_logo_list == NULL )
311 msg_Err( p_vout, "out of memory" );
316 p_vout->pf_init = Init;
317 p_vout->pf_end = End;
318 p_vout->pf_manage = NULL;
319 p_vout->pf_render = Render;
320 p_vout->pf_display = NULL;
321 p_vout->pf_control = Control;
323 p_logo_list->psz_filename = var_CreateGetString( p_this , "logo-file" );
324 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
326 msg_Err( p_this, "logo file not specified" );
330 var_Create( p_this, "logo-position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
331 var_Get( p_this, "logo-position", &val );
332 p_sys->pos = val.i_int;
334 var_Create( p_this, "logo-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
335 var_Get( p_this, "logo-x", &val );
336 p_sys->posx = val.i_int;
338 var_Create( p_this, "logo-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
339 var_Get( p_this, "logo-y", &val );
340 p_sys->posy = val.i_int;
342 var_Create( p_this, "logo-delay", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
343 var_Get( p_this, "logo-delay", &val );
344 p_logo_list->i_delay = __MAX( __MIN( val.i_int, 60000 ), 0 );
346 var_Create( p_this, "logo-repeat", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
347 var_Get( p_this, "logo-repeat", &val );
348 p_logo_list->i_repeat = val.i_int;
350 var_Create(p_this, "logo-transparency", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT);
351 var_Get( p_this, "logo-transparency", &val );
352 p_logo_list->i_alpha = __MAX( __MIN( val.i_int, 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 video_format_t fmt = {0};
369 logo_list_t *p_logo_list = p_sys->p_logo_list;
371 I_OUTPUTPICTURES = 0;
373 /* adjust index to the next logo */
374 p_logo_list->i_counter =
375 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
377 p_pic = p_logo_list->p_logo[p_logo_list->i_counter].p_pic;
378 /* Initialize the output structure */
379 p_vout->output.i_chroma = p_vout->render.i_chroma;
380 p_vout->output.i_width = p_vout->render.i_width;
381 p_vout->output.i_height = p_vout->render.i_height;
382 p_vout->output.i_aspect = p_vout->render.i_aspect;
383 p_vout->fmt_out = p_vout->fmt_in;
384 fmt = p_vout->fmt_out;
386 /* Load the video blending filter */
387 p_sys->p_blend = vlc_object_create( p_vout, sizeof(filter_t) );
388 vlc_object_attach( p_sys->p_blend, p_vout );
389 p_sys->p_blend->fmt_out.video.i_x_offset =
390 p_sys->p_blend->fmt_out.video.i_y_offset = 0;
391 p_sys->p_blend->fmt_in.video.i_x_offset =
392 p_sys->p_blend->fmt_in.video.i_y_offset = 0;
393 p_sys->p_blend->fmt_out.video.i_aspect = p_vout->render.i_aspect;
394 p_sys->p_blend->fmt_out.video.i_chroma = p_vout->output.i_chroma;
395 p_sys->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','A');
396 p_sys->p_blend->fmt_in.video.i_aspect = VOUT_ASPECT_FACTOR;
398 p_sys->p_blend->fmt_in.video.i_width =
399 p_sys->p_blend->fmt_in.video.i_visible_width =
400 p_pic ? p_pic->p[Y_PLANE].i_visible_pitch : 0;
402 p_sys->p_blend->fmt_in.video.i_height =
403 p_sys->p_blend->fmt_in.video.i_visible_height =
404 p_pic ? p_pic->p[Y_PLANE].i_visible_lines : 0;
405 p_sys->p_blend->fmt_out.video.i_width =
406 p_sys->p_blend->fmt_out.video.i_visible_width =
407 p_vout->output.i_width;
408 p_sys->p_blend->fmt_out.video.i_height =
409 p_sys->p_blend->fmt_out.video.i_visible_height =
410 p_vout->output.i_height;
412 p_sys->p_blend->p_module =
413 module_Need( p_sys->p_blend, "video blending", 0, 0 );
414 if( !p_sys->p_blend->p_module )
416 msg_Err( p_vout, "can't open blending filter, aborting" );
417 vlc_object_detach( p_sys->p_blend );
418 vlc_object_destroy( p_sys->p_blend );
422 if( p_sys->posx < 0 || p_sys->posy < 0 )
424 p_sys->posx = 0; p_sys->posy = 0;
426 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
428 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
430 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
432 p_sys->posy = p_vout->render.i_height / 2 - p_sys->i_height / 2;
435 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
437 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
439 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
441 p_sys->posx = p_vout->render.i_width / 2 - p_sys->i_width / 2;
445 /* Try to open the real video output */
446 msg_Dbg( p_vout, "spawning the real video output" );
448 p_sys->p_vout = vout_Create( p_vout, &fmt );
450 /* Everything failed */
451 if( p_sys->p_vout == NULL )
453 msg_Err( p_vout, "can't open vout, aborting" );
457 var_AddCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
458 var_AddCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
460 ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );
461 ADD_CALLBACKS( p_sys->p_vout, SendEvents );
462 ADD_PARENT_CALLBACKS( SendEventsToChild );
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;
475 /* Free the fake output buffers we allocated */
476 for( i_index = I_OUTPUTPICTURES ; i_index ; )
479 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
482 var_DelCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
483 var_DelCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
487 DEL_CALLBACKS( p_sys->p_vout, SendEvents );
488 vlc_object_detach( p_sys->p_vout );
489 vout_Destroy( p_sys->p_vout );
492 if( p_sys->p_blend->p_module )
493 module_Unneed( p_sys->p_blend, p_sys->p_blend->p_module );
494 vlc_object_detach( p_sys->p_blend );
495 vlc_object_destroy( p_sys->p_blend );
498 /*****************************************************************************
499 * Destroy: destroy logo video thread output method
500 *****************************************************************************/
501 static void Destroy( vlc_object_t *p_this )
503 vout_thread_t *p_vout = (vout_thread_t *)p_this;
504 vout_sys_t *p_sys = p_vout->p_sys;
506 DEL_PARENT_CALLBACKS( SendEventsToChild );
508 FreeLogoList( p_sys->p_logo_list );
509 free( p_sys->p_logo_list );
514 /*****************************************************************************
515 * Render: render the logo onto the video
516 *****************************************************************************/
517 static void Render( vout_thread_t *p_vout, picture_t *p_inpic )
519 vout_sys_t *p_sys = p_vout->p_sys;
522 logo_list_t *p_logo_list;
525 p_logo_list = p_sys->p_logo_list;
527 if( p_logo_list->i_next_pic < p_inpic->date )
529 /* It's time to use a new logo */
530 p_logo_list->i_counter =
531 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
532 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
533 p_pic = p_logo->p_pic;
534 p_logo_list->i_next_pic = p_inpic->date + ( p_logo->i_delay != -1 ?
535 p_logo->i_delay : p_logo_list->i_delay ) * 1000;
540 p_sys->p_blend->fmt_in.video.i_width =
541 p_sys->p_blend->fmt_in.video.i_visible_width =
542 p_pic->p[Y_PLANE].i_visible_pitch;
544 p_sys->p_blend->fmt_in.video.i_height =
545 p_sys->p_blend->fmt_in.video.i_visible_height =
546 p_pic->p[Y_PLANE].i_visible_lines;
548 /* Just in case the new image would overflow the vout */
549 if( (unsigned int)(p_sys->posy + p_sys->i_height)
550 > p_vout->render.i_height
551 || (unsigned int)(p_sys->posx + p_sys->i_width)
552 > p_vout->render.i_width
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;
564 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
566 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
568 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
570 p_sys->posx = p_vout->render.i_width/2 - p_sys->i_width/2;
578 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
579 p_pic = p_logo->p_pic;
582 /* This is a new frame. Get a structure from the video_output. */
583 while( !(p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 )) )
585 if( p_vout->b_die || p_vout->b_error ) return;
586 msleep( VOUT_OUTMEM_SLEEP );
589 vout_CopyPicture( p_vout, p_outpic, p_inpic );
590 vout_DatePicture( p_sys->p_vout, p_outpic, p_inpic->date );
593 p_sys->p_blend->pf_video_blend( p_sys->p_blend, p_outpic, p_outpic,
594 p_pic, p_sys->posx, p_sys->posy,
595 p_logo->i_alpha != -1 ? p_logo->i_alpha
596 : p_logo_list->i_alpha );
598 vout_DisplayPicture( p_sys->p_vout, p_outpic );
601 /*****************************************************************************
602 * SendEvents: forward mouse and keyboard events to the parent p_vout
603 *****************************************************************************/
604 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
605 vlc_value_t oldval, vlc_value_t newval, void *p_data )
607 var_Set( (vlc_object_t *)p_data, psz_var, newval );
611 /*****************************************************************************
612 * MouseEvent: callback for mouse events
613 *****************************************************************************/
614 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
615 vlc_value_t oldval, vlc_value_t newval, void *p_data )
617 vout_thread_t *p_vout = (vout_thread_t*)p_data;
618 vout_sys_t *p_sys = p_vout->p_sys;
622 var_Get( p_vout->p_sys->p_vout, "mouse-button-down", &valb );
624 i_delta = newval.i_int - oldval.i_int;
626 if( (valb.i_int & 0x1) == 0 )
631 if( psz_var[6] == 'x' )
634 var_Get( p_vout->p_sys->p_vout, "mouse-y", &valy );
635 if( newval.i_int >= (int)p_sys->posx &&
636 valy.i_int >= (int)p_sys->posy &&
637 newval.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
638 valy.i_int <= (int)(p_sys->posy + p_sys->i_height) )
640 p_sys->posx = __MIN( __MAX( p_sys->posx + i_delta, 0 ),
641 p_vout->output.i_width - p_sys->i_width );
644 else if( psz_var[6] == 'y' )
647 var_Get( p_vout->p_sys->p_vout, "mouse-x", &valx );
648 if( valx.i_int >= (int)p_sys->posx &&
649 newval.i_int >= (int)p_sys->posy &&
650 valx.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
651 newval.i_int <= (int)(p_sys->posy + p_sys->i_height) )
653 p_sys->posy = __MIN( __MAX( p_sys->posy + i_delta, 0 ),
654 p_vout->output.i_height - p_sys->i_height );
661 /*****************************************************************************
662 * Control: control facility for the vout (forwards to child vout)
663 *****************************************************************************/
664 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
666 return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
669 /*****************************************************************************
670 * SendEventsToChild: forward events to the child/children vout
671 *****************************************************************************/
672 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
673 vlc_value_t oldval, vlc_value_t newval, void *p_data )
675 vout_thread_t *p_vout = (vout_thread_t *)p_this;
676 var_Set( p_vout->p_sys->p_vout, psz_var, newval );
680 /*****************************************************************************
681 * filter_sys_t: logo filter descriptor
682 *****************************************************************************/
685 logo_list_t *p_logo_list;
689 vlc_bool_t b_absolute;
692 /* On the fly control variable */
693 vlc_bool_t b_need_update;
696 static subpicture_t *Filter( filter_t *, mtime_t );
698 /*****************************************************************************
699 * CreateFilter: allocates logo video filter
700 *****************************************************************************/
701 static int CreateFilter( vlc_object_t *p_this )
703 filter_t *p_filter = (filter_t *)p_this;
705 vlc_object_t *p_input;
706 logo_list_t *p_logo_list;
708 /* Allocate structure */
709 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
712 msg_Err( p_filter, "out of memory" );
715 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
716 if( p_logo_list == NULL )
718 msg_Err( p_filter, "out of memory" );
723 /* Hook used for callback variables */
724 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
732 p_logo_list->psz_filename =
733 var_CreateGetString( p_input->p_libvlc , "logo-file" );
734 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
736 msg_Err( p_this, "logo file not specified" );
737 vlc_object_release( p_input );
738 //if( p_sys->psz_filename ) free( p_sys->psz_filename );
744 p_sys->posx = var_CreateGetInteger( p_input->p_libvlc , "logo-x" );
745 p_sys->posy = var_CreateGetInteger( p_input->p_libvlc , "logo-y" );
746 p_sys->pos = var_CreateGetInteger( p_input->p_libvlc , "logo-position" );
747 p_logo_list->i_alpha = __MAX( __MIN( var_CreateGetInteger(
748 p_input->p_libvlc, "logo-transparency"), 255 ), 0 );
749 p_logo_list->i_delay =
750 var_CreateGetInteger( p_input->p_libvlc , "logo-delay" );
751 p_logo_list->i_repeat =
752 var_CreateGetInteger( p_input->p_libvlc , "logo-repeat" );
754 var_AddCallback( p_input->p_libvlc, "logo-file", LogoCallback, p_sys );
755 var_AddCallback( p_input->p_libvlc, "logo-x", LogoCallback, p_sys );
756 var_AddCallback( p_input->p_libvlc, "logo-y", LogoCallback, p_sys );
757 var_AddCallback( p_input->p_libvlc, "logo-position", LogoCallback, p_sys );
758 var_AddCallback( p_input->p_libvlc, "logo-transparency", LogoCallback, p_sys );
759 var_AddCallback( p_input->p_libvlc, "logo-repeat", LogoCallback, p_sys );
760 vlc_object_release( p_input );
762 vlc_mutex_init( p_filter, &p_logo_list->lock );
763 vlc_mutex_lock( &p_logo_list->lock );
765 LoadLogoList( p_this, p_logo_list );
767 vlc_mutex_unlock( &p_logo_list->lock );
770 p_filter->pf_sub_filter = Filter;
771 p_sys->b_need_update = VLC_TRUE;
773 p_sys->i_last_date = 0;
778 /*****************************************************************************
779 * DestroyFilter: destroy logo video filter
780 *****************************************************************************/
781 static void DestroyFilter( vlc_object_t *p_this )
783 filter_t *p_filter = (filter_t *)p_this;
784 filter_sys_t *p_sys = p_filter->p_sys;
785 vlc_object_t *p_input;
787 vlc_mutex_destroy( &p_sys->p_logo_list->lock );
788 FreeLogoList( p_sys->p_logo_list );
789 free( p_sys->p_logo_list );
792 /* Delete the logo variables from INPUT */
793 p_input = vlc_object_find( p_this, VLC_OBJECT_INPUT, FIND_PARENT );
794 if( !p_input ) return;
796 var_Destroy( p_input->p_libvlc , "logo-file" );
797 var_Destroy( p_input->p_libvlc , "logo-x" );
798 var_Destroy( p_input->p_libvlc , "logo-y" );
799 var_Destroy( p_input->p_libvlc , "logo-delay" );
800 var_Destroy( p_input->p_libvlc , "logo-repeat" );
801 var_Destroy( p_input->p_libvlc , "logo-position" );
802 var_Destroy( p_input->p_libvlc , "logo-transparency" );
803 vlc_object_release( p_input );
806 /*****************************************************************************
807 * Filter: the whole thing
808 *****************************************************************************
809 * This function outputs subpictures at regular time intervals.
810 *****************************************************************************/
811 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
813 filter_sys_t *p_sys = p_filter->p_sys;
814 logo_list_t *p_logo_list = p_sys->p_logo_list;
816 subpicture_region_t *p_region;
821 vlc_mutex_lock( &p_logo_list->lock );
822 /* Basic test: b_need_update occurs on a dynamic change,
823 & i_next_pic is the general timer, when to
824 look at updating the logo image */
826 if( ( ( !p_sys->b_need_update ) && ( p_logo_list->i_next_pic > date ) )
827 || !p_logo_list->i_repeat )
829 vlc_mutex_unlock( &p_logo_list->lock );
832 /* prior code tested on && p_sys->i_last_date +5000000 > date ) return 0; */
834 /* adjust index to the next logo */
835 p_logo_list->i_counter =
836 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
838 p_logo = &p_logo_list->p_logo[p_logo_list->i_counter];
839 p_pic = p_logo->p_pic;
841 /* Allocate the subpicture internal data. */
842 p_spu = p_filter->pf_sub_buffer_new( p_filter );
845 vlc_mutex_unlock( &p_logo_list->lock );
849 p_spu->b_absolute = p_sys->b_absolute;
850 p_spu->i_start = p_sys->i_last_date = date;
852 p_spu->b_ephemer = VLC_TRUE;
854 p_sys->b_need_update = VLC_FALSE;
855 p_logo_list->i_next_pic = date +
856 ( p_logo->i_delay != -1 ? p_logo->i_delay : p_logo_list->i_delay ) * 1000;
858 if( p_logo_list->i_repeat != -1
859 && p_logo_list->i_counter == 0 )
861 p_logo_list->i_repeat--;
862 if( p_logo_list->i_repeat == 0 )
864 vlc_mutex_unlock( &p_logo_list->lock );
869 if( !p_pic || !p_logo->i_alpha
870 || ( p_logo->i_alpha == -1 && !p_logo_list->i_alpha ) )
872 /* Send an empty subpicture to clear the display */
873 vlc_mutex_unlock( &p_logo_list->lock );
877 /* Create new SPU region */
878 memset( &fmt, 0, sizeof(video_format_t) );
879 fmt.i_chroma = VLC_FOURCC('Y','U','V','A');
880 fmt.i_aspect = VOUT_ASPECT_FACTOR;
881 fmt.i_sar_num = fmt.i_sar_den = 1;
882 fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
883 fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
884 fmt.i_x_offset = fmt.i_y_offset = 0;
885 p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
888 msg_Err( p_filter, "cannot allocate SPU region" );
889 p_filter->pf_sub_buffer_del( p_filter, p_spu );
890 vlc_mutex_unlock( &p_logo_list->lock );
894 vout_CopyPicture( p_filter, &p_region->picture, p_pic );
895 vlc_mutex_unlock( &p_logo_list->lock );
897 /* where to locate the logo: */
898 if( p_sys->posx < 0 || p_sys->posy < 0 )
899 { /* set to one of the 9 relative locations */
900 p_spu->i_flags = p_sys->pos;
903 p_spu->b_absolute = VLC_FALSE;
906 { /* set to an absolute xy, referenced to upper left corner */
907 p_spu->i_flags = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
908 p_spu->i_x = p_sys->posx;
909 p_spu->i_y = p_sys->posy;
910 p_spu->b_absolute = VLC_TRUE;
913 p_spu->p_region = p_region;
915 p_spu->i_alpha = ( p_logo->i_alpha != -1 ?
916 p_logo->i_alpha : p_logo_list->i_alpha );
921 /*****************************************************************************
922 * Callback to update params on the fly
923 *****************************************************************************/
924 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
925 vlc_value_t oldval, vlc_value_t newval, void *p_data )
927 filter_sys_t *p_sys = (filter_sys_t *)p_data;
928 logo_list_t *p_logo_list = p_sys->p_logo_list;
930 if( !strncmp( psz_var, "logo-file", 6 ) )
932 vlc_mutex_lock( &p_logo_list->lock );
933 FreeLogoList( p_logo_list );
934 p_logo_list->psz_filename = strdup( newval.psz_string );
935 LoadLogoList( p_this, p_logo_list );
936 vlc_mutex_unlock( &p_logo_list->lock );
937 p_sys->b_need_update = VLC_TRUE;
939 else if ( !strncmp( psz_var, "logo-x", 6 ) )
941 p_sys->posx = newval.i_int;
943 else if ( !strncmp( psz_var, "logo-y", 6 ) )
945 p_sys->posy = newval.i_int;
947 else if ( !strncmp( psz_var, "logo-position", 12 ) )
949 p_sys->pos = newval.i_int;
951 else if ( !strncmp( psz_var, "logo-transparency", 9 ) )
953 vlc_mutex_lock( &p_logo_list->lock );
954 p_logo_list->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
955 vlc_mutex_unlock( &p_logo_list->lock );
957 else if ( !strncmp( psz_var, "logo-repeat", 11 ) )
959 vlc_mutex_lock( &p_logo_list->lock );
960 p_logo_list->i_repeat = newval.i_int;
961 vlc_mutex_unlock( &p_logo_list->lock );
963 p_sys->b_need_update = VLC_TRUE;