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