]> git.sesse.net Git - vlc/blob - modules/video_filter/logo.c
f8b2b14e56ebd99e5d4c0f12708b212046fa2708
[vlc] / modules / video_filter / logo.c
1 /*****************************************************************************
2  * logo.c : logo video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2003-2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *          Simon Latapie <garf@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32 #include <assert.h>
33
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_filter.h>
37
38 #include <vlc_image.h>
39 #include <vlc_osd.h>
40
41 #ifdef LoadImage
42 #   undef LoadImage
43 #endif
44
45 /*****************************************************************************
46  * Module descriptor
47  *****************************************************************************/
48 #define FILE_TEXT N_("Logo filenames")
49 #define FILE_LONGTEXT N_("Full path of the image files to use. Format is " \
50 "<image>[,<delay in ms>[,<alpha>]][;<image>[,<delay>[,<alpha>]]][;...]. " \
51 "If you only have one file, simply enter its filename.")
52 #define REPEAT_TEXT N_("Logo animation # of loops")
53 #define REPEAT_LONGTEXT N_("Number of loops for the logo animation." \
54         "-1 = continuous, 0 = disabled")
55 #define DELAY_TEXT N_("Logo individual image time in ms")
56 #define DELAY_LONGTEXT N_("Individual image display time of 0 - 60000 ms.")
57
58 #define POSX_TEXT N_("X coordinate")
59 #define POSX_LONGTEXT N_("X coordinate of the logo. You can move the logo " \
60                 "by left-clicking it." )
61 #define POSY_TEXT N_("Y coordinate")
62 #define POSY_LONGTEXT N_("Y coordinate of the logo. You can move the logo " \
63                 "by left-clicking it." )
64 #define TRANS_TEXT N_("Transparency of the logo")
65 #define TRANS_LONGTEXT N_("Logo transparency value " \
66   "(from 0 for full transparency to 255 for full opacity)." )
67 #define POS_TEXT N_("Logo position")
68 #define POS_LONGTEXT N_( \
69   "Enforce the logo position on the video " \
70   "(0=center, 1=left, 2=right, 4=top, 8=bottom, you can " \
71   "also use combinations of these values, eg 6 = top-right).")
72
73 #define CFG_PREFIX "logo-"
74
75 static const int pi_pos_values[] = { 0, 1, 2, 4, 8, 5, 6, 9, 10 };
76 static const char *const ppsz_pos_descriptions[] =
77 { N_("Center"), N_("Left"), N_("Right"), N_("Top"), N_("Bottom"),
78   N_("Top-Left"), N_("Top-Right"), N_("Bottom-Left"), N_("Bottom-Right") };
79
80 static int  OpenSub  ( vlc_object_t * );
81 static int  OpenVideo( vlc_object_t * );
82 static void Close    ( vlc_object_t * );
83
84 vlc_module_begin ()
85     set_category( CAT_VIDEO )
86     set_subcategory( SUBCAT_VIDEO_SUBPIC )
87
88     set_capability( "sub filter", 0 )
89     set_callbacks( OpenSub, Close )
90     set_description( N_("Logo sub filter") )
91     set_shortname( N_("Logo overlay") )
92     add_shortcut( "logo" )
93
94     add_file( CFG_PREFIX "file", NULL, NULL, FILE_TEXT, FILE_LONGTEXT, false )
95     add_integer( CFG_PREFIX "x", 0, NULL, POSX_TEXT, POSX_LONGTEXT, true )
96     add_integer( CFG_PREFIX "y", 0, NULL, POSY_TEXT, POSY_LONGTEXT, true )
97     /* default to 1000 ms per image, continuously cycle through them */
98     add_integer( CFG_PREFIX "delay", 1000, NULL, DELAY_TEXT, DELAY_LONGTEXT, true )
99     add_integer( CFG_PREFIX "repeat", -1, NULL, REPEAT_TEXT, REPEAT_LONGTEXT, true )
100     add_integer_with_range( CFG_PREFIX "transparency", 255, 0, 255, NULL,
101         TRANS_TEXT, TRANS_LONGTEXT, false )
102     add_integer( CFG_PREFIX "position", -1, NULL, POS_TEXT, POS_LONGTEXT, false )
103         change_integer_list( pi_pos_values, ppsz_pos_descriptions, NULL )
104
105     /* video output filter submodule */
106     add_submodule ()
107     set_capability( "video filter2", 0 )
108     set_callbacks( OpenVideo, Close )
109     set_description( N_("Logo video filter") )
110     add_shortcut( "logo" )
111 vlc_module_end ()
112
113
114 /*****************************************************************************
115  * Local prototypes
116  *****************************************************************************/
117
118 /**
119  * Structure to hold the set of individual logo image names, times,
120  * transparencies
121  */
122 typedef struct
123 {
124     char *psz_file;    /* candidate for deletion -- not needed */
125     int i_delay;       /* -1 means use default delay */
126     int i_alpha;       /* -1 means use default alpha */
127     picture_t *p_pic;
128
129 } logo_t;
130
131 /**
132  * Logo list structure.
133  */
134 typedef struct
135 {
136     logo_t *p_logo;         /* the parsing's result */
137     unsigned int i_count;   /* the number of logo images to be displayed */
138
139     int i_repeat;         /* how often to repeat the images, image time in ms */
140     mtime_t i_next_pic;     /* when to bring up a new logo image */
141
142     unsigned int i_counter; /* index into the list of logo images */
143
144     int i_delay;            /* default delay (0 - 60000 ms) */
145     int i_alpha;            /* default alpha */
146
147     char *psz_filename;     /* --logo-file string ( is it really useful
148                              * to store it ? ) */
149 } logo_list_t;
150
151 /**
152  * Private logo data holder
153  */
154 struct filter_sys_t
155 {
156     filter_t *p_blend;
157
158     vlc_mutex_t lock;
159
160     logo_list_t list;
161
162     int i_pos;
163     int i_pos_x;
164     int i_pos_y;
165     bool b_absolute;
166
167     /* On the fly control variable */
168     bool b_spu_update;
169
170     /* */
171     bool b_mouse_grab;
172 };
173
174 static const char *const ppsz_filter_options[] = {
175     "file", "x", "y", "delay", "repeat", "transparency", "position", NULL
176 };
177
178 static const char *const ppsz_filter_callbacks[] = {
179     "logo-file",
180     "logo-x",
181     "logo-y",
182     "logo-position",
183     "logo-transparency",
184     "logo-repeat",
185     NULL
186 };
187
188 static int OpenCommon( vlc_object_t *, bool b_sub );
189
190 static subpicture_t *FilterSub( filter_t *, mtime_t );
191 static picture_t    *FilterVideo( filter_t *, picture_t * );
192
193 static int Mouse( filter_t *, vlc_mouse_t *, const vlc_mouse_t *, const vlc_mouse_t * );
194
195 static int LogoCallback( vlc_object_t *, char const *,
196                          vlc_value_t, vlc_value_t, void * );
197
198 static void LogoListLoad( vlc_object_t *, logo_list_t * );
199 static void LogoListUnload( logo_list_t * );
200 static logo_t *LogoListNext( logo_list_t *p_list, mtime_t i_date );
201 static logo_t *LogoListCurrent( logo_list_t *p_list );
202
203 /**
204  * Open the sub filter
205  */
206 static int OpenSub( vlc_object_t *p_this )
207 {
208     return OpenCommon( p_this, true );
209 }
210
211 /**
212  * Open the video filter
213  */
214 static int OpenVideo( vlc_object_t *p_this )
215 {
216     return OpenCommon( p_this, false );
217 }
218
219 /**
220  * Common open function
221  */
222 static int OpenCommon( vlc_object_t *p_this, bool b_sub )
223 {
224     filter_t *p_filter = (filter_t *)p_this;
225     filter_sys_t *p_sys;
226
227     /* */
228     if( !b_sub && !es_format_IsSimilar( &p_filter->fmt_in, &p_filter->fmt_out ) )
229     {
230         msg_Err( p_filter, "Input and output format does not match" );
231         return VLC_EGENERIC;
232     }
233
234
235     /* */
236     p_filter->p_sys = p_sys = malloc( sizeof( *p_sys ) );
237     if( !p_sys )
238         return VLC_ENOMEM;
239
240     /* */
241     p_sys->p_blend = NULL;
242     if( !b_sub )
243     {
244
245         p_sys->p_blend = filter_NewBlend( VLC_OBJECT(p_filter),
246                                           p_filter->fmt_in.i_codec );
247         if( !p_sys->p_blend )
248         {
249             free( p_sys );
250             return VLC_EGENERIC;
251         }
252     }
253
254     /* */
255     config_ChainParse( p_filter, CFG_PREFIX, ppsz_filter_options,
256                        p_filter->p_cfg );
257
258     /* */
259     logo_list_t *p_list = &p_sys->list;
260
261     p_list->psz_filename =
262         var_CreateGetStringCommand( p_filter, "logo-file" );
263     if( !p_list->psz_filename )
264     {
265         if( p_sys->p_blend )
266             filter_DeleteBlend( p_sys->p_blend );
267         free( p_sys );
268         return VLC_ENOMEM;
269     }
270     if( *p_list->psz_filename == '\0' )
271         msg_Warn( p_this, "no logo file specified" );
272
273     p_list->i_alpha = var_CreateGetIntegerCommand( p_filter,
274                                                         "logo-transparency");
275     p_list->i_alpha = __MAX( __MIN( p_list->i_alpha, 255 ), 0 );
276     p_list->i_delay =
277         var_CreateGetIntegerCommand( p_filter, "logo-delay" );
278     p_list->i_repeat =
279         var_CreateGetIntegerCommand( p_filter, "logo-repeat" );
280
281     p_sys->i_pos = var_CreateGetIntegerCommand( p_filter, "logo-position" );
282     p_sys->i_pos_x = var_CreateGetIntegerCommand( p_filter, "logo-x" );
283     p_sys->i_pos_y = var_CreateGetIntegerCommand( p_filter, "logo-y" );
284
285     /* Ignore aligment if a position is given for video filter */
286     if( !b_sub && p_sys->i_pos_x >= 0 && p_sys->i_pos_y >= 0 )
287         p_sys->i_pos = 0;
288
289     vlc_mutex_init( &p_sys->lock );
290     LogoListLoad( p_this, p_list );
291     p_sys->b_spu_update = true;
292     p_sys->b_mouse_grab = false;
293
294     for( int i = 0; ppsz_filter_callbacks[i]; i++ )
295         var_AddCallback( p_filter, ppsz_filter_callbacks[i],
296                          LogoCallback, p_sys );
297
298     /* Misc init */
299     if( b_sub )
300     {
301         p_filter->pf_sub_filter = FilterSub;
302     }
303     else
304     {
305         p_filter->pf_video_filter = FilterVideo;
306         p_filter->pf_mouse = Mouse;
307     }
308
309     return VLC_SUCCESS;
310 }
311
312 /**
313  * Common close function
314  */
315 static void Close( vlc_object_t *p_this )
316 {
317     filter_t *p_filter = (filter_t *)p_this;
318     filter_sys_t *p_sys = p_filter->p_sys;
319
320     for( int i = 0; ppsz_filter_callbacks[i]; i++ )
321         var_DelCallback( p_filter, ppsz_filter_callbacks[i],
322                          LogoCallback, p_sys );
323
324     if( p_sys->p_blend )
325         filter_DeleteBlend( p_sys->p_blend );
326
327     vlc_mutex_destroy( &p_sys->lock );
328     LogoListUnload( &p_sys->list );
329     free( p_sys );
330 }
331
332 /**
333  * Sub filter
334  */
335 static subpicture_t *FilterSub( filter_t *p_filter, mtime_t date )
336 {
337     filter_sys_t *p_sys = p_filter->p_sys;
338     logo_list_t *p_list = &p_sys->list;
339
340     subpicture_t *p_spu;
341     subpicture_region_t *p_region;
342     video_format_t fmt;
343     picture_t *p_pic;
344     logo_t *p_logo;
345
346     vlc_mutex_lock( &p_sys->lock );
347     /* Basic test:  b_spu_update occurs on a dynamic change,
348                     & i_next_pic is the general timer, when to
349                     look at updating the logo image */
350
351     if( ( !p_sys->b_spu_update && p_list->i_next_pic > date ) ||
352         !p_list->i_repeat )
353     {
354         vlc_mutex_unlock( &p_sys->lock );
355         return NULL;
356     }
357
358     /* adjust index to the next logo */
359     p_logo = LogoListNext( p_list, date );
360     p_sys->b_spu_update = false;
361
362     p_pic = p_logo->p_pic;
363
364     /* Allocate the subpicture internal data. */
365     p_spu = filter_NewSubpicture( p_filter );
366     if( !p_spu )
367         goto exit;
368
369     p_spu->b_absolute = p_sys->b_absolute;
370     p_spu->i_start = date;
371     p_spu->i_stop = 0;
372     p_spu->b_ephemer = true;
373
374     /* Send an empty subpicture to clear the display when needed */
375     if( p_list->i_repeat != -1 && p_list->i_counter == 0 )
376     {
377         p_list->i_repeat--;
378         if( p_list->i_repeat == 0 )
379             goto exit;
380     }
381     if( !p_pic || !p_logo->i_alpha ||
382         ( p_logo->i_alpha == -1 && !p_list->i_alpha ) )
383         goto exit;
384
385     /* Create new SPU region */
386     memset( &fmt, 0, sizeof(video_format_t) );
387     fmt.i_chroma = VLC_CODEC_YUVA;
388     fmt.i_aspect = VOUT_ASPECT_FACTOR;
389     fmt.i_sar_num = fmt.i_sar_den = 1;
390     fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
391     fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
392     fmt.i_x_offset = fmt.i_y_offset = 0;
393     p_region = subpicture_region_New( &fmt );
394     if( !p_region )
395     {
396         msg_Err( p_filter, "cannot allocate SPU region" );
397         p_filter->pf_sub_buffer_del( p_filter, p_spu );
398         p_spu = NULL;
399         goto exit;
400     }
401
402     /* */
403     picture_Copy( p_region->p_picture, p_pic );
404
405     /*  where to locate the logo: */
406     if( p_sys->i_pos < 0 )
407     {   /*  set to an absolute xy */
408         p_region->i_align = OSD_ALIGN_RIGHT | OSD_ALIGN_TOP;
409         p_spu->b_absolute = true;
410     }
411     else
412     {   /* set to one of the 9 relative locations */
413         p_region->i_align = p_sys->i_pos;
414         p_spu->b_absolute = false;
415     }
416
417     p_region->i_x = p_sys->i_pos_x;
418     p_region->i_y = p_sys->i_pos_y;
419
420     p_spu->p_region = p_region;
421
422     p_spu->i_alpha = ( p_logo->i_alpha != -1 ?
423                        p_logo->i_alpha : p_list->i_alpha );
424
425 exit:
426     vlc_mutex_unlock( &p_sys->lock );
427
428     return p_spu;
429 }
430
431 /**
432  * Video filter
433  */
434 static picture_t *FilterVideo( filter_t *p_filter, picture_t *p_src )
435 {
436     filter_sys_t *p_sys = p_filter->p_sys;
437     logo_list_t *p_list = &p_sys->list;
438
439     picture_t *p_dst = filter_NewPicture( p_filter );
440     if( !p_dst )
441         goto exit;
442
443     picture_Copy( p_dst, p_src );
444
445     /* */
446     vlc_mutex_lock( &p_sys->lock );
447
448     logo_t *p_logo;
449     if( p_list->i_next_pic < p_src->date )
450         p_logo = LogoListNext( p_list, p_src->date );
451     else
452         p_logo = LogoListCurrent( p_list );
453
454     /* */
455     const picture_t *p_pic = p_logo->p_pic;
456     if( p_pic )
457     {
458         const video_format_t *p_fmt = &p_pic->format;
459         const int i_dst_w = p_filter->fmt_out.video.i_visible_width;
460         const int i_dst_h = p_filter->fmt_out.video.i_visible_height;
461
462         if( p_sys->i_pos )
463         {
464             if( p_sys->i_pos & SUBPICTURE_ALIGN_BOTTOM )
465             {
466                 p_sys->i_pos_y = i_dst_h - p_fmt->i_visible_height;
467             }
468             else if ( !(p_sys->i_pos & SUBPICTURE_ALIGN_TOP) )
469             {
470                 p_sys->i_pos_y = ( i_dst_h - p_fmt->i_visible_height ) / 2;
471             }
472             else
473             {
474                 p_sys->i_pos_y = 0;
475             }
476
477             if( p_sys->i_pos & SUBPICTURE_ALIGN_RIGHT )
478             {
479                 p_sys->i_pos_x = i_dst_w - p_fmt->i_visible_width;
480             }
481             else if ( !(p_sys->i_pos & SUBPICTURE_ALIGN_LEFT) )
482             {
483                 p_sys->i_pos_x = ( i_dst_w - p_fmt->i_visible_width ) / 2;
484             }
485             else
486             {
487                 p_sys->i_pos_x = 0;
488             }
489         }
490
491         /* */
492         const int i_alpha = p_logo->i_alpha != -1 ? p_logo->i_alpha : p_list->i_alpha;
493         if( filter_ConfigureBlend( p_sys->p_blend, i_dst_w, i_dst_h, p_fmt ) ||
494             filter_Blend( p_sys->p_blend, p_dst, p_sys->i_pos_x, p_sys->i_pos_y,
495                           p_pic, i_alpha ) )
496         {
497             msg_Err( p_filter, "failed to blend a picture" );
498         }
499     }
500     vlc_mutex_unlock( &p_sys->lock );
501
502 exit:
503     picture_Release( p_src );
504     return p_dst;
505 }
506
507 static int Mouse( filter_t *p_filter, vlc_mouse_t *p_mouse,
508                   const vlc_mouse_t *p_old, const vlc_mouse_t *p_new )
509 {
510     filter_sys_t *p_sys = p_filter->p_sys;
511
512     vlc_mutex_lock( &p_sys->lock );
513     logo_t *p_logo = LogoListCurrent( &p_sys->list );
514     const picture_t *p_pic = p_logo->p_pic;
515
516     if( p_pic )
517     {
518         const video_format_t *p_fmt = &p_pic->format;
519         const int i_logo_w = p_fmt->i_visible_width;
520         const int i_logo_h = p_fmt->i_visible_height;
521
522         /* Check if we are over the logo */
523         const bool b_over = p_new->i_x >= p_sys->i_pos_x &&
524                             p_new->i_x <  p_sys->i_pos_x + i_logo_w &&
525                             p_new->i_y >= p_sys->i_pos_y &&
526                             p_new->i_y <  p_sys->i_pos_y + i_logo_h;
527
528         if( b_over && vlc_mouse_HasPressed( p_old, p_new, MOUSE_BUTTON_LEFT ) )
529             p_sys->b_mouse_grab = true;
530         else if( vlc_mouse_HasReleased( p_old, p_new, MOUSE_BUTTON_LEFT ) )
531             p_sys->b_mouse_grab = false;
532
533         if( p_sys->b_mouse_grab )
534         {
535             int i_dx, i_dy;
536             vlc_mouse_GetMotion( &i_dx, &i_dy, p_old, p_new );
537             p_sys->i_pos_x = __MIN( __MAX( p_sys->i_pos_x + i_dx, 0 ),
538                                     p_filter->fmt_in.video.i_width  - i_logo_w );
539             p_sys->i_pos_y = __MIN( __MAX( p_sys->i_pos_y + i_dy, 0 ),
540                                     p_filter->fmt_in.video.i_height - i_logo_h );
541         }
542
543         if( p_sys->b_mouse_grab || b_over )
544         {
545             vlc_mutex_unlock( &p_sys->lock );
546             return VLC_EGENERIC;
547         }
548     }
549     vlc_mutex_unlock( &p_sys->lock );
550
551     *p_mouse = *p_new;
552     return VLC_SUCCESS;
553 }
554
555 /*****************************************************************************
556  * Callback to update params on the fly
557  *****************************************************************************/
558 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
559                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
560 {
561     VLC_UNUSED(oldval);
562     filter_sys_t *p_sys = (filter_sys_t *)p_data;
563     logo_list_t *p_list = &p_sys->list;
564
565     vlc_mutex_lock( &p_sys->lock );
566     if( !strcmp( psz_var, "logo-file" ) )
567     {
568         LogoListUnload( p_list );
569         p_list->psz_filename = strdup( newval.psz_string );
570         if( !p_list->psz_filename )
571             abort();
572         LogoListLoad( p_this, p_list );
573     }
574     else if ( !strcmp( psz_var, "logo-x" ) )
575     {
576         p_sys->i_pos_x = newval.i_int;
577     }
578     else if ( !strcmp( psz_var, "logo-y" ) )
579     {
580         p_sys->i_pos_y = newval.i_int;
581     }
582     else if ( !strcmp( psz_var, "logo-position" ) )
583     {
584         p_sys->i_pos = newval.i_int;
585     }
586     else if ( !strcmp( psz_var, "logo-transparency" ) )
587     {
588         p_list->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
589     }
590     else if ( !strcmp( psz_var, "logo-repeat" ) )
591     {
592         p_list->i_repeat = newval.i_int;
593     }
594     p_sys->b_spu_update = true;
595     vlc_mutex_unlock( &p_sys->lock );
596
597     return VLC_SUCCESS;
598 }
599
600 /**
601  * It loads the logo image into memory.
602  */
603 static picture_t *LoadImage( vlc_object_t *p_this, char *psz_filename )
604 {
605     if( !psz_filename )
606         return NULL;
607
608     video_format_t fmt_in;
609     video_format_Init( &fmt_in, 0 );
610
611     video_format_t fmt_out;
612     video_format_Init( &fmt_out, VLC_CODEC_YUVA );
613
614     image_handler_t *p_image = image_HandlerCreate( p_this );
615     if( !p_image )
616         return NULL;
617
618     picture_t *p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
619     image_HandlerDelete( p_image );
620
621     return p_pic;
622 }
623
624 /**
625  * It loads the logo images into memory.
626  *
627  * Read the logo-file input switch, obtaining a list of images and associated
628  * durations and transparencies.  Store the image(s), and times.  An image
629  * without a stated time or transparency will use the logo-delay and
630  * logo-transparency values.
631  */
632 static void LogoListLoad( vlc_object_t *p_this, logo_list_t *p_logo_list )
633 {
634     char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */
635     unsigned int i;
636     logo_t *p_logo;         /* the parsing's result */
637
638     p_logo_list->i_counter = 0;
639     p_logo_list->i_next_pic = 0;
640
641     psz_list = strdup( p_logo_list->psz_filename );
642     if( !psz_list )
643         abort();
644
645     /* Count the number logos == number of ';' + 1 */
646     p_logo_list->i_count = 1;
647     for( i = 0; i < strlen( psz_list ); i++ )
648     {
649         if( psz_list[i] == ';' )
650             p_logo_list->i_count++;
651     }
652
653     p_logo_list->p_logo =
654     p_logo              = calloc( p_logo_list->i_count, sizeof(*p_logo) );
655     if( !p_logo )
656         abort();
657
658     /* Fill the data */
659     for( i = 0; i < p_logo_list->i_count; i++ )
660     {
661         char *p_c  = strchr( psz_list, ';' );
662         char *p_c2 = strchr( psz_list, ',' );
663
664         p_logo[i].i_alpha = -1; /* use default settings */
665         p_logo[i].i_delay = -1; /* use default settings */
666
667         if( p_c2 && ( p_c2 < p_c || !p_c ) )
668         {
669             /* <logo>,<delay>[,<alpha>] type */
670             if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' )
671                 p_logo[i].i_delay = atoi( p_c2+1 );
672             *p_c2 = '\0';
673             if( ( p_c2 = strchr( p_c2+1, ',' ) )
674                 && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' )
675                 p_logo[i].i_alpha = atoi( p_c2 + 1 );
676         }
677         else
678         {
679             /* <logo> type */
680             if( p_c )
681                 *p_c = '\0';
682         }
683
684         p_logo[i].psz_file = strdup( psz_list );
685         p_logo[i].p_pic = LoadImage( p_this, p_logo[i].psz_file );
686
687         if( !p_logo[i].p_pic )
688         {
689             msg_Warn( p_this, "error while loading logo %s, will be skipped",
690                       p_logo[i].psz_file );
691         }
692
693         if( p_c )
694             psz_list = &p_c[1];
695     }
696
697     for( i = 0; i < p_logo_list->i_count; i++ )
698     {
699        msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d",
700                 p_logo[i].psz_file, p_logo[i].i_delay, p_logo[i].i_alpha );
701     }
702
703     /* initialize so that on the first update it will wrap back to 0 */
704     p_logo_list->i_counter = p_logo_list->i_count - 1;
705 }
706
707 /**
708  * Unload a list of logo and release associated ressources.
709  */
710 static void LogoListUnload( logo_list_t *p_list )
711 {
712     free( p_list->psz_filename );
713
714     for( unsigned i = 0; i < p_list->i_count; i++ )
715     {
716         logo_t *p_logo = &p_list->p_logo[i];
717
718         free( p_logo->psz_file );
719         if( p_logo->p_pic )
720         {
721             picture_Release( p_logo->p_pic );
722             p_logo->p_pic = NULL;
723         }
724     }
725 }
726
727 /**
728  * Go to the next logo and return its pointer.
729  */
730 static logo_t *LogoListNext( logo_list_t *p_list, mtime_t i_date )
731 {
732     p_list->i_counter = ( p_list->i_counter + 1 ) % p_list->i_count;
733
734     logo_t *p_logo = LogoListCurrent( p_list );
735
736     p_list->i_next_pic = i_date + ( p_logo->i_delay != -1 ?
737                           p_logo->i_delay : p_list->i_delay ) * 1000;
738     return p_logo;
739 }
740 /**
741  * Return the current logo pointer
742  */
743 static logo_t *LogoListCurrent( logo_list_t *p_list )
744 {
745     return &p_list->p_logo[p_list->i_counter];
746 }
747