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@netcourrier.com>
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>
41 # include <errno.h> /* ENOMEM */
43 #include <stdio.h> /* sprintf() */
44 #include <string.h> /* strerror() */
45 #include <stdlib.h> /* free() */
48 # include <netinet/in.h> /* BSD: struct in_addr */
53 #elif defined( WIN32 ) && !defined( UNDER_CE )
57 #ifdef WIN32 /* optind, getopt(), included in unistd.h */
58 # include "extras/getopt.h"
65 #include "vlc_cpu.h" /* CPU detection */
66 #include "os_specific.h"
68 #include "vlc_error.h"
70 #include "vlc_playlist.h"
71 #include "vlc_interface.h"
73 #include "audio_output.h"
75 #include "vlc_video.h"
76 #include "video_output.h"
78 #include "stream_output.h"
82 /*****************************************************************************
83 * The evil global variable. We handle it with care, don't worry.
84 *****************************************************************************/
85 static libvlc_t libvlc;
86 static libvlc_t * p_libvlc;
87 static vlc_t * p_static_vlc;
89 /*****************************************************************************
91 *****************************************************************************/
92 static void SetLanguage ( char const * );
93 static int GetFilenames ( vlc_t *, int, char *[] );
94 static void Usage ( vlc_t *, char const *psz_module_name );
95 static void ListModules ( vlc_t * );
96 static void Version ( void );
99 static void ShowConsole ( void );
101 static int ConsoleWidth ( void );
103 static int VerboseCallback( vlc_object_t *, char const *,
104 vlc_value_t, vlc_value_t, void * );
106 /*****************************************************************************
107 * vlc_current_object: return the current object.
108 *****************************************************************************
109 * If i_object is non-zero, return the corresponding object. Otherwise,
110 * return the statically allocated p_vlc object.
111 *****************************************************************************/
112 vlc_t * vlc_current_object( int i_object )
116 return vlc_object_get( p_libvlc, i_object );
122 /*****************************************************************************
123 * VLC_Version: return the libvlc version.
124 *****************************************************************************
125 * This function returns full version string (numeric version and codename).
126 *****************************************************************************/
127 char const * VLC_Version( void )
129 return VERSION_MESSAGE;
132 /*****************************************************************************
133 * VLC_Error: strerror() equivalent
134 *****************************************************************************
135 * This function returns full version string (numeric version and codename).
136 *****************************************************************************/
137 char const * VLC_Error( int i_err )
139 return vlc_error( i_err );
142 /*****************************************************************************
143 * VLC_Create: allocate a vlc_t structure, and initialize libvlc if needed.
144 *****************************************************************************
145 * This function allocates a vlc_t structure and returns a negative value
146 * in case of failure. Also, the thread system is initialized.
147 *****************************************************************************/
148 int VLC_Create( void )
151 vlc_t * p_vlc = NULL;
154 /* &libvlc never changes, so we can safely call this multiple times. */
157 /* vlc_threads_init *must* be the first internal call! No other call is
158 * allowed before the thread system has been initialized. */
159 i_ret = vlc_threads_init( p_libvlc );
165 /* Now that the thread system is initialized, we don't have much, but
166 * at least we have var_Create */
167 var_Create( p_libvlc, "libvlc", VLC_VAR_MUTEX );
168 var_Get( p_libvlc, "libvlc", &lockval );
169 vlc_mutex_lock( lockval.p_address );
170 if( !libvlc.b_ready )
174 /* Guess what CPU we have */
175 libvlc.i_cpu = CPUCapabilities();
177 /* Find verbosity from VLC_VERBOSE environment variable */
178 psz_env = getenv( "VLC_VERBOSE" );
179 libvlc.i_verbose = psz_env ? atoi( psz_env ) : -1;
181 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
182 libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
184 libvlc.b_color = VLC_FALSE;
187 /* Initialize message queue */
188 msg_Create( p_libvlc );
190 /* Announce who we are */
191 msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE );
192 msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
194 /* The module bank will be initialized later */
195 libvlc.p_module_bank = NULL;
197 libvlc.b_ready = VLC_TRUE;
199 vlc_mutex_unlock( lockval.p_address );
200 var_Destroy( p_libvlc, "libvlc" );
202 /* Allocate a vlc object */
203 p_vlc = vlc_object_create( p_libvlc, VLC_OBJECT_VLC );
208 p_vlc->thread_id = 0;
209 vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
211 p_vlc->psz_object_name = "root";
213 /* Initialize mutexes */
214 vlc_mutex_init( p_vlc, &p_vlc->config_lock );
216 vlc_mutex_init( p_vlc, &p_vlc->quicktime_lock );
219 /* Store our newly allocated structure in the global list */
220 vlc_object_attach( p_vlc, p_libvlc );
222 /* Store data for the non-reentrant API */
223 p_static_vlc = p_vlc;
225 return p_vlc->i_object_id;
228 /*****************************************************************************
229 * VLC_Init: initialize a vlc_t structure.
230 *****************************************************************************
231 * This function initializes a previously allocated vlc_t structure:
233 * - gettext initialization
234 * - message queue, module bank and playlist initialization
235 * - configuration and commandline parsing
236 *****************************************************************************/
237 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
239 char p_capabilities[200];
244 vlc_bool_t b_exit = VLC_FALSE;
245 vlc_t * p_vlc = vlc_current_object( i_object );
246 module_t *p_help_module;
247 playlist_t *p_playlist;
255 * System specific initialization code
257 system_Init( p_vlc, &i_argc, ppsz_argv );
259 /* Get the executable name (similar to the basename command) */
262 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
265 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
271 p_vlc->psz_object_name = "vlc";
275 * Support for gettext
279 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
280 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
282 /* Initialize the module bank and load the configuration of the
283 * main module. We need to do this at this stage to be able to display
284 * a short help if required by the user. (short help == main module
286 module_InitBank( p_vlc );
288 /* Hack: insert the help module here */
289 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
290 if( p_help_module == NULL )
292 module_EndBank( p_vlc );
293 if( i_object ) vlc_object_release( p_vlc );
296 p_help_module->psz_object_name = "help";
297 p_help_module->psz_longname = N_("Help options");
298 config_Duplicate( p_help_module, p_help_config );
299 vlc_object_attach( p_help_module, libvlc.p_module_bank );
302 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
304 vlc_object_detach( p_help_module );
305 config_Free( p_help_module );
306 vlc_object_destroy( p_help_module );
307 module_EndBank( p_vlc );
308 if( i_object ) vlc_object_release( p_vlc );
312 /* Check for short help option */
313 if( config_GetInt( p_vlc, "help" ) )
315 fprintf( stdout, _("Usage: %s [options] [items]...\n"),
316 p_vlc->psz_object_name );
317 Usage( p_vlc, "main" );
318 Usage( p_vlc, "help" );
321 /* Check for version option */
322 else if( config_GetInt( p_vlc, "version" ) )
328 /* Set the config file stuff */
329 p_vlc->psz_homedir = config_GetHomeDir();
330 p_vlc->psz_configfile = config_GetPsz( p_vlc, "config" );
332 /* Check for plugins cache options */
333 if( config_GetInt( p_vlc, "reset-plugins-cache" ) )
335 libvlc.p_module_bank->b_cache_delete = VLC_TRUE;
338 /* Hack: remove the help module here */
339 vlc_object_detach( p_help_module );
344 config_Free( p_help_module );
345 vlc_object_destroy( p_help_module );
346 module_EndBank( p_vlc );
347 if( i_object ) vlc_object_release( p_vlc );
351 /* Check for translation config option */
352 #if defined( ENABLE_NLS ) \
353 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
355 /* This ain't really nice to have to reload the config here but it seems
356 * the only way to do it. */
357 config_LoadConfigFile( p_vlc, "main" );
358 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
360 /* Check if the user specified a custom language */
361 psz_language = config_GetPsz( p_vlc, "language" );
362 if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
364 vlc_bool_t b_cache_delete = libvlc.p_module_bank->b_cache_delete;
366 /* Reset the default domain */
367 SetLanguage( psz_language );
369 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
370 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
372 textdomain( PACKAGE );
374 #if defined( ENABLE_UTF8 )
375 bind_textdomain_codeset( PACKAGE, "UTF-8" );
378 module_EndBank( p_vlc );
379 module_InitBank( p_vlc );
380 config_LoadConfigFile( p_vlc, "main" );
381 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
382 libvlc.p_module_bank->b_cache_delete = b_cache_delete;
384 if( psz_language ) free( psz_language );
388 * Load the builtins and plugins into the module_bank.
389 * We have to do it before config_Load*() because this also gets the
390 * list of configuration options exported by each module and loads their
393 module_LoadBuiltins( p_vlc );
394 module_LoadPlugins( p_vlc );
400 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
401 libvlc.p_module_bank->i_children );
403 /* Hack: insert the help module here */
404 vlc_object_attach( p_help_module, libvlc.p_module_bank );
407 /* Check for help on modules */
408 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
410 Usage( p_vlc, p_tmp );
414 /* Check for long help option */
415 else if( config_GetInt( p_vlc, "longhelp" ) )
417 Usage( p_vlc, NULL );
420 /* Check for module list option */
421 else if( config_GetInt( p_vlc, "list" ) )
423 ListModules( p_vlc );
427 /* Check for config file options */
428 if( config_GetInt( p_vlc, "reset-config" ) )
430 vlc_object_detach( p_help_module );
431 config_ResetAll( p_vlc );
432 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
433 config_SaveConfigFile( p_vlc, NULL );
434 vlc_object_attach( p_help_module, libvlc.p_module_bank );
436 if( config_GetInt( p_vlc, "save-config" ) )
438 vlc_object_detach( p_help_module );
439 config_LoadConfigFile( p_vlc, NULL );
440 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
441 config_SaveConfigFile( p_vlc, NULL );
442 vlc_object_attach( p_help_module, libvlc.p_module_bank );
445 /* Hack: remove the help module here */
446 vlc_object_detach( p_help_module );
451 config_Free( p_help_module );
452 vlc_object_destroy( p_help_module );
453 module_EndBank( p_vlc );
454 if( i_object ) vlc_object_release( p_vlc );
459 * Override default configuration with config file settings
461 config_LoadConfigFile( p_vlc, NULL );
463 /* Hack: insert the help module here */
464 vlc_object_attach( p_help_module, libvlc.p_module_bank );
468 * Override configuration with command line settings
470 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
474 /* Pause the console because it's destroyed when we exit */
475 fprintf( stderr, "The command line options couldn't be loaded, check "
476 "that they are valid.\nPress the RETURN key to continue..." );
479 vlc_object_detach( p_help_module );
480 config_Free( p_help_module );
481 vlc_object_destroy( p_help_module );
482 module_EndBank( p_vlc );
483 if( i_object ) vlc_object_release( p_vlc );
487 /* Hack: remove the help module here */
488 vlc_object_detach( p_help_module );
489 config_Free( p_help_module );
490 vlc_object_destroy( p_help_module );
494 * System specific configuration
496 system_Configure( p_vlc, &i_argc, ppsz_argv );
499 * Message queue options
502 var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
503 if( config_GetInt( p_vlc, "quiet" ) )
507 var_Set( p_vlc, "verbose", val );
509 var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
510 var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
512 libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
515 * Output messages that may still be in the queue
519 /* p_vlc initialization. FIXME ? */
521 #if defined( __i386__ )
522 if( !config_GetInt( p_vlc, "mmx" ) )
523 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
524 if( !config_GetInt( p_vlc, "3dn" ) )
525 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
526 if( !config_GetInt( p_vlc, "mmxext" ) )
527 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
528 if( !config_GetInt( p_vlc, "sse" ) )
529 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
530 if( !config_GetInt( p_vlc, "sse2" ) )
531 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
533 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
534 if( !config_GetInt( p_vlc, "altivec" ) )
535 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
538 #define PRINT_CAPABILITY( capability, string ) \
539 if( libvlc.i_cpu & capability ) \
541 strncat( p_capabilities, string " ", \
542 sizeof(p_capabilities) - strlen(p_capabilities) ); \
543 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
546 p_capabilities[0] = '\0';
547 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
548 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
549 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
550 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
551 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
552 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
553 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
554 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
555 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
556 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
557 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
560 * Choose the best memcpy module
562 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
564 if( p_vlc->pf_memcpy == NULL )
566 p_vlc->pf_memcpy = memcpy;
569 if( p_vlc->pf_memset == NULL )
571 p_vlc->pf_memset = memset;
574 /* Check for daemon mode */
575 if( config_GetInt( p_vlc, "daemon" ) )
578 if( ( i_pid = fork() ) < 0 )
580 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
585 /* This is the parent, exit right now */
586 msg_Dbg( p_vlc, "closing parent process" );
591 /* we are the child */
592 msg_Dbg( p_vlc, "we are the child !!!" );
597 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
598 //VLC_AddIntf( 0, "logger,none", VLC_FALSE, VLC_FALSE );
603 * Initialize hotkey handling
605 var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
606 p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
607 /* Do a copy (we don't need to modify the strings) */
608 memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
611 * Initialize playlist and get commandline files
613 p_playlist = playlist_Create( p_vlc );
616 msg_Err( p_vlc, "playlist initialization failed" );
617 if( p_vlc->p_memcpy_module != NULL )
619 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
621 module_EndBank( p_vlc );
622 if( i_object ) vlc_object_release( p_vlc );
627 * Load background interfaces
629 psz_modules = config_GetPsz( p_vlc, "extraintf" );
630 psz_parser = psz_modules;
631 while ( psz_parser && *psz_parser )
633 char *psz_module, *psz_temp;
634 psz_module = psz_parser;
635 psz_parser = strchr( psz_module, ',' );
641 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
644 sprintf( psz_temp, "%s,none", psz_module );
645 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
655 * Allways load the hotkeys interface if it exists
657 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
660 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
662 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
663 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
664 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
665 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
666 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
667 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
668 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
669 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
670 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
671 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
672 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
673 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
676 * Get input filenames given as commandline arguments
678 GetFilenames( p_vlc, i_argc, ppsz_argv );
680 if( i_object ) vlc_object_release( p_vlc );
684 /*****************************************************************************
685 * VLC_AddIntf: add an interface
686 *****************************************************************************
687 * This function opens an interface plugin and runs it. If b_block is set
688 * to 0, VLC_AddIntf will return immediately and let the interface run in a
689 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
690 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
691 * the playlist when it is completely initialised.
692 *****************************************************************************/
693 int VLC_AddIntf( int i_object, char const *psz_module,
694 vlc_bool_t b_block, vlc_bool_t b_play )
697 intf_thread_t *p_intf;
698 vlc_t *p_vlc = vlc_current_object( i_object );
705 /* Try to create the interface */
706 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
710 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
711 if( i_object ) vlc_object_release( p_vlc );
715 /* Interface doesn't handle play on start so do it ourselves */
716 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
718 /* Try to run the interface */
719 p_intf->b_play = b_play;
720 p_intf->b_block = b_block;
721 i_err = intf_RunThread( p_intf );
724 vlc_object_detach( p_intf );
725 intf_Destroy( p_intf );
726 if( i_object ) vlc_object_release( p_vlc );
730 if( i_object ) vlc_object_release( p_vlc );
734 /*****************************************************************************
735 * VLC_Die: ask vlc to die.
736 *****************************************************************************
737 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
738 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
739 *****************************************************************************/
740 int VLC_Die( int i_object )
742 vlc_t *p_vlc = vlc_current_object( i_object );
749 p_vlc->b_die = VLC_TRUE;
751 if( i_object ) vlc_object_release( p_vlc );
755 /*****************************************************************************
756 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
757 *****************************************************************************/
758 int VLC_CleanUp( int i_object )
760 intf_thread_t * p_intf;
761 playlist_t * p_playlist;
762 vout_thread_t * p_vout;
763 aout_instance_t * p_aout;
764 announce_handler_t * p_announce;
765 vlc_t *p_vlc = vlc_current_object( i_object );
767 /* Check that the handle is valid */
774 * Ask the interfaces to stop and destroy them
776 msg_Dbg( p_vlc, "removing all interfaces" );
777 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
779 intf_StopThread( p_intf );
780 vlc_object_detach( p_intf );
781 vlc_object_release( p_intf );
782 intf_Destroy( p_intf );
788 msg_Dbg( p_vlc, "removing all playlists" );
789 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
792 vlc_object_detach( p_playlist );
793 vlc_object_release( p_playlist );
794 playlist_Destroy( p_playlist );
800 msg_Dbg( p_vlc, "removing all video outputs" );
801 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
803 vlc_object_detach( p_vout );
804 vlc_object_release( p_vout );
805 vout_Destroy( p_vout );
811 msg_Dbg( p_vlc, "removing all audio outputs" );
812 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
814 vlc_object_detach( (vlc_object_t *)p_aout );
815 vlc_object_release( (vlc_object_t *)p_aout );
816 aout_Delete( p_aout );
820 * Free announce handler(s?)
822 msg_Dbg( p_vlc, "removing announce handler" );
823 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
826 vlc_object_detach( p_announce );
827 vlc_object_release( p_announce );
828 announce_HandlerDestroy( p_announce );
831 if( i_object ) vlc_object_release( p_vlc );
835 /*****************************************************************************
836 * VLC_Destroy: Destroy everything.
837 *****************************************************************************
838 * This function requests the running threads to finish, waits for their
839 * termination, and destroys their structure.
840 *****************************************************************************/
841 int VLC_Destroy( int i_object )
843 vlc_t *p_vlc = vlc_current_object( i_object );
851 * Free allocated memory
853 if( p_vlc->p_memcpy_module )
855 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
856 p_vlc->p_memcpy_module = NULL;
862 module_EndBank( p_vlc );
864 if( p_vlc->psz_homedir )
866 free( p_vlc->psz_homedir );
867 p_vlc->psz_homedir = NULL;
870 if( p_vlc->psz_configfile )
872 free( p_vlc->psz_configfile );
873 p_vlc->psz_configfile = NULL;
876 if( p_vlc->p_hotkeys )
878 free( p_vlc->p_hotkeys );
879 p_vlc->p_hotkeys = NULL;
883 * System specific cleaning code
887 /* Destroy mutexes */
888 vlc_mutex_destroy( &p_vlc->config_lock );
890 vlc_object_detach( p_vlc );
892 /* Release object before destroying it */
893 if( i_object ) vlc_object_release( p_vlc );
895 vlc_object_destroy( p_vlc );
897 /* Stop thread system: last one out please shut the door! */
898 vlc_threads_end( p_libvlc );
903 /*****************************************************************************
904 * VLC_VariableSet: set a vlc variable
905 *****************************************************************************/
906 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
908 vlc_t *p_vlc = vlc_current_object( i_object );
916 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
917 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
918 if( !strncmp( psz_var, "conf::", 6 ) )
920 module_config_t *p_item;
921 char const *psz_newvar = psz_var + 6;
923 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
927 switch( p_item->i_type )
929 case CONFIG_ITEM_BOOL:
930 config_PutInt( p_vlc, psz_newvar, value.b_bool );
932 case CONFIG_ITEM_INTEGER:
933 config_PutInt( p_vlc, psz_newvar, value.i_int );
935 case CONFIG_ITEM_FLOAT:
936 config_PutFloat( p_vlc, psz_newvar, value.f_float );
939 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
942 if( i_object ) vlc_object_release( p_vlc );
947 i_ret = var_Set( p_vlc, psz_var, value );
949 if( i_object ) vlc_object_release( p_vlc );
953 /*****************************************************************************
954 * VLC_VariableGet: get a vlc variable
955 *****************************************************************************/
956 int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
958 vlc_t *p_vlc = vlc_current_object( i_object );
966 i_ret = var_Get( p_vlc, psz_var, p_value );
968 if( i_object ) vlc_object_release( p_vlc );
972 /*****************************************************************************
973 * VLC_AddTarget: adds a target for playing.
974 *****************************************************************************
975 * This function adds psz_target to the current playlist. If a playlist does
976 * not exist, it will create one.
977 *****************************************************************************/
978 int VLC_AddTarget( int i_object, char const *psz_target,
979 char const **ppsz_options, int i_options,
980 int i_mode, int i_pos )
983 playlist_t *p_playlist;
984 vlc_t *p_vlc = vlc_current_object( i_object );
991 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
993 if( p_playlist == NULL )
995 msg_Dbg( p_vlc, "no playlist present, creating one" );
996 p_playlist = playlist_Create( p_vlc );
998 if( p_playlist == NULL )
1000 if( i_object ) vlc_object_release( p_vlc );
1001 return VLC_EGENERIC;
1004 vlc_object_yield( p_playlist );
1007 i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
1008 i_mode, i_pos, -1, ppsz_options, i_options);
1010 vlc_object_release( p_playlist );
1012 if( i_object ) vlc_object_release( p_vlc );
1016 /*****************************************************************************
1018 *****************************************************************************/
1019 int VLC_Play( int i_object )
1021 playlist_t * p_playlist;
1022 vlc_t *p_vlc = vlc_current_object( i_object );
1024 /* Check that the handle is valid */
1030 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1034 if( i_object ) vlc_object_release( p_vlc );
1038 playlist_Play( p_playlist );
1039 vlc_object_release( p_playlist );
1041 if( i_object ) vlc_object_release( p_vlc );
1045 /*****************************************************************************
1046 * VLC_Pause: toggle pause
1047 *****************************************************************************/
1048 int VLC_Pause( int i_object )
1050 playlist_t * p_playlist;
1051 vlc_t *p_vlc = vlc_current_object( i_object );
1053 /* Check that the handle is valid */
1059 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1063 if( i_object ) vlc_object_release( p_vlc );
1067 playlist_Pause( p_playlist );
1068 vlc_object_release( p_playlist );
1070 if( i_object ) vlc_object_release( p_vlc );
1074 /*****************************************************************************
1075 * VLC_Pause: toggle pause
1076 *****************************************************************************/
1077 int VLC_Stop( int i_object )
1079 playlist_t * p_playlist;
1080 vlc_t *p_vlc = vlc_current_object( i_object );
1082 /* Check that the handle is valid */
1088 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1092 if( i_object ) vlc_object_release( p_vlc );
1096 playlist_Stop( p_playlist );
1097 vlc_object_release( p_playlist );
1099 if( i_object ) vlc_object_release( p_vlc );
1103 /*****************************************************************************
1104 * VLC_IsPlaying: Query for Playlist Status
1105 *****************************************************************************/
1106 vlc_bool_t VLC_IsPlaying( int i_object )
1108 playlist_t * p_playlist;
1109 vlc_bool_t b_playing;
1111 vlc_t *p_vlc = vlc_current_object( i_object );
1113 /* Check that the handle is valid */
1119 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1123 if( i_object ) vlc_object_release( p_vlc );
1127 b_playing = playlist_IsPlaying( p_playlist );
1128 vlc_object_release( p_playlist );
1130 if( i_object ) vlc_object_release( p_vlc );
1135 * Get the current position in a input
1137 * Return the current position as a float
1138 * \note For some inputs, this will be unknown.
1140 * \param i_object a vlc object id
1141 * \return a float in the range of 0.0 - 1.0
1143 float VLC_PositionGet( int i_object )
1145 input_thread_t *p_input;
1147 vlc_t *p_vlc = vlc_current_object( i_object );
1149 /* Check that the handle is valid */
1155 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1159 if( i_object ) vlc_object_release( p_vlc );
1163 var_Get( p_input, "position", &val );
1164 vlc_object_release( p_input );
1166 if( i_object ) vlc_object_release( p_vlc );
1171 * Set the current position in a input
1173 * Set the current position in a input and then return
1174 * the current position as a float.
1175 * \note For some inputs, this will be unknown.
1177 * \param i_object a vlc object id
1178 * \param i_position a float in the range of 0.0 - 1.0
1179 * \return a float in the range of 0.0 - 1.0
1181 float VLC_PositionSet( int i_object, float i_position )
1183 input_thread_t *p_input;
1185 vlc_t *p_vlc = vlc_current_object( i_object );
1187 /* Check that the handle is valid */
1193 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1197 if( i_object ) vlc_object_release( p_vlc );
1201 val.f_float = i_position;
1202 var_Set( p_input, "position", val );
1203 var_Get( p_input, "position", &val );
1204 vlc_object_release( p_input );
1206 if( i_object ) vlc_object_release( p_vlc );
1211 * Get the current position in a input
1213 * Return the current position in seconds from the start.
1214 * \note For some inputs, this will be unknown.
1216 * \param i_object a vlc object id
1217 * \return the offset from 0:00 in seconds
1219 int VLC_TimeGet( int i_object )
1221 input_thread_t *p_input;
1223 vlc_t *p_vlc = vlc_current_object( i_object );
1225 /* Check that the handle is valid */
1231 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1235 if( i_object ) vlc_object_release( p_vlc );
1239 var_Get( p_input, "time", &val );
1240 vlc_object_release( p_input );
1242 if( i_object ) vlc_object_release( p_vlc );
1243 return val.i_time / 1000000;
1247 * Seek to a position in the current input
1249 * Seek i_seconds in the current input. If b_relative is set,
1250 * then the seek will be relative to the current position, otherwise
1251 * it will seek to i_seconds from the beginning of the input.
1252 * \note For some inputs, this will be unknown.
1254 * \param i_object a vlc object id
1255 * \param i_seconds seconds from current position or from beginning of input
1256 * \param b_relative seek relative from current position
1257 * \return VLC_SUCCESS on success
1259 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1261 input_thread_t *p_input;
1263 vlc_t *p_vlc = vlc_current_object( i_object );
1265 /* Check that the handle is valid */
1271 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1275 if( i_object ) vlc_object_release( p_vlc );
1281 val.i_time = i_seconds * 1000000;
1282 var_Set( p_input, "time-offset", val );
1286 val.i_time = i_seconds * 1000000;
1287 var_Set( p_input, "time", val );
1289 vlc_object_release( p_input );
1291 if( i_object ) vlc_object_release( p_vlc );
1296 * Get the total length of a input
1298 * Return the total length in seconds from the current input.
1299 * \note For some inputs, this will be unknown.
1301 * \param i_object a vlc object id
1302 * \return the length in seconds
1304 int VLC_LengthGet( int i_object )
1306 input_thread_t *p_input;
1308 vlc_t *p_vlc = vlc_current_object( i_object );
1310 /* Check that the handle is valid */
1316 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1320 if( i_object ) vlc_object_release( p_vlc );
1324 var_Get( p_input, "length", &val );
1325 vlc_object_release( p_input );
1327 if( i_object ) vlc_object_release( p_vlc );
1328 return val.i_time / 1000000;
1332 * Play the input faster than realtime
1334 * 2x, 4x, 8x faster than realtime
1335 * \note For some inputs, this will be impossible.
1337 * \param i_object a vlc object id
1338 * \return the current speedrate
1340 float VLC_SpeedFaster( int i_object )
1342 input_thread_t *p_input;
1344 vlc_t *p_vlc = vlc_current_object( i_object );
1346 /* Check that the handle is valid */
1352 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1356 if( i_object ) vlc_object_release( p_vlc );
1360 val.b_bool = VLC_TRUE;
1361 var_Set( p_input, "rate-faster", val );
1362 var_Get( p_input, "rate", &val );
1363 vlc_object_release( p_input );
1365 if( i_object ) vlc_object_release( p_vlc );
1366 return val.f_float / INPUT_RATE_DEFAULT;
1370 * Play the input slower than realtime
1372 * 1/2x, 1/4x, 1/8x slower than realtime
1373 * \note For some inputs, this will be impossible.
1375 * \param i_object a vlc object id
1376 * \return the current speedrate
1378 float VLC_SpeedSlower( int i_object )
1380 input_thread_t *p_input;
1382 vlc_t *p_vlc = vlc_current_object( i_object );
1384 /* Check that the handle is valid */
1390 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1394 if( i_object ) vlc_object_release( p_vlc );
1398 val.b_bool = VLC_TRUE;
1399 var_Set( p_input, "rate-slower", val );
1400 var_Get( p_input, "rate", &val );
1401 vlc_object_release( p_input );
1403 if( i_object ) vlc_object_release( p_vlc );
1404 return val.f_float / INPUT_RATE_DEFAULT;
1408 * Return the current playlist item
1410 * Returns the index of the playlistitem that is currently selected for play.
1411 * This is valid even if nothing is currently playing.
1413 * \param i_object a vlc object id
1414 * \return the current index
1416 int VLC_PlaylistIndex( int i_object )
1419 playlist_t * p_playlist;
1420 vlc_t *p_vlc = vlc_current_object( i_object );
1422 /* Check that the handle is valid */
1428 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1432 if( i_object ) vlc_object_release( p_vlc );
1436 i_index = p_playlist->i_index;
1437 vlc_object_release( p_playlist );
1439 if( i_object ) vlc_object_release( p_vlc );
1444 * Total amount of items in the playlist
1446 * \param i_object a vlc object id
1447 * \return amount of playlist items
1449 int VLC_PlaylistNumberOfItems( int i_object )
1452 playlist_t * p_playlist;
1453 vlc_t *p_vlc = vlc_current_object( i_object );
1455 /* Check that the handle is valid */
1461 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1465 if( i_object ) vlc_object_release( p_vlc );
1469 i_size = p_playlist->i_size;
1470 vlc_object_release( p_playlist );
1472 if( i_object ) vlc_object_release( p_vlc );
1477 * Next playlist item
1479 * Skip to the next playlistitem and play it.
1481 * \param i_object a vlc object id
1482 * \return VLC_SUCCESS on success
1484 int VLC_PlaylistNext( int i_object )
1486 playlist_t * p_playlist;
1487 vlc_t *p_vlc = vlc_current_object( i_object );
1489 /* Check that the handle is valid */
1495 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1499 if( i_object ) vlc_object_release( p_vlc );
1503 playlist_Next( p_playlist );
1504 vlc_object_release( p_playlist );
1506 if( i_object ) vlc_object_release( p_vlc );
1511 * Previous playlist item
1513 * Skip to the previous playlistitem and play it.
1515 * \param i_object a vlc object id
1516 * \return VLC_SUCCESS on success
1518 int VLC_PlaylistPrev( int i_object )
1520 playlist_t * p_playlist;
1521 vlc_t *p_vlc = vlc_current_object( i_object );
1523 /* Check that the handle is valid */
1529 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1533 if( i_object ) vlc_object_release( p_vlc );
1537 playlist_Prev( p_playlist );
1538 vlc_object_release( p_playlist );
1540 if( i_object ) vlc_object_release( p_vlc );
1545 /*****************************************************************************
1546 * VLC_PlaylistClear: Empty the playlist
1547 *****************************************************************************/
1548 int VLC_PlaylistClear( int i_object )
1551 playlist_t * p_playlist;
1552 vlc_t *p_vlc = vlc_current_object( i_object );
1554 /* Check that the handle is valid */
1560 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1564 if( i_object ) vlc_object_release( p_vlc );
1568 i_err = playlist_Clear( p_playlist );
1570 vlc_object_release( p_playlist );
1572 if( i_object ) vlc_object_release( p_vlc );
1579 * \param i_object a vlc object id
1580 * \param i_volume something in a range from 0-200
1581 * \return the new volume (range 0-200 %)
1583 int VLC_VolumeSet( int i_object, int i_volume )
1585 audio_volume_t i_vol = 0;
1586 vlc_t *p_vlc = vlc_current_object( i_object );
1588 /* Check that the handle is valid */
1594 if( i_volume >= 0 && i_volume <= 200 )
1596 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1597 aout_VolumeSet( p_vlc, i_vol );
1600 if( i_object ) vlc_object_release( p_vlc );
1601 return i_vol * 200 / AOUT_VOLUME_MAX;
1605 * Get the current volume
1607 * Retrieve the current volume.
1609 * \param i_object a vlc object id
1610 * \return the current volume (range 0-200 %)
1612 int VLC_VolumeGet( int i_object )
1614 audio_volume_t i_volume;
1615 vlc_t *p_vlc = vlc_current_object( i_object );
1617 /* Check that the handle is valid */
1623 aout_VolumeGet( p_vlc, &i_volume );
1625 if( i_object ) vlc_object_release( p_vlc );
1626 return i_volume*200/AOUT_VOLUME_MAX;
1630 * Mute/Unmute the volume
1632 * \param i_object a vlc object id
1633 * \return VLC_SUCCESS on success
1635 int VLC_VolumeMute( int i_object )
1637 vlc_t *p_vlc = vlc_current_object( i_object );
1639 /* Check that the handle is valid */
1645 aout_VolumeMute( p_vlc, NULL );
1647 if( i_object ) vlc_object_release( p_vlc );
1651 /*****************************************************************************
1652 * VLC_FullScreen: toggle fullscreen mode
1653 *****************************************************************************/
1654 int VLC_FullScreen( int i_object )
1656 vout_thread_t *p_vout;
1657 vlc_t *p_vlc = vlc_current_object( i_object );
1664 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1668 if( i_object ) vlc_object_release( p_vlc );
1672 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1673 vlc_object_release( p_vout );
1675 if( i_object ) vlc_object_release( p_vlc );
1679 /* following functions are local */
1681 /*****************************************************************************
1682 * SetLanguage: set the interface language.
1683 *****************************************************************************
1684 * We set the LC_MESSAGES locale category for interface messages and buttons,
1685 * as well as the LC_CTYPE category for string sorting and possible wide
1686 * character support.
1687 *****************************************************************************/
1688 static void SetLanguage ( char const *psz_lang )
1690 #if defined( ENABLE_NLS ) \
1691 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1694 #if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
1698 if( psz_lang && !*psz_lang )
1700 # if defined( HAVE_LC_MESSAGES )
1701 setlocale( LC_MESSAGES, psz_lang );
1703 setlocale( LC_CTYPE, psz_lang );
1708 /* I need that under Darwin, please check it doesn't disturb
1709 * other platforms. --Meuuh */
1710 setenv( "LANG", psz_lang, 1 );
1712 #elif defined( SYS_BEOS ) || defined( WIN32 )
1713 /* We set LC_ALL manually because it is the only way to set
1714 * the language at runtime under eg. Windows. Beware that this
1715 * makes the environment unconsistent when libvlc is unloaded and
1716 * should probably be moved to a safer place like vlc.c. */
1717 static char psz_lcall[20];
1718 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1719 psz_lcall[19] = '\0';
1720 putenv( psz_lcall );
1723 setlocale( LC_ALL, psz_lang );
1726 /* Specify where to find the locales for current domain */
1727 #if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1728 psz_path = LOCALEDIR;
1730 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1734 if( !bindtextdomain( PACKAGE, psz_path ) )
1736 fprintf( stderr, "warning: no domain %s in directory %s\n",
1737 PACKAGE, psz_path );
1740 /* Set the default domain */
1741 textdomain( PACKAGE );
1743 #if defined( ENABLE_UTF8 )
1744 bind_textdomain_codeset( PACKAGE, "UTF-8" );
1750 /*****************************************************************************
1751 * GetFilenames: parse command line options which are not flags
1752 *****************************************************************************
1753 * Parse command line for input files as well as their associated options.
1754 * An option always follows its associated input and begins with a ":".
1755 *****************************************************************************/
1756 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1758 int i_opt, i_options;
1760 /* We assume that the remaining parameters are filenames
1761 * and their input options */
1762 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
1766 /* Count the input options */
1767 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
1773 /* TODO: write an internal function of this one, to avoid
1774 * unnecessary lookups. */
1775 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1776 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
1778 PLAYLIST_INSERT, 0 );
1784 /*****************************************************************************
1785 * Usage: print program usage
1786 *****************************************************************************
1787 * Print a short inline help. Message interface is initialized at this stage.
1788 *****************************************************************************/
1789 static void Usage( vlc_t *p_this, char const *psz_module_name )
1791 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1792 /* short option ------' | | | | | | |
1793 * option name ------------' | | | | | |
1794 * <bra -------------------------' | | | | |
1795 * option type or "" --------------' | | | |
1796 * ket> -----------------------------' | | |
1797 * padding spaces ---------------------' | |
1798 * comment -------------------------------' |
1799 * comment suffix --------------------------'
1801 * The purpose of having bra and ket is that we might i18n them as well.
1803 #define LINE_START 8
1804 #define PADDING_SPACES 25
1807 module_config_t *p_item;
1808 char psz_spaces[PADDING_SPACES+LINE_START+1];
1809 char psz_format[sizeof(FORMAT_STRING)];
1810 char psz_buffer[1000];
1813 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1814 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
1816 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1817 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1819 strcpy( psz_format, FORMAT_STRING );
1825 /* List all modules */
1826 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1828 /* Enumerate the config for each module */
1829 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1831 vlc_bool_t b_help_module;
1833 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1835 if( psz_module_name && strcmp( psz_module_name,
1836 p_parser->psz_object_name ) )
1841 /* Ignore modules without config options */
1842 if( !p_parser->i_config_items )
1847 /* Ignore modules with only advanced config options if requested */
1850 for( p_item = p_parser->p_config;
1851 p_item->i_type != CONFIG_HINT_END;
1854 if( (p_item->i_type & CONFIG_ITEM) &&
1855 !p_item->b_advanced ) break;
1857 if( p_item->i_type == CONFIG_HINT_END ) continue;
1860 /* Print name of module */
1861 if( strcmp( "main", p_parser->psz_object_name ) )
1862 fprintf( stdout, "\n %s\n", p_parser->psz_longname );
1864 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1866 /* Print module options */
1867 for( p_item = p_parser->p_config;
1868 p_item->i_type != CONFIG_HINT_END;
1872 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1873 char *psz_suf = "", *psz_prefix = NULL;
1876 /* Skip advanced options if requested */
1877 if( p_item->b_advanced && !b_advanced )
1882 switch( p_item->i_type )
1884 case CONFIG_HINT_CATEGORY:
1885 case CONFIG_HINT_USAGE:
1886 if( !strcmp( "main", p_parser->psz_object_name ) )
1887 fprintf( stdout, "\n %s\n", p_item->psz_text );
1890 case CONFIG_ITEM_STRING:
1891 case CONFIG_ITEM_FILE:
1892 case CONFIG_ITEM_DIRECTORY:
1893 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1894 if( !p_item->ppsz_list )
1896 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1902 psz_type = psz_buffer;
1904 for( i = 0; p_item->ppsz_list[i]; i++ )
1906 if( i ) strcat( psz_type, "," );
1907 strcat( psz_type, p_item->ppsz_list[i] );
1912 case CONFIG_ITEM_INTEGER:
1913 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
1914 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1916 case CONFIG_ITEM_FLOAT:
1917 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1919 case CONFIG_ITEM_BOOL:
1920 psz_bra = ""; psz_type = ""; psz_ket = "";
1921 if( !b_help_module )
1923 psz_suf = p_item->i_value ? _(" (default enabled)") :
1924 _(" (default disabled)");
1934 /* Add short option if any */
1935 if( p_item->i_short )
1937 sprintf( psz_short, "-%c,", p_item->i_short );
1941 strcpy( psz_short, " " );
1944 i = PADDING_SPACES - strlen( p_item->psz_name )
1945 - strlen( psz_bra ) - strlen( psz_type )
1946 - strlen( psz_ket ) - 1;
1948 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1950 /* If option is of type --foo-bar, we print its counterpart
1951 * as --no-foo-bar, but if it is of type --foobar (without
1952 * dashes in the name) we print it as --nofoobar. Both
1953 * values are of course valid, only the display changes. */
1954 psz_prefix = strchr( p_item->psz_name, '-' ) ? ", --no-"
1956 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
1961 psz_spaces[0] = '\n';
1966 psz_spaces[i] = '\0';
1969 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1971 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1972 psz_prefix, p_item->psz_name, psz_bra, psz_type,
1973 psz_ket, psz_spaces );
1977 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1978 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
1981 psz_spaces[i] = ' ';
1983 /* We wrap the rest of the output */
1984 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
1985 psz_text = psz_buffer;
1988 char *psz_parser, *psz_word;
1989 int i_end = strlen( psz_text );
1991 /* If the remaining text fits in a line, print it. */
1992 if( i_end <= i_width )
1994 fprintf( stdout, "%s\n", psz_text );
1998 /* Otherwise, eat as many words as possible */
1999 psz_parser = psz_text;
2002 psz_word = psz_parser;
2003 psz_parser = strchr( psz_word, ' ' );
2004 /* If no space was found, we reached the end of the text
2005 * block; otherwise, we skip the space we just found. */
2006 psz_parser = psz_parser ? psz_parser + 1
2009 } while( psz_parser - psz_text <= i_width );
2011 /* We cut a word in one of these cases:
2012 * - it's the only word in the line and it's too long.
2013 * - we used less than 80% of the width and the word we are
2014 * going to wrap is longer than 40% of the width, and even
2015 * if the word would have fit in the next line. */
2016 if( psz_word == psz_text
2017 || ( psz_word - psz_text < 80 * i_width / 100
2018 && psz_parser - psz_word > 40 * i_width / 100 ) )
2020 char c = psz_text[i_width];
2021 psz_text[i_width] = '\0';
2022 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2023 psz_text += i_width;
2028 psz_word[-1] = '\0';
2029 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2030 psz_text = psz_word;
2036 /* Release the module list */
2037 vlc_list_release( p_list );
2039 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2040 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2045 /*****************************************************************************
2046 * ListModules: list the available modules with their description
2047 *****************************************************************************
2048 * Print a list of all available modules (builtins and plugins) and a short
2049 * description for each one.
2050 *****************************************************************************/
2051 static void ListModules( vlc_t *p_this )
2055 char psz_spaces[22];
2058 memset( psz_spaces, ' ', 22 );
2065 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
2066 p_this->p_vlc->psz_object_name );
2068 fprintf( stdout, _("[module] [description]\n") );
2070 /* List all modules */
2071 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2073 /* Enumerate each module */
2074 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2078 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2080 /* Nasty hack, but right now I'm too tired to think about a nice
2082 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2086 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2087 psz_spaces, p_parser->psz_longname );
2089 psz_spaces[i] = ' ';
2092 vlc_list_release( p_list );
2094 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2095 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2100 /*****************************************************************************
2101 * Version: print complete program version
2102 *****************************************************************************
2103 * Print complete program version and build number.
2104 *****************************************************************************/
2105 static void Version( void )
2111 fprintf( stdout, VERSION_MESSAGE "\n" );
2113 _("This program comes with NO WARRANTY, to the extent permitted by "
2114 "law.\nYou may redistribute it under the terms of the GNU General "
2115 "Public License;\nsee the file named COPYING for details.\n"
2116 "Written by the VideoLAN team; see the AUTHORS file.\n") );
2118 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2119 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2124 /*****************************************************************************
2125 * ShowConsole: On Win32, create an output console for debug messages
2126 *****************************************************************************
2127 * This function is useful only on Win32.
2128 *****************************************************************************/
2130 static void ShowConsole( void )
2134 freopen( "CONOUT$", "w", stdout );
2135 freopen( "CONOUT$", "w", stderr );
2136 freopen( "CONIN$", "r", stdin );
2142 /*****************************************************************************
2143 * ConsoleWidth: Return the console width in characters
2144 *****************************************************************************
2145 * We use the stty shell command to get the console width; if this fails or
2146 * if the width is less than 80, we default to 80.
2147 *****************************************************************************/
2148 static int ConsoleWidth( void )
2153 char buf[20], *psz_parser;
2157 file = popen( "stty size 2>/dev/null", "r" );
2160 i_ret = fread( buf, 1, 20, file );
2164 psz_parser = strchr( buf, ' ' );
2167 i_ret = atoi( psz_parser + 1 );
2182 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2183 vlc_value_t old_val, vlc_value_t new_val, void *param)
2185 vlc_t *p_vlc = (vlc_t *)p_this;
2187 if( new_val.i_int >= -1 )
2189 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );