playlist: added a pp_all_items to playlist_t allowing GetItemById to return

nodes as well as items.
made playlist_Control not take the playlist lock, and created a
playlist_LockControl that does the same but takes the lock
parent 6635deda
...@@ -154,6 +154,9 @@ struct playlist_t ...@@ -154,6 +154,9 @@ struct playlist_t
int i_size; /**< total size of the list */ int i_size; /**< total size of the list */
playlist_item_t ** pp_items; /**< array of pointers to the playlist_item_t ** pp_items; /**< array of pointers to the
* playlist items */ * playlist items */
int i_all_size; /**< size of list of items and nodes */
playlist_item_t ** pp_all_items; /**< array of pointers to the
* playlist items and nodes */
int i_views; /**< Number of views */ int i_views; /**< Number of views */
playlist_view_t ** pp_views; /**< array of pointers to the playlist_view_t ** pp_views; /**< array of pointers to the
...@@ -237,15 +240,16 @@ playlist_t * __playlist_Create ( vlc_object_t * ); ...@@ -237,15 +240,16 @@ playlist_t * __playlist_Create ( vlc_object_t * );
int playlist_Destroy ( playlist_t * ); int playlist_Destroy ( playlist_t * );
/* Playlist control */ /* Playlist control */
#define playlist_Play(p) playlist_Control(p,PLAYLIST_PLAY ) #define playlist_Play(p) playlist_LockControl(p,PLAYLIST_PLAY )
#define playlist_Pause(p) playlist_Control(p,PLAYLIST_PAUSE ) #define playlist_Pause(p) playlist_LockControl(p,PLAYLIST_PAUSE )
#define playlist_Stop(p) playlist_Control(p,PLAYLIST_STOP ) #define playlist_Stop(p) playlist_LockControl(p,PLAYLIST_STOP )
#define playlist_Next(p) playlist_Control(p,PLAYLIST_SKIP , 1) #define playlist_Next(p) playlist_LockControl(p,PLAYLIST_SKIP, 1)
#define playlist_Prev(p) playlist_Control(p,PLAYLIST_SKIP , -1) #define playlist_Prev(p) playlist_LockControl(p,PLAYLIST_SKIP, -1)
#define playlist_Skip(p,i) playlist_Control(p,PLAYLIST_SKIP,i) #define playlist_Skip(p,i) playlist_LockControl(p,PLAYLIST_SKIP, i)
#define playlist_Goto(p,i) playlist_Control(p,PLAYLIST_GOTO,i) #define playlist_Goto(p,i) playlist_LockControl(p,PLAYLIST_GOTO, i)
VLC_EXPORT( int, playlist_Control, ( playlist_t *, int, ... ) ); VLC_EXPORT( int, playlist_Control, ( playlist_t *, int, ... ) );
VLC_EXPORT( int, playlist_LockControl, ( playlist_t *, int, ... ) );
VLC_EXPORT( int, playlist_Clear, ( playlist_t * ) ); VLC_EXPORT( int, playlist_Clear, ( playlist_t * ) );
VLC_EXPORT( int, playlist_LockClear, ( playlist_t * ) ); VLC_EXPORT( int, playlist_LockClear, ( playlist_t * ) );
......
...@@ -188,6 +188,8 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item, ...@@ -188,6 +188,8 @@ int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
} }
INSERT_ELEM( p_playlist->pp_items, p_playlist->i_size, i_pos, p_item ); INSERT_ELEM( p_playlist->pp_items, p_playlist->i_size, i_pos, 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 ++;
/* We update the ALL view directly */ /* We update the ALL view directly */
...@@ -345,6 +347,10 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item, ...@@ -345,6 +347,10 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item,
p_playlist->i_size, p_playlist->i_size,
i_position, i_position,
p_item ); 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 ++;
/* TODO: Handle modes */ /* TODO: Handle modes */
...@@ -401,9 +407,9 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item, ...@@ -401,9 +407,9 @@ int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item,
int playlist_GetPositionById( playlist_t * p_playlist , int i_id ) int playlist_GetPositionById( playlist_t * p_playlist , int i_id )
{ {
int i; int i;
for( i = 0 ; i < p_playlist->i_size ; i++ ) for( i = 0 ; i < p_playlist->i_all_size ; i++ )
{ {
if( p_playlist->pp_items[i]->input.i_id == i_id ) if( p_playlist->pp_all_items[i]->input.i_id == i_id )
{ {
return i; return i;
} }
...@@ -455,11 +461,11 @@ playlist_item_t *playlist_LockItemGetByPos( playlist_t *p_playlist, int i_pos ) ...@@ -455,11 +461,11 @@ playlist_item_t *playlist_LockItemGetByPos( playlist_t *p_playlist, int i_pos )
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; int i;
for( i = 0 ; i < p_playlist->i_size ; i++ ) for( i = 0 ; i < p_playlist->i_all_size ; i++ )
{ {
if( p_playlist->pp_items[i]->input.i_id == i_id ) if( p_playlist->pp_all_items[i]->input.i_id == i_id )
{ {
return p_playlist->pp_items[i]; return p_playlist->pp_all_items[i];
} }
} }
return NULL; return NULL;
......
...@@ -107,6 +107,7 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent ) ...@@ -107,6 +107,7 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
var_CreateGetBool( p_playlist, "loop" ); var_CreateGetBool( p_playlist, "loop" );
/* Initialise data structures */ /* Initialise data structures */
p_playlist->i_last_id = 0;
p_playlist->b_go_next = VLC_TRUE; p_playlist->b_go_next = VLC_TRUE;
p_playlist->p_input = NULL; p_playlist->p_input = NULL;
...@@ -118,6 +119,8 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent ) ...@@ -118,6 +119,8 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
p_playlist->i_index = -1; p_playlist->i_index = -1;
p_playlist->i_size = 0; p_playlist->i_size = 0;
p_playlist->pp_items = NULL; p_playlist->pp_items = NULL;
p_playlist->i_all_size = 0;
p_playlist->pp_all_items = malloc(sizeof(playlist_item_t*));
playlist_ViewInsert( p_playlist, VIEW_CATEGORY, TITLE_CATEGORY ); playlist_ViewInsert( p_playlist, VIEW_CATEGORY, TITLE_CATEGORY );
playlist_ViewInsert( p_playlist, VIEW_SIMPLE, TITLE_SIMPLE ); playlist_ViewInsert( p_playlist, VIEW_SIMPLE, TITLE_SIMPLE );
...@@ -140,7 +143,6 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent ) ...@@ -140,7 +143,6 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
p_playlist->status.i_status = PLAYLIST_STOPPED; p_playlist->status.i_status = PLAYLIST_STOPPED;
p_playlist->i_last_id = 0;
p_playlist->i_sort = SORT_ID; p_playlist->i_sort = SORT_ID;
p_playlist->i_order = ORDER_NORMAL; p_playlist->i_order = ORDER_NORMAL;
...@@ -246,6 +248,31 @@ int playlist_Destroy( playlist_t * p_playlist ) ...@@ -246,6 +248,31 @@ int playlist_Destroy( playlist_t * p_playlist )
* \param variable number of arguments * \param variable number of arguments
* \return VLC_SUCCESS or an error * \return VLC_SUCCESS or an error
*/ */
int playlist_LockControl( playlist_t * p_playlist, int i_query, ... )
{
va_list args;
int i_result;
va_start( args, i_query );
vlc_mutex_lock( &p_playlist->object_lock );
i_result = playlist_vaControl( p_playlist, i_query, args );
va_end( args );
vlc_mutex_unlock( &p_playlist->object_lock );
return i_result;
}
/**
* Do a playlist action.
*
* If there is something in the playlist then you can do playlist actions.
*
* Playlist lock must be taken when calling this function
*
* \param p_playlist the playlist to do the command on
* \param i_query the command to do
* \param variable number of arguments
* \return VLC_SUCCESS or an error
*/
int playlist_Control( playlist_t * p_playlist, int i_query, ... ) int playlist_Control( playlist_t * p_playlist, int i_query, ... )
{ {
va_list args; va_list args;
...@@ -262,8 +289,6 @@ int playlist_vaControl( playlist_t * p_playlist, int i_query, va_list args ) ...@@ -262,8 +289,6 @@ int playlist_vaControl( playlist_t * p_playlist, int i_query, va_list args )
playlist_view_t *p_view; playlist_view_t *p_view;
vlc_value_t val; vlc_value_t val;
vlc_mutex_lock( &p_playlist->object_lock );
#ifdef PLAYLIST_PROFILE #ifdef PLAYLIST_PROFILE
p_playlist->request_date = mdate(); p_playlist->request_date = mdate();
#endif #endif
...@@ -397,7 +422,6 @@ int playlist_vaControl( playlist_t * p_playlist, int i_query, va_list args ) ...@@ -397,7 +422,6 @@ int playlist_vaControl( playlist_t * p_playlist, int i_query, va_list args )
break; break;
} }
vlc_mutex_unlock( &p_playlist->object_lock );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
......
...@@ -251,11 +251,11 @@ playlist_item_t * playlist_NodeCreate( playlist_t *p_playlist, int i_view, ...@@ -251,11 +251,11 @@ playlist_item_t * playlist_NodeCreate( playlist_t *p_playlist, int i_view,
vlc_value_t val; vlc_value_t val;
playlist_add_t *p_add = (playlist_add_t*)malloc( sizeof(playlist_add_t)); playlist_add_t *p_add = (playlist_add_t*)malloc( sizeof(playlist_add_t));
vlc_input_item_Init( VLC_OBJECT(p_playlist), &p_item->input );
if( p_item == NULL ) if( p_item == NULL )
{ {
return NULL; return NULL;
} }
vlc_input_item_Init( VLC_OBJECT(p_playlist), &p_item->input );
if( psz_name != NULL ) if( psz_name != NULL )
{ {
...@@ -292,6 +292,11 @@ playlist_item_t * playlist_NodeCreate( playlist_t *p_playlist, int i_view, ...@@ -292,6 +292,11 @@ playlist_item_t * playlist_NodeCreate( playlist_t *p_playlist, int i_view,
vlc_mutex_init( p_playlist, &p_item->input.lock ); vlc_mutex_init( p_playlist, &p_item->input.lock );
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, i_view, p_item, p_parent ); playlist_NodeAppend( p_playlist, i_view, p_item, p_parent );
......
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