]> git.sesse.net Git - vlc/blob - src/playlist/item.c
Compiler warnings rampage
[vlc] / src / playlist / item.c
1 /*****************************************************************************
2  * item.c : Playlist item creation/deletion/add/removal functions
3  *****************************************************************************
4  * Copyright (C) 1999-2007 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 <assert.h>
26 #include <vlc_playlist.h>
27 #include "playlist_internal.h"
28
29 static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
30                      playlist_item_t *p_node, int i_mode, int i_pos );
31 static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
32                            playlist_item_t *, playlist_item_t * );
33 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item );
34 static 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 *const *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     DECMALLOC_NULL( p_item, playlist_item_t );
59     playlist_t *p_playlist = p_obj->p_libvlc->p_playlist;
60     vlc_object_yield( p_playlist );
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 when it appears from a root playlist item */
90 static int DeleteFromInput( playlist_t *p_playlist, int i_input_id,
91                             playlist_item_t *p_root, vlc_bool_t b_do_stop )
92 {
93     int i;
94     for( i = 0 ; i< p_root->i_children ; i++ )
95     {
96         if( p_root->pp_children[i]->i_children == -1 &&
97             p_root->pp_children[i]->p_input->i_id == i_input_id )
98         {
99             DeleteInner( p_playlist, p_root->pp_children[i], b_do_stop );
100             return VLC_SUCCESS;
101         }
102         else if( p_root->pp_children[i]->i_children >= 0 )
103         {
104             int i_ret = DeleteFromInput( p_playlist, i_input_id,
105                                          p_root->pp_children[i], b_do_stop );
106             if( i_ret == VLC_SUCCESS ) return VLC_SUCCESS;
107         }
108     }
109     return VLC_EGENERIC;
110 }
111
112 /** Remove an input item from ONELEVEL and CATEGORY */
113 int playlist_DeleteFromInput( playlist_t *p_playlist, int i_input_id,
114                               vlc_bool_t b_locked )
115 {
116     int i_ret1, i_ret2;
117     if( !b_locked ) PL_LOCK;
118     i_ret1 = DeleteFromInput( p_playlist, i_input_id,
119                              p_playlist->p_root_category, VLC_TRUE );
120     i_ret2 = DeleteFromInput( p_playlist, i_input_id,
121                      p_playlist->p_root_onelevel, VLC_TRUE );
122     if( !b_locked ) PL_UNLOCK;
123     return ( i_ret1 == VLC_SUCCESS || i_ret2 == VLC_SUCCESS ) ?
124                             VLC_SUCCESS : VLC_ENOITEM;
125 }
126
127 void playlist_Clear( playlist_t * p_playlist, vlc_bool_t b_locked )
128 {
129     if( !b_locked ) PL_LOCK;
130     playlist_NodeEmpty( p_playlist, p_playlist->p_root_category, VLC_TRUE );
131     playlist_NodeEmpty( p_playlist, p_playlist->p_root_onelevel, VLC_TRUE );
132     if( !b_locked ) PL_UNLOCK;
133 }
134
135 /** Remove a playlist item from the playlist, given its id
136  * This function is to be used only by the playlist */
137 int playlist_DeleteFromItemId( playlist_t *p_playlist, int i_id )
138 {
139     playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id,
140                                                     VLC_TRUE );
141     if( !p_item ) return VLC_EGENERIC;
142     return DeleteInner( p_playlist, p_item, VLC_TRUE );
143 }
144
145 /***************************************************************************
146  * Playlist item addition
147  ***************************************************************************/
148 /** Add an item to the playlist or the media library
149  * \param p_playlist the playlist to add into
150  * \param psz_uri the mrl to add to the playlist
151  * \param psz_name a text giving a name or description of this item
152  * \param i_mode the mode used when adding
153  * \param i_pos the position in the playlist where to add. If this is
154  *        PLAYLIST_END the item will be added at the end of the playlist
155  *        regardless of its size
156  * \param b_playlist TRUE for playlist, FALSE for media library
157  * \return The id of the playlist item
158  */
159 int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
160                   const char *psz_name, int i_mode, int i_pos,
161                   vlc_bool_t b_playlist, vlc_bool_t b_locked )
162 {
163     return playlist_AddExt( p_playlist, psz_uri, psz_name,
164                             i_mode, i_pos, -1, NULL, 0, b_playlist, b_locked );
165 }
166
167 /**
168  * Add a MRL into the playlist or the media library, duration and options given
169  *
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 its size
177  * \param i_duration length of the item in milliseconds.
178  * \param ppsz_options an array of options
179  * \param i_options the number of options
180  * \param b_playlist TRUE for playlist, FALSE for media library
181  * \return The id of the playlist item
182 */
183 int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
184                      const char *psz_name, int i_mode, int i_pos,
185                      mtime_t i_duration, const char *const *ppsz_options,
186                      int i_options, vlc_bool_t b_playlist, vlc_bool_t b_locked )
187 {
188     int i_ret;
189     input_item_t *p_input = input_ItemNewExt( p_playlist, psz_uri, psz_name,
190                                               i_options, ppsz_options,
191                                               i_duration );
192
193     i_ret = playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist,
194                                b_locked );
195     if( i_ret == VLC_SUCCESS )
196         return p_input->i_id;
197     return -1;
198 }
199
200 /** Add an input item to the playlist node */
201 int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
202                        int i_mode, int i_pos, vlc_bool_t b_playlist,
203                        vlc_bool_t b_locked )
204 {
205     playlist_item_t *p_item_cat, *p_item_one;
206
207     if( !p_playlist->b_doing_ml )
208         PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name,
209                                              p_input->psz_uri );
210
211     if( !b_locked ) PL_LOCK;
212
213     /* Add to ONELEVEL */
214     p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
215     if( p_item_one == NULL ) return VLC_ENOMEM;
216     AddItem( p_playlist, p_item_one,
217              b_playlist ? p_playlist->p_local_onelevel :
218                           p_playlist->p_ml_onelevel , i_mode, i_pos );
219
220     /* Add to CATEGORY */
221     p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
222     if( p_item_cat == NULL ) return VLC_ENOMEM;
223     AddItem( p_playlist, p_item_cat,
224              b_playlist ? p_playlist->p_local_category :
225                           p_playlist->p_ml_category , i_mode, i_pos );
226
227     GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
228
229     if( !b_locked ) PL_UNLOCK;
230     return VLC_SUCCESS;
231 }
232
233 /** Add an input item to p_direct_parent in the category tree, and to the
234  *  matching top category in onelevel **/
235 int playlist_BothAddInput( playlist_t *p_playlist,
236                            input_item_t *p_input,
237                            playlist_item_t *p_direct_parent,
238                            int i_mode, int i_pos,
239                            int *i_cat, int *i_one, vlc_bool_t b_locked )
240 {
241     playlist_item_t *p_item_cat, *p_item_one, *p_up;
242     int i_top;
243     assert( p_input );
244     if( !b_locked ) PL_LOCK;
245
246     /* Add to category */
247     p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
248     if( p_item_cat == NULL ) return VLC_ENOMEM;
249     AddItem( p_playlist, p_item_cat, p_direct_parent, i_mode, i_pos );
250
251     /* Add to onelevel */
252     /** \todo make a faster case for ml import */
253     p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
254     if( p_item_one == NULL ) return VLC_ENOMEM;
255
256     p_up = p_direct_parent;
257     while( p_up->p_parent != p_playlist->p_root_category )
258     {
259         p_up = p_up->p_parent;
260     }
261     for( i_top = 0 ; i_top < p_playlist->p_root_onelevel->i_children; i_top++ )
262     {
263         if( p_playlist->p_root_onelevel->pp_children[i_top]->p_input->i_id ==
264                              p_up->p_input->i_id )
265         {
266             AddItem( p_playlist, p_item_one,
267                      p_playlist->p_root_onelevel->pp_children[i_top],
268                      i_mode, i_pos );
269             break;
270         }
271     }
272     GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
273
274     if( i_cat ) *i_cat = p_item_cat->i_id;
275     if( i_one ) *i_one = p_item_one->i_id;
276
277     if( !b_locked ) PL_UNLOCK;
278     return VLC_SUCCESS;
279 }
280
281 /** Add an input item to a given node */
282 playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist,
283                                          input_item_t *p_input,
284                                          playlist_item_t *p_parent,
285                                          int i_mode, int i_pos,
286                                          vlc_bool_t b_locked )
287 {
288     playlist_item_t *p_item;
289     assert( p_input );
290     assert( p_parent && p_parent->i_children != -1 );
291
292     if( !b_locked ) PL_LOCK;
293
294     p_item = playlist_ItemNewFromInput( p_playlist, p_input );
295     if( p_item == NULL ) return NULL;
296     AddItem( p_playlist, p_item, p_parent, i_mode, i_pos );
297
298     if( !b_locked ) PL_UNLOCK;
299
300     return p_item;
301 }
302
303 /*****************************************************************************
304  * Playlist item misc operations
305  *****************************************************************************/
306
307 /**
308  * Transform an item to a node. Return the node in the category tree, or NULL
309  * if not found there
310  * This function must be entered without the playlist lock
311  */
312 playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
313                                       playlist_item_t *p_item,
314                                       vlc_bool_t b_locked )
315 {
316
317     playlist_item_t *p_item_in_category;
318     /* What we do
319      * Find the input in CATEGORY.
320      *  - If we find it
321      *    - change it to node
322      *    - we'll return it at the end
323      *    - If we are a direct child of onelevel root, change to node, else
324      *      delete the input from ONELEVEL
325      *  - If we don't find it, just change to node (we are probably in VLM)
326      *    and return NULL
327      *
328      * If we were in ONELEVEL, we thus retrieve the node in CATEGORY (will be
329      * useful for later BothAddInput )
330      */
331
332     if( !b_locked ) PL_LOCK;
333
334     /* Fast track the media library, no time to loose */
335     if( p_item == p_playlist->p_ml_category ) {
336         if( !b_locked ) PL_UNLOCK;
337         return p_item;
338     }
339
340     /** \todo First look if we don't already have it */
341     p_item_in_category = playlist_ItemFindFromInputAndRoot(
342                                             p_playlist, p_item->p_input->i_id,
343                                             p_playlist->p_root_category,
344                                             VLC_TRUE );
345
346     if( p_item_in_category )
347     {
348         playlist_item_t *p_item_in_one = playlist_ItemFindFromInputAndRoot(
349                                             p_playlist, p_item->p_input->i_id,
350                                             p_playlist->p_root_onelevel,
351                                             VLC_TRUE );
352         assert( p_item_in_one );
353         ChangeToNode( p_playlist, p_item_in_category );
354         /* Item in one is a root, change it to node */
355         if( p_item_in_one->p_parent == p_playlist->p_root_onelevel )
356             ChangeToNode( p_playlist, p_item_in_one );
357         else
358         {
359             DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id,
360                              p_playlist->p_root_onelevel, VLC_FALSE );
361         }
362         p_playlist->b_reset_currently_playing = VLC_TRUE;
363         vlc_cond_signal( &p_playlist->object_wait );
364         var_SetInteger( p_playlist, "item-change", p_item_in_category->
365                                                         p_input->i_id );
366         if( !b_locked ) PL_UNLOCK;
367         return p_item_in_category;
368     }
369     else
370     {
371         ChangeToNode( p_playlist, p_item );
372         if( !b_locked ) PL_UNLOCK;
373         return NULL;
374     }
375 }
376
377 /** Find an item within a root, given its input id.
378  * \return the first found item, or NULL if not found
379  */
380 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
381                                                     int i_input_id,
382                                                     playlist_item_t *p_root,
383                                                     vlc_bool_t b_items_only )
384 {
385     int i;
386     for( i = 0 ; i< p_root->i_children ; i++ )
387     {
388         if( ( b_items_only ? p_root->pp_children[i]->i_children == -1 : 1 ) &&
389             p_root->pp_children[i]->p_input->i_id == i_input_id )
390         {
391             return p_root->pp_children[i];
392         }
393         else if( p_root->pp_children[i]->i_children >= 0 )
394         {
395             playlist_item_t *p_search =
396                  playlist_ItemFindFromInputAndRoot( p_playlist, i_input_id,
397                                                     p_root->pp_children[i],
398                                                     b_items_only );
399             if( p_search ) return p_search;
400         }
401     }
402     return NULL;
403 }
404
405
406 static int TreeMove( playlist_t *p_playlist, playlist_item_t *p_item,
407                      playlist_item_t *p_node, int i_newpos )
408 {
409     int j;
410     playlist_item_t *p_detach = p_item->p_parent;
411     (void)p_playlist;
412
413     if( p_node->i_children == -1 ) return VLC_EGENERIC;
414
415     for( j = 0; j < p_detach->i_children; j++ )
416     {
417          if( p_detach->pp_children[j] == p_item ) break;
418     }
419     REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, j );
420
421     /* Attach to new parent */
422     INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
423     p_item->p_parent = p_node;
424
425     return VLC_SUCCESS;
426 }
427
428 /**
429  * Moves an item
430  *
431  * This function must be entered with the playlist lock
432  *
433  * \param p_playlist the playlist
434  * \param p_item the item to move
435  * \param p_node the new parent of the item
436  * \param i_newpos the new position under this new parent
437  * \return VLC_SUCCESS or an error
438  */
439 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
440                        playlist_item_t *p_node, int i_newpos )
441 {
442     int i_ret;
443     /* Drop on a top level node. Move in the two trees */
444     if( p_node->p_parent == p_playlist->p_root_category ||
445         p_node->p_parent == p_playlist->p_root_onelevel )
446     {
447         /* Fixme: avoid useless lookups but we need some clean helpers */
448         {
449             /* Fixme: if we try to move a node on a top-level node, it will
450              * fail because the node doesn't exist in onelevel and we will
451              * do some shit in onelevel. We should recursively move all items
452              * within the node */
453             playlist_item_t *p_node_onelevel;
454             playlist_item_t *p_item_onelevel;
455             p_node_onelevel = playlist_ItemFindFromInputAndRoot( p_playlist,
456                                                 p_node->p_input->i_id,
457                                                 p_playlist->p_root_onelevel,
458                                                 VLC_FALSE );
459             p_item_onelevel = playlist_ItemFindFromInputAndRoot( p_playlist,
460                                                 p_item->p_input->i_id,
461                                                 p_playlist->p_root_onelevel,
462                                                 VLC_FALSE );
463             if( p_node_onelevel && p_item_onelevel )
464                 TreeMove( p_playlist, p_item_onelevel, p_node_onelevel, 0 );
465         }
466         {
467             playlist_item_t *p_node_category;
468             playlist_item_t *p_item_category;
469             p_node_category = playlist_ItemFindFromInputAndRoot( p_playlist,
470                                                 p_node->p_input->i_id,
471                                                 p_playlist->p_root_category,
472                                                 VLC_FALSE );
473             p_item_category = playlist_ItemFindFromInputAndRoot( p_playlist,
474                                                 p_item->p_input->i_id,
475                                                 p_playlist->p_root_category,
476                                                 VLC_FALSE );
477             if( p_node_category && p_item_category )
478                 TreeMove( p_playlist, p_item_category, p_node_category, 0 );
479         }
480         i_ret = VLC_SUCCESS;
481     }
482     else
483         i_ret = TreeMove( p_playlist, p_item, p_node, i_newpos );
484     p_playlist->b_reset_currently_playing = VLC_TRUE;
485     vlc_cond_signal( &p_playlist->object_wait );
486     return i_ret;
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, vlc_bool_t b_signal )
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_currently_playing = VLC_TRUE;
499     if( b_signal )
500         vlc_cond_signal( &p_playlist->object_wait );
501     var_Set( p_playlist, "item-append", val );
502     free( p_add );
503 }
504
505 /*****************************************************************************
506  * Playlist item accessors
507  *****************************************************************************/
508
509 /** Set the name of a playlist item */
510 int playlist_ItemSetName( playlist_item_t *p_item, const char *psz_name )
511 {
512     if( psz_name && p_item )
513     {
514         if( p_item->p_input->psz_name ) free( p_item->p_input->psz_name );
515         p_item->p_input->psz_name = strdup( psz_name );
516         return VLC_SUCCESS;
517     }
518     return VLC_EGENERIC;
519 }
520
521 /***************************************************************************
522  * The following functions are local
523  ***************************************************************************/
524
525 /* Enqueue an item for preparsing, and play it, if needed */
526 static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
527                            playlist_item_t *p_item_cat,
528                            playlist_item_t *p_item_one )
529 {
530     if( (i_mode & PLAYLIST_GO ) )
531     {
532         playlist_item_t *p_parent = p_item_one;
533         playlist_item_t *p_toplay = NULL;
534         while( p_parent )
535         {
536             if( p_parent == p_playlist->p_root_category )
537             {
538                 p_toplay = p_item_cat; break;
539             }
540             else if( p_parent == p_playlist->p_root_onelevel )
541             {
542                 p_toplay = p_item_one; break;
543             }
544             p_parent = p_parent->p_parent;
545         }
546         assert( p_toplay );
547         p_playlist->request.b_request = VLC_TRUE;
548         p_playlist->request.i_skip = 0;
549         p_playlist->request.p_item = p_toplay;
550         if( p_playlist->p_input )
551             input_StopThread( p_playlist->p_input );
552         p_playlist->request.i_status = PLAYLIST_RUNNING;
553         vlc_cond_signal( &p_playlist->object_wait );
554     }
555     /* Preparse if PREPARSE or SPREPARSE & not enough meta */
556     if( p_playlist->b_auto_preparse &&
557           (i_mode & PLAYLIST_PREPARSE ||
558           ( i_mode & PLAYLIST_SPREPARSE &&
559             ( !p_item_cat->p_input->p_meta || (p_item_cat->p_input->p_meta &&
560               ( EMPTY_STR( p_item_cat->p_input->p_meta->psz_artist ) ||
561                 EMPTY_STR( p_item_cat->p_input->p_meta->psz_album ) )
562               )
563             )
564           ) ) )
565         playlist_PreparseEnqueue( p_playlist, p_item_cat->p_input );
566     /* If we already have it, signal it */
567     else if( p_item_cat->p_input->p_meta &&
568              !EMPTY_STR( p_item_cat->p_input->p_meta->psz_artist ) &&
569              !EMPTY_STR( p_item_cat->p_input->p_meta->psz_album ) )
570         p_item_cat->p_input->p_meta->i_status = ITEM_PREPARSED;
571 }
572
573 /* Add the playlist item to the requested node and fire a notification */
574 static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
575                      playlist_item_t *p_node, int i_mode, int i_pos )
576 {
577     ARRAY_APPEND(p_playlist->items, p_item);
578     ARRAY_APPEND(p_playlist->all_items, p_item);
579     p_playlist->i_enabled ++;
580
581     if( i_pos == PLAYLIST_END )
582         playlist_NodeAppend( p_playlist, p_item, p_node );
583     else
584         playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
585
586     if( !p_playlist->b_doing_ml )
587         playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id,
588                                  !( i_mode & PLAYLIST_NO_REBUILD ) );
589 }
590
591 /* Actually convert an item to a node */
592 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
593 {
594     int i;
595     if( p_item->i_children == -1 )
596         p_item->i_children = 0;
597
598     /* Remove it from the array of available items */
599     ARRAY_BSEARCH( p_playlist->items,->i_id, int, p_item->i_id, i );
600     if( i != -1 )
601         ARRAY_REMOVE( p_playlist->items, i );
602 }
603
604 /* Do the actual removal */
605 static int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
606                         vlc_bool_t b_stop )
607 {
608     int i;
609     int i_id = p_item->i_id;
610     vlc_bool_t b_flag = VLC_FALSE;
611
612     if( p_item->i_children > -1 )
613     {
614         return playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
615     }
616     p_playlist->b_reset_currently_playing = VLC_TRUE;
617     var_SetInteger( p_playlist, "item-deleted", i_id );
618
619     /* Remove the item from the bank */
620     ARRAY_BSEARCH( p_playlist->all_items,->i_id, int, i_id, i );
621     if( i != -1 )
622         ARRAY_REMOVE( p_playlist->all_items, i );
623
624     /* Check if it is the current item */
625     if( p_playlist->status.p_item == p_item )
626     {
627         /* Hack we don't call playlist_Control for lock reasons */
628         if( b_stop )
629         {
630             p_playlist->request.i_status = PLAYLIST_STOPPED;
631             p_playlist->request.b_request = VLC_TRUE;
632             p_playlist->request.p_item = NULL;
633             msg_Info( p_playlist, "stopping playback" );
634             vlc_cond_signal( &p_playlist->object_wait );
635         }
636         b_flag = VLC_TRUE;
637     }
638
639     PL_DEBUG( "deleting item `%s'", p_item->p_input->psz_name );
640
641     /* Remove the item from its parent */
642     playlist_NodeRemoveItem( p_playlist, p_item, p_item->p_parent );
643
644     if( b_flag == VLC_FALSE )
645         playlist_ItemDelete( p_item );
646     else
647     {
648         PL_DEBUG( "marking %s for further deletion", PLI_NAME( p_item ) );
649         p_item->i_flags |= PLAYLIST_REMOVE_FLAG;
650     }
651
652     return VLC_SUCCESS;
653 }