]> git.sesse.net Git - vlc/blob - modules/video_filter/logo.c
decoder: do not mix and match condidition variable and mutex pairings
[vlc] / modules / video_filter / logo.c
1 /*****************************************************************************
2  * logo.c : logo video plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2003-2006 VLC authors and VideoLAN
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 it
11  * under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with this program; if not, write to the Free Software Foundation,
22  * 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 source", 0 )
91     set_callbacks( OpenSub, Close )
92     set_description( N_("Logo sub source") )
93     set_shortname( N_("Logo overlay") )
94     add_shortcut( "logo" )
95
96     add_loadfile( CFG_PREFIX "file", NULL, FILE_TEXT, FILE_LONGTEXT, false )
97     add_integer( CFG_PREFIX "x", -1, POSX_TEXT, POSX_LONGTEXT, true )
98     add_integer( CFG_PREFIX "y", -1, POSY_TEXT, POSY_LONGTEXT, true )
99     /* default to 1000 ms per image, continuously cycle through them */
100     add_integer( CFG_PREFIX "delay", 1000, DELAY_TEXT, DELAY_LONGTEXT, true )
101     add_integer( CFG_PREFIX "repeat", -1, REPEAT_TEXT, REPEAT_LONGTEXT, true )
102     add_integer_with_range( CFG_PREFIX "opacity", 255, 0, 255,
103         OPACITY_TEXT, OPACITY_LONGTEXT, false )
104     add_integer( CFG_PREFIX "position", -1, POS_TEXT, POS_LONGTEXT, false )
105         change_integer_list( pi_pos_values, ppsz_pos_descriptions )
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 source
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 = VLC_CLIP( p_list->i_alpha, 0, 255 );
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     p_sys->b_absolute = (p_sys->i_pos < 0);
280
281     /* Ignore aligment if a position is given for video filter */
282     if( !b_sub && p_sys->i_pos_x >= 0 && p_sys->i_pos_y >= 0 )
283         p_sys->i_pos = 0;
284
285     vlc_mutex_init( &p_sys->lock );
286     LogoListLoad( p_this, p_list, psz_filename );
287     p_sys->b_spu_update = true;
288     p_sys->b_mouse_grab = false;
289
290     for( int i = 0; ppsz_filter_callbacks[i]; i++ )
291         var_AddCallback( p_filter, ppsz_filter_callbacks[i],
292                          LogoCallback, p_sys );
293
294     /* Misc init */
295     if( b_sub )
296     {
297         p_filter->pf_sub_source = FilterSub;
298     }
299     else
300     {
301         p_filter->pf_video_filter = FilterVideo;
302         p_filter->pf_video_mouse = Mouse;
303     }
304
305     free( psz_filename );
306     return VLC_SUCCESS;
307 }
308
309 /**
310  * Common close function
311  */
312 static void Close( vlc_object_t *p_this )
313 {
314     filter_t *p_filter = (filter_t *)p_this;
315     filter_sys_t *p_sys = p_filter->p_sys;
316
317     for( int i = 0; ppsz_filter_callbacks[i]; i++ )
318         var_DelCallback( p_filter, ppsz_filter_callbacks[i],
319                          LogoCallback, p_sys );
320
321     if( p_sys->p_blend )
322         filter_DeleteBlend( p_sys->p_blend );
323
324     vlc_mutex_destroy( &p_sys->lock );
325     LogoListUnload( &p_sys->list );
326     free( p_sys );
327 }
328
329 /**
330  * Sub source
331  */
332 static subpicture_t *FilterSub( filter_t *p_filter, mtime_t date )
333 {
334     filter_sys_t *p_sys = p_filter->p_sys;
335     logo_list_t *p_list = &p_sys->list;
336
337     subpicture_t *p_spu;
338     subpicture_region_t *p_region;
339     video_format_t fmt;
340     picture_t *p_pic;
341     logo_t *p_logo;
342
343     vlc_mutex_lock( &p_sys->lock );
344     /* Basic test:  b_spu_update occurs on a dynamic change,
345                     & i_next_pic is the general timer, when to
346                     look at updating the logo image */
347
348     if( ( !p_sys->b_spu_update && p_list->i_next_pic > date ) ||
349         !p_list->i_repeat )
350     {
351         vlc_mutex_unlock( &p_sys->lock );
352         return NULL;
353     }
354
355     /* adjust index to the next logo */
356     p_logo = LogoListNext( p_list, date );
357     p_sys->b_spu_update = false;
358
359     p_pic = p_logo->p_pic;
360
361     /* Allocate the subpicture internal data. */
362     p_spu = filter_NewSubpicture( p_filter );
363     if( !p_spu )
364         goto exit;
365
366     p_spu->b_absolute = p_sys->b_absolute;
367     p_spu->i_start = date;
368     p_spu->i_stop = 0;
369     p_spu->b_ephemer = true;
370
371     /* Send an empty subpicture to clear the display when needed */
372     if( p_list->i_repeat != -1 && p_list->i_counter == 0 )
373     {
374         p_list->i_repeat--;
375         if( p_list->i_repeat < 0 )
376             goto exit;
377     }
378     if( !p_pic || !p_logo->i_alpha ||
379         ( p_logo->i_alpha == -1 && !p_list->i_alpha ) )
380         goto exit;
381
382     /* Create new SPU region */
383     memset( &fmt, 0, sizeof(video_format_t) );
384     fmt.i_chroma = VLC_CODEC_YUVA;
385     fmt.i_sar_num = fmt.i_sar_den = 1;
386     fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
387     fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
388     fmt.i_x_offset = fmt.i_y_offset = 0;
389     p_region = subpicture_region_New( &fmt );
390     if( !p_region )
391     {
392         msg_Err( p_filter, "cannot allocate SPU region" );
393         subpicture_Delete( p_spu );
394         p_spu = NULL;
395         goto exit;
396     }
397
398     /* */
399     picture_Copy( p_region->p_picture, p_pic );
400
401     /*  where to locate the logo: */
402     if( p_sys->i_pos < 0 )
403     {   /*  set to an absolute xy */
404         p_region->i_align = SUBPICTURE_ALIGN_RIGHT | SUBPICTURE_ALIGN_TOP;
405         p_spu->b_absolute = true;
406     }
407     else
408     {   /* set to one of the 9 relative locations */
409         p_region->i_align = p_sys->i_pos;
410         p_spu->b_absolute = false;
411     }
412
413     p_region->i_x = p_sys->i_pos_x;
414     p_region->i_y = p_sys->i_pos_y;
415
416     p_spu->p_region = p_region;
417
418     p_spu->i_alpha = ( p_logo->i_alpha != -1 ?
419                        p_logo->i_alpha : p_list->i_alpha );
420
421 exit:
422     vlc_mutex_unlock( &p_sys->lock );
423
424     return p_spu;
425 }
426
427 /**
428  * Video filter
429  */
430 static picture_t *FilterVideo( filter_t *p_filter, picture_t *p_src )
431 {
432     filter_sys_t *p_sys = p_filter->p_sys;
433     logo_list_t *p_list = &p_sys->list;
434
435     picture_t *p_dst = filter_NewPicture( p_filter );
436     if( !p_dst )
437         goto exit;
438
439     picture_Copy( p_dst, p_src );
440
441     /* */
442     vlc_mutex_lock( &p_sys->lock );
443
444     logo_t *p_logo;
445     if( p_list->i_next_pic < p_src->date )
446         p_logo = LogoListNext( p_list, p_src->date );
447     else
448         p_logo = LogoListCurrent( p_list );
449
450     /* */
451     const picture_t *p_pic = p_logo->p_pic;
452     if( p_pic )
453     {
454         const video_format_t *p_fmt = &p_pic->format;
455         const int i_dst_w = p_filter->fmt_out.video.i_visible_width;
456         const int i_dst_h = p_filter->fmt_out.video.i_visible_height;
457
458         if( p_sys->i_pos )
459         {
460             if( p_sys->i_pos & SUBPICTURE_ALIGN_BOTTOM )
461             {
462                 p_sys->i_pos_y = i_dst_h - p_fmt->i_visible_height;
463             }
464             else if ( !(p_sys->i_pos & SUBPICTURE_ALIGN_TOP) )
465             {
466                 p_sys->i_pos_y = ( i_dst_h - p_fmt->i_visible_height ) / 2;
467             }
468             else
469             {
470                 p_sys->i_pos_y = 0;
471             }
472
473             if( p_sys->i_pos & SUBPICTURE_ALIGN_RIGHT )
474             {
475                 p_sys->i_pos_x = i_dst_w - p_fmt->i_visible_width;
476             }
477             else if ( !(p_sys->i_pos & SUBPICTURE_ALIGN_LEFT) )
478             {
479                 p_sys->i_pos_x = ( i_dst_w - p_fmt->i_visible_width ) / 2;
480             }
481             else
482             {
483                 p_sys->i_pos_x = 0;
484             }
485         }
486
487         if( p_sys->i_pos_x < 0 || p_sys->i_pos_y < 0 )
488         {
489             msg_Warn( p_filter,
490                 "logo(%ix%i) doesn't fit into video(%ix%i)",
491                 p_fmt->i_visible_width, p_fmt->i_visible_height,
492                 i_dst_w,i_dst_h );
493             p_sys->i_pos_x = (p_sys->i_pos_x > 0) ? p_sys->i_pos_x : 0;
494             p_sys->i_pos_y = (p_sys->i_pos_y > 0) ? p_sys->i_pos_y : 0;
495         }
496
497         /* */
498         const int i_alpha = p_logo->i_alpha != -1 ? p_logo->i_alpha : p_list->i_alpha;
499         if( filter_ConfigureBlend( p_sys->p_blend, i_dst_w, i_dst_h, p_fmt ) ||
500             filter_Blend( p_sys->p_blend, p_dst, p_sys->i_pos_x, p_sys->i_pos_y,
501                           p_pic, i_alpha ) )
502         {
503             msg_Err( p_filter, "failed to blend a picture" );
504         }
505     }
506     vlc_mutex_unlock( &p_sys->lock );
507
508 exit:
509     picture_Release( p_src );
510     return p_dst;
511 }
512
513 static int Mouse( filter_t *p_filter, vlc_mouse_t *p_mouse,
514                   const vlc_mouse_t *p_old, const vlc_mouse_t *p_new )
515 {
516     filter_sys_t *p_sys = p_filter->p_sys;
517
518     vlc_mutex_lock( &p_sys->lock );
519     logo_t *p_logo = LogoListCurrent( &p_sys->list );
520     const picture_t *p_pic = p_logo->p_pic;
521
522     if( p_pic )
523     {
524         const video_format_t *p_fmt = &p_pic->format;
525         const int i_logo_w = p_fmt->i_visible_width;
526         const int i_logo_h = p_fmt->i_visible_height;
527
528         /* Check if we are over the logo */
529         const bool b_over = p_new->i_x >= p_sys->i_pos_x &&
530                             p_new->i_x <  p_sys->i_pos_x + i_logo_w &&
531                             p_new->i_y >= p_sys->i_pos_y &&
532                             p_new->i_y <  p_sys->i_pos_y + i_logo_h;
533
534         if( b_over && vlc_mouse_HasPressed( p_old, p_new, MOUSE_BUTTON_LEFT ) )
535             p_sys->b_mouse_grab = true;
536         else if( vlc_mouse_HasReleased( p_old, p_new, MOUSE_BUTTON_LEFT ) )
537             p_sys->b_mouse_grab = false;
538
539         if( p_sys->b_mouse_grab )
540         {
541             int i_dx, i_dy;
542             vlc_mouse_GetMotion( &i_dx, &i_dy, p_old, p_new );
543             p_sys->i_pos_x = VLC_CLIP( p_sys->i_pos_x + i_dx, 0,
544                                     p_filter->fmt_in.video.i_width  - i_logo_w );
545             p_sys->i_pos_y = VLC_CLIP( p_sys->i_pos_y + i_dy, 0,
546                                     p_filter->fmt_in.video.i_height - i_logo_h );
547
548             /* object under mouse has moved */
549             var_SetBool( p_filter->p_parent, "mouse-object", true );
550         }
551         else if( b_over )
552         {
553             /* object under mouse stoped moving */
554             var_SetBool( p_filter->p_parent, "mouse-object", false );
555         }
556
557         if( p_sys->b_mouse_grab || b_over )
558         {
559             vlc_mutex_unlock( &p_sys->lock );
560             return VLC_EGENERIC;
561         }
562     }
563     vlc_mutex_unlock( &p_sys->lock );
564
565     *p_mouse = *p_new;
566     return VLC_SUCCESS;
567 }
568
569 /*****************************************************************************
570  * Callback to update params on the fly
571  *****************************************************************************/
572 static int LogoCallback( vlc_object_t *p_this, char const *psz_var,
573                          vlc_value_t oldval, vlc_value_t newval, void *p_data )
574 {
575     VLC_UNUSED(oldval);
576     filter_sys_t *p_sys = (filter_sys_t *)p_data;
577     logo_list_t *p_list = &p_sys->list;
578
579     vlc_mutex_lock( &p_sys->lock );
580     if( !strcmp( psz_var, "logo-file" ) )
581     {
582         LogoListUnload( p_list );
583         LogoListLoad( p_this, p_list, newval.psz_string );
584     }
585     else if ( !strcmp( psz_var, "logo-x" ) )
586     {
587         p_sys->i_pos_x = newval.i_int;
588     }
589     else if ( !strcmp( psz_var, "logo-y" ) )
590     {
591         p_sys->i_pos_y = newval.i_int;
592     }
593     else if ( !strcmp( psz_var, "logo-position" ) )
594     {
595         p_sys->i_pos = newval.i_int;
596     }
597     else if ( !strcmp( psz_var, "logo-opacity" ) )
598     {
599         p_list->i_alpha = VLC_CLIP( newval.i_int, 0, 255 );
600     }
601     else if ( !strcmp( psz_var, "logo-repeat" ) )
602     {
603         p_list->i_repeat = newval.i_int;
604     }
605     p_sys->b_spu_update = true;
606     vlc_mutex_unlock( &p_sys->lock );
607
608     return VLC_SUCCESS;
609 }
610
611 /**
612  * It loads the logo image into memory.
613  */
614 static picture_t *LoadImage( vlc_object_t *p_this, const char *psz_filename )
615 {
616     if( !psz_filename )
617         return NULL;
618
619     video_format_t fmt_in;
620     video_format_Init( &fmt_in, 0 );
621
622     video_format_t fmt_out;
623     video_format_Init( &fmt_out, VLC_CODEC_YUVA );
624
625     image_handler_t *p_image = image_HandlerCreate( p_this );
626     if( !p_image )
627         return NULL;
628
629     char *psz_url = vlc_path2uri( psz_filename, NULL );
630     picture_t *p_pic = image_ReadUrl( p_image, psz_url, &fmt_in, &fmt_out );
631     free( psz_url );
632     image_HandlerDelete( p_image );
633
634     return p_pic;
635 }
636
637 /**
638  * It loads the logo images into memory.
639  *
640  * Read the logo-file input switch, obtaining a list of images and
641  * associated durations and transparencies. Store the image(s), and
642  * times. An image without a stated time or opacity will use the
643  * logo-delay and logo-opacity values.
644  */
645 static void LogoListLoad( vlc_object_t *p_this, logo_list_t *p_logo_list,
646                           const char *psz_filename )
647 {
648     char *psz_list; /* the list: <logo>[,[<delay>[,[<alpha>]]]][;...] */
649     char *psz_original;
650     unsigned int i;
651     logo_t *p_logo;         /* the parsing's result */
652
653     p_logo_list->i_counter = 0;
654     p_logo_list->i_next_pic = 0;
655
656     psz_original = psz_list = strdup( psz_filename );
657     if( !psz_list )
658         abort();
659
660     /* Count the number logos == number of ';' + 1 */
661     p_logo_list->i_count = 1;
662     for( i = 0; i < strlen( psz_list ); i++ )
663     {
664         if( psz_list[i] == ';' )
665             p_logo_list->i_count++;
666     }
667
668     p_logo_list->p_logo =
669     p_logo              = calloc( p_logo_list->i_count, sizeof(*p_logo) );
670     if( !p_logo )
671         abort();
672
673     /* Fill the data */
674     for( i = 0; i < p_logo_list->i_count; i++ )
675     {
676         char *p_c  = strchr( psz_list, ';' );
677         char *p_c2 = strchr( psz_list, ',' );
678
679         p_logo[i].i_alpha = -1; /* use default settings */
680         p_logo[i].i_delay = -1; /* use default settings */
681
682         if( p_c2 && ( p_c2 < p_c || !p_c ) )
683         {
684             /* <logo>,<delay>[,<alpha>] type */
685             if( p_c2[1] != ',' && p_c2[1] != ';' && p_c2[1] != '\0' )
686                 p_logo[i].i_delay = atoi( p_c2+1 );
687             *p_c2 = '\0';
688             if( ( p_c2 = strchr( p_c2+1, ',' ) )
689                 && ( p_c2 < p_c || !p_c ) && p_c2[1] != ';' && p_c2[1] != '\0' )
690                 p_logo[i].i_alpha = atoi( p_c2 + 1 );
691         }
692         else
693         {
694             /* <logo> type */
695             if( p_c )
696                 *p_c = '\0';
697         }
698
699         msg_Dbg( p_this, "logo file name %s, delay %d, alpha %d",
700                  psz_list, p_logo[i].i_delay, p_logo[i].i_alpha );
701         p_logo[i].p_pic = LoadImage( p_this, psz_list );
702         if( !p_logo[i].p_pic )
703         {
704             msg_Warn( p_this, "error while loading logo %s, will be skipped",
705                       psz_list );
706         }
707
708         if( p_c )
709             psz_list = &p_c[1];
710     }
711
712     /* initialize so that on the first update it will wrap back to 0 */
713     p_logo_list->i_counter = p_logo_list->i_count - 1;
714
715     free( psz_original );
716 }
717
718 /**
719  * Unload a list of logo and release associated ressources.
720  */
721 static void LogoListUnload( logo_list_t *p_list )
722 {
723     for( unsigned i = 0; i < p_list->i_count; i++ )
724     {
725         logo_t *p_logo = &p_list->p_logo[i];
726
727         if( p_logo->p_pic )
728             picture_Release( p_logo->p_pic );
729     }
730     free( p_list->p_logo );
731 }
732
733 /**
734  * Go to the next logo and return its pointer.
735  */
736 static logo_t *LogoListNext( logo_list_t *p_list, mtime_t i_date )
737 {
738     p_list->i_counter = ( p_list->i_counter + 1 ) % p_list->i_count;
739
740     logo_t *p_logo = LogoListCurrent( p_list );
741
742     p_list->i_next_pic = i_date + ( p_logo->i_delay != -1 ?
743                           p_logo->i_delay : p_list->i_delay ) * 1000;
744     return p_logo;
745 }
746 /**
747  * Return the current logo pointer
748  */
749 static logo_t *LogoListCurrent( logo_list_t *p_list )
750 {
751     return &p_list->p_logo[p_list->i_counter];
752 }
753