X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Flibvlc.c;h=9ec04a6b5590d8d63197d36d849e087009e0ed62;hb=6cf46ba69751908f401b28264e68cb805ddd5b65;hp=a4e0c5bd6fa34cbd0db83013086352b7da4060fc;hpb=ef1962f89acadb8069365ba1f74c2dc1b1363848;p=vlc diff --git a/src/libvlc.c b/src/libvlc.c index a4e0c5bd6f..9ec04a6b55 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -68,6 +68,8 @@ # include #endif + +#include #include #include @@ -251,6 +253,7 @@ libvlc_int_t * libvlc_InternalCreate( void ) priv = libvlc_priv (p_libvlc); priv->p_playlist = NULL; + priv->p_ml = NULL; priv->p_dialog_provider = NULL; priv->p_vlm = NULL; @@ -273,6 +276,7 @@ libvlc_int_t * libvlc_InternalCreate( void ) /* Initialize mutexes */ vlc_mutex_init( &priv->timer_lock ); + vlc_ExitInit( &priv->exit ); return p_libvlc; error: @@ -321,7 +325,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, * options) */ module_InitBank( p_libvlc ); - if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, true ) ) + if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, NULL ) ) { module_EndBank( p_libvlc, false ); return VLC_EGENERIC; @@ -534,10 +538,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, /* * Override configuration with command line settings */ - /* config_LoadCmdLine(), DBus (below) and Win32-specific use vlc_optind, - * vlc_optarg and vlc_optopt globals. This is not thread-safe!! */ -#warning BUG! - if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, false ) ) + int vlc_optind; + if( config_LoadCmdLine( p_libvlc, i_argc, ppsz_argv, &vlc_optind ) ) { #ifdef WIN32 ShowConsole( false ); @@ -818,7 +820,24 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, } /* System specific configuration */ - system_Configure( p_libvlc, &i_argc, ppsz_argv ); + system_Configure( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); + +#if defined(MEDIA_LIBRARY) + /* Get the ML */ + if( var_GetBool( p_libvlc, "load-media-library-on-startup" ) == true ) + { + priv->p_ml = __ml_Create( VLC_OBJECT( p_libvlc ), NULL ); + if( !priv->p_ml ) + { + msg_Err( p_libvlc, "ML initialization failed" ); + return VLC_EGENERIC; + } + } + else + { + priv->p_ml = NULL; + } +#endif /* Add service discovery modules */ psz_modules = var_InheritString( p_libvlc, "services-discovery" ); @@ -966,7 +985,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc, * We assume that the remaining parameters are filenames * and their input options. */ - msg_Info( p_libvlc, "optind = %u", vlc_optind ); GetFilenames( p_libvlc, i_argc - vlc_optind, ppsz_argv + vlc_optind ); /* @@ -1016,6 +1034,22 @@ void libvlc_InternalCleanup( libvlc_int_t *p_libvlc ) /* Free playlist now, all threads are gone */ playlist_Destroy( p_playlist ); + /* Free playlist now */ +#if defined(MEDIA_LIBRARY) + media_library_t* p_ml = priv->p_ml; + if( p_ml ) + { + __ml_Destroy( VLC_OBJECT( p_ml ) ); + vlc_object_release( p_ml ); + libvlc_priv(p_playlist->p_libvlc)->p_ml = NULL; + } +#endif + + /* Free playlist */ + /* Any thread still running must not assume pl_Hold() succeeds. */ + msg_Dbg( p_libvlc, "removing playlist" ); + vlc_object_release( p_playlist ); + stats_TimersDumpAll( p_libvlc ); stats_TimersCleanAll( p_libvlc ); @@ -1076,6 +1110,7 @@ void libvlc_InternalDestroy( libvlc_int_t *p_libvlc ) msg_Destroy (priv->msg_bank); /* Destroy mutexes */ + vlc_ExitDestroy( &priv->exit ); vlc_mutex_destroy( &priv->timer_lock ); #ifndef NDEBUG /* Hack to dump leaked objects tree */ @@ -1124,40 +1159,6 @@ int libvlc_InternalAddIntf( libvlc_int_t *p_libvlc, char const *psz_module ) return ret; } -#ifndef WIN32 -static vlc_mutex_t exit_lock = VLC_STATIC_MUTEX; -static vlc_cond_t exiting = VLC_STATIC_COND; -#else -extern vlc_mutex_t super_mutex; -extern vlc_cond_t super_variable; -# define exit_lock super_mutex -# define exiting super_variable -#endif - -/** - * Waits until the LibVLC instance gets an exit signal. Normally, this happens - * when the user "exits" an interface plugin. - */ -void libvlc_InternalWait( libvlc_int_t *p_libvlc ) -{ - vlc_mutex_lock( &exit_lock ); - while( vlc_object_alive( p_libvlc ) ) - vlc_cond_wait( &exiting, &exit_lock ); - vlc_mutex_unlock( &exit_lock ); -} - -/** - * Posts an exit signal to LibVLC instance. This will normally initiate the - * cleanup and destroy process. It should only be called on behalf of the user. - */ -void libvlc_Quit( libvlc_int_t *p_libvlc ) -{ - vlc_mutex_lock( &exit_lock ); - vlc_object_kill( p_libvlc ); - vlc_cond_broadcast( &exiting ); - vlc_mutex_unlock( &exit_lock ); -} - #if defined( ENABLE_NLS ) && (defined (__APPLE__) || defined (WIN32)) && \ ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) /***************************************************************************** @@ -1180,8 +1181,7 @@ static void SetLanguage ( const char *psz_lang ) * makes the environment unconsistent when libvlc is unloaded and * should probably be moved to a safer place like vlc.c. */ static char psz_lcall[20]; - snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang ); - psz_lcall[19] = '\0'; + snprintf( psz_lcall, sizeof(psz_lcall), "LC_ALL=%s", psz_lang ); putenv( psz_lcall ); #endif @@ -1427,15 +1427,15 @@ static void Usage( libvlc_int_t *p_this, char const *psz_search ) ( b_strict ? strcmp( psz_search, p_parser->psz_object_name ) : !strstr( p_parser->psz_object_name, psz_search ) ) ) { - char *const *pp_shortcut = p_parser->pp_shortcuts; - while( *pp_shortcut ) + char *const *pp_shortcuts = p_parser->pp_shortcuts; + unsigned i; + for( i = 0; i < p_parser->i_shortcuts; i++ ) { - if( b_strict ? !strcmp( psz_search, *pp_shortcut ) - : !!strstr( *pp_shortcut, psz_search ) ) + if( b_strict ? !strcmp( psz_search, pp_shortcuts[i] ) + : !!strstr( pp_shortcuts[i], psz_search ) ) break; - pp_shortcut ++; } - if( !*pp_shortcut ) + if( i == p_parser->i_shortcuts ) continue; } @@ -1865,19 +1865,18 @@ static void ListModules( libvlc_int_t *p_this, bool b_verbose ) if( b_verbose ) { - char *const *pp_shortcut = p_parser->pp_shortcuts; - while( *pp_shortcut ) + char *const *pp_shortcuts = p_parser->pp_shortcuts; + for( unsigned i = 0; i < p_parser->i_shortcuts; i++ ) { - if( strcmp( *pp_shortcut, p_parser->psz_object_name ) ) + if( strcmp( pp_shortcuts[i], p_parser->psz_object_name ) ) { if( b_color ) utf8_fprintf( stdout, CYAN" s %s\n"GRAY, - *pp_shortcut ); + pp_shortcuts[i] ); else utf8_fprintf( stdout, " s %s\n", - *pp_shortcut ); + pp_shortcuts[i] ); } - pp_shortcut++; } if( p_parser->psz_capability ) { @@ -2004,15 +2003,3 @@ static int ConsoleWidth( void ) return i_width; } - -#include - -void vlc_avcodec_mutex (bool acquire) -{ - static vlc_mutex_t lock = VLC_STATIC_MUTEX; - - if (acquire) - vlc_mutex_lock (&lock); - else - vlc_mutex_unlock (&lock); -}