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