Commit 799b2826 authored by Clément Stenac's avatar Clément Stenac

Playlist

 * Remove the random special case
 * Use the array of currently playing items for all cases
 * Convert array items to array API
 * Replace standard searches in sorted arrays by bsearches
 * Size is not yet fixed (next round).

Array
 * Add reset/value and bsearch functions
 * Add foreach helper
parent c925ed56
...@@ -118,7 +118,7 @@ ...@@ -118,7 +118,7 @@
} }
/** /**
* Binary search in an array * Binary search in a sorted array. The key must be comparable by < and >
* \param entries array of entries * \param entries array of entries
* \param count number of entries * \param count number of entries
* \param elem key to check within an entry (like .id, or ->i_id) * \param elem key to check within an entry (like .id, or ->i_id)
...@@ -218,6 +218,11 @@ VLC_EXPORT( int, vlc_DictLookup, (dict_t *, int, const char * ) ); ...@@ -218,6 +218,11 @@ VLC_EXPORT( int, vlc_DictLookup, (dict_t *, int, const char * ) );
array.i_size = 0; \ array.i_size = 0; \
array.p_elems = NULL; array.p_elems = NULL;
#define ARRAY_RESET(array) \
array.i_alloc = 0; \
array.i_size = 0; \
free( array.p_elems ); array.p_elems = NULL;
#define ARRAY_APPEND(array, elem) { \ #define ARRAY_APPEND(array, elem) { \
_ARRAY_GROW1(array); \ _ARRAY_GROW1(array); \
array.p_elems[array.i_size] = elem; \ array.p_elems[array.i_size] = elem; \
...@@ -244,4 +249,17 @@ VLC_EXPORT( int, vlc_DictLookup, (dict_t *, int, const char * ) ); ...@@ -244,4 +249,17 @@ VLC_EXPORT( int, vlc_DictLookup, (dict_t *, int, const char * ) );
_ARRAY_SHRINK(array); \ _ARRAY_SHRINK(array); \
} }
#define ARRAY_VAL(array, pos) array.p_elems[pos]
#define ARRAY_BSEARCH(array, elem, zetype, key, answer) \
BSEARCH( array.p_elems, array.i_size, elem, zetype, key, answer)
#define FOREACH_ARRAY( item, array ) { \
int fe_idx; \
for( fe_idx = 0 ; fe_idx < array.i_size ; fe_idx++ ) \
{ \
item = array.p_elems[fe_idx];
#define FOREACH_END() } }
#endif #endif
...@@ -26,13 +26,13 @@ ...@@ -26,13 +26,13 @@
#include <assert.h> #include <assert.h>
TYPEDEF_ARRAY(playlist_item_t*, playlist_item_array_t);
TYPEDEF_ARRAY(input_item_t*, input_item_array_t);
/** /**
* \file * \file
* This file contain structures and function prototypes related * This file contain structures and function prototypes related
* to the playlist in vlc * to the playlist in vlc
*/ *
/**
* \defgroup vlc_playlist Playlist * \defgroup vlc_playlist Playlist
* @{ * @{
*/ */
...@@ -102,20 +102,15 @@ struct playlist_t ...@@ -102,20 +102,15 @@ struct playlist_t
/*@{*/ /*@{*/
int i_enabled; /**< How many items are enabled ? */ int i_enabled; /**< How many items are enabled ? */
/* Arrays of items */ playlist_item_array_t items; /**< Arrays of items */
int i_size; /**< total size of the list */ playlist_item_array_t all_items; /**< Array of items and nodes */
playlist_item_t ** pp_items; /**< array of pointers to the
* playlist items */ input_item_array_t input_items; /**< Array of input items */
int i_all_size; /**< size of list of items and nodes */
playlist_item_t ** pp_all_items; /**< array of pointers to the playlist_item_array_t current; /**< Items currently being played */
* playlist items and nodes */ int i_current_index; /**< Index in current array */
int i_input_items; /** Reset current item ? */
input_item_t ** pp_input_items; vlc_bool_t b_reset_currently_playing;
int i_random; /**< Number of candidates for random */
playlist_item_t ** pp_random; /**< Random candidate items */
int i_random_index; /**< Current random item */
vlc_bool_t b_reset_random; /**< Recreate random array ?*/
int i_last_playlist_id; /**< Last id to an item */ int i_last_playlist_id; /**< Last id to an item */
int i_last_input_id ; /**< Last id on an input */ int i_last_input_id ; /**< Last id on an input */
...@@ -433,7 +428,7 @@ static inline vlc_bool_t playlist_IsEmpty( playlist_t * p_playlist ) ...@@ -433,7 +428,7 @@ static inline vlc_bool_t playlist_IsEmpty( playlist_t * p_playlist )
{ {
vlc_bool_t b_empty; vlc_bool_t b_empty;
vlc_mutex_lock( &p_playlist->object_lock ); vlc_mutex_lock( &p_playlist->object_lock );
b_empty = p_playlist->i_size == 0; b_empty = p_playlist->items.i_size == 0;
vlc_mutex_unlock( &p_playlist->object_lock ); vlc_mutex_unlock( &p_playlist->object_lock );
return( b_empty ); return( b_empty );
} }
......
...@@ -796,13 +796,13 @@ static void PlayBookmark( intf_thread_t *p_intf, int i_num ) ...@@ -796,13 +796,13 @@ static void PlayBookmark( intf_thread_t *p_intf, int i_num )
var_Get( p_intf, psz_bookmark_name, &val ); var_Get( p_intf, psz_bookmark_name, &val );
char *psz_bookmark = strdup( val.psz_string ); char *psz_bookmark = strdup( val.psz_string );
for( i = 0; i < p_playlist->i_size; i++) for( i = 0; i < p_playlist->items.i_size; i++)
{ {
if( !strcmp( psz_bookmark, if( !strcmp( psz_bookmark,
p_playlist->pp_items[i]->p_input->psz_uri ) ) ARRAY_VAL( p_playlist->items,i )->p_input->psz_uri ) )
{ {
playlist_LockControl( p_playlist, PLAYLIST_VIEWPLAY, NULL, playlist_LockControl( p_playlist, PLAYLIST_VIEWPLAY, NULL,
p_playlist->pp_items[i] ); ARRAY_VAL( p_playlist->items, i ) );
break; break;
} }
} }
......
...@@ -398,19 +398,20 @@ void E_(MacroDo)( httpd_file_sys_t *p_args, ...@@ -398,19 +398,20 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
i_nb_items++; i_nb_items++;
} }
for( i = p_sys->p_playlist->i_size - 1 ; i >= 0; i-- ) for( i = p_sys->p_playlist->items.i_size - 1 ; i >= 0; i-- )
{ {
/* Check if the item is in the keep list */ /* Check if the item is in the keep list */
for( j = 0 ; j < i_nb_items ; j++ ) for( j = 0 ; j < i_nb_items ; j++ )
{ {
if( p_items[j] == if( p_items[j] ==
p_sys->p_playlist->pp_items[i]->p_input->i_id ) ARRAY_VAL(p_sys->p_playlist->items,i)
->p_input->i_id)
break; break;
} }
if( j == i_nb_items ) if( j == i_nb_items )
{ {
playlist_LockDeleteAllFromInput( p_sys->p_playlist, playlist_LockDeleteAllFromInput( p_sys->p_playlist,
p_sys->p_playlist->pp_items[i]->p_input->i_id ); p_sys->p_playlist->items.p_elems[i]->p_input->i_id );
msg_Dbg( p_intf, "requested playlist delete: %d", msg_Dbg( p_intf, "requested playlist delete: %d",
i ); i );
} }
......
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
playlist_t * p_playlist = pl_Yield( p_intf ); playlist_t * p_playlist = pl_Yield( p_intf );
vlc_mutex_lock( &p_playlist->object_lock ); vlc_mutex_lock( &p_playlist->object_lock );
if( p_playlist->i_size <= 0 ) if( playlist_IsEmpty( p_playlist ) )
{ {
vlc_mutex_unlock( &p_playlist->object_lock ); vlc_mutex_unlock( &p_playlist->object_lock );
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
...@@ -812,7 +812,8 @@ ...@@ -812,7 +812,8 @@
else if( [[o_mi title] isEqualToString: _NS("Previous")] || else if( [[o_mi title] isEqualToString: _NS("Previous")] ||
[[o_mi title] isEqualToString: _NS("Next")] ) [[o_mi title] isEqualToString: _NS("Next")] )
{ {
bEnabled = p_playlist->i_size > 1; /** \todo fix i_size use */
bEnabled = p_playlist->items.i_size > 1;
} }
else if( [[o_mi title] isEqualToString: _NS("Random")] ) else if( [[o_mi title] isEqualToString: _NS("Random")] )
{ {
......
...@@ -1067,7 +1067,8 @@ static VLCMain *_o_sharedMainInstance = nil; ...@@ -1067,7 +1067,8 @@ static VLCMain *_o_sharedMainInstance = nil;
vlc_bool_t b_chapters = VLC_FALSE; vlc_bool_t b_chapters = VLC_FALSE;
playlist_t * p_playlist = pl_Yield( p_intf ); playlist_t * p_playlist = pl_Yield( p_intf );
b_plmul = p_playlist->i_size > 1; /** \todo fix i_size use */
b_plmul = p_playlist->items.i_size > 1;
vlc_object_release( p_playlist ); vlc_object_release( p_playlist );
......
...@@ -464,14 +464,15 @@ NSLog( @"expandable" ); ...@@ -464,14 +464,15 @@ NSLog( @"expandable" );
playlist_t *p_playlist = pl_Yield( VLCIntf ); playlist_t *p_playlist = pl_Yield( VLCIntf );
if( p_playlist->i_size >= 2 ) /** \todo fix i_size use */
if( p_playlist->items.i_size >= 2 )
{ {
[o_status_field setStringValue: [NSString stringWithFormat: [o_status_field setStringValue: [NSString stringWithFormat:
_NS("%i items in the playlist"), p_playlist->i_size]]; _NS("%i items in the playlist"), p_playlist->items.i_size]];
} }
else else
{ {
if( p_playlist->i_size == 0 ) if( playlist_IsEmpty( p_playlist ) )
{ {
[o_status_field setStringValue: _NS("No items in the playlist")]; [o_status_field setStringValue: _NS("No items in the playlist")];
} }
...@@ -1366,15 +1367,15 @@ NSLog( @"expandable" ); ...@@ -1366,15 +1367,15 @@ NSLog( @"expandable" );
/* FIXME: playlist->i_size doesn't provide the correct number of items anymore /* FIXME: playlist->i_size doesn't provide the correct number of items anymore
* check the playlist API for the fixed function, once zorglub implemented it -- fpk, 9/17/06 */ * check the playlist API for the fixed function, once zorglub implemented it -- fpk, 9/17/06 */
/** \todo fix i_size use */
if( p_playlist->i_size >= 2 ) if( p_playlist->items.i_size >= 2 )
{ {
[o_status_field setStringValue: [NSString stringWithFormat: [o_status_field setStringValue: [NSString stringWithFormat:
_NS("%i items in the playlist"), p_playlist->i_size]]; _NS("%i items in the playlist"), p_playlist->items.i_size]];
} }
else else
{ {
if( p_playlist->i_size == 0 ) if( playlist_IsEmpty( p_playlist ) )
{ {
[o_status_field setStringValue: _NS("No items in the playlist")]; [o_status_field setStringValue: _NS("No items in the playlist")];
} }
......
...@@ -556,7 +556,7 @@ void MainInterface::stop() ...@@ -556,7 +556,7 @@ void MainInterface::stop()
} }
void MainInterface::play() void MainInterface::play()
{ {
if( !THEPL->i_size || !THEPL->i_enabled ) if( !playlist_IsEmpty(THEPL) || !THEPL->i_enabled )
{ {
/* The playlist is empty, open a file requester */ /* The playlist is empty, open a file requester */
THEDP->simpleOpenDialog(); THEDP->simpleOpenDialog();
......
...@@ -354,7 +354,7 @@ QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf ) ...@@ -354,7 +354,7 @@ QMenu *QVLCMenu::SDMenu( intf_thread_t *p_intf )
else \ else \
MIM_SADD( qtr("Pause"), "", "", togglePlayPause() ) \ MIM_SADD( qtr("Pause"), "", "", togglePlayPause() ) \
} \ } \
else if( THEPL->i_size && THEPL->i_enabled ) \ else if( THEPL->items.i_size && THEPL->i_enabled ) \
MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \ MIM_SADD( qtr("Play"), "", "", togglePlayPause() ) \
\ \
QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \ QMenu *intfmenu = InterfacesMenu( p_intf, NULL ); \
......
...@@ -35,10 +35,8 @@ void CmdPlay::execute() ...@@ -35,10 +35,8 @@ void CmdPlay::execute()
return; return;
} }
if( pPlaylist->i_size ) if( !playlist_IsEmpty( pPlaylist ) )
{
playlist_Play( pPlaylist ); playlist_Play( pPlaylist );
}
else else
{ {
// If the playlist is empty, open a file requester instead // If the playlist is empty, open a file requester instead
......
...@@ -220,7 +220,7 @@ mediacontrol_start( mediacontrol_Instance *self, ...@@ -220,7 +220,7 @@ mediacontrol_start( mediacontrol_Instance *self,
} }
vlc_mutex_lock( &p_playlist->object_lock ); vlc_mutex_lock( &p_playlist->object_lock );
if( p_playlist->i_size ) if( p_playlist->items.i_size )
{ {
int i_from; int i_from;
char *psz_from = NULL; char *psz_from = NULL;
...@@ -360,13 +360,13 @@ mediacontrol_playlist_get_list( mediacontrol_Instance *self, ...@@ -360,13 +360,13 @@ mediacontrol_playlist_get_list( mediacontrol_Instance *self,
} }
vlc_mutex_lock( &p_playlist->object_lock ); vlc_mutex_lock( &p_playlist->object_lock );
i_playlist_size = p_playlist->i_size; i_playlist_size = p_playlist->items.i_size;
retval = mediacontrol_PlaylistSeq__alloc( i_playlist_size ); retval = mediacontrol_PlaylistSeq__alloc( i_playlist_size );
for( i_index = 0 ; i_index < i_playlist_size ; i_index++ ) for( i_index = 0 ; i_index < i_playlist_size ; i_index++ )
{ {
retval->data[i_index] = strdup( p_playlist->pp_items[i_index]->p_input->psz_uri ); retval->data[i_index] = strdup( ARRAY_VAL(p_playlist->items, i_index)->p_input->psz_uri );
} }
vlc_mutex_unlock( &p_playlist->object_lock ); vlc_mutex_unlock( &p_playlist->object_lock );
......
...@@ -44,7 +44,7 @@ void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id, ...@@ -44,7 +44,7 @@ void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id,
assert( PL ); assert( PL );
///\todo Handle additionnal options ///\todo Handle additionnal options
if( PL->i_size == 0 ) RAISEVOID( "Empty playlist" ); if( PL->items.i_size == 0 ) RAISEVOID( "Empty playlist" );
if( i_id > 0 ) if( i_id > 0 )
{ {
playlist_item_t *p_item = playlist_ItemGetById( PL, playlist_item_t *p_item = playlist_ItemGetById( PL,
...@@ -136,7 +136,7 @@ int libvlc_playlist_items_count( libvlc_instance_t *p_instance, ...@@ -136,7 +136,7 @@ int libvlc_playlist_items_count( libvlc_instance_t *p_instance,
libvlc_exception_t *p_e ) libvlc_exception_t *p_e )
{ {
assert( PL ); assert( PL );
return PL->i_size; return PL->items.i_size;
} }
libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance, libvlc_input_t * libvlc_playlist_get_input( libvlc_instance_t *p_instance,
......
...@@ -76,15 +76,10 @@ static void input_ItemDestroy ( gc_object_t *p_this ) ...@@ -76,15 +76,10 @@ static void input_ItemDestroy ( gc_object_t *p_this )
playlist_t *p_playlist = pl_Yield( p_obj ); playlist_t *p_playlist = pl_Yield( p_obj );
input_ItemClean( p_input ); input_ItemClean( p_input );
for( i = 0 ; i< p_playlist->i_input_items ; i++ ) ARRAY_BSEARCH( p_playlist->input_items,->i_id, int, p_input->i_id, i);
{ if( i != -1 )
if( p_playlist->pp_input_items[i]->i_id == p_input->i_id ) ARRAY_REMOVE( p_playlist->input_items, i);
{
REMOVE_ELEM( p_playlist->pp_input_items,
p_playlist->i_input_items, i );
break;
}
}
pl_Release( p_obj ); pl_Release( p_obj );
free( p_input ); free( p_input );
} }
...@@ -186,22 +181,10 @@ int input_ItemAddInfo( input_item_t *p_i, ...@@ -186,22 +181,10 @@ int input_ItemAddInfo( input_item_t *p_i,
input_item_t *input_ItemGetById( playlist_t *p_playlist, int i_id ) input_item_t *input_ItemGetById( playlist_t *p_playlist, int i_id )
{ {
int i, i_top, i_bottom; int i;
i_bottom = 0; i_top = p_playlist->i_input_items -1; ARRAY_BSEARCH( p_playlist->input_items, ->i_id, int, i_id, i);
i = i_top /2 ; if( i != -1 )
while( p_playlist->pp_input_items[i]->i_id != i_id && return ARRAY_VAL( p_playlist->input_items, i);
i_top > i_bottom )
{
if( p_playlist->pp_input_items[i]->i_id < i_id )
i_bottom = i + 1;
else
i_top = i - 1;
i = i_bottom + ( i_top - i_bottom ) / 2;
}
if( p_playlist->pp_input_items[i]->i_id == i_id )
{
return p_playlist->pp_input_items[i];
}
return NULL; return NULL;
} }
...@@ -228,9 +211,7 @@ input_item_t *input_ItemNewWithType( vlc_object_t *p_obj, const char *psz_uri, ...@@ -228,9 +211,7 @@ input_item_t *input_ItemNewWithType( vlc_object_t *p_obj, const char *psz_uri,
PL_LOCK; PL_LOCK;
p_input->i_id = ++p_playlist->i_last_input_id; p_input->i_id = ++p_playlist->i_last_input_id;
TAB_APPEND( p_playlist->i_input_items, ARRAY_APPEND( p_playlist->input_items, p_input );
p_playlist->pp_input_items,
p_input );
PL_UNLOCK; PL_UNLOCK;
pl_Release( p_obj ); pl_Release( p_obj );
......
...@@ -670,7 +670,7 @@ int VLC_PlaylistNumberOfItems( int i_object ) ...@@ -670,7 +670,7 @@ int VLC_PlaylistNumberOfItems( int i_object )
{ {
int i_size; int i_size;
LIBVLC_PLAYLIST_FUNC; LIBVLC_PLAYLIST_FUNC;
i_size = p_libvlc->p_playlist->i_size; i_size = p_libvlc->p_playlist->items.i_size;
LIBVLC_PLAYLIST_FUNC_END; LIBVLC_PLAYLIST_FUNC_END;
return i_size; return i_size;
} }
......
This diff is collapsed.
...@@ -34,6 +34,13 @@ ...@@ -34,6 +34,13 @@
*****************************************************************************/ *****************************************************************************/
static void VariablesInit( playlist_t *p_playlist ); static void VariablesInit( playlist_t *p_playlist );
static int RandomCallback( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *a )
{
((playlist_t*)p_this)->b_reset_currently_playing = VLC_TRUE;
return VLC_SUCCESS;
}
/** /**
* Create playlist * Create playlist
* *
...@@ -66,18 +73,13 @@ playlist_t * playlist_Create( vlc_object_t *p_parent ) ...@@ -66,18 +73,13 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
p_playlist->i_vout_destroyed_date = 0; p_playlist->i_vout_destroyed_date = 0;
p_playlist->i_sout_destroyed_date = 0; p_playlist->i_sout_destroyed_date = 0;
p_playlist->i_size = 0; ARRAY_INIT( p_playlist->items );
p_playlist->pp_items = NULL; ARRAY_INIT( p_playlist->all_items );
p_playlist->i_all_size = 0; ARRAY_INIT( p_playlist->input_items );
p_playlist->pp_all_items = NULL; ARRAY_INIT( p_playlist->current );
p_playlist->i_input_items = 0; p_playlist->i_current_index = 0;
p_playlist->pp_input_items = NULL; p_playlist->b_reset_currently_playing = VLC_TRUE;
p_playlist->i_random = 0;
p_playlist->pp_random = NULL;
p_playlist->i_random_index = 0;
p_playlist->b_reset_random = VLC_TRUE;
i_tree = var_CreateGetBool( p_playlist, "playlist-tree" ); i_tree = var_CreateGetBool( p_playlist, "playlist-tree" );
p_playlist->b_always_tree = (i_tree == 1); p_playlist->b_always_tree = (i_tree == 1);
...@@ -162,10 +164,24 @@ void playlist_Destroy( playlist_t *p_playlist ) ...@@ -162,10 +164,24 @@ void playlist_Destroy( playlist_t *p_playlist )
var_Destroy( p_playlist, "activity" ); var_Destroy( p_playlist, "activity" );
PL_LOCK; PL_LOCK;
playlist_NodeDelete( p_playlist, p_playlist->p_root_category, VLC_TRUE, /* Go through all items, and simply free everything without caring
VLC_TRUE ); * about the tree structure. Do not decref, it will be done by doing
playlist_NodeDelete( p_playlist, p_playlist->p_root_onelevel, VLC_TRUE, * the same thing on the input items array */
VLC_TRUE ); FOREACH_ARRAY( playlist_item_t *p_del, p_playlist->all_items )
free( p_del->pp_children );
free( p_del );
FOREACH_END();
ARRAY_RESET( p_playlist->all_items );
FOREACH_ARRAY( input_item_t *p_del, p_playlist->input_items )
input_ItemClean( p_del );
free( p_del );
FOREACH_END();
ARRAY_RESET( p_playlist->input_items );
ARRAY_RESET( p_playlist->items );
ARRAY_RESET( p_playlist->current );
PL_UNLOCK; PL_UNLOCK;
if( p_playlist->p_stats ) if( p_playlist->p_stats )
...@@ -635,4 +651,6 @@ static void VariablesInit( playlist_t *p_playlist ) ...@@ -635,4 +651,6 @@ static void VariablesInit( playlist_t *p_playlist )
var_CreateGetBool( p_playlist, "random" ); var_CreateGetBool( p_playlist, "random" );
var_CreateGetBool( p_playlist, "repeat" ); var_CreateGetBool( p_playlist, "repeat" );
var_CreateGetBool( p_playlist, "loop" ); var_CreateGetBool( p_playlist, "loop" );
var_AddCallback( p_playlist, "random", RandomCallback, NULL );
} }
...@@ -403,7 +403,7 @@ playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist, ...@@ -403,7 +403,7 @@ playlist_item_t *playlist_ItemToNode( playlist_t *p_playlist,
playlist_DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id, playlist_DeleteFromInput( p_playlist, p_item_in_one->p_input->i_id,
p_playlist->p_root_onelevel, VLC_FALSE ); p_playlist->p_root_onelevel, VLC_FALSE );
} }
p_playlist->b_reset_random = VLC_TRUE; p_playlist->b_reset_currently_playing = VLC_TRUE;
var_SetInteger( p_playlist, "item-change", p_item_in_category-> var_SetInteger( p_playlist, "item-change", p_item_in_category->
p_input->i_id ); p_input->i_id );
return p_item_in_category; return p_item_in_category;
...@@ -544,7 +544,7 @@ void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id, ...@@ -544,7 +544,7 @@ void playlist_SendAddNotify( playlist_t *p_playlist, int i_item_id,
p_add->i_item = i_item_id; p_add->i_item = i_item_id;
p_add->i_node = i_node_id; p_add->i_node = i_node_id;
val.p_address = p_add; val.p_address = p_add;
p_playlist->b_reset_random = VLC_TRUE; p_playlist->b_reset_currently_playing = VLC_TRUE;
var_Set( p_playlist, "item-append", val ); var_Set( p_playlist, "item-append", val );
free( p_add ); free( p_add );
} }
...@@ -610,20 +610,15 @@ void GoAndPreparse( playlist_t *p_playlist, int i_mode, ...@@ -610,20 +610,15 @@ void GoAndPreparse( playlist_t *p_playlist, int i_mode,
void AddItem( playlist_t *p_playlist, playlist_item_t *p_item, void AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
playlist_item_t *p_node, int i_pos ) playlist_item_t *p_node, int i_pos )
{ {
INSERT_ELEM( p_playlist->pp_items, p_playlist->i_size, ARRAY_APPEND(p_playlist->items, p_item);
p_playlist->i_size, p_item ); ARRAY_APPEND(p_playlist->all_items, p_item);
INSERT_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size,
p_playlist->i_all_size, p_item );
p_playlist->i_enabled ++; p_playlist->i_enabled ++;
if( i_pos == PLAYLIST_END ) if( i_pos == PLAYLIST_END )
{
playlist_NodeAppend( p_playlist, p_item, p_node ); playlist_NodeAppend( p_playlist, p_item, p_node );
}
else else
{
playlist_NodeInsert( p_playlist, p_item, p_node, i_pos ); playlist_NodeInsert( p_playlist, p_item, p_node, i_pos );
}
if( !p_playlist->b_doing_ml ) if( !p_playlist->b_doing_ml )
playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id ); playlist_SendAddNotify( p_playlist, p_item->i_id, p_node->i_id );
} }
...@@ -636,20 +631,16 @@ void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item ) ...@@ -636,20 +631,16 @@ void ChangeToNode( playlist_t *p_playlist, playlist_item_t *p_item )
p_item->i_children = 0; p_item->i_children = 0;
/* Remove it from the array of available items */ /* Remove it from the array of available items */
for( i = 0 ; i < p_playlist->i_size ; i++ ) ARRAY_BSEARCH( p_playlist->items,->i_id, int, p_item->i_id, i );
{ if( i != -1 )
if( p_item == p_playlist->pp_items[i] ) ARRAY_REMOVE( p_playlist->items, i );
{
REMOVE_ELEM( p_playlist->pp_items, p_playlist->i_size, i );
}
}
} }
/* Do the actual removal */ /* Do the actual removal */
int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item, int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
vlc_bool_t b_stop ) vlc_bool_t b_stop )
{ {
int i, i_top, i_bottom; int i;
int i_id = p_item->i_id; int i_id = p_item->i_id;
vlc_bool_t b_flag = VLC_FALSE; vlc_bool_t b_flag = VLC_FALSE;
...@@ -657,29 +648,13 @@ int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item, ...@@ -657,29 +648,13 @@ int DeleteInner( playlist_t * p_playlist, playlist_item_t *p_item,
{ {
return playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE ); return playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
} }
p_playlist->b_reset_random = VLC_TRUE; p_playlist->b_reset_currently_playing = VLC_TRUE;
var_SetInteger( p_playlist, "item-deleted", i_id ); var_SetInteger( p_playlist, "item-deleted", i_id );
/* Remove the item from the bank */ /* Remove the item from the bank */
i_bottom = 0; i_top = p_playlist->i_all_size - 1; ARRAY_BSEARCH( p_playlist->all_items,->i_id, int, i_id, i );
i = i_top / 2; if( i != -1 )
while( p_playlist->pp_all_items[i]->i_id != i_id && ARRAY_REMOVE( p_playlist->all_items, i );
i_top > i_bottom )
{
if( p_playlist->pp_all_items[i]->i_id < i_id )
{
i_bottom = i + 1;
}
else
{
i_top = i - 1;
}
i = i_bottom + ( i_top - i_bottom ) / 2;
}
if( p_playlist->pp_all_items[i]->i_id == i_id )
{
REMOVE_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size, i );
}
/* Check if it is the current item */ /* Check if it is the current item */
if( p_playlist->status.p_item == p_item ) if( p_playlist->status.p_item == p_item )
......
...@@ -38,22 +38,10 @@ ...@@ -38,22 +38,10 @@
*/ */
playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id ) playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id )
{ {
int i, i_top, i_bottom; int i;
i_bottom = 0; i_top = p_playlist->i_all_size - 1; ARRAY_BSEARCH( p_playlist->all_items,->i_id, int, i_id, i );
i = i_top / 2; if( i != -1 )
while( p_playlist->pp_all_items[i]->i_id != i_id && return ARRAY_VAL( p_playlist->all_items, i );
i_top > i_bottom )
{
if( p_playlist->pp_all_items[i]->i_id < i_id )
i_bottom = i + 1;
else
i_top = i - 1;
i = i_bottom + ( i_top - i_bottom ) / 2;
}
if( p_playlist->pp_all_items[i]->i_id == i_id )
{
return p_playlist->pp_all_items[i];
}
return NULL; return NULL;
} }
...@@ -73,13 +61,11 @@ playlist_item_t * playlist_ItemGetByInput( playlist_t * p_playlist , ...@@ -73,13 +61,11 @@ playlist_item_t * playlist_ItemGetByInput( playlist_t * p_playlist ,
{ {
return p_playlist->status.p_item; return p_playlist->status.p_item;
} }
/** \todo Check if this is always incremental and whether we can bsearch */
for( i = 0 ; i < p_playlist->i_all_size; i++ ) for( i = 0 ; i < p_playlist->all_items.i_size; i++ )
{ {
if( p_playlist->pp_all_items[i]->p_input->i_id == p_item->i_id ) if( ARRAY_VAL(p_playlist->all_items, i)->p_input->i_id == p_item->i_id )
{ return ARRAY_VAL(p_playlist->all_items, i);
return p_playlist->pp_all_items[i];
}
} }
return NULL; return NULL;
} }
...@@ -92,7 +78,7 @@ int playlist_LiveSearchUpdate( playlist_t *p_playlist, playlist_item_t *p_root, ...@@ -92,7 +78,7 @@ int playlist_LiveSearchUpdate( playlist_t *p_playlist, playlist_item_t *p_root,
const char *psz_string ) const char *psz_string )
{ {
int i; int i;
p_playlist->b_reset_random = VLC_TRUE; p_playlist->b_reset_currently_playing = VLC_TRUE;
for( i = 0 ; i< p_root->i_children ; i ++ ) for( i = 0 ; i< p_root->i_children ; i ++ )
{ {
playlist_item_t *p_item = p_root->pp_children[i]; playlist_item_t *p_item = p_root->pp_children[i];
......
...@@ -143,9 +143,15 @@ int playlist_ThreadDestroy( playlist_t * p_playlist ) ...@@ -143,9 +143,15 @@ int playlist_ThreadDestroy( playlist_t * p_playlist )
{ {
p_playlist->b_die = VLC_TRUE; p_playlist->b_die = VLC_TRUE;
if( p_playlist->p_preparse ) if( p_playlist->p_preparse )
{
vlc_cond_signal( &p_playlist->p_preparse->object_wait ); vlc_cond_signal( &p_playlist->p_preparse->object_wait );
free( p_playlist->p_preparse->pp_waiting );
}
if( p_playlist->p_secondary_preparse ) if( p_playlist->p_secondary_preparse )
{
vlc_cond_signal( &p_playlist->p_secondary_preparse->object_wait ); vlc_cond_signal( &p_playlist->p_secondary_preparse->object_wait );
free( p_playlist->p_secondary_preparse->p_waiting );
}
DestroyInteraction( p_playlist ); DestroyInteraction( p_playlist );
DestroyPlaylist( p_playlist ); DestroyPlaylist( p_playlist );
......
...@@ -62,19 +62,12 @@ playlist_item_t * playlist_NodeCreate( playlist_t *p_playlist, char *psz_name, ...@@ -62,19 +62,12 @@ playlist_item_t * playlist_NodeCreate( playlist_t *p_playlist, char *psz_name,
p_item = playlist_ItemNewFromInput( VLC_OBJECT(p_playlist), p_input ); p_item = playlist_ItemNewFromInput( VLC_OBJECT(p_playlist), p_input );
p_item->i_children = 0; p_item->i_children = 0;
if( p_item == NULL ) if( p_item == NULL ) return NULL;
{
return NULL; ARRAY_APPEND(p_playlist->all_items, p_item);
}
INSERT_ELEM( p_playlist->pp_all_items,
p_playlist->i_all_size,
p_playlist->i_all_size,
p_item );
if( p_parent != NULL ) if( p_parent != NULL )
{
playlist_NodeAppend( p_playlist, p_item, p_parent ); playlist_NodeAppend( p_playlist, p_item, p_parent );
}
playlist_SendAddNotify( p_playlist, p_item->i_id, playlist_SendAddNotify( p_playlist, p_item->i_id,
p_parent ? p_parent->i_id : -1 ); p_parent ? p_parent->i_id : -1 );
...@@ -156,23 +149,16 @@ int playlist_NodeDelete( playlist_t *p_playlist, playlist_item_t *p_root, ...@@ -156,23 +149,16 @@ int playlist_NodeDelete( playlist_t *p_playlist, playlist_item_t *p_root,
} }
else else
{ {
int i;
var_SetInteger( p_playlist, "item-deleted", p_root->p_input->i_id ); var_SetInteger( p_playlist, "item-deleted", p_root->p_input->i_id );
for( i = 0 ; i< p_playlist->i_all_size; i ++ ) ARRAY_BSEARCH( p_playlist->all_items, ->p_input->i_id, int,
{ p_root->p_input->i_id, i );
if( p_playlist->pp_all_items[i]->p_input->i_id == if( i != -1 )
p_root->p_input->i_id ) ARRAY_REMOVE( p_playlist->all_items, i );
{
REMOVE_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size,
i );
break;
}
}
/* Remove the item from its parent */ /* Remove the item from its parent */
if( p_root->p_parent ) if( p_root->p_parent )
{
playlist_NodeRemoveItem( p_playlist, p_root, p_root->p_parent ); playlist_NodeRemoveItem( p_playlist, p_root, p_root->p_parent );
}
playlist_ItemDelete( p_root ); playlist_ItemDelete( p_root );
} }
...@@ -430,7 +416,6 @@ playlist_item_t *playlist_GetNextLeaf( playlist_t *p_playlist, ...@@ -430,7 +416,6 @@ playlist_item_t *playlist_GetNextLeaf( playlist_t *p_playlist,
{ {
vlc_bool_t b_ena_ok = VLC_TRUE, b_unplayed_ok = VLC_TRUE; vlc_bool_t b_ena_ok = VLC_TRUE, b_unplayed_ok = VLC_TRUE;
p_next = GetNextItem( p_playlist, p_root, p_next ); p_next = GetNextItem( p_playlist, p_root, p_next );
PL_DEBUG( "Got next item %s, testing suitability", PLI_NAME(p_next) );
if( !p_next || p_next == p_root ) if( !p_next || p_next == p_root )
break; break;
if( p_next->i_children == -1 ) if( p_next->i_children == -1 )
...@@ -521,8 +506,6 @@ playlist_item_t *GetNextItem( playlist_t *p_playlist, ...@@ -521,8 +506,6 @@ playlist_item_t *GetNextItem( playlist_t *p_playlist,
p_parent = p_item->p_parent; p_parent = p_item->p_parent;
else else
p_parent = p_root; p_parent = p_root;
PL_DEBUG( "Parent %s has %i children", PLI_NAME(p_parent),
p_parent->i_children );
for( i= 0 ; i < p_parent->i_children ; i++ ) for( i= 0 ; i < p_parent->i_children ; i++ )
{ {
if( p_item == NULL || p_parent->pp_children[i] == p_item ) if( p_item == NULL || p_parent->pp_children[i] == p_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