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 *****************************************************************************/
40 # include <errno.h> /* ENOMEM */
42 #include <stdio.h> /* sprintf() */
43 #include <string.h> /* strerror() */
44 #include <stdlib.h> /* free() */
47 # include <netinet/in.h> /* BSD: struct in_addr */
52 #elif defined( WIN32 ) && !defined( UNDER_CE )
56 #ifdef WIN32 /* optind, getopt(), included in unistd.h */
57 # include "extras/getopt.h"
64 #include "vlc_cpu.h" /* CPU detection */
65 #include "os_specific.h"
67 #include "vlc_error.h"
69 #include "stream_control.h"
70 #include "input_ext-intf.h"
72 #include "vlc_playlist.h"
73 #include "vlc_interface.h"
75 #include "audio_output.h"
77 #include "vlc_video.h"
78 #include "video_output.h"
80 #include "stream_output.h"
84 /*****************************************************************************
85 * The evil global variable. We handle it with care, don't worry.
86 *****************************************************************************/
87 static libvlc_t libvlc;
88 static libvlc_t * p_libvlc;
89 static vlc_t * p_static_vlc;
91 /*****************************************************************************
93 *****************************************************************************/
94 static void SetLanguage ( char const * );
95 static int GetFilenames ( vlc_t *, int, char *[] );
96 static void Usage ( vlc_t *, char const *psz_module_name );
97 static void ListModules ( vlc_t * );
98 static void Version ( void );
101 static void ShowConsole ( void );
103 static int ConsoleWidth ( void );
105 static int VerboseCallback( vlc_object_t *, char const *,
106 vlc_value_t, vlc_value_t, void * );
108 /*****************************************************************************
109 * vlc_current_object: return the current object.
110 *****************************************************************************
111 * If i_object is non-zero, return the corresponding object. Otherwise,
112 * return the statically allocated p_vlc object.
113 *****************************************************************************/
114 vlc_t * vlc_current_object( int i_object )
118 return vlc_object_get( p_libvlc, i_object );
124 /*****************************************************************************
125 * VLC_Version: return the libvlc version.
126 *****************************************************************************
127 * This function returns full version string (numeric version and codename).
128 *****************************************************************************/
129 char const * VLC_Version( void )
131 return VERSION_MESSAGE;
134 /*****************************************************************************
135 * VLC_Error: strerror() equivalent
136 *****************************************************************************
137 * This function returns full version string (numeric version and codename).
138 *****************************************************************************/
139 char const * VLC_Error( int i_err )
141 return vlc_error( i_err );
144 /*****************************************************************************
145 * VLC_Create: allocate a vlc_t structure, and initialize libvlc if needed.
146 *****************************************************************************
147 * This function allocates a vlc_t structure and returns a negative value
148 * in case of failure. Also, the thread system is initialized.
149 *****************************************************************************/
150 int VLC_Create( void )
153 vlc_t * p_vlc = NULL;
156 /* &libvlc never changes, so we can safely call this multiple times. */
159 /* vlc_threads_init *must* be the first internal call! No other call is
160 * allowed before the thread system has been initialized. */
161 i_ret = vlc_threads_init( p_libvlc );
167 /* Now that the thread system is initialized, we don't have much, but
168 * at least we have var_Create */
169 var_Create( p_libvlc, "libvlc", VLC_VAR_MUTEX );
170 var_Get( p_libvlc, "libvlc", &lockval );
171 vlc_mutex_lock( lockval.p_address );
172 if( !libvlc.b_ready )
176 /* Guess what CPU we have */
177 libvlc.i_cpu = CPUCapabilities();
179 /* Find verbosity from VLC_VERBOSE environment variable */
180 psz_env = getenv( "VLC_VERBOSE" );
181 libvlc.i_verbose = psz_env ? atoi( psz_env ) : -1;
183 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
184 libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
186 libvlc.b_color = VLC_FALSE;
189 /* Initialize message queue */
190 msg_Create( p_libvlc );
192 /* Announce who we are */
193 msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE );
194 msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
196 /* The module bank will be initialized later */
197 libvlc.p_module_bank = NULL;
199 libvlc.b_ready = VLC_TRUE;
201 vlc_mutex_unlock( lockval.p_address );
202 var_Destroy( p_libvlc, "libvlc" );
204 /* Allocate a vlc object */
205 p_vlc = vlc_object_create( p_libvlc, VLC_OBJECT_VLC );
210 p_vlc->thread_id = 0;
211 vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
213 p_vlc->psz_object_name = "root";
215 /* Initialize mutexes */
216 vlc_mutex_init( p_vlc, &p_vlc->config_lock );
218 vlc_mutex_init( p_vlc, &p_vlc->quicktime_lock );
221 /* Store our newly allocated structure in the global list */
222 vlc_object_attach( p_vlc, p_libvlc );
224 /* Store data for the non-reentrant API */
225 p_static_vlc = p_vlc;
227 return p_vlc->i_object_id;
230 /*****************************************************************************
231 * VLC_Init: initialize a vlc_t structure.
232 *****************************************************************************
233 * This function initializes a previously allocated vlc_t structure:
235 * - gettext initialization
236 * - message queue, module bank and playlist initialization
237 * - configuration and commandline parsing
238 *****************************************************************************/
239 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
241 char p_capabilities[200];
246 vlc_bool_t b_exit = VLC_FALSE;
247 vlc_t * p_vlc = vlc_current_object( i_object );
248 module_t *p_help_module;
249 playlist_t *p_playlist;
257 * System specific initialization code
259 system_Init( p_vlc, &i_argc, ppsz_argv );
261 /* Get the executable name (similar to the basename command) */
264 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
267 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
273 p_vlc->psz_object_name = "vlc";
277 * Support for gettext
281 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
282 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
284 /* Initialize the module bank and load the configuration of the
285 * main module. We need to do this at this stage to be able to display
286 * a short help if required by the user. (short help == main module
288 module_InitBank( p_vlc );
290 /* Hack: insert the help module here */
291 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
292 if( p_help_module == NULL )
294 module_EndBank( p_vlc );
295 if( i_object ) vlc_object_release( p_vlc );
298 p_help_module->psz_object_name = "help";
299 p_help_module->psz_longname = N_("Help options");
300 config_Duplicate( p_help_module, p_help_config );
301 vlc_object_attach( p_help_module, libvlc.p_module_bank );
304 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
306 vlc_object_detach( p_help_module );
307 config_Free( p_help_module );
308 vlc_object_destroy( p_help_module );
309 module_EndBank( p_vlc );
310 if( i_object ) vlc_object_release( p_vlc );
314 /* Check for short help option */
315 if( config_GetInt( p_vlc, "help" ) )
317 fprintf( stdout, _("Usage: %s [options] [items]...\n"),
318 p_vlc->psz_object_name );
319 Usage( p_vlc, "main" );
320 Usage( p_vlc, "help" );
323 /* Check for version option */
324 else if( config_GetInt( p_vlc, "version" ) )
330 /* Set the config file stuff */
331 p_vlc->psz_homedir = config_GetHomeDir();
332 p_vlc->psz_configfile = config_GetPsz( p_vlc, "config" );
334 /* Check for plugins cache options */
335 if( config_GetInt( p_vlc, "reset-plugins-cache" ) )
337 libvlc.p_module_bank->b_cache_delete = VLC_TRUE;
340 /* Hack: remove the help module here */
341 vlc_object_detach( p_help_module );
346 config_Free( p_help_module );
347 vlc_object_destroy( p_help_module );
348 module_EndBank( p_vlc );
349 if( i_object ) vlc_object_release( p_vlc );
353 /* Check for translation config option */
354 #if defined( ENABLE_NLS ) \
355 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
357 /* This ain't really nice to have to reload the config here but it seems
358 * the only way to do it. */
359 config_LoadConfigFile( p_vlc, "main" );
360 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
362 /* Check if the user specified a custom language */
363 psz_language = config_GetPsz( p_vlc, "language" );
364 if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
366 vlc_bool_t b_cache_delete = libvlc.p_module_bank->b_cache_delete;
368 /* Reset the default domain */
369 SetLanguage( psz_language );
371 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
372 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
374 textdomain( PACKAGE );
376 #if defined( ENABLE_UTF8 )
377 bind_textdomain_codeset( PACKAGE, "UTF-8" );
380 module_EndBank( p_vlc );
381 module_InitBank( p_vlc );
382 config_LoadConfigFile( p_vlc, "main" );
383 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
384 libvlc.p_module_bank->b_cache_delete = b_cache_delete;
386 if( psz_language ) free( psz_language );
390 * Load the builtins and plugins into the module_bank.
391 * We have to do it before config_Load*() because this also gets the
392 * list of configuration options exported by each module and loads their
395 module_LoadBuiltins( p_vlc );
396 module_LoadPlugins( p_vlc );
402 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
403 libvlc.p_module_bank->i_children );
405 /* Hack: insert the help module here */
406 vlc_object_attach( p_help_module, libvlc.p_module_bank );
409 /* Check for help on modules */
410 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
412 Usage( p_vlc, p_tmp );
416 /* Check for long help option */
417 else if( config_GetInt( p_vlc, "longhelp" ) )
419 Usage( p_vlc, NULL );
422 /* Check for module list option */
423 else if( config_GetInt( p_vlc, "list" ) )
425 ListModules( p_vlc );
429 /* Check for config file options */
430 if( config_GetInt( p_vlc, "reset-config" ) )
432 vlc_object_detach( p_help_module );
433 config_ResetAll( p_vlc );
434 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
435 config_SaveConfigFile( p_vlc, NULL );
436 vlc_object_attach( p_help_module, libvlc.p_module_bank );
438 if( config_GetInt( p_vlc, "save-config" ) )
440 vlc_object_detach( p_help_module );
441 config_LoadConfigFile( p_vlc, NULL );
442 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
443 config_SaveConfigFile( p_vlc, NULL );
444 vlc_object_attach( p_help_module, libvlc.p_module_bank );
447 /* Hack: remove the help module here */
448 vlc_object_detach( p_help_module );
453 config_Free( p_help_module );
454 vlc_object_destroy( p_help_module );
455 module_EndBank( p_vlc );
456 if( i_object ) vlc_object_release( p_vlc );
461 * Override default configuration with config file settings
463 config_LoadConfigFile( p_vlc, NULL );
465 /* Hack: insert the help module here */
466 vlc_object_attach( p_help_module, libvlc.p_module_bank );
470 * Override configuration with command line settings
472 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
476 /* Pause the console because it's destroyed when we exit */
477 fprintf( stderr, "The command line options couldn't be loaded, check "
478 "that they are valid.\nPress the RETURN key to continue..." );
481 vlc_object_detach( p_help_module );
482 config_Free( p_help_module );
483 vlc_object_destroy( p_help_module );
484 module_EndBank( p_vlc );
485 if( i_object ) vlc_object_release( p_vlc );
489 /* Hack: remove the help module here */
490 vlc_object_detach( p_help_module );
491 config_Free( p_help_module );
492 vlc_object_destroy( p_help_module );
496 * System specific configuration
498 system_Configure( p_vlc, &i_argc, ppsz_argv );
501 * Message queue options
504 var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
505 if( config_GetInt( p_vlc, "quiet" ) )
509 var_Set( p_vlc, "verbose", val );
511 var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
512 var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
514 libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
517 * Output messages that may still be in the queue
521 /* p_vlc initialization. FIXME ? */
523 #if defined( __i386__ )
524 if( !config_GetInt( p_vlc, "mmx" ) )
525 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
526 if( !config_GetInt( p_vlc, "3dn" ) )
527 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
528 if( !config_GetInt( p_vlc, "mmxext" ) )
529 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
530 if( !config_GetInt( p_vlc, "sse" ) )
531 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
532 if( !config_GetInt( p_vlc, "sse2" ) )
533 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
535 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
536 if( !config_GetInt( p_vlc, "altivec" ) )
537 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
540 #define PRINT_CAPABILITY( capability, string ) \
541 if( libvlc.i_cpu & capability ) \
543 strncat( p_capabilities, string " ", \
544 sizeof(p_capabilities) - strlen(p_capabilities) ); \
545 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
548 p_capabilities[0] = '\0';
549 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
550 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
551 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
552 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
553 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
554 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
555 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
556 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
557 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
558 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
559 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
562 * Choose the best memcpy module
564 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
566 if( p_vlc->pf_memcpy == NULL )
568 p_vlc->pf_memcpy = memcpy;
571 if( p_vlc->pf_memset == NULL )
573 p_vlc->pf_memset = memset;
577 * Initialize hotkey handling
579 var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
580 p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
581 /* Do a copy (we don't need to modify the strings) */
582 memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
585 * Initialize playlist and get commandline files
587 p_playlist = playlist_Create( p_vlc );
590 msg_Err( p_vlc, "playlist initialization failed" );
591 if( p_vlc->p_memcpy_module != NULL )
593 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
595 module_EndBank( p_vlc );
596 if( i_object ) vlc_object_release( p_vlc );
601 * Load background interfaces
603 psz_modules = config_GetPsz( p_vlc, "extraintf" );
604 psz_parser = psz_modules;
605 while ( psz_parser && *psz_parser )
607 char *psz_module, *psz_temp;
608 psz_module = psz_parser;
609 psz_parser = strchr( psz_module, ',' );
615 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
618 sprintf( psz_temp, "%s,none", psz_module );
619 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
629 * Allways load the hotkeys interface if it exists
631 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
634 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
636 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
637 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
638 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
639 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
640 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
641 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
642 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
643 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
644 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
645 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
646 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
647 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
650 * Get input filenames given as commandline arguments
652 GetFilenames( p_vlc, i_argc, ppsz_argv );
654 if( i_object ) vlc_object_release( p_vlc );
658 /*****************************************************************************
659 * VLC_AddIntf: add an interface
660 *****************************************************************************
661 * This function opens an interface plugin and runs it. If b_block is set
662 * to 0, VLC_AddIntf will return immediately and let the interface run in a
663 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
664 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
665 * the playlist when it is completely initialised.
666 *****************************************************************************/
667 int VLC_AddIntf( int i_object, char const *psz_module,
668 vlc_bool_t b_block, vlc_bool_t b_play )
671 intf_thread_t *p_intf;
672 vlc_t *p_vlc = vlc_current_object( i_object );
679 /* Try to create the interface */
680 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
684 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
685 if( i_object ) vlc_object_release( p_vlc );
689 /* Interface doesn't handle play on start so do it ourselves */
690 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
692 /* Try to run the interface */
693 p_intf->b_play = b_play;
694 p_intf->b_block = b_block;
695 i_err = intf_RunThread( p_intf );
698 vlc_object_detach( p_intf );
699 intf_Destroy( p_intf );
700 if( i_object ) vlc_object_release( p_vlc );
704 if( i_object ) vlc_object_release( p_vlc );
708 /*****************************************************************************
709 * VLC_Die: ask vlc to die.
710 *****************************************************************************
711 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
712 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
713 *****************************************************************************/
714 int VLC_Die( int i_object )
716 vlc_t *p_vlc = vlc_current_object( i_object );
723 p_vlc->b_die = VLC_TRUE;
725 if( i_object ) vlc_object_release( p_vlc );
729 /*****************************************************************************
730 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
731 *****************************************************************************/
732 int VLC_CleanUp( int i_object )
734 intf_thread_t * p_intf;
735 playlist_t * p_playlist;
736 vout_thread_t * p_vout;
737 aout_instance_t * p_aout;
738 announce_handler_t * p_announce;
739 vlc_t *p_vlc = vlc_current_object( i_object );
741 /* Check that the handle is valid */
748 * Ask the interfaces to stop and destroy them
750 msg_Dbg( p_vlc, "removing all interfaces" );
751 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
753 intf_StopThread( p_intf );
754 vlc_object_detach( p_intf );
755 vlc_object_release( p_intf );
756 intf_Destroy( p_intf );
762 msg_Dbg( p_vlc, "removing all playlists" );
763 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
766 vlc_object_detach( p_playlist );
767 vlc_object_release( p_playlist );
768 playlist_Destroy( p_playlist );
774 msg_Dbg( p_vlc, "removing all video outputs" );
775 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
777 vlc_object_detach( p_vout );
778 vlc_object_release( p_vout );
779 vout_Destroy( p_vout );
785 msg_Dbg( p_vlc, "removing all audio outputs" );
786 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
788 vlc_object_detach( (vlc_object_t *)p_aout );
789 vlc_object_release( (vlc_object_t *)p_aout );
790 aout_Delete( p_aout );
794 * Free announce handler(s?)
796 msg_Dbg( p_vlc, "removing announce handler" );
797 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
800 vlc_object_detach( p_announce );
801 vlc_object_release( p_announce );
802 announce_HandlerDestroy( p_announce );
805 if( i_object ) vlc_object_release( p_vlc );
809 /*****************************************************************************
810 * VLC_Destroy: Destroy everything.
811 *****************************************************************************
812 * This function requests the running threads to finish, waits for their
813 * termination, and destroys their structure.
814 *****************************************************************************/
815 int VLC_Destroy( int i_object )
817 vlc_t *p_vlc = vlc_current_object( i_object );
825 * Free allocated memory
827 if( p_vlc->p_memcpy_module )
829 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
830 p_vlc->p_memcpy_module = NULL;
836 module_EndBank( p_vlc );
838 if( p_vlc->psz_homedir )
840 free( p_vlc->psz_homedir );
841 p_vlc->psz_homedir = NULL;
844 if( p_vlc->psz_configfile )
846 free( p_vlc->psz_configfile );
847 p_vlc->psz_configfile = NULL;
850 if( p_vlc->p_hotkeys )
852 free( p_vlc->p_hotkeys );
853 p_vlc->p_hotkeys = NULL;
857 * System specific cleaning code
861 /* Destroy mutexes */
862 vlc_mutex_destroy( &p_vlc->config_lock );
864 vlc_object_detach( p_vlc );
866 /* Release object before destroying it */
867 if( i_object ) vlc_object_release( p_vlc );
869 vlc_object_destroy( p_vlc );
871 /* Stop thread system: last one out please shut the door! */
872 vlc_threads_end( p_libvlc );
877 /*****************************************************************************
878 * VLC_VariableSet: set a vlc variable
879 *****************************************************************************/
880 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
882 vlc_t *p_vlc = vlc_current_object( i_object );
890 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
891 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
892 if( !strncmp( psz_var, "conf::", 6 ) )
894 module_config_t *p_item;
895 char const *psz_newvar = psz_var + 6;
897 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
901 switch( p_item->i_type )
903 case CONFIG_ITEM_BOOL:
904 config_PutInt( p_vlc, psz_newvar, value.b_bool );
906 case CONFIG_ITEM_INTEGER:
907 config_PutInt( p_vlc, psz_newvar, value.i_int );
909 case CONFIG_ITEM_FLOAT:
910 config_PutFloat( p_vlc, psz_newvar, value.f_float );
913 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
916 if( i_object ) vlc_object_release( p_vlc );
921 i_ret = var_Set( p_vlc, psz_var, value );
923 if( i_object ) vlc_object_release( p_vlc );
927 /*****************************************************************************
928 * VLC_VariableGet: get a vlc variable
929 *****************************************************************************/
930 int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
932 vlc_t *p_vlc = vlc_current_object( i_object );
940 i_ret = var_Get( p_vlc, psz_var, p_value );
942 if( i_object ) vlc_object_release( p_vlc );
946 /*****************************************************************************
947 * VLC_AddTarget: adds a target for playing.
948 *****************************************************************************
949 * This function adds psz_target to the current playlist. If a playlist does
950 * not exist, it will create one.
951 *****************************************************************************/
952 int VLC_AddTarget( int i_object, char const *psz_target,
953 char const **ppsz_options, int i_options,
954 int i_mode, int i_pos )
957 playlist_t *p_playlist;
958 vlc_t *p_vlc = vlc_current_object( i_object );
965 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
967 if( p_playlist == NULL )
969 msg_Dbg( p_vlc, "no playlist present, creating one" );
970 p_playlist = playlist_Create( p_vlc );
972 if( p_playlist == NULL )
974 if( i_object ) vlc_object_release( p_vlc );
978 vlc_object_yield( p_playlist );
981 i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
982 i_mode, i_pos, -1, ppsz_options, i_options);
984 vlc_object_release( p_playlist );
986 if( i_object ) vlc_object_release( p_vlc );
990 /*****************************************************************************
992 *****************************************************************************/
993 int VLC_Play( int i_object )
995 playlist_t * p_playlist;
996 vlc_t *p_vlc = vlc_current_object( i_object );
998 /* Check that the handle is valid */
1004 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1008 if( i_object ) vlc_object_release( p_vlc );
1012 playlist_Play( p_playlist );
1013 vlc_object_release( p_playlist );
1015 if( i_object ) vlc_object_release( p_vlc );
1019 /*****************************************************************************
1020 * VLC_Pause: toggle pause
1021 *****************************************************************************/
1022 int VLC_Pause( int i_object )
1024 playlist_t * p_playlist;
1025 vlc_t *p_vlc = vlc_current_object( i_object );
1027 /* Check that the handle is valid */
1033 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1037 if( i_object ) vlc_object_release( p_vlc );
1041 playlist_Pause( p_playlist );
1042 vlc_object_release( p_playlist );
1044 if( i_object ) vlc_object_release( p_vlc );
1048 /*****************************************************************************
1049 * VLC_Pause: toggle pause
1050 *****************************************************************************/
1051 int VLC_Stop( int i_object )
1053 playlist_t * p_playlist;
1054 vlc_t *p_vlc = vlc_current_object( i_object );
1056 /* Check that the handle is valid */
1062 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1066 if( i_object ) vlc_object_release( p_vlc );
1070 playlist_Stop( p_playlist );
1071 vlc_object_release( p_playlist );
1073 if( i_object ) vlc_object_release( p_vlc );
1077 /*****************************************************************************
1078 * VLC_IsPlaying: Query for Playlist Status
1079 *****************************************************************************/
1080 vlc_bool_t VLC_IsPlaying( int i_object )
1082 playlist_t * p_playlist;
1083 vlc_bool_t b_playing;
1085 vlc_t *p_vlc = vlc_current_object( i_object );
1087 /* Check that the handle is valid */
1093 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1097 if( i_object ) vlc_object_release( p_vlc );
1101 b_playing = playlist_IsPlaying( p_playlist );
1102 vlc_object_release( p_playlist );
1104 if( i_object ) vlc_object_release( p_vlc );
1109 * Get the current position in a input
1111 * Return the current position as a float
1112 * \note For some inputs, this will be unknown.
1114 * \param i_object a vlc object id
1115 * \return a float in the range of 0.0 - 1.0
1117 float VLC_PositionGet( int i_object )
1119 input_thread_t *p_input;
1121 vlc_t *p_vlc = vlc_current_object( i_object );
1123 /* Check that the handle is valid */
1129 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1133 if( i_object ) vlc_object_release( p_vlc );
1137 var_Get( p_input, "position", &val );
1138 vlc_object_release( p_input );
1140 if( i_object ) vlc_object_release( p_vlc );
1145 * Set the current position in a input
1147 * Set the current position in a input and then return
1148 * the current position as a float.
1149 * \note For some inputs, this will be unknown.
1151 * \param i_object a vlc object id
1152 * \param i_position a float in the range of 0.0 - 1.0
1153 * \return a float in the range of 0.0 - 1.0
1155 float VLC_PositionSet( int i_object, float i_position )
1157 input_thread_t *p_input;
1159 vlc_t *p_vlc = vlc_current_object( i_object );
1161 /* Check that the handle is valid */
1167 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1171 if( i_object ) vlc_object_release( p_vlc );
1175 val.f_float = i_position;
1176 var_Set( p_input, "position", val );
1177 var_Get( p_input, "position", &val );
1178 vlc_object_release( p_input );
1180 if( i_object ) vlc_object_release( p_vlc );
1185 * Get the current position in a input
1187 * Return the current position in seconds from the start.
1188 * \note For some inputs, this will be unknown.
1190 * \param i_object a vlc object id
1191 * \return the offset from 0:00 in seconds
1193 int VLC_TimeGet( int i_object )
1195 input_thread_t *p_input;
1197 vlc_t *p_vlc = vlc_current_object( i_object );
1199 /* Check that the handle is valid */
1205 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1209 if( i_object ) vlc_object_release( p_vlc );
1213 var_Get( p_input, "time", &val );
1214 vlc_object_release( p_input );
1216 if( i_object ) vlc_object_release( p_vlc );
1217 return val.i_time / 1000000;
1221 * Seek to a position in the current input
1223 * Seek i_seconds in the current input. If b_relative is set,
1224 * then the seek will be relative to the current position, otherwise
1225 * it will seek to i_seconds from the beginning of the input.
1226 * \note For some inputs, this will be unknown.
1228 * \param i_object a vlc object id
1229 * \param i_seconds seconds from current position or from beginning of input
1230 * \param b_relative seek relative from current position
1231 * \return VLC_SUCCESS on success
1233 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1235 input_thread_t *p_input;
1237 vlc_t *p_vlc = vlc_current_object( i_object );
1239 /* Check that the handle is valid */
1245 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1249 if( i_object ) vlc_object_release( p_vlc );
1255 val.i_time = i_seconds * 1000000;
1256 var_Set( p_input, "time-offset", val );
1260 val.i_time = i_seconds * 1000000;
1261 var_Set( p_input, "time", val );
1263 vlc_object_release( p_input );
1265 if( i_object ) vlc_object_release( p_vlc );
1270 * Get the total length of a input
1272 * Return the total length in seconds from the current input.
1273 * \note For some inputs, this will be unknown.
1275 * \param i_object a vlc object id
1276 * \return the length in seconds
1278 int VLC_LengthGet( int i_object )
1280 input_thread_t *p_input;
1282 vlc_t *p_vlc = vlc_current_object( i_object );
1284 /* Check that the handle is valid */
1290 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1294 if( i_object ) vlc_object_release( p_vlc );
1298 var_Get( p_input, "length", &val );
1299 vlc_object_release( p_input );
1301 if( i_object ) vlc_object_release( p_vlc );
1302 return val.i_time / 1000000;
1306 * Play the input faster than realtime
1308 * 2x, 4x, 8x faster than realtime
1309 * \note For some inputs, this will be impossible.
1311 * \param i_object a vlc object id
1312 * \return the current speedrate
1314 float VLC_SpeedFaster( int i_object )
1316 input_thread_t *p_input;
1318 vlc_t *p_vlc = vlc_current_object( i_object );
1320 /* Check that the handle is valid */
1326 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1330 if( i_object ) vlc_object_release( p_vlc );
1334 val.b_bool = VLC_TRUE;
1335 var_Set( p_input, "rate-faster", val );
1336 var_Get( p_input, "rate", &val );
1337 vlc_object_release( p_input );
1339 if( i_object ) vlc_object_release( p_vlc );
1340 return val.f_float / DEFAULT_RATE;
1344 * Play the input slower than realtime
1346 * 1/2x, 1/4x, 1/8x slower than realtime
1347 * \note For some inputs, this will be impossible.
1349 * \param i_object a vlc object id
1350 * \return the current speedrate
1352 float VLC_SpeedSlower( int i_object )
1354 input_thread_t *p_input;
1356 vlc_t *p_vlc = vlc_current_object( i_object );
1358 /* Check that the handle is valid */
1364 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1368 if( i_object ) vlc_object_release( p_vlc );
1372 val.b_bool = VLC_TRUE;
1373 var_Set( p_input, "rate-slower", val );
1374 var_Get( p_input, "rate", &val );
1375 vlc_object_release( p_input );
1377 if( i_object ) vlc_object_release( p_vlc );
1378 return val.f_float / DEFAULT_RATE;
1382 * Return the current playlist item
1384 * Returns the index of the playlistitem that is currently selected for play.
1385 * This is valid even if nothing is currently playing.
1387 * \param i_object a vlc object id
1388 * \return the current index
1390 int VLC_PlaylistIndex( int i_object )
1393 playlist_t * p_playlist;
1394 vlc_t *p_vlc = vlc_current_object( i_object );
1396 /* Check that the handle is valid */
1402 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1406 if( i_object ) vlc_object_release( p_vlc );
1410 i_index = p_playlist->i_index;
1411 vlc_object_release( p_playlist );
1413 if( i_object ) vlc_object_release( p_vlc );
1418 * Total amount of items in the playlist
1420 * \param i_object a vlc object id
1421 * \return amount of playlist items
1423 int VLC_PlaylistNumberOfItems( int i_object )
1426 playlist_t * p_playlist;
1427 vlc_t *p_vlc = vlc_current_object( i_object );
1429 /* Check that the handle is valid */
1435 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1439 if( i_object ) vlc_object_release( p_vlc );
1443 i_size = p_playlist->i_size;
1444 vlc_object_release( p_playlist );
1446 if( i_object ) vlc_object_release( p_vlc );
1451 * Next playlist item
1453 * Skip to the next playlistitem and play it.
1455 * \param i_object a vlc object id
1456 * \return VLC_SUCCESS on success
1458 int VLC_PlaylistNext( int i_object )
1460 playlist_t * p_playlist;
1461 vlc_t *p_vlc = vlc_current_object( i_object );
1463 /* Check that the handle is valid */
1469 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1473 if( i_object ) vlc_object_release( p_vlc );
1477 playlist_Next( p_playlist );
1478 vlc_object_release( p_playlist );
1480 if( i_object ) vlc_object_release( p_vlc );
1485 * Previous playlist item
1487 * Skip to the previous playlistitem and play it.
1489 * \param i_object a vlc object id
1490 * \return VLC_SUCCESS on success
1492 int VLC_PlaylistPrev( int i_object )
1494 playlist_t * p_playlist;
1495 vlc_t *p_vlc = vlc_current_object( i_object );
1497 /* Check that the handle is valid */
1503 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1507 if( i_object ) vlc_object_release( p_vlc );
1511 playlist_Prev( p_playlist );
1512 vlc_object_release( p_playlist );
1514 if( i_object ) vlc_object_release( p_vlc );
1519 /*****************************************************************************
1520 * VLC_PlaylistClear: Empty the playlist
1521 *****************************************************************************/
1522 int VLC_PlaylistClear( int i_object )
1525 playlist_t * p_playlist;
1526 vlc_t *p_vlc = vlc_current_object( i_object );
1528 /* Check that the handle is valid */
1534 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1538 if( i_object ) vlc_object_release( p_vlc );
1542 i_err = playlist_Clear( p_playlist );
1544 vlc_object_release( p_playlist );
1546 if( i_object ) vlc_object_release( p_vlc );
1553 * \param i_object a vlc object id
1554 * \param i_volume something in a range from 0-200
1555 * \return the new volume (range 0-200 %)
1557 int VLC_VolumeSet( int i_object, int i_volume )
1559 audio_volume_t i_vol;
1560 vlc_t *p_vlc = vlc_current_object( i_object );
1562 /* Check that the handle is valid */
1568 if( 0 >= i_volume && i_volume <= 200 )
1570 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1571 aout_VolumeSet( p_vlc, i_vol );
1574 if( i_object ) vlc_object_release( p_vlc );
1575 return i_vol * 200 / AOUT_VOLUME_MAX;
1579 * Get the current volume
1581 * Retrieve the current volume.
1583 * \param i_object a vlc object id
1584 * \return the current volume (range 0-200 %)
1586 int VLC_VolumeGet( int i_object )
1588 audio_volume_t i_volume;
1589 vlc_t *p_vlc = vlc_current_object( i_object );
1591 /* Check that the handle is valid */
1597 aout_VolumeGet( p_vlc, &i_volume );
1599 if( i_object ) vlc_object_release( p_vlc );
1600 return i_volume*200/AOUT_VOLUME_MAX;
1604 * Mute/Unmute the volume
1606 * \param i_object a vlc object id
1607 * \return VLC_SUCCESS on success
1609 int VLC_VolumeMute( int i_object )
1611 vlc_t *p_vlc = vlc_current_object( i_object );
1613 /* Check that the handle is valid */
1619 aout_VolumeMute( p_vlc, NULL );
1621 if( i_object ) vlc_object_release( p_vlc );
1625 /*****************************************************************************
1626 * VLC_FullScreen: toggle fullscreen mode
1627 *****************************************************************************/
1628 int VLC_FullScreen( int i_object )
1630 vout_thread_t *p_vout;
1631 vlc_t *p_vlc = vlc_current_object( i_object );
1638 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1642 if( i_object ) vlc_object_release( p_vlc );
1646 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1647 vlc_object_release( p_vout );
1649 if( i_object ) vlc_object_release( p_vlc );
1653 /* following functions are local */
1655 /*****************************************************************************
1656 * SetLanguage: set the interface language.
1657 *****************************************************************************
1658 * We set the LC_MESSAGES locale category for interface messages and buttons,
1659 * as well as the LC_CTYPE category for string sorting and possible wide
1660 * character support.
1661 *****************************************************************************/
1662 static void SetLanguage ( char const *psz_lang )
1664 #if defined( ENABLE_NLS ) \
1665 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1668 #if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
1672 if( psz_lang && !*psz_lang )
1674 # if defined( HAVE_LC_MESSAGES )
1675 setlocale( LC_MESSAGES, psz_lang );
1677 setlocale( LC_CTYPE, psz_lang );
1682 /* I need that under Darwin, please check it doesn't disturb
1683 * other platforms. --Meuuh */
1684 setenv( "LANG", psz_lang, 1 );
1686 #elif defined( SYS_BEOS ) || defined( WIN32 )
1687 /* We set LC_ALL manually because it is the only way to set
1688 * the language at runtime under eg. Windows. Beware that this
1689 * makes the environment unconsistent when libvlc is unloaded and
1690 * should probably be moved to a safer place like vlc.c. */
1691 static char psz_lcall[20];
1692 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1693 psz_lcall[19] = '\0';
1694 putenv( psz_lcall );
1697 setlocale( LC_ALL, psz_lang );
1700 /* Specify where to find the locales for current domain */
1701 #if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1702 psz_path = LOCALEDIR;
1704 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1708 if( !bindtextdomain( PACKAGE, psz_path ) )
1710 fprintf( stderr, "warning: no domain %s in directory %s\n",
1711 PACKAGE, psz_path );
1714 /* Set the default domain */
1715 textdomain( PACKAGE );
1717 #if defined( ENABLE_UTF8 )
1718 bind_textdomain_codeset( PACKAGE, "UTF-8" );
1724 /*****************************************************************************
1725 * GetFilenames: parse command line options which are not flags
1726 *****************************************************************************
1727 * Parse command line for input files as well as their associated options.
1728 * An option always follows its associated input and begins with a ":".
1729 *****************************************************************************/
1730 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1732 int i_opt, i_options;
1734 /* We assume that the remaining parameters are filenames
1735 * and their input options */
1736 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
1740 /* Count the input options */
1741 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
1747 /* TODO: write an internal function of this one, to avoid
1748 * unnecessary lookups. */
1749 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1750 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
1752 PLAYLIST_INSERT, 0 );
1758 /*****************************************************************************
1759 * Usage: print program usage
1760 *****************************************************************************
1761 * Print a short inline help. Message interface is initialized at this stage.
1762 *****************************************************************************/
1763 static void Usage( vlc_t *p_this, char const *psz_module_name )
1765 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1766 /* short option ------' | | | | | | |
1767 * option name ------------' | | | | | |
1768 * <bra -------------------------' | | | | |
1769 * option type or "" --------------' | | | |
1770 * ket> -----------------------------' | | |
1771 * padding spaces ---------------------' | |
1772 * comment -------------------------------' |
1773 * comment suffix --------------------------'
1775 * The purpose of having bra and ket is that we might i18n them as well.
1777 #define LINE_START 8
1778 #define PADDING_SPACES 25
1781 module_config_t *p_item;
1782 char psz_spaces[PADDING_SPACES+LINE_START+1];
1783 char psz_format[sizeof(FORMAT_STRING)];
1784 char psz_buffer[1000];
1787 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1788 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
1790 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1791 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1793 strcpy( psz_format, FORMAT_STRING );
1799 /* List all modules */
1800 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1802 /* Enumerate the config for each module */
1803 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1805 vlc_bool_t b_help_module;
1807 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1809 if( psz_module_name && strcmp( psz_module_name,
1810 p_parser->psz_object_name ) )
1815 /* Ignore modules without config options */
1816 if( !p_parser->i_config_items )
1821 /* Ignore modules with only advanced config options if requested */
1824 for( p_item = p_parser->p_config;
1825 p_item->i_type != CONFIG_HINT_END;
1828 if( (p_item->i_type & CONFIG_ITEM) &&
1829 !p_item->b_advanced ) break;
1831 if( p_item->i_type == CONFIG_HINT_END ) continue;
1834 /* Print name of module */
1835 if( strcmp( "main", p_parser->psz_object_name ) )
1836 fprintf( stdout, "\n %s\n", p_parser->psz_longname );
1838 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1840 /* Print module options */
1841 for( p_item = p_parser->p_config;
1842 p_item->i_type != CONFIG_HINT_END;
1846 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1847 char *psz_suf = "", *psz_prefix = NULL;
1850 /* Skip advanced options if requested */
1851 if( p_item->b_advanced && !b_advanced )
1856 switch( p_item->i_type )
1858 case CONFIG_HINT_CATEGORY:
1859 case CONFIG_HINT_USAGE:
1860 if( !strcmp( "main", p_parser->psz_object_name ) )
1861 fprintf( stdout, "\n %s\n", p_item->psz_text );
1864 case CONFIG_ITEM_STRING:
1865 case CONFIG_ITEM_FILE:
1866 case CONFIG_ITEM_DIRECTORY:
1867 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1868 if( !p_item->ppsz_list )
1870 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1876 psz_type = psz_buffer;
1878 for( i = 0; p_item->ppsz_list[i]; i++ )
1880 if( i ) strcat( psz_type, "," );
1881 strcat( psz_type, p_item->ppsz_list[i] );
1886 case CONFIG_ITEM_INTEGER:
1887 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
1888 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1890 case CONFIG_ITEM_FLOAT:
1891 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1893 case CONFIG_ITEM_BOOL:
1894 psz_bra = ""; psz_type = ""; psz_ket = "";
1895 if( !b_help_module )
1897 psz_suf = p_item->i_value ? _(" (default enabled)") :
1898 _(" (default disabled)");
1908 /* Add short option if any */
1909 if( p_item->i_short )
1911 sprintf( psz_short, "-%c,", p_item->i_short );
1915 strcpy( psz_short, " " );
1918 i = PADDING_SPACES - strlen( p_item->psz_name )
1919 - strlen( psz_bra ) - strlen( psz_type )
1920 - strlen( psz_ket ) - 1;
1922 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1924 /* If option is of type --foo-bar, we print its counterpart
1925 * as --no-foo-bar, but if it is of type --foobar (without
1926 * dashes in the name) we print it as --nofoobar. Both
1927 * values are of course valid, only the display changes. */
1928 psz_prefix = strchr( p_item->psz_name, '-' ) ? ", --no-"
1930 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
1935 psz_spaces[0] = '\n';
1940 psz_spaces[i] = '\0';
1943 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1945 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1946 psz_prefix, p_item->psz_name, psz_bra, psz_type,
1947 psz_ket, psz_spaces );
1951 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1952 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
1955 psz_spaces[i] = ' ';
1957 /* We wrap the rest of the output */
1958 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
1959 psz_text = psz_buffer;
1962 char *psz_parser, *psz_word;
1963 int i_end = strlen( psz_text );
1965 /* If the remaining text fits in a line, print it. */
1966 if( i_end <= i_width )
1968 fprintf( stdout, "%s\n", psz_text );
1972 /* Otherwise, eat as many words as possible */
1973 psz_parser = psz_text;
1976 psz_word = psz_parser;
1977 psz_parser = strchr( psz_word, ' ' );
1978 /* If no space was found, we reached the end of the text
1979 * block; otherwise, we skip the space we just found. */
1980 psz_parser = psz_parser ? psz_parser + 1
1983 } while( psz_parser - psz_text <= i_width );
1985 /* We cut a word in one of these cases:
1986 * - it's the only word in the line and it's too long.
1987 * - we used less than 80% of the width and the word we are
1988 * going to wrap is longer than 40% of the width, and even
1989 * if the word would have fit in the next line. */
1990 if( psz_word == psz_text
1991 || ( psz_word - psz_text < 80 * i_width / 100
1992 && psz_parser - psz_word > 40 * i_width / 100 ) )
1994 char c = psz_text[i_width];
1995 psz_text[i_width] = '\0';
1996 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
1997 psz_text += i_width;
2002 psz_word[-1] = '\0';
2003 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2004 psz_text = psz_word;
2010 /* Release the module list */
2011 vlc_list_release( p_list );
2013 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2014 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2019 /*****************************************************************************
2020 * ListModules: list the available modules with their description
2021 *****************************************************************************
2022 * Print a list of all available modules (builtins and plugins) and a short
2023 * description for each one.
2024 *****************************************************************************/
2025 static void ListModules( vlc_t *p_this )
2029 char psz_spaces[22];
2032 memset( psz_spaces, ' ', 22 );
2039 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
2040 p_this->p_vlc->psz_object_name );
2042 fprintf( stdout, _("[module] [description]\n") );
2044 /* List all modules */
2045 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2047 /* Enumerate each module */
2048 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2052 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2054 /* Nasty hack, but right now I'm too tired to think about a nice
2056 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2060 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2061 psz_spaces, p_parser->psz_longname );
2063 psz_spaces[i] = ' ';
2066 vlc_list_release( p_list );
2068 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2069 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2074 /*****************************************************************************
2075 * Version: print complete program version
2076 *****************************************************************************
2077 * Print complete program version and build number.
2078 *****************************************************************************/
2079 static void Version( void )
2085 fprintf( stdout, VERSION_MESSAGE "\n" );
2087 _("This program comes with NO WARRANTY, to the extent permitted by "
2088 "law.\nYou may redistribute it under the terms of the GNU General "
2089 "Public License;\nsee the file named COPYING for details.\n"
2090 "Written by the VideoLAN team; see the AUTHORS file.\n") );
2092 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2093 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2098 /*****************************************************************************
2099 * ShowConsole: On Win32, create an output console for debug messages
2100 *****************************************************************************
2101 * This function is useful only on Win32.
2102 *****************************************************************************/
2104 static void ShowConsole( void )
2108 freopen( "CONOUT$", "w", stdout );
2109 freopen( "CONOUT$", "w", stderr );
2110 freopen( "CONIN$", "r", stdin );
2116 /*****************************************************************************
2117 * ConsoleWidth: Return the console width in characters
2118 *****************************************************************************
2119 * We use the stty shell command to get the console width; if this fails or
2120 * if the width is less than 80, we default to 80.
2121 *****************************************************************************/
2122 static int ConsoleWidth( void )
2127 char buf[20], *psz_parser;
2131 file = popen( "stty size 2>/dev/null", "r" );
2134 i_ret = fread( buf, 1, 20, file );
2138 psz_parser = strchr( buf, ' ' );
2141 i_ret = atoi( psz_parser + 1 );
2156 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2157 vlc_value_t old_val, vlc_value_t new_val, void *param)
2159 vlc_t *p_vlc = (vlc_t *)p_this;
2161 if( new_val.i_int >= -1 )
2163 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );