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;
575 * Initialize hotkey handling
577 var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
578 p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
579 /* Do a copy (we don't need to modify the strings) */
580 memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
583 * Initialize playlist and get commandline files
585 p_playlist = playlist_Create( p_vlc );
588 msg_Err( p_vlc, "playlist initialization failed" );
589 if( p_vlc->p_memcpy_module != NULL )
591 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
593 module_EndBank( p_vlc );
594 if( i_object ) vlc_object_release( p_vlc );
599 * Load background interfaces
601 psz_modules = config_GetPsz( p_vlc, "extraintf" );
602 psz_parser = psz_modules;
603 while ( psz_parser && *psz_parser )
605 char *psz_module, *psz_temp;
606 psz_module = psz_parser;
607 psz_parser = strchr( psz_module, ',' );
613 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
616 sprintf( psz_temp, "%s,none", psz_module );
617 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
627 * Allways load the hotkeys interface if it exists
629 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
632 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
634 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
635 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
636 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
637 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
638 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
639 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
640 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
641 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
642 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
643 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
644 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
645 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
648 * Get input filenames given as commandline arguments
650 GetFilenames( p_vlc, i_argc, ppsz_argv );
652 if( i_object ) vlc_object_release( p_vlc );
656 /*****************************************************************************
657 * VLC_AddIntf: add an interface
658 *****************************************************************************
659 * This function opens an interface plugin and runs it. If b_block is set
660 * to 0, VLC_AddIntf will return immediately and let the interface run in a
661 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
662 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
663 * the playlist when it is completely initialised.
664 *****************************************************************************/
665 int VLC_AddIntf( int i_object, char const *psz_module,
666 vlc_bool_t b_block, vlc_bool_t b_play )
669 intf_thread_t *p_intf;
670 vlc_t *p_vlc = vlc_current_object( i_object );
677 /* Try to create the interface */
678 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
682 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
683 if( i_object ) vlc_object_release( p_vlc );
687 /* Interface doesn't handle play on start so do it ourselves */
688 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
690 /* Try to run the interface */
691 p_intf->b_play = b_play;
692 p_intf->b_block = b_block;
693 i_err = intf_RunThread( p_intf );
696 vlc_object_detach( p_intf );
697 intf_Destroy( p_intf );
698 if( i_object ) vlc_object_release( p_vlc );
702 if( i_object ) vlc_object_release( p_vlc );
706 /*****************************************************************************
707 * VLC_Die: ask vlc to die.
708 *****************************************************************************
709 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
710 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
711 *****************************************************************************/
712 int VLC_Die( int i_object )
714 vlc_t *p_vlc = vlc_current_object( i_object );
721 p_vlc->b_die = VLC_TRUE;
723 if( i_object ) vlc_object_release( p_vlc );
727 /*****************************************************************************
728 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
729 *****************************************************************************/
730 int VLC_CleanUp( int i_object )
732 intf_thread_t * p_intf;
733 playlist_t * p_playlist;
734 vout_thread_t * p_vout;
735 aout_instance_t * p_aout;
736 announce_handler_t * p_announce;
737 vlc_t *p_vlc = vlc_current_object( i_object );
739 /* Check that the handle is valid */
746 * Ask the interfaces to stop and destroy them
748 msg_Dbg( p_vlc, "removing all interfaces" );
749 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
751 intf_StopThread( p_intf );
752 vlc_object_detach( p_intf );
753 vlc_object_release( p_intf );
754 intf_Destroy( p_intf );
760 msg_Dbg( p_vlc, "removing all playlists" );
761 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
764 vlc_object_detach( p_playlist );
765 vlc_object_release( p_playlist );
766 playlist_Destroy( p_playlist );
772 msg_Dbg( p_vlc, "removing all video outputs" );
773 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
775 vlc_object_detach( p_vout );
776 vlc_object_release( p_vout );
777 vout_Destroy( p_vout );
783 msg_Dbg( p_vlc, "removing all audio outputs" );
784 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
786 vlc_object_detach( (vlc_object_t *)p_aout );
787 vlc_object_release( (vlc_object_t *)p_aout );
788 aout_Delete( p_aout );
792 * Free announce handler(s?)
794 msg_Dbg( p_vlc, "removing announce handler" );
795 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
798 vlc_object_detach( p_announce );
799 vlc_object_release( p_announce );
800 announce_HandlerDestroy( p_announce );
803 if( i_object ) vlc_object_release( p_vlc );
807 /*****************************************************************************
808 * VLC_Destroy: Destroy everything.
809 *****************************************************************************
810 * This function requests the running threads to finish, waits for their
811 * termination, and destroys their structure.
812 *****************************************************************************/
813 int VLC_Destroy( int i_object )
815 vlc_t *p_vlc = vlc_current_object( i_object );
823 * Free allocated memory
825 if( p_vlc->p_memcpy_module )
827 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
828 p_vlc->p_memcpy_module = NULL;
834 module_EndBank( p_vlc );
836 if( p_vlc->psz_homedir )
838 free( p_vlc->psz_homedir );
839 p_vlc->psz_homedir = NULL;
842 if( p_vlc->psz_configfile )
844 free( p_vlc->psz_configfile );
845 p_vlc->psz_configfile = NULL;
848 if( p_vlc->p_hotkeys )
850 free( p_vlc->p_hotkeys );
851 p_vlc->p_hotkeys = NULL;
855 * System specific cleaning code
859 /* Destroy mutexes */
860 vlc_mutex_destroy( &p_vlc->config_lock );
862 vlc_object_detach( p_vlc );
864 /* Release object before destroying it */
865 if( i_object ) vlc_object_release( p_vlc );
867 vlc_object_destroy( p_vlc );
869 /* Stop thread system: last one out please shut the door! */
870 vlc_threads_end( p_libvlc );
875 /*****************************************************************************
876 * VLC_VariableSet: set a vlc variable
877 *****************************************************************************/
878 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
880 vlc_t *p_vlc = vlc_current_object( i_object );
888 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
889 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
890 if( !strncmp( psz_var, "conf::", 6 ) )
892 module_config_t *p_item;
893 char const *psz_newvar = psz_var + 6;
895 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
899 switch( p_item->i_type )
901 case CONFIG_ITEM_BOOL:
902 config_PutInt( p_vlc, psz_newvar, value.b_bool );
904 case CONFIG_ITEM_INTEGER:
905 config_PutInt( p_vlc, psz_newvar, value.i_int );
907 case CONFIG_ITEM_FLOAT:
908 config_PutFloat( p_vlc, psz_newvar, value.f_float );
911 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
914 if( i_object ) vlc_object_release( p_vlc );
919 i_ret = var_Set( p_vlc, psz_var, value );
921 if( i_object ) vlc_object_release( p_vlc );
925 /*****************************************************************************
926 * VLC_VariableGet: get a vlc variable
927 *****************************************************************************/
928 int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
930 vlc_t *p_vlc = vlc_current_object( i_object );
938 i_ret = var_Get( p_vlc, psz_var, p_value );
940 if( i_object ) vlc_object_release( p_vlc );
944 /*****************************************************************************
945 * VLC_AddTarget: adds a target for playing.
946 *****************************************************************************
947 * This function adds psz_target to the current playlist. If a playlist does
948 * not exist, it will create one.
949 *****************************************************************************/
950 int VLC_AddTarget( int i_object, char const *psz_target,
951 char const **ppsz_options, int i_options,
952 int i_mode, int i_pos )
955 playlist_t *p_playlist;
956 vlc_t *p_vlc = vlc_current_object( i_object );
963 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
965 if( p_playlist == NULL )
967 msg_Dbg( p_vlc, "no playlist present, creating one" );
968 p_playlist = playlist_Create( p_vlc );
970 if( p_playlist == NULL )
972 if( i_object ) vlc_object_release( p_vlc );
976 vlc_object_yield( p_playlist );
979 i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
980 i_mode, i_pos, -1, ppsz_options, i_options);
982 vlc_object_release( p_playlist );
984 if( i_object ) vlc_object_release( p_vlc );
988 /*****************************************************************************
990 *****************************************************************************/
991 int VLC_Play( int i_object )
993 playlist_t * p_playlist;
994 vlc_t *p_vlc = vlc_current_object( i_object );
996 /* Check that the handle is valid */
1002 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1006 if( i_object ) vlc_object_release( p_vlc );
1010 playlist_Play( p_playlist );
1011 vlc_object_release( p_playlist );
1013 if( i_object ) vlc_object_release( p_vlc );
1017 /*****************************************************************************
1018 * VLC_Pause: toggle pause
1019 *****************************************************************************/
1020 int VLC_Pause( int i_object )
1022 playlist_t * p_playlist;
1023 vlc_t *p_vlc = vlc_current_object( i_object );
1025 /* Check that the handle is valid */
1031 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1035 if( i_object ) vlc_object_release( p_vlc );
1039 playlist_Pause( p_playlist );
1040 vlc_object_release( p_playlist );
1042 if( i_object ) vlc_object_release( p_vlc );
1046 /*****************************************************************************
1047 * VLC_Pause: toggle pause
1048 *****************************************************************************/
1049 int VLC_Stop( int i_object )
1051 playlist_t * p_playlist;
1052 vlc_t *p_vlc = vlc_current_object( i_object );
1054 /* Check that the handle is valid */
1060 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1064 if( i_object ) vlc_object_release( p_vlc );
1068 playlist_Stop( p_playlist );
1069 vlc_object_release( p_playlist );
1071 if( i_object ) vlc_object_release( p_vlc );
1075 /*****************************************************************************
1076 * VLC_IsPlaying: Query for Playlist Status
1077 *****************************************************************************/
1078 vlc_bool_t VLC_IsPlaying( int i_object )
1080 playlist_t * p_playlist;
1081 vlc_bool_t b_playing;
1083 vlc_t *p_vlc = vlc_current_object( i_object );
1085 /* Check that the handle is valid */
1091 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1095 if( i_object ) vlc_object_release( p_vlc );
1099 b_playing = playlist_IsPlaying( p_playlist );
1100 vlc_object_release( p_playlist );
1102 if( i_object ) vlc_object_release( p_vlc );
1107 * Get the current position in a input
1109 * Return the current position as a float
1110 * \note For some inputs, this will be unknown.
1112 * \param i_object a vlc object id
1113 * \return a float in the range of 0.0 - 1.0
1115 float VLC_PositionGet( int i_object )
1117 input_thread_t *p_input;
1119 vlc_t *p_vlc = vlc_current_object( i_object );
1121 /* Check that the handle is valid */
1127 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1131 if( i_object ) vlc_object_release( p_vlc );
1135 var_Get( p_input, "position", &val );
1136 vlc_object_release( p_input );
1138 if( i_object ) vlc_object_release( p_vlc );
1143 * Set the current position in a input
1145 * Set the current position in a input and then return
1146 * the current position as a float.
1147 * \note For some inputs, this will be unknown.
1149 * \param i_object a vlc object id
1150 * \param i_position a float in the range of 0.0 - 1.0
1151 * \return a float in the range of 0.0 - 1.0
1153 float VLC_PositionSet( int i_object, float i_position )
1155 input_thread_t *p_input;
1157 vlc_t *p_vlc = vlc_current_object( i_object );
1159 /* Check that the handle is valid */
1165 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1169 if( i_object ) vlc_object_release( p_vlc );
1173 val.f_float = i_position;
1174 var_Set( p_input, "position", val );
1175 var_Get( p_input, "position", &val );
1176 vlc_object_release( p_input );
1178 if( i_object ) vlc_object_release( p_vlc );
1183 * Get the current position in a input
1185 * Return the current position in seconds from the start.
1186 * \note For some inputs, this will be unknown.
1188 * \param i_object a vlc object id
1189 * \return the offset from 0:00 in seconds
1191 int VLC_TimeGet( int i_object )
1193 input_thread_t *p_input;
1195 vlc_t *p_vlc = vlc_current_object( i_object );
1197 /* Check that the handle is valid */
1203 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1207 if( i_object ) vlc_object_release( p_vlc );
1211 var_Get( p_input, "time", &val );
1212 vlc_object_release( p_input );
1214 if( i_object ) vlc_object_release( p_vlc );
1215 return val.i_time / 1000000;
1219 * Seek to a position in the current input
1221 * Seek i_seconds in the current input. If b_relative is set,
1222 * then the seek will be relative to the current position, otherwise
1223 * it will seek to i_seconds from the beginning of the input.
1224 * \note For some inputs, this will be unknown.
1226 * \param i_object a vlc object id
1227 * \param i_seconds seconds from current position or from beginning of input
1228 * \param b_relative seek relative from current position
1229 * \return VLC_SUCCESS on success
1231 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1233 input_thread_t *p_input;
1235 vlc_t *p_vlc = vlc_current_object( i_object );
1237 /* Check that the handle is valid */
1243 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1247 if( i_object ) vlc_object_release( p_vlc );
1253 val.i_time = i_seconds * 1000000;
1254 var_Set( p_input, "time-offset", val );
1258 val.i_time = i_seconds * 1000000;
1259 var_Set( p_input, "time", val );
1261 vlc_object_release( p_input );
1263 if( i_object ) vlc_object_release( p_vlc );
1268 * Get the total length of a input
1270 * Return the total length in seconds from the current input.
1271 * \note For some inputs, this will be unknown.
1273 * \param i_object a vlc object id
1274 * \return the length in seconds
1276 int VLC_LengthGet( int i_object )
1278 input_thread_t *p_input;
1280 vlc_t *p_vlc = vlc_current_object( i_object );
1282 /* Check that the handle is valid */
1288 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1292 if( i_object ) vlc_object_release( p_vlc );
1296 var_Get( p_input, "length", &val );
1297 vlc_object_release( p_input );
1299 if( i_object ) vlc_object_release( p_vlc );
1300 return val.i_time / 1000000;
1304 * Play the input faster than realtime
1306 * 2x, 4x, 8x faster than realtime
1307 * \note For some inputs, this will be impossible.
1309 * \param i_object a vlc object id
1310 * \return the current speedrate
1312 float VLC_SpeedFaster( int i_object )
1314 input_thread_t *p_input;
1316 vlc_t *p_vlc = vlc_current_object( i_object );
1318 /* Check that the handle is valid */
1324 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1328 if( i_object ) vlc_object_release( p_vlc );
1332 val.b_bool = VLC_TRUE;
1333 var_Set( p_input, "rate-faster", val );
1334 var_Get( p_input, "rate", &val );
1335 vlc_object_release( p_input );
1337 if( i_object ) vlc_object_release( p_vlc );
1338 return val.f_float / INPUT_RATE_DEFAULT;
1342 * Play the input slower than realtime
1344 * 1/2x, 1/4x, 1/8x slower than realtime
1345 * \note For some inputs, this will be impossible.
1347 * \param i_object a vlc object id
1348 * \return the current speedrate
1350 float VLC_SpeedSlower( int i_object )
1352 input_thread_t *p_input;
1354 vlc_t *p_vlc = vlc_current_object( i_object );
1356 /* Check that the handle is valid */
1362 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1366 if( i_object ) vlc_object_release( p_vlc );
1370 val.b_bool = VLC_TRUE;
1371 var_Set( p_input, "rate-slower", val );
1372 var_Get( p_input, "rate", &val );
1373 vlc_object_release( p_input );
1375 if( i_object ) vlc_object_release( p_vlc );
1376 return val.f_float / INPUT_RATE_DEFAULT;
1380 * Return the current playlist item
1382 * Returns the index of the playlistitem that is currently selected for play.
1383 * This is valid even if nothing is currently playing.
1385 * \param i_object a vlc object id
1386 * \return the current index
1388 int VLC_PlaylistIndex( int i_object )
1391 playlist_t * p_playlist;
1392 vlc_t *p_vlc = vlc_current_object( i_object );
1394 /* Check that the handle is valid */
1400 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1404 if( i_object ) vlc_object_release( p_vlc );
1408 i_index = p_playlist->i_index;
1409 vlc_object_release( p_playlist );
1411 if( i_object ) vlc_object_release( p_vlc );
1416 * Total amount of items in the playlist
1418 * \param i_object a vlc object id
1419 * \return amount of playlist items
1421 int VLC_PlaylistNumberOfItems( int i_object )
1424 playlist_t * p_playlist;
1425 vlc_t *p_vlc = vlc_current_object( i_object );
1427 /* Check that the handle is valid */
1433 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1437 if( i_object ) vlc_object_release( p_vlc );
1441 i_size = p_playlist->i_size;
1442 vlc_object_release( p_playlist );
1444 if( i_object ) vlc_object_release( p_vlc );
1449 * Next playlist item
1451 * Skip to the next playlistitem and play it.
1453 * \param i_object a vlc object id
1454 * \return VLC_SUCCESS on success
1456 int VLC_PlaylistNext( int i_object )
1458 playlist_t * p_playlist;
1459 vlc_t *p_vlc = vlc_current_object( i_object );
1461 /* Check that the handle is valid */
1467 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1471 if( i_object ) vlc_object_release( p_vlc );
1475 playlist_Next( p_playlist );
1476 vlc_object_release( p_playlist );
1478 if( i_object ) vlc_object_release( p_vlc );
1483 * Previous playlist item
1485 * Skip to the previous playlistitem and play it.
1487 * \param i_object a vlc object id
1488 * \return VLC_SUCCESS on success
1490 int VLC_PlaylistPrev( int i_object )
1492 playlist_t * p_playlist;
1493 vlc_t *p_vlc = vlc_current_object( i_object );
1495 /* Check that the handle is valid */
1501 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1505 if( i_object ) vlc_object_release( p_vlc );
1509 playlist_Prev( p_playlist );
1510 vlc_object_release( p_playlist );
1512 if( i_object ) vlc_object_release( p_vlc );
1517 /*****************************************************************************
1518 * VLC_PlaylistClear: Empty the playlist
1519 *****************************************************************************/
1520 int VLC_PlaylistClear( int i_object )
1523 playlist_t * p_playlist;
1524 vlc_t *p_vlc = vlc_current_object( i_object );
1526 /* Check that the handle is valid */
1532 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1536 if( i_object ) vlc_object_release( p_vlc );
1540 i_err = playlist_Clear( p_playlist );
1542 vlc_object_release( p_playlist );
1544 if( i_object ) vlc_object_release( p_vlc );
1551 * \param i_object a vlc object id
1552 * \param i_volume something in a range from 0-200
1553 * \return the new volume (range 0-200 %)
1555 int VLC_VolumeSet( int i_object, int i_volume )
1557 audio_volume_t i_vol = 0;
1558 vlc_t *p_vlc = vlc_current_object( i_object );
1560 /* Check that the handle is valid */
1566 if( i_volume >= 0 && i_volume <= 200 )
1568 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1569 aout_VolumeSet( p_vlc, i_vol );
1572 if( i_object ) vlc_object_release( p_vlc );
1573 return i_vol * 200 / AOUT_VOLUME_MAX;
1577 * Get the current volume
1579 * Retrieve the current volume.
1581 * \param i_object a vlc object id
1582 * \return the current volume (range 0-200 %)
1584 int VLC_VolumeGet( int i_object )
1586 audio_volume_t i_volume;
1587 vlc_t *p_vlc = vlc_current_object( i_object );
1589 /* Check that the handle is valid */
1595 aout_VolumeGet( p_vlc, &i_volume );
1597 if( i_object ) vlc_object_release( p_vlc );
1598 return i_volume*200/AOUT_VOLUME_MAX;
1602 * Mute/Unmute the volume
1604 * \param i_object a vlc object id
1605 * \return VLC_SUCCESS on success
1607 int VLC_VolumeMute( int i_object )
1609 vlc_t *p_vlc = vlc_current_object( i_object );
1611 /* Check that the handle is valid */
1617 aout_VolumeMute( p_vlc, NULL );
1619 if( i_object ) vlc_object_release( p_vlc );
1623 /*****************************************************************************
1624 * VLC_FullScreen: toggle fullscreen mode
1625 *****************************************************************************/
1626 int VLC_FullScreen( int i_object )
1628 vout_thread_t *p_vout;
1629 vlc_t *p_vlc = vlc_current_object( i_object );
1636 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1640 if( i_object ) vlc_object_release( p_vlc );
1644 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1645 vlc_object_release( p_vout );
1647 if( i_object ) vlc_object_release( p_vlc );
1651 /* following functions are local */
1653 /*****************************************************************************
1654 * SetLanguage: set the interface language.
1655 *****************************************************************************
1656 * We set the LC_MESSAGES locale category for interface messages and buttons,
1657 * as well as the LC_CTYPE category for string sorting and possible wide
1658 * character support.
1659 *****************************************************************************/
1660 static void SetLanguage ( char const *psz_lang )
1662 #if defined( ENABLE_NLS ) \
1663 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1666 #if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
1670 if( psz_lang && !*psz_lang )
1672 # if defined( HAVE_LC_MESSAGES )
1673 setlocale( LC_MESSAGES, psz_lang );
1675 setlocale( LC_CTYPE, psz_lang );
1680 /* I need that under Darwin, please check it doesn't disturb
1681 * other platforms. --Meuuh */
1682 setenv( "LANG", psz_lang, 1 );
1684 #elif defined( SYS_BEOS ) || defined( WIN32 )
1685 /* We set LC_ALL manually because it is the only way to set
1686 * the language at runtime under eg. Windows. Beware that this
1687 * makes the environment unconsistent when libvlc is unloaded and
1688 * should probably be moved to a safer place like vlc.c. */
1689 static char psz_lcall[20];
1690 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1691 psz_lcall[19] = '\0';
1692 putenv( psz_lcall );
1695 setlocale( LC_ALL, psz_lang );
1698 /* Specify where to find the locales for current domain */
1699 #if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1700 psz_path = LOCALEDIR;
1702 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1706 if( !bindtextdomain( PACKAGE, psz_path ) )
1708 fprintf( stderr, "warning: no domain %s in directory %s\n",
1709 PACKAGE, psz_path );
1712 /* Set the default domain */
1713 textdomain( PACKAGE );
1715 #if defined( ENABLE_UTF8 )
1716 bind_textdomain_codeset( PACKAGE, "UTF-8" );
1722 /*****************************************************************************
1723 * GetFilenames: parse command line options which are not flags
1724 *****************************************************************************
1725 * Parse command line for input files as well as their associated options.
1726 * An option always follows its associated input and begins with a ":".
1727 *****************************************************************************/
1728 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1730 int i_opt, i_options;
1732 /* We assume that the remaining parameters are filenames
1733 * and their input options */
1734 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
1738 /* Count the input options */
1739 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
1745 /* TODO: write an internal function of this one, to avoid
1746 * unnecessary lookups. */
1747 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1748 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
1750 PLAYLIST_INSERT, 0 );
1756 /*****************************************************************************
1757 * Usage: print program usage
1758 *****************************************************************************
1759 * Print a short inline help. Message interface is initialized at this stage.
1760 *****************************************************************************/
1761 static void Usage( vlc_t *p_this, char const *psz_module_name )
1763 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1764 /* short option ------' | | | | | | |
1765 * option name ------------' | | | | | |
1766 * <bra -------------------------' | | | | |
1767 * option type or "" --------------' | | | |
1768 * ket> -----------------------------' | | |
1769 * padding spaces ---------------------' | |
1770 * comment -------------------------------' |
1771 * comment suffix --------------------------'
1773 * The purpose of having bra and ket is that we might i18n them as well.
1775 #define LINE_START 8
1776 #define PADDING_SPACES 25
1779 module_config_t *p_item;
1780 char psz_spaces[PADDING_SPACES+LINE_START+1];
1781 char psz_format[sizeof(FORMAT_STRING)];
1782 char psz_buffer[1000];
1785 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1786 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
1788 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1789 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1791 strcpy( psz_format, FORMAT_STRING );
1797 /* List all modules */
1798 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1800 /* Enumerate the config for each module */
1801 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1803 vlc_bool_t b_help_module;
1805 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1807 if( psz_module_name && strcmp( psz_module_name,
1808 p_parser->psz_object_name ) )
1813 /* Ignore modules without config options */
1814 if( !p_parser->i_config_items )
1819 /* Ignore modules with only advanced config options if requested */
1822 for( p_item = p_parser->p_config;
1823 p_item->i_type != CONFIG_HINT_END;
1826 if( (p_item->i_type & CONFIG_ITEM) &&
1827 !p_item->b_advanced ) break;
1829 if( p_item->i_type == CONFIG_HINT_END ) continue;
1832 /* Print name of module */
1833 if( strcmp( "main", p_parser->psz_object_name ) )
1834 fprintf( stdout, "\n %s\n", p_parser->psz_longname );
1836 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1838 /* Print module options */
1839 for( p_item = p_parser->p_config;
1840 p_item->i_type != CONFIG_HINT_END;
1844 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1845 char *psz_suf = "", *psz_prefix = NULL;
1848 /* Skip advanced options if requested */
1849 if( p_item->b_advanced && !b_advanced )
1854 switch( p_item->i_type )
1856 case CONFIG_HINT_CATEGORY:
1857 case CONFIG_HINT_USAGE:
1858 if( !strcmp( "main", p_parser->psz_object_name ) )
1859 fprintf( stdout, "\n %s\n", p_item->psz_text );
1862 case CONFIG_ITEM_STRING:
1863 case CONFIG_ITEM_FILE:
1864 case CONFIG_ITEM_DIRECTORY:
1865 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1866 if( !p_item->ppsz_list )
1868 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1874 psz_type = psz_buffer;
1876 for( i = 0; p_item->ppsz_list[i]; i++ )
1878 if( i ) strcat( psz_type, "," );
1879 strcat( psz_type, p_item->ppsz_list[i] );
1884 case CONFIG_ITEM_INTEGER:
1885 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
1886 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1888 case CONFIG_ITEM_FLOAT:
1889 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1891 case CONFIG_ITEM_BOOL:
1892 psz_bra = ""; psz_type = ""; psz_ket = "";
1893 if( !b_help_module )
1895 psz_suf = p_item->i_value ? _(" (default enabled)") :
1896 _(" (default disabled)");
1906 /* Add short option if any */
1907 if( p_item->i_short )
1909 sprintf( psz_short, "-%c,", p_item->i_short );
1913 strcpy( psz_short, " " );
1916 i = PADDING_SPACES - strlen( p_item->psz_name )
1917 - strlen( psz_bra ) - strlen( psz_type )
1918 - strlen( psz_ket ) - 1;
1920 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1922 /* If option is of type --foo-bar, we print its counterpart
1923 * as --no-foo-bar, but if it is of type --foobar (without
1924 * dashes in the name) we print it as --nofoobar. Both
1925 * values are of course valid, only the display changes. */
1926 psz_prefix = strchr( p_item->psz_name, '-' ) ? ", --no-"
1928 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
1933 psz_spaces[0] = '\n';
1938 psz_spaces[i] = '\0';
1941 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1943 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1944 psz_prefix, p_item->psz_name, psz_bra, psz_type,
1945 psz_ket, psz_spaces );
1949 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1950 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
1953 psz_spaces[i] = ' ';
1955 /* We wrap the rest of the output */
1956 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
1957 psz_text = psz_buffer;
1960 char *psz_parser, *psz_word;
1961 int i_end = strlen( psz_text );
1963 /* If the remaining text fits in a line, print it. */
1964 if( i_end <= i_width )
1966 fprintf( stdout, "%s\n", psz_text );
1970 /* Otherwise, eat as many words as possible */
1971 psz_parser = psz_text;
1974 psz_word = psz_parser;
1975 psz_parser = strchr( psz_word, ' ' );
1976 /* If no space was found, we reached the end of the text
1977 * block; otherwise, we skip the space we just found. */
1978 psz_parser = psz_parser ? psz_parser + 1
1981 } while( psz_parser - psz_text <= i_width );
1983 /* We cut a word in one of these cases:
1984 * - it's the only word in the line and it's too long.
1985 * - we used less than 80% of the width and the word we are
1986 * going to wrap is longer than 40% of the width, and even
1987 * if the word would have fit in the next line. */
1988 if( psz_word == psz_text
1989 || ( psz_word - psz_text < 80 * i_width / 100
1990 && psz_parser - psz_word > 40 * i_width / 100 ) )
1992 char c = psz_text[i_width];
1993 psz_text[i_width] = '\0';
1994 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
1995 psz_text += i_width;
2000 psz_word[-1] = '\0';
2001 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2002 psz_text = psz_word;
2008 /* Release the module list */
2009 vlc_list_release( p_list );
2011 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2012 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2017 /*****************************************************************************
2018 * ListModules: list the available modules with their description
2019 *****************************************************************************
2020 * Print a list of all available modules (builtins and plugins) and a short
2021 * description for each one.
2022 *****************************************************************************/
2023 static void ListModules( vlc_t *p_this )
2027 char psz_spaces[22];
2030 memset( psz_spaces, ' ', 22 );
2037 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
2038 p_this->p_vlc->psz_object_name );
2040 fprintf( stdout, _("[module] [description]\n") );
2042 /* List all modules */
2043 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2045 /* Enumerate each module */
2046 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2050 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2052 /* Nasty hack, but right now I'm too tired to think about a nice
2054 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2058 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2059 psz_spaces, p_parser->psz_longname );
2061 psz_spaces[i] = ' ';
2064 vlc_list_release( p_list );
2066 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2067 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2072 /*****************************************************************************
2073 * Version: print complete program version
2074 *****************************************************************************
2075 * Print complete program version and build number.
2076 *****************************************************************************/
2077 static void Version( void )
2083 fprintf( stdout, VERSION_MESSAGE "\n" );
2085 _("This program comes with NO WARRANTY, to the extent permitted by "
2086 "law.\nYou may redistribute it under the terms of the GNU General "
2087 "Public License;\nsee the file named COPYING for details.\n"
2088 "Written by the VideoLAN team; see the AUTHORS file.\n") );
2090 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2091 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2096 /*****************************************************************************
2097 * ShowConsole: On Win32, create an output console for debug messages
2098 *****************************************************************************
2099 * This function is useful only on Win32.
2100 *****************************************************************************/
2102 static void ShowConsole( void )
2106 freopen( "CONOUT$", "w", stdout );
2107 freopen( "CONOUT$", "w", stderr );
2108 freopen( "CONIN$", "r", stdin );
2114 /*****************************************************************************
2115 * ConsoleWidth: Return the console width in characters
2116 *****************************************************************************
2117 * We use the stty shell command to get the console width; if this fails or
2118 * if the width is less than 80, we default to 80.
2119 *****************************************************************************/
2120 static int ConsoleWidth( void )
2125 char buf[20], *psz_parser;
2129 file = popen( "stty size 2>/dev/null", "r" );
2132 i_ret = fread( buf, 1, 20, file );
2136 psz_parser = strchr( buf, ' ' );
2139 i_ret = atoi( psz_parser + 1 );
2154 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2155 vlc_value_t old_val, vlc_value_t new_val, void *param)
2157 vlc_t *p_vlc = (vlc_t *)p_this;
2159 if( new_val.i_int >= -1 )
2161 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );