*
* Authors: Vincent Seguin <seguin@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
- * Gildas Bazin <gbazin@netcourrier.com>
+ * Gildas Bazin <gbazin@videolan.org>
* Derk-Jan Hartman <hartman at videolan dot org>
*
* This program is free software; you can redistribute it and/or modify
#include <vlc/vlc.h>
#include <vlc/input.h>
-#ifdef HAVE_ERRNO_H
-# include <errno.h> /* ENOMEM */
-#endif
+#include <errno.h> /* ENOMEM */
#include <stdio.h> /* sprintf() */
#include <string.h> /* strerror() */
#include <stdlib.h> /* free() */
# include <locale.h>
#endif
+#ifdef HAVE_HAL
+# include <hal/libhal.h>
+#endif
+
#include "vlc_cpu.h" /* CPU detection */
#include "os_specific.h"
*****************************************************************************/
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 PauseConsole ( void );
#endif
static int ConsoleWidth ( void );
static int VerboseCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
+static void InitDeviceValues( vlc_t * );
+
/*****************************************************************************
* vlc_current_object: return the current object.
*****************************************************************************
return VLC_EGENERIC;
}
p_vlc->thread_id = 0;
- vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
p_vlc->psz_object_name = "root";
vlc_mutex_init( p_vlc, &p_vlc->config_lock );
#ifdef SYS_DARWIN
vlc_mutex_init( p_vlc, &p_vlc->quicktime_lock );
+ vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
#endif
/* Store our newly allocated structure in the global list */
char * p_tmp;
char * psz_modules;
char * psz_parser;
+ char * psz_control;
char * psz_language;
vlc_bool_t b_exit = VLC_FALSE;
vlc_t * p_vlc = vlc_current_object( i_object );
/* 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;
}
/* Check for version option */
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 );
/* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
- textdomain( PACKAGE );
+ textdomain( PACKAGE_NAME );
#if defined( ENABLE_UTF8 )
- bind_textdomain_codeset( PACKAGE, "UTF-8" );
+ bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
#endif
module_EndBank( p_vlc );
/* 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;
}
/* Check for long help option */
else if( config_GetInt( p_vlc, "longhelp" ) )
{
- Usage( p_vlc, NULL );
+ Help( p_vlc, "longhelp" );
b_exit = VLC_TRUE;
}
/* Check for module list option */
return VLC_EEXIT;
}
+ /*
+ * Init device values
+ */
+ InitDeviceValues( p_vlc );
+
/*
* Override default configuration with config file settings
*/
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.\nPress the RETURN key to continue..." );
- getchar();
+ "that they are valid.\n" );
+ PauseConsole();
#endif
vlc_object_detach( p_help_module );
config_Free( p_help_module );
/* 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" ) )
{
p_vlc->pf_memset = memset;
}
-
- /* Check for daemon mode */
- if( config_GetInt( p_vlc, "daemon" ) )
- {
- pid_t i_pid = 0;
- if( ( i_pid = fork() ) < 0 )
- {
- msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
- exit(1);
- }
- else if( i_pid )
- {
- /* This is the parent, exit right now */
- msg_Dbg( p_vlc, "closing parent process" );
- exit(0);
- }
- else
- {
- /* we are the child */
- msg_Dbg( p_vlc, "we are the child !!!" );
- close( 0 );
- close( 1 );
- close( 2 );
-
- p_vlc->p_libvlc->b_daemon = VLC_TRUE;
- //VLC_AddIntf( 0, "logger,none", VLC_FALSE, VLC_FALSE );
- }
- }
/*
* Initialize hotkey handling
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 )
{
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" );
/*****************************************************************************
* VLC_VariableGet: get a vlc variable
*****************************************************************************/
-int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
+int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
{
vlc_t *p_vlc = vlc_current_object( i_object );
int i_ret;
return VLC_ENOOBJ;
}
- i_ret = var_Get( p_vlc, psz_var, p_value );
+ i_ret = var_Get( p_vlc , psz_var, p_value );
if( i_object ) vlc_object_release( p_vlc );
return i_ret;
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 );
vlc_object_release( p_input );
if( i_object ) vlc_object_release( p_vlc );
- return val.i_time / 1000000;
+ return val.i_time / 1000000L;
}
/**
"locale" );
psz_path = psz_tmp;
#endif
- if( !bindtextdomain( PACKAGE, psz_path ) )
+ if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
{
fprintf( stderr, "warning: no domain %s in directory %s\n",
- PACKAGE, psz_path );
+ PACKAGE_NAME, psz_path );
}
/* Set the default domain */
- textdomain( PACKAGE );
+ textdomain( PACKAGE_NAME );
#if defined( ENABLE_UTF8 )
- bind_textdomain_codeset( PACKAGE, "UTF-8" );
+ bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
#endif
#endif
}
/*****************************************************************************
- * 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();
+#endif
+
+ if( psz_help_name && !strcmp( psz_help_name, "help" ) )
+ {
+ 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" ) )
+ {
+ 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.
*****************************************************************************/
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 );
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;
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;
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 = ">";
/* 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 )
{
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;
+ 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 */
- fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
- getchar();
-#endif
}
/*****************************************************************************
ShowConsole();
#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 );
vlc_list_release( p_list );
#ifdef WIN32 /* Pause the console because it's destroyed when we exit */
- fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
- getchar();
+ PauseConsole();
#endif
}
"Written by the VideoLAN team; see the AUTHORS file.\n") );
#ifdef WIN32 /* Pause the console because it's destroyed when we exit */
- fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
- getchar();
+ PauseConsole();
#endif
}
static void ShowConsole( void )
{
# ifndef UNDER_CE
+
+ if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
+
AllocConsole();
freopen( "CONOUT$", "w", stdout );
freopen( "CONOUT$", "w", stderr );
freopen( "CONIN$", "r", stdin );
+
+# endif
+}
+#endif
+
+/*****************************************************************************
+ * PauseConsole: On Win32, wait for a key press before closing the console
+ *****************************************************************************
+ * This function is useful only on Win32.
+ *****************************************************************************/
+#ifdef WIN32 /* */
+static void PauseConsole( void )
+{
+# ifndef UNDER_CE
+
+ if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
+ fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
+ getchar();
+
# endif
- return;
}
#endif
}
return VLC_SUCCESS;
}
+
+/*****************************************************************************
+ * InitDeviceValues: initialize device values
+ *****************************************************************************
+ * This function inits the dvd, vcd and cd-audio values
+ *****************************************************************************/
+static void InitDeviceValues( vlc_t *p_vlc )
+{
+#ifdef HAVE_HAL
+ LibHalContext * ctx;
+ int i, i_devices;
+ char **devices;
+ char *block_dev;
+ dbus_bool_t b_dvd;
+
+ if( ( ctx = hal_initialize( NULL, FALSE ) ) )
+ {
+ if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) )
+ {
+ for( i = 0; i < i_devices; i++ )
+ {
+ if( !hal_device_property_exists( ctx, devices[ i ],
+ "storage.cdrom.dvd" ) )
+ {
+ continue;
+ }
+
+ 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" );
+
+ if( b_dvd )
+ {
+ config_PutPsz( p_vlc, "dvd", block_dev );
+ }
+
+ config_PutPsz( p_vlc, "vcd", block_dev );
+ config_PutPsz( p_vlc, "cd-audio", block_dev );
+
+ hal_free_string( block_dev );
+ }
+ hal_free_string_array( devices );
+ }
+
+ hal_shutdown( ctx );
+ }
+#endif
+}