]> git.sesse.net Git - vlc/blob - src/playlist/item.c
Auto load and save media library (Closes:#433)
[vlc] / src / playlist / item.c
1 /*****************************************************************************
2  * item.c : Playlist item creation/deletion/add/removal functions
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 #include <vlc/vlc.h>
25 #include <vlc/input.h>
26 #include <assert.h>
27 #include "vlc_playlist.h"
28
29 void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
30               playlist_item_t *p_node, int i_pos );
31 void GoAndPreparse( playlist_t *p_playlist, int i_mode,
32                     playlist_item_t *, playlist_item_t * );
33 void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item );
34 int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
35                           vlc_bool_t b_stop );
36
37 /*****************************************************************************
38  * Playlist item creation
39  *****************************************************************************/
40 playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj,
41                                             const char *psz_uri,
42                                             const char *psz_name,
43                                             int i_options,
44                                             const char **ppsz_options,
45                                             int i_duration, int i_type )
46 {
47     input_item_t *p_input;
48     if( psz_uri == NULL ) return NULL;
49     p_input = input_ItemNewWithType( p_obj, psz_uri,
50                                      psz_name, i_options, ppsz_options,
51                                      i_duration, i_type );
52     return playlist_ItemNewFromInput( p_obj, p_input );
53 }
54
55 playlist_item_t *__playlist_ItemNewFromInput( vlc_object_t *p_obj,
56                                               input_item_t *p_input )
57 {
58     /** FIXME !!!!! don't find playlist each time */
59     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_obj, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
60     DECMALLOC_NULL( p_item, playlist_item_t );
61
62     p_item->p_input = p_input;
63     vlc_gc_incref( p_item->p_input );
64
65     p_item->i_id = ++p_playlist->i_last_playlist_id;
66
67     p_item->p_parent = NULL;
68     p_item->i_children = -1;
69     p_item->pp_children = NULL;
70     p_item->i_flags = 0;
71
72     vlc_object_release( p_playlist );
73
74     return p_item;
75 }
76
77 /***************************************************************************
78  * Playlist item destruction
79  ***************************************************************************/
80
81 /** Delete a playlist item and detach its input item */
82 int playlist_ItemDelete( playlist_item_t *p_item )
83 {
84     vlc_gc_decref( p_item->p_input );
85     free( p_item );
86     return VLC_SUCCESS;
87 }
88
89 /** Remove an input item from ONELEVEL and CATEGORY */
90 int playlist_DeleteAllFromInput( playlist_t *p_playlist, int i_input_id )
91 {
92     playlist_DeleteFromInput( p_playlist, i_input_id,
93                               p_playlist->p_root_category, VLC_TRUE );
94     playlist_DeleteFromInput( p_playlist, i_input_id,
95                               p_playlist->p_root_onelevel, VLC_TRUE );
96     return VLC_SUCCESS;
97 }
98
99 /** Remove an input item from ONELEVEL and CATEGORY.
100  * This function must be entered without the playlist lock */
101 int playlist_LockDeleteAllFromInput( playlist_t * p_playlist, int i_id )
102 {
103     int i_ret;
104     vlc_mutex_lock( &p_playlist->object_lock );
105     i_ret = playlist_DeleteAllFromInput( p_playlist, i_id );
106     vlc_mutex_unlock( &p_playlist->object_lock );
107     return i_ret;
108 }
109
110 /** Remove an input item when it appears from a root playlist item */
111 int playlist_DeleteFromInput( playlist_t *p_playlist, int i_input_id,
112                               playlist_item_t *p_root, vlc_bool_t b_do_stop )
113 {
114     int i;
115     for( i = 0 ; i< p_root->i_children ; i++ )
116     {
117         if( p_root->pp_children[i]->i_children == -1 &&
118             p_root->pp_children[i]->p_input->i_id == i_input_id )
119         {
120             DeleteInner( p_playlist, p_root->pp_children[i], b_do_stop );
121             return VLC_SUCCESS;
122         }
123         else if( p_root->pp_children[i]->i_children >= 0 )
124         {
125             int i_ret = playlist_DeleteFromInput( p_playlist, i_input_id,
126                                         p_root->pp_children[i], b_do_stop );
127             if( i_ret == VLC_SUCCESS ) return VLC_SUCCESS;
128         }
129     }
130     return VLC_EGENERIC;
131 }
132
133 /** Remove a playlist item from the playlist, given its id */
134 int playlist_DeleteFromItemId( playlist_t *p_playlist, int i_id )
135 {
136     playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
137     if( !p_item ) return VLC_EGENERIC;
138     return DeleteInner( p_playlist, p_item, VLC_TRUE );
139 }
140
141 /** Remove a playlist item from the playlist, given its id
142  * This function should be entered without the playlist lock */
143 int playlist_LockDelete( playlist_t * p_playlist, int i_id )
144 {
145     int i_ret;
146     vlc_mutex_lock( &p_playlist->object_lock );
147     i_ret = playlist_DeleteFromItemId( p_playlist, i_id );
148     vlc_mutex_unlock( &p_playlist->object_lock );
149     return i_ret;
150 }
151
152 /** Clear the playlist */
153 void playlist_Clear( playlist_t * p_playlist )
154 {
155     playlist_NodeEmpty( p_playlist, p_playlist->p_root_category, VLC_TRUE );
156     playlist_NodeEmpty( p_playlist, p_playlist->p_root_onelevel, VLC_TRUE );
157 }
158 /** Clear the playlist. This function must be entered without the lock */
159 void playlist_LockClear( playlist_t *p_playlist )
160 {
161     vlc_mutex_lock( &p_playlist->object_lock );
162     playlist_Clear( p_playlist );
163     vlc_mutex_unlock( &p_playlist->object_lock );
164 }
165
166 /***************************************************************************
167  * Playlist item addition
168  ***************************************************************************/
169 /** Add an item to the playlist or the media library
170  * \param p_playlist the playlist to add into
171  * \param psz_uri the mrl to add to the playlist
172  * \param psz_name a text giving a name or description of this item
173  * \param i_mode the mode used when adding
174  * \param i_pos the position in the playlist where to add. If this is
175  *        PLAYLIST_END the item will be added at the end of the playlist
176  *        regardless of it's size
177  * \param b_playlist TRUE for playlist, FALSE for media library
178  * \return The id of the playlist item
179  */
180 int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
181                   const char *psz_name, int i_mode, int i_pos,
182                   vlc_bool_t b_playlist  )
183 {
184     return playlist_AddExt( p_playlist, psz_uri, psz_name,
185                             i_mode, i_pos, -1, NULL, 0, b_playlist );
186 }
187
188 /**
189  * Add a MRL into the playlist or the media library, duration and options given
190  *
191  * \param p_playlist the playlist to add into
192  * \param psz_uri the mrl to add to the playlist
193  * \param psz_name a text giving a name or description of this item
194  * \param i_mode the mode used when adding
195  * \param i_pos the position in the playlist where to add. If this is
196  *        PLAYLIST_END the item will be added at the end of the playlist
197  *        regardless of it's size
198  * \param i_duration length of the item in milliseconds.
199  * \param ppsz_options an array of options
200  * \param i_options the number of options
201  * \param b_playlist TRUE for playlist, FALSE for media library
202  * \return The id of the playlist item
203 */
204 int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
205                      const char *psz_name, int i_mode, int i_pos,
206                      mtime_t i_duration, const char **ppsz_options,
207                      int i_options, vlc_bool_t b_playlist )
208 {
209     input_item_t *p_input = input_ItemNewExt( p_playlist, psz_uri, psz_name,
210                                               i_options, ppsz_options,
211                                               i_duration );
212
213     return playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist );
214 }
215
216 /** Add an input item to the playlist node */
217 int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
218                       int i_mode, int i_pos, vlc_bool_t b_playlist )
219 {
220     playlist_item_t *p_item_cat, *p_item_one;
221
222     if( !p_playlist->b_doing_ml )
223         PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name,
224                                              p_input->psz_uri );
225
226     vlc_mutex_lock( &p_playlist->object_lock );
227
228     /* Add to ONELEVEL */
229     p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
230     if( p_item_one == NULL ) return VLC_EGENERIC;
231     AddItem( p_playlist, p_item_one,
232              b_playlist ? p_playlist->p_local_onelevel :
233                           p_playlist->p_ml_onelevel , i_pos );
234
235     /* Add to CATEGORY */
236     p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
237     if( p_item_cat == NULL ) return VLC_EGENERIC;
238     AddItem( p_playlist, p_item_cat,
239              b_playlist ? p_playlist->p_local_category :
240                           p_playlist->p_ml_category , i_pos );
241
242     GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
243
244     vlc_mutex_unlock( &p_playlist->object_lock );
245     return VLC_SUCCESS;
246 }
247
248 /** Add an input item to p_direct_parent in the category tree, and to the
249  *  matching top category in onelevel **/
250 int playlist_BothAddInput( playlist_t *p_playlist,
251                            input_item_t *p_input,
252                            playlist_item_t *p_direct_parent,
253                            int i_mode, int i_pos )
254 {
255     playlist_item_t *p_item_cat, *p_item_one, *p_up;
256     int i_top;
257     assert( p_input );
258     vlc_mutex_lock( & p_playlist->object_lock );
259
260     /* Add to category */
261     p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
262     if( p_item_cat == NULL ) return VLC_EGENERIC;
263     AddItem( p_playlist, p_item_cat, p_direct_parent, i_pos );
264
265     /* Add to onelevel */
266     /** \todo make a faster case for ml import */
267     p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
268     if( p_item_one == NULL ) return VLC_EGENERIC;
269
270     p_up = p_direct_parent;
271     while( p_up->p_parent != p_playlist->p_root_category )
272     {
273         p_up = p_up->p_parent;
274     }
275     for( i_top = 0 ; i_top < p_playlist->p_root_onelevel->i_children; i_top++ )
276     {
277         if( p_playlist->p_root_onelevel->pp_children[i_top]->p_input->i_id == p_up->p_input->i_id )
278         {
279             AddItem( p_playlist, p_item_one,
280                      p_playlist->p_root_onelevel->pp_children[i_top], i_pos );
281             break;
282         }
283     }
284     GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
285
286     vlc_mutex_unlock( &p_playlist->object_lock );
287     return VLC_SUCCESS;
288 }
289
290 /**
291  * Add an item where it should be added, when adding from a node
292  * (ex: directory access, playlist demuxers, services discovery, ... )
293  * \param p_playlist the playlist
294  * \param p_input the input to add
295  * \param p_parent the direct node
296  * \param p_item_in_category the item within category root (as returned by playlist_ItemToNode)
297  * \param b_forced_parent Are we forced to add only to p_parent ?
298  */
299 void playlist_AddWhereverNeeded( playlist_t *p_playlist, input_item_t *p_input,
300                                  playlist_item_t *p_parent,
301                                  playlist_item_t *p_item_in_category,
302                                  vlc_bool_t b_forced_parent, int i_mode )
303 {
304     /* If we have forced a parent :
305      *   - Just add the input to the forced parent (which should be p_parent)
306      * Else
307      *    - If we have item in category, add to it, and to onelevel (bothadd)
308      *    - If we don't, just add to p_parent
309      */
310     if( b_forced_parent == VLC_TRUE || !p_item_in_category  )
311     {
312         playlist_NodeAddInput( p_playlist, p_input, p_parent, i_mode,
313                                PLAYLIST_END );
314     }
315     else
316     {
317         playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
318                                i_mode, PLAYLIST_END );
319     }
320 }
321
322
323 /** Add an input item to a given node */
324 playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist,
325                                          input_item_t *p_input,
326                                          playlist_item_t *p_parent,
327                                          int i_mode, int i_pos )
328 {
329     playlist_item_t *p_item;
330     assert( p_input );
331     assert( p_parent && p_parent->i_children != -1 );
332
333     vlc_mutex_lock( &p_playlist->object_lock );
334
335     p_item = playlist_ItemNewFromInput( p_playlist, p_input );
336     if( p_item == NULL ) return NULL;
337     AddItem( p_playlist, p_item, p_parent, i_pos );
338
339     vlc_mutex_unlock( &p_playlist->object_lock );
340
341     return p_item;
342 }
343
344 /** Add a playlist item to a given node */
345 void playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item,
346                            playlist_item_t *p_parent, int i_mode, int i_pos )
347 {
348     vlc_mutex_lock( &p_playlist->object_lock );
349     AddItem( p_playlist, p_item, p_parent, i_pos );
350     vlc_mutex_unlock( &p_playlist->object_lock );
351 }
352
353 /*****************************************************************************
354  * Playlist item misc operations
355  *****************************************************************************/
356
357 /**
358  * Transform an item to a node. Return the node in the category tree, or NULL
359  * if not found there
360  * This function must be entered without the playlist lock
361  */
362 playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
363                                       playlist_item_t *p_item )
364 {
365
366     playlist_item_t *p_item_in_category;
367     /* What we do
368      * Find the input in CATEGORY.
369      *  - If we find it
370      *    - change it to node
371      *    - we'll return it at the end
372      *    - If we are a direct child of onelevel root, change to node, else
373      *      delete the input from ONELEVEL
374      *  - If we don't find it, just change to node (we are probably in VLM)
375      *    and return NULL
376      *
377      * If we were in ONELEVEL, we thus retrieve the node in CATEGORY (will be
378      * useful for later BothAddInput )
379      */
380
381     /* Fast track the media library, no time to loose */
382     if( p_item == p_playlist->p_ml_category )
383         return p_item;
384
385     /** \todo First look if we don't already have it */
386     p_item_in_category = playlist_ItemFindFromInputAndRoot(
387                                             p_playlist, p_item->p_input->i_id,
388                                             p_playlist->p_root_category );
389
390     if( p_item_in_category )
391     {
392         playlist_item_t *p_item_in_one = playlist_ItemFindFromInputAndRoot(
393                                             p_playlist, p_item->p_input->i_id,
394                                             p_playlist->p_root_onelevel );
395         ChangeToNode( p_playlist, p_item_in_category );
396         if( p_item_in_one->p_parent == p_playlist->p_root_onelevel )
397             ChangeToNode( p_playlist, p_item_in_one );
398         else
399         {
400             playlist_DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id,
401                                       p_playlist->p_root_onelevel, VLC_FALSE );
402         }
403         p_playlist->b_reset_random = VLC_TRUE;
404         var_SetInteger( p_playlist, "item-change", p_item_in_category->
405                                                         p_input->i_id );
406         return p_item_in_category;
407     }
408     else
409     {
410         ChangeToNode( p_playlist, p_item );
411         return NULL;
412     }
413 }
414
415 /** Transform an item to a node
416  *  This function must be entered without the playlist lock
417  *  \see playlist_ItemToNode
418  */
419 playlist_item_t * playlist_LockItemToNode( playlist_t *p_playlist,
420                                            playlist_item_t *p_item )
421 {
422     playlist_item_t *p_ret;
423     vlc_mutex_lock( &p_playlist->object_lock );
424     p_ret = playlist_ItemToNode( p_playlist, p_item );
425     vlc_mutex_unlock( &p_playlist->object_lock );
426     return p_ret;
427 }
428
429 /** Find an item within a root, given its input id.
430  * \return the first found item, or NULL if not found
431  */
432 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
433                                                     int i_input_id,
434                                                     playlist_item_t *p_root )
435 {
436     int i;
437     for( i = 0 ; i< p_root->i_children ; i++ )
438     {
439         if( p_root->pp_children[i]->i_children == -1 &&
440             p_root->pp_children[i]->p_input->i_id == i_input_id )
441         {
442             return p_root->pp_children[i];
443         }
444         else if( p_root->pp_children[i]->i_children >= 0 )
445         {
446             playlist_item_t *p_search =
447                  playlist_ItemFindFromInputAndRoot( p_playlist, i_input_id,
448                                                     p_root->pp_children[i] );
449             if( p_search ) return p_search;
450         }
451     }
452     return NULL;
453 }
454
455
456 /**
457  * Moves an item
458  *
459  * This function must be entered with the playlist lock
460  *
461  * \param p_playlist the playlist
462  * \param p_item the item to move
463  * \param p_node the new parent of the item
464  * \param i_newpos the new position under this new parent
465  * \return VLC_SUCCESS or an error
466  */
467 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
468                        playlist_item_t *p_node, int i_newpos )
469 {
470     int j;
471     playlist_item_t *p_detach = NULL;
472
473     if( p_node->i_children == -1 ) return VLC_EGENERIC;
474
475     p_detach = p_item->p_parent;
476     for( j = 0; j < p_detach->i_children; j++ )
477     {
478          if( p_detach->pp_children[j] == p_item ) break;
479     }
480     REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, j );
481
482     /* Attach to new parent */
483     INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
484
485     return VLC_SUCCESS;
486 }
487
488 /** Send a notification that an item has been added to a node */
489 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
490                              int i_node_id )
491 {
492     vlc_value_t val;
493     playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
494     p_add->i_item = i_item_id;
495     p_add->i_node = i_node_id;
496     val.p_address = p_add;
497     p_playlist->b_reset_random = VLC_TRUE;
498     var_Set( p_playlist, "item-append", val );
499     free( p_add );
500 }
501
502 /*****************************************************************************
503  * Playlist item accessors
504  *****************************************************************************/
505
506 /** Set the name of a playlist item */
507 int playlist_ItemSetName( playlist_item_t *p_item, char *psz_name )
508 {
509     if( psz_name && p_item )
510     {
511         if( p_item->p_input->psz_name ) free( p_item->p_input->psz_name );
512         p_item->p_input->psz_name = strdup( psz_name );
513         return VLC_SUCCESS;
514     }
515     return VLC_EGENERIC;
516 }
517
518 /***************************************************************************
519  * The following functions are local
520  ***************************************************************************/
521
522 /* Enqueue an item for preparsing, and play it, if needed */
523 void GoAndPreparse( playlist_t *p_playlist, int i_mode,
524                     playlist_item_t *p_item_cat, playlist_item_t *p_item_one )
525 {
526     if( (i_mode & PLAYLIST_GO ) )
527     {
528         playlist_item_t *p_parent = p_item_one;
529         playlist_item_t *p_toplay = NULL;
530         while( p_parent )
531         {
532             if( p_parent == p_playlist->p_root_category )
533             {
534                 p_toplay = p_item_cat; break;
535             }
536             else if( p_parent == p_playlist->p_root_onelevel )
537             {
538                 p_toplay = p_item_one; break;
539             }
540             p_parent = p_parent->p_parent;
541         }
542         assert( p_toplay );
543         p_playlist->request.b_request = VLC_TRUE;
544         p_playlist->request.p_item = p_toplay;
545         if( p_playlist->p_input )
546         {
547             input_StopThread( p_playlist->p_input );
548         }
549         p_playlist->request.i_status = PLAYLIST_RUNNING;
550     }
551     if( i_mode & PLAYLIST_PREPARSE &&
552         var_CreateGetBool( p_playlist, "auto-preparse" ) )
553     {
554         playlist_PreparseEnqueue( p_playlist, p_item_cat->p_input );
555     }
556 }
557
558 /* Add the playlist item to the requested node and fire a notification */
559 void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
560               playlist_item_t *p_node, int i_pos )
561 {
562     INSERT_ELEM( p_playlist->pp_items, p_playlist->i_size,
563                  p_playlist->i_size, p_item );
564     INSERT_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size,
565                  p_playlist->i_all_size, p_item );
566     p_playlist->i_enabled ++;
567
568     if( i_pos == PLAYLIST_END )
569     {
570         playlist_NodeAppend( p_playlist, p_item, p_node );
571     }
572     else
573     {
574         playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
575     }
576     if( !p_playlist->b_doing_ml )
577         playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id );
578 }
579
580 /* Actually convert an item to a node */
581 void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
582 {
583     int i;
584     if( p_item->i_children == -1 )
585         p_item->i_children = 0;
586
587     /* Remove it from the array of available items */
588     for( i = 0 ; i < p_playlist->i_size ; i++ )
589     {
590         if( p_item == p_playlist->pp_items[i] )
591         {
592             REMOVE_ELEM( p_playlist->pp_items, p_playlist->i_size, i );
593         }
594     }
595 }
596
597 /* Do the actual removal */
598 int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
599                 vlc_bool_t b_stop )
600 {
601     int i, i_top, i_bottom;
602     int i_id = p_item->i_id;
603     vlc_bool_t b_flag = VLC_FALSE;
604
605     if( p_item->i_children > -1 )
606     {
607         return playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
608     }
609     p_playlist->b_reset_random = VLC_TRUE;
610     var_SetInteger( p_playlist, "item-deleted", i_id );
611
612     /* Remove the item from the bank */
613     i_bottom = 0; i_top = p_playlist->i_all_size - 1;
614     i = i_top / 2;
615     while( p_playlist->pp_all_items[i]->i_id != i_id &&
616            i_top > i_bottom )
617     {
618         if( p_playlist->pp_all_items[i]->i_id < i_id )
619         {
620             i_bottom = i + 1;
621         }
622         else
623         {
624             i_top = i - 1;
625         }
626         i = i_bottom + ( i_top - i_bottom ) / 2;
627     }
628     if( p_playlist->pp_all_items[i]->i_id == i_id )
629     {
630         REMOVE_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size, i );
631     }
632
633     /* Check if it is the current item */
634     if( p_playlist->status.p_item == p_item )
635     {
636         /* Hack we don't call playlist_Control for lock reasons */
637         if( b_stop )
638         {
639             p_playlist->request.i_status = PLAYLIST_STOPPED;
640             p_playlist->request.b_request = VLC_TRUE;
641             p_playlist->request.p_item = NULL;
642             msg_Info( p_playlist, "stopping playback" );
643         }
644         b_flag = VLC_TRUE;
645     }
646
647     PL_DEBUG( "deleting item `%s'", p_item->p_input->psz_name );
648
649     /* Remove the item from its parent */
650     playlist_NodeRemoveItem( p_playlist, p_item, p_item->p_parent );
651
652     if( b_flag == VLC_FALSE )
653         playlist_ItemDelete( p_item );
654     else
655     {
656         PL_DEBUG( "marking %s for further deletion", PLI_NAME( p_item ) );
657         p_item->i_flags |= PLAYLIST_REMOVE_FLAG;
658     }
659
660     return VLC_SUCCESS;
661 }