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>
37 #include "vlc_filter.h"
38 #include "filter_common.h"
39 #include "vlc_image.h"
46 /*****************************************************************************
48 *****************************************************************************/
49 static int Create ( vlc_object_t * );
50 static void Destroy ( vlc_object_t * );
52 static int Init ( vout_thread_t * );
53 static void End ( vout_thread_t * );
54 static void Render ( vout_thread_t *, picture_t * );
56 static int SendEvents( vlc_object_t *, char const *,
57 vlc_value_t, vlc_value_t, void * );
58 static int MouseEvent( vlc_object_t *, char const *,
59 vlc_value_t , vlc_value_t , void * );
60 static int Control ( vout_thread_t *, int, va_list );
62 static int CreateFilter ( vlc_object_t * );
63 static void DestroyFilter( vlc_object_t * );
65 static int LogoCallback( vlc_object_t *, char const *,
66 vlc_value_t, vlc_value_t, void * );
68 /*****************************************************************************
70 *****************************************************************************/
71 #define FILE_TEXT N_("Logo filenames")
72 #define FILE_LONGTEXT N_("Full path of the image files to use. Format is " \
73 "<image>[,<delay in ms>[,<alpha>]][;<image>[,<delay>[,<alpha>]]][;...]. " \
74 "If you only have one file, simply enter its filename.")
75 #define REPEAT_TEXT N_("Logo animation # of loops")
76 #define REPEAT_LONGTEXT N_("Number of loops for the logo animation." \
77 "-1 = continuous, 0 = disabled")
78 #define DELAY_TEXT N_("Logo individual image time in ms")
79 #define DELAY_LONGTEXT N_("Individual image display time of 0 - 60000 ms.")
81 #define POSX_TEXT N_("X coordinate")
82 #define POSX_LONGTEXT N_("X coordinate of the logo. You can move the logo " \
83 "by left-clicking it." )
84 #define POSY_TEXT N_("Y coordinate")
85 #define POSY_LONGTEXT N_("Y coordinate of the logo. You can move the logo " \
86 "by left-clicking it." )
87 #define TRANS_TEXT N_("Transparency of the logo")
88 #define TRANS_LONGTEXT N_("Logo transparency value " \
89 "(from 0 for full transparency to 255 for full opacity)." )
90 #define POS_TEXT N_("Logo position")
91 #define POS_LONGTEXT N_( \
92 "Enforce the logo position on the video " \
93 "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
94 "also use combinations of these values, eg 6 = top-right).")
96 #define CFG_PREFIX "logo-"
98 static const int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
99 static const char *const ppsz_pos_descriptions[] =
100 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
101 N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
104 set_description( N_("Logo video filter") );
105 set_capability( "video filter", 0 );
106 set_shortname( N_("Logo overlay") );
107 set_category( CAT_VIDEO );
108 set_subcategory( SUBCAT_VIDEO_SUBPIC );
109 add_shortcut( "logo" );
110 set_callbacks( Create, Destroy );
112 add_file( CFG_PREFIX "file", NULL, NULL, FILE_TEXT, FILE_LONGTEXT, false );
113 add_integer( CFG_PREFIX "x", 0, NULL, POSX_TEXT, POSX_LONGTEXT, true );
114 add_integer( CFG_PREFIX "y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, true );
115 /* default to 1000 ms per image, continuously cycle through them */
116 add_integer( CFG_PREFIX "delay", 1000, NULL, DELAY_TEXT, DELAY_LONGTEXT, true );
117 add_integer( CFG_PREFIX "repeat", -1, NULL, REPEAT_TEXT, REPEAT_LONGTEXT, true );
118 add_integer_with_range( CFG_PREFIX "transparency", 255, 0, 255, NULL,
119 TRANS_TEXT, TRANS_LONGTEXT, false );
120 add_integer( CFG_PREFIX "position", -1, NULL, POS_TEXT, POS_LONGTEXT, false );
121 change_integer_list( pi_pos_values, ppsz_pos_descriptions, 0 );
123 /* subpicture filter submodule */
125 set_capability( "sub filter", 0 );
126 set_callbacks( CreateFilter, DestroyFilter );
127 set_description( N_("Logo sub filter") );
130 static const char *const ppsz_filter_options[] = {
131 "file", "x", "y", "delay", "repeat", "transparency", "position", NULL
134 /*****************************************************************************
135 * Structure to hold the set of individual logo image names, times,
137 ****************************************************************************/
140 char *psz_file; /* candidate for deletion -- not needed */
141 int i_delay; /* -1 means use default delay */
142 int i_alpha; /* -1 means use default alpha */
147 /*****************************************************************************
148 * Logo list structure. Common to both the vout and sub picture filter
149 ****************************************************************************/
152 logo_t *p_logo; /* the parsing's result */
153 unsigned int i_count; /* the number of logo images to be displayed */
155 int i_repeat; /* how often to repeat the images, image time in ms */
156 mtime_t i_next_pic; /* when to bring up a new logo image */
158 unsigned int i_counter; /* index into the list of logo images */
160 int i_delay; /* default delay (0 - 60000 ms) */
161 int i_alpha; /* default alpha */
163 char *psz_filename; /* --logo-file string ( is it really useful
169 /*****************************************************************************
170 * LoadImage: loads the logo image into memory
171 *****************************************************************************/
172 static picture_t *LoadImage( vlc_object_t *p_this, char *psz_filename )
175 image_handler_t *p_image;
176 video_format_t fmt_in;
177 video_format_t fmt_out;
179 memset( &fmt_in, 0, sizeof(video_format_t) );
180 memset( &fmt_out, 0, sizeof(video_format_t) );
182 fmt_out.i_chroma = VLC_FOURCC('Y','U','V','A');
183 p_image = image_HandlerCreate( p_this );
184 p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
185 image_HandlerDelete( p_image );
190 /*****************************************************************************
191 * LoadLogoList: loads the logo images into memory
192 *****************************************************************************
193 * Read the logo-file input switch, obtaining a list of images and associated
194 * durations and transparencies. Store the image(s), and times. An image
195 * without a stated time or transparency will use the logo-delay and
196 * logo-transparency values.
197 *****************************************************************************/
198 #define LoadLogoList( a, b ) __LoadLogoList( VLC_OBJECT( a ), b )
199 static void __LoadLogoList( vlc_object_t *p_this, logo_list_t *p_logo_list )
201 char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */
203 logo_t *p_logo; /* the parsing's result */
205 p_logo_list->i_counter = 0;
206 p_logo_list->i_next_pic = 0;
208 psz_list = strdup( p_logo_list->psz_filename );
210 /* Count the number logos == number of ';' + 1 */
211 p_logo_list->i_count = 1;
212 for( i = 0; i < strlen( psz_list ); i++ )
214 if( psz_list[i] == ';' ) p_logo_list->i_count++;
217 p_logo_list->p_logo = p_logo =
218 (logo_t *)malloc( p_logo_list->i_count * sizeof(logo_t) );
221 for( i = 0; i < p_logo_list->i_count; i++ )
225 p_c = strchr( psz_list, ';' );
226 p_c2 = strchr( psz_list, ',' );
228 p_logo[i].i_alpha = -1; /* use default settings */
229 p_logo[i].i_delay = -1; /* use default settings */
231 if( p_c2 && ( p_c2 < p_c || !p_c ) )
233 /* <logo>,<delay>[,<alpha>] type */
234 if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' )
235 p_logo[i].i_delay = atoi( p_c2+1 );
237 if( ( p_c2 = strchr( p_c2+1, ',' ) )
238 && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' )
239 p_logo[i].i_alpha = atoi( p_c2 + 1 );
244 if( p_c ) *p_c = '\0';
247 p_logo[i].psz_file = strdup( psz_list );
248 p_logo[i].p_pic = LoadImage( p_this, p_logo[i].psz_file );
250 if( !p_logo[i].p_pic )
252 msg_Warn( p_this, "error while loading logo %s, will be skipped",
253 p_logo[i].psz_file );
256 if( p_c ) psz_list = p_c + 1;
259 for( i = 0; i < p_logo_list->i_count; i++ )
261 msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d",
262 p_logo[i].psz_file, p_logo[i].i_delay, p_logo[i].i_alpha );
265 /* initialize so that on the first update it will wrap back to 0 */
266 p_logo_list->i_counter = p_logo_list->i_count;
269 /*****************************************************************************
271 *****************************************************************************/
272 static void FreeLogoList( logo_list_t *p_logo_list )
275 FREENULL( p_logo_list->psz_filename );
276 for( i = 0; i < p_logo_list->i_count; i++ )
278 logo_t *p_logo = &p_logo_list->p_logo[i];
279 FREENULL( p_logo->psz_file );
282 picture_Release( p_logo->p_pic );
283 p_logo->p_pic = NULL;
288 /*****************************************************************************
289 * vout_sys_t: logo video output method descriptor
290 *****************************************************************************
291 * This structure is part of the video output thread descriptor.
292 * It describes the Invert specific properties of an output thread.
293 *****************************************************************************/
296 logo_list_t *p_logo_list;
298 vout_thread_t *p_vout;
302 int i_width, i_height;
306 /*****************************************************************************
307 * Create: allocates logo video thread output method
308 *****************************************************************************/
309 static int Create( vlc_object_t *p_this )
311 vout_thread_t *p_vout = (vout_thread_t *)p_this;
313 logo_list_t *p_logo_list;
315 /* Allocate structure */
316 p_sys = p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
319 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
320 if( p_logo_list == NULL )
326 config_ChainParse( p_vout, CFG_PREFIX, ppsz_filter_options,
329 p_logo_list->psz_filename = var_CreateGetStringCommand( p_vout,
331 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
333 msg_Err( p_vout, "logo file not specified" );
337 p_vout->pf_init = Init;
338 p_vout->pf_end = End;
339 p_vout->pf_manage = NULL;
340 p_vout->pf_render = Render;
341 p_vout->pf_display = NULL;
342 p_vout->pf_control = Control;
344 p_sys->pos = var_CreateGetIntegerCommand( p_vout, "logo-position" );
345 p_sys->posx = var_CreateGetIntegerCommand( p_vout, "logo-x" );
346 p_sys->posy = var_CreateGetIntegerCommand( p_vout, "logo-y" );
347 p_logo_list->i_delay = __MAX( __MIN(
348 var_CreateGetIntegerCommand( p_vout, "logo-delay" ) , 60000 ), 0 );
349 p_logo_list->i_repeat = var_CreateGetIntegerCommand( p_vout, "logo-repeat");
350 p_logo_list->i_alpha = __MAX( __MIN(
351 var_CreateGetIntegerCommand( p_vout, "logo-transparency" ), 255 ), 0 );
353 LoadLogoList( p_vout, p_logo_list );
358 /*****************************************************************************
359 * Init: initialize logo video thread output method
360 *****************************************************************************/
361 static int Init( vout_thread_t *p_vout )
363 vout_sys_t *p_sys = p_vout->p_sys;
367 logo_list_t *p_logo_list = p_sys->p_logo_list;
369 I_OUTPUTPICTURES = 0;
370 memset( &fmt, 0, sizeof(video_format_t) );
372 /* adjust index to the next logo */
373 p_logo_list->i_counter =
374 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
376 p_pic = p_logo_list->p_logo[p_logo_list->i_counter].p_pic;
377 /* Initialize the output structure */
378 p_vout->output.i_chroma = p_vout->render.i_chroma;
379 p_vout->output.i_width = p_vout->render.i_width;
380 p_vout->output.i_height = p_vout->render.i_height;
381 p_vout->output.i_aspect = p_vout->render.i_aspect;
382 p_vout->fmt_out = p_vout->fmt_in;
383 fmt = p_vout->fmt_out;
385 /* Load the video blending filter */
386 p_sys->p_blend = vlc_object_create( p_vout, sizeof(filter_t) );
387 vlc_object_attach( p_sys->p_blend, p_vout );
388 p_sys->p_blend->fmt_out.video.i_x_offset =
389 p_sys->p_blend->fmt_out.video.i_y_offset = 0;
390 p_sys->p_blend->fmt_in.video.i_x_offset =
391 p_sys->p_blend->fmt_in.video.i_y_offset = 0;
392 p_sys->p_blend->fmt_out.video.i_aspect = p_vout->render.i_aspect;
393 p_sys->p_blend->fmt_out.video.i_chroma = p_vout->output.i_chroma;
394 p_sys->p_blend->fmt_in.video.i_chroma = VLC_FOURCC('Y','U','V','A');
395 p_sys->p_blend->fmt_in.video.i_aspect = VOUT_ASPECT_FACTOR;
397 p_sys->p_blend->fmt_in.video.i_width =
398 p_sys->p_blend->fmt_in.video.i_visible_width =
399 p_pic ? p_pic->p[Y_PLANE].i_visible_pitch : 0;
401 p_sys->p_blend->fmt_in.video.i_height =
402 p_sys->p_blend->fmt_in.video.i_visible_height =
403 p_pic ? p_pic->p[Y_PLANE].i_visible_lines : 0;
404 p_sys->p_blend->fmt_out.video.i_width =
405 p_sys->p_blend->fmt_out.video.i_visible_width =
406 p_vout->output.i_width;
407 p_sys->p_blend->fmt_out.video.i_height =
408 p_sys->p_blend->fmt_out.video.i_visible_height =
409 p_vout->output.i_height;
411 p_sys->p_blend->p_module =
412 module_Need( p_sys->p_blend, "video blending", 0, 0 );
413 if( !p_sys->p_blend->p_module )
415 msg_Err( p_vout, "can't open blending filter, aborting" );
416 vlc_object_detach( p_sys->p_blend );
417 vlc_object_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 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 DEL_PARENT_CALLBACKS( SendEventsToChild );
480 DEL_CALLBACKS( p_sys->p_vout, SendEvents );
482 /* Free the fake output buffers we allocated */
483 for( i_index = I_OUTPUTPICTURES ; i_index ; )
486 free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
489 var_DelCallback( p_sys->p_vout, "mouse-x", MouseEvent, p_vout);
490 var_DelCallback( p_sys->p_vout, "mouse-y", MouseEvent, p_vout);
492 vout_CloseAndRelease( p_sys->p_vout );
494 if( p_sys->p_blend->p_module )
495 module_Unneed( p_sys->p_blend, p_sys->p_blend->p_module );
496 vlc_object_detach( p_sys->p_blend );
497 vlc_object_release( p_sys->p_blend );
500 /*****************************************************************************
501 * Destroy: destroy logo video thread output method
502 *****************************************************************************/
503 static void Destroy( vlc_object_t *p_this )
505 vout_thread_t *p_vout = (vout_thread_t *)p_this;
506 vout_sys_t *p_sys = p_vout->p_sys;
509 FreeLogoList( p_sys->p_logo_list );
510 free( p_sys->p_logo_list );
515 /*****************************************************************************
516 * Render: render the logo onto the video
517 *****************************************************************************/
518 static void Render( vout_thread_t *p_vout, picture_t *p_inpic )
520 vout_sys_t *p_sys = p_vout->p_sys;
523 logo_list_t *p_logo_list;
526 p_logo_list = p_sys->p_logo_list;
528 if( p_logo_list->i_next_pic < p_inpic->date )
530 /* It's time to use a new logo */
531 p_logo_list->i_counter =
532 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
533 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
534 p_pic = p_logo->p_pic;
535 p_logo_list->i_next_pic = p_inpic->date + ( p_logo->i_delay != -1 ?
536 p_logo->i_delay : p_logo_list->i_delay ) * 1000;
541 p_sys->p_blend->fmt_in.video.i_width =
542 p_sys->p_blend->fmt_in.video.i_visible_width =
543 p_pic->p[Y_PLANE].i_visible_pitch;
545 p_sys->p_blend->fmt_in.video.i_height =
546 p_sys->p_blend->fmt_in.video.i_visible_height =
547 p_pic->p[Y_PLANE].i_visible_lines;
551 if( p_sys->pos & SUBPICTURE_ALIGN_BOTTOM )
553 p_sys->posy = p_vout->render.i_height - p_sys->i_height;
555 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_TOP) )
557 p_sys->posy = p_vout->render.i_height/2 - p_sys->i_height/2;
559 if( p_sys->pos & SUBPICTURE_ALIGN_RIGHT )
561 p_sys->posx = p_vout->render.i_width - p_sys->i_width;
563 else if ( !(p_sys->pos & SUBPICTURE_ALIGN_LEFT) )
565 p_sys->posx = p_vout->render.i_width/2 - p_sys->i_width/2;
573 p_logo = &p_logo_list->p_logo[p_sys->p_logo_list->i_counter];
574 p_pic = p_logo->p_pic;
577 /* This is a new frame. Get a structure from the video_output. */
578 while( !(p_outpic = vout_CreatePicture( p_sys->p_vout, 0, 0, 0 )) )
580 if( !vlc_object_alive (p_vout) || p_vout->b_error ) return;
581 msleep( VOUT_OUTMEM_SLEEP );
584 vout_CopyPicture( p_vout, p_outpic, p_inpic );
585 vout_DatePicture( p_sys->p_vout, p_outpic, p_inpic->date );
588 p_sys->p_blend->pf_video_blend( p_sys->p_blend, p_outpic, p_outpic,
589 p_pic, p_sys->posx, p_sys->posy,
590 p_logo->i_alpha != -1 ? p_logo->i_alpha
591 : p_logo_list->i_alpha );
593 vout_DisplayPicture( p_sys->p_vout, p_outpic );
596 /*****************************************************************************
597 * SendEvents: forward mouse and keyboard events to the parent p_vout
598 *****************************************************************************/
599 static int SendEvents( vlc_object_t *p_this, char const *psz_var,
600 vlc_value_t oldval, vlc_value_t newval, void *p_data )
602 VLC_UNUSED(p_this); VLC_UNUSED(oldval);
603 var_Set( (vlc_object_t *)p_data, psz_var, newval );
607 /*****************************************************************************
608 * MouseEvent: callback for mouse events
609 *****************************************************************************/
610 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
611 vlc_value_t oldval, vlc_value_t newval, void *p_data )
613 VLC_UNUSED(p_this); VLC_UNUSED(oldval);
614 vout_thread_t *p_vout = (vout_thread_t*)p_data;
615 vout_sys_t *p_sys = p_vout->p_sys;
619 var_Get( p_vout->p_sys->p_vout, "mouse-button-down", &valb );
621 i_delta = newval.i_int - oldval.i_int;
623 if( (valb.i_int & 0x1) == 0 )
628 if( psz_var[6] == 'x' )
631 var_Get( p_vout->p_sys->p_vout, "mouse-y", &valy );
632 if( newval.i_int >= (int)p_sys->posx &&
633 valy.i_int >= (int)p_sys->posy &&
634 newval.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
635 valy.i_int <= (int)(p_sys->posy + p_sys->i_height) )
637 p_sys->posx = __MIN( __MAX( p_sys->posx + i_delta, 0 ),
638 p_vout->output.i_width - p_sys->i_width );
641 else if( psz_var[6] == 'y' )
644 var_Get( p_vout->p_sys->p_vout, "mouse-x", &valx );
645 if( valx.i_int >= (int)p_sys->posx &&
646 newval.i_int >= (int)p_sys->posy &&
647 valx.i_int <= (int)(p_sys->posx + p_sys->i_width) &&
648 newval.i_int <= (int)(p_sys->posy + p_sys->i_height) )
650 p_sys->posy = __MIN( __MAX( p_sys->posy + i_delta, 0 ),
651 p_vout->output.i_height - p_sys->i_height );
658 /*****************************************************************************
659 * Control: control facility for the vout (forwards to child vout)
660 *****************************************************************************/
661 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
663 return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
666 /*****************************************************************************
667 * SendEventsToChild: forward events to the child/children vout
668 *****************************************************************************/
669 static int SendEventsToChild( vlc_object_t *p_this, char const *psz_var,
670 vlc_value_t oldval, vlc_value_t newval, void *p_data )
672 VLC_UNUSED(p_data); VLC_UNUSED(oldval);
673 vout_thread_t *p_vout = (vout_thread_t *)p_this;
674 var_Set( p_vout->p_sys->p_vout, psz_var, newval );
678 /*****************************************************************************
679 * filter_sys_t: logo filter descriptor
680 *****************************************************************************/
683 logo_list_t *p_logo_list;
690 /* On the fly control variable */
694 static subpicture_t *Filter( filter_t *, mtime_t );
696 /*****************************************************************************
697 * CreateFilter: allocates logo video filter
698 *****************************************************************************/
699 static int CreateFilter( vlc_object_t *p_this )
701 filter_t *p_filter = (filter_t *)p_this;
703 logo_list_t *p_logo_list;
705 /* Allocate structure */
706 p_sys = p_filter->p_sys = malloc( sizeof( filter_sys_t ) );
709 p_logo_list = p_sys->p_logo_list = malloc( sizeof( logo_list_t ) );
710 if( p_logo_list == NULL )
716 config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
719 /* Hook used for callback variables */
720 p_logo_list->psz_filename =
721 var_CreateGetStringCommand( p_filter, "logo-file" );
722 if( !p_logo_list->psz_filename || !*p_logo_list->psz_filename )
724 msg_Err( p_this, "logo file not specified" );
730 p_sys->posx = var_CreateGetIntegerCommand( p_filter, "logo-x" );
731 p_sys->posy = var_CreateGetIntegerCommand( p_filter, "logo-y" );
732 p_sys->pos = var_CreateGetIntegerCommand( p_filter, "logo-position" );
733 p_logo_list->i_alpha = __MAX( __MIN( var_CreateGetIntegerCommand(
734 p_filter, "logo-transparency"), 255 ), 0 );
735 p_logo_list->i_delay =
736 var_CreateGetIntegerCommand( p_filter, "logo-delay" );
737 p_logo_list->i_repeat =
738 var_CreateGetIntegerCommand( p_filter, "logo-repeat" );
740 var_AddCallback( p_filter, "logo-file", LogoCallback, p_sys );
741 var_AddCallback( p_filter, "logo-x", LogoCallback, p_sys );
742 var_AddCallback( p_filter, "logo-y", LogoCallback, p_sys );
743 var_AddCallback( p_filter, "logo-position", LogoCallback, p_sys );
744 var_AddCallback( p_filter, "logo-transparency", LogoCallback, p_sys );
745 var_AddCallback( p_filter, "logo-repeat", LogoCallback, p_sys );
747 vlc_mutex_init( &p_logo_list->lock );
748 vlc_mutex_lock( &p_logo_list->lock );
750 LoadLogoList( p_this, p_logo_list );
752 vlc_mutex_unlock( &p_logo_list->lock );
755 p_filter->pf_sub_filter = Filter;
756 p_sys->b_need_update = true;
758 p_sys->i_last_date = 0;
763 /*****************************************************************************
764 * DestroyFilter: destroy logo video filter
765 *****************************************************************************/
766 static void DestroyFilter( vlc_object_t *p_this )
768 filter_t *p_filter = (filter_t *)p_this;
769 filter_sys_t *p_sys = p_filter->p_sys;
771 vlc_mutex_destroy( &p_sys->p_logo_list->lock );
772 FreeLogoList( p_sys->p_logo_list );
773 free( p_sys->p_logo_list );
776 /* Delete the logo variables from INPUT */
777 var_Destroy( p_filter->p_libvlc, "logo-file" );
778 var_Destroy( p_filter->p_libvlc, "logo-x" );
779 var_Destroy( p_filter->p_libvlc, "logo-y" );
780 var_Destroy( p_filter->p_libvlc, "logo-delay" );
781 var_Destroy( p_filter->p_libvlc, "logo-repeat" );
782 var_Destroy( p_filter->p_libvlc, "logo-position" );
783 var_Destroy( p_filter->p_libvlc, "logo-transparency" );
786 /*****************************************************************************
787 * Filter: the whole thing
788 *****************************************************************************
789 * This function outputs subpictures at regular time intervals.
790 *****************************************************************************/
791 static subpicture_t *Filter( filter_t *p_filter, mtime_t date )
793 filter_sys_t *p_sys = p_filter->p_sys;
794 logo_list_t *p_logo_list = p_sys->p_logo_list;
796 subpicture_region_t *p_region;
801 vlc_mutex_lock( &p_logo_list->lock );
802 /* Basic test: b_need_update occurs on a dynamic change,
803 & i_next_pic is the general timer, when to
804 look at updating the logo image */
806 if( ( ( !p_sys->b_need_update ) && ( p_logo_list->i_next_pic > date ) )
807 || !p_logo_list->i_repeat )
809 vlc_mutex_unlock( &p_logo_list->lock );
812 /* prior code tested on && p_sys->i_last_date +5000000 > date ) return 0; */
814 /* adjust index to the next logo */
815 p_logo_list->i_counter =
816 ( p_logo_list->i_counter + 1 )%p_logo_list->i_count;
818 p_logo = &p_logo_list->p_logo[p_logo_list->i_counter];
819 p_pic = p_logo->p_pic;
821 /* Allocate the subpicture internal data. */
822 p_spu = filter_NewSubpicture( p_filter );
825 vlc_mutex_unlock( &p_logo_list->lock );
829 p_spu->b_absolute = p_sys->b_absolute;
830 p_spu->i_start = p_sys->i_last_date = date;
832 p_spu->b_ephemer = true;
834 p_sys->b_need_update = false;
835 p_logo_list->i_next_pic = date +
836 ( p_logo->i_delay != -1 ? p_logo->i_delay : p_logo_list->i_delay ) * 1000;
838 if( p_logo_list->i_repeat != -1
839 && p_logo_list->i_counter == 0 )
841 p_logo_list->i_repeat--;
842 if( p_logo_list->i_repeat == 0 )
844 vlc_mutex_unlock( &p_logo_list->lock );
849 if( !p_pic || !p_logo->i_alpha
850 || ( p_logo->i_alpha == -1 && !p_logo_list->i_alpha ) )
852 /* Send an empty subpicture to clear the display */
853 vlc_mutex_unlock( &p_logo_list->lock );
857 /* Create new SPU region */
858 memset( &fmt, 0, sizeof(video_format_t) );
859 fmt.i_chroma = VLC_FOURCC('Y','U','V','A');
860 fmt.i_aspect = VOUT_ASPECT_FACTOR;
861 fmt.i_sar_num = fmt.i_sar_den = 1;
862 fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
863 fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
864 fmt.i_x_offset = fmt.i_y_offset = 0;
865 p_region = p_spu->pf_create_region( VLC_OBJECT(p_filter), &fmt );
868 msg_Err( p_filter, "cannot allocate SPU region" );
869 p_filter->pf_sub_buffer_del( p_filter, p_spu );
870 vlc_mutex_unlock( &p_logo_list->lock );
874 vout_CopyPicture( p_filter, &p_region->picture, p_pic );
875 vlc_mutex_unlock( &p_logo_list->lock );
877 /* where to locate the logo: */
879 { /* set to an absolute xy */
880 p_region->i_align = OSD_ALIGN_RIGHT | OSD_ALIGN_TOP;
881 p_spu->b_absolute = true;
884 { /* set to one of the 9 relative locations */
885 p_region->i_align = p_sys->pos;
886 p_spu->b_absolute = false;
889 p_spu->i_x = p_sys->posx;
890 p_spu->i_y = p_sys->posy;
892 p_spu->p_region = p_region;
894 p_spu->i_alpha = ( p_logo->i_alpha != -1 ?
895 p_logo->i_alpha : p_logo_list->i_alpha );
900 /*****************************************************************************
901 * Callback to update params on the fly
902 *****************************************************************************/
903 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
904 vlc_value_t oldval, vlc_value_t newval, void *p_data )
907 filter_sys_t *p_sys = (filter_sys_t *)p_data;
908 logo_list_t *p_logo_list = p_sys->p_logo_list;
910 if( !strncmp( psz_var, "logo-file", 6 ) )
912 vlc_mutex_lock( &p_logo_list->lock );
913 FreeLogoList( p_logo_list );
914 p_logo_list->psz_filename = strdup( newval.psz_string );
915 LoadLogoList( p_this, p_logo_list );
916 vlc_mutex_unlock( &p_logo_list->lock );
917 p_sys->b_need_update = true;
919 else if ( !strncmp( psz_var, "logo-x", 6 ) )
921 p_sys->posx = newval.i_int;
923 else if ( !strncmp( psz_var, "logo-y", 6 ) )
925 p_sys->posy = newval.i_int;
927 else if ( !strncmp( psz_var, "logo-position", 12 ) )
929 p_sys->pos = newval.i_int;
931 else if ( !strncmp( psz_var, "logo-transparency", 9 ) )
933 vlc_mutex_lock( &p_logo_list->lock );
934 p_logo_list->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
935 vlc_mutex_unlock( &p_logo_list->lock );
937 else if ( !strncmp( psz_var, "logo-repeat", 11 ) )
939 vlc_mutex_lock( &p_logo_list->lock );
940 p_logo_list->i_repeat = newval.i_int;
941 vlc_mutex_unlock( &p_logo_list->lock );
943 p_sys->b_need_update = true;