1 /*****************************************************************************
2 * libvlc.c: main libvlc source
3 *****************************************************************************
4 * Copyright (C) 1998-2004 VideoLAN
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Gildas Bazin <gbazin@videolan.org>
10 * Derk-Jan Hartman <hartman at videolan dot org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
28 * Pretend we are a builtin module
29 *****************************************************************************/
30 #define MODULE_NAME main
31 #define MODULE_PATH main
34 /*****************************************************************************
36 *****************************************************************************/
38 #include <vlc/input.h>
40 #include <errno.h> /* ENOMEM */
41 #include <stdio.h> /* sprintf() */
42 #include <string.h> /* strerror() */
43 #include <stdlib.h> /* free() */
46 # include <netinet/in.h> /* BSD: struct in_addr */
51 #elif defined( WIN32 ) && !defined( UNDER_CE )
55 #ifdef WIN32 /* optind, getopt(), included in unistd.h */
56 # include "extras/getopt.h"
64 # include <hal/libhal.h>
67 #include "vlc_cpu.h" /* CPU detection */
68 #include "os_specific.h"
70 #include "vlc_error.h"
72 #include "vlc_playlist.h"
73 #include "vlc_interface.h"
75 #include "audio_output.h"
77 #include "vlc_video.h"
78 #include "video_output.h"
80 #include "stream_output.h"
84 /*****************************************************************************
85 * The evil global variable. We handle it with care, don't worry.
86 *****************************************************************************/
87 static libvlc_t libvlc;
88 static libvlc_t * p_libvlc;
89 static vlc_t * p_static_vlc;
91 /*****************************************************************************
93 *****************************************************************************/
94 static void SetLanguage ( char const * );
95 static int GetFilenames ( vlc_t *, int, char *[] );
96 static void Usage ( vlc_t *, char const *psz_module_name );
97 static void ListModules ( vlc_t * );
98 static void Version ( void );
101 static void ShowConsole ( void );
102 static void PauseConsole ( void );
104 static int ConsoleWidth ( void );
106 static int VerboseCallback( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
109 static void InitDeviceValues( vlc_t * );
111 /*****************************************************************************
112 * vlc_current_object: return the current object.
113 *****************************************************************************
114 * If i_object is non-zero, return the corresponding object. Otherwise,
115 * return the statically allocated p_vlc object.
116 *****************************************************************************/
117 vlc_t * vlc_current_object( int i_object )
121 return vlc_object_get( p_libvlc, i_object );
127 /*****************************************************************************
128 * VLC_Version: return the libvlc version.
129 *****************************************************************************
130 * This function returns full version string (numeric version and codename).
131 *****************************************************************************/
132 char const * VLC_Version( void )
134 return VERSION_MESSAGE;
137 /*****************************************************************************
138 * VLC_Error: strerror() equivalent
139 *****************************************************************************
140 * This function returns full version string (numeric version and codename).
141 *****************************************************************************/
142 char const * VLC_Error( int i_err )
144 return vlc_error( i_err );
147 /*****************************************************************************
148 * VLC_Create: allocate a vlc_t structure, and initialize libvlc if needed.
149 *****************************************************************************
150 * This function allocates a vlc_t structure and returns a negative value
151 * in case of failure. Also, the thread system is initialized.
152 *****************************************************************************/
153 int VLC_Create( void )
156 vlc_t * p_vlc = NULL;
159 /* &libvlc never changes, so we can safely call this multiple times. */
162 /* vlc_threads_init *must* be the first internal call! No other call is
163 * allowed before the thread system has been initialized. */
164 i_ret = vlc_threads_init( p_libvlc );
170 /* Now that the thread system is initialized, we don't have much, but
171 * at least we have var_Create */
172 var_Create( p_libvlc, "libvlc", VLC_VAR_MUTEX );
173 var_Get( p_libvlc, "libvlc", &lockval );
174 vlc_mutex_lock( lockval.p_address );
175 if( !libvlc.b_ready )
179 /* Guess what CPU we have */
180 libvlc.i_cpu = CPUCapabilities();
182 /* Find verbosity from VLC_VERBOSE environment variable */
183 psz_env = getenv( "VLC_VERBOSE" );
184 libvlc.i_verbose = psz_env ? atoi( psz_env ) : -1;
186 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
187 libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
189 libvlc.b_color = VLC_FALSE;
192 /* Initialize message queue */
193 msg_Create( p_libvlc );
195 /* Announce who we are */
196 msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE );
197 msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
199 /* The module bank will be initialized later */
200 libvlc.p_module_bank = NULL;
202 libvlc.b_ready = VLC_TRUE;
204 vlc_mutex_unlock( lockval.p_address );
205 var_Destroy( p_libvlc, "libvlc" );
207 /* Allocate a vlc object */
208 p_vlc = vlc_object_create( p_libvlc, VLC_OBJECT_VLC );
213 p_vlc->thread_id = 0;
215 p_vlc->psz_object_name = "root";
217 /* Initialize mutexes */
218 vlc_mutex_init( p_vlc, &p_vlc->config_lock );
220 vlc_mutex_init( p_vlc, &p_vlc->quicktime_lock );
221 vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
224 /* Store our newly allocated structure in the global list */
225 vlc_object_attach( p_vlc, p_libvlc );
227 /* Store data for the non-reentrant API */
228 p_static_vlc = p_vlc;
230 return p_vlc->i_object_id;
233 /*****************************************************************************
234 * VLC_Init: initialize a vlc_t structure.
235 *****************************************************************************
236 * This function initializes a previously allocated vlc_t structure:
238 * - gettext initialization
239 * - message queue, module bank and playlist initialization
240 * - configuration and commandline parsing
241 *****************************************************************************/
242 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
244 char p_capabilities[200];
250 vlc_bool_t b_exit = VLC_FALSE;
251 vlc_t * p_vlc = vlc_current_object( i_object );
252 module_t *p_help_module;
253 playlist_t *p_playlist;
261 * System specific initialization code
263 system_Init( p_vlc, &i_argc, ppsz_argv );
265 /* Get the executable name (similar to the basename command) */
268 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
271 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
277 p_vlc->psz_object_name = "vlc";
281 * Support for gettext
285 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
286 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
288 /* Initialize the module bank and load the configuration of the
289 * main module. We need to do this at this stage to be able to display
290 * a short help if required by the user. (short help == main module
292 module_InitBank( p_vlc );
294 /* Hack: insert the help module here */
295 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
296 if( p_help_module == NULL )
298 module_EndBank( p_vlc );
299 if( i_object ) vlc_object_release( p_vlc );
302 p_help_module->psz_object_name = "help";
303 p_help_module->psz_longname = N_("Help options");
304 config_Duplicate( p_help_module, p_help_config );
305 vlc_object_attach( p_help_module, libvlc.p_module_bank );
308 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
310 vlc_object_detach( p_help_module );
311 config_Free( p_help_module );
312 vlc_object_destroy( p_help_module );
313 module_EndBank( p_vlc );
314 if( i_object ) vlc_object_release( p_vlc );
318 /* Check for short help option */
319 if( config_GetInt( p_vlc, "help" ) )
321 fprintf( stdout, _("Usage: %s [options] [items]...\n"),
322 p_vlc->psz_object_name );
323 Usage( p_vlc, "main" );
324 Usage( p_vlc, "help" );
327 /* Check for version option */
328 else if( config_GetInt( p_vlc, "version" ) )
334 /* Set the config file stuff */
335 p_vlc->psz_homedir = config_GetHomeDir();
336 p_vlc->psz_configfile = config_GetPsz( p_vlc, "config" );
338 /* Check for plugins cache options */
339 if( config_GetInt( p_vlc, "reset-plugins-cache" ) )
341 libvlc.p_module_bank->b_cache_delete = VLC_TRUE;
344 /* Hack: remove the help module here */
345 vlc_object_detach( p_help_module );
348 /* Will be re-done properly later on */
349 p_vlc->p_libvlc->i_verbose = config_GetInt( p_vlc, "verbose" );
351 /* Check for daemon mode */
353 if( config_GetInt( p_vlc, "daemon" ) )
356 if( daemon( 0, 0) != 0 )
358 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
362 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
367 if( ( i_pid = fork() ) < 0 )
369 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
374 /* This is the parent, exit right now */
375 msg_Dbg( p_vlc, "closing parent process" );
380 /* We are the child */
381 msg_Dbg( p_vlc, "daemon spawned" );
382 close( STDIN_FILENO );
383 close( STDOUT_FILENO );
384 close( STDERR_FILENO );
386 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
394 config_Free( p_help_module );
395 vlc_object_destroy( p_help_module );
396 module_EndBank( p_vlc );
397 if( i_object ) vlc_object_release( p_vlc );
401 /* Check for translation config option */
402 #if defined( ENABLE_NLS ) \
403 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
405 /* This ain't really nice to have to reload the config here but it seems
406 * the only way to do it. */
407 config_LoadConfigFile( p_vlc, "main" );
408 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
410 /* Check if the user specified a custom language */
411 psz_language = config_GetPsz( p_vlc, "language" );
412 if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
414 vlc_bool_t b_cache_delete = libvlc.p_module_bank->b_cache_delete;
416 /* Reset the default domain */
417 SetLanguage( psz_language );
419 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
420 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
422 textdomain( PACKAGE_NAME );
424 #if defined( ENABLE_UTF8 )
425 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
428 module_EndBank( p_vlc );
429 module_InitBank( p_vlc );
430 config_LoadConfigFile( p_vlc, "main" );
431 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
432 libvlc.p_module_bank->b_cache_delete = b_cache_delete;
434 if( psz_language ) free( psz_language );
438 * Load the builtins and plugins into the module_bank.
439 * We have to do it before config_Load*() because this also gets the
440 * list of configuration options exported by each module and loads their
443 module_LoadBuiltins( p_vlc );
444 module_LoadPlugins( p_vlc );
450 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
451 libvlc.p_module_bank->i_children );
453 /* Hack: insert the help module here */
454 vlc_object_attach( p_help_module, libvlc.p_module_bank );
457 /* Check for help on modules */
458 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
460 Usage( p_vlc, p_tmp );
464 /* Check for long help option */
465 else if( config_GetInt( p_vlc, "longhelp" ) )
467 Usage( p_vlc, NULL );
470 /* Check for module list option */
471 else if( config_GetInt( p_vlc, "list" ) )
473 ListModules( p_vlc );
477 /* Check for config file options */
478 if( config_GetInt( p_vlc, "reset-config" ) )
480 vlc_object_detach( p_help_module );
481 config_ResetAll( p_vlc );
482 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
483 config_SaveConfigFile( p_vlc, NULL );
484 vlc_object_attach( p_help_module, libvlc.p_module_bank );
486 if( config_GetInt( p_vlc, "save-config" ) )
488 vlc_object_detach( p_help_module );
489 config_LoadConfigFile( p_vlc, NULL );
490 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
491 config_SaveConfigFile( p_vlc, NULL );
492 vlc_object_attach( p_help_module, libvlc.p_module_bank );
495 /* Hack: remove the help module here */
496 vlc_object_detach( p_help_module );
501 config_Free( p_help_module );
502 vlc_object_destroy( p_help_module );
503 module_EndBank( p_vlc );
504 if( i_object ) vlc_object_release( p_vlc );
511 InitDeviceValues( p_vlc );
514 * Override default configuration with config file settings
516 config_LoadConfigFile( p_vlc, NULL );
518 /* Hack: insert the help module here */
519 vlc_object_attach( p_help_module, libvlc.p_module_bank );
523 * Override configuration with command line settings
525 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
529 /* Pause the console because it's destroyed when we exit */
530 fprintf( stderr, "The command line options couldn't be loaded, check "
531 "that they are valid.\n" );
534 vlc_object_detach( p_help_module );
535 config_Free( p_help_module );
536 vlc_object_destroy( p_help_module );
537 module_EndBank( p_vlc );
538 if( i_object ) vlc_object_release( p_vlc );
542 /* Hack: remove the help module here */
543 vlc_object_detach( p_help_module );
544 config_Free( p_help_module );
545 vlc_object_destroy( p_help_module );
549 * System specific configuration
551 system_Configure( p_vlc, &i_argc, ppsz_argv );
554 * Message queue options
557 var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
558 if( config_GetInt( p_vlc, "quiet" ) )
562 var_Set( p_vlc, "verbose", val );
564 var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
565 var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
567 libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
570 * Output messages that may still be in the queue
574 /* p_vlc initialization. FIXME ? */
576 #if defined( __i386__ )
577 if( !config_GetInt( p_vlc, "mmx" ) )
578 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
579 if( !config_GetInt( p_vlc, "3dn" ) )
580 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
581 if( !config_GetInt( p_vlc, "mmxext" ) )
582 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
583 if( !config_GetInt( p_vlc, "sse" ) )
584 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
585 if( !config_GetInt( p_vlc, "sse2" ) )
586 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
588 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
589 if( !config_GetInt( p_vlc, "altivec" ) )
590 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
593 #define PRINT_CAPABILITY( capability, string ) \
594 if( libvlc.i_cpu & capability ) \
596 strncat( p_capabilities, string " ", \
597 sizeof(p_capabilities) - strlen(p_capabilities) ); \
598 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
601 p_capabilities[0] = '\0';
602 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
603 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
604 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
605 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
606 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
607 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
608 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
609 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
610 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
611 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
612 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
615 * Choose the best memcpy module
617 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
619 if( p_vlc->pf_memcpy == NULL )
621 p_vlc->pf_memcpy = memcpy;
624 if( p_vlc->pf_memset == NULL )
626 p_vlc->pf_memset = memset;
630 * Initialize hotkey handling
632 var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
633 p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
634 /* Do a copy (we don't need to modify the strings) */
635 memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
638 * Initialize playlist and get commandline files
640 p_playlist = playlist_Create( p_vlc );
643 msg_Err( p_vlc, "playlist initialization failed" );
644 if( p_vlc->p_memcpy_module != NULL )
646 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
648 module_EndBank( p_vlc );
649 if( i_object ) vlc_object_release( p_vlc );
653 /* Add service discovery modules */
654 playlist_AddSDModules( p_playlist,
655 config_GetPsz( p_playlist, "services-discovery" ) );
658 * Load background interfaces
660 psz_modules = config_GetPsz( p_vlc, "extraintf" );
661 psz_control = config_GetPsz( p_vlc, "control" );
663 if( psz_modules && *psz_modules && psz_control && *psz_control )
665 psz_modules = (char *)realloc( psz_modules, strlen( psz_modules ) +
666 strlen( psz_control ) + 1 );
667 sprintf( psz_modules, "%s,%s", psz_modules, psz_control );
669 else if( psz_control && *psz_control )
671 if( psz_modules ) free( psz_modules );
672 psz_modules = strdup( psz_control );
675 psz_parser = psz_modules;
676 while ( psz_parser && *psz_parser )
678 char *psz_module, *psz_temp;
679 psz_module = psz_parser;
680 psz_parser = strchr( psz_module, ',' );
686 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
689 sprintf( psz_temp, "%s,none", psz_module );
690 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
700 * Allways load the hotkeys interface if it exists
702 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
705 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
707 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
708 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
709 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
710 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
711 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
712 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
713 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
714 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
715 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
716 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
717 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
718 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
721 * Get input filenames given as commandline arguments
723 GetFilenames( p_vlc, i_argc, ppsz_argv );
725 if( i_object ) vlc_object_release( p_vlc );
729 /*****************************************************************************
730 * VLC_AddIntf: add an interface
731 *****************************************************************************
732 * This function opens an interface plugin and runs it. If b_block is set
733 * to 0, VLC_AddIntf will return immediately and let the interface run in a
734 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
735 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
736 * the playlist when it is completely initialised.
737 *****************************************************************************/
738 int VLC_AddIntf( int i_object, char const *psz_module,
739 vlc_bool_t b_block, vlc_bool_t b_play )
742 intf_thread_t *p_intf;
743 vlc_t *p_vlc = vlc_current_object( i_object );
751 if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module )
754 * We prefer the dummy interface if none is specified. */
755 char *psz_interface = config_GetPsz( p_vlc, "intf" );
756 if( !psz_interface || !*psz_interface ) psz_module = "dummy";
757 if( psz_interface ) free( psz_interface );
761 /* Try to create the interface */
762 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
766 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
767 if( i_object ) vlc_object_release( p_vlc );
771 /* Interface doesn't handle play on start so do it ourselves */
772 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
774 /* Try to run the interface */
775 p_intf->b_play = b_play;
776 p_intf->b_block = b_block;
777 i_err = intf_RunThread( p_intf );
780 vlc_object_detach( p_intf );
781 intf_Destroy( p_intf );
782 if( i_object ) vlc_object_release( p_vlc );
786 if( i_object ) vlc_object_release( p_vlc );
790 /*****************************************************************************
791 * VLC_Die: ask vlc to die.
792 *****************************************************************************
793 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
794 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
795 *****************************************************************************/
796 int VLC_Die( int i_object )
798 vlc_t *p_vlc = vlc_current_object( i_object );
805 p_vlc->b_die = VLC_TRUE;
807 if( i_object ) vlc_object_release( p_vlc );
811 /*****************************************************************************
812 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
813 *****************************************************************************/
814 int VLC_CleanUp( int i_object )
816 intf_thread_t * p_intf;
817 playlist_t * p_playlist;
818 vout_thread_t * p_vout;
819 aout_instance_t * p_aout;
820 announce_handler_t * p_announce;
821 vlc_t *p_vlc = vlc_current_object( i_object );
823 /* Check that the handle is valid */
830 * Ask the interfaces to stop and destroy them
832 msg_Dbg( p_vlc, "removing all interfaces" );
833 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
835 intf_StopThread( p_intf );
836 vlc_object_detach( p_intf );
837 vlc_object_release( p_intf );
838 intf_Destroy( p_intf );
844 msg_Dbg( p_vlc, "removing all playlists" );
845 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
848 vlc_object_detach( p_playlist );
849 vlc_object_release( p_playlist );
850 playlist_Destroy( p_playlist );
856 msg_Dbg( p_vlc, "removing all video outputs" );
857 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
859 vlc_object_detach( p_vout );
860 vlc_object_release( p_vout );
861 vout_Destroy( p_vout );
867 msg_Dbg( p_vlc, "removing all audio outputs" );
868 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
870 vlc_object_detach( (vlc_object_t *)p_aout );
871 vlc_object_release( (vlc_object_t *)p_aout );
872 aout_Delete( p_aout );
876 * Free announce handler(s?)
878 msg_Dbg( p_vlc, "removing announce handler" );
879 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
882 vlc_object_detach( p_announce );
883 vlc_object_release( p_announce );
884 announce_HandlerDestroy( p_announce );
887 if( i_object ) vlc_object_release( p_vlc );
891 /*****************************************************************************
892 * VLC_Destroy: Destroy everything.
893 *****************************************************************************
894 * This function requests the running threads to finish, waits for their
895 * termination, and destroys their structure.
896 *****************************************************************************/
897 int VLC_Destroy( int i_object )
899 vlc_t *p_vlc = vlc_current_object( i_object );
907 * Free allocated memory
909 if( p_vlc->p_memcpy_module )
911 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
912 p_vlc->p_memcpy_module = NULL;
918 module_EndBank( p_vlc );
920 if( p_vlc->psz_homedir )
922 free( p_vlc->psz_homedir );
923 p_vlc->psz_homedir = NULL;
926 if( p_vlc->psz_configfile )
928 free( p_vlc->psz_configfile );
929 p_vlc->psz_configfile = NULL;
932 if( p_vlc->p_hotkeys )
934 free( p_vlc->p_hotkeys );
935 p_vlc->p_hotkeys = NULL;
939 * System specific cleaning code
943 /* Destroy mutexes */
944 vlc_mutex_destroy( &p_vlc->config_lock );
946 vlc_object_detach( p_vlc );
948 /* Release object before destroying it */
949 if( i_object ) vlc_object_release( p_vlc );
951 vlc_object_destroy( p_vlc );
953 /* Stop thread system: last one out please shut the door! */
954 vlc_threads_end( p_libvlc );
959 /*****************************************************************************
960 * VLC_VariableSet: set a vlc variable
961 *****************************************************************************/
962 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
964 vlc_t *p_vlc = vlc_current_object( i_object );
972 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
973 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
974 if( !strncmp( psz_var, "conf::", 6 ) )
976 module_config_t *p_item;
977 char const *psz_newvar = psz_var + 6;
979 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
983 switch( p_item->i_type )
985 case CONFIG_ITEM_BOOL:
986 config_PutInt( p_vlc, psz_newvar, value.b_bool );
988 case CONFIG_ITEM_INTEGER:
989 config_PutInt( p_vlc, psz_newvar, value.i_int );
991 case CONFIG_ITEM_FLOAT:
992 config_PutFloat( p_vlc, psz_newvar, value.f_float );
995 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
998 if( i_object ) vlc_object_release( p_vlc );
1003 i_ret = var_Set( p_vlc, psz_var, value );
1005 if( i_object ) vlc_object_release( p_vlc );
1009 /*****************************************************************************
1010 * VLC_VariableGet: get a vlc variable
1011 *****************************************************************************/
1012 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
1014 vlc_t *p_vlc = vlc_current_object( i_object );
1022 i_ret = var_Get( p_vlc , psz_var, p_value );
1024 if( i_object ) vlc_object_release( p_vlc );
1028 /*****************************************************************************
1029 * VLC_AddTarget: adds a target for playing.
1030 *****************************************************************************
1031 * This function adds psz_target to the current playlist. If a playlist does
1032 * not exist, it will create one.
1033 *****************************************************************************/
1034 int VLC_AddTarget( int i_object, char const *psz_target,
1035 char const **ppsz_options, int i_options,
1036 int i_mode, int i_pos )
1039 playlist_t *p_playlist;
1040 vlc_t *p_vlc = vlc_current_object( i_object );
1047 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1049 if( p_playlist == NULL )
1051 msg_Dbg( p_vlc, "no playlist present, creating one" );
1052 p_playlist = playlist_Create( p_vlc );
1054 if( p_playlist == NULL )
1056 if( i_object ) vlc_object_release( p_vlc );
1057 return VLC_EGENERIC;
1060 vlc_object_yield( p_playlist );
1063 i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
1064 i_mode, i_pos, -1, ppsz_options, i_options);
1066 vlc_object_release( p_playlist );
1068 if( i_object ) vlc_object_release( p_vlc );
1072 /*****************************************************************************
1074 *****************************************************************************/
1075 int VLC_Play( int i_object )
1077 playlist_t * p_playlist;
1078 vlc_t *p_vlc = vlc_current_object( i_object );
1080 /* Check that the handle is valid */
1086 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1090 if( i_object ) vlc_object_release( p_vlc );
1094 playlist_Play( p_playlist );
1095 vlc_object_release( p_playlist );
1097 if( i_object ) vlc_object_release( p_vlc );
1101 /*****************************************************************************
1102 * VLC_Pause: toggle pause
1103 *****************************************************************************/
1104 int VLC_Pause( int i_object )
1106 playlist_t * p_playlist;
1107 vlc_t *p_vlc = vlc_current_object( i_object );
1109 /* Check that the handle is valid */
1115 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1119 if( i_object ) vlc_object_release( p_vlc );
1123 playlist_Pause( p_playlist );
1124 vlc_object_release( p_playlist );
1126 if( i_object ) vlc_object_release( p_vlc );
1130 /*****************************************************************************
1131 * VLC_Pause: toggle pause
1132 *****************************************************************************/
1133 int VLC_Stop( int i_object )
1135 playlist_t * p_playlist;
1136 vlc_t *p_vlc = vlc_current_object( i_object );
1138 /* Check that the handle is valid */
1144 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1148 if( i_object ) vlc_object_release( p_vlc );
1152 playlist_Stop( p_playlist );
1153 vlc_object_release( p_playlist );
1155 if( i_object ) vlc_object_release( p_vlc );
1159 /*****************************************************************************
1160 * VLC_IsPlaying: Query for Playlist Status
1161 *****************************************************************************/
1162 vlc_bool_t VLC_IsPlaying( int i_object )
1164 playlist_t * p_playlist;
1165 vlc_bool_t b_playing;
1167 vlc_t *p_vlc = vlc_current_object( i_object );
1169 /* Check that the handle is valid */
1175 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1179 if( i_object ) vlc_object_release( p_vlc );
1183 b_playing = playlist_IsPlaying( p_playlist );
1184 vlc_object_release( p_playlist );
1186 if( i_object ) vlc_object_release( p_vlc );
1191 * Get the current position in a input
1193 * Return the current position as a float
1194 * \note For some inputs, this will be unknown.
1196 * \param i_object a vlc object id
1197 * \return a float in the range of 0.0 - 1.0
1199 float VLC_PositionGet( int i_object )
1201 input_thread_t *p_input;
1203 vlc_t *p_vlc = vlc_current_object( i_object );
1205 /* Check that the handle is valid */
1211 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1215 if( i_object ) vlc_object_release( p_vlc );
1219 var_Get( p_input, "position", &val );
1220 vlc_object_release( p_input );
1222 if( i_object ) vlc_object_release( p_vlc );
1227 * Set the current position in a input
1229 * Set the current position in a input and then return
1230 * the current position as a float.
1231 * \note For some inputs, this will be unknown.
1233 * \param i_object a vlc object id
1234 * \param i_position a float in the range of 0.0 - 1.0
1235 * \return a float in the range of 0.0 - 1.0
1237 float VLC_PositionSet( int i_object, float i_position )
1239 input_thread_t *p_input;
1241 vlc_t *p_vlc = vlc_current_object( i_object );
1243 /* Check that the handle is valid */
1249 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1253 if( i_object ) vlc_object_release( p_vlc );
1257 val.f_float = i_position;
1258 var_Set( p_input, "position", val );
1259 var_Get( p_input, "position", &val );
1260 vlc_object_release( p_input );
1262 if( i_object ) vlc_object_release( p_vlc );
1267 * Get the current position in a input
1269 * Return the current position in seconds from the start.
1270 * \note For some inputs, this will be unknown.
1272 * \param i_object a vlc object id
1273 * \return the offset from 0:00 in seconds
1275 int VLC_TimeGet( int i_object )
1277 input_thread_t *p_input;
1279 vlc_t *p_vlc = vlc_current_object( i_object );
1281 /* Check that the handle is valid */
1287 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1291 if( i_object ) vlc_object_release( p_vlc );
1295 var_Get( p_input, "time", &val );
1296 vlc_object_release( p_input );
1298 if( i_object ) vlc_object_release( p_vlc );
1299 return val.i_time / 1000000;
1303 * Seek to a position in the current input
1305 * Seek i_seconds in the current input. If b_relative is set,
1306 * then the seek will be relative to the current position, otherwise
1307 * it will seek to i_seconds from the beginning of the input.
1308 * \note For some inputs, this will be unknown.
1310 * \param i_object a vlc object id
1311 * \param i_seconds seconds from current position or from beginning of input
1312 * \param b_relative seek relative from current position
1313 * \return VLC_SUCCESS on success
1315 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1317 input_thread_t *p_input;
1319 vlc_t *p_vlc = vlc_current_object( i_object );
1321 /* Check that the handle is valid */
1327 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1331 if( i_object ) vlc_object_release( p_vlc );
1337 val.i_time = i_seconds * 1000000;
1338 var_Set( p_input, "time-offset", val );
1342 val.i_time = i_seconds * 1000000;
1343 var_Set( p_input, "time", val );
1345 vlc_object_release( p_input );
1347 if( i_object ) vlc_object_release( p_vlc );
1352 * Get the total length of a input
1354 * Return the total length in seconds from the current input.
1355 * \note For some inputs, this will be unknown.
1357 * \param i_object a vlc object id
1358 * \return the length in seconds
1360 int VLC_LengthGet( int i_object )
1362 input_thread_t *p_input;
1364 vlc_t *p_vlc = vlc_current_object( i_object );
1366 /* Check that the handle is valid */
1372 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1376 if( i_object ) vlc_object_release( p_vlc );
1380 var_Get( p_input, "length", &val );
1381 vlc_object_release( p_input );
1383 if( i_object ) vlc_object_release( p_vlc );
1384 return val.i_time / 1000000;
1388 * Play the input faster than realtime
1390 * 2x, 4x, 8x faster than realtime
1391 * \note For some inputs, this will be impossible.
1393 * \param i_object a vlc object id
1394 * \return the current speedrate
1396 float VLC_SpeedFaster( int i_object )
1398 input_thread_t *p_input;
1400 vlc_t *p_vlc = vlc_current_object( i_object );
1402 /* Check that the handle is valid */
1408 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1412 if( i_object ) vlc_object_release( p_vlc );
1416 val.b_bool = VLC_TRUE;
1417 var_Set( p_input, "rate-faster", val );
1418 var_Get( p_input, "rate", &val );
1419 vlc_object_release( p_input );
1421 if( i_object ) vlc_object_release( p_vlc );
1422 return val.f_float / INPUT_RATE_DEFAULT;
1426 * Play the input slower than realtime
1428 * 1/2x, 1/4x, 1/8x slower than realtime
1429 * \note For some inputs, this will be impossible.
1431 * \param i_object a vlc object id
1432 * \return the current speedrate
1434 float VLC_SpeedSlower( int i_object )
1436 input_thread_t *p_input;
1438 vlc_t *p_vlc = vlc_current_object( i_object );
1440 /* Check that the handle is valid */
1446 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1450 if( i_object ) vlc_object_release( p_vlc );
1454 val.b_bool = VLC_TRUE;
1455 var_Set( p_input, "rate-slower", val );
1456 var_Get( p_input, "rate", &val );
1457 vlc_object_release( p_input );
1459 if( i_object ) vlc_object_release( p_vlc );
1460 return val.f_float / INPUT_RATE_DEFAULT;
1464 * Return the current playlist item
1466 * Returns the index of the playlistitem that is currently selected for play.
1467 * This is valid even if nothing is currently playing.
1469 * \param i_object a vlc object id
1470 * \return the current index
1472 int VLC_PlaylistIndex( int i_object )
1475 playlist_t * p_playlist;
1476 vlc_t *p_vlc = vlc_current_object( i_object );
1478 /* Check that the handle is valid */
1484 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1488 if( i_object ) vlc_object_release( p_vlc );
1492 i_index = p_playlist->i_index;
1493 vlc_object_release( p_playlist );
1495 if( i_object ) vlc_object_release( p_vlc );
1500 * Total amount of items in the playlist
1502 * \param i_object a vlc object id
1503 * \return amount of playlist items
1505 int VLC_PlaylistNumberOfItems( int i_object )
1508 playlist_t * p_playlist;
1509 vlc_t *p_vlc = vlc_current_object( i_object );
1511 /* Check that the handle is valid */
1517 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1521 if( i_object ) vlc_object_release( p_vlc );
1525 i_size = p_playlist->i_size;
1526 vlc_object_release( p_playlist );
1528 if( i_object ) vlc_object_release( p_vlc );
1533 * Next playlist item
1535 * Skip to the next playlistitem and play it.
1537 * \param i_object a vlc object id
1538 * \return VLC_SUCCESS on success
1540 int VLC_PlaylistNext( int i_object )
1542 playlist_t * p_playlist;
1543 vlc_t *p_vlc = vlc_current_object( i_object );
1545 /* Check that the handle is valid */
1551 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1555 if( i_object ) vlc_object_release( p_vlc );
1559 playlist_Next( p_playlist );
1560 vlc_object_release( p_playlist );
1562 if( i_object ) vlc_object_release( p_vlc );
1567 * Previous playlist item
1569 * Skip to the previous playlistitem and play it.
1571 * \param i_object a vlc object id
1572 * \return VLC_SUCCESS on success
1574 int VLC_PlaylistPrev( int i_object )
1576 playlist_t * p_playlist;
1577 vlc_t *p_vlc = vlc_current_object( i_object );
1579 /* Check that the handle is valid */
1585 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1589 if( i_object ) vlc_object_release( p_vlc );
1593 playlist_Prev( p_playlist );
1594 vlc_object_release( p_playlist );
1596 if( i_object ) vlc_object_release( p_vlc );
1601 /*****************************************************************************
1602 * VLC_PlaylistClear: Empty the playlist
1603 *****************************************************************************/
1604 int VLC_PlaylistClear( int i_object )
1607 playlist_t * p_playlist;
1608 vlc_t *p_vlc = vlc_current_object( i_object );
1610 /* Check that the handle is valid */
1616 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1620 if( i_object ) vlc_object_release( p_vlc );
1624 i_err = playlist_Clear( p_playlist );
1626 vlc_object_release( p_playlist );
1628 if( i_object ) vlc_object_release( p_vlc );
1635 * \param i_object a vlc object id
1636 * \param i_volume something in a range from 0-200
1637 * \return the new volume (range 0-200 %)
1639 int VLC_VolumeSet( int i_object, int i_volume )
1641 audio_volume_t i_vol = 0;
1642 vlc_t *p_vlc = vlc_current_object( i_object );
1644 /* Check that the handle is valid */
1650 if( i_volume >= 0 && i_volume <= 200 )
1652 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1653 aout_VolumeSet( p_vlc, i_vol );
1656 if( i_object ) vlc_object_release( p_vlc );
1657 return i_vol * 200 / AOUT_VOLUME_MAX;
1661 * Get the current volume
1663 * Retrieve the current volume.
1665 * \param i_object a vlc object id
1666 * \return the current volume (range 0-200 %)
1668 int VLC_VolumeGet( int i_object )
1670 audio_volume_t i_volume;
1671 vlc_t *p_vlc = vlc_current_object( i_object );
1673 /* Check that the handle is valid */
1679 aout_VolumeGet( p_vlc, &i_volume );
1681 if( i_object ) vlc_object_release( p_vlc );
1682 return i_volume*200/AOUT_VOLUME_MAX;
1686 * Mute/Unmute the volume
1688 * \param i_object a vlc object id
1689 * \return VLC_SUCCESS on success
1691 int VLC_VolumeMute( int i_object )
1693 vlc_t *p_vlc = vlc_current_object( i_object );
1695 /* Check that the handle is valid */
1701 aout_VolumeMute( p_vlc, NULL );
1703 if( i_object ) vlc_object_release( p_vlc );
1707 /*****************************************************************************
1708 * VLC_FullScreen: toggle fullscreen mode
1709 *****************************************************************************/
1710 int VLC_FullScreen( int i_object )
1712 vout_thread_t *p_vout;
1713 vlc_t *p_vlc = vlc_current_object( i_object );
1720 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1724 if( i_object ) vlc_object_release( p_vlc );
1728 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1729 vlc_object_release( p_vout );
1731 if( i_object ) vlc_object_release( p_vlc );
1735 /* following functions are local */
1737 /*****************************************************************************
1738 * SetLanguage: set the interface language.
1739 *****************************************************************************
1740 * We set the LC_MESSAGES locale category for interface messages and buttons,
1741 * as well as the LC_CTYPE category for string sorting and possible wide
1742 * character support.
1743 *****************************************************************************/
1744 static void SetLanguage ( char const *psz_lang )
1746 #if defined( ENABLE_NLS ) \
1747 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1750 #if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
1754 if( psz_lang && !*psz_lang )
1756 # if defined( HAVE_LC_MESSAGES )
1757 setlocale( LC_MESSAGES, psz_lang );
1759 setlocale( LC_CTYPE, psz_lang );
1764 /* I need that under Darwin, please check it doesn't disturb
1765 * other platforms. --Meuuh */
1766 setenv( "LANG", psz_lang, 1 );
1768 #elif defined( SYS_BEOS ) || defined( WIN32 )
1769 /* We set LC_ALL manually because it is the only way to set
1770 * the language at runtime under eg. Windows. Beware that this
1771 * makes the environment unconsistent when libvlc is unloaded and
1772 * should probably be moved to a safer place like vlc.c. */
1773 static char psz_lcall[20];
1774 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1775 psz_lcall[19] = '\0';
1776 putenv( psz_lcall );
1779 setlocale( LC_ALL, psz_lang );
1782 /* Specify where to find the locales for current domain */
1783 #if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1784 psz_path = LOCALEDIR;
1786 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1790 if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
1792 fprintf( stderr, "warning: no domain %s in directory %s\n",
1793 PACKAGE_NAME, psz_path );
1796 /* Set the default domain */
1797 textdomain( PACKAGE_NAME );
1799 #if defined( ENABLE_UTF8 )
1800 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
1806 /*****************************************************************************
1807 * GetFilenames: parse command line options which are not flags
1808 *****************************************************************************
1809 * Parse command line for input files as well as their associated options.
1810 * An option always follows its associated input and begins with a ":".
1811 *****************************************************************************/
1812 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1814 int i_opt, i_options;
1816 /* We assume that the remaining parameters are filenames
1817 * and their input options */
1818 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
1822 /* Count the input options */
1823 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
1829 /* TODO: write an internal function of this one, to avoid
1830 * unnecessary lookups. */
1831 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1832 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
1834 PLAYLIST_INSERT, 0 );
1840 /*****************************************************************************
1841 * Usage: print program usage
1842 *****************************************************************************
1843 * Print a short inline help. Message interface is initialized at this stage.
1844 *****************************************************************************/
1845 static void Usage( vlc_t *p_this, char const *psz_module_name )
1847 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1848 /* short option ------' | | | | | | |
1849 * option name ------------' | | | | | |
1850 * <bra -------------------------' | | | | |
1851 * option type or "" --------------' | | | |
1852 * ket> -----------------------------' | | |
1853 * padding spaces ---------------------' | |
1854 * comment -------------------------------' |
1855 * comment suffix --------------------------'
1857 * The purpose of having bra and ket is that we might i18n them as well.
1859 #define LINE_START 8
1860 #define PADDING_SPACES 25
1863 module_config_t *p_item;
1864 char psz_spaces[PADDING_SPACES+LINE_START+1];
1865 char psz_format[sizeof(FORMAT_STRING)];
1866 char psz_buffer[1000];
1869 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1870 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
1872 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1873 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1875 strcpy( psz_format, FORMAT_STRING );
1881 /* List all modules */
1882 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1884 /* Enumerate the config for each module */
1885 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1887 vlc_bool_t b_help_module;
1889 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1891 if( psz_module_name && strcmp( psz_module_name,
1892 p_parser->psz_object_name ) )
1897 /* Ignore modules without config options */
1898 if( !p_parser->i_config_items )
1903 /* Ignore modules with only advanced config options if requested */
1906 for( p_item = p_parser->p_config;
1907 p_item->i_type != CONFIG_HINT_END;
1910 if( (p_item->i_type & CONFIG_ITEM) &&
1911 !p_item->b_advanced ) break;
1913 if( p_item->i_type == CONFIG_HINT_END ) continue;
1916 /* Print name of module */
1917 if( strcmp( "main", p_parser->psz_object_name ) )
1918 fprintf( stdout, "\n %s\n", p_parser->psz_longname );
1920 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1922 /* Print module options */
1923 for( p_item = p_parser->p_config;
1924 p_item->i_type != CONFIG_HINT_END;
1928 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1929 char *psz_suf = "", *psz_prefix = NULL;
1932 /* Skip advanced options if requested */
1933 if( p_item->b_advanced && !b_advanced )
1938 switch( p_item->i_type )
1940 case CONFIG_HINT_CATEGORY:
1941 case CONFIG_HINT_USAGE:
1942 if( !strcmp( "main", p_parser->psz_object_name ) )
1943 fprintf( stdout, "\n %s\n", p_item->psz_text );
1946 case CONFIG_ITEM_STRING:
1947 case CONFIG_ITEM_FILE:
1948 case CONFIG_ITEM_DIRECTORY:
1949 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1950 if( !p_item->ppsz_list )
1952 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1958 psz_type = psz_buffer;
1960 for( i = 0; p_item->ppsz_list[i]; i++ )
1962 if( i ) strcat( psz_type, "," );
1963 strcat( psz_type, p_item->ppsz_list[i] );
1968 case CONFIG_ITEM_INTEGER:
1969 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
1970 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1972 case CONFIG_ITEM_FLOAT:
1973 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1975 case CONFIG_ITEM_BOOL:
1976 psz_bra = ""; psz_type = ""; psz_ket = "";
1977 if( !b_help_module )
1979 psz_suf = p_item->i_value ? _(" (default enabled)") :
1980 _(" (default disabled)");
1990 /* Add short option if any */
1991 if( p_item->i_short )
1993 sprintf( psz_short, "-%c,", p_item->i_short );
1997 strcpy( psz_short, " " );
2000 i = PADDING_SPACES - strlen( p_item->psz_name )
2001 - strlen( psz_bra ) - strlen( psz_type )
2002 - strlen( psz_ket ) - 1;
2004 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2006 /* If option is of type --foo-bar, we print its counterpart
2007 * as --no-foo-bar, but if it is of type --foobar (without
2008 * dashes in the name) we print it as --nofoobar. Both
2009 * values are of course valid, only the display changes. */
2010 psz_prefix = strchr( p_item->psz_name, '-' ) ? ", --no-"
2012 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
2017 psz_spaces[0] = '\n';
2022 psz_spaces[i] = '\0';
2025 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2027 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2028 psz_prefix, p_item->psz_name, psz_bra, psz_type,
2029 psz_ket, psz_spaces );
2033 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2034 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
2037 psz_spaces[i] = ' ';
2039 /* We wrap the rest of the output */
2040 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
2041 psz_text = psz_buffer;
2044 char *psz_parser, *psz_word;
2045 int i_end = strlen( psz_text );
2047 /* If the remaining text fits in a line, print it. */
2048 if( i_end <= i_width )
2050 fprintf( stdout, "%s\n", psz_text );
2054 /* Otherwise, eat as many words as possible */
2055 psz_parser = psz_text;
2058 psz_word = psz_parser;
2059 psz_parser = strchr( psz_word, ' ' );
2060 /* If no space was found, we reached the end of the text
2061 * block; otherwise, we skip the space we just found. */
2062 psz_parser = psz_parser ? psz_parser + 1
2065 } while( psz_parser - psz_text <= i_width );
2067 /* We cut a word in one of these cases:
2068 * - it's the only word in the line and it's too long.
2069 * - we used less than 80% of the width and the word we are
2070 * going to wrap is longer than 40% of the width, and even
2071 * if the word would have fit in the next line. */
2072 if( psz_word == psz_text
2073 || ( psz_word - psz_text < 80 * i_width / 100
2074 && psz_parser - psz_word > 40 * i_width / 100 ) )
2076 char c = psz_text[i_width];
2077 psz_text[i_width] = '\0';
2078 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2079 psz_text += i_width;
2084 psz_word[-1] = '\0';
2085 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2086 psz_text = psz_word;
2092 /* Release the module list */
2093 vlc_list_release( p_list );
2095 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2100 /*****************************************************************************
2101 * ListModules: list the available modules with their description
2102 *****************************************************************************
2103 * Print a list of all available modules (builtins and plugins) and a short
2104 * description for each one.
2105 *****************************************************************************/
2106 static void ListModules( vlc_t *p_this )
2110 char psz_spaces[22];
2113 memset( psz_spaces, ' ', 22 );
2120 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
2121 p_this->p_vlc->psz_object_name );
2123 fprintf( stdout, _("[module] [description]\n") );
2125 /* List all modules */
2126 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2128 /* Enumerate each module */
2129 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2133 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2135 /* Nasty hack, but right now I'm too tired to think about a nice
2137 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2141 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2142 psz_spaces, p_parser->psz_longname );
2144 psz_spaces[i] = ' ';
2147 vlc_list_release( p_list );
2149 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2154 /*****************************************************************************
2155 * Version: print complete program version
2156 *****************************************************************************
2157 * Print complete program version and build number.
2158 *****************************************************************************/
2159 static void Version( void )
2165 fprintf( stdout, VERSION_MESSAGE "\n" );
2167 _("This program comes with NO WARRANTY, to the extent permitted by "
2168 "law.\nYou may redistribute it under the terms of the GNU General "
2169 "Public License;\nsee the file named COPYING for details.\n"
2170 "Written by the VideoLAN team; see the AUTHORS file.\n") );
2172 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2177 /*****************************************************************************
2178 * ShowConsole: On Win32, create an output console for debug messages
2179 *****************************************************************************
2180 * This function is useful only on Win32.
2181 *****************************************************************************/
2183 static void ShowConsole( void )
2187 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2190 freopen( "CONOUT$", "w", stdout );
2191 freopen( "CONOUT$", "w", stderr );
2192 freopen( "CONIN$", "r", stdin );
2198 /*****************************************************************************
2199 * PauseConsole: On Win32, wait for a key press before closing the console
2200 *****************************************************************************
2201 * This function is useful only on Win32.
2202 *****************************************************************************/
2204 static void PauseConsole( void )
2208 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2209 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2216 /*****************************************************************************
2217 * ConsoleWidth: Return the console width in characters
2218 *****************************************************************************
2219 * We use the stty shell command to get the console width; if this fails or
2220 * if the width is less than 80, we default to 80.
2221 *****************************************************************************/
2222 static int ConsoleWidth( void )
2227 char buf[20], *psz_parser;
2231 file = popen( "stty size 2>/dev/null", "r" );
2234 i_ret = fread( buf, 1, 20, file );
2238 psz_parser = strchr( buf, ' ' );
2241 i_ret = atoi( psz_parser + 1 );
2256 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2257 vlc_value_t old_val, vlc_value_t new_val, void *param)
2259 vlc_t *p_vlc = (vlc_t *)p_this;
2261 if( new_val.i_int >= -1 )
2263 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );
2268 /*****************************************************************************
2269 * InitDeviceValues: initialize device values
2270 *****************************************************************************
2271 * This function inits the dvd, vcd and cd-audio values
2272 *****************************************************************************/
2273 static void InitDeviceValues( vlc_t *p_vlc )
2276 LibHalContext * ctx;
2282 if( ( ctx = hal_initialize( NULL, FALSE ) ) )
2284 if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) )
2286 for( i = 0; i < i_devices; i++ )
2288 if( !hal_device_property_exists( ctx, devices[ i ],
2289 "storage.cdrom.dvd" ) )
2294 b_dvd = hal_device_get_property_bool( ctx, devices[ i ],
2295 "storage.cdrom.dvd" );
2296 block_dev = hal_device_get_property_string( ctx, devices[ i ],
2301 config_PutPsz( p_vlc, "dvd", block_dev );
2304 config_PutPsz( p_vlc, "vcd", block_dev );
2305 config_PutPsz( p_vlc, "cd-audio", block_dev );
2307 hal_free_string( block_dev );
2311 hal_shutdown( ctx );