]> git.sesse.net Git - vlc/blob - modules/video_filter/logo.c
6b583c9f1829af0abfc013be24e6f97de49217d7
[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     int i_delay;       /* -1 means use default delay */
125     int i_alpha;       /* -1 means use default alpha */
126     picture_t *p_pic;
127
128 } logo_t;
129
130 /**
131  * Logo list structure.
132  */
133 typedef struct
134 {
135     logo_t *p_logo;         /* the parsing's result */
136     unsigned int i_count;   /* the number of logo images to be displayed */
137
138     int i_repeat;         /* how often to repeat the images, image time in ms */
139     mtime_t i_next_pic;     /* when to bring up a new logo image */
140
141     unsigned int i_counter; /* index into the list of logo images */
142
143     int i_delay;            /* default delay (0 - 60000 ms) */
144     int i_alpha;            /* default alpha */
145
146 } logo_list_t;
147
148 /**
149  * Private logo data holder
150  */
151 struct filter_sys_t
152 {
153     filter_t *p_blend;
154
155     vlc_mutex_t lock;
156
157     logo_list_t list;
158
159     int i_pos;
160     int i_pos_x;
161     int i_pos_y;
162     bool b_absolute;
163
164     /* On the fly control variable */
165     bool b_spu_update;
166
167     /* */
168     bool b_mouse_grab;
169 };
170
171 static const char *const ppsz_filter_options[] = {
172     "file", "x", "y", "delay", "repeat", "transparency", "position", NULL
173 };
174
175 static const char *const ppsz_filter_callbacks[] = {
176     "logo-file",
177     "logo-x",
178     "logo-y",
179     "logo-position",
180     "logo-transparency",
181     "logo-repeat",
182     NULL
183 };
184
185 static int OpenCommon( vlc_object_t *, bool b_sub );
186
187 static subpicture_t *FilterSub( filter_t *, mtime_t );
188 static picture_t    *FilterVideo( filter_t *, picture_t * );
189
190 static int Mouse( filter_t *, vlc_mouse_t *, const vlc_mouse_t *, const vlc_mouse_t * );
191
192 static int LogoCallback( vlc_object_t *, char const *,
193                          vlc_value_t, vlc_value_t, void * );
194
195 static void LogoListLoad( vlc_object_t *, logo_list_t *, const char * );
196 static void LogoListUnload( logo_list_t * );
197 static logo_t *LogoListNext( logo_list_t *p_list, mtime_t i_date );
198 static logo_t *LogoListCurrent( logo_list_t *p_list );
199
200 /**
201  * Open the sub filter
202  */
203 static int OpenSub( vlc_object_t *p_this )
204 {
205     return OpenCommon( p_this, true );
206 }
207
208 /**
209  * Open the video filter
210  */
211 static int OpenVideo( vlc_object_t *p_this )
212 {
213     return OpenCommon( p_this, false );
214 }
215
216 /**
217  * Common open function
218  */
219 static int OpenCommon( vlc_object_t *p_this, bool b_sub )
220 {
221     filter_t *p_filter = (filter_t *)p_this;
222     filter_sys_t *p_sys;
223     char *psz_filename;
224
225     /* */
226     if( !b_sub && !es_format_IsSimilar( &p_filter->fmt_in, &p_filter->fmt_out ) )
227     {
228         msg_Err( p_filter, "Input and output format does not match" );
229         return VLC_EGENERIC;
230     }
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,
271                                                         "logo-transparency");
272     p_list->i_alpha = __MAX( __MIN( p_list->i_alpha, 255 ), 0 );
273     p_list->i_delay =
274         var_CreateGetIntegerCommand( p_filter, "logo-delay" );
275     p_list->i_repeat =
276         var_CreateGetIntegerCommand( p_filter, "logo-repeat" );
277
278     p_sys->i_pos = var_CreateGetIntegerCommand( p_filter, "logo-position" );
279     p_sys->i_pos_x = var_CreateGetIntegerCommand( p_filter, "logo-x" );
280     p_sys->i_pos_y = var_CreateGetIntegerCommand( p_filter, "logo-y" );
281
282     /* Ignore aligment if a position is given for video filter */
283     if( !b_sub && p_sys->i_pos_x >= 0 && p_sys->i_pos_y >= 0 )
284         p_sys->i_pos = 0;
285
286     vlc_mutex_init( &p_sys->lock );
287     LogoListLoad( p_this, p_list, psz_filename );
288     p_sys->b_spu_update = true;
289     p_sys->b_mouse_grab = false;
290
291     for( int i = 0; ppsz_filter_callbacks[i]; i++ )
292         var_AddCallback( p_filter, ppsz_filter_callbacks[i],
293                          LogoCallback, p_sys );
294
295     /* Misc init */
296     if( b_sub )
297     {
298         p_filter->pf_sub_filter = FilterSub;
299     }
300     else
301     {
302         p_filter->pf_video_filter = FilterVideo;
303         p_filter->pf_mouse = Mouse;
304     }
305
306     free( psz_filename );
307     return VLC_SUCCESS;
308 }
309
310 /**
311  * Common close function
312  */
313 static void Close( vlc_object_t *p_this )
314 {
315     filter_t *p_filter = (filter_t *)p_this;
316     filter_sys_t *p_sys = p_filter->p_sys;
317
318     for( int i = 0; ppsz_filter_callbacks[i]; i++ )
319         var_DelCallback( p_filter, ppsz_filter_callbacks[i],
320                          LogoCallback, p_sys );
321
322     if( p_sys->p_blend )
323         filter_DeleteBlend( p_sys->p_blend );
324
325     vlc_mutex_destroy( &p_sys->lock );
326     LogoListUnload( &p_sys->list );
327     free( p_sys );
328 }
329
330 /**
331  * Sub filter
332  */
333 static subpicture_t *FilterSub( filter_t *p_filter, mtime_t date )
334 {
335     filter_sys_t *p_sys = p_filter->p_sys;
336     logo_list_t *p_list = &p_sys->list;
337
338     subpicture_t *p_spu;
339     subpicture_region_t *p_region;
340     video_format_t fmt;
341     picture_t *p_pic;
342     logo_t *p_logo;
343
344     vlc_mutex_lock( &p_sys->lock );
345     /* Basic test:  b_spu_update occurs on a dynamic change,
346                     & i_next_pic is the general timer, when to
347                     look at updating the logo image */
348
349     if( ( !p_sys->b_spu_update && p_list->i_next_pic > date ) ||
350         !p_list->i_repeat )
351     {
352         vlc_mutex_unlock( &p_sys->lock );
353         return NULL;
354     }
355
356     /* adjust index to the next logo */
357     p_logo = LogoListNext( p_list, date );
358     p_sys->b_spu_update = false;
359
360     p_pic = p_logo->p_pic;
361
362     /* Allocate the subpicture internal data. */
363     p_spu = filter_NewSubpicture( p_filter );
364     if( !p_spu )
365         goto exit;
366
367     p_spu->b_absolute = p_sys->b_absolute;
368     p_spu->i_start = date;
369     p_spu->i_stop = 0;
370     p_spu->b_ephemer = true;
371
372     /* Send an empty subpicture to clear the display when needed */
373     if( p_list->i_repeat != -1 && p_list->i_counter == 0 )
374     {
375         p_list->i_repeat--;
376         if( p_list->i_repeat == 0 )
377             goto exit;
378     }
379     if( !p_pic || !p_logo->i_alpha ||
380         ( p_logo->i_alpha == -1 && !p_list->i_alpha ) )
381         goto exit;
382
383     /* Create new SPU region */
384     memset( &fmt, 0, sizeof(video_format_t) );
385     fmt.i_chroma = VLC_CODEC_YUVA;
386     fmt.i_sar_num = fmt.i_sar_den = 1;
387     fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
388     fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
389     fmt.i_x_offset = fmt.i_y_offset = 0;
390     p_region = subpicture_region_New( &fmt );
391     if( !p_region )
392     {
393         msg_Err( p_filter, "cannot allocate SPU region" );
394         p_filter->pf_sub_buffer_del( p_filter, p_spu );
395         p_spu = NULL;
396         goto exit;
397     }
398
399     /* */
400     picture_Copy( p_region->p_picture, p_pic );
401
402     /*  where to locate the logo: */
403     if( p_sys->i_pos < 0 )
404     {   /*  set to an absolute xy */
405         p_region->i_align = OSD_ALIGN_RIGHT | OSD_ALIGN_TOP;
406         p_spu->b_absolute = true;
407     }
408     else
409     {   /* set to one of the 9 relative locations */
410         p_region->i_align = p_sys->i_pos;
411         p_spu->b_absolute = false;
412     }
413
414     p_region->i_x = p_sys->i_pos_x;
415     p_region->i_y = p_sys->i_pos_y;
416
417     p_spu->p_region = p_region;
418
419     p_spu->i_alpha = ( p_logo->i_alpha != -1 ?
420                        p_logo->i_alpha : p_list->i_alpha );
421
422 exit:
423     vlc_mutex_unlock( &p_sys->lock );
424
425     return p_spu;
426 }
427
428 /**
429  * Video filter
430  */
431 static picture_t *FilterVideo( filter_t *p_filter, picture_t *p_src )
432 {
433     filter_sys_t *p_sys = p_filter->p_sys;
434     logo_list_t *p_list = &p_sys->list;
435
436     picture_t *p_dst = filter_NewPicture( p_filter );
437     if( !p_dst )
438         goto exit;
439
440     picture_Copy( p_dst, p_src );
441
442     /* */
443     vlc_mutex_lock( &p_sys->lock );
444
445     logo_t *p_logo;
446     if( p_list->i_next_pic < p_src->date )
447         p_logo = LogoListNext( p_list, p_src->date );
448     else
449         p_logo = LogoListCurrent( p_list );
450
451     /* */
452     const picture_t *p_pic = p_logo->p_pic;
453     if( p_pic )
454     {
455         const video_format_t *p_fmt = &p_pic->format;
456         const int i_dst_w = p_filter->fmt_out.video.i_visible_width;
457         const int i_dst_h = p_filter->fmt_out.video.i_visible_height;
458
459         if( p_sys->i_pos )
460         {
461             if( p_sys->i_pos & SUBPICTURE_ALIGN_BOTTOM )
462             {
463                 p_sys->i_pos_y = i_dst_h - p_fmt->i_visible_height;
464             }
465             else if ( !(p_sys->i_pos & SUBPICTURE_ALIGN_TOP) )
466             {
467                 p_sys->i_pos_y = ( i_dst_h - p_fmt->i_visible_height ) / 2;
468             }
469             else
470             {
471                 p_sys->i_pos_y = 0;
472             }
473
474             if( p_sys->i_pos & SUBPICTURE_ALIGN_RIGHT )
475             {
476                 p_sys->i_pos_x = i_dst_w - p_fmt->i_visible_width;
477             }
478             else if ( !(p_sys->i_pos & SUBPICTURE_ALIGN_LEFT) )
479             {
480                 p_sys->i_pos_x = ( i_dst_w - p_fmt->i_visible_width ) / 2;
481             }
482             else
483             {
484                 p_sys->i_pos_x = 0;
485             }
486         }
487
488         /* */
489         const int i_alpha = p_logo->i_alpha != -1 ? p_logo->i_alpha : p_list->i_alpha;
490         if( filter_ConfigureBlend( p_sys->p_blend, i_dst_w, i_dst_h, p_fmt ) ||
491             filter_Blend( p_sys->p_blend, p_dst, p_sys->i_pos_x, p_sys->i_pos_y,
492                           p_pic, i_alpha ) )
493         {
494             msg_Err( p_filter, "failed to blend a picture" );
495         }
496     }
497     vlc_mutex_unlock( &p_sys->lock );
498
499 exit:
500     picture_Release( p_src );
501     return p_dst;
502 }
503
504 static int Mouse( filter_t *p_filter, vlc_mouse_t *p_mouse,
505                   const vlc_mouse_t *p_old, const vlc_mouse_t *p_new )
506 {
507     filter_sys_t *p_sys = p_filter->p_sys;
508
509     vlc_mutex_lock( &p_sys->lock );
510     logo_t *p_logo = LogoListCurrent( &p_sys->list );
511     const picture_t *p_pic = p_logo->p_pic;
512
513     if( p_pic )
514     {
515         const video_format_t *p_fmt = &p_pic->format;
516         const int i_logo_w = p_fmt->i_visible_width;
517         const int i_logo_h = p_fmt->i_visible_height;
518
519         /* Check if we are over the logo */
520         const bool b_over = p_new->i_x >= p_sys->i_pos_x &&
521                             p_new->i_x <  p_sys->i_pos_x + i_logo_w &&
522                             p_new->i_y >= p_sys->i_pos_y &&
523                             p_new->i_y <  p_sys->i_pos_y + i_logo_h;
524
525         if( b_over && vlc_mouse_HasPressed( p_old, p_new, MOUSE_BUTTON_LEFT ) )
526             p_sys->b_mouse_grab = true;
527         else if( vlc_mouse_HasReleased( p_old, p_new, MOUSE_BUTTON_LEFT ) )
528             p_sys->b_mouse_grab = false;
529
530         if( p_sys->b_mouse_grab )
531         {
532             int i_dx, i_dy;
533             vlc_mouse_GetMotion( &i_dx, &i_dy, p_old, p_new );
534             p_sys->i_pos_x = __MIN( __MAX( p_sys->i_pos_x + i_dx, 0 ),
535                                     p_filter->fmt_in.video.i_width  - i_logo_w );
536             p_sys->i_pos_y = __MIN( __MAX( p_sys->i_pos_y + i_dy, 0 ),
537                                     p_filter->fmt_in.video.i_height - i_logo_h );
538         }
539
540         if( p_sys->b_mouse_grab || b_over )
541         {
542             vlc_mutex_unlock( &p_sys->lock );
543             return VLC_EGENERIC;
544         }
545     }
546     vlc_mutex_unlock( &p_sys->lock );
547
548     *p_mouse = *p_new;
549     return VLC_SUCCESS;
550 }
551
552 /*****************************************************************************
553  * Callback to update params on the fly
554  *****************************************************************************/
555 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
556                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
557 {
558     VLC_UNUSED(oldval);
559     filter_sys_t *p_sys = (filter_sys_t *)p_data;
560     logo_list_t *p_list = &p_sys->list;
561
562     vlc_mutex_lock( &p_sys->lock );
563     if( !strcmp( psz_var, "logo-file" ) )
564     {
565         LogoListUnload( p_list );
566         LogoListLoad( p_this, p_list, newval.psz_string );
567     }
568     else if ( !strcmp( psz_var, "logo-x" ) )
569     {
570         p_sys->i_pos_x = newval.i_int;
571     }
572     else if ( !strcmp( psz_var, "logo-y" ) )
573     {
574         p_sys->i_pos_y = newval.i_int;
575     }
576     else if ( !strcmp( psz_var, "logo-position" ) )
577     {
578         p_sys->i_pos = newval.i_int;
579     }
580     else if ( !strcmp( psz_var, "logo-transparency" ) )
581     {
582         p_list->i_alpha = __MAX( __MIN( newval.i_int, 255 ), 0 );
583     }
584     else if ( !strcmp( psz_var, "logo-repeat" ) )
585     {
586         p_list->i_repeat = newval.i_int;
587     }
588     p_sys->b_spu_update = true;
589     vlc_mutex_unlock( &p_sys->lock );
590
591     return VLC_SUCCESS;
592 }
593
594 /**
595  * It loads the logo image into memory.
596  */
597 static picture_t *LoadImage( vlc_object_t *p_this, const char *psz_filename )
598 {
599     if( !psz_filename )
600         return NULL;
601
602     video_format_t fmt_in;
603     video_format_Init( &fmt_in, 0 );
604
605     video_format_t fmt_out;
606     video_format_Init( &fmt_out, VLC_CODEC_YUVA );
607
608     image_handler_t *p_image = image_HandlerCreate( p_this );
609     if( !p_image )
610         return NULL;
611
612     picture_t *p_pic = image_ReadUrl( p_image, psz_filename, &fmt_in, &fmt_out );
613     image_HandlerDelete( p_image );
614
615     return p_pic;
616 }
617
618 /**
619  * It loads the logo images into memory.
620  *
621  * Read the logo-file input switch, obtaining a list of images and associated
622  * durations and transparencies.  Store the image(s), and times.  An image
623  * without a stated time or transparency will use the logo-delay and
624  * logo-transparency values.
625  */
626 static void LogoListLoad( vlc_object_t *p_this, logo_list_t *p_logo_list,
627                           const char *psz_filename )
628 {
629     char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */
630     char *psz_original;
631     unsigned int i;
632     logo_t *p_logo;         /* the parsing's result */
633
634     p_logo_list->i_counter = 0;
635     p_logo_list->i_next_pic = 0;
636
637     psz_original = psz_list = strdup( psz_filename );
638     if( !psz_list )
639         abort();
640
641     /* Count the number logos == number of ';' + 1 */
642     p_logo_list->i_count = 1;
643     for( i = 0; i < strlen( psz_list ); i++ )
644     {
645         if( psz_list[i] == ';' )
646             p_logo_list->i_count++;
647     }
648
649     p_logo_list->p_logo =
650     p_logo              = calloc( p_logo_list->i_count, sizeof(*p_logo) );
651     if( !p_logo )
652         abort();
653
654     /* Fill the data */
655     for( i = 0; i < p_logo_list->i_count; i++ )
656     {
657         char *p_c  = strchr( psz_list, ';' );
658         char *p_c2 = strchr( psz_list, ',' );
659
660         p_logo[i].i_alpha = -1; /* use default settings */
661         p_logo[i].i_delay = -1; /* use default settings */
662
663         if( p_c2 && ( p_c2 < p_c || !p_c ) )
664         {
665             /* <logo>,<delay>[,<alpha>] type */
666             if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' )
667                 p_logo[i].i_delay = atoi( p_c2+1 );
668             *p_c2 = '\0';
669             if( ( p_c2 = strchr( p_c2+1, ',' ) )
670                 && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' )
671                 p_logo[i].i_alpha = atoi( p_c2 + 1 );
672         }
673         else
674         {
675             /* <logo> type */
676             if( p_c )
677                 *p_c = '\0';
678         }
679
680         msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d",
681                  psz_list, p_logo[i].i_delay, p_logo[i].i_alpha );
682         p_logo[i].p_pic = LoadImage( p_this, psz_list );
683         if( !p_logo[i].p_pic )
684         {
685             msg_Warn( p_this, "error while loading logo %s, will be skipped",
686                       psz_list );
687         }
688
689         if( p_c )
690             psz_list = &p_c[1];
691     }
692
693     /* initialize so that on the first update it will wrap back to 0 */
694     p_logo_list->i_counter = p_logo_list->i_count - 1;
695
696     free( psz_original );
697 }
698
699 /**
700  * Unload a list of logo and release associated ressources.
701  */
702 static void LogoListUnload( logo_list_t *p_list )
703 {
704     for( unsigned i = 0; i < p_list->i_count; i++ )
705     {
706         logo_t *p_logo = &p_list->p_logo[i];
707
708         if( p_logo->p_pic )
709             picture_Release( p_logo->p_pic );
710     }
711     free( p_list->p_logo );
712 }
713
714 /**
715  * Go to the next logo and return its pointer.
716  */
717 static logo_t *LogoListNext( logo_list_t *p_list, mtime_t i_date )
718 {
719     p_list->i_counter = ( p_list->i_counter + 1 ) % p_list->i_count;
720
721     logo_t *p_logo = LogoListCurrent( p_list );
722
723     p_list->i_next_pic = i_date + ( p_logo->i_delay != -1 ?
724                           p_logo->i_delay : p_list->i_delay ) * 1000;
725     return p_logo;
726 }
727 /**
728  * Return the current logo pointer
729  */
730 static logo_t *LogoListCurrent( logo_list_t *p_list )
731 {
732     return &p_list->p_logo[p_list->i_counter];
733 }
734