+ playlist_ItemRelease( p_item );
+
+ return VLC_SUCCESS;
+}
+
+static int RecursiveAddIntoParent (
+ playlist_t *p_playlist, playlist_item_t *p_parent,
+ input_item_node_t *p_node, int i_pos, bool b_flat,
+ playlist_item_t **pp_first_leaf )
+{
+ if( p_parent->i_children == -1 ) ChangeToNode( p_playlist, p_parent );
+
+ if( i_pos == PLAYLIST_END ) i_pos = p_parent->i_children;
+
+ for( int i = 0; i < p_node->i_children; i++ )
+ {
+ playlist_item_t *p_child = NULL;
+ if( b_flat ? p_node->pp_children[i]->i_children == 0 : 1 )
+ {
+ p_child = playlist_NodeAddInput( p_playlist,
+ p_node->pp_children[i]->p_item,
+ p_parent,
+ PLAYLIST_INSERT, i_pos,
+ pl_Locked );
+ i_pos++;
+ }
+ if( p_node->pp_children[i]->i_children > 0 )
+ {
+ if( b_flat )
+ {
+ i_pos = RecursiveAddIntoParent(
+ p_playlist, p_parent,
+ p_node->pp_children[i], i_pos, true,
+ &p_child );
+ }
+ else
+ {
+ RecursiveAddIntoParent( p_playlist, p_child,
+ p_node->pp_children[i], 0, false,
+ &p_child );
+ }
+ }
+ assert( p_child != NULL );
+ if( i == 0 ) *pp_first_leaf = p_child;
+ }
+ return i_pos;
+}
+
+static int RecursiveInsertCopy (
+ playlist_t *p_playlist, playlist_item_t *p_item,
+ playlist_item_t *p_parent, int i_pos, bool b_flat )
+{
+ PL_ASSERT_LOCKED;
+ assert( p_parent != NULL && p_item != NULL );
+
+ if( p_item == p_parent ) return i_pos;
+
+ input_item_t *p_input = p_item->p_input;
+
+ if( !(p_item->i_children != -1 && b_flat) )
+ {
+ input_item_t *p_new_input = input_item_Copy( VLC_OBJECT(p_playlist),
+ p_input );
+ if( !p_new_input ) return i_pos;
+
+ playlist_item_t *p_new_item = NULL;
+ if( p_item->i_children == -1 )
+ p_new_item = playlist_NodeAddInput( p_playlist, p_new_input,
+ p_parent, PLAYLIST_INSERT, i_pos,
+ pl_Locked );
+ else
+ p_new_item = playlist_NodeCreate( p_playlist, NULL,
+ p_parent, i_pos, 0, p_new_input );
+ vlc_gc_decref( p_new_input );
+ if( !p_new_item ) return i_pos;
+
+ i_pos++;
+
+ if( p_new_item->i_children != -1 )
+ p_parent = p_new_item;
+ }
+
+ for( int i = 0; i < p_item->i_children; i++ )