Commit 3fc7cdd5 authored by sigmunau's avatar sigmunau
Browse files

playlist/item.c, include/vlc_playlist.h: introduced playlist_ItemCopy

playlist/item-ext.c: O(log(N)) playlist_GetItemById()
parent 0b014101
......@@ -267,7 +267,9 @@ VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const
/* Item management functions (act on items) */
#define playlist_AddItem(p,pi,i1,i2) playlist_ItemAdd(p,pi,i1,i2)
#define playlist_ItemNew( a , b, c ) __playlist_ItemNew(VLC_OBJECT(a) , b , c )
#define playlist_ItemCopy( a, b ) __playlist_ItemCopy(VLC_OBJECT(a), b )
VLC_EXPORT( playlist_item_t* , __playlist_ItemNew, ( vlc_object_t *,const char *,const char * ) );
VLC_EXPORT( playlist_item_t* , __playlist_ItemCopy, ( vlc_object_t *,playlist_item_t* ) );
VLC_EXPORT( playlist_item_t* , playlist_ItemNewWithType, ( vlc_object_t *,const char *,const char *, int ) );
VLC_EXPORT( int, playlist_ItemDelete, ( playlist_item_t * ) );
VLC_EXPORT( int, playlist_ItemAddParent, ( playlist_item_t *, int,playlist_item_t *) );
......
......@@ -460,13 +460,25 @@ playlist_item_t *playlist_LockItemGetByPos( playlist_t *p_playlist, int i_pos )
*/
playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id )
{
int i;
for( i = 0 ; i < p_playlist->i_all_size ; i++ )
int i, i_top, i_bottom;
i_bottom = 0; i_top = p_playlist->i_all_size;
i = i_top / 2;
while( p_playlist->pp_all_items[i]->input.i_id != i_id &&
i_top > i_bottom )
{
if( p_playlist->pp_all_items[i]->input.i_id == i_id )
if( p_playlist->pp_all_items[i]->input.i_id < i_id )
{
i_bottom = i;
}
else
{
return p_playlist->pp_all_items[i];
i_top = i;
}
i = i_bottom + ( i_top - i_bottom ) / 2;
}
if( p_playlist->pp_all_items[i]->input.i_id == i_id )
{
return p_playlist->pp_all_items[i];
}
return NULL;
}
......
......@@ -92,6 +92,87 @@ playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj,
return p_item;
}
/**
* Copy a playlist item
*
* Creates a new item with name, mrl and meta infor like the
* source. Does not copy children for node type items.
* \param p_obj any vlc object, needed for mutex init
* \param p_item the item to copy
* \return pointer to the new item, or NULL on error
* \note function takes the lock on p_item
*/
playlist_item_t *__playlist_ItemCopy( vlc_object_t *p_obj,
playlist_item_t *p_item )
{
playlist_item_t *p_res;
int i;
vlc_mutex_lock( &p_item->input.lock );
p_res = malloc( sizeof( playlist_item_t ) );
if( p_res == NULL )
{
vlc_mutex_unlock( &p_item->input.lock );
return NULL;
}
memcpy( p_res, p_item, sizeof(playlist_item_t) );
vlc_mutex_init( p_obj, &p_res->input.lock );
p_res->input.ppsz_options = malloc( p_item->input.i_options * sizeof(char*));
for( i = 0; i < p_item->input.i_options; i++ )
{
p_res->input.ppsz_options[i] = strdup( p_item->input.ppsz_options[i] );
}
if( p_item->i_children != -1 )
{
msg_Warn( p_obj, "not copying playlist items children" );
p_res->i_children = -1;
p_res->pp_children = NULL;
}
p_res->i_parents = 0;
p_res->pp_parents = NULL;
if( p_item->input.psz_name )
p_res->input.psz_name = strdup( p_item->input.psz_name );
if( p_item->input.psz_uri )
p_res->input.psz_uri = strdup( p_item->input.psz_uri );
if( p_item->input.i_es )
{
p_res->input.es = (es_format_t**)malloc( p_item->input.i_es * sizeof(es_format_t*));
for( i = 0; i < p_item->input.i_es; i++ )
{
p_res->input.es[ i ] = (es_format_t*)malloc(sizeof(es_format_t*));
es_format_Copy( p_res->input.es[ i ],
p_item->input.es[ i ] );
}
}
if( p_item->input.i_categories )
{
p_res->input.pp_categories = NULL;
p_res->input.i_categories = 0;
for( i = 0; i < p_item->input.i_categories; i++ )
{
info_category_t *p_incat;
p_incat = p_item->input.pp_categories[i];
if( p_incat->i_infos )
{
int j;
for( j = 0; j < p_incat->i_infos; j++ )
{
vlc_input_item_AddInfo( &p_res->input, p_incat->psz_name,
p_incat->pp_infos[j]->psz_name,
"%s", /* to be safe */
p_incat->pp_infos[j]->psz_value );
}
}
}
}
vlc_mutex_unlock( &p_item->input.lock );
return p_res;
}
/**
* Deletes a playlist item
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment