]> git.sesse.net Git - vlc/blob - src/playlist/item.c
BeOS / gcc 2.x fixes, patch by Cian Duffy
[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     PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name, p_input->psz_uri );
223
224     vlc_mutex_lock( &p_playlist->object_lock );
225
226     /* Add to ONELEVEL */
227     p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
228     if( p_item_one == NULL ) return VLC_EGENERIC;
229     AddItem( p_playlist, p_item_one, 
230              b_playlist ? p_playlist->p_local_onelevel : 
231                           p_playlist->p_ml_onelevel , i_pos );
232
233     /* Add to CATEGORY */
234     p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
235     if( p_item_cat == NULL ) return VLC_EGENERIC;
236     AddItem( p_playlist, p_item_cat,
237              b_playlist ? p_playlist->p_local_category : 
238                           p_playlist->p_ml_category , i_pos );
239
240     GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
241
242     vlc_mutex_unlock( &p_playlist->object_lock );
243     return VLC_SUCCESS;
244 }
245
246 /** Add an input item to p_direct_parent in the category tree, and to the
247  *  matching top category in onelevel **/
248 int playlist_BothAddInput( playlist_t *p_playlist,
249                            input_item_t *p_input,
250                            playlist_item_t *p_direct_parent,
251                            int i_mode, int i_pos )
252 {
253     playlist_item_t *p_item_cat, *p_item_one, *p_up;
254     int i_top;
255     assert( p_input );
256     vlc_mutex_lock( & p_playlist->object_lock );
257
258     /* Add to category */
259     p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
260     if( p_item_cat == NULL ) return VLC_EGENERIC;
261     AddItem( p_playlist, p_item_cat, p_direct_parent, i_pos );
262
263     /* Add to onelevel */
264     /** \todo make a faster case for ml import */
265     p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
266     if( p_item_one == NULL ) return VLC_EGENERIC;
267
268     p_up = p_direct_parent;
269     while( p_up->p_parent != p_playlist->p_root_category )
270     {
271         p_up = p_up->p_parent;
272     }
273     for( i_top = 0 ; i_top < p_playlist->p_root_onelevel->i_children; i_top++ )
274     {
275         if( p_playlist->p_root_onelevel->pp_children[i_top]->p_input->i_id == p_up->p_input->i_id )
276         {
277             AddItem( p_playlist, p_item_one,
278                      p_playlist->p_root_onelevel->pp_children[i_top], i_pos );
279             break;
280         }
281     }
282     GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
283
284     vlc_mutex_unlock( &p_playlist->object_lock );
285     return VLC_SUCCESS;
286 }
287
288 /**
289  * Add an item where it should be added, when adding from a node
290  * (ex: directory access, playlist demuxers, services discovery, ... )
291  * \param p_playlist the playlist
292  * \param p_input the input to add
293  * \param p_parent the direct node
294  * \param p_item_in_category the item within category root (as returned by playlist_ItemToNode)
295  * \param b_forced_parent Are we forced to add only to p_parent ?
296  */
297 void playlist_AddWhereverNeeded( playlist_t *p_playlist, input_item_t *p_input,
298                                  playlist_item_t *p_parent,
299                                  playlist_item_t *p_item_in_category,
300                                  vlc_bool_t b_forced_parent, int i_mode )
301 {
302     /* If we have forced a parent :
303      *   - Just add the input to the forced parent (which should be p_parent)
304      * Else
305      *    - If we have item in category, add to it, and to onelevel (bothadd)
306      *    - If we don't, just add to p_parent
307      */
308     if( b_forced_parent == VLC_TRUE || !p_item_in_category  )
309     {
310         playlist_NodeAddInput( p_playlist, p_input, p_parent, i_mode,
311                                PLAYLIST_END );
312     }
313     else
314     {
315         playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
316                                i_mode, PLAYLIST_END );
317     }
318 }
319
320
321 /** Add an input item to a given node */
322 playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist,
323                                          input_item_t *p_input,
324                                          playlist_item_t *p_parent,
325                                          int i_mode, int i_pos )
326 {
327     playlist_item_t *p_item;
328     assert( p_input );
329     assert( p_parent && p_parent->i_children != -1 );
330
331     vlc_mutex_lock( &p_playlist->object_lock );
332
333     p_item = playlist_ItemNewFromInput( p_playlist, p_input );
334     if( p_item == NULL ) return NULL;
335     AddItem( p_playlist, p_item, p_parent, i_pos );
336
337     vlc_mutex_unlock( &p_playlist->object_lock );
338
339     return p_item;
340 }
341
342 /** Add a playlist item to a given node */
343 void playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item,
344                            playlist_item_t *p_parent, int i_mode, int i_pos )
345 {
346     vlc_mutex_lock( &p_playlist->object_lock );
347     AddItem( p_playlist, p_item, p_parent, i_pos );
348     vlc_mutex_unlock( &p_playlist->object_lock );
349 }
350
351 /*****************************************************************************
352  * Playlist item misc operations
353  *****************************************************************************/
354
355 /**
356  * Transform an item to a node. Return the node in the category tree, or NULL
357  * if not found there
358  * This function must be entered without the playlist lock
359  */
360 playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
361                                       playlist_item_t *p_item )
362 {
363
364     playlist_item_t *p_item_in_category;
365     /* What we do
366      * Find the input in CATEGORY.
367      *  - If we find it
368      *    - change it to node
369      *    - we'll return it at the end
370      *    - If we are a direct child of onelevel root, change to node, else
371      *      delete the input from ONELEVEL
372      *  - If we don't find it, just change to node (we are probably in VLM)
373      *    and return NULL
374      *
375      * If we were in ONELEVEL, we thus retrieve the node in CATEGORY (will be
376      * useful for later BothAddInput )
377      */
378
379     /* Fast track the media library, no time to loose */
380     if( p_item == p_playlist->p_ml_category )
381         return p_item;
382
383     /** \todo First look if we don't already have it */
384     p_item_in_category = playlist_ItemFindFromInputAndRoot(
385                                             p_playlist, p_item->p_input->i_id,
386                                             p_playlist->p_root_category );
387
388     if( p_item_in_category )
389     {
390         playlist_item_t *p_item_in_one = playlist_ItemFindFromInputAndRoot(
391                                             p_playlist, p_item->p_input->i_id,
392                                             p_playlist->p_root_onelevel );
393         ChangeToNode( p_playlist, p_item_in_category );
394         if( p_item_in_one->p_parent == p_playlist->p_root_onelevel )
395         {
396             ChangeToNode( p_playlist, p_item_in_one );
397         }
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         var_SetInteger( p_playlist, "item-change", p_item->p_input->i_id );
404         return p_item_in_category;
405     }
406     else
407     {
408         ChangeToNode( p_playlist, p_item );
409         return NULL;
410     }
411 }
412
413 /** Transform an item to a node
414  *  This function must be entered without the playlist lock
415  *  \see playlist_ItemToNode
416  */
417 playlist_item_t * playlist_LockItemToNode( playlist_t *p_playlist,
418                                            playlist_item_t *p_item )
419 {
420     playlist_item_t *p_ret;
421     vlc_mutex_lock( &p_playlist->object_lock );
422     p_ret = playlist_ItemToNode( p_playlist, p_item );
423     vlc_mutex_unlock( &p_playlist->object_lock );
424     return p_ret;
425 }
426
427 /** Find an item within a root, given its input id.
428  * \return the first found item, or NULL if not found
429  */
430 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
431                                                     int i_input_id,
432                                                     playlist_item_t *p_root )
433 {
434     int i;
435     for( i = 0 ; i< p_root->i_children ; i++ )
436     {
437         if( p_root->pp_children[i]->i_children == -1 &&
438             p_root->pp_children[i]->p_input->i_id == i_input_id )
439         {
440             return p_root->pp_children[i];
441         }
442         else if( p_root->pp_children[i]->i_children >= 0 )
443         {
444             playlist_item_t *p_search =
445                  playlist_ItemFindFromInputAndRoot( p_playlist, i_input_id,
446                                                     p_root->pp_children[i] );
447             if( p_search ) return p_search;
448         }
449     }
450     return NULL;
451 }
452
453
454 /**
455  * Moves an item
456  *
457  * This function must be entered with the playlist lock
458  *
459  * \param p_playlist the playlist
460  * \param p_item the item to move
461  * \param p_node the new parent of the item
462  * \param i_newpos the new position under this new parent
463  * \return VLC_SUCCESS or an error
464  */
465 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
466                        playlist_item_t *p_node, int i_newpos )
467 {
468     int j;
469     playlist_item_t *p_detach = NULL;
470
471     if( p_node->i_children == -1 ) return VLC_EGENERIC;
472
473     p_detach = p_item->p_parent;
474     for( j = 0; j < p_detach->i_children; j++ )
475     {
476          if( p_detach->pp_children[j] == p_item ) break;
477     }
478     REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, j );
479
480     /* Attach to new parent */
481     INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
482
483     return VLC_SUCCESS;
484 }
485
486 /** Send a notification that an item has been added to a node */
487 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
488                              int i_node_id )
489 {
490     vlc_value_t val;
491     playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
492     p_add->i_item = i_item_id;
493     p_add->i_node = i_node_id;
494     val.p_address = p_add;
495     var_Set( p_playlist, "item-append", val );
496     free( p_add );
497 }
498
499 /*****************************************************************************
500  * Playlist item accessors
501  *****************************************************************************/
502
503 /** Set the name of a playlist item */
504 int playlist_ItemSetName( playlist_item_t *p_item, char *psz_name )
505 {
506     if( psz_name && p_item )
507     {
508         if( p_item->p_input->psz_name ) free( p_item->p_input->psz_name );
509         p_item->p_input->psz_name = strdup( psz_name );
510         return VLC_SUCCESS;
511     }
512     return VLC_EGENERIC;
513 }
514
515 /***************************************************************************
516  * The following functions are local
517  ***************************************************************************/
518
519 /* Enqueue an item for preparsing, and play it, if needed */
520 void GoAndPreparse( playlist_t *p_playlist, int i_mode,
521                     playlist_item_t *p_item_cat, playlist_item_t *p_item_one )
522 {
523     if( (i_mode & PLAYLIST_GO ) )
524     {
525         playlist_item_t *p_parent = p_item_one;
526         playlist_item_t *p_toplay = NULL;
527         while( p_parent )
528         {
529             if( p_parent == p_playlist->p_root_category )
530             {
531                 p_toplay = p_item_cat; break;
532             }
533             else if( p_parent == p_playlist->p_root_onelevel )
534             {
535                 p_toplay = p_item_one; break;
536             }
537             p_parent = p_parent->p_parent;
538         }
539         assert( p_toplay );
540         p_playlist->request.b_request = VLC_TRUE;
541         p_playlist->request.p_item = p_toplay;
542         if( p_playlist->p_input )
543         {
544             input_StopThread( p_playlist->p_input );
545         }
546         p_playlist->request.i_status = PLAYLIST_RUNNING;
547     }
548     if( i_mode & PLAYLIST_PREPARSE &&
549         var_CreateGetBool( p_playlist, "auto-preparse" ) )
550     {
551         playlist_PreparseEnqueue( p_playlist, p_item_cat->p_input );
552     }
553 }
554
555 /* Add the playlist item to the requested node and fire a notification */
556 void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
557               playlist_item_t *p_node, int i_pos )
558 {
559     INSERT_ELEM( p_playlist->pp_items, p_playlist->i_size,
560                  p_playlist->i_size, p_item );
561     INSERT_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size,
562                  p_playlist->i_all_size, p_item );
563     p_playlist->i_enabled ++;
564
565     if( i_pos == PLAYLIST_END )
566     {
567         playlist_NodeAppend( p_playlist, p_item, p_node );
568     }
569     else
570     {
571         playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
572     }
573
574     playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id );
575 }
576
577 /* Actually convert an item to a node */
578 void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
579 {
580     int i;
581     if( p_item->i_children == -1 )
582         p_item->i_children = 0;
583
584     /* Remove it from the array of available items */
585     for( i = 0 ; i < p_playlist->i_size ; i++ )
586     {
587         if( p_item == p_playlist->pp_items[i] )
588         {
589             REMOVE_ELEM( p_playlist->pp_items, p_playlist->i_size, i );
590         }
591     }
592 }
593
594 /* Do the actual removal */
595 int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
596                 vlc_bool_t b_stop )
597 {
598     int i, i_top, i_bottom;
599     int i_id = p_item->i_id;
600     vlc_bool_t b_flag = VLC_FALSE;
601
602     if( p_item->i_children > -1 )
603     {
604         return playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
605     }
606     var_SetInteger( p_playlist, "item-deleted", i_id );
607
608     /* Remove the item from the bank */
609     i_bottom = 0; i_top = p_playlist->i_all_size - 1;
610     i = i_top / 2;
611     while( p_playlist->pp_all_items[i]->i_id != i_id &&
612            i_top > i_bottom )
613     {
614         if( p_playlist->pp_all_items[i]->i_id < i_id )
615         {
616             i_bottom = i + 1;
617         }
618         else
619         {
620             i_top = i - 1;
621         }
622         i = i_bottom + ( i_top - i_bottom ) / 2;
623     }
624     if( p_playlist->pp_all_items[i]->i_id == i_id )
625     {
626         REMOVE_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size, i );
627     }
628
629     /* Check if it is the current item */
630     if( p_playlist->status.p_item == p_item )
631     {
632         /* Hack we don't call playlist_Control for lock reasons */
633         if( b_stop )
634         {
635             p_playlist->status.i_status = PLAYLIST_STOPPED;
636             p_playlist->request.b_request = VLC_TRUE;
637             p_playlist->request.p_item = NULL;
638             msg_Info( p_playlist, "stopping playback" );
639         }
640         b_flag = VLC_TRUE;
641     }
642
643     PL_DEBUG( "deleting item `%s'", p_item->p_input->psz_name );
644
645     /* Remove the item from its parent */
646     playlist_NodeRemoveItem( p_playlist, p_item, p_item->p_parent );
647
648     if( b_flag == VLC_FALSE )
649         playlist_ItemDelete( p_item );
650     else
651         p_item->i_flags |= PLAYLIST_REMOVE_FLAG;
652
653     return VLC_SUCCESS;
654 }