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 var_Create( p_vlc, "interface", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
599 var_SetString( p_vlc, "interface", "dummy" );
600 VLC_AddIntf( 0, "logger,none", VLC_FALSE, VLC_FALSE );
605 * Initialize hotkey handling
607 var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
608 p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
609 /* Do a copy (we don't need to modify the strings) */
610 memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
613 * Initialize playlist and get commandline files
615 p_playlist = playlist_Create( p_vlc );
618 msg_Err( p_vlc, "playlist initialization failed" );
619 if( p_vlc->p_memcpy_module != NULL )
621 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
623 module_EndBank( p_vlc );
624 if( i_object ) vlc_object_release( p_vlc );
629 * Load background interfaces
631 psz_modules = config_GetPsz( p_vlc, "extraintf" );
632 psz_parser = psz_modules;
633 while ( psz_parser && *psz_parser )
635 char *psz_module, *psz_temp;
636 psz_module = psz_parser;
637 psz_parser = strchr( psz_module, ',' );
643 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
646 sprintf( psz_temp, "%s,none", psz_module );
647 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
657 * Allways load the hotkeys interface if it exists
659 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
662 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
664 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
665 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
666 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
667 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
668 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
669 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
670 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
671 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
672 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
673 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
674 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
675 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
678 * Get input filenames given as commandline arguments
680 GetFilenames( p_vlc, i_argc, ppsz_argv );
682 if( i_object ) vlc_object_release( p_vlc );
686 /*****************************************************************************
687 * VLC_AddIntf: add an interface
688 *****************************************************************************
689 * This function opens an interface plugin and runs it. If b_block is set
690 * to 0, VLC_AddIntf will return immediately and let the interface run in a
691 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
692 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
693 * the playlist when it is completely initialised.
694 *****************************************************************************/
695 int VLC_AddIntf( int i_object, char const *psz_module,
696 vlc_bool_t b_block, vlc_bool_t b_play )
699 intf_thread_t *p_intf;
700 vlc_t *p_vlc = vlc_current_object( i_object );
707 /* Try to create the interface */
708 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
712 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
713 if( i_object ) vlc_object_release( p_vlc );
717 /* Interface doesn't handle play on start so do it ourselves */
718 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
720 /* Try to run the interface */
721 p_intf->b_play = b_play;
722 p_intf->b_block = b_block;
723 i_err = intf_RunThread( p_intf );
726 vlc_object_detach( p_intf );
727 intf_Destroy( p_intf );
728 if( i_object ) vlc_object_release( p_vlc );
732 if( i_object ) vlc_object_release( p_vlc );
736 /*****************************************************************************
737 * VLC_Die: ask vlc to die.
738 *****************************************************************************
739 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
740 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
741 *****************************************************************************/
742 int VLC_Die( int i_object )
744 vlc_t *p_vlc = vlc_current_object( i_object );
751 p_vlc->b_die = VLC_TRUE;
753 if( i_object ) vlc_object_release( p_vlc );
757 /*****************************************************************************
758 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
759 *****************************************************************************/
760 int VLC_CleanUp( int i_object )
762 intf_thread_t * p_intf;
763 playlist_t * p_playlist;
764 vout_thread_t * p_vout;
765 aout_instance_t * p_aout;
766 announce_handler_t * p_announce;
767 vlc_t *p_vlc = vlc_current_object( i_object );
769 /* Check that the handle is valid */
776 * Ask the interfaces to stop and destroy them
778 msg_Dbg( p_vlc, "removing all interfaces" );
779 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
781 intf_StopThread( p_intf );
782 vlc_object_detach( p_intf );
783 vlc_object_release( p_intf );
784 intf_Destroy( p_intf );
790 msg_Dbg( p_vlc, "removing all playlists" );
791 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
794 vlc_object_detach( p_playlist );
795 vlc_object_release( p_playlist );
796 playlist_Destroy( p_playlist );
802 msg_Dbg( p_vlc, "removing all video outputs" );
803 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
805 vlc_object_detach( p_vout );
806 vlc_object_release( p_vout );
807 vout_Destroy( p_vout );
813 msg_Dbg( p_vlc, "removing all audio outputs" );
814 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
816 vlc_object_detach( (vlc_object_t *)p_aout );
817 vlc_object_release( (vlc_object_t *)p_aout );
818 aout_Delete( p_aout );
822 * Free announce handler(s?)
824 msg_Dbg( p_vlc, "removing announce handler" );
825 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
828 vlc_object_detach( p_announce );
829 vlc_object_release( p_announce );
830 announce_HandlerDestroy( p_announce );
833 if( i_object ) vlc_object_release( p_vlc );
837 /*****************************************************************************
838 * VLC_Destroy: Destroy everything.
839 *****************************************************************************
840 * This function requests the running threads to finish, waits for their
841 * termination, and destroys their structure.
842 *****************************************************************************/
843 int VLC_Destroy( int i_object )
845 vlc_t *p_vlc = vlc_current_object( i_object );
853 * Free allocated memory
855 if( p_vlc->p_memcpy_module )
857 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
858 p_vlc->p_memcpy_module = NULL;
864 module_EndBank( p_vlc );
866 if( p_vlc->psz_homedir )
868 free( p_vlc->psz_homedir );
869 p_vlc->psz_homedir = NULL;
872 if( p_vlc->psz_configfile )
874 free( p_vlc->psz_configfile );
875 p_vlc->psz_configfile = NULL;
878 if( p_vlc->p_hotkeys )
880 free( p_vlc->p_hotkeys );
881 p_vlc->p_hotkeys = NULL;
885 * System specific cleaning code
889 /* Destroy mutexes */
890 vlc_mutex_destroy( &p_vlc->config_lock );
892 vlc_object_detach( p_vlc );
894 /* Release object before destroying it */
895 if( i_object ) vlc_object_release( p_vlc );
897 vlc_object_destroy( p_vlc );
899 /* Stop thread system: last one out please shut the door! */
900 vlc_threads_end( p_libvlc );
905 /*****************************************************************************
906 * VLC_VariableSet: set a vlc variable
907 *****************************************************************************/
908 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
910 vlc_t *p_vlc = vlc_current_object( i_object );
918 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
919 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
920 if( !strncmp( psz_var, "conf::", 6 ) )
922 module_config_t *p_item;
923 char const *psz_newvar = psz_var + 6;
925 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
929 switch( p_item->i_type )
931 case CONFIG_ITEM_BOOL:
932 config_PutInt( p_vlc, psz_newvar, value.b_bool );
934 case CONFIG_ITEM_INTEGER:
935 config_PutInt( p_vlc, psz_newvar, value.i_int );
937 case CONFIG_ITEM_FLOAT:
938 config_PutFloat( p_vlc, psz_newvar, value.f_float );
941 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
944 if( i_object ) vlc_object_release( p_vlc );
949 i_ret = var_Set( p_vlc, psz_var, value );
951 if( i_object ) vlc_object_release( p_vlc );
955 /*****************************************************************************
956 * VLC_VariableGet: get a vlc variable
957 *****************************************************************************/
958 int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
960 vlc_t *p_vlc = vlc_current_object( i_object );
968 i_ret = var_Get( p_vlc, psz_var, p_value );
970 if( i_object ) vlc_object_release( p_vlc );
974 /*****************************************************************************
975 * VLC_AddTarget: adds a target for playing.
976 *****************************************************************************
977 * This function adds psz_target to the current playlist. If a playlist does
978 * not exist, it will create one.
979 *****************************************************************************/
980 int VLC_AddTarget( int i_object, char const *psz_target,
981 char const **ppsz_options, int i_options,
982 int i_mode, int i_pos )
985 playlist_t *p_playlist;
986 vlc_t *p_vlc = vlc_current_object( i_object );
993 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
995 if( p_playlist == NULL )
997 msg_Dbg( p_vlc, "no playlist present, creating one" );
998 p_playlist = playlist_Create( p_vlc );
1000 if( p_playlist == NULL )
1002 if( i_object ) vlc_object_release( p_vlc );
1003 return VLC_EGENERIC;
1006 vlc_object_yield( p_playlist );
1009 i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
1010 i_mode, i_pos, -1, ppsz_options, i_options);
1012 vlc_object_release( p_playlist );
1014 if( i_object ) vlc_object_release( p_vlc );
1018 /*****************************************************************************
1020 *****************************************************************************/
1021 int VLC_Play( int i_object )
1023 playlist_t * p_playlist;
1024 vlc_t *p_vlc = vlc_current_object( i_object );
1026 /* Check that the handle is valid */
1032 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1036 if( i_object ) vlc_object_release( p_vlc );
1040 playlist_Play( p_playlist );
1041 vlc_object_release( p_playlist );
1043 if( i_object ) vlc_object_release( p_vlc );
1047 /*****************************************************************************
1048 * VLC_Pause: toggle pause
1049 *****************************************************************************/
1050 int VLC_Pause( int i_object )
1052 playlist_t * p_playlist;
1053 vlc_t *p_vlc = vlc_current_object( i_object );
1055 /* Check that the handle is valid */
1061 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1065 if( i_object ) vlc_object_release( p_vlc );
1069 playlist_Pause( p_playlist );
1070 vlc_object_release( p_playlist );
1072 if( i_object ) vlc_object_release( p_vlc );
1076 /*****************************************************************************
1077 * VLC_Pause: toggle pause
1078 *****************************************************************************/
1079 int VLC_Stop( int i_object )
1081 playlist_t * p_playlist;
1082 vlc_t *p_vlc = vlc_current_object( i_object );
1084 /* Check that the handle is valid */
1090 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1094 if( i_object ) vlc_object_release( p_vlc );
1098 playlist_Stop( p_playlist );
1099 vlc_object_release( p_playlist );
1101 if( i_object ) vlc_object_release( p_vlc );
1105 /*****************************************************************************
1106 * VLC_IsPlaying: Query for Playlist Status
1107 *****************************************************************************/
1108 vlc_bool_t VLC_IsPlaying( int i_object )
1110 playlist_t * p_playlist;
1111 vlc_bool_t b_playing;
1113 vlc_t *p_vlc = vlc_current_object( i_object );
1115 /* Check that the handle is valid */
1121 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1125 if( i_object ) vlc_object_release( p_vlc );
1129 b_playing = playlist_IsPlaying( p_playlist );
1130 vlc_object_release( p_playlist );
1132 if( i_object ) vlc_object_release( p_vlc );
1137 * Get the current position in a input
1139 * Return the current position as a float
1140 * \note For some inputs, this will be unknown.
1142 * \param i_object a vlc object id
1143 * \return a float in the range of 0.0 - 1.0
1145 float VLC_PositionGet( int i_object )
1147 input_thread_t *p_input;
1149 vlc_t *p_vlc = vlc_current_object( i_object );
1151 /* Check that the handle is valid */
1157 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1161 if( i_object ) vlc_object_release( p_vlc );
1165 var_Get( p_input, "position", &val );
1166 vlc_object_release( p_input );
1168 if( i_object ) vlc_object_release( p_vlc );
1173 * Set the current position in a input
1175 * Set the current position in a input and then return
1176 * the current position as a float.
1177 * \note For some inputs, this will be unknown.
1179 * \param i_object a vlc object id
1180 * \param i_position a float in the range of 0.0 - 1.0
1181 * \return a float in the range of 0.0 - 1.0
1183 float VLC_PositionSet( int i_object, float i_position )
1185 input_thread_t *p_input;
1187 vlc_t *p_vlc = vlc_current_object( i_object );
1189 /* Check that the handle is valid */
1195 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1199 if( i_object ) vlc_object_release( p_vlc );
1203 val.f_float = i_position;
1204 var_Set( p_input, "position", val );
1205 var_Get( p_input, "position", &val );
1206 vlc_object_release( p_input );
1208 if( i_object ) vlc_object_release( p_vlc );
1213 * Get the current position in a input
1215 * Return the current position in seconds from the start.
1216 * \note For some inputs, this will be unknown.
1218 * \param i_object a vlc object id
1219 * \return the offset from 0:00 in seconds
1221 int VLC_TimeGet( int i_object )
1223 input_thread_t *p_input;
1225 vlc_t *p_vlc = vlc_current_object( i_object );
1227 /* Check that the handle is valid */
1233 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1237 if( i_object ) vlc_object_release( p_vlc );
1241 var_Get( p_input, "time", &val );
1242 vlc_object_release( p_input );
1244 if( i_object ) vlc_object_release( p_vlc );
1245 return val.i_time / 1000000;
1249 * Seek to a position in the current input
1251 * Seek i_seconds in the current input. If b_relative is set,
1252 * then the seek will be relative to the current position, otherwise
1253 * it will seek to i_seconds from the beginning of the input.
1254 * \note For some inputs, this will be unknown.
1256 * \param i_object a vlc object id
1257 * \param i_seconds seconds from current position or from beginning of input
1258 * \param b_relative seek relative from current position
1259 * \return VLC_SUCCESS on success
1261 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1263 input_thread_t *p_input;
1265 vlc_t *p_vlc = vlc_current_object( i_object );
1267 /* Check that the handle is valid */
1273 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1277 if( i_object ) vlc_object_release( p_vlc );
1283 val.i_time = i_seconds * 1000000;
1284 var_Set( p_input, "time-offset", val );
1288 val.i_time = i_seconds * 1000000;
1289 var_Set( p_input, "time", val );
1291 vlc_object_release( p_input );
1293 if( i_object ) vlc_object_release( p_vlc );
1298 * Get the total length of a input
1300 * Return the total length in seconds from the current input.
1301 * \note For some inputs, this will be unknown.
1303 * \param i_object a vlc object id
1304 * \return the length in seconds
1306 int VLC_LengthGet( int i_object )
1308 input_thread_t *p_input;
1310 vlc_t *p_vlc = vlc_current_object( i_object );
1312 /* Check that the handle is valid */
1318 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1322 if( i_object ) vlc_object_release( p_vlc );
1326 var_Get( p_input, "length", &val );
1327 vlc_object_release( p_input );
1329 if( i_object ) vlc_object_release( p_vlc );
1330 return val.i_time / 1000000;
1334 * Play the input faster than realtime
1336 * 2x, 4x, 8x faster than realtime
1337 * \note For some inputs, this will be impossible.
1339 * \param i_object a vlc object id
1340 * \return the current speedrate
1342 float VLC_SpeedFaster( int i_object )
1344 input_thread_t *p_input;
1346 vlc_t *p_vlc = vlc_current_object( i_object );
1348 /* Check that the handle is valid */
1354 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1358 if( i_object ) vlc_object_release( p_vlc );
1362 val.b_bool = VLC_TRUE;
1363 var_Set( p_input, "rate-faster", val );
1364 var_Get( p_input, "rate", &val );
1365 vlc_object_release( p_input );
1367 if( i_object ) vlc_object_release( p_vlc );
1368 return val.f_float / INPUT_RATE_DEFAULT;
1372 * Play the input slower than realtime
1374 * 1/2x, 1/4x, 1/8x slower than realtime
1375 * \note For some inputs, this will be impossible.
1377 * \param i_object a vlc object id
1378 * \return the current speedrate
1380 float VLC_SpeedSlower( int i_object )
1382 input_thread_t *p_input;
1384 vlc_t *p_vlc = vlc_current_object( i_object );
1386 /* Check that the handle is valid */
1392 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1396 if( i_object ) vlc_object_release( p_vlc );
1400 val.b_bool = VLC_TRUE;
1401 var_Set( p_input, "rate-slower", val );
1402 var_Get( p_input, "rate", &val );
1403 vlc_object_release( p_input );
1405 if( i_object ) vlc_object_release( p_vlc );
1406 return val.f_float / INPUT_RATE_DEFAULT;
1410 * Return the current playlist item
1412 * Returns the index of the playlistitem that is currently selected for play.
1413 * This is valid even if nothing is currently playing.
1415 * \param i_object a vlc object id
1416 * \return the current index
1418 int VLC_PlaylistIndex( int i_object )
1421 playlist_t * p_playlist;
1422 vlc_t *p_vlc = vlc_current_object( i_object );
1424 /* Check that the handle is valid */
1430 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1434 if( i_object ) vlc_object_release( p_vlc );
1438 i_index = p_playlist->i_index;
1439 vlc_object_release( p_playlist );
1441 if( i_object ) vlc_object_release( p_vlc );
1446 * Total amount of items in the playlist
1448 * \param i_object a vlc object id
1449 * \return amount of playlist items
1451 int VLC_PlaylistNumberOfItems( int i_object )
1454 playlist_t * p_playlist;
1455 vlc_t *p_vlc = vlc_current_object( i_object );
1457 /* Check that the handle is valid */
1463 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1467 if( i_object ) vlc_object_release( p_vlc );
1471 i_size = p_playlist->i_size;
1472 vlc_object_release( p_playlist );
1474 if( i_object ) vlc_object_release( p_vlc );
1479 * Next playlist item
1481 * Skip to the next playlistitem and play it.
1483 * \param i_object a vlc object id
1484 * \return VLC_SUCCESS on success
1486 int VLC_PlaylistNext( int i_object )
1488 playlist_t * p_playlist;
1489 vlc_t *p_vlc = vlc_current_object( i_object );
1491 /* Check that the handle is valid */
1497 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1501 if( i_object ) vlc_object_release( p_vlc );
1505 playlist_Next( p_playlist );
1506 vlc_object_release( p_playlist );
1508 if( i_object ) vlc_object_release( p_vlc );
1513 * Previous playlist item
1515 * Skip to the previous playlistitem and play it.
1517 * \param i_object a vlc object id
1518 * \return VLC_SUCCESS on success
1520 int VLC_PlaylistPrev( int i_object )
1522 playlist_t * p_playlist;
1523 vlc_t *p_vlc = vlc_current_object( i_object );
1525 /* Check that the handle is valid */
1531 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1535 if( i_object ) vlc_object_release( p_vlc );
1539 playlist_Prev( p_playlist );
1540 vlc_object_release( p_playlist );
1542 if( i_object ) vlc_object_release( p_vlc );
1547 /*****************************************************************************
1548 * VLC_PlaylistClear: Empty the playlist
1549 *****************************************************************************/
1550 int VLC_PlaylistClear( int i_object )
1553 playlist_t * p_playlist;
1554 vlc_t *p_vlc = vlc_current_object( i_object );
1556 /* Check that the handle is valid */
1562 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1566 if( i_object ) vlc_object_release( p_vlc );
1570 i_err = playlist_Clear( p_playlist );
1572 vlc_object_release( p_playlist );
1574 if( i_object ) vlc_object_release( p_vlc );
1581 * \param i_object a vlc object id
1582 * \param i_volume something in a range from 0-200
1583 * \return the new volume (range 0-200 %)
1585 int VLC_VolumeSet( int i_object, int i_volume )
1587 audio_volume_t i_vol = 0;
1588 vlc_t *p_vlc = vlc_current_object( i_object );
1590 /* Check that the handle is valid */
1596 if( i_volume >= 0 && i_volume <= 200 )
1598 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1599 aout_VolumeSet( p_vlc, i_vol );
1602 if( i_object ) vlc_object_release( p_vlc );
1603 return i_vol * 200 / AOUT_VOLUME_MAX;
1607 * Get the current volume
1609 * Retrieve the current volume.
1611 * \param i_object a vlc object id
1612 * \return the current volume (range 0-200 %)
1614 int VLC_VolumeGet( int i_object )
1616 audio_volume_t i_volume;
1617 vlc_t *p_vlc = vlc_current_object( i_object );
1619 /* Check that the handle is valid */
1625 aout_VolumeGet( p_vlc, &i_volume );
1627 if( i_object ) vlc_object_release( p_vlc );
1628 return i_volume*200/AOUT_VOLUME_MAX;
1632 * Mute/Unmute the volume
1634 * \param i_object a vlc object id
1635 * \return VLC_SUCCESS on success
1637 int VLC_VolumeMute( int i_object )
1639 vlc_t *p_vlc = vlc_current_object( i_object );
1641 /* Check that the handle is valid */
1647 aout_VolumeMute( p_vlc, NULL );
1649 if( i_object ) vlc_object_release( p_vlc );
1653 /*****************************************************************************
1654 * VLC_FullScreen: toggle fullscreen mode
1655 *****************************************************************************/
1656 int VLC_FullScreen( int i_object )
1658 vout_thread_t *p_vout;
1659 vlc_t *p_vlc = vlc_current_object( i_object );
1666 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1670 if( i_object ) vlc_object_release( p_vlc );
1674 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1675 vlc_object_release( p_vout );
1677 if( i_object ) vlc_object_release( p_vlc );
1681 /* following functions are local */
1683 /*****************************************************************************
1684 * SetLanguage: set the interface language.
1685 *****************************************************************************
1686 * We set the LC_MESSAGES locale category for interface messages and buttons,
1687 * as well as the LC_CTYPE category for string sorting and possible wide
1688 * character support.
1689 *****************************************************************************/
1690 static void SetLanguage ( char const *psz_lang )
1692 #if defined( ENABLE_NLS ) \
1693 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1696 #if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
1700 if( psz_lang && !*psz_lang )
1702 # if defined( HAVE_LC_MESSAGES )
1703 setlocale( LC_MESSAGES, psz_lang );
1705 setlocale( LC_CTYPE, psz_lang );
1710 /* I need that under Darwin, please check it doesn't disturb
1711 * other platforms. --Meuuh */
1712 setenv( "LANG", psz_lang, 1 );
1714 #elif defined( SYS_BEOS ) || defined( WIN32 )
1715 /* We set LC_ALL manually because it is the only way to set
1716 * the language at runtime under eg. Windows. Beware that this
1717 * makes the environment unconsistent when libvlc is unloaded and
1718 * should probably be moved to a safer place like vlc.c. */
1719 static char psz_lcall[20];
1720 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1721 psz_lcall[19] = '\0';
1722 putenv( psz_lcall );
1725 setlocale( LC_ALL, psz_lang );
1728 /* Specify where to find the locales for current domain */
1729 #if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1730 psz_path = LOCALEDIR;
1732 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1736 if( !bindtextdomain( PACKAGE, psz_path ) )
1738 fprintf( stderr, "warning: no domain %s in directory %s\n",
1739 PACKAGE, psz_path );
1742 /* Set the default domain */
1743 textdomain( PACKAGE );
1745 #if defined( ENABLE_UTF8 )
1746 bind_textdomain_codeset( PACKAGE, "UTF-8" );
1752 /*****************************************************************************
1753 * GetFilenames: parse command line options which are not flags
1754 *****************************************************************************
1755 * Parse command line for input files as well as their associated options.
1756 * An option always follows its associated input and begins with a ":".
1757 *****************************************************************************/
1758 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1760 int i_opt, i_options;
1762 /* We assume that the remaining parameters are filenames
1763 * and their input options */
1764 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
1768 /* Count the input options */
1769 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
1775 /* TODO: write an internal function of this one, to avoid
1776 * unnecessary lookups. */
1777 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1778 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
1780 PLAYLIST_INSERT, 0 );
1786 /*****************************************************************************
1787 * Usage: print program usage
1788 *****************************************************************************
1789 * Print a short inline help. Message interface is initialized at this stage.
1790 *****************************************************************************/
1791 static void Usage( vlc_t *p_this, char const *psz_module_name )
1793 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1794 /* short option ------' | | | | | | |
1795 * option name ------------' | | | | | |
1796 * <bra -------------------------' | | | | |
1797 * option type or "" --------------' | | | |
1798 * ket> -----------------------------' | | |
1799 * padding spaces ---------------------' | |
1800 * comment -------------------------------' |
1801 * comment suffix --------------------------'
1803 * The purpose of having bra and ket is that we might i18n them as well.
1805 #define LINE_START 8
1806 #define PADDING_SPACES 25
1809 module_config_t *p_item;
1810 char psz_spaces[PADDING_SPACES+LINE_START+1];
1811 char psz_format[sizeof(FORMAT_STRING)];
1812 char psz_buffer[1000];
1815 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1816 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
1818 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1819 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1821 strcpy( psz_format, FORMAT_STRING );
1827 /* List all modules */
1828 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1830 /* Enumerate the config for each module */
1831 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1833 vlc_bool_t b_help_module;
1835 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1837 if( psz_module_name && strcmp( psz_module_name,
1838 p_parser->psz_object_name ) )
1843 /* Ignore modules without config options */
1844 if( !p_parser->i_config_items )
1849 /* Ignore modules with only advanced config options if requested */
1852 for( p_item = p_parser->p_config;
1853 p_item->i_type != CONFIG_HINT_END;
1856 if( (p_item->i_type & CONFIG_ITEM) &&
1857 !p_item->b_advanced ) break;
1859 if( p_item->i_type == CONFIG_HINT_END ) continue;
1862 /* Print name of module */
1863 if( strcmp( "main", p_parser->psz_object_name ) )
1864 fprintf( stdout, "\n %s\n", p_parser->psz_longname );
1866 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1868 /* Print module options */
1869 for( p_item = p_parser->p_config;
1870 p_item->i_type != CONFIG_HINT_END;
1874 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1875 char *psz_suf = "", *psz_prefix = NULL;
1878 /* Skip advanced options if requested */
1879 if( p_item->b_advanced && !b_advanced )
1884 switch( p_item->i_type )
1886 case CONFIG_HINT_CATEGORY:
1887 case CONFIG_HINT_USAGE:
1888 if( !strcmp( "main", p_parser->psz_object_name ) )
1889 fprintf( stdout, "\n %s\n", p_item->psz_text );
1892 case CONFIG_ITEM_STRING:
1893 case CONFIG_ITEM_FILE:
1894 case CONFIG_ITEM_DIRECTORY:
1895 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1896 if( !p_item->ppsz_list )
1898 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1904 psz_type = psz_buffer;
1906 for( i = 0; p_item->ppsz_list[i]; i++ )
1908 if( i ) strcat( psz_type, "," );
1909 strcat( psz_type, p_item->ppsz_list[i] );
1914 case CONFIG_ITEM_INTEGER:
1915 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
1916 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1918 case CONFIG_ITEM_FLOAT:
1919 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1921 case CONFIG_ITEM_BOOL:
1922 psz_bra = ""; psz_type = ""; psz_ket = "";
1923 if( !b_help_module )
1925 psz_suf = p_item->i_value ? _(" (default enabled)") :
1926 _(" (default disabled)");
1936 /* Add short option if any */
1937 if( p_item->i_short )
1939 sprintf( psz_short, "-%c,", p_item->i_short );
1943 strcpy( psz_short, " " );
1946 i = PADDING_SPACES - strlen( p_item->psz_name )
1947 - strlen( psz_bra ) - strlen( psz_type )
1948 - strlen( psz_ket ) - 1;
1950 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1952 /* If option is of type --foo-bar, we print its counterpart
1953 * as --no-foo-bar, but if it is of type --foobar (without
1954 * dashes in the name) we print it as --nofoobar. Both
1955 * values are of course valid, only the display changes. */
1956 psz_prefix = strchr( p_item->psz_name, '-' ) ? ", --no-"
1958 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
1963 psz_spaces[0] = '\n';
1968 psz_spaces[i] = '\0';
1971 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1973 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1974 psz_prefix, p_item->psz_name, psz_bra, psz_type,
1975 psz_ket, psz_spaces );
1979 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1980 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
1983 psz_spaces[i] = ' ';
1985 /* We wrap the rest of the output */
1986 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
1987 psz_text = psz_buffer;
1990 char *psz_parser, *psz_word;
1991 int i_end = strlen( psz_text );
1993 /* If the remaining text fits in a line, print it. */
1994 if( i_end <= i_width )
1996 fprintf( stdout, "%s\n", psz_text );
2000 /* Otherwise, eat as many words as possible */
2001 psz_parser = psz_text;
2004 psz_word = psz_parser;
2005 psz_parser = strchr( psz_word, ' ' );
2006 /* If no space was found, we reached the end of the text
2007 * block; otherwise, we skip the space we just found. */
2008 psz_parser = psz_parser ? psz_parser + 1
2011 } while( psz_parser - psz_text <= i_width );
2013 /* We cut a word in one of these cases:
2014 * - it's the only word in the line and it's too long.
2015 * - we used less than 80% of the width and the word we are
2016 * going to wrap is longer than 40% of the width, and even
2017 * if the word would have fit in the next line. */
2018 if( psz_word == psz_text
2019 || ( psz_word - psz_text < 80 * i_width / 100
2020 && psz_parser - psz_word > 40 * i_width / 100 ) )
2022 char c = psz_text[i_width];
2023 psz_text[i_width] = '\0';
2024 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2025 psz_text += i_width;
2030 psz_word[-1] = '\0';
2031 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2032 psz_text = psz_word;
2038 /* Release the module list */
2039 vlc_list_release( p_list );
2041 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2042 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2047 /*****************************************************************************
2048 * ListModules: list the available modules with their description
2049 *****************************************************************************
2050 * Print a list of all available modules (builtins and plugins) and a short
2051 * description for each one.
2052 *****************************************************************************/
2053 static void ListModules( vlc_t *p_this )
2057 char psz_spaces[22];
2060 memset( psz_spaces, ' ', 22 );
2067 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
2068 p_this->p_vlc->psz_object_name );
2070 fprintf( stdout, _("[module] [description]\n") );
2072 /* List all modules */
2073 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2075 /* Enumerate each module */
2076 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2080 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2082 /* Nasty hack, but right now I'm too tired to think about a nice
2084 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2088 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2089 psz_spaces, p_parser->psz_longname );
2091 psz_spaces[i] = ' ';
2094 vlc_list_release( p_list );
2096 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2097 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2102 /*****************************************************************************
2103 * Version: print complete program version
2104 *****************************************************************************
2105 * Print complete program version and build number.
2106 *****************************************************************************/
2107 static void Version( void )
2113 fprintf( stdout, VERSION_MESSAGE "\n" );
2115 _("This program comes with NO WARRANTY, to the extent permitted by "
2116 "law.\nYou may redistribute it under the terms of the GNU General "
2117 "Public License;\nsee the file named COPYING for details.\n"
2118 "Written by the VideoLAN team; see the AUTHORS file.\n") );
2120 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2121 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2126 /*****************************************************************************
2127 * ShowConsole: On Win32, create an output console for debug messages
2128 *****************************************************************************
2129 * This function is useful only on Win32.
2130 *****************************************************************************/
2132 static void ShowConsole( void )
2136 freopen( "CONOUT$", "w", stdout );
2137 freopen( "CONOUT$", "w", stderr );
2138 freopen( "CONIN$", "r", stdin );
2144 /*****************************************************************************
2145 * ConsoleWidth: Return the console width in characters
2146 *****************************************************************************
2147 * We use the stty shell command to get the console width; if this fails or
2148 * if the width is less than 80, we default to 80.
2149 *****************************************************************************/
2150 static int ConsoleWidth( void )
2155 char buf[20], *psz_parser;
2159 file = popen( "stty size 2>/dev/null", "r" );
2162 i_ret = fread( buf, 1, 20, file );
2166 psz_parser = strchr( buf, ' ' );
2169 i_ret = atoi( psz_parser + 1 );
2184 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2185 vlc_value_t old_val, vlc_value_t new_val, void *param)
2187 vlc_t *p_vlc = (vlc_t *)p_this;
2189 if( new_val.i_int >= -1 )
2191 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );