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 );
342 /* Will be re-done properly later on */
343 p_vlc->p_libvlc->i_verbose = config_GetInt( p_vlc, "verbose" );
345 /* Check for daemon mode */
347 if( config_GetInt( p_vlc, "daemon" ) )
351 if( ( i_pid = fork() ) < 0 )
353 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
358 /* This is the parent, exit right now */
359 msg_Dbg( p_vlc, "closing parent process" );
364 /* We are the child */
365 msg_Dbg( p_vlc, "daemon spawned" );
370 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
377 config_Free( p_help_module );
378 vlc_object_destroy( p_help_module );
379 module_EndBank( p_vlc );
380 if( i_object ) vlc_object_release( p_vlc );
384 /* Check for translation config option */
385 #if defined( ENABLE_NLS ) \
386 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
388 /* This ain't really nice to have to reload the config here but it seems
389 * the only way to do it. */
390 config_LoadConfigFile( p_vlc, "main" );
391 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
393 /* Check if the user specified a custom language */
394 psz_language = config_GetPsz( p_vlc, "language" );
395 if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
397 vlc_bool_t b_cache_delete = libvlc.p_module_bank->b_cache_delete;
399 /* Reset the default domain */
400 SetLanguage( psz_language );
402 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
403 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
405 textdomain( PACKAGE );
407 #if defined( ENABLE_UTF8 )
408 bind_textdomain_codeset( PACKAGE, "UTF-8" );
411 module_EndBank( p_vlc );
412 module_InitBank( p_vlc );
413 config_LoadConfigFile( p_vlc, "main" );
414 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
415 libvlc.p_module_bank->b_cache_delete = b_cache_delete;
417 if( psz_language ) free( psz_language );
421 * Load the builtins and plugins into the module_bank.
422 * We have to do it before config_Load*() because this also gets the
423 * list of configuration options exported by each module and loads their
426 module_LoadBuiltins( p_vlc );
427 module_LoadPlugins( p_vlc );
433 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
434 libvlc.p_module_bank->i_children );
436 /* Hack: insert the help module here */
437 vlc_object_attach( p_help_module, libvlc.p_module_bank );
440 /* Check for help on modules */
441 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
443 Usage( p_vlc, p_tmp );
447 /* Check for long help option */
448 else if( config_GetInt( p_vlc, "longhelp" ) )
450 Usage( p_vlc, NULL );
453 /* Check for module list option */
454 else if( config_GetInt( p_vlc, "list" ) )
456 ListModules( p_vlc );
460 /* Check for config file options */
461 if( config_GetInt( p_vlc, "reset-config" ) )
463 vlc_object_detach( p_help_module );
464 config_ResetAll( p_vlc );
465 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
466 config_SaveConfigFile( p_vlc, NULL );
467 vlc_object_attach( p_help_module, libvlc.p_module_bank );
469 if( config_GetInt( p_vlc, "save-config" ) )
471 vlc_object_detach( p_help_module );
472 config_LoadConfigFile( p_vlc, NULL );
473 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
474 config_SaveConfigFile( p_vlc, NULL );
475 vlc_object_attach( p_help_module, libvlc.p_module_bank );
478 /* Hack: remove the help module here */
479 vlc_object_detach( p_help_module );
484 config_Free( p_help_module );
485 vlc_object_destroy( p_help_module );
486 module_EndBank( p_vlc );
487 if( i_object ) vlc_object_release( p_vlc );
492 * Override default configuration with config file settings
494 config_LoadConfigFile( p_vlc, NULL );
496 /* Hack: insert the help module here */
497 vlc_object_attach( p_help_module, libvlc.p_module_bank );
501 * Override configuration with command line settings
503 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
507 /* Pause the console because it's destroyed when we exit */
508 fprintf( stderr, "The command line options couldn't be loaded, check "
509 "that they are valid.\nPress the RETURN key to continue..." );
512 vlc_object_detach( p_help_module );
513 config_Free( p_help_module );
514 vlc_object_destroy( p_help_module );
515 module_EndBank( p_vlc );
516 if( i_object ) vlc_object_release( p_vlc );
520 /* Hack: remove the help module here */
521 vlc_object_detach( p_help_module );
522 config_Free( p_help_module );
523 vlc_object_destroy( p_help_module );
527 * System specific configuration
529 system_Configure( p_vlc, &i_argc, ppsz_argv );
532 * Message queue options
535 var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
536 if( config_GetInt( p_vlc, "quiet" ) )
540 var_Set( p_vlc, "verbose", val );
542 var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
543 var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
545 libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
548 * Output messages that may still be in the queue
552 /* p_vlc initialization. FIXME ? */
554 #if defined( __i386__ )
555 if( !config_GetInt( p_vlc, "mmx" ) )
556 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
557 if( !config_GetInt( p_vlc, "3dn" ) )
558 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
559 if( !config_GetInt( p_vlc, "mmxext" ) )
560 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
561 if( !config_GetInt( p_vlc, "sse" ) )
562 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
563 if( !config_GetInt( p_vlc, "sse2" ) )
564 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
566 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
567 if( !config_GetInt( p_vlc, "altivec" ) )
568 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
571 #define PRINT_CAPABILITY( capability, string ) \
572 if( libvlc.i_cpu & capability ) \
574 strncat( p_capabilities, string " ", \
575 sizeof(p_capabilities) - strlen(p_capabilities) ); \
576 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
579 p_capabilities[0] = '\0';
580 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
581 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
582 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
583 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
584 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
585 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
586 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
587 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
588 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
589 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
590 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
593 * Choose the best memcpy module
595 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
597 if( p_vlc->pf_memcpy == NULL )
599 p_vlc->pf_memcpy = memcpy;
602 if( p_vlc->pf_memset == NULL )
604 p_vlc->pf_memset = memset;
608 * Initialize hotkey handling
610 var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
611 p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
612 /* Do a copy (we don't need to modify the strings) */
613 memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
616 * Initialize playlist and get commandline files
618 p_playlist = playlist_Create( p_vlc );
621 msg_Err( p_vlc, "playlist initialization failed" );
622 if( p_vlc->p_memcpy_module != NULL )
624 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
626 module_EndBank( p_vlc );
627 if( i_object ) vlc_object_release( p_vlc );
632 * Load background interfaces
634 psz_modules = config_GetPsz( p_vlc, "extraintf" );
635 psz_parser = psz_modules;
636 while ( psz_parser && *psz_parser )
638 char *psz_module, *psz_temp;
639 psz_module = psz_parser;
640 psz_parser = strchr( psz_module, ',' );
646 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
649 sprintf( psz_temp, "%s,none", psz_module );
650 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
660 * Allways load the hotkeys interface if it exists
662 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
665 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
667 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
668 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
669 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
670 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
671 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
672 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
673 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
674 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
675 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
676 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
677 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
678 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
681 * Get input filenames given as commandline arguments
683 GetFilenames( p_vlc, i_argc, ppsz_argv );
685 if( i_object ) vlc_object_release( p_vlc );
689 /*****************************************************************************
690 * VLC_AddIntf: add an interface
691 *****************************************************************************
692 * This function opens an interface plugin and runs it. If b_block is set
693 * to 0, VLC_AddIntf will return immediately and let the interface run in a
694 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
695 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
696 * the playlist when it is completely initialised.
697 *****************************************************************************/
698 int VLC_AddIntf( int i_object, char const *psz_module,
699 vlc_bool_t b_block, vlc_bool_t b_play )
702 intf_thread_t *p_intf;
703 vlc_t *p_vlc = vlc_current_object( i_object );
711 if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module )
714 * We prefer the dummy interface if none is specified. */
715 char *psz_interface = config_GetPsz( p_vlc, "intf" );
716 if( !psz_interface || !*psz_interface ) psz_module = "dummy";
717 if( psz_interface ) free( psz_interface );
721 /* Try to create the interface */
722 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
726 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
727 if( i_object ) vlc_object_release( p_vlc );
731 /* Interface doesn't handle play on start so do it ourselves */
732 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
734 /* Try to run the interface */
735 p_intf->b_play = b_play;
736 p_intf->b_block = b_block;
737 i_err = intf_RunThread( p_intf );
740 vlc_object_detach( p_intf );
741 intf_Destroy( p_intf );
742 if( i_object ) vlc_object_release( p_vlc );
746 if( i_object ) vlc_object_release( p_vlc );
750 /*****************************************************************************
751 * VLC_Die: ask vlc to die.
752 *****************************************************************************
753 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
754 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
755 *****************************************************************************/
756 int VLC_Die( int i_object )
758 vlc_t *p_vlc = vlc_current_object( i_object );
765 p_vlc->b_die = VLC_TRUE;
767 if( i_object ) vlc_object_release( p_vlc );
771 /*****************************************************************************
772 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
773 *****************************************************************************/
774 int VLC_CleanUp( int i_object )
776 intf_thread_t * p_intf;
777 playlist_t * p_playlist;
778 vout_thread_t * p_vout;
779 aout_instance_t * p_aout;
780 announce_handler_t * p_announce;
781 vlc_t *p_vlc = vlc_current_object( i_object );
783 /* Check that the handle is valid */
790 * Ask the interfaces to stop and destroy them
792 msg_Dbg( p_vlc, "removing all interfaces" );
793 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
795 intf_StopThread( p_intf );
796 vlc_object_detach( p_intf );
797 vlc_object_release( p_intf );
798 intf_Destroy( p_intf );
804 msg_Dbg( p_vlc, "removing all playlists" );
805 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
808 vlc_object_detach( p_playlist );
809 vlc_object_release( p_playlist );
810 playlist_Destroy( p_playlist );
816 msg_Dbg( p_vlc, "removing all video outputs" );
817 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
819 vlc_object_detach( p_vout );
820 vlc_object_release( p_vout );
821 vout_Destroy( p_vout );
827 msg_Dbg( p_vlc, "removing all audio outputs" );
828 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
830 vlc_object_detach( (vlc_object_t *)p_aout );
831 vlc_object_release( (vlc_object_t *)p_aout );
832 aout_Delete( p_aout );
836 * Free announce handler(s?)
838 msg_Dbg( p_vlc, "removing announce handler" );
839 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
842 vlc_object_detach( p_announce );
843 vlc_object_release( p_announce );
844 announce_HandlerDestroy( p_announce );
847 if( i_object ) vlc_object_release( p_vlc );
851 /*****************************************************************************
852 * VLC_Destroy: Destroy everything.
853 *****************************************************************************
854 * This function requests the running threads to finish, waits for their
855 * termination, and destroys their structure.
856 *****************************************************************************/
857 int VLC_Destroy( int i_object )
859 vlc_t *p_vlc = vlc_current_object( i_object );
867 * Free allocated memory
869 if( p_vlc->p_memcpy_module )
871 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
872 p_vlc->p_memcpy_module = NULL;
878 module_EndBank( p_vlc );
880 if( p_vlc->psz_homedir )
882 free( p_vlc->psz_homedir );
883 p_vlc->psz_homedir = NULL;
886 if( p_vlc->psz_configfile )
888 free( p_vlc->psz_configfile );
889 p_vlc->psz_configfile = NULL;
892 if( p_vlc->p_hotkeys )
894 free( p_vlc->p_hotkeys );
895 p_vlc->p_hotkeys = NULL;
899 * System specific cleaning code
903 /* Destroy mutexes */
904 vlc_mutex_destroy( &p_vlc->config_lock );
906 vlc_object_detach( p_vlc );
908 /* Release object before destroying it */
909 if( i_object ) vlc_object_release( p_vlc );
911 vlc_object_destroy( p_vlc );
913 /* Stop thread system: last one out please shut the door! */
914 vlc_threads_end( p_libvlc );
919 /*****************************************************************************
920 * VLC_VariableSet: set a vlc variable
921 *****************************************************************************/
922 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
924 vlc_t *p_vlc = vlc_current_object( i_object );
932 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
933 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
934 if( !strncmp( psz_var, "conf::", 6 ) )
936 module_config_t *p_item;
937 char const *psz_newvar = psz_var + 6;
939 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
943 switch( p_item->i_type )
945 case CONFIG_ITEM_BOOL:
946 config_PutInt( p_vlc, psz_newvar, value.b_bool );
948 case CONFIG_ITEM_INTEGER:
949 config_PutInt( p_vlc, psz_newvar, value.i_int );
951 case CONFIG_ITEM_FLOAT:
952 config_PutFloat( p_vlc, psz_newvar, value.f_float );
955 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
958 if( i_object ) vlc_object_release( p_vlc );
963 i_ret = var_Set( p_vlc, psz_var, value );
965 if( i_object ) vlc_object_release( p_vlc );
969 /*****************************************************************************
970 * VLC_VariableGet: get a vlc variable
971 *****************************************************************************/
972 int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
974 vlc_t *p_vlc = vlc_current_object( i_object );
982 i_ret = var_Get( p_vlc, psz_var, p_value );
984 if( i_object ) vlc_object_release( p_vlc );
988 /*****************************************************************************
989 * VLC_AddTarget: adds a target for playing.
990 *****************************************************************************
991 * This function adds psz_target to the current playlist. If a playlist does
992 * not exist, it will create one.
993 *****************************************************************************/
994 int VLC_AddTarget( int i_object, char const *psz_target,
995 char const **ppsz_options, int i_options,
996 int i_mode, int i_pos )
999 playlist_t *p_playlist;
1000 vlc_t *p_vlc = vlc_current_object( i_object );
1007 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1009 if( p_playlist == NULL )
1011 msg_Dbg( p_vlc, "no playlist present, creating one" );
1012 p_playlist = playlist_Create( p_vlc );
1014 if( p_playlist == NULL )
1016 if( i_object ) vlc_object_release( p_vlc );
1017 return VLC_EGENERIC;
1020 vlc_object_yield( p_playlist );
1023 i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
1024 i_mode, i_pos, -1, ppsz_options, i_options);
1026 vlc_object_release( p_playlist );
1028 if( i_object ) vlc_object_release( p_vlc );
1032 /*****************************************************************************
1034 *****************************************************************************/
1035 int VLC_Play( int i_object )
1037 playlist_t * p_playlist;
1038 vlc_t *p_vlc = vlc_current_object( i_object );
1040 /* Check that the handle is valid */
1046 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1050 if( i_object ) vlc_object_release( p_vlc );
1054 playlist_Play( p_playlist );
1055 vlc_object_release( p_playlist );
1057 if( i_object ) vlc_object_release( p_vlc );
1061 /*****************************************************************************
1062 * VLC_Pause: toggle pause
1063 *****************************************************************************/
1064 int VLC_Pause( int i_object )
1066 playlist_t * p_playlist;
1067 vlc_t *p_vlc = vlc_current_object( i_object );
1069 /* Check that the handle is valid */
1075 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1079 if( i_object ) vlc_object_release( p_vlc );
1083 playlist_Pause( p_playlist );
1084 vlc_object_release( p_playlist );
1086 if( i_object ) vlc_object_release( p_vlc );
1090 /*****************************************************************************
1091 * VLC_Pause: toggle pause
1092 *****************************************************************************/
1093 int VLC_Stop( int i_object )
1095 playlist_t * p_playlist;
1096 vlc_t *p_vlc = vlc_current_object( i_object );
1098 /* Check that the handle is valid */
1104 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1108 if( i_object ) vlc_object_release( p_vlc );
1112 playlist_Stop( p_playlist );
1113 vlc_object_release( p_playlist );
1115 if( i_object ) vlc_object_release( p_vlc );
1119 /*****************************************************************************
1120 * VLC_IsPlaying: Query for Playlist Status
1121 *****************************************************************************/
1122 vlc_bool_t VLC_IsPlaying( int i_object )
1124 playlist_t * p_playlist;
1125 vlc_bool_t b_playing;
1127 vlc_t *p_vlc = vlc_current_object( i_object );
1129 /* Check that the handle is valid */
1135 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1139 if( i_object ) vlc_object_release( p_vlc );
1143 b_playing = playlist_IsPlaying( p_playlist );
1144 vlc_object_release( p_playlist );
1146 if( i_object ) vlc_object_release( p_vlc );
1151 * Get the current position in a input
1153 * Return the current position as a float
1154 * \note For some inputs, this will be unknown.
1156 * \param i_object a vlc object id
1157 * \return a float in the range of 0.0 - 1.0
1159 float VLC_PositionGet( int i_object )
1161 input_thread_t *p_input;
1163 vlc_t *p_vlc = vlc_current_object( i_object );
1165 /* Check that the handle is valid */
1171 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1175 if( i_object ) vlc_object_release( p_vlc );
1179 var_Get( p_input, "position", &val );
1180 vlc_object_release( p_input );
1182 if( i_object ) vlc_object_release( p_vlc );
1187 * Set the current position in a input
1189 * Set the current position in a input and then return
1190 * the current position as a float.
1191 * \note For some inputs, this will be unknown.
1193 * \param i_object a vlc object id
1194 * \param i_position a float in the range of 0.0 - 1.0
1195 * \return a float in the range of 0.0 - 1.0
1197 float VLC_PositionSet( int i_object, float i_position )
1199 input_thread_t *p_input;
1201 vlc_t *p_vlc = vlc_current_object( i_object );
1203 /* Check that the handle is valid */
1209 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1213 if( i_object ) vlc_object_release( p_vlc );
1217 val.f_float = i_position;
1218 var_Set( p_input, "position", val );
1219 var_Get( p_input, "position", &val );
1220 vlc_object_release( p_input );
1222 if( i_object ) vlc_object_release( p_vlc );
1227 * Get the current position in a input
1229 * Return the current position in seconds from the start.
1230 * \note For some inputs, this will be unknown.
1232 * \param i_object a vlc object id
1233 * \return the offset from 0:00 in seconds
1235 int VLC_TimeGet( int i_object )
1237 input_thread_t *p_input;
1239 vlc_t *p_vlc = vlc_current_object( i_object );
1241 /* Check that the handle is valid */
1247 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1251 if( i_object ) vlc_object_release( p_vlc );
1255 var_Get( p_input, "time", &val );
1256 vlc_object_release( p_input );
1258 if( i_object ) vlc_object_release( p_vlc );
1259 return val.i_time / 1000000;
1263 * Seek to a position in the current input
1265 * Seek i_seconds in the current input. If b_relative is set,
1266 * then the seek will be relative to the current position, otherwise
1267 * it will seek to i_seconds from the beginning of the input.
1268 * \note For some inputs, this will be unknown.
1270 * \param i_object a vlc object id
1271 * \param i_seconds seconds from current position or from beginning of input
1272 * \param b_relative seek relative from current position
1273 * \return VLC_SUCCESS on success
1275 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1277 input_thread_t *p_input;
1279 vlc_t *p_vlc = vlc_current_object( i_object );
1281 /* Check that the handle is valid */
1287 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1291 if( i_object ) vlc_object_release( p_vlc );
1297 val.i_time = i_seconds * 1000000;
1298 var_Set( p_input, "time-offset", val );
1302 val.i_time = i_seconds * 1000000;
1303 var_Set( p_input, "time", val );
1305 vlc_object_release( p_input );
1307 if( i_object ) vlc_object_release( p_vlc );
1312 * Get the total length of a input
1314 * Return the total length in seconds from the current input.
1315 * \note For some inputs, this will be unknown.
1317 * \param i_object a vlc object id
1318 * \return the length in seconds
1320 int VLC_LengthGet( int i_object )
1322 input_thread_t *p_input;
1324 vlc_t *p_vlc = vlc_current_object( i_object );
1326 /* Check that the handle is valid */
1332 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1336 if( i_object ) vlc_object_release( p_vlc );
1340 var_Get( p_input, "length", &val );
1341 vlc_object_release( p_input );
1343 if( i_object ) vlc_object_release( p_vlc );
1344 return val.i_time / 1000000;
1348 * Play the input faster than realtime
1350 * 2x, 4x, 8x faster than realtime
1351 * \note For some inputs, this will be impossible.
1353 * \param i_object a vlc object id
1354 * \return the current speedrate
1356 float VLC_SpeedFaster( int i_object )
1358 input_thread_t *p_input;
1360 vlc_t *p_vlc = vlc_current_object( i_object );
1362 /* Check that the handle is valid */
1368 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1372 if( i_object ) vlc_object_release( p_vlc );
1376 val.b_bool = VLC_TRUE;
1377 var_Set( p_input, "rate-faster", val );
1378 var_Get( p_input, "rate", &val );
1379 vlc_object_release( p_input );
1381 if( i_object ) vlc_object_release( p_vlc );
1382 return val.f_float / INPUT_RATE_DEFAULT;
1386 * Play the input slower than realtime
1388 * 1/2x, 1/4x, 1/8x slower than realtime
1389 * \note For some inputs, this will be impossible.
1391 * \param i_object a vlc object id
1392 * \return the current speedrate
1394 float VLC_SpeedSlower( int i_object )
1396 input_thread_t *p_input;
1398 vlc_t *p_vlc = vlc_current_object( i_object );
1400 /* Check that the handle is valid */
1406 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1410 if( i_object ) vlc_object_release( p_vlc );
1414 val.b_bool = VLC_TRUE;
1415 var_Set( p_input, "rate-slower", val );
1416 var_Get( p_input, "rate", &val );
1417 vlc_object_release( p_input );
1419 if( i_object ) vlc_object_release( p_vlc );
1420 return val.f_float / INPUT_RATE_DEFAULT;
1424 * Return the current playlist item
1426 * Returns the index of the playlistitem that is currently selected for play.
1427 * This is valid even if nothing is currently playing.
1429 * \param i_object a vlc object id
1430 * \return the current index
1432 int VLC_PlaylistIndex( int i_object )
1435 playlist_t * p_playlist;
1436 vlc_t *p_vlc = vlc_current_object( i_object );
1438 /* Check that the handle is valid */
1444 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1448 if( i_object ) vlc_object_release( p_vlc );
1452 i_index = p_playlist->i_index;
1453 vlc_object_release( p_playlist );
1455 if( i_object ) vlc_object_release( p_vlc );
1460 * Total amount of items in the playlist
1462 * \param i_object a vlc object id
1463 * \return amount of playlist items
1465 int VLC_PlaylistNumberOfItems( int i_object )
1468 playlist_t * p_playlist;
1469 vlc_t *p_vlc = vlc_current_object( i_object );
1471 /* Check that the handle is valid */
1477 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1481 if( i_object ) vlc_object_release( p_vlc );
1485 i_size = p_playlist->i_size;
1486 vlc_object_release( p_playlist );
1488 if( i_object ) vlc_object_release( p_vlc );
1493 * Next playlist item
1495 * Skip to the next playlistitem and play it.
1497 * \param i_object a vlc object id
1498 * \return VLC_SUCCESS on success
1500 int VLC_PlaylistNext( int i_object )
1502 playlist_t * p_playlist;
1503 vlc_t *p_vlc = vlc_current_object( i_object );
1505 /* Check that the handle is valid */
1511 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1515 if( i_object ) vlc_object_release( p_vlc );
1519 playlist_Next( p_playlist );
1520 vlc_object_release( p_playlist );
1522 if( i_object ) vlc_object_release( p_vlc );
1527 * Previous playlist item
1529 * Skip to the previous playlistitem and play it.
1531 * \param i_object a vlc object id
1532 * \return VLC_SUCCESS on success
1534 int VLC_PlaylistPrev( int i_object )
1536 playlist_t * p_playlist;
1537 vlc_t *p_vlc = vlc_current_object( i_object );
1539 /* Check that the handle is valid */
1545 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1549 if( i_object ) vlc_object_release( p_vlc );
1553 playlist_Prev( p_playlist );
1554 vlc_object_release( p_playlist );
1556 if( i_object ) vlc_object_release( p_vlc );
1561 /*****************************************************************************
1562 * VLC_PlaylistClear: Empty the playlist
1563 *****************************************************************************/
1564 int VLC_PlaylistClear( int i_object )
1567 playlist_t * p_playlist;
1568 vlc_t *p_vlc = vlc_current_object( i_object );
1570 /* Check that the handle is valid */
1576 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1580 if( i_object ) vlc_object_release( p_vlc );
1584 i_err = playlist_Clear( p_playlist );
1586 vlc_object_release( p_playlist );
1588 if( i_object ) vlc_object_release( p_vlc );
1595 * \param i_object a vlc object id
1596 * \param i_volume something in a range from 0-200
1597 * \return the new volume (range 0-200 %)
1599 int VLC_VolumeSet( int i_object, int i_volume )
1601 audio_volume_t i_vol = 0;
1602 vlc_t *p_vlc = vlc_current_object( i_object );
1604 /* Check that the handle is valid */
1610 if( i_volume >= 0 && i_volume <= 200 )
1612 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1613 aout_VolumeSet( p_vlc, i_vol );
1616 if( i_object ) vlc_object_release( p_vlc );
1617 return i_vol * 200 / AOUT_VOLUME_MAX;
1621 * Get the current volume
1623 * Retrieve the current volume.
1625 * \param i_object a vlc object id
1626 * \return the current volume (range 0-200 %)
1628 int VLC_VolumeGet( int i_object )
1630 audio_volume_t i_volume;
1631 vlc_t *p_vlc = vlc_current_object( i_object );
1633 /* Check that the handle is valid */
1639 aout_VolumeGet( p_vlc, &i_volume );
1641 if( i_object ) vlc_object_release( p_vlc );
1642 return i_volume*200/AOUT_VOLUME_MAX;
1646 * Mute/Unmute the volume
1648 * \param i_object a vlc object id
1649 * \return VLC_SUCCESS on success
1651 int VLC_VolumeMute( int i_object )
1653 vlc_t *p_vlc = vlc_current_object( i_object );
1655 /* Check that the handle is valid */
1661 aout_VolumeMute( p_vlc, NULL );
1663 if( i_object ) vlc_object_release( p_vlc );
1667 /*****************************************************************************
1668 * VLC_FullScreen: toggle fullscreen mode
1669 *****************************************************************************/
1670 int VLC_FullScreen( int i_object )
1672 vout_thread_t *p_vout;
1673 vlc_t *p_vlc = vlc_current_object( i_object );
1680 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1684 if( i_object ) vlc_object_release( p_vlc );
1688 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1689 vlc_object_release( p_vout );
1691 if( i_object ) vlc_object_release( p_vlc );
1695 /* following functions are local */
1697 /*****************************************************************************
1698 * SetLanguage: set the interface language.
1699 *****************************************************************************
1700 * We set the LC_MESSAGES locale category for interface messages and buttons,
1701 * as well as the LC_CTYPE category for string sorting and possible wide
1702 * character support.
1703 *****************************************************************************/
1704 static void SetLanguage ( char const *psz_lang )
1706 #if defined( ENABLE_NLS ) \
1707 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1710 #if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
1714 if( psz_lang && !*psz_lang )
1716 # if defined( HAVE_LC_MESSAGES )
1717 setlocale( LC_MESSAGES, psz_lang );
1719 setlocale( LC_CTYPE, psz_lang );
1724 /* I need that under Darwin, please check it doesn't disturb
1725 * other platforms. --Meuuh */
1726 setenv( "LANG", psz_lang, 1 );
1728 #elif defined( SYS_BEOS ) || defined( WIN32 )
1729 /* We set LC_ALL manually because it is the only way to set
1730 * the language at runtime under eg. Windows. Beware that this
1731 * makes the environment unconsistent when libvlc is unloaded and
1732 * should probably be moved to a safer place like vlc.c. */
1733 static char psz_lcall[20];
1734 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1735 psz_lcall[19] = '\0';
1736 putenv( psz_lcall );
1739 setlocale( LC_ALL, psz_lang );
1742 /* Specify where to find the locales for current domain */
1743 #if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1744 psz_path = LOCALEDIR;
1746 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1750 if( !bindtextdomain( PACKAGE, psz_path ) )
1752 fprintf( stderr, "warning: no domain %s in directory %s\n",
1753 PACKAGE, psz_path );
1756 /* Set the default domain */
1757 textdomain( PACKAGE );
1759 #if defined( ENABLE_UTF8 )
1760 bind_textdomain_codeset( PACKAGE, "UTF-8" );
1766 /*****************************************************************************
1767 * GetFilenames: parse command line options which are not flags
1768 *****************************************************************************
1769 * Parse command line for input files as well as their associated options.
1770 * An option always follows its associated input and begins with a ":".
1771 *****************************************************************************/
1772 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1774 int i_opt, i_options;
1776 /* We assume that the remaining parameters are filenames
1777 * and their input options */
1778 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
1782 /* Count the input options */
1783 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
1789 /* TODO: write an internal function of this one, to avoid
1790 * unnecessary lookups. */
1791 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1792 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
1794 PLAYLIST_INSERT, 0 );
1800 /*****************************************************************************
1801 * Usage: print program usage
1802 *****************************************************************************
1803 * Print a short inline help. Message interface is initialized at this stage.
1804 *****************************************************************************/
1805 static void Usage( vlc_t *p_this, char const *psz_module_name )
1807 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1808 /* short option ------' | | | | | | |
1809 * option name ------------' | | | | | |
1810 * <bra -------------------------' | | | | |
1811 * option type or "" --------------' | | | |
1812 * ket> -----------------------------' | | |
1813 * padding spaces ---------------------' | |
1814 * comment -------------------------------' |
1815 * comment suffix --------------------------'
1817 * The purpose of having bra and ket is that we might i18n them as well.
1819 #define LINE_START 8
1820 #define PADDING_SPACES 25
1823 module_config_t *p_item;
1824 char psz_spaces[PADDING_SPACES+LINE_START+1];
1825 char psz_format[sizeof(FORMAT_STRING)];
1826 char psz_buffer[1000];
1829 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1830 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
1832 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1833 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1835 strcpy( psz_format, FORMAT_STRING );
1841 /* List all modules */
1842 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1844 /* Enumerate the config for each module */
1845 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1847 vlc_bool_t b_help_module;
1849 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1851 if( psz_module_name && strcmp( psz_module_name,
1852 p_parser->psz_object_name ) )
1857 /* Ignore modules without config options */
1858 if( !p_parser->i_config_items )
1863 /* Ignore modules with only advanced config options if requested */
1866 for( p_item = p_parser->p_config;
1867 p_item->i_type != CONFIG_HINT_END;
1870 if( (p_item->i_type & CONFIG_ITEM) &&
1871 !p_item->b_advanced ) break;
1873 if( p_item->i_type == CONFIG_HINT_END ) continue;
1876 /* Print name of module */
1877 if( strcmp( "main", p_parser->psz_object_name ) )
1878 fprintf( stdout, "\n %s\n", p_parser->psz_longname );
1880 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1882 /* Print module options */
1883 for( p_item = p_parser->p_config;
1884 p_item->i_type != CONFIG_HINT_END;
1888 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1889 char *psz_suf = "", *psz_prefix = NULL;
1892 /* Skip advanced options if requested */
1893 if( p_item->b_advanced && !b_advanced )
1898 switch( p_item->i_type )
1900 case CONFIG_HINT_CATEGORY:
1901 case CONFIG_HINT_USAGE:
1902 if( !strcmp( "main", p_parser->psz_object_name ) )
1903 fprintf( stdout, "\n %s\n", p_item->psz_text );
1906 case CONFIG_ITEM_STRING:
1907 case CONFIG_ITEM_FILE:
1908 case CONFIG_ITEM_DIRECTORY:
1909 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1910 if( !p_item->ppsz_list )
1912 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1918 psz_type = psz_buffer;
1920 for( i = 0; p_item->ppsz_list[i]; i++ )
1922 if( i ) strcat( psz_type, "," );
1923 strcat( psz_type, p_item->ppsz_list[i] );
1928 case CONFIG_ITEM_INTEGER:
1929 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
1930 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1932 case CONFIG_ITEM_FLOAT:
1933 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1935 case CONFIG_ITEM_BOOL:
1936 psz_bra = ""; psz_type = ""; psz_ket = "";
1937 if( !b_help_module )
1939 psz_suf = p_item->i_value ? _(" (default enabled)") :
1940 _(" (default disabled)");
1950 /* Add short option if any */
1951 if( p_item->i_short )
1953 sprintf( psz_short, "-%c,", p_item->i_short );
1957 strcpy( psz_short, " " );
1960 i = PADDING_SPACES - strlen( p_item->psz_name )
1961 - strlen( psz_bra ) - strlen( psz_type )
1962 - strlen( psz_ket ) - 1;
1964 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1966 /* If option is of type --foo-bar, we print its counterpart
1967 * as --no-foo-bar, but if it is of type --foobar (without
1968 * dashes in the name) we print it as --nofoobar. Both
1969 * values are of course valid, only the display changes. */
1970 psz_prefix = strchr( p_item->psz_name, '-' ) ? ", --no-"
1972 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
1977 psz_spaces[0] = '\n';
1982 psz_spaces[i] = '\0';
1985 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1987 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1988 psz_prefix, p_item->psz_name, psz_bra, psz_type,
1989 psz_ket, psz_spaces );
1993 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1994 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
1997 psz_spaces[i] = ' ';
1999 /* We wrap the rest of the output */
2000 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
2001 psz_text = psz_buffer;
2004 char *psz_parser, *psz_word;
2005 int i_end = strlen( psz_text );
2007 /* If the remaining text fits in a line, print it. */
2008 if( i_end <= i_width )
2010 fprintf( stdout, "%s\n", psz_text );
2014 /* Otherwise, eat as many words as possible */
2015 psz_parser = psz_text;
2018 psz_word = psz_parser;
2019 psz_parser = strchr( psz_word, ' ' );
2020 /* If no space was found, we reached the end of the text
2021 * block; otherwise, we skip the space we just found. */
2022 psz_parser = psz_parser ? psz_parser + 1
2025 } while( psz_parser - psz_text <= i_width );
2027 /* We cut a word in one of these cases:
2028 * - it's the only word in the line and it's too long.
2029 * - we used less than 80% of the width and the word we are
2030 * going to wrap is longer than 40% of the width, and even
2031 * if the word would have fit in the next line. */
2032 if( psz_word == psz_text
2033 || ( psz_word - psz_text < 80 * i_width / 100
2034 && psz_parser - psz_word > 40 * i_width / 100 ) )
2036 char c = psz_text[i_width];
2037 psz_text[i_width] = '\0';
2038 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2039 psz_text += i_width;
2044 psz_word[-1] = '\0';
2045 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2046 psz_text = psz_word;
2052 /* Release the module list */
2053 vlc_list_release( p_list );
2055 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2056 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2061 /*****************************************************************************
2062 * ListModules: list the available modules with their description
2063 *****************************************************************************
2064 * Print a list of all available modules (builtins and plugins) and a short
2065 * description for each one.
2066 *****************************************************************************/
2067 static void ListModules( vlc_t *p_this )
2071 char psz_spaces[22];
2074 memset( psz_spaces, ' ', 22 );
2081 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
2082 p_this->p_vlc->psz_object_name );
2084 fprintf( stdout, _("[module] [description]\n") );
2086 /* List all modules */
2087 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2089 /* Enumerate each module */
2090 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2094 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2096 /* Nasty hack, but right now I'm too tired to think about a nice
2098 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2102 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2103 psz_spaces, p_parser->psz_longname );
2105 psz_spaces[i] = ' ';
2108 vlc_list_release( p_list );
2110 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2111 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2116 /*****************************************************************************
2117 * Version: print complete program version
2118 *****************************************************************************
2119 * Print complete program version and build number.
2120 *****************************************************************************/
2121 static void Version( void )
2127 fprintf( stdout, VERSION_MESSAGE "\n" );
2129 _("This program comes with NO WARRANTY, to the extent permitted by "
2130 "law.\nYou may redistribute it under the terms of the GNU General "
2131 "Public License;\nsee the file named COPYING for details.\n"
2132 "Written by the VideoLAN team; see the AUTHORS file.\n") );
2134 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2135 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2140 /*****************************************************************************
2141 * ShowConsole: On Win32, create an output console for debug messages
2142 *****************************************************************************
2143 * This function is useful only on Win32.
2144 *****************************************************************************/
2146 static void ShowConsole( void )
2150 freopen( "CONOUT$", "w", stdout );
2151 freopen( "CONOUT$", "w", stderr );
2152 freopen( "CONIN$", "r", stdin );
2158 /*****************************************************************************
2159 * ConsoleWidth: Return the console width in characters
2160 *****************************************************************************
2161 * We use the stty shell command to get the console width; if this fails or
2162 * if the width is less than 80, we default to 80.
2163 *****************************************************************************/
2164 static int ConsoleWidth( void )
2169 char buf[20], *psz_parser;
2173 file = popen( "stty size 2>/dev/null", "r" );
2176 i_ret = fread( buf, 1, 20, file );
2180 psz_parser = strchr( buf, ' ' );
2183 i_ret = atoi( psz_parser + 1 );
2198 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2199 vlc_value_t old_val, vlc_value_t new_val, void *param)
2201 vlc_t *p_vlc = (vlc_t *)p_this;
2203 if( new_val.i_int >= -1 )
2205 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );