Commit 3bb2997f authored by Clément Stenac's avatar Clément Stenac

* Add return values to all functions

* Fix locking issues in services discovery
* Add playlist_Replace function
* Beginning of playlist_TreeMove
* Fix some warnings
* Doxygen update
parent 66845c94
...@@ -68,12 +68,15 @@ struct playlist_item_t ...@@ -68,12 +68,15 @@ struct playlist_item_t
int i_nb_played; /**< How many times was this item played ? */ int i_nb_played; /**< How many times was this item played ? */
/* LEGACY FIELDS */
vlc_bool_t b_autodeletion; /**< Indicates whther this item is to vlc_bool_t b_autodeletion; /**< Indicates whther this item is to
* be deleted after playback. True mean * be deleted after playback. True mean
* that this item is to be deleted * that this item is to be deleted
* after playback, false otherwise */ * after playback, false otherwise */
vlc_bool_t b_enabled; /**< Indicates whether this item is to be vlc_bool_t b_enabled; /**< Indicates whether this item is to be
* played or skipped */ * played or skipped */
/* END LEGACY FIELDS */
}; };
#define PLAYLIST_SAVE_FLAG 0x1 /**< Must it be saved */ #define PLAYLIST_SAVE_FLAG 0x1 /**< Must it be saved */
...@@ -219,7 +222,7 @@ struct playlist_add_t ...@@ -219,7 +222,7 @@ struct playlist_add_t
/* Creation/Deletion */ /* Creation/Deletion */
#define playlist_Create(a) __playlist_Create(VLC_OBJECT(a)) #define playlist_Create(a) __playlist_Create(VLC_OBJECT(a))
playlist_t * __playlist_Create ( vlc_object_t * ); playlist_t * __playlist_Create ( vlc_object_t * );
void 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_Control(p,PLAYLIST_PLAY )
...@@ -238,7 +241,7 @@ VLC_EXPORT( int, playlist_Clear, ( playlist_t * ) ); ...@@ -238,7 +241,7 @@ VLC_EXPORT( int, playlist_Clear, ( playlist_t * ) );
/* Services discovery */ /* Services discovery */
VLC_EXPORT( int, playlist_ServicesDiscoveryAdd, (playlist_t *, const char *)); VLC_EXPORT( int, playlist_ServicesDiscoveryAdd, (playlist_t *, const char *));
VLC_EXPORT( void, playlist_ServicesDiscoveryRemove, (playlist_t *, const char *)); VLC_EXPORT( int, playlist_ServicesDiscoveryRemove, (playlist_t *, const char *));
VLC_EXPORT( int, playlist_AddSDModules, (playlist_t *, char *)); VLC_EXPORT( int, playlist_AddSDModules, (playlist_t *, char *));
VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const char *)); VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const char *));
...@@ -247,9 +250,9 @@ VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const ...@@ -247,9 +250,9 @@ VLC_EXPORT( vlc_bool_t, playlist_IsServicesDiscoveryLoaded, ( playlist_t *,const
#define playlist_AddItem(p,pi,i1,i2) playlist_ItemAdd(p,pi,i1,i2) #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_ItemNew( a , b, c ) __playlist_ItemNew(VLC_OBJECT(a) , b , c )
VLC_EXPORT( playlist_item_t* , __playlist_ItemNew, ( vlc_object_t *,const char *,const char * ) ); VLC_EXPORT( playlist_item_t* , __playlist_ItemNew, ( vlc_object_t *,const char *,const char * ) );
VLC_EXPORT( void, playlist_ItemDelete, ( playlist_item_t * ) ); VLC_EXPORT( int, playlist_ItemDelete, ( playlist_item_t * ) );
VLC_EXPORT( void, playlist_ItemAddParent, ( playlist_item_t *, int,playlist_item_t *) ); VLC_EXPORT( int, playlist_ItemAddParent, ( playlist_item_t *, int,playlist_item_t *) );
VLC_EXPORT( void, playlist_CopyParents, ( playlist_item_t *,playlist_item_t *) ); VLC_EXPORT( int, playlist_CopyParents, ( playlist_item_t *,playlist_item_t *) );
/* Item informations accessors */ /* Item informations accessors */
VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *, char * ) ); VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *, char * ) );
VLC_EXPORT( int, playlist_ItemSetDuration, (playlist_item_t *, mtime_t ) ); VLC_EXPORT( int, playlist_ItemSetDuration, (playlist_item_t *, mtime_t ) );
...@@ -257,10 +260,10 @@ VLC_EXPORT( int, playlist_ItemSetDuration, (playlist_item_t *, mtime_t ) ); ...@@ -257,10 +260,10 @@ VLC_EXPORT( int, playlist_ItemSetDuration, (playlist_item_t *, mtime_t ) );
/* View management functions */ /* View management functions */
VLC_EXPORT( int, playlist_ViewInsert, (playlist_t *, int, char * ) ); VLC_EXPORT( int, playlist_ViewInsert, (playlist_t *, int, char * ) );
VLC_EXPORT( void, playlist_ViewDelete, (playlist_t *,playlist_view_t* ) ); VLC_EXPORT( int, playlist_ViewDelete, (playlist_t *,playlist_view_t* ) );
VLC_EXPORT( playlist_view_t *, playlist_ViewFind, (playlist_t *, int ) ); VLC_EXPORT( playlist_view_t *, playlist_ViewFind, (playlist_t *, int ) );
VLC_EXPORT( int, playlist_ViewUpdate, (playlist_t *, int ) ); VLC_EXPORT( int, playlist_ViewUpdate, (playlist_t *, int ) );
VLC_EXPORT( void, playlist_ViewDump, (playlist_t *, playlist_view_t * ) ); VLC_EXPORT( int, playlist_ViewDump, (playlist_t *, playlist_view_t * ) );
VLC_EXPORT( int, playlist_ViewEmpty, (playlist_t *, int, vlc_bool_t ) ); VLC_EXPORT( int, playlist_ViewEmpty, (playlist_t *, int, vlc_bool_t ) );
/* Node management */ /* Node management */
...@@ -298,7 +301,8 @@ VLC_EXPORT(int, playlist_NodeAddItem, ( playlist_t *, playlist_item_t *,int,play ...@@ -298,7 +301,8 @@ VLC_EXPORT(int, playlist_NodeAddItem, ( playlist_t *, playlist_item_t *,int,play
VLC_EXPORT( int, playlist_Delete, ( playlist_t *, int ) ); VLC_EXPORT( int, playlist_Delete, ( playlist_t *, int ) );
VLC_EXPORT( int, playlist_Disable, ( playlist_t *, playlist_item_t * ) ); VLC_EXPORT( int, playlist_Disable, ( playlist_t *, playlist_item_t * ) );
VLC_EXPORT( int, playlist_Enable, ( playlist_t *, playlist_item_t * ) ); VLC_EXPORT( int, playlist_Enable, ( playlist_t *, playlist_item_t * ) );
VLC_EXPORT( void, playlist_ItemToNode, (playlist_t *,playlist_item_t *) ); VLC_EXPORT( int, playlist_ItemToNode, (playlist_t *,playlist_item_t *) );
VLC_EXPORT( int, playlist_Replace, (playlist_t *,playlist_item_t *, input_item_t*) );
/* Item search functions */ /* Item search functions */
......
...@@ -455,11 +455,13 @@ playlist_item_t * playlist_ItemGetByInput( playlist_t * p_playlist , ...@@ -455,11 +455,13 @@ playlist_item_t * playlist_ItemGetByInput( playlist_t * p_playlist ,
/** /**
* Transform an item to a node * Transform an item to a node
* *
* This function must be entered without the playlist lock
*
* \param p_playlist the playlist object * \param p_playlist the playlist object
* \param p_item the item to transform * \param p_item the item to transform
* \return nothing * \return nothing
*/ */
void playlist_ItemToNode( playlist_t *p_playlist,playlist_item_t *p_item ) int playlist_ItemToNode( playlist_t *p_playlist,playlist_item_t *p_item )
{ {
int i = 0; int i = 0;
if( p_item->i_children == -1 ) if( p_item->i_children == -1 )
...@@ -479,12 +481,71 @@ void playlist_ItemToNode( playlist_t *p_playlist,playlist_item_t *p_item ) ...@@ -479,12 +481,71 @@ void playlist_ItemToNode( playlist_t *p_playlist,playlist_item_t *p_item )
} }
vlc_mutex_unlock( &p_playlist->object_lock ); vlc_mutex_unlock( &p_playlist->object_lock );
/* Handle the parents return VLC_SUCCESS;
* Nothing to do ! */ }
/**
* Replaces an item with another one
* This function must be entered without the playlist lock
*
* \see playlist_Replace
*/
int playlist_LockAndReplace( playlist_t *p_playlist,
playlist_item_t *p_olditem,
input_item_t *p_new )
{
int i_ret;
vlc_mutex_lock( &p_playlist->object_lock );
i_ret = playlist_Replace( p_playlist, p_olditem, p_new );
vlc_mutex_unlock( &p_playlist->object_lock );
return i_ret;
}
/**
* Replaces an item with another one
* This function must be entered with the playlist lock:
*
* \param p_playlist the playlist
* \param p_olditem the item to replace
* \param p_new the new input_item
* \return VLC_SUCCESS or an error
*/
int playlist_Replace( playlist_t *p_playlist, playlist_item_t *p_olditem,
input_item_t *p_new )
{
int i;
int j;
if( p_olditem->i_children != -1 )
{
msg_Err( p_playlist, "playlist_Replace can only be used on leafs");
return VLC_EGENERIC;
}
p_olditem->i_nb_played = 0;
memcpy( &p_olditem->input, p_new, sizeof( input_item_t ) );
p_olditem->i_nb_played = 0;
for( i = 0 ; i< p_olditem->i_parents ; i++ )
{
playlist_item_t *p_parent = p_olditem->pp_parents[i]->p_parent;
for( j = 0 ; j< p_parent->i_children ; i++ )
{
if( p_parent->pp_children[j] == p_olditem )
{
p_parent->i_serial++;
}
}
}
return VLC_SUCCESS;
} }
/** /**
* delete an item from a playlist. * Deletes an item from a playlist.
*
* This function must be entered without the playlist lock
* *
* \param p_playlist the playlist to remove from. * \param p_playlist the playlist to remove from.
* \param i_id the identifier of the item to delete * \param i_id the identifier of the item to delete
...@@ -605,6 +666,8 @@ int playlist_Enable( playlist_t * p_playlist, playlist_item_t *p_item ) ...@@ -605,6 +666,8 @@ int playlist_Enable( playlist_t * p_playlist, playlist_item_t *p_item )
/** /**
* Move an item in a playlist * Move an item in a playlist
* *
* This function must be entered without the playlist lock
*
* Move the item in the playlist with position i_pos before the current item * Move the item in the playlist with position i_pos before the current item
* at position i_newpos. * at position i_newpos.
* \param p_playlist the playlist to move items in * \param p_playlist the playlist to move items in
...@@ -673,3 +736,52 @@ int playlist_Move( playlist_t * p_playlist, int i_pos, int i_newpos ) ...@@ -673,3 +736,52 @@ int playlist_Move( playlist_t * p_playlist, int i_pos, int i_newpos )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
/**
* Moves an item
*
* \param p_playlist the playlist
* \param p_item the item to move
* \param p_node the new parent of the item
* \param i_newpos the new position under this new parent
* \param i_view the view in which the move must be done or ALL_VIEWS
* \return VLC_SUCCESS or an error
*/
int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
playlist_item_t *p_node, int i_newpos, int i_view )
{
int i;
playlist_item_t *p_detach = NULL;
#if 0
if( i_view == ALL_VIEWS )
{
for( i = 0 ; i < p_playlist->i_views; i++ )
{
playlist_TreeMove( p_playlist, p_item, p_node, i_newpos,
p_playlist->pp_views[i] );
}
}
#endif
/* Find the parent */
for( i = 0 ; i< p_item->i_parents; i++ )
{
if( p_item->pp_parents[i]->i_view == i_view )
{
p_detach = p_item->pp_parents[i]->p_parent;
break;
}
}
if( p_detach == NULL )
{
msg_Err( p_playlist, "item not found in view %i", i_view );
return VLC_EGENERIC;
}
/* Detach from the parent */
// playlist_NodeDetach( p_detach, p_item );
/* Attach to new parent */
return VLC_SUCCESS;
}
...@@ -85,7 +85,7 @@ playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj, ...@@ -85,7 +85,7 @@ playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
* \param p_item the item to delete * \param p_item the item to delete
* \return nothing * \return nothing
*/ */
void playlist_ItemDelete( playlist_item_t *p_item ) int playlist_ItemDelete( playlist_item_t *p_item )
{ {
vlc_mutex_lock( &p_item->input.lock ); vlc_mutex_lock( &p_item->input.lock );
...@@ -132,6 +132,8 @@ void playlist_ItemDelete( playlist_item_t *p_item ) ...@@ -132,6 +132,8 @@ void playlist_ItemDelete( playlist_item_t *p_item )
vlc_mutex_destroy( &p_item->input.lock ); vlc_mutex_destroy( &p_item->input.lock );
free( p_item ); free( p_item );
return VLC_SUCCESS;
} }
/** /**
...@@ -161,7 +163,7 @@ int playlist_ItemAddOption( playlist_item_t *p_item, const char *psz_option ) ...@@ -161,7 +163,7 @@ int playlist_ItemAddOption( playlist_item_t *p_item, const char *psz_option )
* \param p_parent the parent to add * \param p_parent the parent to add
* \return nothing * \return nothing
*/ */
void playlist_ItemAddParent( playlist_item_t *p_item, int i_view, int playlist_ItemAddParent( playlist_item_t *p_item, int i_view,
playlist_item_t *p_parent ) playlist_item_t *p_parent )
{ {
vlc_bool_t b_found = VLC_FALSE; vlc_bool_t b_found = VLC_FALSE;
...@@ -188,12 +190,13 @@ void playlist_ItemAddParent( playlist_item_t *p_item, int i_view, ...@@ -188,12 +190,13 @@ void playlist_ItemAddParent( playlist_item_t *p_item, int i_view,
p_item->i_parents, p_item->i_parents, p_item->i_parents, p_item->i_parents,
p_ip ); p_ip );
} }
return VLC_SUCCESS;
} }
/** /**
* Copy all parents from parent to child * Copy all parents from parent to child
*/ */
void playlist_CopyParents( playlist_item_t *p_parent, int playlist_CopyParents( playlist_item_t *p_parent,
playlist_item_t *p_child ) playlist_item_t *p_child )
{ {
int i=0; int i=0;
...@@ -203,6 +206,7 @@ void playlist_CopyParents( playlist_item_t *p_parent, ...@@ -203,6 +206,7 @@ void playlist_CopyParents( playlist_item_t *p_parent,
p_parent->pp_parents[i]->i_view, p_parent->pp_parents[i]->i_view,
p_parent ); p_parent );
} }
return VLC_SUCCESS;
} }
...@@ -260,6 +264,8 @@ int playlist_ItemSetDuration( playlist_item_t *p_item, mtime_t i_duration ) ...@@ -260,6 +264,8 @@ int playlist_ItemSetDuration( playlist_item_t *p_item, mtime_t i_duration )
return VLC_EGENERIC; return VLC_EGENERIC;
} }
/*
* Guess the type of the item using the beginning of the mrl */
static void GuessType( input_item_t *p_item) static void GuessType( input_item_t *p_item)
{ {
int i; int i;
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
*****************************************************************************/ *****************************************************************************/
static void RunThread ( playlist_t * ); static void RunThread ( playlist_t * );
static playlist_item_t * NextItem ( playlist_t * ); static playlist_item_t * NextItem ( playlist_t * );
static void PlayItem ( playlist_t *, playlist_item_t * ); static int PlayItem ( playlist_t *, playlist_item_t * );
static int ItemChange( vlc_object_t *, const char *, static int ItemChange( vlc_object_t *, const char *,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, vlc_value_t, void * );
...@@ -61,7 +61,6 @@ int playlist_vaControl( playlist_t * p_playlist, int i_query, va_list args ); ...@@ -61,7 +61,6 @@ int playlist_vaControl( playlist_t * p_playlist, int i_query, va_list args );
*/ */
playlist_t * __playlist_Create ( vlc_object_t *p_parent ) playlist_t * __playlist_Create ( vlc_object_t *p_parent )
{ {
int i_index;
playlist_t *p_playlist; playlist_t *p_playlist;
playlist_view_t *p_view; playlist_view_t *p_view;
vlc_value_t val; vlc_value_t val;
...@@ -157,8 +156,9 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent ) ...@@ -157,8 +156,9 @@ playlist_t * __playlist_Create ( vlc_object_t *p_parent )
* *
* Delete all items in the playlist and free the playlist structure. * Delete all items in the playlist and free the playlist structure.
* \param p_playlist the playlist structure to destroy * \param p_playlist the playlist structure to destroy
* \return VLC_SUCCESS or an error
*/ */
void playlist_Destroy( playlist_t * p_playlist ) int playlist_Destroy( playlist_t * p_playlist )
{ {
int i; int i;
p_playlist->b_die = 1; p_playlist->b_die = 1;
...@@ -194,6 +194,8 @@ void playlist_Destroy( playlist_t * p_playlist ) ...@@ -194,6 +194,8 @@ void playlist_Destroy( playlist_t * p_playlist )
} }
vlc_object_destroy( p_playlist ); vlc_object_destroy( p_playlist );
return VLC_SUCCESS;
} }
...@@ -903,10 +905,9 @@ static void SkipItem( playlist_t *p_playlist, int i_arg ) ...@@ -903,10 +905,9 @@ static void SkipItem( playlist_t *p_playlist, int i_arg )
/***************************************************************************** /*****************************************************************************
* PlayItem: start the input thread for an item * PlayItem: start the input thread for an item
****************************************************************************/ ****************************************************************************/
static void PlayItem( playlist_t *p_playlist, playlist_item_t *p_item ) static int PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
{ {
vlc_value_t val; vlc_value_t val;
int i;
msg_Dbg( p_playlist, "creating new input thread" ); msg_Dbg( p_playlist, "creating new input thread" );
...@@ -932,6 +933,8 @@ static void PlayItem( playlist_t *p_playlist, playlist_item_t *p_item ) ...@@ -932,6 +933,8 @@ static void PlayItem( playlist_t *p_playlist, playlist_item_t *p_item )
var_Set( p_playlist, "playlist-current", val); var_Set( p_playlist, "playlist-current", val);
vlc_mutex_lock( &p_playlist->object_lock); vlc_mutex_lock( &p_playlist->object_lock);
return VLC_SUCCESS;
} }
/* Forward item change from input */ /* Forward item change from input */
......
...@@ -80,7 +80,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist, ...@@ -80,7 +80,7 @@ int playlist_ServicesDiscoveryAdd( playlist_t *p_playlist,
return VLC_SUCCESS; return VLC_SUCCESS;
} }
void playlist_ServicesDiscoveryRemove( playlist_t * p_playlist, int playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
const char *psz_module ) const char *psz_module )
{ {
int i; int i;
...@@ -99,18 +99,22 @@ void playlist_ServicesDiscoveryRemove( playlist_t * p_playlist, ...@@ -99,18 +99,22 @@ void playlist_ServicesDiscoveryRemove( playlist_t * p_playlist,
if( p_sd ) if( p_sd )
{ {
vlc_mutex_unlock( &p_playlist->object_lock );
p_sd->b_die = VLC_TRUE; p_sd->b_die = VLC_TRUE;
vlc_thread_join( p_sd ); vlc_thread_join( p_sd );
module_Unneed( p_sd, p_sd->p_module ); module_Unneed( p_sd, p_sd->p_module );
vlc_mutex_lock( &p_playlist->object_lock );
vlc_object_destroy( p_sd ); vlc_object_destroy( p_sd );
} }
else else
{ {
msg_Warn( p_playlist, "module %s is not loaded", psz_module ); msg_Warn( p_playlist, "module %s is not loaded", psz_module );
vlc_mutex_unlock( &p_playlist->object_lock );
return VLC_EGENERIC;
} }
vlc_mutex_unlock( &p_playlist->object_lock ); vlc_mutex_unlock( &p_playlist->object_lock );
return; return VLC_SUCCESS;
} }
vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist, vlc_bool_t playlist_IsServicesDiscoveryLoaded( playlist_t * p_playlist,
......
...@@ -90,7 +90,6 @@ int playlist_Sort( playlist_t * p_playlist , int i_mode, int i_type ) ...@@ -90,7 +90,6 @@ int playlist_Sort( playlist_t * p_playlist , int i_mode, int i_type )
int playlist_NodeSort( playlist_t * p_playlist , playlist_item_t *p_node, int playlist_NodeSort( playlist_t * p_playlist , playlist_item_t *p_node,
int i_mode, int i_type ) int i_mode, int i_type )
{ {
int i_id;
vlc_value_t val; vlc_value_t val;
val.b_bool = VLC_TRUE; val.b_bool = VLC_TRUE;
......
...@@ -116,10 +116,10 @@ int playlist_ViewInsert( playlist_t *p_playlist, int i_id, char *psz_name ) ...@@ -116,10 +116,10 @@ int playlist_ViewInsert( playlist_t *p_playlist, int i_id, char *psz_name )
* \param p_view the view to delete * \param p_view the view to delete
* \return nothing * \return nothing
*/ */
void playlist_ViewDelete( playlist_t *p_playlist,playlist_view_t *p_view ) int playlist_ViewDelete( playlist_t *p_playlist,playlist_view_t *p_view )
{ {
//playlist_Delete( p_view->p_root );
REMOVE_ELEM( p_playlist->pp_views, p_playlist->i_views, 0 ); REMOVE_ELEM( p_playlist->pp_views, p_playlist->i_views, 0 );
return VLC_SUCCESS;
} }
...@@ -130,10 +130,11 @@ void playlist_ViewDelete( playlist_t *p_playlist,playlist_view_t *p_view ) ...@@ -130,10 +130,11 @@ void playlist_ViewDelete( playlist_t *p_playlist,playlist_view_t *p_view )
* \param p_view the view to dump * \param p_view the view to dump
* \return nothing * \return nothing
*/ */
void playlist_ViewDump( playlist_t *p_playlist, playlist_view_t *p_view ) int playlist_ViewDump( playlist_t *p_playlist, playlist_view_t *p_view )
{ {
msg_Dbg( p_playlist, "dumping view %i",p_view->i_id ); msg_Dbg( p_playlist, "dumping view %i",p_view->i_id );
playlist_NodeDump( p_playlist,p_view->p_root, 1 ); playlist_NodeDump( p_playlist,p_view->p_root, 1 );
return VLC_SUCCESS;
} }
/** /**
......
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