Commit 85ff1461 authored by Clément Stenac's avatar Clément Stenac

* Start cleaning up libvlc playlist API (Refs:#457)

  - Return correct item ids
  - Structures for navigating the playlist
  - Consistent locking
* Add a b_locked parameter to the remaining playlist API calls
parent 4630e1ed
......@@ -48,13 +48,12 @@ extern "C" {
* @{
*/
struct libvlc_exception_t
typedef struct
{
int b_raised;
int i_code;
char *psz_message;
};
typedef struct libvlc_exception_t libvlc_exception_t;
} libvlc_exception_t;
/**
* Initialize an exception structure. This can be called several times to reuse
......@@ -140,6 +139,13 @@ VLC_PUBLIC_API void libvlc_destroy( libvlc_instance_t *, libvlc_exception_t * );
* @{
*/
typedef struct {
int i_id;
char * psz_uri;
char * psz_name
} libvlc_playlist_item_t;
/**
* Set loop variable
*/
......
......@@ -368,11 +368,11 @@ VLC_EXPORT( int, playlist_DeleteFromInput, ( playlist_t *, int, vlc_bool_t ) );
VLC_EXPORT( int, playlist_ItemSetName, (playlist_item_t *, const char * ) );
/******************** Item addition ********************/
VLC_EXPORT( int, playlist_Add, ( playlist_t *, const char *, const char *, int, int, vlc_bool_t ) );
VLC_EXPORT( int, playlist_AddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char *const *,int, vlc_bool_t ) );
VLC_EXPORT( int, playlist_AddInput, ( playlist_t *, input_item_t *,int , int, vlc_bool_t ) );
VLC_EXPORT( playlist_item_t *, playlist_NodeAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int ) );
VLC_EXPORT( int, playlist_BothAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int, int*, int* ) );
VLC_EXPORT( int, playlist_Add, ( playlist_t *, const char *, const char *, int, int, vlc_bool_t, vlc_bool_t ) );
VLC_EXPORT( int, playlist_AddExt, ( playlist_t *, const char *, const char *, int, int, mtime_t, const char *const *,int, vlc_bool_t, vlc_bool_t ) );
VLC_EXPORT( int, playlist_AddInput, ( playlist_t *, input_item_t *, int, int, vlc_bool_t, vlc_bool_t ) );
VLC_EXPORT( playlist_item_t *, playlist_NodeAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int, vlc_bool_t ) );
VLC_EXPORT( int, playlist_BothAddInput, ( playlist_t *, input_item_t *,playlist_item_t *,int , int, int*, int*, vlc_bool_t ) );
/********************** Misc item operations **********************/
VLC_EXPORT( playlist_item_t*, playlist_ItemToNode, (playlist_t *,playlist_item_t *, vlc_bool_t) );
......@@ -415,7 +415,7 @@ static inline int playlist_Import( playlist_t *p_playlist, const char *psz_file)
snprintf( psz_uri, 256+9, "file/://%s", psz_file );
p_input = input_ItemNewExt( p_playlist, psz_uri, psz_file, 0, NULL, -1 );
playlist_AddInput( p_playlist, p_input, PLAYLIST_APPEND, PLAYLIST_END,
VLC_TRUE );
VLC_TRUE, VLC_FALSE );
input_Read( p_playlist, p_input, VLC_TRUE );
return VLC_SUCCESS;
}
......
......@@ -503,7 +503,8 @@ static int GetTracks( access_t *p_access,
}
#endif
playlist_BothAddInput( p_playlist, p_input_item, p_item_in_category,
PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL );
PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL,
VLC_FALSE );
free( psz_uri ); free( psz_opt ); free( psz_name );
free( psz_first ); free( psz_last );
}
......
......@@ -516,7 +516,8 @@ static int ReadDir( playlist_t *p_playlist, const char *psz_name,
p_parent_category,
PLAYLIST_APPEND|PLAYLIST_PREPARSE|
PLAYLIST_NO_REBUILD,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL,
VLC_FALSE );
}
}
}
......
......@@ -112,7 +112,8 @@ int E_(MMSHOpen)( access_t *p_access )
/** \bug we do not autodelete here */
playlist_Add( p_playlist, psz_location, psz_location,
PLAYLIST_INSERT | PLAYLIST_GO, PLAYLIST_END, VLC_TRUE );
PLAYLIST_INSERT | PLAYLIST_GO, PLAYLIST_END, VLC_TRUE,
VLC_FALSE );
vlc_object_release( p_playlist );
free( psz_location );
......
......@@ -796,7 +796,8 @@ static void ReplacePlaylistItem( playlist_t *p_playlist, char *psz_uri )
{
playlist_Stop( p_playlist );
(void) playlist_Add( p_playlist, psz_uri, psz_uri,
PLAYLIST_INSERT /* FIXME: used to be PLAYLIST_REPLACE */, PLAYLIST_END|PLAYLIST_GO, VLC_TRUE /* FIXME: p_playlist->status.i_index */ );
PLAYLIST_INSERT /* FIXME: used to be PLAYLIST_REPLACE */, PLAYLIST_END|PLAYLIST_GO, VLC_TRUE /* FIXME: p_playlist->status.i_index */,
VLC_FALSE);
}
/****************************************************************************
......
......@@ -343,7 +343,8 @@ void E_(MacroDo)( httpd_file_sys_t *p_args,
else
{
playlist_AddInput( p_sys->p_playlist, p_input,
PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
VLC_FALSE);
msg_Dbg( p_intf, "requested mrl add: %s", mrl );
}
......
......@@ -851,7 +851,8 @@ void E_(EvaluateRPN)( intf_thread_t *p_intf, mvar_t *vars,
else
{
i_id = playlist_AddInput( p_sys->p_playlist, p_input,
PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
VLC_FALSE);
msg_Dbg( p_intf, "requested mrl add: %s", mrl );
}
E_(SSPushN)( st, i_id );
......
......@@ -1367,7 +1367,8 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
{
msg_rc( "Trying to add %s to playlist.", newval.psz_string );
playlist_AddInput( p_playlist, p_item,
PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
VLC_FALSE );
}
}
else if( !strcmp( psz_cmd, "enqueue" ) &&
......@@ -1379,7 +1380,8 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
{
msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
playlist_AddInput( p_playlist, p_item,
PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
VLC_FALSE);
}
}
else if( !strcmp( psz_cmd, "playlist" ) )
......
......@@ -419,7 +419,7 @@ static int Open( vlc_object_t * p_this )
playlist_BothAddInput( p_playlist, p_input,
p_item_in_category,
PLAYLIST_APPEND, PLAYLIST_END,
NULL, NULL);
NULL, NULL, VLC_FALSE );
}
}
else
......
......@@ -371,7 +371,8 @@ static int Demux( demux_t *p_demux )
playlist_BothAddInput( p_playlist, p_input,
p_item_in_category,
PLAYLIST_APPEND|PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL,
VLC_FALSE);
free( psz_string );
}
else continue;
......@@ -451,7 +452,8 @@ static int Demux( demux_t *p_demux )
playlist_BothAddInput( p_playlist, p_entry,
p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE
, PLAYLIST_END, NULL, NULL);
, PLAYLIST_END, NULL, NULL,
VLC_FALSE );
free( psz_string );
}
else continue;
......
......@@ -270,7 +270,7 @@ static int Demux( demux_t *p_demux )
playlist_BothAddInput( p_playlist, p_input,
p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL, VLC_FALSE );
FREENULL( psz_name );
FREENULL( psz_mrl );
FREENULL( psz_genre );
......
......@@ -120,7 +120,7 @@ static int Demux( demux_t *p_demux )
}
playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL, VLC_FALSE );
while( i_options-- ) free( ppsz_options[i_options] );
if( ppsz_options ) free( ppsz_options );
......
......@@ -215,7 +215,7 @@ static int Demux( demux_t *p_demux )
playlist_BothAddInput( p_sys->p_playlist, p_input,
p_sys->p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL, VLC_FALSE );
}
HANDLE_PLAY_AND_RELEASE;
......
......@@ -187,7 +187,7 @@ static int Demux( demux_t *p_demux )
_(VLC_META_ARTIST), "%s", psz_artist );
playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL, VLC_FALSE );
free( psz_mrl );
// XXX Not to be a scare monger, but I suspect options are leaked
}
......
......@@ -163,7 +163,7 @@ static int Demux( demux_t *p_demux )
input_ItemCopyOptions( p_current->p_input, p_input );
playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL, VLC_FALSE );
}
else
{
......@@ -220,7 +220,7 @@ static int Demux( demux_t *p_demux )
input_ItemCopyOptions( p_current->p_input, p_input );
playlist_BothAddInput( p_playlist, p_input, p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL, VLC_FALSE );
free( psz_mrl_orig );
psz_mrl = NULL;
}
......
......@@ -293,7 +293,7 @@ static int Demux( demux_t *p_demux )
playlist_BothAddInput( p_playlist, p_input,
p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE
, PLAYLIST_END, NULL, NULL );
, PLAYLIST_END, NULL, NULL, VLC_FALSE );
FREENULL( psz_item_name );
FREENULL( psz_item_mrl );
FREENULL( psz_item_size );
......
......@@ -362,7 +362,7 @@ static int Demux( demux_t *p_demux )
playlist_BothAddInput( p_sys->p_playlist, p_input,
p_sys->p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL, VLC_FALSE );
if( psz_qtnext )
{
p_input = input_ItemNewExt( p_sys->p_playlist,
......@@ -370,7 +370,7 @@ static int Demux( demux_t *p_demux )
playlist_BothAddInput( p_sys->p_playlist, p_input,
p_sys->p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL, VLC_FALSE );
}
}
......
......@@ -408,7 +408,7 @@ static int Demux ( demux_t *p_demux )
playlist_BothAddInput( p_playlist, p_child, p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE, PLAYLIST_END,
NULL, NULL);
NULL, NULL, VLC_FALSE );
HANDLE_PLAY_AND_RELEASE
return -1; /* Needed for correct operation of go back */
}
......
......@@ -242,7 +242,7 @@ static int DemuxGenre( demux_t *p_demux )
playlist_BothAddInput( p_sys->p_playlist, p_input,
p_sys->p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL, VLC_FALSE );
FREENULL( psz_name );
}
FREENULL( psz_eltname );
......@@ -434,7 +434,7 @@ static int DemuxStation( demux_t *p_demux )
playlist_BothAddInput( p_sys->p_playlist, p_input,
p_sys->p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL, VLC_FALSE );
FREENULL( psz_name );
FREENULL( psz_mt )
......
......@@ -481,7 +481,7 @@ static vlc_bool_t parse_track_node COMPLEX_INTERFACE
playlist_BothAddInput( p_playlist, p_new_input,
p_demux->p_sys->p_item_in_category,
PLAYLIST_APPEND | PLAYLIST_SPREPARSE,
PLAYLIST_END, NULL, NULL );
PLAYLIST_END, NULL, NULL, VLC_FALSE );
if( p_demux->p_sys->i_identifier <
p_demux->p_sys->i_tracklist_entries )
{
......
......@@ -58,7 +58,7 @@
[[[NSFileManager defaultManager]
displayNameAtPath: o_urlString] UTF8String] );
playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
PLAYLIST_END, VLC_TRUE );
PLAYLIST_END, VLC_TRUE, VLC_FALSE );
o_url = [NSURL fileURLWithPath: o_urlString];
......@@ -163,4 +163,4 @@
[o_controls toogleFullscreen: self];
}
@end
\ No newline at end of file
@end
......@@ -1011,7 +1011,8 @@ NSLog( @"expandable" );
/* Add the item */
playlist_AddInput( p_playlist, p_input, PLAYLIST_INSERT,
i_position == -1 ? PLAYLIST_END : i_position + i_item, VLC_TRUE );
i_position == -1 ? PLAYLIST_END : i_position + i_item, VLC_TRUE,
VLC_FALSE );
if( i_item == 0 && !b_enqueue )
{
......
......@@ -1314,7 +1314,7 @@ static VLCWizard *_o_sharedInstance = nil;
UTF8String] );
playlist_AddInput( p_playlist, p_input, PLAYLIST_STOP,
PLAYLIST_END, VLC_TRUE );
PLAYLIST_END, VLC_TRUE, VLC_FALSE );
if( x == 0 )
{
......
......@@ -121,7 +121,7 @@ void OpenDialog::ok()
playlist_Add( THEPL, psz_utf8, NULL,
PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
( i ? PLAYLIST_PREPARSE : 0 ),
PLAYLIST_END, VLC_TRUE );
PLAYLIST_END, VLC_TRUE, VLC_FALSE );
}
}
......
......@@ -85,7 +85,7 @@ void PlaylistDialog::dropEvent(QDropEvent *event)
QString s = url.toString();
if( s.length() > 0 ) {
playlist_Add( THEPL, qtu(s), NULL,
PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE );
PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE, VLC_FALSE );
}
}
event->acceptProposedAction();
......
......@@ -239,7 +239,7 @@ void DialogsProvider::addFromSimple( bool pl, bool go)
( i ? PLAYLIST_PREPARSE : 0 ) )
: ( PLAYLIST_APPEND | PLAYLIST_PREPARSE ),
PLAYLIST_END,
pl ? VLC_TRUE : VLC_FALSE );
pl ? VLC_TRUE : VLC_FALSE, VLC_FALSE );
i++;
}
}
......@@ -319,7 +319,7 @@ static void openDirectory( intf_thread_t* p_intf, bool pl, bool go )
0, NULL, -1 );
playlist_AddInput( THEPL, p_input,
go ? ( PLAYLIST_APPEND | PLAYLIST_GO ) : PLAYLIST_APPEND,
PLAYLIST_END, pl);
PLAYLIST_END, pl, VLC_FALSE );
input_Read( THEPL, p_input, VLC_FALSE );
}
......@@ -354,7 +354,7 @@ void DialogsProvider::streamingDialog()
playlist_AddExt( THEPL, qtu( o->mrl ), "Streaming",
PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END,
-1, &psz_option, 1, VLC_TRUE );
-1, &psz_option, 1, VLC_TRUE, VLC_FALSE );
}
delete s;
}
......
......@@ -521,7 +521,7 @@ void MainInterface::dropEvent(QDropEvent *event)
if( s.length() > 0 ) {
playlist_Add( THEPL, qtu(s), NULL,
PLAYLIST_APPEND | (first ? PLAYLIST_GO:0),
PLAYLIST_END, VLC_TRUE );
PLAYLIST_END, VLC_TRUE, VLC_FALSE );
first = false;
}
}
......
......@@ -453,10 +453,10 @@ void DialogsProvider::OnOpenFileSimple( wxCommandEvent& event )
playlist_Add( p_playlist, psz_utf8, NULL,
PLAYLIST_APPEND | (i ? 0 : PLAYLIST_GO) |
(i ? PLAYLIST_PREPARSE : 0 ),
PLAYLIST_END, VLC_TRUE );
PLAYLIST_END, VLC_TRUE, VLC_FALSE );
else
playlist_Add( p_playlist, psz_utf8, NULL,
PLAYLIST_APPEND | PLAYLIST_PREPARSE , PLAYLIST_END , VLC_TRUE);
PLAYLIST_APPEND | PLAYLIST_PREPARSE , PLAYLIST_END , VLC_TRUE, VLC_FALSE );
wxLocaleFree( psz_utf8 );
}
}
......@@ -483,7 +483,7 @@ void DialogsProvider::OnOpenDirectory( wxCommandEvent& event )
char *psz_utf8 = wxFromLocale( path );
playlist_Add( p_playlist, psz_utf8, NULL,
PLAYLIST_APPEND | (event.GetInt() ? PLAYLIST_GO : 0),
PLAYLIST_END, VLC_TRUE );
PLAYLIST_END, VLC_TRUE, VLC_FALSE );
wxLocaleFree( psz_utf8 );
}
......
......@@ -1206,13 +1206,13 @@ void OpenDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
{
playlist_AddInput( p_playlist, p_input,
PLAYLIST_APPEND | PLAYLIST_GO,
PLAYLIST_END, VLC_TRUE );
PLAYLIST_END, VLC_TRUE, VLC_FALSE );
}
else
{
playlist_AddInput( p_playlist, p_input,
PLAYLIST_APPEND|PLAYLIST_PREPARSE,
PLAYLIST_END, VLC_TRUE );
PLAYLIST_END, VLC_TRUE, VLC_FALSE );
}
}
......
......@@ -1640,7 +1640,7 @@ void WizardDialog::Run()
input_ItemAddOption( p_input, psz_ttl );
playlist_AddInput( p_playlist, p_input,
PLAYLIST_GO, PLAYLIST_END, VLC_TRUE );
PLAYLIST_GO, PLAYLIST_END, VLC_TRUE, VLC_FALSE );
vlc_object_release(p_playlist);
}
else
......
......@@ -1324,7 +1324,7 @@ bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
playlist_Add( p_playlist, psz_utf8, NULL,
PLAYLIST_APPEND | ((i | b_enqueue) ? 0 : PLAYLIST_GO),
PLAYLIST_END, VLC_TRUE );
PLAYLIST_END, VLC_TRUE, VLC_FALSE );
wxDnDLocaleFree( psz_utf8 );
}
......
......@@ -184,12 +184,14 @@ static void resolve_callback(
playlist_item_t *p_item;
p_item = playlist_NodeAddInput( p_sys->p_playlist, p_input,
p_sys->p_node_cat,
PLAYLIST_APPEND, PLAYLIST_END );
PLAYLIST_APPEND, PLAYLIST_END,
VLC_FALSE);
p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
p_item = playlist_NodeAddInput( p_sys->p_playlist, p_input,
p_sys->p_node_one,
PLAYLIST_APPEND, PLAYLIST_END );
PLAYLIST_APPEND, PLAYLIST_END,
VLC_FALSE );
p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
}
......
......@@ -226,10 +226,12 @@ static void AddItem( services_discovery_t *p_sd, input_item_t * p_input
return;
}
p_item_cat = playlist_NodeAddInput( p_playlist,
p_input,p_sd->p_sys->p_node_cat, PLAYLIST_APPEND, PLAYLIST_END );
p_input,p_sd->p_sys->p_node_cat, PLAYLIST_APPEND, PLAYLIST_END,
VLC_FALSE );
p_item_cat->i_flags &= ~PLAYLIST_SKIP_FLAG;
p_item_one = playlist_NodeAddInput( p_playlist,
p_input,p_sd->p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END );
p_input,p_sd->p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END,
VLC_FALSE );
p_item_one->i_flags &= ~PLAYLIST_SKIP_FLAG;
vlc_object_release( p_playlist );
......
......@@ -167,9 +167,11 @@ static int Open( vlc_object_t *p_this )
p_sys->ppsz_urls[i], 0, NULL, -1 );
input_ItemAddOption( p_input, "demux=podcast" );
p_item = playlist_NodeAddInput( p_playlist, p_input, p_sys->p_node_cat,
PLAYLIST_APPEND, PLAYLIST_END );
PLAYLIST_APPEND, PLAYLIST_END,
VLC_FALSE );
p_item = playlist_NodeAddInput( p_playlist, p_input, p_sys->p_node_one,
PLAYLIST_APPEND, PLAYLIST_END );
PLAYLIST_APPEND, PLAYLIST_END,
VLC_FALSE );
free( psz_buf );
p_sys->pp_input[i] = input_CreateThread( p_playlist, p_input );
}
......
......@@ -813,13 +813,14 @@ sap_announce_t *CreateAnnounce( services_discovery_t *p_sd, uint16_t i_hash,
}
p_item = playlist_NodeAddInput( pl_Get( p_sd ), p_input, p_child,
PLAYLIST_APPEND, PLAYLIST_END );
PLAYLIST_APPEND, PLAYLIST_END, VLC_FALSE );
p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
p_sap->i_item_id_cat = p_item->i_id;
p_item = playlist_NodeAddInput( pl_Get( p_sd ), p_input,
p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END );
p_sys->p_node_one, PLAYLIST_APPEND, PLAYLIST_END,
VLC_FALSE );
p_item->i_flags &= ~PLAYLIST_SKIP_FLAG;
p_item->i_flags &= ~PLAYLIST_SAVE_FLAG;
p_sap->i_item_id_one = p_item->i_id;
......
......@@ -139,10 +139,10 @@ static int Open( vlc_object_t *p_this, int i_type )
p_sys->p_input->b_prefers_tree = VLC_TRUE;
p_sys->p_node_cat = playlist_NodeAddInput( p_playlist, p_sys->p_input,
p_playlist->p_root_category,
PLAYLIST_APPEND, PLAYLIST_END );
PLAYLIST_APPEND, PLAYLIST_END, VLC_FALSE );
p_sys->p_node_one = playlist_NodeAddInput( p_playlist, p_sys->p_input,
p_playlist->p_root_onelevel,
PLAYLIST_APPEND, PLAYLIST_END );
PLAYLIST_APPEND, PLAYLIST_END, VLC_FALSE );
p_sys->p_node_cat->i_flags |= PLAYLIST_RO_FLAG;
p_sys->p_node_cat->i_flags |= PLAYLIST_SKIP_FLAG;
p_sys->p_node_one->i_flags |= PLAYLIST_RO_FLAG;
......
......@@ -240,7 +240,8 @@ void UPnPHandler::AddContent( playlist_item_t *p_parent, ContentNode *node )
ItemNode *iNode = (ItemNode *)node;
input_item_t *p_input = input_ItemNew( p_sd, iNode->getResource(), title );
playlist_BothAddInput( p_sys->p_playlist, p_input, p_parent,
PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL );
PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL,
VLC_FALSE );
} else if ( node->isContainerNode() )
{
ContainerNode *conNode = (ContainerNode *)node;
......
......@@ -871,7 +871,8 @@ void MediaServer::_buildPlaylist( Container* parent )
item->getTitle() );
int i_cat;
playlist_BothAddInput( p_playlist, p_input, parentNode,
PLAYLIST_APPEND, PLAYLIST_END, &i_cat, NULL );
PLAYLIST_APPEND, PLAYLIST_END, &i_cat, NULL,
VLC_FALSE );
/* TODO: do this better by storing ids */
playlist_item_t *p_node = playlist_ItemGetById( p_playlist, i_cat, VLC_FALSE );
assert( p_node );
......
......@@ -49,7 +49,9 @@ VLC_EXPORT (int, libvlc_InternalAddIntf, ( libvlc_int_t *, const char *, vlc_boo
struct libvlc_instance_t
{
libvlc_int_t *p_libvlc_int;
vlm_t *p_vlm;
vlm_t *p_vlm;
int b_playlist_locked;
vlc_mutex_t instance_lock;
};
struct libvlc_input_t
......
......@@ -31,6 +31,23 @@
#define PL p_instance->p_libvlc_int->p_playlist
static inline int playlist_was_locked( libvlc_instance_t *p_instance )
{
int was_locked;
vlc_mutex_lock( &p_instance->instance_lock );
was_locked = p_instance->b_playlist_locked;
vlc_mutex_unlock( &p_instance->instance_lock );
return was_locked;
}
static inline void playlist_mark_locked( libvlc_instance_t *p_instance,
int locked )
{
vlc_mutex_lock( &p_instance->instance_lock );
p_instance->b_playlist_locked = locked;
vlc_mutex_unlock( &p_instance->instance_lock );
}
void libvlc_playlist_loop( libvlc_instance_t *p_instance, vlc_bool_t loop,
libvlc_exception_t *p_e)
{
......@@ -42,30 +59,54 @@ void libvlc_playlist_play( libvlc_instance_t *p_instance, int i_id,
int i_options, char **ppsz_options,
libvlc_exception_t *p_e )
{
int did_lock = 0;
assert( PL );
///\todo Handle additionnal options
if( PL->items.i_size == 0 ) RAISEVOID( "Empty playlist" );
if( i_id > 0 )
{
playlist_item_t *p_item = playlist_ItemGetByInputId( PL, i_id,
PL->status.p_node );
if( !p_item ) RAISEVOID( "Unable to find item" );
playlist_Control( PL, PLAYLIST_VIEWPLAY, VLC_FALSE,
playlist_item_t *p_item;
if (! playlist_was_locked( p_instance ) )
{
playlist_mark_locked( p_instance, 1 );
vlc_mutex_lock( &PL->object_lock );
did_lock = 1;
}
p_item = playlist_ItemGetByInputId( PL, i_id,
PL->status.p_node );
if( !p_item )
{
if( did_lock == 1 )
{
vlc_mutex_unlock( &PL->object_lock );
playlist_mark_locked( p_instance, 0 );
}
RAISEVOID( "Unable to find item" );
}
playlist_Control( PL, PLAYLIST_VIEWPLAY, VLC_TRUE,
PL->status.p_node, p_item );
if( did_lock == 1 )
{
vlc_mutex_unlock( &PL->object_lock );
playlist_mark_locked( p_instance, 0 );
}
}
else
{
playlist_Play( PL );
playlist_Control( PL, PLAYLIST_PLAY,
playlist_was_locked( p_instance ) );
}
}
void libvlc_playlist_pause( libvlc_instance_t *p_instance,
libvlc_exception_t *p_e )
libvlc_exception_t *p_e )
{
assert( PL );
if( playlist_Pause( PL ) != VLC_SUCCESS )
if( playlist_Control( PL, PLAYLIST_PAUSE,
playlist_was_locked( p_instance ) ) != VLC_SUCCESS )
RAISEVOID( "Empty playlist" );
}
......@@ -74,29 +115,32 @@ void libvlc_playlist_stop( libvlc_instance_t *p_instance,
libvlc_exception_t *p_e )
{
assert( PL );
if( playlist_Stop( PL ) != VLC_SUCCESS )
if( playlist_Control( PL, PLAYLIST_STOP,
playlist_was_locked( p_instance ) ) != VLC_SUCCESS )
RAISEVOID( "Empty playlist" );
}
void libvlc_playlist_clear( libvlc_instance_t *p_instance,
libvlc_exception_t *p_e )
libvlc_exception_t *p_e )
{
assert( PL );
playlist_Clear( PL, VLC_FALSE );
playlist_Clear( PL, playlist_was_locked( p_instance ) );
}
void libvlc_playlist_next( libvlc_instance_t *p_instance,
libvlc_exception_t *p_e )
{
assert( PL );
if( playlist_Next( PL ) != VLC_SUCCESS )
if( playlist_Control( PL, PLAYLIST_SKIP, playlist_was_locked( p_instance ),
1 ) != VLC_SUCCESS )
RAISEVOID( "Empty playlist" );
}
void libvlc_playlist_prev( libvlc_instance_t *p_instance,
libvlc_exception_t *p_e )
{
if( playlist_Prev( PL ) != VLC_SUCCESS )
if( playlist_Control( PL, PLAYLIST_SKIP, playlist_was_locked( p_instance ),
-1 ) != VLC_SUCCESS )
RAISEVOID( "Empty playlist" );
}
......@@ -113,19 +157,25 @@ int libvlc_playlist_add_extended( libvlc_instance_t *p_instance,
libvlc_exception_t *p_e )
{
assert( PL );
if( playlist_was_locked( p_instance ) )
{
libvlc_exeption_raise( p_e, "You must unlock playlist before "
"calling libvlc_playlist_add" );
return VLC_EGENERIC;
}
return playlist_AddExt( PL, psz_uri, psz_name,
PLAYLIST_INSERT, PLAYLIST_END, -1, ppsz_options,
i_options, 1 );
i_options, 1, VLC_FALSE );
}
int libvlc_playlist_delete_item( libvlc_instance_t *p_instance, int i_id,
libvlc_exception_t *p_e )
{
assert( PL );
if( playlist_DeleteFromInput( PL, i_id, VLC_FALSE ) )
if( playlist_DeleteFromInput( PL, i_id,
playlist_was_locked( p_instance ) ) )