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@videolan.org>
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>
40 #include <errno.h> /* ENOMEM */
41 #include <stdio.h> /* sprintf() */
42 #include <string.h> /* strerror() */
43 #include <stdlib.h> /* free() */
46 # include <netinet/in.h> /* BSD: struct in_addr */
51 #elif defined( WIN32 ) && !defined( UNDER_CE )
55 #ifdef WIN32 /* optind, getopt(), included in unistd.h */
56 # include "extras/getopt.h"
64 # include <hal/libhal.h>
67 #include "vlc_cpu.h" /* CPU detection */
68 #include "os_specific.h"
70 #include "vlc_error.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 );
102 static void PauseConsole ( void );
104 static int ConsoleWidth ( void );
106 static int VerboseCallback( vlc_object_t *, char const *,
107 vlc_value_t, vlc_value_t, void * );
109 static void InitDeviceValues( vlc_t * );
111 /*****************************************************************************
112 * vlc_current_object: return the current object.
113 *****************************************************************************
114 * If i_object is non-zero, return the corresponding object. Otherwise,
115 * return the statically allocated p_vlc object.
116 *****************************************************************************/
117 vlc_t * vlc_current_object( int i_object )
121 return vlc_object_get( p_libvlc, i_object );
127 /*****************************************************************************
128 * VLC_Version: return the libvlc version.
129 *****************************************************************************
130 * This function returns full version string (numeric version and codename).
131 *****************************************************************************/
132 char const * VLC_Version( void )
134 return VERSION_MESSAGE;
137 /*****************************************************************************
138 * VLC_Error: strerror() equivalent
139 *****************************************************************************
140 * This function returns full version string (numeric version and codename).
141 *****************************************************************************/
142 char const * VLC_Error( int i_err )
144 return vlc_error( i_err );
147 /*****************************************************************************
148 * VLC_Create: allocate a vlc_t structure, and initialize libvlc if needed.
149 *****************************************************************************
150 * This function allocates a vlc_t structure and returns a negative value
151 * in case of failure. Also, the thread system is initialized.
152 *****************************************************************************/
153 int VLC_Create( void )
156 vlc_t * p_vlc = NULL;
159 /* &libvlc never changes, so we can safely call this multiple times. */
162 /* vlc_threads_init *must* be the first internal call! No other call is
163 * allowed before the thread system has been initialized. */
164 i_ret = vlc_threads_init( p_libvlc );
170 /* Now that the thread system is initialized, we don't have much, but
171 * at least we have var_Create */
172 var_Create( p_libvlc, "libvlc", VLC_VAR_MUTEX );
173 var_Get( p_libvlc, "libvlc", &lockval );
174 vlc_mutex_lock( lockval.p_address );
175 if( !libvlc.b_ready )
179 /* Guess what CPU we have */
180 libvlc.i_cpu = CPUCapabilities();
182 /* Find verbosity from VLC_VERBOSE environment variable */
183 psz_env = getenv( "VLC_VERBOSE" );
184 libvlc.i_verbose = psz_env ? atoi( psz_env ) : -1;
186 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
187 libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
189 libvlc.b_color = VLC_FALSE;
192 /* Initialize message queue */
193 msg_Create( p_libvlc );
195 /* Announce who we are */
196 msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE );
197 msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
199 /* The module bank will be initialized later */
200 libvlc.p_module_bank = NULL;
202 libvlc.b_ready = VLC_TRUE;
204 vlc_mutex_unlock( lockval.p_address );
205 var_Destroy( p_libvlc, "libvlc" );
207 /* Allocate a vlc object */
208 p_vlc = vlc_object_create( p_libvlc, VLC_OBJECT_VLC );
213 p_vlc->thread_id = 0;
214 vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
216 p_vlc->psz_object_name = "root";
218 /* Initialize mutexes */
219 vlc_mutex_init( p_vlc, &p_vlc->config_lock );
221 vlc_mutex_init( p_vlc, &p_vlc->quicktime_lock );
224 /* Store our newly allocated structure in the global list */
225 vlc_object_attach( p_vlc, p_libvlc );
227 /* Store data for the non-reentrant API */
228 p_static_vlc = p_vlc;
230 return p_vlc->i_object_id;
233 /*****************************************************************************
234 * VLC_Init: initialize a vlc_t structure.
235 *****************************************************************************
236 * This function initializes a previously allocated vlc_t structure:
238 * - gettext initialization
239 * - message queue, module bank and playlist initialization
240 * - configuration and commandline parsing
241 *****************************************************************************/
242 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
244 char p_capabilities[200];
249 vlc_bool_t b_exit = VLC_FALSE;
250 vlc_t * p_vlc = vlc_current_object( i_object );
251 module_t *p_help_module;
252 playlist_t *p_playlist;
260 * System specific initialization code
262 system_Init( p_vlc, &i_argc, ppsz_argv );
264 /* Get the executable name (similar to the basename command) */
267 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
270 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
276 p_vlc->psz_object_name = "vlc";
280 * Support for gettext
284 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
285 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
287 /* Initialize the module bank and load the configuration of the
288 * main module. We need to do this at this stage to be able to display
289 * a short help if required by the user. (short help == main module
291 module_InitBank( p_vlc );
293 /* Hack: insert the help module here */
294 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
295 if( p_help_module == NULL )
297 module_EndBank( p_vlc );
298 if( i_object ) vlc_object_release( p_vlc );
301 p_help_module->psz_object_name = "help";
302 p_help_module->psz_longname = N_("Help options");
303 config_Duplicate( p_help_module, p_help_config );
304 vlc_object_attach( p_help_module, libvlc.p_module_bank );
307 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
309 vlc_object_detach( p_help_module );
310 config_Free( p_help_module );
311 vlc_object_destroy( p_help_module );
312 module_EndBank( p_vlc );
313 if( i_object ) vlc_object_release( p_vlc );
317 /* Check for short help option */
318 if( config_GetInt( p_vlc, "help" ) )
320 fprintf( stdout, _("Usage: %s [options] [items]...\n"),
321 p_vlc->psz_object_name );
322 Usage( p_vlc, "main" );
323 Usage( p_vlc, "help" );
326 /* Check for version option */
327 else if( config_GetInt( p_vlc, "version" ) )
333 /* Set the config file stuff */
334 p_vlc->psz_homedir = config_GetHomeDir();
335 p_vlc->psz_configfile = config_GetPsz( p_vlc, "config" );
337 /* Check for plugins cache options */
338 if( config_GetInt( p_vlc, "reset-plugins-cache" ) )
340 libvlc.p_module_bank->b_cache_delete = VLC_TRUE;
343 /* Hack: remove the help module here */
344 vlc_object_detach( p_help_module );
347 /* Will be re-done properly later on */
348 p_vlc->p_libvlc->i_verbose = config_GetInt( p_vlc, "verbose" );
350 /* Check for daemon mode */
352 if( config_GetInt( p_vlc, "daemon" ) )
355 if( daemon( 0, 0) != 0 )
357 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
361 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
366 if( ( i_pid = fork() ) < 0 )
368 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
373 /* This is the parent, exit right now */
374 msg_Dbg( p_vlc, "closing parent process" );
379 /* We are the child */
380 msg_Dbg( p_vlc, "daemon spawned" );
381 close( STDIN_FILENO );
382 close( STDOUT_FILENO );
383 close( STDERR_FILENO );
385 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
393 config_Free( p_help_module );
394 vlc_object_destroy( p_help_module );
395 module_EndBank( p_vlc );
396 if( i_object ) vlc_object_release( p_vlc );
400 /* Check for translation config option */
401 #if defined( ENABLE_NLS ) \
402 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
404 /* This ain't really nice to have to reload the config here but it seems
405 * the only way to do it. */
406 config_LoadConfigFile( p_vlc, "main" );
407 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
409 /* Check if the user specified a custom language */
410 psz_language = config_GetPsz( p_vlc, "language" );
411 if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
413 vlc_bool_t b_cache_delete = libvlc.p_module_bank->b_cache_delete;
415 /* Reset the default domain */
416 SetLanguage( psz_language );
418 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
419 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
421 textdomain( PACKAGE_NAME );
423 #if defined( ENABLE_UTF8 )
424 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
427 module_EndBank( p_vlc );
428 module_InitBank( p_vlc );
429 config_LoadConfigFile( p_vlc, "main" );
430 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
431 libvlc.p_module_bank->b_cache_delete = b_cache_delete;
433 if( psz_language ) free( psz_language );
437 * Load the builtins and plugins into the module_bank.
438 * We have to do it before config_Load*() because this also gets the
439 * list of configuration options exported by each module and loads their
442 module_LoadBuiltins( p_vlc );
443 module_LoadPlugins( p_vlc );
449 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
450 libvlc.p_module_bank->i_children );
452 /* Hack: insert the help module here */
453 vlc_object_attach( p_help_module, libvlc.p_module_bank );
456 /* Check for help on modules */
457 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
459 Usage( p_vlc, p_tmp );
463 /* Check for long help option */
464 else if( config_GetInt( p_vlc, "longhelp" ) )
466 Usage( p_vlc, NULL );
469 /* Check for module list option */
470 else if( config_GetInt( p_vlc, "list" ) )
472 ListModules( p_vlc );
476 /* Check for config file options */
477 if( config_GetInt( p_vlc, "reset-config" ) )
479 vlc_object_detach( p_help_module );
480 config_ResetAll( p_vlc );
481 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
482 config_SaveConfigFile( p_vlc, NULL );
483 vlc_object_attach( p_help_module, libvlc.p_module_bank );
485 if( config_GetInt( p_vlc, "save-config" ) )
487 vlc_object_detach( p_help_module );
488 config_LoadConfigFile( p_vlc, NULL );
489 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
490 config_SaveConfigFile( p_vlc, NULL );
491 vlc_object_attach( p_help_module, libvlc.p_module_bank );
494 /* Hack: remove the help module here */
495 vlc_object_detach( p_help_module );
500 config_Free( p_help_module );
501 vlc_object_destroy( p_help_module );
502 module_EndBank( p_vlc );
503 if( i_object ) vlc_object_release( p_vlc );
510 InitDeviceValues( p_vlc );
513 * Override default configuration with config file settings
515 config_LoadConfigFile( p_vlc, NULL );
517 /* Hack: insert the help module here */
518 vlc_object_attach( p_help_module, libvlc.p_module_bank );
522 * Override configuration with command line settings
524 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
528 /* Pause the console because it's destroyed when we exit */
529 fprintf( stderr, "The command line options couldn't be loaded, check "
530 "that they are valid.\n" );
533 vlc_object_detach( p_help_module );
534 config_Free( p_help_module );
535 vlc_object_destroy( p_help_module );
536 module_EndBank( p_vlc );
537 if( i_object ) vlc_object_release( p_vlc );
541 /* Hack: remove the help module here */
542 vlc_object_detach( p_help_module );
543 config_Free( p_help_module );
544 vlc_object_destroy( p_help_module );
548 * System specific configuration
550 system_Configure( p_vlc, &i_argc, ppsz_argv );
553 * Message queue options
556 var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
557 if( config_GetInt( p_vlc, "quiet" ) )
561 var_Set( p_vlc, "verbose", val );
563 var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
564 var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
566 libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
569 * Output messages that may still be in the queue
573 /* p_vlc initialization. FIXME ? */
575 #if defined( __i386__ )
576 if( !config_GetInt( p_vlc, "mmx" ) )
577 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
578 if( !config_GetInt( p_vlc, "3dn" ) )
579 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
580 if( !config_GetInt( p_vlc, "mmxext" ) )
581 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
582 if( !config_GetInt( p_vlc, "sse" ) )
583 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
584 if( !config_GetInt( p_vlc, "sse2" ) )
585 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
587 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
588 if( !config_GetInt( p_vlc, "altivec" ) )
589 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
592 #define PRINT_CAPABILITY( capability, string ) \
593 if( libvlc.i_cpu & capability ) \
595 strncat( p_capabilities, string " ", \
596 sizeof(p_capabilities) - strlen(p_capabilities) ); \
597 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
600 p_capabilities[0] = '\0';
601 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
602 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
603 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
604 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
605 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
606 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
607 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
608 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
609 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
610 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
611 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
614 * Choose the best memcpy module
616 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
618 if( p_vlc->pf_memcpy == NULL )
620 p_vlc->pf_memcpy = memcpy;
623 if( p_vlc->pf_memset == NULL )
625 p_vlc->pf_memset = memset;
629 * Initialize hotkey handling
631 var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
632 p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
633 /* Do a copy (we don't need to modify the strings) */
634 memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
637 * Initialize playlist and get commandline files
639 p_playlist = playlist_Create( p_vlc );
642 msg_Err( p_vlc, "playlist initialization failed" );
643 if( p_vlc->p_memcpy_module != NULL )
645 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
647 module_EndBank( p_vlc );
648 if( i_object ) vlc_object_release( p_vlc );
653 * Load background interfaces
655 psz_modules = config_GetPsz( p_vlc, "extraintf" );
656 psz_parser = psz_modules;
657 while ( psz_parser && *psz_parser )
659 char *psz_module, *psz_temp;
660 psz_module = psz_parser;
661 psz_parser = strchr( psz_module, ',' );
667 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
670 sprintf( psz_temp, "%s,none", psz_module );
671 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
681 * Allways load the hotkeys interface if it exists
683 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
686 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
688 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
689 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
690 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
691 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
692 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
693 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
694 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
695 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
696 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
697 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
698 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
699 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
702 * Get input filenames given as commandline arguments
704 GetFilenames( p_vlc, i_argc, ppsz_argv );
706 if( i_object ) vlc_object_release( p_vlc );
710 /*****************************************************************************
711 * VLC_AddIntf: add an interface
712 *****************************************************************************
713 * This function opens an interface plugin and runs it. If b_block is set
714 * to 0, VLC_AddIntf will return immediately and let the interface run in a
715 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
716 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
717 * the playlist when it is completely initialised.
718 *****************************************************************************/
719 int VLC_AddIntf( int i_object, char const *psz_module,
720 vlc_bool_t b_block, vlc_bool_t b_play )
723 intf_thread_t *p_intf;
724 vlc_t *p_vlc = vlc_current_object( i_object );
732 if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module )
735 * We prefer the dummy interface if none is specified. */
736 char *psz_interface = config_GetPsz( p_vlc, "intf" );
737 if( !psz_interface || !*psz_interface ) psz_module = "dummy";
738 if( psz_interface ) free( psz_interface );
742 /* Try to create the interface */
743 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
747 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
748 if( i_object ) vlc_object_release( p_vlc );
752 /* Interface doesn't handle play on start so do it ourselves */
753 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
755 /* Try to run the interface */
756 p_intf->b_play = b_play;
757 p_intf->b_block = b_block;
758 i_err = intf_RunThread( p_intf );
761 vlc_object_detach( p_intf );
762 intf_Destroy( p_intf );
763 if( i_object ) vlc_object_release( p_vlc );
767 if( i_object ) vlc_object_release( p_vlc );
771 /*****************************************************************************
772 * VLC_Die: ask vlc to die.
773 *****************************************************************************
774 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
775 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
776 *****************************************************************************/
777 int VLC_Die( int i_object )
779 vlc_t *p_vlc = vlc_current_object( i_object );
786 p_vlc->b_die = VLC_TRUE;
788 if( i_object ) vlc_object_release( p_vlc );
792 /*****************************************************************************
793 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
794 *****************************************************************************/
795 int VLC_CleanUp( int i_object )
797 intf_thread_t * p_intf;
798 playlist_t * p_playlist;
799 vout_thread_t * p_vout;
800 aout_instance_t * p_aout;
801 announce_handler_t * p_announce;
802 vlc_t *p_vlc = vlc_current_object( i_object );
804 /* Check that the handle is valid */
811 * Ask the interfaces to stop and destroy them
813 msg_Dbg( p_vlc, "removing all interfaces" );
814 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
816 intf_StopThread( p_intf );
817 vlc_object_detach( p_intf );
818 vlc_object_release( p_intf );
819 intf_Destroy( p_intf );
825 msg_Dbg( p_vlc, "removing all playlists" );
826 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
829 vlc_object_detach( p_playlist );
830 vlc_object_release( p_playlist );
831 playlist_Destroy( p_playlist );
837 msg_Dbg( p_vlc, "removing all video outputs" );
838 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
840 vlc_object_detach( p_vout );
841 vlc_object_release( p_vout );
842 vout_Destroy( p_vout );
848 msg_Dbg( p_vlc, "removing all audio outputs" );
849 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
851 vlc_object_detach( (vlc_object_t *)p_aout );
852 vlc_object_release( (vlc_object_t *)p_aout );
853 aout_Delete( p_aout );
857 * Free announce handler(s?)
859 msg_Dbg( p_vlc, "removing announce handler" );
860 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
863 vlc_object_detach( p_announce );
864 vlc_object_release( p_announce );
865 announce_HandlerDestroy( p_announce );
868 if( i_object ) vlc_object_release( p_vlc );
872 /*****************************************************************************
873 * VLC_Destroy: Destroy everything.
874 *****************************************************************************
875 * This function requests the running threads to finish, waits for their
876 * termination, and destroys their structure.
877 *****************************************************************************/
878 int VLC_Destroy( int i_object )
880 vlc_t *p_vlc = vlc_current_object( i_object );
888 * Free allocated memory
890 if( p_vlc->p_memcpy_module )
892 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
893 p_vlc->p_memcpy_module = NULL;
899 module_EndBank( p_vlc );
901 if( p_vlc->psz_homedir )
903 free( p_vlc->psz_homedir );
904 p_vlc->psz_homedir = NULL;
907 if( p_vlc->psz_configfile )
909 free( p_vlc->psz_configfile );
910 p_vlc->psz_configfile = NULL;
913 if( p_vlc->p_hotkeys )
915 free( p_vlc->p_hotkeys );
916 p_vlc->p_hotkeys = NULL;
920 * System specific cleaning code
924 /* Destroy mutexes */
925 vlc_mutex_destroy( &p_vlc->config_lock );
927 vlc_object_detach( p_vlc );
929 /* Release object before destroying it */
930 if( i_object ) vlc_object_release( p_vlc );
932 vlc_object_destroy( p_vlc );
934 /* Stop thread system: last one out please shut the door! */
935 vlc_threads_end( p_libvlc );
940 /*****************************************************************************
941 * VLC_VariableSet: set a vlc variable
942 *****************************************************************************/
943 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
945 vlc_t *p_vlc = vlc_current_object( i_object );
953 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
954 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
955 if( !strncmp( psz_var, "conf::", 6 ) )
957 module_config_t *p_item;
958 char const *psz_newvar = psz_var + 6;
960 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
964 switch( p_item->i_type )
966 case CONFIG_ITEM_BOOL:
967 config_PutInt( p_vlc, psz_newvar, value.b_bool );
969 case CONFIG_ITEM_INTEGER:
970 config_PutInt( p_vlc, psz_newvar, value.i_int );
972 case CONFIG_ITEM_FLOAT:
973 config_PutFloat( p_vlc, psz_newvar, value.f_float );
976 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
979 if( i_object ) vlc_object_release( p_vlc );
984 i_ret = var_Set( p_vlc, psz_var, value );
986 if( i_object ) vlc_object_release( p_vlc );
990 /*****************************************************************************
991 * VLC_VariableGet: get a vlc variable
992 *****************************************************************************/
993 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
995 vlc_t *p_vlc = vlc_current_object( i_object );
1003 i_ret = var_Get( p_vlc , psz_var, p_value );
1005 if( i_object ) vlc_object_release( p_vlc );
1009 /*****************************************************************************
1010 * VLC_AddTarget: adds a target for playing.
1011 *****************************************************************************
1012 * This function adds psz_target to the current playlist. If a playlist does
1013 * not exist, it will create one.
1014 *****************************************************************************/
1015 int VLC_AddTarget( int i_object, char const *psz_target,
1016 char const **ppsz_options, int i_options,
1017 int i_mode, int i_pos )
1020 playlist_t *p_playlist;
1021 vlc_t *p_vlc = vlc_current_object( i_object );
1028 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1030 if( p_playlist == NULL )
1032 msg_Dbg( p_vlc, "no playlist present, creating one" );
1033 p_playlist = playlist_Create( p_vlc );
1035 if( p_playlist == NULL )
1037 if( i_object ) vlc_object_release( p_vlc );
1038 return VLC_EGENERIC;
1041 vlc_object_yield( p_playlist );
1044 i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
1045 i_mode, i_pos, -1, ppsz_options, i_options);
1047 vlc_object_release( p_playlist );
1049 if( i_object ) vlc_object_release( p_vlc );
1053 /*****************************************************************************
1055 *****************************************************************************/
1056 int VLC_Play( int i_object )
1058 playlist_t * p_playlist;
1059 vlc_t *p_vlc = vlc_current_object( i_object );
1061 /* Check that the handle is valid */
1067 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1071 if( i_object ) vlc_object_release( p_vlc );
1075 playlist_Play( p_playlist );
1076 vlc_object_release( p_playlist );
1078 if( i_object ) vlc_object_release( p_vlc );
1082 /*****************************************************************************
1083 * VLC_Pause: toggle pause
1084 *****************************************************************************/
1085 int VLC_Pause( int i_object )
1087 playlist_t * p_playlist;
1088 vlc_t *p_vlc = vlc_current_object( i_object );
1090 /* Check that the handle is valid */
1096 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1100 if( i_object ) vlc_object_release( p_vlc );
1104 playlist_Pause( p_playlist );
1105 vlc_object_release( p_playlist );
1107 if( i_object ) vlc_object_release( p_vlc );
1111 /*****************************************************************************
1112 * VLC_Pause: toggle pause
1113 *****************************************************************************/
1114 int VLC_Stop( int i_object )
1116 playlist_t * p_playlist;
1117 vlc_t *p_vlc = vlc_current_object( i_object );
1119 /* Check that the handle is valid */
1125 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1129 if( i_object ) vlc_object_release( p_vlc );
1133 playlist_Stop( p_playlist );
1134 vlc_object_release( p_playlist );
1136 if( i_object ) vlc_object_release( p_vlc );
1140 /*****************************************************************************
1141 * VLC_IsPlaying: Query for Playlist Status
1142 *****************************************************************************/
1143 vlc_bool_t VLC_IsPlaying( int i_object )
1145 playlist_t * p_playlist;
1146 vlc_bool_t b_playing;
1148 vlc_t *p_vlc = vlc_current_object( i_object );
1150 /* Check that the handle is valid */
1156 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1160 if( i_object ) vlc_object_release( p_vlc );
1164 b_playing = playlist_IsPlaying( p_playlist );
1165 vlc_object_release( p_playlist );
1167 if( i_object ) vlc_object_release( p_vlc );
1172 * Get the current position in a input
1174 * Return the current position as a float
1175 * \note For some inputs, this will be unknown.
1177 * \param i_object a vlc object id
1178 * \return a float in the range of 0.0 - 1.0
1180 float VLC_PositionGet( int i_object )
1182 input_thread_t *p_input;
1184 vlc_t *p_vlc = vlc_current_object( i_object );
1186 /* Check that the handle is valid */
1192 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1196 if( i_object ) vlc_object_release( p_vlc );
1200 var_Get( p_input, "position", &val );
1201 vlc_object_release( p_input );
1203 if( i_object ) vlc_object_release( p_vlc );
1208 * Set the current position in a input
1210 * Set the current position in a input and then return
1211 * the current position as a float.
1212 * \note For some inputs, this will be unknown.
1214 * \param i_object a vlc object id
1215 * \param i_position a float in the range of 0.0 - 1.0
1216 * \return a float in the range of 0.0 - 1.0
1218 float VLC_PositionSet( int i_object, float i_position )
1220 input_thread_t *p_input;
1222 vlc_t *p_vlc = vlc_current_object( i_object );
1224 /* Check that the handle is valid */
1230 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1234 if( i_object ) vlc_object_release( p_vlc );
1238 val.f_float = i_position;
1239 var_Set( p_input, "position", val );
1240 var_Get( p_input, "position", &val );
1241 vlc_object_release( p_input );
1243 if( i_object ) vlc_object_release( p_vlc );
1248 * Get the current position in a input
1250 * Return the current position in seconds from the start.
1251 * \note For some inputs, this will be unknown.
1253 * \param i_object a vlc object id
1254 * \return the offset from 0:00 in seconds
1256 int VLC_TimeGet( int i_object )
1258 input_thread_t *p_input;
1260 vlc_t *p_vlc = vlc_current_object( i_object );
1262 /* Check that the handle is valid */
1268 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1272 if( i_object ) vlc_object_release( p_vlc );
1276 var_Get( p_input, "time", &val );
1277 vlc_object_release( p_input );
1279 if( i_object ) vlc_object_release( p_vlc );
1280 return val.i_time / 1000000;
1284 * Seek to a position in the current input
1286 * Seek i_seconds in the current input. If b_relative is set,
1287 * then the seek will be relative to the current position, otherwise
1288 * it will seek to i_seconds from the beginning of the input.
1289 * \note For some inputs, this will be unknown.
1291 * \param i_object a vlc object id
1292 * \param i_seconds seconds from current position or from beginning of input
1293 * \param b_relative seek relative from current position
1294 * \return VLC_SUCCESS on success
1296 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1298 input_thread_t *p_input;
1300 vlc_t *p_vlc = vlc_current_object( i_object );
1302 /* Check that the handle is valid */
1308 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1312 if( i_object ) vlc_object_release( p_vlc );
1318 val.i_time = i_seconds * 1000000;
1319 var_Set( p_input, "time-offset", val );
1323 val.i_time = i_seconds * 1000000;
1324 var_Set( p_input, "time", val );
1326 vlc_object_release( p_input );
1328 if( i_object ) vlc_object_release( p_vlc );
1333 * Get the total length of a input
1335 * Return the total length in seconds from the current input.
1336 * \note For some inputs, this will be unknown.
1338 * \param i_object a vlc object id
1339 * \return the length in seconds
1341 int VLC_LengthGet( int i_object )
1343 input_thread_t *p_input;
1345 vlc_t *p_vlc = vlc_current_object( i_object );
1347 /* Check that the handle is valid */
1353 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1357 if( i_object ) vlc_object_release( p_vlc );
1361 var_Get( p_input, "length", &val );
1362 vlc_object_release( p_input );
1364 if( i_object ) vlc_object_release( p_vlc );
1365 return val.i_time / 1000000;
1369 * Play the input faster than realtime
1371 * 2x, 4x, 8x faster than realtime
1372 * \note For some inputs, this will be impossible.
1374 * \param i_object a vlc object id
1375 * \return the current speedrate
1377 float VLC_SpeedFaster( int i_object )
1379 input_thread_t *p_input;
1381 vlc_t *p_vlc = vlc_current_object( i_object );
1383 /* Check that the handle is valid */
1389 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1393 if( i_object ) vlc_object_release( p_vlc );
1397 val.b_bool = VLC_TRUE;
1398 var_Set( p_input, "rate-faster", val );
1399 var_Get( p_input, "rate", &val );
1400 vlc_object_release( p_input );
1402 if( i_object ) vlc_object_release( p_vlc );
1403 return val.f_float / INPUT_RATE_DEFAULT;
1407 * Play the input slower than realtime
1409 * 1/2x, 1/4x, 1/8x slower than realtime
1410 * \note For some inputs, this will be impossible.
1412 * \param i_object a vlc object id
1413 * \return the current speedrate
1415 float VLC_SpeedSlower( int i_object )
1417 input_thread_t *p_input;
1419 vlc_t *p_vlc = vlc_current_object( i_object );
1421 /* Check that the handle is valid */
1427 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1431 if( i_object ) vlc_object_release( p_vlc );
1435 val.b_bool = VLC_TRUE;
1436 var_Set( p_input, "rate-slower", val );
1437 var_Get( p_input, "rate", &val );
1438 vlc_object_release( p_input );
1440 if( i_object ) vlc_object_release( p_vlc );
1441 return val.f_float / INPUT_RATE_DEFAULT;
1445 * Return the current playlist item
1447 * Returns the index of the playlistitem that is currently selected for play.
1448 * This is valid even if nothing is currently playing.
1450 * \param i_object a vlc object id
1451 * \return the current index
1453 int VLC_PlaylistIndex( int i_object )
1456 playlist_t * p_playlist;
1457 vlc_t *p_vlc = vlc_current_object( i_object );
1459 /* Check that the handle is valid */
1465 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1469 if( i_object ) vlc_object_release( p_vlc );
1473 i_index = p_playlist->i_index;
1474 vlc_object_release( p_playlist );
1476 if( i_object ) vlc_object_release( p_vlc );
1481 * Total amount of items in the playlist
1483 * \param i_object a vlc object id
1484 * \return amount of playlist items
1486 int VLC_PlaylistNumberOfItems( int i_object )
1489 playlist_t * p_playlist;
1490 vlc_t *p_vlc = vlc_current_object( i_object );
1492 /* Check that the handle is valid */
1498 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1502 if( i_object ) vlc_object_release( p_vlc );
1506 i_size = p_playlist->i_size;
1507 vlc_object_release( p_playlist );
1509 if( i_object ) vlc_object_release( p_vlc );
1514 * Next playlist item
1516 * Skip to the next playlistitem and play it.
1518 * \param i_object a vlc object id
1519 * \return VLC_SUCCESS on success
1521 int VLC_PlaylistNext( 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 playlist_Next( p_playlist );
1541 vlc_object_release( p_playlist );
1543 if( i_object ) vlc_object_release( p_vlc );
1548 * Previous playlist item
1550 * Skip to the previous playlistitem and play it.
1552 * \param i_object a vlc object id
1553 * \return VLC_SUCCESS on success
1555 int VLC_PlaylistPrev( int i_object )
1557 playlist_t * p_playlist;
1558 vlc_t *p_vlc = vlc_current_object( i_object );
1560 /* Check that the handle is valid */
1566 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1570 if( i_object ) vlc_object_release( p_vlc );
1574 playlist_Prev( p_playlist );
1575 vlc_object_release( p_playlist );
1577 if( i_object ) vlc_object_release( p_vlc );
1582 /*****************************************************************************
1583 * VLC_PlaylistClear: Empty the playlist
1584 *****************************************************************************/
1585 int VLC_PlaylistClear( int i_object )
1588 playlist_t * p_playlist;
1589 vlc_t *p_vlc = vlc_current_object( i_object );
1591 /* Check that the handle is valid */
1597 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1601 if( i_object ) vlc_object_release( p_vlc );
1605 i_err = playlist_Clear( p_playlist );
1607 vlc_object_release( p_playlist );
1609 if( i_object ) vlc_object_release( p_vlc );
1616 * \param i_object a vlc object id
1617 * \param i_volume something in a range from 0-200
1618 * \return the new volume (range 0-200 %)
1620 int VLC_VolumeSet( int i_object, int i_volume )
1622 audio_volume_t i_vol = 0;
1623 vlc_t *p_vlc = vlc_current_object( i_object );
1625 /* Check that the handle is valid */
1631 if( i_volume >= 0 && i_volume <= 200 )
1633 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1634 aout_VolumeSet( p_vlc, i_vol );
1637 if( i_object ) vlc_object_release( p_vlc );
1638 return i_vol * 200 / AOUT_VOLUME_MAX;
1642 * Get the current volume
1644 * Retrieve the current volume.
1646 * \param i_object a vlc object id
1647 * \return the current volume (range 0-200 %)
1649 int VLC_VolumeGet( int i_object )
1651 audio_volume_t i_volume;
1652 vlc_t *p_vlc = vlc_current_object( i_object );
1654 /* Check that the handle is valid */
1660 aout_VolumeGet( p_vlc, &i_volume );
1662 if( i_object ) vlc_object_release( p_vlc );
1663 return i_volume*200/AOUT_VOLUME_MAX;
1667 * Mute/Unmute the volume
1669 * \param i_object a vlc object id
1670 * \return VLC_SUCCESS on success
1672 int VLC_VolumeMute( int i_object )
1674 vlc_t *p_vlc = vlc_current_object( i_object );
1676 /* Check that the handle is valid */
1682 aout_VolumeMute( p_vlc, NULL );
1684 if( i_object ) vlc_object_release( p_vlc );
1688 /*****************************************************************************
1689 * VLC_FullScreen: toggle fullscreen mode
1690 *****************************************************************************/
1691 int VLC_FullScreen( int i_object )
1693 vout_thread_t *p_vout;
1694 vlc_t *p_vlc = vlc_current_object( i_object );
1701 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1705 if( i_object ) vlc_object_release( p_vlc );
1709 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1710 vlc_object_release( p_vout );
1712 if( i_object ) vlc_object_release( p_vlc );
1716 /* following functions are local */
1718 /*****************************************************************************
1719 * SetLanguage: set the interface language.
1720 *****************************************************************************
1721 * We set the LC_MESSAGES locale category for interface messages and buttons,
1722 * as well as the LC_CTYPE category for string sorting and possible wide
1723 * character support.
1724 *****************************************************************************/
1725 static void SetLanguage ( char const *psz_lang )
1727 #if defined( ENABLE_NLS ) \
1728 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1731 #if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
1735 if( psz_lang && !*psz_lang )
1737 # if defined( HAVE_LC_MESSAGES )
1738 setlocale( LC_MESSAGES, psz_lang );
1740 setlocale( LC_CTYPE, psz_lang );
1745 /* I need that under Darwin, please check it doesn't disturb
1746 * other platforms. --Meuuh */
1747 setenv( "LANG", psz_lang, 1 );
1749 #elif defined( SYS_BEOS ) || defined( WIN32 )
1750 /* We set LC_ALL manually because it is the only way to set
1751 * the language at runtime under eg. Windows. Beware that this
1752 * makes the environment unconsistent when libvlc is unloaded and
1753 * should probably be moved to a safer place like vlc.c. */
1754 static char psz_lcall[20];
1755 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1756 psz_lcall[19] = '\0';
1757 putenv( psz_lcall );
1760 setlocale( LC_ALL, psz_lang );
1763 /* Specify where to find the locales for current domain */
1764 #if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1765 psz_path = LOCALEDIR;
1767 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1771 if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
1773 fprintf( stderr, "warning: no domain %s in directory %s\n",
1774 PACKAGE_NAME, psz_path );
1777 /* Set the default domain */
1778 textdomain( PACKAGE_NAME );
1780 #if defined( ENABLE_UTF8 )
1781 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
1787 /*****************************************************************************
1788 * GetFilenames: parse command line options which are not flags
1789 *****************************************************************************
1790 * Parse command line for input files as well as their associated options.
1791 * An option always follows its associated input and begins with a ":".
1792 *****************************************************************************/
1793 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1795 int i_opt, i_options;
1797 /* We assume that the remaining parameters are filenames
1798 * and their input options */
1799 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
1803 /* Count the input options */
1804 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
1810 /* TODO: write an internal function of this one, to avoid
1811 * unnecessary lookups. */
1812 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1813 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
1815 PLAYLIST_INSERT, 0 );
1821 /*****************************************************************************
1822 * Usage: print program usage
1823 *****************************************************************************
1824 * Print a short inline help. Message interface is initialized at this stage.
1825 *****************************************************************************/
1826 static void Usage( vlc_t *p_this, char const *psz_module_name )
1828 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1829 /* short option ------' | | | | | | |
1830 * option name ------------' | | | | | |
1831 * <bra -------------------------' | | | | |
1832 * option type or "" --------------' | | | |
1833 * ket> -----------------------------' | | |
1834 * padding spaces ---------------------' | |
1835 * comment -------------------------------' |
1836 * comment suffix --------------------------'
1838 * The purpose of having bra and ket is that we might i18n them as well.
1840 #define LINE_START 8
1841 #define PADDING_SPACES 25
1844 module_config_t *p_item;
1845 char psz_spaces[PADDING_SPACES+LINE_START+1];
1846 char psz_format[sizeof(FORMAT_STRING)];
1847 char psz_buffer[1000];
1850 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1851 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
1853 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1854 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1856 strcpy( psz_format, FORMAT_STRING );
1862 /* List all modules */
1863 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1865 /* Enumerate the config for each module */
1866 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1868 vlc_bool_t b_help_module;
1870 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1872 if( psz_module_name && strcmp( psz_module_name,
1873 p_parser->psz_object_name ) )
1878 /* Ignore modules without config options */
1879 if( !p_parser->i_config_items )
1884 /* Ignore modules with only advanced config options if requested */
1887 for( p_item = p_parser->p_config;
1888 p_item->i_type != CONFIG_HINT_END;
1891 if( (p_item->i_type & CONFIG_ITEM) &&
1892 !p_item->b_advanced ) break;
1894 if( p_item->i_type == CONFIG_HINT_END ) continue;
1897 /* Print name of module */
1898 if( strcmp( "main", p_parser->psz_object_name ) )
1899 fprintf( stdout, "\n %s\n", p_parser->psz_longname );
1901 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1903 /* Print module options */
1904 for( p_item = p_parser->p_config;
1905 p_item->i_type != CONFIG_HINT_END;
1909 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1910 char *psz_suf = "", *psz_prefix = NULL;
1913 /* Skip advanced options if requested */
1914 if( p_item->b_advanced && !b_advanced )
1919 switch( p_item->i_type )
1921 case CONFIG_HINT_CATEGORY:
1922 case CONFIG_HINT_USAGE:
1923 if( !strcmp( "main", p_parser->psz_object_name ) )
1924 fprintf( stdout, "\n %s\n", p_item->psz_text );
1927 case CONFIG_ITEM_STRING:
1928 case CONFIG_ITEM_FILE:
1929 case CONFIG_ITEM_DIRECTORY:
1930 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1931 if( !p_item->ppsz_list )
1933 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1939 psz_type = psz_buffer;
1941 for( i = 0; p_item->ppsz_list[i]; i++ )
1943 if( i ) strcat( psz_type, "," );
1944 strcat( psz_type, p_item->ppsz_list[i] );
1949 case CONFIG_ITEM_INTEGER:
1950 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
1951 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1953 case CONFIG_ITEM_FLOAT:
1954 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1956 case CONFIG_ITEM_BOOL:
1957 psz_bra = ""; psz_type = ""; psz_ket = "";
1958 if( !b_help_module )
1960 psz_suf = p_item->i_value ? _(" (default enabled)") :
1961 _(" (default disabled)");
1971 /* Add short option if any */
1972 if( p_item->i_short )
1974 sprintf( psz_short, "-%c,", p_item->i_short );
1978 strcpy( psz_short, " " );
1981 i = PADDING_SPACES - strlen( p_item->psz_name )
1982 - strlen( psz_bra ) - strlen( psz_type )
1983 - strlen( psz_ket ) - 1;
1985 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1987 /* If option is of type --foo-bar, we print its counterpart
1988 * as --no-foo-bar, but if it is of type --foobar (without
1989 * dashes in the name) we print it as --nofoobar. Both
1990 * values are of course valid, only the display changes. */
1991 psz_prefix = strchr( p_item->psz_name, '-' ) ? ", --no-"
1993 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
1998 psz_spaces[0] = '\n';
2003 psz_spaces[i] = '\0';
2006 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2008 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2009 psz_prefix, p_item->psz_name, psz_bra, psz_type,
2010 psz_ket, psz_spaces );
2014 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2015 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
2018 psz_spaces[i] = ' ';
2020 /* We wrap the rest of the output */
2021 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
2022 psz_text = psz_buffer;
2025 char *psz_parser, *psz_word;
2026 int i_end = strlen( psz_text );
2028 /* If the remaining text fits in a line, print it. */
2029 if( i_end <= i_width )
2031 fprintf( stdout, "%s\n", psz_text );
2035 /* Otherwise, eat as many words as possible */
2036 psz_parser = psz_text;
2039 psz_word = psz_parser;
2040 psz_parser = strchr( psz_word, ' ' );
2041 /* If no space was found, we reached the end of the text
2042 * block; otherwise, we skip the space we just found. */
2043 psz_parser = psz_parser ? psz_parser + 1
2046 } while( psz_parser - psz_text <= i_width );
2048 /* We cut a word in one of these cases:
2049 * - it's the only word in the line and it's too long.
2050 * - we used less than 80% of the width and the word we are
2051 * going to wrap is longer than 40% of the width, and even
2052 * if the word would have fit in the next line. */
2053 if( psz_word == psz_text
2054 || ( psz_word - psz_text < 80 * i_width / 100
2055 && psz_parser - psz_word > 40 * i_width / 100 ) )
2057 char c = psz_text[i_width];
2058 psz_text[i_width] = '\0';
2059 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2060 psz_text += i_width;
2065 psz_word[-1] = '\0';
2066 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2067 psz_text = psz_word;
2073 /* Release the module list */
2074 vlc_list_release( p_list );
2076 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2081 /*****************************************************************************
2082 * ListModules: list the available modules with their description
2083 *****************************************************************************
2084 * Print a list of all available modules (builtins and plugins) and a short
2085 * description for each one.
2086 *****************************************************************************/
2087 static void ListModules( vlc_t *p_this )
2091 char psz_spaces[22];
2094 memset( psz_spaces, ' ', 22 );
2101 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
2102 p_this->p_vlc->psz_object_name );
2104 fprintf( stdout, _("[module] [description]\n") );
2106 /* List all modules */
2107 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2109 /* Enumerate each module */
2110 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2114 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2116 /* Nasty hack, but right now I'm too tired to think about a nice
2118 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2122 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2123 psz_spaces, p_parser->psz_longname );
2125 psz_spaces[i] = ' ';
2128 vlc_list_release( p_list );
2130 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2135 /*****************************************************************************
2136 * Version: print complete program version
2137 *****************************************************************************
2138 * Print complete program version and build number.
2139 *****************************************************************************/
2140 static void Version( void )
2146 fprintf( stdout, VERSION_MESSAGE "\n" );
2148 _("This program comes with NO WARRANTY, to the extent permitted by "
2149 "law.\nYou may redistribute it under the terms of the GNU General "
2150 "Public License;\nsee the file named COPYING for details.\n"
2151 "Written by the VideoLAN team; see the AUTHORS file.\n") );
2153 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2158 /*****************************************************************************
2159 * ShowConsole: On Win32, create an output console for debug messages
2160 *****************************************************************************
2161 * This function is useful only on Win32.
2162 *****************************************************************************/
2164 static void ShowConsole( void )
2168 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2171 freopen( "CONOUT$", "w", stdout );
2172 freopen( "CONOUT$", "w", stderr );
2173 freopen( "CONIN$", "r", stdin );
2179 /*****************************************************************************
2180 * PauseConsole: On Win32, wait for a key press before closing the console
2181 *****************************************************************************
2182 * This function is useful only on Win32.
2183 *****************************************************************************/
2185 static void PauseConsole( void )
2189 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2190 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2197 /*****************************************************************************
2198 * ConsoleWidth: Return the console width in characters
2199 *****************************************************************************
2200 * We use the stty shell command to get the console width; if this fails or
2201 * if the width is less than 80, we default to 80.
2202 *****************************************************************************/
2203 static int ConsoleWidth( void )
2208 char buf[20], *psz_parser;
2212 file = popen( "stty size 2>/dev/null", "r" );
2215 i_ret = fread( buf, 1, 20, file );
2219 psz_parser = strchr( buf, ' ' );
2222 i_ret = atoi( psz_parser + 1 );
2237 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2238 vlc_value_t old_val, vlc_value_t new_val, void *param)
2240 vlc_t *p_vlc = (vlc_t *)p_this;
2242 if( new_val.i_int >= -1 )
2244 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );
2249 /*****************************************************************************
2250 * InitDeviceValues: initialize device values
2251 *****************************************************************************
2252 * This function inits the dvd, vcd and cd-audio values
2253 *****************************************************************************/
2254 static void InitDeviceValues( vlc_t *p_vlc )
2257 LibHalContext * ctx;
2263 if( ( ctx = hal_initialize( NULL, FALSE ) ) )
2265 if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) )
2267 for( i = 0; i < i_devices; i++ )
2269 if( !hal_device_property_exists( ctx, devices[ i ],
2270 "storage.cdrom.dvd" ) )
2275 b_dvd = hal_device_get_property_bool( ctx, devices[ i ],
2276 "storage.cdrom.dvd" );
2277 block_dev = hal_device_get_property_string( ctx, devices[ i ],
2282 config_PutPsz( p_vlc, "dvd", block_dev );
2285 config_PutPsz( p_vlc, "vcd", block_dev );
2286 config_PutPsz( p_vlc, "cd-audio", block_dev );
2288 hal_free_string( block_dev );
2292 hal_shutdown( ctx );