- char p_capabilities[200];
- char * p_tmp;
- char * psz_modules;
- char * psz_parser;
- char * psz_control;
- vlc_bool_t b_exit = VLC_FALSE;
- vlc_t * p_vlc = vlc_current_object( i_object );
- module_t *p_help_module;
- playlist_t *p_playlist;
- vlc_value_t val;
- char * psz_language;
-
- if( !p_vlc )
- {
- return VLC_ENOOBJ;
- }
-
- /*
- * System specific initialization code
- */
- system_Init( p_vlc, &i_argc, ppsz_argv );
-
- /* Get the executable name (similar to the basename command) */
- if( i_argc > 0 )
- {
- p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
- while( *p_tmp )
- {
- if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
- else ++p_tmp;
- }
- }
- else
- {
- p_vlc->psz_object_name = "vlc";
- }
-
- /*
- * Support for gettext
- */
- SetLanguage( "" );
-
- /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
- msg_Dbg( p_vlc, "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_vlc );
-
- /* Hack: insert the help module here */
- p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
- if( p_help_module == NULL )
- {
- module_EndBank( p_vlc );
- if( i_object ) vlc_object_release( p_vlc );
- 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.p_module_bank );
- /* End hack */
-
- if( config_LoadCmdLine( p_vlc, &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_vlc );
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_EGENERIC;
- }
-
- /* Check for short help option */
- if( config_GetInt( p_vlc, "help" ) )
- {
- Help( p_vlc, "help" );
- b_exit = VLC_TRUE;
- }
- /* Check for version option */
- else if( config_GetInt( p_vlc, "version" ) )
- {
- Version();
- b_exit = VLC_TRUE;
- }
-
- /* Set the config file stuff */
- p_vlc->psz_homedir = config_GetHomeDir();
- p_vlc->psz_configfile = config_GetPsz( p_vlc, "config" );
-
- /* Check for plugins cache options */
- if( config_GetInt( p_vlc, "reset-plugins-cache" ) )
- {
- libvlc.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_vlc->p_libvlc->i_verbose = config_GetInt( p_vlc, "verbose" );
-
- /* Check for daemon mode */
-#ifndef WIN32
- if( config_GetInt( p_vlc, "daemon" ) )
- {
-#if HAVE_DAEMON
- if( daemon( 0, 0) != 0 )
- {
- msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
- b_exit = VLC_TRUE;
- }
-
- p_vlc->p_libvlc->b_daemon = VLC_TRUE;
-
-#else
- pid_t i_pid;
-
- if( ( i_pid = fork() ) < 0 )
- {
- msg_Err( p_vlc, "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_vlc, "closing parent process" );
- b_exit = VLC_TRUE;
- }
- else
- {
- /* We are the child */
- msg_Dbg( p_vlc, "daemon spawned" );
- close( STDIN_FILENO );
- close( STDOUT_FILENO );
- close( STDERR_FILENO );
-
- p_vlc->p_libvlc->b_daemon = VLC_TRUE;
- }
-#endif
- }
-#endif
-
- if( b_exit )
- {
- config_Free( p_help_module );
- vlc_object_destroy( p_help_module );
- module_EndBank( p_vlc );
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_EEXIT;
- }
-
- /* Check for translation config option */
-#if defined( ENABLE_NLS ) \
- && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
-
- /* This ain't really nice to have to reload the config here but it seems
- * the only way to do it. */
- config_LoadConfigFile( p_vlc, "main" );
- config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
-
- /* Check if the user specified a custom language */
- psz_language = config_GetPsz( p_vlc, "language" );
- if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
- {
- vlc_bool_t b_cache_delete = libvlc.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_vlc, "translation test: code is \"%s\"", _("C") );
-
- textdomain( PACKAGE_NAME );
-
-#if defined( ENABLE_UTF8 )
- bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
-#endif
-
- module_EndBank( p_vlc );
- module_InitBank( p_vlc );
- config_LoadConfigFile( p_vlc, "main" );
- config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
- libvlc.p_module_bank->b_cache_delete = b_cache_delete;
- }
- if( psz_language ) free( psz_language );
-#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_vlc );
- module_LoadPlugins( p_vlc );
- if( p_vlc->b_die )
- {
- b_exit = VLC_TRUE;
- }
-
- msg_Dbg( p_vlc, "module bank initialized, found %i modules",
- libvlc.p_module_bank->i_children );
-
- /* Hack: insert the help module here */
- vlc_object_attach( p_help_module, libvlc.p_module_bank );
- /* End hack */
-
- /* Check for help on modules */
- if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
- {
- Help( p_vlc, p_tmp );
- free( p_tmp );
- b_exit = VLC_TRUE;
- }
- /* Check for long help option */
- else if( config_GetInt( p_vlc, "longhelp" ) )
- {
- Help( p_vlc, "longhelp" );
- b_exit = VLC_TRUE;
- }
- /* Check for module list option */
- else if( config_GetInt( p_vlc, "list" ) )
- {
- ListModules( p_vlc );
- b_exit = VLC_TRUE;
- }
-
- /* Check for config file options */
- if( config_GetInt( p_vlc, "reset-config" ) )
- {
- vlc_object_detach( p_help_module );
- config_ResetAll( p_vlc );
- config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
- config_SaveConfigFile( p_vlc, NULL );
- vlc_object_attach( p_help_module, libvlc.p_module_bank );
- }
- if( config_GetInt( p_vlc, "save-config" ) )
- {
- vlc_object_detach( p_help_module );
- config_LoadConfigFile( p_vlc, NULL );
- config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
- config_SaveConfigFile( p_vlc, NULL );
- vlc_object_attach( p_help_module, libvlc.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_vlc );
- if( i_object ) vlc_object_release( p_vlc );
- return VLC_EEXIT;
- }
-
- /*
- * Init device values
- */
- InitDeviceValues( p_vlc );
-
- /*
- * Override default configuration with config file settings
- */
- config_LoadConfigFile( p_vlc, NULL );
-
- /* Hack: insert the help module here */
- vlc_object_attach( p_help_module, libvlc.p_module_bank );
- /* End hack */
-
- /*
- * Override configuration with command line settings
- */
- if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
- {
-#ifdef WIN32
- ShowConsole();
- /* 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_vlc );
- if( i_object ) vlc_object_release( p_vlc );
- 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_vlc, &i_argc, ppsz_argv );
-
- /*
- * Message queue options
- */
-
- var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
- if( config_GetInt( p_vlc, "quiet" ) )
- {
- val.i_int = -1;
- var_Set( p_vlc, "verbose", val );
- }
- var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
- var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
-
- libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
-
- /*
- * Output messages that may still be in the queue
- */
- msg_Flush( p_vlc );
-
- /* p_vlc initialization. FIXME ? */
-
- if( !config_GetInt( p_vlc, "fpu" ) )
- libvlc.i_cpu &= ~CPU_CAPABILITY_FPU;
-
-#if defined( __i386__ ) || defined( __x86_64__ )
- if( !config_GetInt( p_vlc, "mmx" ) )
- libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
- if( !config_GetInt( p_vlc, "3dn" ) )
- libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
- if( !config_GetInt( p_vlc, "mmxext" ) )
- libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
- if( !config_GetInt( p_vlc, "sse" ) )
- libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
- if( !config_GetInt( p_vlc, "sse2" ) )
- libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
-#endif
-#if defined( __powerpc__ ) || defined( SYS_DARWIN )
- if( !config_GetInt( p_vlc, "altivec" ) )
- libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
-#endif
-
-#define PRINT_CAPABILITY( capability, string ) \
- if( libvlc.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_vlc, "CPU has capabilities %s", p_capabilities );
-
- /*
- * Choose the best memcpy module
- */
- p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
-
- if( p_vlc->pf_memcpy == NULL )
- {
- p_vlc->pf_memcpy = memcpy;
- }
-
- if( p_vlc->pf_memset == NULL )
- {
- p_vlc->pf_memset = memset;
- }
-
- /*
- * Initialize hotkey handling
- */
- var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
- p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
- /* Do a copy (we don't need to modify the strings) */
- memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
-
- /*
- * Initialize playlist and get commandline files
- */
- p_playlist = playlist_Create( p_vlc );
- if( !p_playlist )
- {
- msg_Err( p_vlc, "playlist initialization failed" );
- if( p_vlc->p_memcpy_module != NULL )
- {
- module_Unneed( p_vlc, p_vlc->p_memcpy_module );
- }
- module_EndBank( p_vlc );
- if( i_object ) vlc_object_release( p_vlc );
- 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_vlc, "extraintf" );
- psz_control = config_GetPsz( p_vlc, "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 );
- }
-
- /*
- * Allways load the hotkeys interface if it exists
- */
- VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
-
- /*
- * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
- */
- var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
- var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
- var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
- var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
- var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
- var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
- var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
- var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
- var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
- var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
- var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
- var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
-
- /*
- * Get input filenames given as commandline arguments
- */
- GetFilenames( p_vlc, i_argc, ppsz_argv );
-
- /*
- * Get --open argument
- */
- var_Create( p_vlc, "open", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
- var_Get( p_vlc, "open", &val );
- if ( val.psz_string != NULL && *val.psz_string )
- {
- VLC_AddTarget( p_vlc->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_vlc );
- return VLC_SUCCESS;