1 /*****************************************************************************
2 * item.c : Playlist item creation/deletion/add/removal functions
3 *****************************************************************************
4 * Copyright (C) 1999-2007 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Clément Stenac <zorglub@videolan.org>
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.
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.
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 *****************************************************************************/
28 #include <vlc_common.h>
30 #include <vlc_playlist.h>
31 #include "playlist_internal.h"
33 static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
34 playlist_item_t *p_node, int i_mode, int i_pos );
35 static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
36 playlist_item_t *, playlist_item_t * );
37 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item );
38 static int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
41 /*****************************************************************************
42 * An input item has gained a subitem (Event Callback)
43 *****************************************************************************/
44 static void input_item_subitem_added( const vlc_event_t * p_event,
47 playlist_item_t *p_parent_playlist_item = user_data;
48 playlist_t * p_playlist = p_parent_playlist_item->p_playlist;
49 input_item_t * p_parent, * p_child;
50 playlist_item_t * p_child_in_category;
51 playlist_item_t * p_item_in_category;
54 p_parent = p_event->p_obj;
55 p_child = p_event->u.input_item_subitem_added.p_new_child;
58 b_play = var_CreateGetBool( p_playlist, "playlist-autostart" );
60 /* This part is really hakish, but this playlist system isn't simple */
61 /* First check if we haven't already added the item as we are
62 * listening using the onelevel and the category representent
63 * (Because of the playlist design) */
64 p_child_in_category = playlist_ItemFindFromInputAndRoot(
65 p_playlist, p_child->i_id,
66 p_playlist->p_root_category,
67 false /* Only non-node */ );
69 if( !p_child_in_category )
71 /* Then, transform to a node if needed */
72 p_item_in_category = playlist_ItemFindFromInputAndRoot(
73 p_playlist, p_parent->i_id,
74 p_playlist->p_root_category,
75 false /* Only non-node */ );
76 if( !p_item_in_category )
78 /* Item may have been removed */
83 b_play = b_play && p_item_in_category == p_playlist->status.p_item;
85 /* If this item is already a node don't transform it */
86 if( p_item_in_category->i_children == -1 )
88 p_item_in_category = playlist_ItemToNode( p_playlist,
89 p_item_in_category, true );
90 p_item_in_category->p_input->i_type = ITEM_TYPE_PLAYLIST;
93 int i_ret = playlist_BothAddInput( p_playlist, p_child,
95 PLAYLIST_APPEND | PLAYLIST_SPREPARSE , PLAYLIST_END,
98 if( i_ret == VLC_SUCCESS && b_play )
100 playlist_Control( p_playlist, PLAYLIST_VIEWPLAY,
101 true, p_item_in_category, NULL );
109 /*****************************************************************************
110 * Listen to vlc_InputItemAddSubItem event
111 *****************************************************************************/
112 static void install_input_item_observer( playlist_item_t * p_item )
114 vlc_event_attach( &p_item->p_input->event_manager,
115 vlc_InputItemSubItemAdded,
116 input_item_subitem_added,
120 static void uninstall_input_item_observer( playlist_item_t * p_item )
122 vlc_event_detach( &p_item->p_input->event_manager,
123 vlc_InputItemSubItemAdded,
124 input_item_subitem_added,
129 /*****************************************************************************
130 * Playlist item creation
131 *****************************************************************************/
132 playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj,
134 const char *psz_name,
136 const char *const *ppsz_options,
137 int i_duration, int i_type )
139 input_item_t *p_input;
140 if( psz_uri == NULL ) return NULL;
141 p_input = input_ItemNewWithType( p_obj, psz_uri,
142 psz_name, i_options, ppsz_options,
143 i_duration, i_type );
144 return playlist_ItemNewFromInput( p_obj, p_input );
147 playlist_item_t *__playlist_ItemNewFromInput( vlc_object_t *p_obj,
148 input_item_t *p_input )
150 DECMALLOC_NULL( p_item, playlist_item_t );
151 playlist_t *p_playlist = pl_Yield( p_obj );
153 p_item->p_input = p_input;
154 vlc_gc_incref( p_item->p_input );
156 p_item->i_id = ++p_playlist->i_last_playlist_id;
158 p_item->p_parent = NULL;
159 p_item->i_children = -1;
160 p_item->pp_children = NULL;
162 p_item->p_playlist = p_playlist;
164 install_input_item_observer( p_item );
166 pl_Release( p_item->p_playlist );
171 /***************************************************************************
172 * Playlist item destruction
173 ***************************************************************************/
178 * Delete a playlist item and detach its input item
179 * \param p_item item to delete
180 * \return VLC_SUCCESS
182 int playlist_ItemDelete( playlist_item_t *p_item )
184 uninstall_input_item_observer( p_item );
186 vlc_gc_decref( p_item->p_input );
194 * Remove an input item when it appears from a root playlist item
195 * \param p_playlist playlist object
196 * \param i_input_id id of the input to delete
197 * \param p_root root playlist item
198 * \param b_do_stop must stop or not the playlist
199 * \return VLC_SUCCESS or VLC_EGENERIC
201 static int DeleteFromInput( playlist_t *p_playlist, int i_input_id,
202 playlist_item_t *p_root, bool b_do_stop )
205 for( i = 0 ; i< p_root->i_children ; i++ )
207 if( p_root->pp_children[i]->i_children == -1 &&
208 p_root->pp_children[i]->p_input->i_id == i_input_id )
210 DeleteInner( p_playlist, p_root->pp_children[i], b_do_stop );
213 else if( p_root->pp_children[i]->i_children >= 0 )
215 int i_ret = DeleteFromInput( p_playlist, i_input_id,
216 p_root->pp_children[i], b_do_stop );
217 if( i_ret == VLC_SUCCESS ) return VLC_SUCCESS;
226 * Remove an input item when it appears from a root playlist item
227 * \param p_playlist playlist object
228 * \param i_input_id id of the input to delete
229 * \param p_root root playlist item
230 * \param b_locked TRUE if the playlist is locked
231 * \return VLC_SUCCESS or VLC_EGENERIC
233 int playlist_DeleteInputInParent( playlist_t *p_playlist, int i_input_id,
234 playlist_item_t *p_root, bool b_locked )
237 if( !b_locked ) PL_LOCK;
238 i_ret = DeleteFromInput( p_playlist, i_input_id,
240 if( !b_locked ) PL_UNLOCK;
247 * Remove an input item from ONELEVEL and CATEGORY
248 * \param p_playlist playlist object
249 * \param i_input_id id of the input to delete
250 * \param b_locked TRUE if the playlist is locked
251 * \return VLC_SUCCESS or VLC_ENOITEM
253 int playlist_DeleteFromInput( playlist_t *p_playlist, int i_input_id,
257 if( !b_locked ) PL_LOCK;
258 i_ret1 = DeleteFromInput( p_playlist, i_input_id,
259 p_playlist->p_root_category, true );
260 i_ret2 = DeleteFromInput( p_playlist, i_input_id,
261 p_playlist->p_root_onelevel, true );
262 if( !b_locked ) PL_UNLOCK;
263 return ( i_ret1 == VLC_SUCCESS || i_ret2 == VLC_SUCCESS ) ?
264 VLC_SUCCESS : VLC_ENOITEM;
270 * \param p_playlist playlist object
271 * \param b_locked TRUE if the playlist is locked
274 void playlist_Clear( playlist_t * p_playlist, bool b_locked )
276 if( !b_locked ) PL_LOCK;
277 playlist_NodeEmpty( p_playlist, p_playlist->p_local_category, true );
278 playlist_NodeEmpty( p_playlist, p_playlist->p_local_onelevel, true );
279 if( !b_locked ) PL_UNLOCK;
283 * Delete playlist item
285 * Remove a playlist item from the playlist, given its id
286 * This function is to be used only by the playlist
287 * \param p_playlist playlist object
288 * \param i_id id of the item do delete
289 * \return VLC_SUCCESS or an error
291 int playlist_DeleteFromItemId( playlist_t *p_playlist, int i_id )
293 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id,
295 if( !p_item ) return VLC_EGENERIC;
296 return DeleteInner( p_playlist, p_item, true );
299 /***************************************************************************
300 * Playlist item addition
301 ***************************************************************************/
305 * Add an item to the playlist or the media library
306 * \param p_playlist the playlist to add into
307 * \param psz_uri the mrl to add to the playlist
308 * \param psz_name a text giving a name or description of this item
309 * \param i_mode the mode used when adding
310 * \param i_pos the position in the playlist where to add. If this is
311 * PLAYLIST_END the item will be added at the end of the playlist
312 * regardless of its size
313 * \param b_playlist TRUE for playlist, FALSE for media library
314 * \param b_locked TRUE if the playlist is locked
315 * \return The id of the playlist item
317 int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
318 const char *psz_name, int i_mode, int i_pos,
319 bool b_playlist, bool b_locked )
321 return playlist_AddExt( p_playlist, psz_uri, psz_name,
322 i_mode, i_pos, -1, NULL, 0, b_playlist, b_locked );
326 * Add a MRL into the playlist or the media library, duration and options given
328 * \param p_playlist the playlist to add into
329 * \param psz_uri the mrl to add to the playlist
330 * \param psz_name a text giving a name or description of this item
331 * \param i_mode the mode used when adding
332 * \param i_pos the position in the playlist where to add. If this is
333 * PLAYLIST_END the item will be added at the end of the playlist
334 * regardless of its size
335 * \param i_duration length of the item in milliseconds.
336 * \param ppsz_options an array of options
337 * \param i_options the number of options
338 * \param b_playlist TRUE for playlist, FALSE for media library
339 * \param b_locked TRUE if the playlist is locked
340 * \return The id of the playlist item
342 int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
343 const char *psz_name, int i_mode, int i_pos,
344 mtime_t i_duration, const char *const *ppsz_options,
345 int i_options, bool b_playlist, bool b_locked )
348 input_item_t *p_input = input_ItemNewExt( p_playlist, psz_uri, psz_name,
349 i_options, ppsz_options,
352 i_ret = playlist_AddInput( p_playlist, p_input, i_mode, i_pos, b_playlist,
354 int i_id = i_ret == VLC_SUCCESS ? p_input->i_id : -1;
356 vlc_gc_decref( p_input );
362 * Add an input item to the playlist node
364 * \param p_playlist the playlist to add into
365 * \param p_input the input item to add
366 * \param i_mode the mode used when adding
367 * \param i_pos the position in the playlist where to add. If this is
368 * PLAYLIST_END the item will be added at the end of the playlist
369 * regardless of its size
370 * \param b_playlist TRUE for playlist, FALSE for media library
371 * \param b_locked TRUE if the playlist is locked
372 * \return VLC_SUCCESS or VLC_ENOMEM or VLC_EGENERIC
374 int playlist_AddInput( playlist_t* p_playlist, input_item_t *p_input,
375 int i_mode, int i_pos, bool b_playlist,
378 playlist_item_t *p_item_cat, *p_item_one;
379 if( p_playlist->b_die ) return VLC_EGENERIC;
380 if( !p_playlist->b_doing_ml )
381 PL_DEBUG( "adding item `%s' ( %s )", p_input->psz_name,
384 if( !b_locked ) PL_LOCK;
386 /* Add to ONELEVEL */
387 p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
388 if( p_item_one == NULL ) return VLC_ENOMEM;
389 AddItem( p_playlist, p_item_one,
390 b_playlist ? p_playlist->p_local_onelevel :
391 p_playlist->p_ml_onelevel , i_mode, i_pos );
393 /* Add to CATEGORY */
394 p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
395 if( p_item_cat == NULL ) return VLC_ENOMEM;
396 AddItem( p_playlist, p_item_cat,
397 b_playlist ? p_playlist->p_local_category :
398 p_playlist->p_ml_category , i_mode, i_pos );
400 GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
402 if( !b_locked ) PL_UNLOCK;
409 * Add an input item to p_direct_parent in the category tree, and to the
410 * matching top category in onelevel
411 * \param p_playlist the playlist to add into
412 * \param p_input the input item to add
413 * \param p_direct_parent the parent item to add into
414 * \param i_mode the mode used when adding
415 * \param i_pos the position in the playlist where to add. If this is
416 * PLAYLIST_END the item will be added at the end of the playlist
417 * regardless of its size
418 * \param i_cat id of the items category
419 * \param i_one id of the item onelevel category
420 * \param b_locked TRUE if the playlist is locked
421 * \return VLC_SUCCESS if success, VLC_EGENERIC if fail, VLC_ENOMEM if OOM
423 int playlist_BothAddInput( playlist_t *p_playlist,
424 input_item_t *p_input,
425 playlist_item_t *p_direct_parent,
426 int i_mode, int i_pos,
427 int *i_cat, int *i_one, bool b_locked )
429 playlist_item_t *p_item_cat, *p_item_one, *p_up;
432 if( p_playlist->b_die ) return VLC_EGENERIC;
433 if( !b_locked ) PL_LOCK;
435 /* Add to category */
436 p_item_cat = playlist_ItemNewFromInput( p_playlist, p_input );
437 if( p_item_cat == NULL ) return VLC_ENOMEM;
438 AddItem( p_playlist, p_item_cat, p_direct_parent, i_mode, i_pos );
440 /* Add to onelevel */
441 /**Â \todo make a faster case for ml import */
442 p_item_one = playlist_ItemNewFromInput( p_playlist, p_input );
443 if( p_item_one == NULL ) return VLC_ENOMEM;
445 p_up = p_direct_parent;
446 while( p_up->p_parent != p_playlist->p_root_category )
448 p_up = p_up->p_parent;
450 for( i_top = 0 ; i_top < p_playlist->p_root_onelevel->i_children; i_top++ )
452 if( p_playlist->p_root_onelevel->pp_children[i_top]->p_input->i_id ==
453 p_up->p_input->i_id )
455 AddItem( p_playlist, p_item_one,
456 p_playlist->p_root_onelevel->pp_children[i_top],
461 GoAndPreparse( p_playlist, i_mode, p_item_cat, p_item_one );
463 if( i_cat ) *i_cat = p_item_cat->i_id;
464 if( i_one ) *i_one = p_item_one->i_id;
466 if( !b_locked ) PL_UNLOCK;
471 * Add an input item to a given node
473 * \param p_playlist the playlist to add into
474 * \param p_input the input item to add
475 * \param p_parent the parent item to add into
476 * \param i_mode the mode used when addin
477 * \param i_pos the position in the playlist where to add. If this is
478 * PLAYLIST_END the item will be added at the end of the playlist
479 * regardless of its size
480 * \param b_locked TRUE if the playlist is locked
481 * \return the new playlist item
483 playlist_item_t * playlist_NodeAddInput( playlist_t *p_playlist,
484 input_item_t *p_input,
485 playlist_item_t *p_parent,
486 int i_mode, int i_pos,
489 playlist_item_t *p_item;
491 assert( p_parent && p_parent->i_children != -1 );
493 if( p_playlist->b_die )
495 if( !b_locked ) PL_LOCK;
497 p_item = playlist_ItemNewFromInput( p_playlist, p_input );
498 if( p_item == NULL ) return NULL;
499 AddItem( p_playlist, p_item, p_parent, i_mode, i_pos );
501 if( !b_locked ) PL_UNLOCK;
506 /*****************************************************************************
507 * Playlist item misc operations
508 *****************************************************************************/
513 * Transform an item to a node. Return the node in the category tree, or NULL
515 * This function must be entered without the playlist lock
516 * \param p_playlist the playlist object
517 * \param p_item the item to transform
518 * \param b_locked TRUE if the playlist is locked
519 * \return the item transform in a node
521 playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
522 playlist_item_t *p_item,
526 playlist_item_t *p_item_in_category;
528 * Find the input in CATEGORY.
530 * - change it to node
531 * - we'll return it at the end
532 * - If we are a direct child of onelevel root, change to node, else
533 * delete the input from ONELEVEL
534 * - If we don't find it, just change to node (we are probably in VLM)
537 * If we were in ONELEVEL, we thus retrieve the node in CATEGORY (will be
538 * useful for later BothAddInput )
541 if( !b_locked ) PL_LOCK;
543 /* Fast track the media library, no time to loose */
544 if( p_item == p_playlist->p_ml_category ) {
545 if( !b_locked ) PL_UNLOCK;
549 /** \todo First look if we don't already have it */
550 p_item_in_category = playlist_ItemFindFromInputAndRoot(
551 p_playlist, p_item->p_input->i_id,
552 p_playlist->p_root_category,
555 if( p_item_in_category )
557 playlist_item_t *p_item_in_one = playlist_ItemFindFromInputAndRoot(
558 p_playlist, p_item->p_input->i_id,
559 p_playlist->p_root_onelevel,
561 assert( p_item_in_one );
563 /* We already have it, and there is nothing more to do */
564 ChangeToNode( p_playlist, p_item_in_category );
566 /* Item in one is a root, change it to node */
567 if( p_item_in_one->p_parent == p_playlist->p_root_onelevel )
568 ChangeToNode( p_playlist, p_item_in_one );
571 DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id,
572 p_playlist->p_root_onelevel, false );
574 p_playlist->b_reset_currently_playing = true;
575 vlc_cond_signal( &p_playlist->object_wait );
576 var_SetInteger( p_playlist, "item-change", p_item_in_category->
578 if( !b_locked ) PL_UNLOCK;
579 return p_item_in_category;
583 ChangeToNode( p_playlist, p_item );
584 if( !b_locked ) PL_UNLOCK;
590 * Find an item within a root, given its input id.
592 * \param p_playlist the playlist object
593 * \param i_input_id id of the input
594 * \param p_root root playlist item
595 * \param b_items_only TRUE if we want the item himself
596 * \return the first found item, or NULL if not found
598 playlist_item_t *playlist_ItemFindFromInputAndRoot( playlist_t *p_playlist,
600 playlist_item_t *p_root,
604 for( i = 0 ; i< p_root->i_children ; i++ )
606 if( ( b_items_only ? p_root->pp_children[i]->i_children == -1 : 1 ) &&
607 p_root->pp_children[i]->p_input->i_id == i_input_id )
609 return p_root->pp_children[i];
611 else if( p_root->pp_children[i]->i_children >= 0 )
613 playlist_item_t *p_search =
614 playlist_ItemFindFromInputAndRoot( p_playlist, i_input_id,
615 p_root->pp_children[i],
617 if( p_search ) return p_search;
624 static int TreeMove( playlist_t *p_playlist, playlist_item_t *p_item,
625 playlist_item_t *p_node, int i_newpos )
628 playlist_item_t *p_detach = p_item->p_parent;
631 if( p_node->i_children == -1 ) return VLC_EGENERIC;
633 for( j = 0; j < p_detach->i_children; j++ )
635 if( p_detach->pp_children[j] == p_item ) break;
637 REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, j );
639 /* Attach to new parent */
640 INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
641 p_item->p_parent = p_node;
649 * This function must be entered with the playlist lock
651 * \param p_playlist the playlist
652 * \param p_item the item to move
653 * \param p_node the new parent of the item
654 * \param i_newpos the new position under this new parent
655 * \return VLC_SUCCESS or an error
657 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
658 playlist_item_t *p_node, int i_newpos )
661 /* Drop on a top level node. Move in the two trees */
662 if( p_node->p_parent == p_playlist->p_root_category ||
663 p_node->p_parent == p_playlist->p_root_onelevel )
665 /* Fixme: avoid useless lookups but we need some clean helpers */
667 /* Fixme: if we try to move a node on a top-level node, it will
668 * fail because the node doesn't exist in onelevel and we will
669 * do some shit in onelevel. We should recursively move all items
671 playlist_item_t *p_node_onelevel;
672 playlist_item_t *p_item_onelevel;
673 p_node_onelevel = playlist_ItemFindFromInputAndRoot( p_playlist,
674 p_node->p_input->i_id,
675 p_playlist->p_root_onelevel,
677 p_item_onelevel = playlist_ItemFindFromInputAndRoot( p_playlist,
678 p_item->p_input->i_id,
679 p_playlist->p_root_onelevel,
681 if( p_node_onelevel && p_item_onelevel )
682 TreeMove( p_playlist, p_item_onelevel, p_node_onelevel, 0 );
685 playlist_item_t *p_node_category;
686 playlist_item_t *p_item_category;
687 p_node_category = playlist_ItemFindFromInputAndRoot( p_playlist,
688 p_node->p_input->i_id,
689 p_playlist->p_root_category,
691 p_item_category = playlist_ItemFindFromInputAndRoot( p_playlist,
692 p_item->p_input->i_id,
693 p_playlist->p_root_category,
695 if( p_node_category && p_item_category )
696 TreeMove( p_playlist, p_item_category, p_node_category, 0 );
701 i_ret = TreeMove( p_playlist, p_item, p_node, i_newpos );
702 p_playlist->b_reset_currently_playing = true;
703 vlc_cond_signal( &p_playlist->object_wait );
708 * Send a notification that an item has been added to a node
710 * \param p_playlist the playlist object
711 * \param i_item_id id of the item added
712 * \param i_node_id id of the node in wich the item was added
713 * \param b_signal TRUE if the function must send a signal
716 void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
717 int i_node_id, bool b_signal )
720 playlist_add_t *p_add = (playlist_add_t *)malloc( sizeof( playlist_add_t) );
724 p_add->i_item = i_item_id;
725 p_add->i_node = i_node_id;
726 val.p_address = p_add;
727 p_playlist->b_reset_currently_playing = true;
729 vlc_cond_signal( &p_playlist->object_wait );
730 var_Set( p_playlist, "item-append", val );
734 /*****************************************************************************
735 * Playlist item accessors
736 *****************************************************************************/
739 * Set the name of a playlist item
741 * \param p_item the item
742 * \param psz_name the name
743 * \return VLC_SUCCESS or VLC_EGENERIC
745 int playlist_ItemSetName( playlist_item_t *p_item, const char *psz_name )
747 if( psz_name && p_item )
749 input_item_SetName( p_item->p_input, psz_name );
755 /***************************************************************************
756 * The following functions are local
757 ***************************************************************************/
759 /* Enqueue an item for preparsing, and play it, if needed */
760 static void GoAndPreparse( playlist_t *p_playlist, int i_mode,
761 playlist_item_t *p_item_cat,
762 playlist_item_t *p_item_one )
764 if( (i_mode & PLAYLIST_GO ) )
766 playlist_item_t *p_parent = p_item_one;
767 playlist_item_t *p_toplay = NULL;
770 if( p_parent == p_playlist->p_root_category )
772 p_toplay = p_item_cat; break;
774 else if( p_parent == p_playlist->p_root_onelevel )
776 p_toplay = p_item_one; break;
778 p_parent = p_parent->p_parent;
781 p_playlist->request.b_request = true;
782 p_playlist->request.i_skip = 0;
783 p_playlist->request.p_item = p_toplay;
784 if( p_playlist->p_input )
785 input_StopThread( p_playlist->p_input );
786 p_playlist->request.i_status = PLAYLIST_RUNNING;
787 vlc_cond_signal( &p_playlist->object_wait );
789 /* Preparse if PREPARSE or SPREPARSE & not enough meta */
790 char *psz_artist = input_item_GetArtist( p_item_cat->p_input );
791 char *psz_album = input_item_GetAlbum( p_item_cat->p_input );
792 if( p_playlist->b_auto_preparse &&
793 (i_mode & PLAYLIST_PREPARSE ||
794 ( i_mode & PLAYLIST_SPREPARSE &&
795 ( EMPTY_STR( psz_artist ) || ( EMPTY_STR( psz_album ) ) )
797 playlist_PreparseEnqueue( p_playlist, p_item_cat->p_input );
798 /* If we already have it, signal it */
799 else if( !EMPTY_STR( psz_artist ) && !EMPTY_STR( psz_album ) )
800 input_item_SetPreparsed( p_item_cat->p_input, true );
805 /* Add the playlist item to the requested node and fire a notification */
806 static void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
807 playlist_item_t *p_node, int i_mode, int i_pos )
809 ARRAY_APPEND(p_playlist->items, p_item);
810 ARRAY_APPEND(p_playlist->all_items, p_item);
812 if( i_pos == PLAYLIST_END )
813 playlist_NodeAppend( p_playlist, p_item, p_node );
815 playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
817 if( !p_playlist->b_doing_ml )
818 playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id,
819 !( i_mode & PLAYLIST_NO_REBUILD ) );
822 /* Actually convert an item to a node */
823 static void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
826 if( p_item->i_children == -1 )
827 p_item->i_children = 0;
829 /* Remove it from the array of available items */
830 ARRAY_BSEARCH( p_playlist->items,->i_id, int, p_item->i_id, i );
832 ARRAY_REMOVE( p_playlist->items, i );
835 /* Do the actual removal */
836 static int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
840 int i_id = p_item->i_id;
841 bool b_delay_deletion = false;
843 if( p_item->i_children > -1 )
845 return playlist_NodeDelete( p_playlist, p_item, true, false );
847 p_playlist->b_reset_currently_playing = true;
848 var_SetInteger( p_playlist, "item-deleted", i_id );
850 /* Remove the item from the bank */
851 ARRAY_BSEARCH( p_playlist->all_items,->i_id, int, i_id, i );
853 ARRAY_REMOVE( p_playlist->all_items, i );
855 ARRAY_BSEARCH( p_playlist->items,->i_id, int, i_id, i );
857 ARRAY_REMOVE( p_playlist->items, i );
859 /* Check if it is the current item */
860 if( p_playlist->status.p_item == p_item )
862 /* Hack we don't call playlist_Control for lock reasons */
865 p_playlist->request.i_status = PLAYLIST_STOPPED;
866 p_playlist->request.b_request = true;
867 p_playlist->request.p_item = NULL;
868 msg_Info( p_playlist, "stopping playback" );
869 vlc_cond_signal( &p_playlist->object_wait );
871 b_delay_deletion = true;
874 PL_DEBUG( "deleting item `%s'", p_item->p_input->psz_name );
876 /* Remove the item from its parent */
877 playlist_NodeRemoveItem( p_playlist, p_item, p_item->p_parent );
879 if( !b_delay_deletion )
880 playlist_ItemDelete( p_item );
883 PL_DEBUG( "marking %s for further deletion", PLI_NAME( p_item ) );
884 p_item->i_flags |= PLAYLIST_REMOVE_FLAG;