]> git.sesse.net Git - vlc/blob - src/playlist/item.c
* Almost fix shoutcast (still some problems in "flat" view)
[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
27 #include "vlc_playlist.h"
28
29 void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
30               playlist_item_t *p_node, int i_pos );
31 void GoAndPreparse( playlist_t *p_playlist, int i_mode,
32                     playlist_item_t *p_item );
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 /**
41  * Create a new item, without adding it to the playlist
42  *
43  * \param p_obj a vlc object (anyone will do)
44  * \param psz_uri the mrl of the item
45  * \param psz_name a text giving a name or description of the item
46  * \return the new item or NULL on failure
47  */
48 playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
49                                       const char *psz_uri,
50                                       const char *psz_name )
51 {
52     return playlist_ItemNewWithType( p_obj, psz_uri,
53                                      psz_name, 0, NULL, -1,
54                                      ITEM_TYPE_UNKNOWN );
55 }
56
57 playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj,
58                                             const char *psz_uri,
59                                             const char *psz_name,
60                                             int i_options,
61                                             const char **ppsz_options,
62                                             int i_duration,
63                                             int i_type )
64 {
65     if( psz_uri == NULL ) return NULL;
66     input_item_t *p_input = input_ItemNewWithType( p_obj, psz_uri,
67                                         psz_name, i_options, ppsz_options,
68                                         i_duration, i_type );
69     return playlist_ItemNewFromInput( p_obj, p_input );
70 }
71
72 playlist_item_t *__playlist_ItemNewFromInput( vlc_object_t *p_obj,
73                                             input_item_t *p_input )
74 {
75     /** FIXME !!!!! don't find playlist each time */
76     playlist_t *p_playlist = (playlist_t *)vlc_object_find( p_obj, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
77     playlist_item_t * p_item;
78     p_item = malloc( sizeof( playlist_item_t ) );
79     if( p_item == NULL ) return NULL;
80
81     p_item->p_input = p_input;
82     vlc_gc_incref( p_item->p_input );
83
84     p_item->i_id = ++p_playlist->i_last_playlist_id;
85
86     p_item->p_parent = NULL;
87     p_item->i_children = -1;
88     p_item->pp_children = NULL;
89     p_item->i_flags = 0;
90
91     vlc_object_release( p_playlist );
92
93     return p_item;
94 }
95
96 /***************************************************************************
97  * Playlist item destruction
98  ***************************************************************************/
99
100 /** Delete a playlist item and detach its input item */
101 int playlist_ItemDelete( playlist_item_t *p_item )
102 {
103     vlc_gc_decref( p_item->p_input );
104     free( p_item );
105     return VLC_SUCCESS;
106 }
107
108 /** Remove an input item from ONELEVEL and CATEGORY */
109 int playlist_DeleteAllFromInput( playlist_t *p_playlist, int i_input_id )
110 {
111     playlist_DeleteFromInput( p_playlist, i_input_id,
112                               p_playlist->p_root_category, VLC_TRUE );
113     playlist_DeleteFromInput( p_playlist, i_input_id,
114                               p_playlist->p_root_onelevel, VLC_TRUE );
115     return VLC_SUCCESS;
116 }
117
118 /** Remove an input item from ONELEVEL and CATEGORY.
119  * This function must be entered without the playlist lock */
120 int playlist_LockDeleteAllFromInput( playlist_t * p_playlist, int i_id )
121 {
122     int i_ret;
123     vlc_mutex_lock( &p_playlist->object_lock );
124     i_ret = playlist_DeleteAllFromInput( p_playlist, i_id );
125     vlc_mutex_unlock( &p_playlist->object_lock );
126     return i_ret;
127 }
128
129 /** Remove an input item when it appears from a root playlist item */
130 int playlist_DeleteFromInput( playlist_t *p_playlist, int i_input_id,
131                               playlist_item_t *p_root, vlc_bool_t b_do_stop )
132 {
133     int i;
134     for( i = 0 ; i< p_root->i_children ; i++ )
135     {
136         if( p_root->pp_children[i]->i_children == -1 &&
137             p_root->pp_children[i]->p_input->i_id == i_input_id )
138         {
139             DeleteInner( p_playlist, p_root->pp_children[i], b_do_stop );
140         }
141         else if( p_root->pp_children[i]->i_children >= 0 )
142         {
143             return playlist_DeleteFromInput( p_playlist, i_input_id,
144                                         p_root->pp_children[i], b_do_stop );
145         }
146     }
147     return -1;
148 }
149
150 /** Remove a playlist item from the playlist, given its id */
151 int playlist_DeleteFromItemId( playlist_t *p_playlist, int i_id )
152 {
153     playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
154     if( !p_item ) return VLC_EGENERIC;
155     return DeleteInner( p_playlist, p_item, VLC_TRUE );
156 }
157
158 /** Remove a playlist item from the playlist, given its id
159  * This function should be entered without the playlist lock */
160 int playlist_LockDelete( playlist_t * p_playlist, int i_id )
161 {
162     int i_ret;
163     vlc_mutex_lock( &p_playlist->object_lock );
164     i_ret = playlist_DeleteFromItemId( p_playlist, i_id );
165     vlc_mutex_unlock( &p_playlist->object_lock );
166     return i_ret;
167 }
168
169 /** Clear the playlist */
170 void playlist_Clear( playlist_t * p_playlist )
171 {
172     playlist_NodeEmpty( p_playlist, p_playlist->p_root_category, VLC_TRUE );
173     playlist_NodeEmpty( p_playlist, p_playlist->p_root_onelevel, VLC_TRUE );
174 }
175 /** Clear the playlist. This function must be entered without the lock */
176 void playlist_LockClear( playlist_t *p_playlist )
177 {
178     vlc_mutex_lock( &p_playlist->object_lock );
179     playlist_Clear( p_playlist );
180     vlc_mutex_unlock( &p_playlist->object_lock );
181 }
182
183 /***************************************************************************
184  * Playlist item addition
185  ***************************************************************************/
186
187 /**
188  * Add a MRL into the playlist.
189  *
190  * \param p_playlist the playlist to add into
191  * \param psz_uri the mrl to add to the playlist
192  * \param psz_name a text giving a name or description of this item
193  * \param i_mode the mode used when adding
194  * \param i_pos the position in the playlist where to add. If this is
195  *        PLAYLIST_END the item will be added at the end of the playlist
196  *        regardless of it's size
197  * \return The id of the playlist item
198  */
199 int playlist_PlaylistAdd( playlist_t *p_playlist, const char *psz_uri,
200                           const char *psz_name, int i_mode, int i_pos )
201 {
202     return playlist_PlaylistAddExt( p_playlist, psz_uri, psz_name,
203                                     i_mode, i_pos, -1, NULL, 0 );
204 }
205
206 /**
207  * Add a MRL into the playlist, duration and options given
208  *
209  * \param p_playlist the playlist to add into
210  * \param psz_uri the mrl to add to the playlist
211  * \param psz_name a text giving a name or description of this item
212  * \param i_mode the mode used when adding
213  * \param i_pos the position in the playlist where to add. If this is
214  *        PLAYLIST_END the item will be added at the end of the playlist
215  *        regardless of it's size
216  * \param i_duration length of the item in milliseconds.
217  * \param ppsz_options an array of options
218  * \param i_options the number of options
219  * \return The id of the playlist item
220 */
221 int playlist_PlaylistAddExt( playlist_t *p_playlist, const char * psz_uri,
222                              const char *psz_name, int i_mode, int i_pos,
223                              mtime_t i_duration, const char **ppsz_options,
224                              int i_options )
225 {
226     input_item_t *p_input = input_ItemNewExt( p_playlist, psz_uri, psz_name,
227                                               i_options, ppsz_options,
228                                               i_duration );
229
230     return playlist_PlaylistAddInput( p_playlist, p_input, i_mode, i_pos );
231 }
232
233 /** Add an input item to the playlist node */
234 int playlist_PlaylistAddInput( playlist_t* p_playlist, input_item_t *p_input,
235                                int i_mode, int i_pos )
236 {
237     playlist_item_t *p_item;
238     p_input->i_id = ++p_playlist->i_last_input_id;
239
240     msg_Dbg( p_playlist, "adding playlist item `%s' ( %s )",
241              p_input->psz_name, p_input->psz_uri );
242
243     vlc_mutex_lock( &p_playlist->object_lock );
244
245     /* Add to ONELEVEL */
246     p_item = playlist_ItemNewFromInput( p_playlist, p_input );
247     if( p_item == NULL ) return VLC_EGENERIC;
248     AddItem( p_playlist, p_item,p_playlist->p_local_onelevel, i_pos );
249
250     /* Add to CATEGORY */
251     p_item = playlist_ItemNewFromInput( p_playlist, p_input );
252     if( p_item == NULL ) return VLC_EGENERIC;
253     AddItem( p_playlist, p_item, p_playlist->p_local_category, i_pos );
254
255     GoAndPreparse( p_playlist, i_mode, p_item );
256
257     vlc_mutex_unlock( &p_playlist->object_lock );
258     return VLC_SUCCESS;
259 }
260
261 /** Add an input item to p_direct_parent in the category tree, and to the
262  *  matching top category in onelevel **/
263 int playlist_BothAddInput( playlist_t *p_playlist,
264                            input_item_t *p_input,
265                            playlist_item_t *p_direct_parent,
266                            int i_mode, int i_pos )
267 {
268     playlist_item_t *p_item, *p_up;
269     int i_top;
270     vlc_mutex_lock( & p_playlist->object_lock );
271
272     /* Add to category */
273     p_item = playlist_ItemNewFromInput( p_playlist, p_input );
274     if( p_item == NULL ) return VLC_EGENERIC;
275     AddItem( p_playlist, p_item, p_direct_parent, i_pos );
276
277     /* Add to onelevel */
278     p_item = playlist_ItemNewFromInput( p_playlist, p_input );
279     if( p_item == NULL ) return VLC_EGENERIC;
280
281     p_up = p_direct_parent;
282     while( p_up->p_parent != p_playlist->p_root_category )
283     {
284         p_up = p_up->p_parent;
285     }
286     for( i_top = 0 ; i_top < p_playlist->p_root_onelevel->i_children; i_top++ )
287     {
288         if( p_playlist->p_root_onelevel->pp_children[i_top]->p_input->i_id == p_up->p_input->i_id )
289         {
290             AddItem( p_playlist, p_item,
291                      p_playlist->p_root_onelevel->pp_children[i_top], i_pos );
292             break;
293         }
294     }
295     GoAndPreparse( p_playlist, i_mode, p_item );
296
297     vlc_mutex_unlock( &p_playlist->object_lock );
298     return VLC_SUCCESS;
299 }
300
301 /**
302  * Add an item where it should be added, when adding from a node
303  * (ex: directory access, playlist demuxers, services discovery, ... )
304  * \param p_playlist the playlist
305  * \param p_input the input to add
306  * \param p_parent the direct node
307  * \param p_item_in_category the item within category root (as returned by playlist_ItemToNode)
308  * \param b_forced_parent Are we forced to add only to p_parent ?
309  */
310 void playlist_AddWhereverNeeded( playlist_t *p_playlist, input_item_t *p_input,
311                                  playlist_item_t *p_parent,
312                                  playlist_item_t *p_item_in_category,
313                                  vlc_bool_t b_forced_parent, int i_mode )
314 {
315     /* If we have forced a parent :
316      *   - Just add the input to the forced parent (which should be p_parent)
317      * Else
318      *    - If we have item in category, add to it, and to onelevel (bothadd)
319      *    - If we don't, just add to p_parent
320      */
321     if( b_forced_parent == VLC_TRUE || !p_item_in_category  )
322     {
323         playlist_NodeAddInput( p_playlist, p_input, p_parent, i_mode,
324                                PLAYLIST_END );
325     }
326     else
327     {
328         playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
329                                i_mode, PLAYLIST_END );
330     }
331 }
332
333
334 /** Add an input item to a given node */
335 playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist,
336                                          input_item_t *p_input,
337                                          playlist_item_t *p_parent,
338                                          int i_mode, int i_pos )
339 {
340     playlist_item_t *p_item;
341
342     /* Sanity checks */
343     if( !p_parent || p_parent->i_children == -1 )
344     {
345         msg_Err( p_playlist, "invalid node" );
346     }
347
348     vlc_mutex_lock( &p_playlist->object_lock );
349
350     p_item = playlist_ItemNewFromInput( p_playlist, p_input );
351     if( p_item == NULL ) return NULL;
352     AddItem( p_playlist, p_item, p_parent, i_pos );
353
354     vlc_mutex_unlock( &p_playlist->object_lock );
355
356     return p_item;
357 }
358
359 /** Add a playlist item to a given node */
360 void playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item,
361                            playlist_item_t *p_parent, int i_mode, int i_pos )
362 {
363     vlc_mutex_lock( &p_playlist->object_lock );
364     AddItem( p_playlist, p_item, p_parent, i_pos );
365     vlc_mutex_unlock( &p_playlist->object_lock );
366 }
367
368 /*****************************************************************************
369  * Playlist item misc operations
370  *****************************************************************************/
371
372 /**
373  * Transform an item to a node. Return the node in the category tree, or NULL
374  * if not found there
375  * This function must be entered without the playlist lock
376  */
377 playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
378                                       playlist_item_t *p_item )
379 {
380     /* What we do
381      * Find the input in CATEGORY.
382      *  - If we find it
383      *    - change it to node
384      *    - we'll return it at the end
385      *    - If we are a direct child of onelevel root, change to node, else
386      *      delete the input from ONELEVEL
387      *  - If we don't find it, just change to node (we are probably in VLM)
388      *    and return NULL
389      *
390      * If we were in ONELEVEL, we thus retrieve the node in CATEGORY (will be
391      * useful for later BothAddInput )
392      */
393
394     /** \todo First look if we don't already have it */
395     playlist_item_t *p_item_in_category = playlist_ItemFindFromInputAndRoot(
396                                             p_playlist, p_item->p_input->i_id,
397                                             p_playlist->p_root_category );
398
399     if( p_item_in_category )
400     {
401         playlist_item_t *p_item_in_one = playlist_ItemFindFromInputAndRoot(
402                                             p_playlist, p_item->p_input->i_id,
403                                             p_playlist->p_root_onelevel );
404         ChangeToNode( p_playlist, p_item_in_category );
405         if( p_item_in_one->p_parent == p_playlist->p_root_onelevel )
406         {
407             ChangeToNode( p_playlist, p_item_in_one );
408         }
409         else
410         {
411             playlist_DeleteFromInput( p_playlist, p_item->p_input->i_id,
412                                       p_playlist->p_root_onelevel, VLC_FALSE );
413         }
414         var_SetInteger( p_playlist, "item-change", p_item->p_input->i_id );
415         return p_item_in_category;
416     }
417     else
418     {
419         ChangeToNode( p_playlist, p_item );
420         return NULL;
421     }
422 }
423
424 /** Transform an item to a node
425  *  This function must be entered without the playlist lock
426  *  \see playlist_ItemToNode
427  */
428 playlist_item_t * playlist_LockItemToNode( playlist_t *p_playlist,
429                                            playlist_item_t *p_item )
430 {
431     playlist_item_t *p_ret;
432     vlc_mutex_lock( &p_playlist->object_lock );
433     p_ret = playlist_ItemToNode( p_playlist, p_item );
434     vlc_mutex_unlock( &p_playlist->object_lock );
435     return p_ret;
436 }
437
438 /** Find an item within a root, given its input id.
439  * \return the first found item, or NULL if not found
440  */
441 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
442                                                     int i_input_id,
443                                                     playlist_item_t *p_root )
444 {
445     int i;
446     for( i = 0 ; i< p_root->i_children ; i++ )
447     {
448         if( p_root->pp_children[i]->i_children == -1 &&
449             p_root->pp_children[i]->p_input->i_id == i_input_id )
450         {
451             return p_root->pp_children[i];
452         }
453         else if( p_root->pp_children[i]->i_children >= 0 )
454         {
455             playlist_item_t *p_search =
456                  playlist_ItemFindFromInputAndRoot( p_playlist, i_input_id,
457                                                     p_root->pp_children[i] );
458             if( p_search ) return p_search;
459         }
460     }
461     return NULL;
462 }
463
464
465 /**
466  * Moves an item
467  *
468  * This function must be entered with the playlist lock
469  *
470  * \param p_playlist the playlist
471  * \param p_item the item to move
472  * \param p_node the new parent of the item
473  * \param i_newpos the new position under this new parent
474  * \return VLC_SUCCESS or an error
475  */
476 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
477                        playlist_item_t *p_node, int i_newpos )
478 {
479     int j;
480     playlist_item_t *p_detach = NULL;
481
482     if( p_node->i_children == -1 ) return VLC_EGENERIC;
483
484     p_detach = p_item->p_parent;
485     for( j = 0; j < p_detach->i_children; j++ )
486     {
487          if( p_detach->pp_children[j] == p_item ) break;
488     }
489     REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, j );
490
491     /* Attach to new parent */
492     INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
493
494     return VLC_SUCCESS;
495 }
496
497 /** Send a notification that an item has been added to a node */
498 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
499                              int i_node_id )
500 {
501     vlc_value_t val;
502     playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
503     p_add->i_item = i_item_id;
504     p_add->i_node = i_node_id;
505     val.p_address = p_add;
506     var_Set( p_playlist, "item-append", val );
507     free( p_add );
508 }
509
510 /*****************************************************************************
511  * Playlist item accessors
512  *****************************************************************************/
513
514 /** Set the name of a playlist item */
515 int playlist_ItemSetName( playlist_item_t *p_item, char *psz_name )
516 {
517     if( psz_name && p_item )
518     {
519         if( p_item->p_input->psz_name ) free( p_item->p_input->psz_name );
520         p_item->p_input->psz_name = strdup( psz_name );
521         return VLC_SUCCESS;
522     }
523     return VLC_EGENERIC;
524 }
525
526 /** Set the duration of a playlist item
527  * \param i_duration the new duration in microseconds
528  */
529 int playlist_ItemSetDuration( playlist_item_t *p_item, mtime_t i_duration )
530 {
531     char psz_buffer[MSTRTIME_MAX_SIZE];
532     if( p_item )
533     {
534         p_item->p_input->i_duration = i_duration;
535         if( i_duration != -1 )
536         {
537             secstotimestr( psz_buffer, (int)(i_duration/1000000) );
538         }
539         else
540         {
541             memcpy( psz_buffer, "--:--:--", sizeof("--:--:--") );
542         }
543         vlc_input_item_AddInfo( p_item->p_input, _("General") , _("Duration"),
544                                 "%s", psz_buffer );
545
546         return VLC_SUCCESS;
547     }
548     return VLC_EGENERIC;
549 }
550
551 /** Add an option to a playlist item */
552 void playlist_ItemAddOption( playlist_item_t *p_item,
553                              const char *psz_option)
554 {
555     vlc_input_item_AddOption( p_item->p_input, psz_option );
556 }
557
558 /***************************************************************************
559  * The following functions are local
560  ***************************************************************************/
561
562 /* Enqueue an item for preparsing, and play it, if needed */
563 void GoAndPreparse( playlist_t *p_playlist, int i_mode,
564                     playlist_item_t *p_item )
565 {
566 #if 0
567     if( (i_mode & PLAYLIST_GO ) && p_view )
568     {
569         p_playlist->request.b_request = VLC_TRUE;
570         /* FIXME ... */
571         p_playlist->request.i_view = VIEW_CATEGORY;
572         p_playlist->request.p_node = p_view->p_root;
573         p_playlist->request.p_item = p_item;
574
575         if( p_playlist->p_input )
576         {
577             input_StopThread( p_playlist->p_input );
578         }
579         p_playlist->status.i_status = PLAYLIST_RUNNING;
580     }
581 #endif
582     if( i_mode & PLAYLIST_PREPARSE &&
583         var_CreateGetBool( p_playlist, "auto-preparse" ) )
584     {
585         playlist_PreparseEnqueue( p_playlist, p_item->p_input );
586     }
587 }
588
589 /* Add the playlist item to the requested node and fire a notification */
590 void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
591               playlist_item_t *p_node, int i_pos )
592 {
593     INSERT_ELEM( p_playlist->pp_items, p_playlist->i_size,
594                  p_playlist->i_size, p_item );
595 #if 0
596     fprintf( stderr, "Adding input %s (id %i) - playlist item id %i "
597                      "to node %s (id %i)\n",
598                      p_item->p_input->psz_name, p_item->p_input->i_id,
599                      p_item->i_id, p_node->p_input->psz_name,
600                      p_node->i_id );
601 #endif
602     INSERT_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size,
603                  p_playlist->i_all_size, p_item );
604     p_playlist->i_enabled ++;
605
606     if( i_pos == PLAYLIST_END )
607     {
608         playlist_NodeAppend( p_playlist, p_item, p_node );
609     }
610     else
611     {
612         playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
613     }
614
615     playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id );
616 }
617
618 /* Actually convert an item to a node */
619 void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
620 {
621     int i;
622     if( p_item->i_children == -1 )
623         p_item->i_children = 0;
624
625     /* Remove it from the array of available items */
626     for( i = 0 ; i < p_playlist->i_size ; i++ )
627     {
628         if( p_item == p_playlist->pp_items[i] )
629         {
630             REMOVE_ELEM( p_playlist->pp_items, p_playlist->i_size, i );
631         }
632     }
633 }
634
635 /* Do the actual removal */
636 int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
637                 vlc_bool_t b_stop )
638 {
639     int i, i_top, i_bottom;
640     int i_id = p_item->i_id;
641     vlc_bool_t b_flag = VLC_FALSE;
642
643     //fprintf( stderr, "Deleting item %i - %s\n", i_id,
644     //                                            p_item->p_input->psz_name );
645
646     if( p_item->i_children > -1 )
647     {
648         return playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
649     }
650     var_SetInteger( p_playlist, "item-deleted", i_id );
651
652     /* Remove the item from the bank */
653     i_bottom = 0; i_top = p_playlist->i_all_size - 1;
654     i = i_top / 2;
655     while( p_playlist->pp_all_items[i]->i_id != i_id &&
656            i_top > i_bottom )
657     {
658         if( p_playlist->pp_all_items[i]->i_id < i_id )
659         {
660             i_bottom = i + 1;
661         }
662         else
663         {
664             i_top = i - 1;
665         }
666         i = i_bottom + ( i_top - i_bottom ) / 2;
667     }
668     if( p_playlist->pp_all_items[i]->i_id == i_id )
669     {
670         REMOVE_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size, i );
671     }
672
673     /* Check if it is the current item */
674     if( p_playlist->status.p_item == p_item )
675     {
676         /* Hack we don't call playlist_Control for lock reasons */
677         if( b_stop )
678         {
679             p_playlist->status.i_status = PLAYLIST_STOPPED;
680             p_playlist->request.b_request = VLC_TRUE;
681             p_playlist->request.p_item = NULL;
682             msg_Info( p_playlist, "stopping playback" );
683         }
684         b_flag = VLC_TRUE;
685     }
686
687     msg_Dbg( p_playlist, "deleting playlist item `%s'",
688                           p_item->p_input->psz_name );
689
690     /* Remove the item from its parent */
691     playlist_NodeRemoveItem( p_playlist, p_item, p_item->p_parent );
692
693     if( b_flag == VLC_FALSE )
694         playlist_ItemDelete( p_item );
695     else
696         p_item->i_flags |= PLAYLIST_REMOVE_FLAG;
697
698     return VLC_SUCCESS;
699 }