Commit f2b9c723 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

playlist: create the playlist when needed (refs #5460)

parent d629c7df
...@@ -145,7 +145,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, ...@@ -145,7 +145,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
char * psz_modules = NULL; char * psz_modules = NULL;
char * psz_parser = NULL; char * psz_parser = NULL;
char * psz_control = NULL; char * psz_control = NULL;
playlist_t *p_playlist = NULL;
char *psz_val; char *psz_val;
/* System specific initialization code */ /* System specific initialization code */
...@@ -433,15 +432,6 @@ dbus_out: ...@@ -433,15 +432,6 @@ dbus_out:
var_Create( p_libvlc, "user-agent", VLC_VAR_STRING ); var_Create( p_libvlc, "user-agent", VLC_VAR_STRING );
var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" ); var_SetString( p_libvlc, "user-agent", "(LibVLC "VERSION")" );
/* Initialize playlist and get commandline files */
p_playlist = playlist_Create( VLC_OBJECT(p_libvlc) );
if( !p_playlist )
{
msg_Err( p_libvlc, "playlist initialization failed" );
module_EndBank (true);
return VLC_EGENERIC;
}
/* System specific configuration */ /* System specific configuration */
system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind );
...@@ -468,7 +458,7 @@ dbus_out: ...@@ -468,7 +458,7 @@ dbus_out:
{ {
char *p = psz_modules, *m; char *p = psz_modules, *m;
while( ( m = strsep( &p, " :," ) ) != NULL ) while( ( m = strsep( &p, " :," ) ) != NULL )
playlist_ServicesDiscoveryAdd( p_playlist, m ); playlist_ServicesDiscoveryAdd( pl_Get(p_libvlc), m );
free( psz_modules ); free( psz_modules );
} }
...@@ -582,7 +572,7 @@ dbus_out: ...@@ -582,7 +572,7 @@ dbus_out:
psz_val = var_InheritString( p_libvlc, "open" ); psz_val = var_InheritString( p_libvlc, "open" );
if ( psz_val != NULL ) if ( psz_val != NULL )
{ {
playlist_AddExt( p_playlist, psz_val, NULL, PLAYLIST_INSERT, 0, playlist_AddExt( pl_Get(p_libvlc), psz_val, NULL, PLAYLIST_INSERT, 0,
-1, 0, NULL, 0, true, pl_Unlocked ); -1, 0, NULL, 0, true, pl_Unlocked );
free( psz_val ); free( psz_val );
} }
...@@ -600,8 +590,11 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc ) ...@@ -600,8 +590,11 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
playlist_t *p_playlist = libvlc_priv (p_libvlc)->p_playlist; playlist_t *p_playlist = libvlc_priv (p_libvlc)->p_playlist;
/* Remove all services discovery */ /* Remove all services discovery */
msg_Dbg( p_libvlc, "removing all services discovery tasks" ); if( p_playlist != NULL )
playlist_ServicesDiscoveryKillAll( p_playlist ); {
msg_Dbg( p_libvlc, "removing all services discovery tasks" );
playlist_ServicesDiscoveryKillAll( p_playlist );
}
/* Ask the interfaces to stop and destroy them */ /* Ask the interfaces to stop and destroy them */
msg_Dbg( p_libvlc, "removing all interfaces" ); msg_Dbg( p_libvlc, "removing all interfaces" );
...@@ -627,7 +620,8 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc ) ...@@ -627,7 +620,8 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc )
#endif #endif
/* Free playlist now, all threads are gone */ /* Free playlist now, all threads are gone */
playlist_Destroy( p_playlist ); if( p_playlist != NULL )
playlist_Destroy( p_playlist );
msg_Dbg( p_libvlc, "removing stats" ); msg_Dbg( p_libvlc, "removing stats" );
......
...@@ -141,8 +141,6 @@ typedef struct libvlc_priv_t ...@@ -141,8 +141,6 @@ typedef struct libvlc_priv_t
{ {
libvlc_int_t public_data; libvlc_int_t public_data;
bool playlist_active;
/* Messages */ /* Messages */
signed char i_verbose; ///< info messages signed char i_verbose; ///< info messages
bool b_color; ///< color messages? bool b_color; ///< color messages?
......
...@@ -195,7 +195,7 @@ static int VideoSplitterCallback( vlc_object_t *p_this, char const *psz_cmd, ...@@ -195,7 +195,7 @@ static int VideoSplitterCallback( vlc_object_t *p_this, char const *psz_cmd,
* \param p_parent the vlc object that is to be the parent of this playlist * \param p_parent the vlc object that is to be the parent of this playlist
* \return a pointer to the created playlist, or NULL on error * \return a pointer to the created playlist, or NULL on error
*/ */
playlist_t * playlist_Create( vlc_object_t *p_parent ) static playlist_t *playlist_Create( vlc_object_t *p_parent )
{ {
playlist_t *p_playlist; playlist_t *p_playlist;
playlist_private_t *p; playlist_private_t *p;
...@@ -209,8 +209,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent ) ...@@ -209,8 +209,6 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
p_playlist = &p->public_data; p_playlist = &p->public_data;
TAB_INIT( pl_priv(p_playlist)->i_sds, pl_priv(p_playlist)->pp_sds ); TAB_INIT( pl_priv(p_playlist)->i_sds, pl_priv(p_playlist)->pp_sds );
libvlc_priv(p_parent->p_libvlc)->p_playlist = p_playlist;
VariablesInit( p_playlist ); VariablesInit( p_playlist );
vlc_mutex_init( &p->lock ); vlc_mutex_init( &p->lock );
vlc_cond_init( &p->signal ); vlc_cond_init( &p->signal );
...@@ -298,6 +296,14 @@ playlist_t * playlist_Create( vlc_object_t *p_parent ) ...@@ -298,6 +296,14 @@ playlist_t * playlist_Create( vlc_object_t *p_parent )
pl_priv(p_playlist)->b_auto_preparse = b_auto_preparse; pl_priv(p_playlist)->b_auto_preparse = b_auto_preparse;
} }
/* Input resources */
p->p_input_resource = input_resource_New( VLC_OBJECT( p_playlist ) );
if( unlikely(p->p_input_resource == NULL) )
abort();
/* Thread */
playlist_Activate (p_playlist);
return p_playlist; return p_playlist;
} }
...@@ -366,12 +372,12 @@ playlist_t *pl_Get (vlc_object_t *obj) ...@@ -366,12 +372,12 @@ playlist_t *pl_Get (vlc_object_t *obj)
vlc_mutex_lock (&lock); vlc_mutex_lock (&lock);
pl = libvlc_priv (p_libvlc)->p_playlist; pl = libvlc_priv (p_libvlc)->p_playlist;
assert (pl != NULL); if (unlikely(pl == NULL))
if (!libvlc_priv (p_libvlc)->playlist_active)
{ {
playlist_Activate (pl); pl = playlist_Create (VLC_OBJECT(p_libvlc));
libvlc_priv (p_libvlc)->playlist_active = true; if (unlikely(pl == NULL))
abort();
libvlc_priv (p_libvlc)->p_playlist = pl;
} }
vlc_mutex_unlock (&lock); vlc_mutex_unlock (&lock);
return pl; return pl;
......
...@@ -99,10 +99,7 @@ typedef struct playlist_private_t ...@@ -99,10 +99,7 @@ typedef struct playlist_private_t
*****************************************************************************/ *****************************************************************************/
/* Creation/Deletion */ /* Creation/Deletion */
playlist_t *playlist_Create( vlc_object_t * );
void playlist_Destroy( playlist_t * ); void playlist_Destroy( playlist_t * );
/* */
void playlist_Activate( playlist_t * ); void playlist_Activate( playlist_t * );
/* */ /* */
......
...@@ -46,29 +46,18 @@ static void *Thread ( void * ); ...@@ -46,29 +46,18 @@ static void *Thread ( void * );
*****************************************************************************/ *****************************************************************************/
/** /**
* Create the main playlist threads. * Creates the main playlist thread.
* Additionally to the playlist, this thread controls :
* - Statistics
* - VLM
* \param p_parent
* \return an object with a started thread
*/ */
void playlist_Activate( playlist_t *p_playlist ) void playlist_Activate( playlist_t *p_playlist )
{ {
/* */
playlist_private_t *p_sys = pl_priv(p_playlist); playlist_private_t *p_sys = pl_priv(p_playlist);
p_sys->p_input_resource = input_resource_New( VLC_OBJECT( p_playlist ) );
if( unlikely(p_sys->p_input_resource == NULL) )
abort();
/* Start the playlist thread */
if( vlc_clone( &p_sys->thread, Thread, p_playlist, if( vlc_clone( &p_sys->thread, Thread, p_playlist,
VLC_THREAD_PRIORITY_LOW ) ) VLC_THREAD_PRIORITY_LOW ) )
{ {
msg_Err( p_playlist, "cannot spawn playlist thread" ); msg_Err( p_playlist, "cannot spawn playlist thread" );
abort();
} }
msg_Dbg( p_playlist, "playlist threads correctly activated" );
} }
/** /**
...@@ -80,9 +69,6 @@ void playlist_Deactivate( playlist_t *p_playlist ) ...@@ -80,9 +69,6 @@ void playlist_Deactivate( playlist_t *p_playlist )
{ {
playlist_private_t *p_sys = pl_priv(p_playlist); playlist_private_t *p_sys = pl_priv(p_playlist);
if( p_sys->p_input_resource == NULL )
return; /* playlist was never activated... */
PL_LOCK; PL_LOCK;
/* WARNING: There is a latent bug. It is assumed that only one thread will /* WARNING: There is a latent bug. It is assumed that only one thread will
* be waiting for playlist deactivation at a time. So far, that works * be waiting for playlist deactivation at a time. So far, that works
......
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