- char p_capabilities[200];
- char * p_tmp;
- char * psz_modules;
- char * psz_parser;
- char * psz_control;
- vlc_bool_t b_exit = VLC_FALSE;
- int i_ret = VLC_EEXIT;
- module_t *p_help_module;
- playlist_t *p_playlist;
- vlc_value_t val;
-#if defined( ENABLE_NLS ) \
- && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
-# if defined (WIN32) || defined (__APPLE__)
- char * psz_language;
-#endif
-#endif
- libvlc_int_t * p_libvlc = vlc_current_object( i_object );
-
- if( !p_libvlc )
- {
- return VLC_ENOOBJ;
- }
-
- /*
- * System specific initialization code
- */
- system_Init( p_libvlc, &i_argc, ppsz_argv );
-
- /* Get the executable name (similar to the basename command) */
- if( i_argc > 0 )
- {
- p_libvlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
- while( *p_tmp )
- {
- if( *p_tmp == '/' ) p_libvlc->psz_object_name = ++p_tmp;
- else ++p_tmp;
- }
- }
- else
- {
- p_libvlc->psz_object_name = "vlc";
- }
-
- /*
- * Support for gettext
- */
- SetLanguage( "" );
-
- /*
- * Global iconv, must be done after setlocale()
- * so that vlc_current_charset() works.
- */
- LocaleInit( (vlc_object_t *)p_libvlc );
-
- /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
- msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
-
- /* Initialize the module bank and load the configuration of the
- * main module. We need to do this at this stage to be able to display
- * a short help if required by the user. (short help == main module
- * options) */
- module_InitBank( p_libvlc );
-
- /* Hack: insert the help module here */
- p_help_module = vlc_object_create( p_libvlc, VLC_OBJECT_MODULE );
- if( p_help_module == NULL )
- {
- module_EndBank( p_libvlc );
- if( i_object ) vlc_object_release( p_libvlc );
- return VLC_EGENERIC;
- }
- p_help_module->psz_object_name = "help";
- p_help_module->psz_longname = N_("Help options");
- config_Duplicate( p_help_module, p_help_config );
- vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
- /* End hack */
-
- if( config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE ) )
- {
- vlc_object_detach( p_help_module );
- config_Free( p_help_module );
- vlc_object_destroy( p_help_module );
- module_EndBank( p_libvlc );
- if( i_object ) vlc_object_release( p_libvlc );
- return VLC_EGENERIC;
- }
-
- /* Check for short help option */
- if( config_GetInt( p_libvlc, "help" ) )
- {
- Help( p_libvlc, "help" );
- b_exit = VLC_TRUE;
- i_ret = VLC_EEXITSUCCESS;
- }
- /* Check for version option */
- else if( config_GetInt( p_libvlc, "version" ) )
- {
- Version();
- b_exit = VLC_TRUE;
- i_ret = VLC_EEXITSUCCESS;
- }
-
- /* Set the config file stuff */
- p_libvlc->psz_homedir = config_GetHomeDir();
- p_libvlc->psz_userdir = config_GetUserDir();
- if( p_libvlc->psz_userdir == NULL )
- p_libvlc->psz_userdir = strdup(p_libvlc->psz_homedir);
- p_libvlc->psz_configfile = config_GetPsz( p_libvlc, "config" );
- if( p_libvlc->psz_configfile != NULL && p_libvlc->psz_configfile[0] == '~'
- && p_libvlc->psz_configfile[1] == '/' )
- {
- char *psz = malloc( strlen(p_libvlc->psz_userdir)
- + strlen(p_libvlc->psz_configfile) );
- /* This is incomplete : we should also support the ~cmassiot/ syntax. */
- sprintf( psz, "%s/%s", p_libvlc->psz_userdir,
- p_libvlc->psz_configfile + 2 );
- free( p_libvlc->psz_configfile );
- p_libvlc->psz_configfile = psz;
- }
-
- /* Check for plugins cache options */
- if( config_GetInt( p_libvlc, "reset-plugins-cache" ) )
- {
- libvlc_global.p_module_bank->b_cache_delete = VLC_TRUE;
- }
-
- /* Hack: remove the help module here */
- vlc_object_detach( p_help_module );
- /* End hack */
-
- /* Will be re-done properly later on */
- p_libvlc->p_libvlc_global->i_verbose = config_GetInt( p_libvlc, "verbose" );
-
- /* Check for daemon mode */
-#ifndef WIN32
- if( config_GetInt( p_libvlc, "daemon" ) )
- {
-#if HAVE_DAEMON
- if( daemon( 1, 0) != 0 )
- {
- msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
- b_exit = VLC_TRUE;
- }
-
- p_libvlc->p_libvlc_global->b_daemon = VLC_TRUE;
-
- /* lets check if we need to write the pidfile */
- char * psz_pidfile = config_GetPsz( p_libvlc, "pidfile" );
-
- msg_Dbg( p_libvlc, "psz_pidfile is %s", psz_pidfile );
-
- if( psz_pidfile != NULL )
- {
- FILE *pidfile;
- pid_t i_pid = getpid ();
-
- msg_Dbg( p_libvlc, "our PID is %d, writing it to %s", i_pid, psz_pidfile );
-
- pidfile = utf8_fopen( psz_pidfile,"w" );
- if( pidfile != NULL )
- {
- utf8_fprintf( pidfile, "%d", (int)i_pid );
- fclose( pidfile );
- }
- else
- {
- msg_Err( p_libvlc, "Cannot open pid file for writing: %s, error: %s",
- psz_pidfile, strerror(errno) );
- }
- }
-
- free( psz_pidfile );
-
-#else
- pid_t i_pid;
-
- if( ( i_pid = fork() ) < 0 )
- {
- msg_Err( p_libvlc, "Unable to fork vlc to daemon mode" );
- b_exit = VLC_TRUE;
- }
- else if( i_pid )
- {
- /* This is the parent, exit right now */
- msg_Dbg( p_libvlc, "closing parent process" );
- b_exit = VLC_TRUE;
- i_ret = VLC_EEXITSUCCESS;
- }
- else
- {
- /* We are the child */
- msg_Dbg( p_libvlc, "daemon spawned" );
- close( STDIN_FILENO );
- close( STDOUT_FILENO );
- close( STDERR_FILENO );
-
- p_libvlc->p_libvlc_global->b_daemon = VLC_TRUE;
- }
-#endif
- }
-#endif
-
- if( b_exit )
- {
- config_Free( p_help_module );
- vlc_object_destroy( p_help_module );
- module_EndBank( p_libvlc );
- if( i_object ) vlc_object_release( p_libvlc );
- return i_ret;
- }
-
- /* Check for translation config option */
-#if defined( ENABLE_NLS ) \
- && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
-# if defined (WIN32) || defined (__APPLE__)
- /* This ain't really nice to have to reload the config here but it seems
- * the only way to do it. */
- config_LoadConfigFile( p_libvlc, "main" );
- config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
-
- /* Check if the user specified a custom language */
- psz_language = config_GetPsz( p_libvlc, "language" );
- if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
- {
- vlc_bool_t b_cache_delete = libvlc_global.p_module_bank->b_cache_delete;
-
- /* Reset the default domain */
- SetLanguage( psz_language );
-
- /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
- msg_Dbg( p_libvlc, "translation test: code is \"%s\"", _("C") );
-
- module_EndBank( p_libvlc );
- module_InitBank( p_libvlc );
- config_LoadConfigFile( p_libvlc, "main" );
- config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
- libvlc_global.p_module_bank->b_cache_delete = b_cache_delete;
- }
- if( psz_language ) free( psz_language );
-# endif
-#endif
-
- /*
- * Load the builtins and plugins into the module_bank.
- * We have to do it before config_Load*() because this also gets the
- * list of configuration options exported by each module and loads their
- * default values.
- */
- module_LoadBuiltins( p_libvlc );
- module_LoadPlugins( p_libvlc );
- if( p_libvlc->b_die )
- {
- b_exit = VLC_TRUE;
- }
-
- msg_Dbg( p_libvlc, "module bank initialized, found %i modules",
- libvlc_global.p_module_bank->i_children );
-
- /* Hack: insert the help module here */
- vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
- /* End hack */
-
- /* Check for help on modules */
- if( (p_tmp = config_GetPsz( p_libvlc, "module" )) )
- {
- Help( p_libvlc, p_tmp );
- free( p_tmp );
- b_exit = VLC_TRUE;
- i_ret = VLC_EEXITSUCCESS;
- }
- /* Check for long help option */
- else if( config_GetInt( p_libvlc, "longhelp" ) )
- {
- Help( p_libvlc, "longhelp" );
- b_exit = VLC_TRUE;
- i_ret = VLC_EEXITSUCCESS;
- }
- /* Check for module list option */
- else if( config_GetInt( p_libvlc, "list" ) )
- {
- ListModules( p_libvlc );
- b_exit = VLC_TRUE;
- i_ret = VLC_EEXITSUCCESS;
- }
-
- /* Check for config file options */
- if( config_GetInt( p_libvlc, "reset-config" ) )
- {
- vlc_object_detach( p_help_module );
- config_ResetAll( p_libvlc );
- config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
- config_SaveConfigFile( p_libvlc, NULL );
- vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
- }
- if( config_GetInt( p_libvlc, "save-config" ) )
- {
- vlc_object_detach( p_help_module );
- config_LoadConfigFile( p_libvlc, NULL );
- config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_TRUE );
- config_SaveConfigFile( p_libvlc, NULL );
- vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
- }
-
- /* Hack: remove the help module here */
- vlc_object_detach( p_help_module );
- /* End hack */
-
- if( b_exit )
- {
- config_Free( p_help_module );
- vlc_object_destroy( p_help_module );
- module_EndBank( p_libvlc );
- if( i_object ) vlc_object_release( p_libvlc );
- return i_ret;
- }
-
- /*
- * Init device values
- */
- InitDeviceValues( p_libvlc );
-
- /*
- * Override default configuration with config file settings
- */
- config_LoadConfigFile( p_libvlc, NULL );
-
- /* Hack: insert the help module here */
- vlc_object_attach( p_help_module, libvlc_global.p_module_bank );
- /* End hack */
-
- /*
- * Override configuration with command line settings
- */
- if( config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, VLC_FALSE ) )
- {
-#ifdef WIN32
- ShowConsole( VLC_FALSE );
- /* Pause the console because it's destroyed when we exit */
- fprintf( stderr, "The command line options couldn't be loaded, check "
- "that they are valid.\n" );
- PauseConsole();
-#endif
- vlc_object_detach( p_help_module );
- config_Free( p_help_module );
- vlc_object_destroy( p_help_module );
- module_EndBank( p_libvlc );
- if( i_object ) vlc_object_release( p_libvlc );
- return VLC_EGENERIC;
- }
-
- /* Hack: remove the help module here */
- vlc_object_detach( p_help_module );
- config_Free( p_help_module );
- vlc_object_destroy( p_help_module );
- /* End hack */
-
- /*
- * System specific configuration
- */
- system_Configure( p_libvlc, &i_argc, ppsz_argv );
-
- /*
- * Message queue options
- */
-
- var_Create( p_libvlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
- if( config_GetInt( p_libvlc, "quiet" ) )
- {
- val.i_int = -1;
- var_Set( p_libvlc, "verbose", val );
- }
- var_AddCallback( p_libvlc, "verbose", VerboseCallback, NULL );
- var_Change( p_libvlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
-
- libvlc_global.b_color = libvlc_global.b_color &&
- config_GetInt( p_libvlc, "color" );
-
- /*
- * Output messages that may still be in the queue
- */
- msg_Flush( p_libvlc );
-
- /* p_libvlc initialization. FIXME ? */
-
- if( !config_GetInt( p_libvlc, "fpu" ) )
- libvlc_global.i_cpu &= ~CPU_CAPABILITY_FPU;
-
-#if defined( __i386__ ) || defined( __x86_64__ )
- if( !config_GetInt( p_libvlc, "mmx" ) )
- libvlc_global.i_cpu &= ~CPU_CAPABILITY_MMX;
- if( !config_GetInt( p_libvlc, "3dn" ) )
- libvlc_global.i_cpu &= ~CPU_CAPABILITY_3DNOW;
- if( !config_GetInt( p_libvlc, "mmxext" ) )
- libvlc_global.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
- if( !config_GetInt( p_libvlc, "sse" ) )
- libvlc_global.i_cpu &= ~CPU_CAPABILITY_SSE;
- if( !config_GetInt( p_libvlc, "sse2" ) )
- libvlc_global.i_cpu &= ~CPU_CAPABILITY_SSE2;
-#endif
-#if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ )
- if( !config_GetInt( p_libvlc, "altivec" ) )
- libvlc_global.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
-#endif
-
-#define PRINT_CAPABILITY( capability, string ) \
- if( libvlc_global.i_cpu & capability ) \
- { \
- strncat( p_capabilities, string " ", \
- sizeof(p_capabilities) - strlen(p_capabilities) ); \
- p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
- }
-
- p_capabilities[0] = '\0';
- PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
- PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
- PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
- PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
- PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
- PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
- PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
- PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
- PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
- PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
- msg_Dbg( p_libvlc, "CPU has capabilities %s", p_capabilities );
-
- /*
- * Choose the best memcpy module
- */
- p_libvlc->p_memcpy_module = module_Need( p_libvlc, "memcpy", "$memcpy", 0 );
-
- if( p_libvlc->pf_memcpy == NULL )
- {
- p_libvlc->pf_memcpy = memcpy;
- }
-
- if( p_libvlc->pf_memset == NULL )
- {
- p_libvlc->pf_memset = memset;
- }
-
- p_libvlc->b_stats = config_GetInt( p_libvlc, "stats" );
- p_libvlc->i_timers = 0;
- p_libvlc->pp_timers = NULL;
- vlc_mutex_init( p_libvlc, &p_libvlc->timer_lock );
-
- /*
- * Initialize hotkey handling
- */
- var_Create( p_libvlc, "key-pressed", VLC_VAR_INTEGER );
- p_libvlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
- /* Do a copy (we don't need to modify the strings) */
- memcpy( p_libvlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
-
- /*
- * Initialize playlist and get commandline files
- */
- p_playlist = playlist_ThreadCreate( p_libvlc );
- if( !p_playlist )
- {
- msg_Err( p_libvlc, "playlist initialization failed" );
- if( p_libvlc->p_memcpy_module != NULL )
- {
- module_Unneed( p_libvlc, p_libvlc->p_memcpy_module );
- }
- module_EndBank( p_libvlc );
- if( i_object ) vlc_object_release( p_libvlc );
- return VLC_EGENERIC;
- }
-
- psz_modules = config_GetPsz( p_playlist, "services-discovery" );
- if( psz_modules && *psz_modules )
- {
- /* Add service discovery modules */
- playlist_AddSDModules( p_playlist, psz_modules );
- }
- if( psz_modules ) free( psz_modules );
-
- /*
- * Load background interfaces
- */
- psz_modules = config_GetPsz( p_libvlc, "extraintf" );
- psz_control = config_GetPsz( p_libvlc, "control" );
-
- if( psz_modules && *psz_modules && psz_control && *psz_control )
- {
- psz_modules = (char *)realloc( psz_modules, strlen( psz_modules ) +
- strlen( psz_control ) + 1 );
- sprintf( psz_modules, "%s:%s", psz_modules, psz_control );
- }
- else if( psz_control && *psz_control )
- {
- if( psz_modules ) free( psz_modules );
- psz_modules = strdup( psz_control );
- }
-
- psz_parser = psz_modules;
- while ( psz_parser && *psz_parser )
- {
- char *psz_module, *psz_temp;
- psz_module = psz_parser;
- psz_parser = strchr( psz_module, ':' );
- if ( psz_parser )
- {
- *psz_parser = '\0';
- psz_parser++;
- }
- psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
- if( psz_temp )
- {
- sprintf( psz_temp, "%s,none", psz_module );
- VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
- free( psz_temp );
- }
- }
- if ( psz_modules )
- {
- free( psz_modules );
- }
-
- /*
- * Always load the hotkeys interface if it exists
- */
- VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
-
- /*
- * If needed, load the Xscreensaver interface
- * Currently, only for X
- */
-#ifdef HAVE_X11_XLIB_H
- if( config_GetInt( p_libvlc, "disable-screensaver" ) == 1 )
- {
- VLC_AddIntf( 0, "screensaver,none", VLC_FALSE, VLC_FALSE );
- }
-#endif
-
- if( config_GetInt( p_libvlc, "file-logging" ) == 1 )
- {
- VLC_AddIntf( 0, "logger,none", VLC_FALSE, VLC_FALSE );
- }
-#ifdef HAVE_SYSLOG_H
- if( config_GetInt( p_libvlc, "syslog" ) == 1 )
- {
- char *psz_logmode = "logmode=syslog";
- AddIntfInternal( 0, "logger,none", VLC_FALSE, VLC_FALSE, 1, &psz_logmode );
- }
-#endif
-
- if( config_GetInt( p_libvlc, "show-intf" ) == 1 )
- {
- VLC_AddIntf( 0, "showintf,none", VLC_FALSE, VLC_FALSE );
- }
-
- if( config_GetInt( p_libvlc, "network-synchronisation") == 1 )
- {
- VLC_AddIntf( 0, "netsync,none", VLC_FALSE, VLC_FALSE );
- }
-
- /*
- * FIXME: kludge to use a p_libvlc-local variable for the Mozilla plugin
- */
- var_Create( p_libvlc, "drawable", VLC_VAR_INTEGER );
- var_Create( p_libvlc, "drawable-view-top", VLC_VAR_INTEGER );
- var_Create( p_libvlc, "drawable-view-left", VLC_VAR_INTEGER );
- var_Create( p_libvlc, "drawable-view-bottom", VLC_VAR_INTEGER );
- var_Create( p_libvlc, "drawable-view-right", VLC_VAR_INTEGER );
- var_Create( p_libvlc, "drawable-clip-top", VLC_VAR_INTEGER );
- var_Create( p_libvlc, "drawable-clip-left", VLC_VAR_INTEGER );
- var_Create( p_libvlc, "drawable-clip-bottom", VLC_VAR_INTEGER );
- var_Create( p_libvlc, "drawable-clip-right", VLC_VAR_INTEGER );
-
- /* Create volume callback system. */
- var_Create( p_libvlc, "volume-change", VLC_VAR_BOOL );
-
- /*
- * Get input filenames given as commandline arguments
- */
- GetFilenames( p_libvlc, i_argc, ppsz_argv );
-
- /*
- * Get --open argument
- */
- var_Create( p_libvlc, "open", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
- var_Get( p_libvlc, "open", &val );
- if ( val.psz_string != NULL && *val.psz_string )
- {
- VLC_AddTarget( p_libvlc->i_object_id, val.psz_string, NULL, 0,
- PLAYLIST_INSERT, 0 );
- }
- if ( val.psz_string != NULL ) free( val.psz_string );
-
- if( i_object ) vlc_object_release( p_libvlc );
- return VLC_SUCCESS;