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