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 static int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
94 static char *ppsz_pos_descriptions[] =
95 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
96 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
99 set_description( _("Logo video filter") );
100 set_capability( "video filter", 0 );
101 set_shortname( N_("Logo overlay") );
102 set_category( CAT_VIDEO );
103 set_subcategory( SUBCAT_VIDEO_SUBPIC );
104 add_shortcut( "logo" );
105 set_callbacks( Create, Destroy );
107 add_file( "logo-file", NULL, NULL, FILE_TEXT, FILE_LONGTEXT, VLC_FALSE );
108 add_integer( "logo-x", -1, NULL, POSX_TEXT, POSX_LONGTEXT, VLC_TRUE );
109 add_integer( "logo-y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, VLC_TRUE );
110 /* default to 1000 ms per image, continuously cycle through them */
111 add_integer( "logo-delay", 1000, NULL, DELAY_TEXT, DELAY_LONGTEXT, VLC_TRUE );
112 add_integer( "logo-repeat", -1, NULL, REPEAT_TEXT, REPEAT_LONGTEXT, VLC_TRUE );
113 add_integer_with_range( "logo-transparency", 255, 0, 255, NULL,
114 TRANS_TEXT, TRANS_LONGTEXT, VLC_FALSE );
115 add_integer( "logo-position", 6, NULL, POS_TEXT, POS_LONGTEXT, VLC_FALSE );
116 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
118 /* subpicture filter submodule */
120 set_capability( "sub filter", 0 );
121 set_callbacks( CreateFilter, DestroyFilter );
122 set_description( _("Logo sub filter") );
123 add_shortcut( "logo" );
126 /*****************************************************************************
127 * Structure to hold the set of individual logo image names, times,
129 ****************************************************************************/
132 char *psz_file; /* candidate for deletion -- not needed */
133 int i_delay; /* -1 means use default delay */
134 int i_alpha; /* -1 means use default alpha */
139 /*****************************************************************************
140 * Logo list structure. Common to both the vout and sub picture filter
141 ****************************************************************************/
144 logo_t *p_logo; /* the parsing's result */
145 unsigned int i_count; /* the number of logo images to be displayed */
147 int i_repeat; /* how often to repeat the images, image time in ms */
148 mtime_t i_next_pic; /* when to bring up a new logo image */
150 unsigned int i_counter; /* index into the list of logo images */
152 int i_delay; /* default delay (0 - 60000 ms) */
153 int i_alpha; /* default alpha */
155 char *psz_filename; /* --logo-file string ( is it really useful
161 /*****************************************************************************
162 * LoadImage: loads the logo image into memory
163 *****************************************************************************/
164 static picture_t *LoadImage( vlc_object_t *p_this, char *psz_filename )
167 image_handler_t *p_image;
168 video_format_t fmt_in = {0}, fmt_out = {0};
170 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
171 p_image = image_HandlerCreate( p_this );
172 p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
173 image_HandlerDelete( p_image );
178 /*****************************************************************************
179 * LoadLogoList: loads the logo images into memory
180 *****************************************************************************
181 * Read the logo-file input switch, obtaining a list of images and associated
182 * durations and transparencies. Store the image(s), and times. An image
183 * without a stated time or transparency will use the logo-delay and
184 * logo-transparency values.
185 *****************************************************************************/
186 #define LoadLogoList( a, b ) __LoadLogoList( VLC_OBJECT( a ), b )
187 void __LoadLogoList( vlc_object_t *p_this, logo_list_t *p_logo_list )
189 char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */
191 logo_t *p_logo; /* the parsing's result */
193 p_logo_list->i_counter = 0;
194 p_logo_list->i_next_pic = 0;
196 psz_list = strdup( p_logo_list->psz_filename );
198 /* Count the number logos == number of ';' + 1 */
199 p_logo_list->i_count = 1;
200 for( i = 0; i < strlen( psz_list ); i++ )
202 if( psz_list[i] == ';' ) p_logo_list->i_count++;
205 p_logo_list->p_logo = p_logo =
206 (logo_t *)malloc( p_logo_list->i_count * sizeof(logo_t) );
209 for( i = 0; i < p_logo_list->i_count; i++ )
213 p_c = strchr( psz_list, ';' );
214 p_c2 = strchr( psz_list, ',' );
216 p_logo[i].i_alpha = -1; /* use default settings */
217 p_logo[i].i_delay = -1; /* use default settings */
219 if( p_c2 && ( p_c2 < p_c || !p_c ) )
221 /* <logo>,<delay>[,<alpha>] type */
222 if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' )
223 p_logo[i].i_delay = atoi( p_c2+1 );
225 if( ( p_c2 = strchr( p_c2+1, ',' ) )
226 && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' )
227 p_logo[i].i_alpha = atoi( p_c2 + 1 );
232 if( p_c ) *p_c = '\0';
235 p_logo[i].psz_file = strdup( psz_list );
236 p_logo[i].p_pic = LoadImage( p_this, p_logo[i].psz_file );
238 if( !p_logo[i].p_pic )
240 msg_Warn( p_this, "error while loading logo %s, will be skipped",
241 p_logo[i].psz_file );
244 if( p_c ) psz_list = p_c + 1;
247 for( i = 0; i < p_logo_list->i_count; i++ )
249 msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d",
250 p_logo[i].psz_file, p_logo[i].i_delay, p_logo[i].i_alpha );
253 /* initialize so that on the first update it will wrap back to 0 */
254 p_logo_list->i_counter = p_logo_list->i_count;
257 /*****************************************************************************
259 *****************************************************************************/
260 void FreeLogoList( logo_list_t *p_logo_list )
263 FREENULL( p_logo_list->psz_filename );
264 for( i = 0; i < p_logo_list->i_count; i++ )
266 logo_t *p_logo = &p_logo_list->p_logo[i];
267 FREENULL( p_logo[i].psz_file );
268 if( p_logo[i].p_pic )
270 p_logo[i].p_pic->pf_release( p_logo[i].p_pic );
271 p_logo[i].p_pic = NULL;
276 /*****************************************************************************
277 * vout_sys_t: logo video output method descriptor
278 *****************************************************************************
279 * This structure is part of the video output thread descriptor.
280 * It describes the Invert specific properties of an output thread.
281 *****************************************************************************/
284 logo_list_t *p_logo_list;
286 vout_thread_t *p_vout;
290 int i_width, i_height;
294 /*****************************************************************************
295 * Create: allocates logo video thread output method
296 *****************************************************************************/
297 static int Create( vlc_object_t *p_this )
299 vout_thread_t *p_vout = (vout_thread_t *)p_this;
302 logo_list_t *p_logo_list;
304 /* Allocate structure */
305 p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
308 msg_Err( p_vout, "out of memory" );
311 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
312 if( p_logo_list == NULL )
314 msg_Err( p_vout, "out of memory" );
319 p_vout->pf_init = Init;
320 p_vout->pf_end = End;
321 p_vout->pf_manage = NULL;
322 p_vout->pf_render = Render;
323 p_vout->pf_display = NULL;
324 p_vout->pf_control = Control;
326 p_logo_list->psz_filename = var_CreateGetString( p_this , "logo-file" );
327 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
329 msg_Err( p_this, "logo file not specified" );
333 var_Create( p_this, "logo-position", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
334 var_Get( p_this, "logo-position", &val );
335 p_sys->pos = val.i_int;
337 var_Create( p_this, "logo-x", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
338 var_Get( p_this, "logo-x", &val );
339 p_sys->posx = val.i_int;
341 var_Create( p_this, "logo-y", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
342 var_Get( p_this, "logo-y", &val );
343 p_sys->posy = val.i_int;
345 var_Create( p_this, "logo-delay", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
346 var_Get( p_this, "logo-delay", &val );
347 p_logo_list->i_delay = __MAX( __MIN( val.i_int, 60000 ), 0 );
349 var_Create( p_this, "logo-repeat", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
350 var_Get( p_this, "logo-repeat", &val );
351 p_logo_list->i_repeat = val.i_int;
353 var_Create(p_this, "logo-transparency", VLC_VAR_INTEGER|VLC_VAR_DOINHERIT);
354 var_Get( p_this, "logo-transparency", &val );
355 p_logo_list->i_alpha = __MAX( __MIN( val.i_int, 255 ), 0 );
357 LoadLogoList( p_vout, p_logo_list );
362 /*****************************************************************************
363 * Init: initialize logo video thread output method
364 *****************************************************************************/
365 static int Init( vout_thread_t *p_vout )
367 vout_sys_t *p_sys = p_vout->p_sys;
370 video_format_t fmt = {0};
372 logo_list_t *p_logo_list = p_sys->p_logo_list;
374 I_OUTPUTPICTURES = 0;
376 /* adjust index to the next logo */
377 p_logo_list->i_counter =
378 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
380 p_pic = p_logo_list->p_logo[p_logo_list->i_counter].p_pic;
381 /* Initialize the output structure */
382 p_vout->output.i_chroma = p_vout->render.i_chroma;
383 p_vout->output.i_width = p_vout->render.i_width;
384 p_vout->output.i_height = p_vout->render.i_height;
385 p_vout->output.i_aspect = p_vout->render.i_aspect;
386 p_vout->fmt_out = p_vout->fmt_in;
387 fmt = p_vout->fmt_out;
389 /* Load the video blending filter */
390 p_sys->p_blend = vlc_object_create( p_vout, sizeof(filter_t) );
391 vlc_object_attach( p_sys->p_blend, p_vout );
392 p_sys->p_blend->fmt_out.video.i_x_offset =
393 p_sys->p_blend->fmt_out.video.i_y_offset = 0;
394 p_sys->p_blend->fmt_in.video.i_x_offset =
395 p_sys->p_blend->fmt_in.video.i_y_offset = 0;
396 p_sys->p_blend->fmt_out.video.i_aspect = p_vout->render.i_aspect;
397 p_sys->p_blend->fmt_out.video.i_chroma = p_vout->output.i_chroma;
398 p_sys->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','A');
399 p_sys->p_blend->fmt_in.video.i_aspect = VOUT_ASPECT_FACTOR;
401 p_sys->p_blend->fmt_in.video.i_width =
402 p_sys->p_blend->fmt_in.video.i_visible_width =
403 p_pic ? p_pic->p[Y_PLANE].i_visible_pitch : 0;
405 p_sys->p_blend->fmt_in.video.i_height =
406 p_sys->p_blend->fmt_in.video.i_visible_height =
407 p_pic ? p_pic->p[Y_PLANE].i_visible_lines : 0;
408 p_sys->p_blend->fmt_out.video.i_width =
409 p_sys->p_blend->fmt_out.video.i_visible_width =
410 p_vout->output.i_width;
411 p_sys->p_blend->fmt_out.video.i_height =
412 p_sys->p_blend->fmt_out.video.i_visible_height =
413 p_vout->output.i_height;
415 p_sys->p_blend->p_module =
416 module_Need( p_sys->p_blend, "video blending", 0, 0 );
417 if( !p_sys->p_blend->p_module )
419 msg_Err( p_vout, "can't open blending filter, aborting" );
420 vlc_object_detach( p_sys->p_blend );
421 vlc_object_destroy( p_sys->p_blend );
425 if( p_sys->posx < 0 || p_sys->posy < 0 )
427 p_sys->posx = 0; p_sys->posy = 0;
429 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
431 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
433 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
435 p_sys->posy = p_vout->render.i_height / 2 - p_sys->i_height / 2;
438 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
440 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
442 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
444 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;
551 /* Just in case the new image would overflow the vout */
552 if( (unsigned int)(p_sys->posy + p_sys->i_height)
553 > p_vout->render.i_height
554 || (unsigned int)(p_sys->posx + p_sys->i_width)
555 > p_vout->render.i_width
558 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
560 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
562 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
564 p_sys->posy = p_vout->render.i_height/2 - p_sys->i_height/2;
567 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
569 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
571 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
573 p_sys->posx = p_vout->render.i_width/2 - p_sys->i_width/2;
581 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
582 p_pic = p_logo->p_pic;
585 /* This is a new frame. Get a structure from the video_output. */
586 while( !(p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 )) )
588 if( p_vout->b_die || p_vout->b_error ) return;
589 msleep( VOUT_OUTMEM_SLEEP );
592 vout_CopyPicture( p_vout, p_outpic, p_inpic );
593 vout_DatePicture( p_sys->p_vout, p_outpic, p_inpic->date );
596 p_sys->p_blend->pf_video_blend( p_sys->p_blend, p_outpic, p_outpic,
597 p_pic, p_sys->posx, p_sys->posy,
598 p_logo->i_alpha != -1 ? p_logo->i_alpha
599 : p_logo_list->i_alpha );
601 vout_DisplayPicture( p_sys->p_vout, p_outpic );
604 /*****************************************************************************
605 * SendEvents: forward mouse and keyboard events to the parent p_vout
606 *****************************************************************************/
607 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
608 vlc_value_t oldval, vlc_value_t newval, void *p_data )
610 var_Set( (vlc_object_t *)p_data, psz_var, newval );
614 /*****************************************************************************
615 * MouseEvent: callback for mouse events
616 *****************************************************************************/
617 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
618 vlc_value_t oldval, vlc_value_t newval, void *p_data )
620 vout_thread_t *p_vout = (vout_thread_t*)p_data;
621 vout_sys_t *p_sys = p_vout->p_sys;
625 var_Get( p_vout->p_sys->p_vout, "mouse-button-down", &valb );
627 i_delta = newval.i_int - oldval.i_int;
629 if( (valb.i_int & 0x1) == 0 )
634 if( psz_var[6] == 'x' )
637 var_Get( p_vout->p_sys->p_vout, "mouse-y", &valy );
638 if( newval.i_int >= (int)p_sys->posx &&
639 valy.i_int >= (int)p_sys->posy &&
640 newval.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
641 valy.i_int <= (int)(p_sys->posy + p_sys->i_height) )
643 p_sys->posx = __MIN( __MAX( p_sys->posx + i_delta, 0 ),
644 p_vout->output.i_width - p_sys->i_width );
647 else if( psz_var[6] == 'y' )
650 var_Get( p_vout->p_sys->p_vout, "mouse-x", &valx );
651 if( valx.i_int >= (int)p_sys->posx &&
652 newval.i_int >= (int)p_sys->posy &&
653 valx.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
654 newval.i_int <= (int)(p_sys->posy + p_sys->i_height) )
656 p_sys->posy = __MIN( __MAX( p_sys->posy + i_delta, 0 ),
657 p_vout->output.i_height - p_sys->i_height );
664 /*****************************************************************************
665 * Control: control facility for the vout (forwards to child vout)
666 *****************************************************************************/
667 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
669 return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
672 /*****************************************************************************
673 * SendEventsToChild: forward events to the child/children vout
674 *****************************************************************************/
675 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
676 vlc_value_t oldval, vlc_value_t newval, void *p_data )
678 vout_thread_t *p_vout = (vout_thread_t *)p_this;
679 var_Set( p_vout->p_sys->p_vout, psz_var, newval );
683 /*****************************************************************************
684 * filter_sys_t: logo filter descriptor
685 *****************************************************************************/
688 logo_list_t *p_logo_list;
692 vlc_bool_t b_absolute;
695 /* On the fly control variable */
696 vlc_bool_t b_need_update;
699 static subpicture_t *Filter( filter_t *, mtime_t );
701 /*****************************************************************************
702 * CreateFilter: allocates logo video filter
703 *****************************************************************************/
704 static int CreateFilter( vlc_object_t *p_this )
706 filter_t *p_filter = (filter_t *)p_this;
708 logo_list_t *p_logo_list;
710 /* Allocate structure */
711 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
714 msg_Err( p_filter, "out of memory" );
717 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
718 if( p_logo_list == NULL )
720 msg_Err( p_filter, "out of memory" );
725 /* Hook used for callback variables */
726 p_logo_list->psz_filename =
727 var_CreateGetString( p_filter->p_libvlc , "logo-file" );
728 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
730 msg_Err( p_this, "logo file not specified" );
736 p_sys->posx = var_CreateGetInteger( p_filter->p_libvlc , "logo-x" );
737 p_sys->posy = var_CreateGetInteger( p_filter->p_libvlc , "logo-y" );
738 p_sys->pos = var_CreateGetInteger( p_filter->p_libvlc , "logo-position" );
739 p_logo_list->i_alpha = __MAX( __MIN( var_CreateGetInteger(
740 p_filter->p_libvlc, "logo-transparency"), 255 ), 0 );
741 p_logo_list->i_delay =
742 var_CreateGetInteger( p_filter->p_libvlc , "logo-delay" );
743 p_logo_list->i_repeat =
744 var_CreateGetInteger( p_filter->p_libvlc , "logo-repeat" );
746 var_AddCallback( p_filter->p_libvlc, "logo-file", LogoCallback, p_sys );
747 var_AddCallback( p_filter->p_libvlc, "logo-x", LogoCallback, p_sys );
748 var_AddCallback( p_filter->p_libvlc, "logo-y", LogoCallback, p_sys );
749 var_AddCallback( p_filter->p_libvlc, "logo-position", LogoCallback, p_sys );
750 var_AddCallback( p_filter->p_libvlc, "logo-transparency", LogoCallback, p_sys );
751 var_AddCallback( p_filter->p_libvlc, "logo-repeat", LogoCallback, p_sys );
753 vlc_mutex_init( p_filter, &p_logo_list->lock );
754 vlc_mutex_lock( &p_logo_list->lock );
756 LoadLogoList( p_this, p_logo_list );
758 vlc_mutex_unlock( &p_logo_list->lock );
761 p_filter->pf_sub_filter = Filter;
762 p_sys->b_need_update = VLC_TRUE;
764 p_sys->i_last_date = 0;
769 /*****************************************************************************
770 * DestroyFilter: destroy logo video filter
771 *****************************************************************************/
772 static void DestroyFilter( vlc_object_t *p_this )
774 filter_t *p_filter = (filter_t *)p_this;
775 filter_sys_t *p_sys = p_filter->p_sys;
777 vlc_mutex_destroy( &p_sys->p_logo_list->lock );
778 FreeLogoList( p_sys->p_logo_list );
779 free( p_sys->p_logo_list );
782 /* Delete the logo variables from INPUT */
783 var_Destroy( p_filter->p_libvlc , "logo-file" );
784 var_Destroy( p_filter->p_libvlc , "logo-x" );
785 var_Destroy( p_filter->p_libvlc , "logo-y" );
786 var_Destroy( p_filter->p_libvlc , "logo-delay" );
787 var_Destroy( p_filter->p_libvlc , "logo-repeat" );
788 var_Destroy( p_filter->p_libvlc , "logo-position" );
789 var_Destroy( p_filter->p_libvlc , "logo-transparency" );
792 /*****************************************************************************
793 * Filter: the whole thing
794 *****************************************************************************
795 * This function outputs subpictures at regular time intervals.
796 *****************************************************************************/
797 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
799 filter_sys_t *p_sys = p_filter->p_sys;
800 logo_list_t *p_logo_list = p_sys->p_logo_list;
802 subpicture_region_t *p_region;
807 vlc_mutex_lock( &p_logo_list->lock );
808 /* Basic test: b_need_update occurs on a dynamic change,
809 & i_next_pic is the general timer, when to
810 look at updating the logo image */
812 if( ( ( !p_sys->b_need_update ) && ( p_logo_list->i_next_pic > date ) )
813 || !p_logo_list->i_repeat )
815 vlc_mutex_unlock( &p_logo_list->lock );
818 /* prior code tested on && p_sys->i_last_date +5000000 > date ) return 0; */
820 /* adjust index to the next logo */
821 p_logo_list->i_counter =
822 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
824 p_logo = &p_logo_list->p_logo[p_logo_list->i_counter];
825 p_pic = p_logo->p_pic;
827 /* Allocate the subpicture internal data. */
828 p_spu = p_filter->pf_sub_buffer_new( p_filter );
831 vlc_mutex_unlock( &p_logo_list->lock );
835 p_spu->b_absolute = p_sys->b_absolute;
836 p_spu->i_start = p_sys->i_last_date = date;
838 p_spu->b_ephemer = VLC_TRUE;
840 p_sys->b_need_update = VLC_FALSE;
841 p_logo_list->i_next_pic = date +
842 ( p_logo->i_delay != -1 ? p_logo->i_delay : p_logo_list->i_delay ) * 1000;
844 if( p_logo_list->i_repeat != -1
845 && p_logo_list->i_counter == 0 )
847 p_logo_list->i_repeat--;
848 if( p_logo_list->i_repeat == 0 )
850 vlc_mutex_unlock( &p_logo_list->lock );
855 if( !p_pic || !p_logo->i_alpha
856 || ( p_logo->i_alpha == -1 && !p_logo_list->i_alpha ) )
858 /* Send an empty subpicture to clear the display */
859 vlc_mutex_unlock( &p_logo_list->lock );
863 /* Create new SPU region */
864 memset( &fmt, 0, sizeof(video_format_t) );
865 fmt.i_chroma = VLC_FOURCC('Y','U','V','A');
866 fmt.i_aspect = VOUT_ASPECT_FACTOR;
867 fmt.i_sar_num = fmt.i_sar_den = 1;
868 fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
869 fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
870 fmt.i_x_offset = fmt.i_y_offset = 0;
871 p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
874 msg_Err( p_filter, "cannot allocate SPU region" );
875 p_filter->pf_sub_buffer_del( p_filter, p_spu );
876 vlc_mutex_unlock( &p_logo_list->lock );
880 vout_CopyPicture( p_filter, &p_region->picture, p_pic );
881 vlc_mutex_unlock( &p_logo_list->lock );
883 /* where to locate the logo: */
884 if( p_sys->posx < 0 || p_sys->posy < 0 )
885 { /* set to one of the 9 relative locations */
886 p_spu->i_flags = p_sys->pos;
889 p_spu->b_absolute = VLC_FALSE;
892 { /* set to an absolute xy, referenced to upper left corner */
893 p_spu->i_flags = OSD_ALIGN_LEFT | OSD_ALIGN_TOP;
894 p_spu->i_x = p_sys->posx;
895 p_spu->i_y = p_sys->posy;
896 p_spu->b_absolute = VLC_TRUE;
899 p_spu->p_region = p_region;
901 p_spu->i_alpha = ( p_logo->i_alpha != -1 ?
902 p_logo->i_alpha : p_logo_list->i_alpha );
907 /*****************************************************************************
908 * Callback to update params on the fly
909 *****************************************************************************/
910 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
911 vlc_value_t oldval, vlc_value_t newval, void *p_data )
913 filter_sys_t *p_sys = (filter_sys_t *)p_data;
914 logo_list_t *p_logo_list = p_sys->p_logo_list;
916 if( !strncmp( psz_var, "logo-file", 6 ) )
918 vlc_mutex_lock( &p_logo_list->lock );
919 FreeLogoList( p_logo_list );
920 p_logo_list->psz_filename = strdup( newval.psz_string );
921 LoadLogoList( p_this, p_logo_list );
922 vlc_mutex_unlock( &p_logo_list->lock );
923 p_sys->b_need_update = VLC_TRUE;
925 else if ( !strncmp( psz_var, "logo-x", 6 ) )
927 p_sys->posx = newval.i_int;
929 else if ( !strncmp( psz_var, "logo-y", 6 ) )
931 p_sys->posy = newval.i_int;
933 else if ( !strncmp( psz_var, "logo-position", 12 ) )
935 p_sys->pos = newval.i_int;
937 else if ( !strncmp( psz_var, "logo-transparency", 9 ) )
939 vlc_mutex_lock( &p_logo_list->lock );
940 p_logo_list->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
941 vlc_mutex_unlock( &p_logo_list->lock );
943 else if ( !strncmp( psz_var, "logo-repeat", 11 ) )
945 vlc_mutex_lock( &p_logo_list->lock );
946 p_logo_list->i_repeat = newval.i_int;
947 vlc_mutex_unlock( &p_logo_list->lock );
949 p_sys->b_need_update = VLC_TRUE;