]> git.sesse.net Git - vlc/blob - src/playlist/engine.c
Preparse playlist items that don't have enough meta
[vlc] / src / playlist / engine.c
1 /*****************************************************************************
2  * engine.c : Run the playlist and handle its control
3  *****************************************************************************
4  * Copyright (C) 1999-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *          ClĂ©ment Stenac <zorglub@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 #include <vlc/vlc.h>
26 #include <vlc/vout.h>
27 #include <vlc/sout.h>
28 #include <vlc/input.h>
29 #include "vlc_playlist.h"
30 #include "vlc_interaction.h"
31 #include "playlist_internal.h"
32
33 /*****************************************************************************
34  * Local prototypes
35  *****************************************************************************/
36 static void VariablesInit( playlist_t *p_playlist );
37
38 static int RandomCallback( vlc_object_t *p_this, char const *psz_cmd,
39                            vlc_value_t oldval, vlc_value_t newval, void *a )
40 {
41     ((playlist_t*)p_this)->b_reset_currently_playing = VLC_TRUE;
42     playlist_Signal( ((playlist_t*)p_this) );
43     return VLC_SUCCESS;
44 }
45
46 /**
47  * Create playlist
48  *
49  * Create a playlist structure.
50  * \param p_parent the vlc object that is to be the parent of this playlist
51  * \return a pointer to the created playlist, or NULL on error
52  */
53 playlist_t * playlist_Create( vlc_object_t *p_parent )
54 {
55     playlist_t *p_playlist;
56     vlc_bool_t b_save;
57     int i_tree;
58
59     /* Allocate structure */
60     p_playlist = vlc_object_create( p_parent, VLC_OBJECT_PLAYLIST );
61     if( !p_playlist )
62     {
63         msg_Err( p_parent, "out of memory" );
64         return NULL;
65     }
66     p_parent->p_libvlc->p_playlist = p_playlist;
67
68     VariablesInit( p_playlist );
69
70     /* Initialise data structures */
71     vlc_mutex_init( p_playlist, &p_playlist->gc_lock );
72     p_playlist->i_last_playlist_id = 0;
73     p_playlist->i_last_input_id = 0;
74     p_playlist->p_input = NULL;
75
76     p_playlist->gc_date = 0;
77     p_playlist->b_cant_sleep = VLC_FALSE;
78
79     ARRAY_INIT( p_playlist->items );
80     ARRAY_INIT( p_playlist->all_items );
81     ARRAY_INIT( p_playlist->input_items );
82     ARRAY_INIT( p_playlist->current );
83
84     p_playlist->i_current_index = 0;
85     p_playlist->b_reset_currently_playing = VLC_TRUE;
86     p_playlist->last_rebuild_date = 0;
87
88     i_tree = var_CreateGetBool( p_playlist, "playlist-tree" );
89     p_playlist->b_always_tree = (i_tree == 1);
90     p_playlist->b_never_tree = (i_tree == 2);
91
92     p_playlist->b_doing_ml = VLC_FALSE;
93
94     p_playlist->b_auto_preparse =
95                         var_CreateGetBool( p_playlist, "auto-preparse") ;
96
97     p_playlist->p_root_category = playlist_NodeCreate( p_playlist, NULL, NULL);
98     p_playlist->p_root_onelevel = playlist_NodeCreate( p_playlist, NULL, NULL);
99
100     /* Create playlist and media library */
101     p_playlist->p_local_category = playlist_NodeCreate( p_playlist,
102                                  _( "Playlist" ),p_playlist->p_root_category );
103     p_playlist->p_local_onelevel =  playlist_NodeCreate( p_playlist,
104                                 _( "Playlist" ), p_playlist->p_root_onelevel );
105     p_playlist->p_local_category->i_flags |= PLAYLIST_RO_FLAG;
106     p_playlist->p_local_onelevel->i_flags |= PLAYLIST_RO_FLAG;
107
108     /* Link the nodes together. Todo: actually create them from the same input*/
109     p_playlist->p_local_onelevel->p_input->i_id =
110         p_playlist->p_local_category->p_input->i_id;
111
112     if( config_GetInt( p_playlist, "media-library") )
113     {
114         p_playlist->p_ml_category =   playlist_NodeCreate( p_playlist,
115                            _( "Media Library" ), p_playlist->p_root_category );
116         p_playlist->p_ml_onelevel =  playlist_NodeCreate( p_playlist,
117                            _( "Media Library" ), p_playlist->p_root_onelevel );
118         p_playlist->p_ml_category->i_flags |= PLAYLIST_RO_FLAG;
119         p_playlist->p_ml_onelevel->i_flags |= PLAYLIST_RO_FLAG;
120         p_playlist->p_ml_onelevel->p_input->i_id =
121              p_playlist->p_ml_category->p_input->i_id;
122
123     }
124     else
125     {
126         p_playlist->p_ml_category = p_playlist->p_ml_onelevel = NULL;
127     }
128
129     /* Initial status */
130     p_playlist->status.p_item = NULL;
131     p_playlist->status.p_node = p_playlist->p_local_onelevel;
132     p_playlist->request.b_request = VLC_FALSE;
133     p_playlist->status.i_status = PLAYLIST_STOPPED;
134
135     p_playlist->i_sort = SORT_ID;
136     p_playlist->i_order = ORDER_NORMAL;
137
138     vlc_object_attach( p_playlist, p_parent );
139     b_save = p_playlist->b_auto_preparse;
140     p_playlist->b_auto_preparse = VLC_FALSE;
141     playlist_MLLoad( p_playlist );
142     p_playlist->b_auto_preparse = VLC_TRUE;
143     return p_playlist;
144 }
145
146 void playlist_Destroy( playlist_t *p_playlist )
147 {
148     while( p_playlist->i_sds )
149     {
150         playlist_ServicesDiscoveryRemove( p_playlist,
151                                           p_playlist->pp_sds[0]->psz_module );
152     }
153
154     playlist_MLDump( p_playlist );
155
156     vlc_thread_join( p_playlist->p_preparse );
157     vlc_thread_join( p_playlist->p_fetcher );
158     vlc_thread_join( p_playlist );
159
160     vlc_object_detach( p_playlist->p_preparse );
161     vlc_object_detach( p_playlist->p_fetcher );
162
163     var_Destroy( p_playlist, "intf-change" );
164     var_Destroy( p_playlist, "item-change" );
165     var_Destroy( p_playlist, "playlist-current" );
166     var_Destroy( p_playlist, "intf-popmenu" );
167     var_Destroy( p_playlist, "intf-show" );
168     var_Destroy( p_playlist, "play-and-stop" );
169     var_Destroy( p_playlist, "play-and-exit" );
170     var_Destroy( p_playlist, "random" );
171     var_Destroy( p_playlist, "repeat" );
172     var_Destroy( p_playlist, "loop" );
173     var_Destroy( p_playlist, "activity" );
174
175     PL_LOCK;
176     /* Go through all items, and simply free everything without caring
177      * about the tree structure. Do not decref, it will be done by doing
178      * the same thing on the input items array */
179     FOREACH_ARRAY( playlist_item_t *p_del, p_playlist->all_items )
180         free( p_del->pp_children );
181         free( p_del );
182     FOREACH_END();
183     ARRAY_RESET( p_playlist->all_items );
184
185     FOREACH_ARRAY( input_item_t *p_del, p_playlist->input_items )
186         input_ItemClean( p_del );
187         free( p_del );
188     FOREACH_END();
189     ARRAY_RESET( p_playlist->input_items );
190
191     ARRAY_RESET( p_playlist->items );
192     ARRAY_RESET( p_playlist->current );
193
194     PL_UNLOCK;
195
196     if( p_playlist->p_stats )
197         free( p_playlist->p_stats );
198
199     vlc_mutex_destroy( &p_playlist->gc_lock );
200     vlc_object_destroy( p_playlist->p_preparse );
201     vlc_object_destroy( p_playlist->p_fetcher );
202     vlc_object_detach( p_playlist );
203     vlc_object_destroy( p_playlist );
204
205 }
206
207 /* Destroy remaining objects */
208 static void ObjectGarbageCollector( playlist_t *p_playlist )
209 {
210     vlc_object_t *p_obj;
211
212     if( mdate() - p_playlist->gc_date < 1000000 )
213     {
214         p_playlist->b_cant_sleep = VLC_TRUE;
215         return;
216     }
217     else if( p_playlist->gc_date == 0 )
218         return;
219
220     vlc_mutex_lock( &p_playlist->gc_lock );
221     while( ( p_obj = vlc_object_find( p_playlist, VLC_OBJECT_VOUT,
222                                                   FIND_CHILD ) ) )
223     {
224         if( p_obj->p_parent != (vlc_object_t*)p_playlist )
225         {
226             vlc_object_release( p_obj );
227             break;
228         }
229         msg_Dbg( p_playlist, "garbage collector destroying 1 vout" );
230         vlc_object_detach( p_obj );
231         vlc_object_release( p_obj );
232         vout_Destroy( (vout_thread_t *)p_obj );
233     }
234     while( ( p_obj = vlc_object_find( p_playlist, VLC_OBJECT_SOUT,
235                                                   FIND_CHILD ) ) )
236     {
237         if( p_obj->p_parent != (vlc_object_t*)p_playlist )
238         {
239             vlc_object_release( p_obj );
240             break;
241         }
242         vlc_object_release( p_obj );
243         sout_DeleteInstance( (sout_instance_t*)p_obj );
244     }
245     p_playlist->b_cant_sleep = VLC_FALSE;
246     vlc_mutex_unlock( &p_playlist->gc_lock );
247 }
248
249 /** Main loop for the playlist */
250 void playlist_MainLoop( playlist_t *p_playlist )
251 {
252     playlist_item_t *p_item = NULL;
253     vlc_bool_t b_playexit = var_GetBool( p_playlist, "play-and-exit" );
254     PL_LOCK;
255
256     if( p_playlist->b_reset_currently_playing &&
257         mdate() - p_playlist->last_rebuild_date > 30000 ) // 30 ms
258     {
259         ResetCurrentlyPlaying( p_playlist, var_GetBool( p_playlist, "random"),
260                              p_playlist->status.p_item );
261         p_playlist->last_rebuild_date = mdate();
262     }
263
264 check_input:
265     /* If there is an input, check that it doesn't need to die. */
266     if( p_playlist->p_input )
267     {
268         if( p_playlist->request.b_request && !p_playlist->p_input->b_die )
269         {
270             PL_DEBUG( "incoming request - stopping current input" );
271             input_StopThread( p_playlist->p_input );
272         }
273
274         /* This input is dead. Remove it ! */
275         if( p_playlist->p_input->b_dead )
276         {
277             int i_activity;
278             input_thread_t *p_input;
279             PL_DEBUG( "dead input" );
280
281             p_input = p_playlist->p_input;
282             p_playlist->p_input = NULL;
283
284             /* Release the playlist lock, because we may get stuck
285              * in input_DestroyThread() for some time. */
286             PL_UNLOCK
287
288             /* Destroy input */
289             input_DestroyThread( p_input );
290
291             /* Unlink current input
292              * (_after_ input_DestroyThread for vout garbage collector) */
293             vlc_object_detach( p_input );
294
295             /* Destroy object */
296             vlc_object_destroy( p_input );
297
298             PL_LOCK;
299
300             p_playlist->gc_date = mdate();
301             p_playlist->b_cant_sleep = VLC_TRUE;
302
303             if( p_playlist->status.p_item->i_flags
304                 & PLAYLIST_REMOVE_FLAG )
305             {
306                  PL_DEBUG( "%s was marked for deletion, deleting",
307                                  PLI_NAME( p_playlist->status.p_item  ) );
308                  playlist_ItemDelete( p_playlist->status.p_item );
309                  if( p_playlist->request.p_item == p_playlist->status.p_item )
310                      p_playlist->request.p_item = NULL;
311                  p_playlist->status.p_item = NULL;
312             }
313
314             i_activity= var_GetInteger( p_playlist, "activity") ;
315             var_SetInteger( p_playlist, "activity", i_activity -
316                             DEFAULT_INPUT_ACTIVITY );
317             goto check_input;
318         }
319         /* This input is dying, let it do */
320         else if( p_playlist->p_input->b_die )
321         {
322             PL_DEBUG( "dying input" );
323             msleep( 25000 ); // 25 ms
324             goto check_input;
325         }
326         /* This input has finished, ask it to die ! */
327         else if( p_playlist->p_input->b_error
328                   || p_playlist->p_input->b_eof )
329         {
330             PL_DEBUG( "finished input" );
331             input_StopThread( p_playlist->p_input );
332             /* No need to wait here, we'll wait in the p_input->b_die case */
333             goto check_input;
334         }
335         else if( p_playlist->p_input->i_state != INIT_S )
336         {
337             PL_UNLOCK;
338             ObjectGarbageCollector( p_playlist );
339             PL_LOCK;
340         }
341     }
342     else
343     {
344         /* No input. Several cases
345          *  - No request, running status -> start new item
346          *  - No request, stopped status -> collect garbage
347          *  - Request, running requested -> start new item
348          *  - Request, stopped requested -> collect garbage
349          */
350          if( (!p_playlist->request.b_request &&
351               p_playlist->status.i_status != PLAYLIST_STOPPED) ||
352               ( p_playlist->request.b_request &&
353                 p_playlist->request.i_status != PLAYLIST_STOPPED ) )
354          {
355              msg_Dbg( p_playlist, "starting new item" );
356              p_item = playlist_NextItem( p_playlist );
357
358              if( p_item == NULL )
359              {
360                 msg_Dbg( p_playlist, "nothing to play" );
361                 if( b_playexit == VLC_TRUE )
362                 {
363                     msg_Info( p_playlist, "end of playlist, exiting" );
364                     p_playlist->p_libvlc->b_die = VLC_TRUE;
365                 }
366                 p_playlist->status.i_status = PLAYLIST_STOPPED;
367                 PL_UNLOCK
368                 return;
369              }
370              playlist_PlayItem( p_playlist, p_item );
371          }
372          else
373          {
374             p_playlist->status.i_status = PLAYLIST_STOPPED;
375             if( p_playlist->status.p_item &&
376                 p_playlist->status.p_item->i_flags & PLAYLIST_REMOVE_FLAG )
377             {
378                 PL_DEBUG( "deleting item marked for deletion" );
379                 playlist_ItemDelete( p_playlist->status.p_item );
380                 p_playlist->status.p_item = NULL;
381             }
382
383             /* Collect garbage */
384             PL_UNLOCK;
385             ObjectGarbageCollector( p_playlist );
386             PL_LOCK;
387         }
388     }
389     PL_UNLOCK
390 }
391
392 /** Playlist dying last loop */
393 void playlist_LastLoop( playlist_t *p_playlist )
394 {
395     vlc_object_t *p_obj;
396
397     /* If there is an input, kill it */
398     while( 1 )
399     {
400         PL_LOCK
401
402         if( p_playlist->p_input == NULL )
403         {
404             PL_UNLOCK
405             break;
406         }
407
408         if( p_playlist->p_input->b_dead )
409         {
410             input_thread_t *p_input;
411
412             /* Unlink current input */
413             p_input = p_playlist->p_input;
414             p_playlist->p_input = NULL;
415             PL_UNLOCK
416
417             /* Destroy input */
418             input_DestroyThread( p_input );
419             /* Unlink current input (_after_ input_DestroyThread for vout
420              * garbage collector)*/
421             vlc_object_detach( p_input );
422
423             /* Destroy object */
424             vlc_object_destroy( p_input );
425             continue;
426         }
427         else if( p_playlist->p_input->b_die )
428         {
429             /* This input is dying, leave it alone */
430             ;
431         }
432         else if( p_playlist->p_input->b_error || p_playlist->p_input->b_eof )
433         {
434             input_StopThread( p_playlist->p_input );
435             PL_UNLOCK
436             continue;
437         }
438         else
439         {
440             p_playlist->p_input->b_eof = 1;
441         }
442
443         PL_UNLOCK
444
445         msleep( INTF_IDLE_SLEEP );
446     }
447
448     /* close all remaining sout */
449     while( ( p_obj = vlc_object_find( p_playlist,
450                                       VLC_OBJECT_SOUT, FIND_CHILD ) ) )
451     {
452         vlc_object_release( p_obj );
453         sout_DeleteInstance( (sout_instance_t*)p_obj );
454     }
455
456     /* close all remaining vout */
457     while( ( p_obj = vlc_object_find( p_playlist,
458                                       VLC_OBJECT_VOUT, FIND_CHILD ) ) )
459     {
460         vlc_object_detach( p_obj );
461         vlc_object_release( p_obj );
462         vout_Destroy( (vout_thread_t *)p_obj );
463     }
464 }
465
466 /** Main loop for preparser queue */
467 void playlist_PreparseLoop( playlist_preparse_t *p_obj )
468 {
469     playlist_t *p_playlist = (playlist_t *)p_obj->p_parent;
470     input_item_t *p_current;
471     int i_activity;
472     uint32_t i_m, i_o;
473
474     while( !p_playlist->b_die )
475     {
476         vlc_mutex_lock( &p_obj->object_lock );
477         while( p_obj->i_waiting == 0 )
478         {
479             vlc_cond_wait( &p_obj->object_wait, &p_obj->object_lock );
480             if( p_playlist->b_die )
481             {
482                 vlc_mutex_unlock( &p_obj->object_lock );
483                 return;
484             }
485         }
486
487         p_current = p_obj->pp_waiting[0];
488         REMOVE_ELEM( p_obj->pp_waiting, p_obj->i_waiting, 0 );
489         vlc_mutex_unlock( &p_obj->object_lock );
490
491         PL_LOCK;
492         if( p_current )
493         {
494             vlc_bool_t b_preparsed = VLC_FALSE;
495             if( strncmp( p_current->psz_uri, "http:", 5 ) &&
496                 strncmp( p_current->psz_uri, "rtsp:", 5 ) &&
497                 strncmp( p_current->psz_uri, "udp:", 4 ) &&
498                 strncmp( p_current->psz_uri, "mms:", 4 ) &&
499                 strncmp( p_current->psz_uri, "cdda:", 4 ) &&
500                 strncmp( p_current->psz_uri, "dvd:", 4 ) &&
501                 strncmp( p_current->psz_uri, "v4l:", 4 ) &&
502                 strncmp( p_current->psz_uri, "dshow:", 6 ) )
503             {
504                 b_preparsed = VLC_TRUE;
505                 stats_TimerStart( p_playlist, "Preparse run",
506                                   STATS_TIMER_PREPARSE );
507                 PL_UNLOCK;
508                 input_Preparse( p_playlist, p_current );
509                 PL_LOCK;
510                 stats_TimerStop( p_playlist, STATS_TIMER_PREPARSE );
511             }
512             PL_UNLOCK;
513             if( b_preparsed )
514             {
515                 p_current->p_meta->i_status |= ITEM_PREPARSED;
516                 var_SetInteger( p_playlist, "item-change", p_current->i_id );
517             }
518             PL_LOCK;
519
520             /* If we haven't retrieved enough meta, add to secondary queue
521              * which will run the "meta fetchers".
522              * This only checks for meta, not for art
523              * \todo don't do this for things we won't get meta for, like vids
524              */
525             if( !input_MetaSatisfied( p_playlist, p_current, &i_m, &i_o ) )
526             {
527                 preparse_item_t p;
528                 PL_DEBUG("need to fetch meta for %s", p_current->psz_name );
529                 p.p_item = p_current;
530                 p.b_fetch_art = VLC_FALSE;
531                 vlc_mutex_lock( &p_playlist->p_fetcher->object_lock );
532                 INSERT_ELEM( p_playlist->p_fetcher->p_waiting,
533                              p_playlist->p_fetcher->i_waiting,
534                              p_playlist->p_fetcher->i_waiting,
535                              p );
536                 vlc_mutex_unlock( &p_playlist->p_fetcher->object_lock );
537                 vlc_cond_signal( &p_playlist->p_fetcher->object_wait );
538             }
539             /* We already have all needed meta, but we need art right now */
540             else if( p_playlist->p_fetcher->i_art_policy == ALBUM_ART_ALL &&
541                      EMPTY_STR( p_current->p_meta->psz_arturl ) )
542             {
543                 preparse_item_t p;
544                 PL_DEBUG("meta ok for %s, need to fetch art",
545                                                          p_current->psz_name );
546                 p.p_item = p_current;
547                 p.b_fetch_art = VLC_TRUE;
548                 vlc_mutex_lock( &p_playlist->p_fetcher->object_lock );
549                 INSERT_ELEM( p_playlist->p_fetcher->p_waiting,
550                              p_playlist->p_fetcher->i_waiting,
551                              p_playlist->p_fetcher->i_waiting,
552                              p );
553                 vlc_mutex_unlock( &p_playlist->p_fetcher->object_lock );
554                 vlc_cond_signal( &p_playlist->p_fetcher->object_wait );
555             }
556             else
557             {
558                 PL_DEBUG( "no fetch required for %s (art currently %s)",
559                           p_current->psz_name, p_current->p_meta->psz_arturl );
560                 vlc_gc_decref( p_current );
561             }
562             PL_UNLOCK;
563         }
564         else
565             PL_UNLOCK;
566
567         vlc_mutex_lock( &p_obj->object_lock );
568         i_activity = var_GetInteger( p_playlist, "activity" );
569         if( i_activity < 0 ) i_activity = 0;
570         vlc_mutex_unlock( &p_obj->object_lock );
571         /* Sleep at least 1ms */
572         msleep( (i_activity+1) * 1000 );
573     }
574 }
575
576 /** Main loop for secondary preparser queue */
577 void playlist_FetcherLoop( playlist_fetcher_t *p_obj )
578 {
579     playlist_t *p_playlist = (playlist_t *)p_obj->p_parent;
580     vlc_bool_t b_fetch_art;
581     input_item_t *p_item;
582     int i_activity;
583
584     while( !p_playlist->b_die )
585     {
586         vlc_mutex_lock( &p_obj->object_lock );
587         while( p_obj->i_waiting == 0 )
588         {
589             vlc_cond_wait( &p_obj->object_wait, &p_obj->object_lock );
590             if( p_playlist->b_die )
591             {
592                 vlc_mutex_unlock( &p_obj->object_lock );
593                 return;
594             }
595         }
596
597         b_fetch_art = p_obj->p_waiting->b_fetch_art;
598         p_item = p_obj->p_waiting->p_item;
599         REMOVE_ELEM( p_obj->p_waiting, p_obj->i_waiting, 0 );
600         vlc_mutex_unlock( &p_obj->object_lock );
601         if( p_item )
602         {
603             if( !b_fetch_art )
604             {
605                 input_MetaFetch( p_playlist, p_item );
606                 p_item->p_meta->i_status |= ITEM_META_FETCHED;
607                 var_SetInteger( p_playlist, "item-change", p_item->i_id );
608                 /*  Fetch right now */
609                 if( p_playlist->p_fetcher->i_art_policy == ALBUM_ART_ALL )
610                 {
611                     vlc_mutex_lock( &p_obj->object_lock );
612                     preparse_item_t p;
613                     p.p_item = p_item;
614                     p.b_fetch_art = VLC_TRUE;
615                     INSERT_ELEM( p_playlist->p_fetcher->p_waiting,
616                                  p_playlist->p_fetcher->i_waiting,
617                                  0, p );
618                     PL_DEBUG("meta fetched for %s, get art", p_item->psz_name);
619                     vlc_mutex_unlock( &p_obj->object_lock );
620                     continue;
621                 }
622                 else
623                     vlc_gc_decref( p_item );
624             }
625             else
626             {
627                 int i_ret = input_ArtFind( p_playlist, p_item );
628                 if( i_ret == 1 )
629                 {
630                     PL_DEBUG("downloading art for %s", p_item->psz_name );
631                     if( !input_DownloadAndCacheArt( p_playlist, p_item ) )
632                         p_item->p_meta->i_status |= ITEM_ART_NOTFOUND;
633                     else
634                         p_item->p_meta->i_status |= ITEM_ART_FETCHED;
635                 }
636                 else if( i_ret == 0 ) /* Was in cache */
637                 {
638                     PL_DEBUG("found art for %s in cache", p_item->psz_name );
639                     p_item->p_meta->i_status |= ITEM_ART_FETCHED;
640                 }
641                 else
642                 {
643                     PL_DEBUG("art not found for %s", p_item->psz_name );
644                     p_item->p_meta->i_status |= ITEM_ART_NOTFOUND;
645                 }
646                 vlc_gc_decref( p_item );
647            }
648         }
649         vlc_mutex_lock( &p_obj->object_lock );
650         i_activity = var_GetInteger( p_playlist, "activity" );
651         if( i_activity < 0 ) i_activity = 0;
652         vlc_mutex_unlock( &p_obj->object_lock );
653         /* Sleep at least 1ms */
654         msleep( (i_activity+1) * 1000 );
655     }
656 }
657
658 static void VariablesInit( playlist_t *p_playlist )
659 {
660     vlc_value_t val;
661     /* These variables control updates */
662     var_Create( p_playlist, "intf-change", VLC_VAR_BOOL );
663     val.b_bool = VLC_TRUE;
664     var_Set( p_playlist, "intf-change", val );
665
666     var_Create( p_playlist, "item-change", VLC_VAR_INTEGER );
667     val.i_int = -1;
668     var_Set( p_playlist, "item-change", val );
669
670     var_Create( p_playlist, "item-deleted", VLC_VAR_INTEGER );
671     val.i_int = -1;
672     var_Set( p_playlist, "item-deleted", val );
673
674     var_Create( p_playlist, "item-append", VLC_VAR_ADDRESS );
675
676     var_Create( p_playlist, "playlist-current", VLC_VAR_INTEGER );
677     val.i_int = -1;
678     var_Set( p_playlist, "playlist-current", val );
679
680     var_Create( p_playlist, "intf-popupmenu", VLC_VAR_BOOL );
681
682     var_Create( p_playlist, "intf-show", VLC_VAR_BOOL );
683     val.b_bool = VLC_TRUE;
684     var_Set( p_playlist, "intf-show", val );
685
686     var_Create( p_playlist, "activity", VLC_VAR_INTEGER );
687     var_SetInteger( p_playlist, "activity", 0 );
688
689     /* Variables to control playback */
690     var_CreateGetBool( p_playlist, "play-and-stop" );
691     var_CreateGetBool( p_playlist, "play-and-exit" );
692     var_CreateGetBool( p_playlist, "random" );
693     var_CreateGetBool( p_playlist, "repeat" );
694     var_CreateGetBool( p_playlist, "loop" );
695
696     var_AddCallback( p_playlist, "random", RandomCallback, NULL );
697 }