X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Flibvlc.c;h=268b1cce3a3524c9a10500d71bd14c5b00445e5f;hb=fb6863d6229118ff58f0a6df0f0770bd18a94928;hp=c28ed675028f2ca439106746921fdc3196ccf768;hpb=a90a19a6b0468ea9fedadc27cfc1118d70295263;p=vlc diff --git a/src/libvlc.c b/src/libvlc.c index c28ed67502..268b1cce3a 100644 --- a/src/libvlc.c +++ b/src/libvlc.c @@ -1,13 +1,14 @@ /***************************************************************************** * libvlc.c: main libvlc source ***************************************************************************** - * Copyright (C) 1998-2004 VideoLAN + * Copyright (C) 1998-2006 the VideoLAN team * $Id$ * * Authors: Vincent Seguin * Samuel Hocevar * Gildas Bazin * Derk-Jan Hartman + * Rémi Denis-Courmont * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,7 +22,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -78,6 +79,7 @@ #include "video_output.h" #include "stream_output.h" +#include "charset.h" #include "libvlc.h" @@ -91,14 +93,21 @@ static vlc_t * p_static_vlc; /***************************************************************************** * Local prototypes *****************************************************************************/ +static int AddIntfInternal( int i_object, char const *psz_module, + vlc_bool_t b_block, vlc_bool_t b_play, + int i_options, char **ppsz_options ); + +void LocaleInit( vlc_object_t * ); +void LocaleDeinit( void ); static void SetLanguage ( char const * ); static int GetFilenames ( vlc_t *, int, char *[] ); +static void Help ( vlc_t *, char const *psz_help_name ); static void Usage ( vlc_t *, char const *psz_module_name ); static void ListModules ( vlc_t * ); static void Version ( void ); #ifdef WIN32 -static void ShowConsole ( void ); +static void ShowConsole ( vlc_bool_t ); static void PauseConsole ( void ); #endif static int ConsoleWidth ( void ); @@ -134,6 +143,27 @@ char const * VLC_Version( void ) return VERSION_MESSAGE; } +/***************************************************************************** + * VLC_CompileBy, VLC_CompileHost, VLC_CompileDomain, + * VLC_Compiler, VLC_Changeset + *****************************************************************************/ +#define DECLARE_VLC_VERSION( func, var ) \ +char const * VLC_##func ( void ) \ +{ \ + return VLC_##var ; \ +} + +DECLARE_VLC_VERSION( CompileBy, COMPILE_BY ); +DECLARE_VLC_VERSION( CompileHost, COMPILE_HOST ); +DECLARE_VLC_VERSION( CompileDomain, COMPILE_DOMAIN ); +DECLARE_VLC_VERSION( Compiler, COMPILER ); + +extern const char psz_vlc_changeset[]; +char const * VLC_Changeset( void ) +{ + return psz_vlc_changeset; +} + /***************************************************************************** * VLC_Error: strerror() equivalent ***************************************************************************** @@ -216,7 +246,7 @@ int VLC_Create( void ) /* Initialize mutexes */ vlc_mutex_init( p_vlc, &p_vlc->config_lock ); -#ifdef SYS_DARWIN +#ifdef __APPLE__ vlc_mutex_init( p_vlc, &p_vlc->quicktime_lock ); vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW ); #endif @@ -246,11 +276,16 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) char * psz_modules; char * psz_parser; char * psz_control; - char * psz_language; vlc_bool_t b_exit = VLC_FALSE; + int i_ret = VLC_EEXIT; vlc_t * p_vlc = vlc_current_object( i_object ); module_t *p_help_module; playlist_t *p_playlist; + vlc_value_t val; +#if defined( ENABLE_NLS ) \ + && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) + char * psz_language; +#endif if( !p_vlc ) { @@ -282,6 +317,12 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) */ SetLanguage( "" ); + /* + * Global iconv, must be done after setlocale() + * so that vlc_current_charset() works. + */ + LocaleInit( (vlc_object_t *)p_vlc ); + /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */ msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") ); @@ -318,22 +359,35 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) /* Check for short help option */ if( config_GetInt( p_vlc, "help" ) ) { - fprintf( stdout, _("Usage: %s [options] [items]...\n"), - p_vlc->psz_object_name ); - Usage( p_vlc, "main" ); - Usage( p_vlc, "help" ); + Help( p_vlc, "help" ); b_exit = VLC_TRUE; + i_ret = VLC_EEXITSUCCESS; } /* Check for version option */ else if( config_GetInt( p_vlc, "version" ) ) { Version(); b_exit = VLC_TRUE; + i_ret = VLC_EEXITSUCCESS; } /* Set the config file stuff */ p_vlc->psz_homedir = config_GetHomeDir(); + p_vlc->psz_userdir = config_GetUserDir(); + if( p_vlc->psz_userdir == NULL ) + p_vlc->psz_userdir = strdup(p_vlc->psz_homedir); p_vlc->psz_configfile = config_GetPsz( p_vlc, "config" ); + if( p_vlc->psz_configfile != NULL && p_vlc->psz_configfile[0] == '~' + && p_vlc->psz_configfile[1] == '/' ) + { + char *psz = malloc( strlen(p_vlc->psz_userdir) + + strlen(p_vlc->psz_configfile) ); + /* This is incomplete : we should also support the ~cmassiot/ syntax. */ + sprintf( psz, "%s/%s", p_vlc->psz_userdir, + p_vlc->psz_configfile + 2 ); + free( p_vlc->psz_configfile ); + p_vlc->psz_configfile = psz; + } /* Check for plugins cache options */ if( config_GetInt( p_vlc, "reset-plugins-cache" ) ) @@ -353,7 +407,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) if( config_GetInt( p_vlc, "daemon" ) ) { #if HAVE_DAEMON - if( daemon( 0, 0) != 0 ) + if( daemon( 1, 0) != 0 ) { msg_Err( p_vlc, "Unable to fork vlc to daemon mode" ); b_exit = VLC_TRUE; @@ -374,6 +428,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) /* This is the parent, exit right now */ msg_Dbg( p_vlc, "closing parent process" ); b_exit = VLC_TRUE; + i_ret = VLC_EEXITSUCCESS; } else { @@ -395,7 +450,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) vlc_object_destroy( p_help_module ); module_EndBank( p_vlc ); if( i_object ) vlc_object_release( p_vlc ); - return VLC_EEXIT; + return i_ret; } /* Check for translation config option */ @@ -416,15 +471,16 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) /* Reset the default domain */ SetLanguage( psz_language ); + /* Should not be needed (otherwise, fixes should rather be + * attempted on vlc_current_charset(). + * Also, if the locale charset is overriden, anything that has been + * translated until now would have to be retranslated. */ + /*LocaleDeinit(); + LocaleInit( (vlc_object_t *)p_vlc );*/ + /* 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" ); @@ -457,21 +513,24 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) /* Check for help on modules */ if( (p_tmp = config_GetPsz( p_vlc, "module" )) ) { - Usage( p_vlc, p_tmp ); + Help( p_vlc, p_tmp ); free( p_tmp ); b_exit = VLC_TRUE; + i_ret = VLC_EEXITSUCCESS; } /* Check for long help option */ else if( config_GetInt( p_vlc, "longhelp" ) ) { - Usage( p_vlc, NULL ); + Help( p_vlc, "longhelp" ); b_exit = VLC_TRUE; + i_ret = VLC_EEXITSUCCESS; } /* Check for module list option */ else if( config_GetInt( p_vlc, "list" ) ) { ListModules( p_vlc ); b_exit = VLC_TRUE; + i_ret = VLC_EEXITSUCCESS; } /* Check for config file options */ @@ -502,7 +561,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) vlc_object_destroy( p_help_module ); module_EndBank( p_vlc ); if( i_object ) vlc_object_release( p_vlc ); - return VLC_EEXIT; + return i_ret; } /* @@ -525,7 +584,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) ) { #ifdef WIN32 - ShowConsole(); + 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" ); @@ -557,7 +616,6 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); if( config_GetInt( p_vlc, "quiet" ) ) { - vlc_value_t val; val.i_int = -1; var_Set( p_vlc, "verbose", val ); } @@ -573,7 +631,10 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) /* p_vlc initialization. FIXME ? */ -#if defined( __i386__ ) + 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" ) ) @@ -585,7 +646,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) if( !config_GetInt( p_vlc, "sse2" ) ) libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2; #endif -#if defined( __powerpc__ ) || defined( SYS_DARWIN ) +#if defined( __powerpc__ ) || defined( __ppc__ ) || defined( __ppc64__ ) if( !config_GetInt( p_vlc, "altivec" ) ) libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC; #endif @@ -626,6 +687,9 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) p_vlc->pf_memset = memset; } + libvlc.b_stats = config_GetInt( p_vlc, "stats" ); + libvlc.p_stats = NULL; + /* * Initialize hotkey handling */ @@ -650,9 +714,13 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) return VLC_EGENERIC; } - /* Add service discovery modules */ - playlist_AddSDModules( p_playlist, - config_GetPsz( p_playlist, "services-discovery" ) ); + 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 @@ -664,7 +732,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) { psz_modules = (char *)realloc( psz_modules, strlen( psz_modules ) + strlen( psz_control ) + 1 ); - sprintf( psz_modules, "%s,%s", psz_modules, psz_control ); + sprintf( psz_modules, "%s:%s", psz_modules, psz_control ); } else if( psz_control && *psz_control ) { @@ -677,7 +745,7 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) { char *psz_module, *psz_temp; psz_module = psz_parser; - psz_parser = strchr( psz_module, ',' ); + psz_parser = strchr( psz_module, ':' ); if ( psz_parser ) { *psz_parser = '\0'; @@ -697,10 +765,43 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) } /* - * Allways load the hotkeys interface if it exists + * 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_vlc, "disable-screensaver" ) == 1 ) + { + VLC_AddIntf( 0, "screensaver", VLC_FALSE, VLC_FALSE ); + } +#endif + + if( config_GetInt( p_vlc, "file-logging" ) == 1 ) + { + VLC_AddIntf( 0, "logger", VLC_FALSE, VLC_FALSE ); + } +#ifdef HAVE_SYSLOG_H + if( config_GetInt( p_vlc, "syslog" ) == 1 ) + { + char *psz_logmode = "logmode=syslog"; + AddIntfInternal( 0, "logger", VLC_FALSE, VLC_FALSE, 1, &psz_logmode ); + } +#endif + + if( config_GetInt( p_vlc, "show-intf" ) == 1 ) + { + VLC_AddIntf( 0, "showintf", VLC_FALSE, VLC_FALSE ); + } + + if( config_GetInt( p_vlc, "network-synchronisation") == 1 ) + { + VLC_AddIntf( 0, "netsync", VLC_FALSE, VLC_FALSE ); + } + /* * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin */ @@ -717,11 +818,26 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER ); var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER ); + /* Create volume callback system. */ + var_Create( p_vlc, "volume-change", VLC_VAR_BOOL ); + /* * 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; } @@ -738,55 +854,10 @@ int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] ) int VLC_AddIntf( int i_object, char const *psz_module, vlc_bool_t b_block, vlc_bool_t b_play ) { - int i_err; - intf_thread_t *p_intf; - vlc_t *p_vlc = vlc_current_object( i_object ); - - if( !p_vlc ) - { - return VLC_ENOOBJ; - } - -#ifndef WIN32 - if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module ) - { - /* Daemon mode hack. - * We prefer the dummy interface if none is specified. */ - char *psz_interface = config_GetPsz( p_vlc, "intf" ); - if( !psz_interface || !*psz_interface ) psz_module = "dummy"; - if( psz_interface ) free( psz_interface ); - } -#endif - - /* Try to create the interface */ - p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" ); - - if( p_intf == NULL ) - { - msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module ); - if( i_object ) vlc_object_release( p_vlc ); - return VLC_EGENERIC; - } - - /* Interface doesn't handle play on start so do it ourselves */ - if( !p_intf->b_play && b_play ) VLC_Play( i_object ); - - /* Try to run the interface */ - p_intf->b_play = b_play; - p_intf->b_block = b_block; - i_err = intf_RunThread( p_intf ); - if( i_err ) - { - vlc_object_detach( p_intf ); - intf_Destroy( p_intf ); - if( i_object ) vlc_object_release( p_vlc ); - return i_err; - } - - if( i_object ) vlc_object_release( p_vlc ); - return VLC_SUCCESS; + return AddIntfInternal( i_object, psz_module, b_block, b_play, 0, NULL ); } + /***************************************************************************** * VLC_Die: ask vlc to die. ***************************************************************************** @@ -818,6 +889,7 @@ int VLC_CleanUp( int i_object ) vout_thread_t * p_vout; aout_instance_t * p_aout; announce_handler_t * p_announce; + stats_handler_t * p_stats; vlc_t *p_vlc = vlc_current_object( i_object ); /* Check that the handle is valid */ @@ -839,9 +911,9 @@ int VLC_CleanUp( int i_object ) } /* - * Free playlists + * Free playlist */ - msg_Dbg( p_vlc, "removing all playlists" ); + msg_Dbg( p_vlc, "removing playlist handler" ); while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD )) ) { @@ -872,17 +944,26 @@ int VLC_CleanUp( int i_object ) aout_Delete( p_aout ); } + while( ( p_stats = vlc_object_find( p_vlc, VLC_OBJECT_STATS, FIND_CHILD) )) + { + stats_TimersDumpAll( p_vlc ); + stats_HandlerDestroy( p_stats ); + vlc_object_detach( (vlc_object_t*) p_stats ); + vlc_object_release( (vlc_object_t *)p_stats ); + // TODO: Delete it + } + /* * Free announce handler(s?) */ - msg_Dbg( p_vlc, "removing announce handler" ); while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE, FIND_CHILD ) ) ) - { + { + msg_Dbg( p_vlc, "removing announce handler" ); vlc_object_detach( p_announce ); vlc_object_release( p_announce ); announce_HandlerDestroy( p_announce ); - } + } if( i_object ) vlc_object_release( p_vlc ); return VLC_SUCCESS; @@ -923,6 +1004,12 @@ int VLC_Destroy( int i_object ) p_vlc->psz_homedir = NULL; } + if( p_vlc->psz_userdir ) + { + free( p_vlc->psz_userdir ); + p_vlc->psz_userdir = NULL; + } + if( p_vlc->psz_configfile ) { free( p_vlc->psz_configfile ); @@ -940,6 +1027,16 @@ int VLC_Destroy( int i_object ) */ system_End( p_vlc ); + /* + * Free message queue. + * Nobody shall use msg_* afterward. + */ + msg_Flush( p_vlc ); + msg_Destroy( p_libvlc ); + + /* Destroy global iconv */ + LocaleDeinit(); + /* Destroy mutexes */ vlc_mutex_destroy( &p_vlc->config_lock ); @@ -1025,6 +1122,62 @@ int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value ) return i_ret; } +/***************************************************************************** + * VLC_VariableType: get a vlc variable type + *****************************************************************************/ +int VLC_VariableType( int i_object, char const *psz_var, int *pi_type ) +{ + int i_type; + vlc_t *p_vlc = vlc_current_object( i_object ); + + if( !p_vlc ) + { + return VLC_ENOOBJ; + } + + /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then + * we handle it as a configuration variable. Don't tell Gildas :) -- sam */ + if( !strncmp( psz_var, "conf::", 6 ) ) + { + module_config_t *p_item; + char const *psz_newvar = psz_var + 6; + + p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar ); + + if( p_item ) + { + switch( p_item->i_type ) + { + case CONFIG_ITEM_BOOL: + i_type = VLC_VAR_BOOL; + break; + case CONFIG_ITEM_INTEGER: + i_type = VLC_VAR_INTEGER; + break; + case CONFIG_ITEM_FLOAT: + i_type = VLC_VAR_FLOAT; + break; + default: + i_type = VLC_VAR_STRING; + break; + } + } + else + i_type = 0; + } + else + i_type = VLC_VAR_TYPE & var_Type( p_vlc , psz_var ); + + if( i_object ) vlc_object_release( p_vlc ); + + if( i_type > 0 ) + { + *pi_type = i_type; + return VLC_SUCCESS; + } + return VLC_ENOVAR; +} + /***************************************************************************** * VLC_AddTarget: adds a target for playing. ***************************************************************************** @@ -1070,7 +1223,7 @@ int VLC_AddTarget( int i_object, char const *psz_target, } /***************************************************************************** - * VLC_Play: play + * VLC_Play: play the playlist *****************************************************************************/ int VLC_Play( int i_object ) { @@ -1180,7 +1333,17 @@ vlc_bool_t VLC_IsPlaying( int i_object ) return VLC_ENOOBJ; } - b_playing = playlist_IsPlaying( p_playlist ); + if( p_playlist->p_input ) + { + vlc_value_t val; + var_Get( p_playlist->p_input, "state", &val ); + b_playing = ( val.i_int == PLAYING_S ); + } + else + { + msg_Dbg(p_vlc, "polling playlist_IsPlaying"); + b_playing = playlist_IsPlaying( p_playlist ); + } vlc_object_release( p_playlist ); if( i_object ) vlc_object_release( p_vlc ); @@ -1334,12 +1497,14 @@ int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative ) if( b_relative ) { - val.i_time = i_seconds * 1000000; + val.i_time = i_seconds; + val.i_time = val.i_time * 1000000L; var_Set( p_input, "time-offset", val ); } else { - val.i_time = i_seconds * 1000000; + val.i_time = i_seconds; + val.i_time = val.i_time * 1000000L; var_Set( p_input, "time", val ); } vlc_object_release( p_input ); @@ -1381,7 +1546,7 @@ int VLC_LengthGet( int i_object ) vlc_object_release( p_input ); if( i_object ) vlc_object_release( p_vlc ); - return val.i_time / 1000000; + return val.i_time / 1000000L; } /** @@ -1734,6 +1899,67 @@ int VLC_FullScreen( int i_object ) /* following functions are local */ + +static int AddIntfInternal( int i_object, char const *psz_module, + vlc_bool_t b_block, vlc_bool_t b_play, + int i_options, char **ppsz_options ) +{ + int i_err,i; + intf_thread_t *p_intf; + vlc_t *p_vlc = vlc_current_object( i_object ); + + if( !p_vlc ) + { + return VLC_ENOOBJ; + } + +#ifndef WIN32 + if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module ) + { + /* Daemon mode hack. + * We prefer the dummy interface if none is specified. */ + char *psz_interface = config_GetPsz( p_vlc, "intf" ); + if( !psz_interface || !*psz_interface ) psz_module = "dummy"; + if( psz_interface ) free( psz_interface ); + } +#endif + + /* Try to create the interface */ + p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf", + i_options, ppsz_options ); + + if( p_intf == NULL ) + { + msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module ); + if( i_object ) vlc_object_release( p_vlc ); + return VLC_EGENERIC; + } + + /* Interface doesn't handle play on start so do it ourselves */ + if( !p_intf->b_play && b_play ) VLC_Play( i_object ); + + /* Try to run the interface */ + p_intf->b_play = b_play; + p_intf->b_block = b_block; + i_err = intf_RunThread( p_intf ); + if( i_err ) + { + vlc_object_detach( p_intf ); + intf_Destroy( p_intf ); + if( i_object ) vlc_object_release( p_vlc ); + return i_err; + } + + for( i = 0 ; i< i_options ; i++ ) + { + + } + + if( i_object ) vlc_object_release( p_vlc ); + return VLC_SUCCESS; +}; + + /***************************************************************************** * SetLanguage: set the interface language. ***************************************************************************** @@ -1747,7 +1973,7 @@ static void SetLanguage ( char const *psz_lang ) && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) ) char * psz_path; -#if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS ) +#if defined( __APPLE__ ) || defined ( WIN32 ) || defined( SYS_BEOS ) char psz_tmp[1024]; #endif @@ -1760,7 +1986,7 @@ static void SetLanguage ( char const *psz_lang ) } else if( psz_lang ) { -#ifdef SYS_DARWIN +#ifdef __APPLE__ /* I need that under Darwin, please check it doesn't disturb * other platforms. --Meuuh */ setenv( "LANG", psz_lang, 1 ); @@ -1777,10 +2003,14 @@ static void SetLanguage ( char const *psz_lang ) #endif setlocale( LC_ALL, psz_lang ); + /* many code paths assume that float numbers are formatted according + * to the US standard (ie. with dot as decimal point), so we keep + * C for LC_NUMERIC. */ + setlocale( LC_NUMERIC, "C" ); } /* Specify where to find the locales for current domain */ -#if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS ) +#if !defined( __APPLE__ ) && !defined( WIN32 ) && !defined( SYS_BEOS ) psz_path = LOCALEDIR; #else snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath, @@ -1789,18 +2019,13 @@ static void SetLanguage ( char const *psz_lang ) #endif if( !bindtextdomain( PACKAGE_NAME, psz_path ) ) { - fprintf( stderr, "warning: no domain %s in directory %s\n", + fprintf( stderr, "warning: couldn't bind domain %s in directory %s\n", PACKAGE_NAME, psz_path ); } /* Set the default domain */ - textdomain( PACKAGE_NAME ); - -#if defined( ENABLE_UTF8 ) bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" ); #endif - -#endif } /***************************************************************************** @@ -1817,6 +2042,7 @@ static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] ) * and their input options */ for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- ) { + const char *psz_target; i_options = 0; /* Count the input options */ @@ -1828,17 +2054,52 @@ static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] ) /* TODO: write an internal function of this one, to avoid * unnecessary lookups. */ - VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ], + /* FIXME: should we convert options to UTF-8 as well ?? */ + psz_target = FromLocale( ppsz_argv[ i_opt ] ); + VLC_AddTarget( p_vlc->i_object_id, psz_target, (char const **)( i_options ? &ppsz_argv[i_opt + 1] : NULL ), i_options, PLAYLIST_INSERT, 0 ); + LocaleFree( psz_target ); } return VLC_SUCCESS; } /***************************************************************************** - * Usage: print program usage + * Help: print program help + ***************************************************************************** + * Print a short inline help. Message interface is initialized at this stage. + *****************************************************************************/ +static void Help( vlc_t *p_this, char const *psz_help_name ) +{ +#ifdef WIN32 + ShowConsole( VLC_TRUE ); +#endif + + if( psz_help_name && !strcmp( psz_help_name, "help" ) ) + { + utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name ); + Usage( p_this, "help" ); + Usage( p_this, "main" ); + } + else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) ) + { + utf8_fprintf( stdout, VLC_USAGE, p_this->psz_object_name ); + Usage( p_this, NULL ); + } + else if( psz_help_name ) + { + Usage( p_this, psz_help_name ); + } + +#ifdef WIN32 /* Pause the console because it's destroyed when we exit */ + PauseConsole(); +#endif +} + +/***************************************************************************** + * Usage: print module usage ***************************************************************************** * Print a short inline help. Message interface is initialized at this stage. *****************************************************************************/ @@ -1861,23 +2122,23 @@ static void Usage( vlc_t *p_this, char const *psz_module_name ) vlc_list_t *p_list; module_t *p_parser; module_config_t *p_item; - char psz_spaces[PADDING_SPACES+LINE_START+1]; + char psz_spaces_text[PADDING_SPACES+LINE_START+1]; + char psz_spaces_longtext[LINE_START+3]; char psz_format[sizeof(FORMAT_STRING)]; - char psz_buffer[1000]; + char psz_buffer[10000]; char psz_short[4]; int i_index; int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1); vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" ); + vlc_bool_t b_description; - memset( psz_spaces, ' ', PADDING_SPACES+LINE_START ); - psz_spaces[PADDING_SPACES+LINE_START] = '\0'; + memset( psz_spaces_text, ' ', PADDING_SPACES+LINE_START ); + psz_spaces_text[PADDING_SPACES+LINE_START] = '\0'; + memset( psz_spaces_longtext, ' ', LINE_START+2 ); + psz_spaces_longtext[LINE_START+2] = '\0'; strcpy( psz_format, FORMAT_STRING ); -#ifdef WIN32 - ShowConsole(); -#endif - /* List all modules */ p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); @@ -1915,7 +2176,7 @@ static void Usage( vlc_t *p_this, char const *psz_module_name ) /* Print name of module */ if( strcmp( "main", p_parser->psz_object_name ) ) - fprintf( stdout, "\n %s\n", p_parser->psz_longname ); + utf8_fprintf( stdout, "\n %s\n", p_parser->psz_longname ); b_help_module = !strcmp( "help", p_parser->psz_object_name ); @@ -1924,11 +2185,16 @@ static void Usage( vlc_t *p_this, char const *psz_module_name ) p_item->i_type != CONFIG_HINT_END; p_item++ ) { - char *psz_text; + char *psz_text, *psz_spaces = psz_spaces_text; char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL; char *psz_suf = "", *psz_prefix = NULL; - int i; + signed int i; + /* Skip deprecated options */ + if( p_item->psz_current ) + { + continue; + } /* Skip advanced options if requested */ if( p_item->b_advanced && !b_advanced ) { @@ -1940,19 +2206,19 @@ static void Usage( vlc_t *p_this, char const *psz_module_name ) case CONFIG_HINT_CATEGORY: case CONFIG_HINT_USAGE: if( !strcmp( "main", p_parser->psz_object_name ) ) - fprintf( stdout, "\n %s\n", p_item->psz_text ); + utf8_fprintf( stdout, "\n %s\n", p_item->psz_text ); break; case CONFIG_ITEM_STRING: case CONFIG_ITEM_FILE: case CONFIG_ITEM_DIRECTORY: case CONFIG_ITEM_MODULE: /* We could also have "=<" here */ - if( !p_item->ppsz_list ) - { - psz_bra = " <"; psz_type = _("string"); psz_ket = ">"; - break; - } - else + case CONFIG_ITEM_MODULE_CAT: + case CONFIG_ITEM_MODULE_LIST: + case CONFIG_ITEM_MODULE_LIST_CAT: + psz_bra = " <"; psz_type = _("string"); psz_ket = ">"; + + if( p_item->ppsz_list ) { psz_bra = " {"; psz_type = psz_buffer; @@ -1963,11 +2229,26 @@ static void Usage( vlc_t *p_this, char const *psz_module_name ) strcat( psz_type, p_item->ppsz_list[i] ); } psz_ket = "}"; - break; } + break; case CONFIG_ITEM_INTEGER: case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */ psz_bra = " <"; psz_type = _("integer"); psz_ket = ">"; + + if( p_item->i_list ) + { + psz_bra = " {"; + psz_type = psz_buffer; + psz_type[0] = '\0'; + for( i = 0; p_item->ppsz_list_text[i]; i++ ) + { + if( i ) strcat( psz_type, ", " ); + sprintf( psz_type + strlen(psz_type), "%i (%s)", + p_item->pi_list[i], + p_item->ppsz_list_text[i] ); + } + psz_ket = "}"; + } break; case CONFIG_ITEM_FLOAT: psz_bra = " <"; psz_type = _("float"); psz_ket = ">"; @@ -2003,12 +2284,7 @@ static void Usage( vlc_t *p_this, char const *psz_module_name ) if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module ) { - /* If option is of type --foo-bar, we print its counterpart - * as --no-foo-bar, but if it is of type --foobar (without - * dashes in the name) we print it as --nofoobar. Both - * values are of course valid, only the display changes. */ - psz_prefix = strchr( p_item->psz_name, '-' ) ? ", --no-" - : ", --no"; + psz_prefix = ", --no-"; i -= strlen( p_item->psz_name ) + strlen( psz_prefix ); } @@ -2024,13 +2300,13 @@ static void Usage( vlc_t *p_this, char const *psz_module_name ) if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module ) { - fprintf( stdout, psz_format, psz_short, p_item->psz_name, + utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name, psz_prefix, p_item->psz_name, psz_bra, psz_type, psz_ket, psz_spaces ); } else { - fprintf( stdout, psz_format, psz_short, p_item->psz_name, + utf8_fprintf( stdout, psz_format, psz_short, p_item->psz_name, "", "", psz_bra, psz_type, psz_ket, psz_spaces ); } @@ -2038,16 +2314,19 @@ static void Usage( vlc_t *p_this, char const *psz_module_name ) /* We wrap the rest of the output */ sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf ); + b_description = config_GetInt( p_this, "help-verbose" ); + + description: psz_text = psz_buffer; while( *psz_text ) { char *psz_parser, *psz_word; - int i_end = strlen( psz_text ); + size_t i_end = strlen( psz_text ); /* If the remaining text fits in a line, print it. */ - if( i_end <= i_width ) + if( i_end <= (size_t)i_width ) { - fprintf( stdout, "%s\n", psz_text ); + utf8_fprintf( stdout, "%s\n", psz_text ); break; } @@ -2075,26 +2354,31 @@ static void Usage( vlc_t *p_this, char const *psz_module_name ) { char c = psz_text[i_width]; psz_text[i_width] = '\0'; - fprintf( stdout, "%s\n%s", psz_text, psz_spaces ); + utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces ); psz_text += i_width; psz_text[0] = c; } else { psz_word[-1] = '\0'; - fprintf( stdout, "%s\n%s", psz_text, psz_spaces ); + utf8_fprintf( stdout, "%s\n%s", psz_text, psz_spaces ); psz_text = psz_word; } } + + if( b_description && p_item->psz_longtext ) + { + sprintf( psz_buffer, "%s%s", p_item->psz_longtext, psz_suf ); + b_description = VLC_FALSE; + psz_spaces = psz_spaces_longtext; + utf8_fprintf( stdout, "%s", psz_spaces ); + goto description; + } } } /* Release the module list */ vlc_list_release( p_list ); - -#ifdef WIN32 /* Pause the console because it's destroyed when we exit */ - PauseConsole(); -#endif } /***************************************************************************** @@ -2113,15 +2397,9 @@ static void ListModules( vlc_t *p_this ) memset( psz_spaces, ' ', 22 ); #ifdef WIN32 - ShowConsole(); + ShowConsole( VLC_TRUE ); #endif - /* Usage */ - fprintf( stdout, _("Usage: %s [options] [items]...\n\n"), - p_this->p_vlc->psz_object_name ); - - fprintf( stdout, _("[module] [description]\n") ); - /* List all modules */ p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE ); @@ -2138,7 +2416,7 @@ static void ListModules( vlc_t *p_this ) if( i < 0 ) i = 0; psz_spaces[i] = 0; - fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name, + utf8_fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name, psz_spaces, p_parser->psz_longname ); psz_spaces[i] = ' '; @@ -2159,15 +2437,17 @@ static void ListModules( vlc_t *p_this ) static void Version( void ) { #ifdef WIN32 - ShowConsole(); + ShowConsole( VLC_TRUE ); #endif - fprintf( stdout, VERSION_MESSAGE "\n" ); - fprintf( stdout, - _("This program comes with NO WARRANTY, to the extent permitted by " - "law.\nYou may redistribute it under the terms of the GNU General " - "Public License;\nsee the file named COPYING for details.\n" - "Written by the VideoLAN team; see the AUTHORS file.\n") ); + utf8_fprintf( stdout, _("VLC version %s\n"), VLC_Version() ); + utf8_fprintf( stdout, _("Compiled by %s@%s.%s\n"), + VLC_CompileBy(), VLC_CompileHost(), VLC_CompileDomain() ); + utf8_fprintf( stdout, _("Compiler: %s\n"), VLC_Compiler() ); + if( strcmp( VLC_Changeset(), "exported" ) ) + utf8_fprintf( stdout, _("Based upon svn changeset [%s]\n"), + VLC_Changeset() ); + utf8_fprintf( stdout, LICENSE_MSG ); #ifdef WIN32 /* Pause the console because it's destroyed when we exit */ PauseConsole(); @@ -2180,17 +2460,27 @@ static void Version( void ) * This function is useful only on Win32. *****************************************************************************/ #ifdef WIN32 /* */ -static void ShowConsole( void ) +static void ShowConsole( vlc_bool_t b_dofile ) { # ifndef UNDER_CE + FILE *f_help; if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */ AllocConsole(); - freopen( "CONOUT$", "w", stdout ); + freopen( "CONOUT$", "w", stderr ); freopen( "CONIN$", "r", stdin ); + if( b_dofile && (f_help = fopen( "vlc-help.txt", "wt" )) ) + { + fclose( f_help ); + freopen( "vlc-help.txt", "wt", stdout ); + utf8_fprintf( stderr, _("\nDumped content to vlc-help.txt file.\n") ); + } + + else freopen( "CONOUT$", "w", stdout ); + # endif } #endif @@ -2206,8 +2496,10 @@ static void PauseConsole( void ) # ifndef UNDER_CE if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */ - fprintf( stdout, _("\nPress the RETURN key to continue...\n") ); + + utf8_fprintf( stderr, _("\nPress the RETURN key to continue...\n") ); getchar(); + fclose( stdout ); # endif } @@ -2278,24 +2570,54 @@ static void InitDeviceValues( vlc_t *p_vlc ) char **devices; char *block_dev; dbus_bool_t b_dvd; + DBusConnection *p_connection; + DBusError error; +#ifdef HAVE_HAL_1 + ctx = libhal_ctx_new(); + if( !ctx ) return; + dbus_error_init( &error ); + p_connection = dbus_bus_get ( DBUS_BUS_SYSTEM, &error ); + if( dbus_error_is_set( &error ) ) + { + dbus_error_free( &error ); + return; + } + libhal_ctx_set_dbus_connection( ctx, p_connection ); + if( libhal_ctx_init( ctx, &error ) ) +#else if( ( ctx = hal_initialize( NULL, FALSE ) ) ) +#endif { +#ifdef HAVE_HAL_1 + if( ( devices = libhal_get_all_devices( ctx, &i_devices, NULL ) ) ) +#else if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) ) +#endif { for( i = 0; i < i_devices; i++ ) { +#ifdef HAVE_HAL_1 + if( !libhal_device_property_exists( ctx, devices[i], + "storage.cdrom.dvd", NULL ) ) +#else if( !hal_device_property_exists( ctx, devices[ i ], "storage.cdrom.dvd" ) ) +#endif { continue; } - +#ifdef HAVE_HAL_1 + b_dvd = libhal_device_get_property_bool( ctx, devices[ i ], + "storage.cdrom.dvd", NULL ); + block_dev = libhal_device_get_property_string( ctx, + devices[ i ], "block.device" , NULL ); +#else b_dvd = hal_device_get_property_bool( ctx, devices[ i ], "storage.cdrom.dvd" ); block_dev = hal_device_get_property_string( ctx, devices[ i ], "block.device" ); - +#endif if( b_dvd ) { config_PutPsz( p_vlc, "dvd", block_dev ); @@ -2303,12 +2625,28 @@ static void InitDeviceValues( vlc_t *p_vlc ) config_PutPsz( p_vlc, "vcd", block_dev ); config_PutPsz( p_vlc, "cd-audio", block_dev ); - +#ifdef HAVE_HAL_1 + libhal_free_string( block_dev ); +#else hal_free_string( block_dev ); +#endif } +#ifdef HAVE_HAL_1 + libhal_free_string_array( devices ); +#else + hal_free_string_array( devices ); +#endif } +#ifdef HAVE_HAL_1 + libhal_ctx_shutdown( ctx, NULL ); +#else hal_shutdown( ctx ); +#endif + } + else + { + msg_Warn( p_vlc, "Unable to get HAL device properties" ); } #endif }