- p_item->psz_name = strdup( psz_name );
- p_item->psz_uri = strdup( psz_uri );
- p_item->i_duration = i_duration;
- p_item->i_type = 0;
- p_item->i_status = 0;
- p_item->b_autodeletion = VLC_FALSE;
-
- p_item->ppsz_options = NULL;
- p_item->i_options = i_options;
-
- if( i_options )
- {
- int i;
-
- p_item->ppsz_options = (char **)malloc( i_options * sizeof(char *) );
- for( i = 0; i < i_options; i++ )
- p_item->ppsz_options[i] = strdup( ppsz_options[i] );
-
- }
-
- return playlist_AddItem( p_playlist, p_item, i_mode, i_pos );
-}
-
-/**
- * Add a playlist item into a playlist
- *
- * \param p_playlist the playlist to insert into
- * \param p_item the playlist item to insert
- * \param i_mode the mode used when adding
- * \param i_pos the possition in the playlist where to add. If this is
- * PLAYLIST_END the item will be added at the end of the playlist
- * regardless of it's size
- * \return always returns 0
-*/
-int playlist_AddItem( playlist_t *p_playlist, playlist_item_t * p_item,
- int i_mode, int i_pos)
-{
- vlc_value_t val;
-
- vlc_mutex_lock( &p_playlist->object_lock );
-
- /*
- * CHECK_INSERT : checks if the item is already enqued before
- * enqueing it
- */
- if ( i_mode & PLAYLIST_CHECK_INSERT )
- {
- int j;
-
- if ( p_playlist->pp_items )
- {
- for ( j = 0; j < p_playlist->i_size; j++ )
- {
- if ( !strcmp( p_playlist->pp_items[j]->psz_uri, p_item->psz_uri ) )
- {
- if( p_item->psz_name )
- {
- free( p_item->psz_name );
- }
- if( p_item->psz_uri )
- {
- free( p_item->psz_uri );
- }
- free( p_item );
- vlc_mutex_unlock( &p_playlist->object_lock );
- return 0;
- }
- }
- }
- i_mode &= ~PLAYLIST_CHECK_INSERT;
- i_mode |= PLAYLIST_APPEND;
- }
-
-
- msg_Dbg( p_playlist, "adding playlist item « %s » ( %s )", p_item->psz_name, p_item->psz_uri);
-
- /* Create the new playlist item */
-
-
- /* Do a few boundary checks and allocate space for the item */
- if( i_pos == PLAYLIST_END )
- {
- if( i_mode & PLAYLIST_INSERT )
- {
- i_mode &= ~PLAYLIST_INSERT;
- i_mode |= PLAYLIST_APPEND;
- }
-
- i_pos = p_playlist->i_size - 1;
- }
-
- if( !(i_mode & PLAYLIST_REPLACE)
- || i_pos < 0 || i_pos >= p_playlist->i_size )
- {
- /* Additional boundary checks */
- if( i_mode & PLAYLIST_APPEND )
- {
- i_pos++;
- }
-
- if( i_pos < 0 )
- {
- i_pos = 0;
- }
- else if( i_pos > p_playlist->i_size )
- {
- i_pos = p_playlist->i_size;
- }