]> git.sesse.net Git - vlc/blob - src/playlist/item.c
Add functions to use the media library
[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     /* What we do
364      * Find the input in CATEGORY.
365      *  - If we find it
366      *    - change it to node
367      *    - we'll return it at the end
368      *    - If we are a direct child of onelevel root, change to node, else
369      *      delete the input from ONELEVEL
370      *  - If we don't find it, just change to node (we are probably in VLM)
371      *    and return NULL
372      *
373      * If we were in ONELEVEL, we thus retrieve the node in CATEGORY (will be
374      * useful for later BothAddInput )
375      */
376
377     /* Fast track the media library, no time to loose */
378     if( p_item == p_playlist->p_ml_category )
379         return p_item;
380
381     /** \todo First look if we don't already have it */
382     playlist_item_t *p_item_in_category = playlist_ItemFindFromInputAndRoot(
383                                             p_playlist, p_item->p_input->i_id,
384                                             p_playlist->p_root_category );
385
386     if( p_item_in_category )
387     {
388         playlist_item_t *p_item_in_one = playlist_ItemFindFromInputAndRoot(
389                                             p_playlist, p_item->p_input->i_id,
390                                             p_playlist->p_root_onelevel );
391         ChangeToNode( p_playlist, p_item_in_category );
392         if( p_item_in_one->p_parent == p_playlist->p_root_onelevel )
393         {
394             ChangeToNode( p_playlist, p_item_in_one );
395         }
396         else
397         {
398             playlist_DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id,
399                                       p_playlist->p_root_onelevel, VLC_FALSE );
400         }
401         var_SetInteger( p_playlist, "item-change", p_item->p_input->i_id );
402         return p_item_in_category;
403     }
404     else
405     {
406         ChangeToNode( p_playlist, p_item );
407         return NULL;
408     }
409 }
410
411 /** Transform an item to a node
412  *  This function must be entered without the playlist lock
413  *  \see playlist_ItemToNode
414  */
415 playlist_item_t * playlist_LockItemToNode( playlist_t *p_playlist,
416                                            playlist_item_t *p_item )
417 {
418     playlist_item_t *p_ret;
419     vlc_mutex_lock( &p_playlist->object_lock );
420     p_ret = playlist_ItemToNode( p_playlist, p_item );
421     vlc_mutex_unlock( &p_playlist->object_lock );
422     return p_ret;
423 }
424
425 /** Find an item within a root, given its input id.
426  * \return the first found item, or NULL if not found
427  */
428 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
429                                                     int i_input_id,
430                                                     playlist_item_t *p_root )
431 {
432     int i;
433     for( i = 0 ; i< p_root->i_children ; i++ )
434     {
435         if( p_root->pp_children[i]->i_children == -1 &&
436             p_root->pp_children[i]->p_input->i_id == i_input_id )
437         {
438             return p_root->pp_children[i];
439         }
440         else if( p_root->pp_children[i]->i_children >= 0 )
441         {
442             playlist_item_t *p_search =
443                  playlist_ItemFindFromInputAndRoot( p_playlist, i_input_id,
444                                                     p_root->pp_children[i] );
445             if( p_search ) return p_search;
446         }
447     }
448     return NULL;
449 }
450
451
452 /**
453  * Moves an item
454  *
455  * This function must be entered with the playlist lock
456  *
457  * \param p_playlist the playlist
458  * \param p_item the item to move
459  * \param p_node the new parent of the item
460  * \param i_newpos the new position under this new parent
461  * \return VLC_SUCCESS or an error
462  */
463 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
464                        playlist_item_t *p_node, int i_newpos )
465 {
466     int j;
467     playlist_item_t *p_detach = NULL;
468
469     if( p_node->i_children == -1 ) return VLC_EGENERIC;
470
471     p_detach = p_item->p_parent;
472     for( j = 0; j < p_detach->i_children; j++ )
473     {
474          if( p_detach->pp_children[j] == p_item ) break;
475     }
476     REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, j );
477
478     /* Attach to new parent */
479     INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
480
481     return VLC_SUCCESS;
482 }
483
484 /** Send a notification that an item has been added to a node */
485 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
486                              int i_node_id )
487 {
488     vlc_value_t val;
489     playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
490     p_add->i_item = i_item_id;
491     p_add->i_node = i_node_id;
492     val.p_address = p_add;
493     var_Set( p_playlist, "item-append", val );
494     free( p_add );
495 }
496
497 /*****************************************************************************
498  * Playlist item accessors
499  *****************************************************************************/
500
501 /** Set the name of a playlist item */
502 int playlist_ItemSetName( playlist_item_t *p_item, char *psz_name )
503 {
504     if( psz_name && p_item )
505     {
506         if( p_item->p_input->psz_name ) free( p_item->p_input->psz_name );
507         p_item->p_input->psz_name = strdup( psz_name );
508         return VLC_SUCCESS;
509     }
510     return VLC_EGENERIC;
511 }
512
513 /***************************************************************************
514  * The following functions are local
515  ***************************************************************************/
516
517 /* Enqueue an item for preparsing, and play it, if needed */
518 void GoAndPreparse( playlist_t *p_playlist, int i_mode,
519                     playlist_item_t *p_item_cat, playlist_item_t *p_item_one )
520 {
521     if( (i_mode & PLAYLIST_GO ) )
522     {
523         playlist_item_t *p_parent = p_item_one;
524         playlist_item_t *p_toplay = NULL;
525         while( p_parent )
526         {
527             if( p_parent == p_playlist->p_root_category )
528             {
529                 p_toplay = p_item_cat; break;
530             }
531             else if( p_parent == p_playlist->p_root_onelevel )
532             {
533                 p_toplay = p_item_one; break;
534             }
535             p_parent = p_parent->p_parent;
536         }
537         assert( p_toplay );
538         p_playlist->request.b_request = VLC_TRUE;
539         p_playlist->request.p_item = p_toplay;
540         if( p_playlist->p_input )
541         {
542             input_StopThread( p_playlist->p_input );
543         }
544         p_playlist->request.i_status = PLAYLIST_RUNNING;
545     }
546     if( i_mode & PLAYLIST_PREPARSE &&
547         var_CreateGetBool( p_playlist, "auto-preparse" ) )
548     {
549         playlist_PreparseEnqueue( p_playlist, p_item_cat->p_input );
550     }
551 }
552
553 /* Add the playlist item to the requested node and fire a notification */
554 void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
555               playlist_item_t *p_node, int i_pos )
556 {
557     INSERT_ELEM( p_playlist->pp_items, p_playlist->i_size,
558                  p_playlist->i_size, p_item );
559     INSERT_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size,
560                  p_playlist->i_all_size, p_item );
561     p_playlist->i_enabled ++;
562
563     if( i_pos == PLAYLIST_END )
564     {
565         playlist_NodeAppend( p_playlist, p_item, p_node );
566     }
567     else
568     {
569         playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
570     }
571
572     playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id );
573 }
574
575 /* Actually convert an item to a node */
576 void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
577 {
578     int i;
579     if( p_item->i_children == -1 )
580         p_item->i_children = 0;
581
582     /* Remove it from the array of available items */
583     for( i = 0 ; i < p_playlist->i_size ; i++ )
584     {
585         if( p_item == p_playlist->pp_items[i] )
586         {
587             REMOVE_ELEM( p_playlist->pp_items, p_playlist->i_size, i );
588         }
589     }
590 }
591
592 /* Do the actual removal */
593 int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
594                 vlc_bool_t b_stop )
595 {
596     int i, i_top, i_bottom;
597     int i_id = p_item->i_id;
598     vlc_bool_t b_flag = VLC_FALSE;
599
600     if( p_item->i_children > -1 )
601     {
602         return playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
603     }
604     var_SetInteger( p_playlist, "item-deleted", i_id );
605
606     /* Remove the item from the bank */
607     i_bottom = 0; i_top = p_playlist->i_all_size - 1;
608     i = i_top / 2;
609     while( p_playlist->pp_all_items[i]->i_id != i_id &&
610            i_top > i_bottom )
611     {
612         if( p_playlist->pp_all_items[i]->i_id < i_id )
613         {
614             i_bottom = i + 1;
615         }
616         else
617         {
618             i_top = i - 1;
619         }
620         i = i_bottom + ( i_top - i_bottom ) / 2;
621     }
622     if( p_playlist->pp_all_items[i]->i_id == i_id )
623     {
624         REMOVE_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size, i );
625     }
626
627     /* Check if it is the current item */
628     if( p_playlist->status.p_item == p_item )
629     {
630         /* Hack we don't call playlist_Control for lock reasons */
631         if( b_stop )
632         {
633             p_playlist->status.i_status = PLAYLIST_STOPPED;
634             p_playlist->request.b_request = VLC_TRUE;
635             p_playlist->request.p_item = NULL;
636             msg_Info( p_playlist, "stopping playback" );
637         }
638         b_flag = VLC_TRUE;
639     }
640
641     PL_DEBUG( "deleting item `%s'", p_item->p_input->psz_name );
642
643     /* Remove the item from its parent */
644     playlist_NodeRemoveItem( p_playlist, p_item, p_item->p_parent );
645
646     if( b_flag == VLC_FALSE )
647         playlist_ItemDelete( p_item );
648     else
649         p_item->i_flags |= PLAYLIST_REMOVE_FLAG;
650
651     return VLC_SUCCESS;
652 }