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