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