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