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