1 /*****************************************************************************
2 * libvlc.c: main libvlc source
3 *****************************************************************************
4 * Copyright (C) 1998-2004 the VideoLAN team
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 Help ( vlc_t *, char const *psz_help_name );
97 static void Usage ( vlc_t *, char const *psz_module_name );
98 static void ListModules ( vlc_t * );
99 static void Version ( void );
102 static void ShowConsole ( void );
103 static void PauseConsole ( void );
105 static int ConsoleWidth ( void );
107 static int VerboseCallback( vlc_object_t *, char const *,
108 vlc_value_t, vlc_value_t, void * );
110 static void InitDeviceValues( vlc_t * );
112 /*****************************************************************************
113 * vlc_current_object: return the current object.
114 *****************************************************************************
115 * If i_object is non-zero, return the corresponding object. Otherwise,
116 * return the statically allocated p_vlc object.
117 *****************************************************************************/
118 vlc_t * vlc_current_object( int i_object )
122 return vlc_object_get( p_libvlc, i_object );
128 /*****************************************************************************
129 * VLC_Version: return the libvlc version.
130 *****************************************************************************
131 * This function returns full version string (numeric version and codename).
132 *****************************************************************************/
133 char const * VLC_Version( void )
135 return VERSION_MESSAGE;
138 /*****************************************************************************
139 * VLC_Error: strerror() equivalent
140 *****************************************************************************
141 * This function returns full version string (numeric version and codename).
142 *****************************************************************************/
143 char const * VLC_Error( int i_err )
145 return vlc_error( i_err );
148 /*****************************************************************************
149 * VLC_Create: allocate a vlc_t structure, and initialize libvlc if needed.
150 *****************************************************************************
151 * This function allocates a vlc_t structure and returns a negative value
152 * in case of failure. Also, the thread system is initialized.
153 *****************************************************************************/
154 int VLC_Create( void )
157 vlc_t * p_vlc = NULL;
160 /* &libvlc never changes, so we can safely call this multiple times. */
163 /* vlc_threads_init *must* be the first internal call! No other call is
164 * allowed before the thread system has been initialized. */
165 i_ret = vlc_threads_init( p_libvlc );
171 /* Now that the thread system is initialized, we don't have much, but
172 * at least we have var_Create */
173 var_Create( p_libvlc, "libvlc", VLC_VAR_MUTEX );
174 var_Get( p_libvlc, "libvlc", &lockval );
175 vlc_mutex_lock( lockval.p_address );
176 if( !libvlc.b_ready )
180 /* Guess what CPU we have */
181 libvlc.i_cpu = CPUCapabilities();
183 /* Find verbosity from VLC_VERBOSE environment variable */
184 psz_env = getenv( "VLC_VERBOSE" );
185 libvlc.i_verbose = psz_env ? atoi( psz_env ) : -1;
187 #if defined( HAVE_ISATTY ) && !defined( WIN32 )
188 libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
190 libvlc.b_color = VLC_FALSE;
193 /* Initialize message queue */
194 msg_Create( p_libvlc );
196 /* Announce who we are */
197 msg_Dbg( p_libvlc, COPYRIGHT_MESSAGE );
198 msg_Dbg( p_libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
200 /* The module bank will be initialized later */
201 libvlc.p_module_bank = NULL;
203 libvlc.b_ready = VLC_TRUE;
205 vlc_mutex_unlock( lockval.p_address );
206 var_Destroy( p_libvlc, "libvlc" );
208 /* Allocate a vlc object */
209 p_vlc = vlc_object_create( p_libvlc, VLC_OBJECT_VLC );
214 p_vlc->thread_id = 0;
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 );
222 vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
225 /* Store our newly allocated structure in the global list */
226 vlc_object_attach( p_vlc, p_libvlc );
228 /* Store data for the non-reentrant API */
229 p_static_vlc = p_vlc;
231 return p_vlc->i_object_id;
234 /*****************************************************************************
235 * VLC_Init: initialize a vlc_t structure.
236 *****************************************************************************
237 * This function initializes a previously allocated vlc_t structure:
239 * - gettext initialization
240 * - message queue, module bank and playlist initialization
241 * - configuration and commandline parsing
242 *****************************************************************************/
243 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
245 char p_capabilities[200];
250 vlc_bool_t b_exit = VLC_FALSE;
251 vlc_t * p_vlc = vlc_current_object( i_object );
252 module_t *p_help_module;
253 playlist_t *p_playlist;
265 * System specific initialization code
267 system_Init( p_vlc, &i_argc, ppsz_argv );
269 /* Get the executable name (similar to the basename command) */
272 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
275 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
281 p_vlc->psz_object_name = "vlc";
285 * Support for gettext
289 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
290 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
292 /* Initialize the module bank and load the configuration of the
293 * main module. We need to do this at this stage to be able to display
294 * a short help if required by the user. (short help == main module
296 module_InitBank( p_vlc );
298 /* Hack: insert the help module here */
299 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
300 if( p_help_module == NULL )
302 module_EndBank( p_vlc );
303 if( i_object ) vlc_object_release( p_vlc );
306 p_help_module->psz_object_name = "help";
307 p_help_module->psz_longname = N_("Help options");
308 config_Duplicate( p_help_module, p_help_config );
309 vlc_object_attach( p_help_module, libvlc.p_module_bank );
312 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
314 vlc_object_detach( p_help_module );
315 config_Free( p_help_module );
316 vlc_object_destroy( p_help_module );
317 module_EndBank( p_vlc );
318 if( i_object ) vlc_object_release( p_vlc );
322 /* Check for short help option */
323 if( config_GetInt( p_vlc, "help" ) )
325 Help( p_vlc, "help" );
328 /* Check for version option */
329 else if( config_GetInt( p_vlc, "version" ) )
335 /* Set the config file stuff */
336 p_vlc->psz_homedir = config_GetHomeDir();
337 p_vlc->psz_configfile = config_GetPsz( p_vlc, "config" );
339 /* Check for plugins cache options */
340 if( config_GetInt( p_vlc, "reset-plugins-cache" ) )
342 libvlc.p_module_bank->b_cache_delete = VLC_TRUE;
345 /* Hack: remove the help module here */
346 vlc_object_detach( p_help_module );
349 /* Will be re-done properly later on */
350 p_vlc->p_libvlc->i_verbose = config_GetInt( p_vlc, "verbose" );
352 /* Check for daemon mode */
354 if( config_GetInt( p_vlc, "daemon" ) )
357 if( daemon( 0, 0) != 0 )
359 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
363 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
368 if( ( i_pid = fork() ) < 0 )
370 msg_Err( p_vlc, "Unable to fork vlc to daemon mode" );
375 /* This is the parent, exit right now */
376 msg_Dbg( p_vlc, "closing parent process" );
381 /* We are the child */
382 msg_Dbg( p_vlc, "daemon spawned" );
383 close( STDIN_FILENO );
384 close( STDOUT_FILENO );
385 close( STDERR_FILENO );
387 p_vlc->p_libvlc->b_daemon = VLC_TRUE;
395 config_Free( p_help_module );
396 vlc_object_destroy( p_help_module );
397 module_EndBank( p_vlc );
398 if( i_object ) vlc_object_release( p_vlc );
402 /* Check for translation config option */
403 #if defined( ENABLE_NLS ) \
404 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
406 /* This ain't really nice to have to reload the config here but it seems
407 * the only way to do it. */
408 config_LoadConfigFile( p_vlc, "main" );
409 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
411 /* Check if the user specified a custom language */
412 psz_language = config_GetPsz( p_vlc, "language" );
413 if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
415 vlc_bool_t b_cache_delete = libvlc.p_module_bank->b_cache_delete;
417 /* Reset the default domain */
418 SetLanguage( psz_language );
420 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
421 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
423 textdomain( PACKAGE_NAME );
425 #if defined( ENABLE_UTF8 )
426 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
429 module_EndBank( p_vlc );
430 module_InitBank( p_vlc );
431 config_LoadConfigFile( p_vlc, "main" );
432 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
433 libvlc.p_module_bank->b_cache_delete = b_cache_delete;
435 if( psz_language ) free( psz_language );
439 * Load the builtins and plugins into the module_bank.
440 * We have to do it before config_Load*() because this also gets the
441 * list of configuration options exported by each module and loads their
444 module_LoadBuiltins( p_vlc );
445 module_LoadPlugins( p_vlc );
451 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
452 libvlc.p_module_bank->i_children );
454 /* Hack: insert the help module here */
455 vlc_object_attach( p_help_module, libvlc.p_module_bank );
458 /* Check for help on modules */
459 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
461 Help( p_vlc, p_tmp );
465 /* Check for long help option */
466 else if( config_GetInt( p_vlc, "longhelp" ) )
468 Help( p_vlc, "longhelp" );
471 /* Check for module list option */
472 else if( config_GetInt( p_vlc, "list" ) )
474 ListModules( p_vlc );
478 /* Check for config file options */
479 if( config_GetInt( p_vlc, "reset-config" ) )
481 vlc_object_detach( p_help_module );
482 config_ResetAll( p_vlc );
483 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
484 config_SaveConfigFile( p_vlc, NULL );
485 vlc_object_attach( p_help_module, libvlc.p_module_bank );
487 if( config_GetInt( p_vlc, "save-config" ) )
489 vlc_object_detach( p_help_module );
490 config_LoadConfigFile( p_vlc, NULL );
491 config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE );
492 config_SaveConfigFile( p_vlc, NULL );
493 vlc_object_attach( p_help_module, libvlc.p_module_bank );
496 /* Hack: remove the help module here */
497 vlc_object_detach( p_help_module );
502 config_Free( p_help_module );
503 vlc_object_destroy( p_help_module );
504 module_EndBank( p_vlc );
505 if( i_object ) vlc_object_release( p_vlc );
512 InitDeviceValues( p_vlc );
515 * Override default configuration with config file settings
517 config_LoadConfigFile( p_vlc, NULL );
519 /* Hack: insert the help module here */
520 vlc_object_attach( p_help_module, libvlc.p_module_bank );
524 * Override configuration with command line settings
526 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
530 /* Pause the console because it's destroyed when we exit */
531 fprintf( stderr, "The command line options couldn't be loaded, check "
532 "that they are valid.\n" );
535 vlc_object_detach( p_help_module );
536 config_Free( p_help_module );
537 vlc_object_destroy( p_help_module );
538 module_EndBank( p_vlc );
539 if( i_object ) vlc_object_release( p_vlc );
543 /* Hack: remove the help module here */
544 vlc_object_detach( p_help_module );
545 config_Free( p_help_module );
546 vlc_object_destroy( p_help_module );
550 * System specific configuration
552 system_Configure( p_vlc, &i_argc, ppsz_argv );
555 * Message queue options
558 var_Create( p_vlc, "verbose", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT );
559 if( config_GetInt( p_vlc, "quiet" ) )
562 var_Set( p_vlc, "verbose", val );
564 var_AddCallback( p_vlc, "verbose", VerboseCallback, NULL );
565 var_Change( p_vlc, "verbose", VLC_VAR_TRIGGER_CALLBACKS, NULL, NULL );
567 libvlc.b_color = libvlc.b_color && config_GetInt( p_vlc, "color" );
570 * Output messages that may still be in the queue
574 /* p_vlc initialization. FIXME ? */
576 if( !config_GetInt( p_vlc, "fpu" ) )
577 libvlc.i_cpu &= ~CPU_CAPABILITY_FPU;
579 #if defined( __i386__ ) || defined( __x86_64__ )
580 if( !config_GetInt( p_vlc, "mmx" ) )
581 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
582 if( !config_GetInt( p_vlc, "3dn" ) )
583 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
584 if( !config_GetInt( p_vlc, "mmxext" ) )
585 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
586 if( !config_GetInt( p_vlc, "sse" ) )
587 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
588 if( !config_GetInt( p_vlc, "sse2" ) )
589 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE2;
591 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
592 if( !config_GetInt( p_vlc, "altivec" ) )
593 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
596 #define PRINT_CAPABILITY( capability, string ) \
597 if( libvlc.i_cpu & capability ) \
599 strncat( p_capabilities, string " ", \
600 sizeof(p_capabilities) - strlen(p_capabilities) ); \
601 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
604 p_capabilities[0] = '\0';
605 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
606 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
607 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
608 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
609 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
610 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
611 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
612 PRINT_CAPABILITY( CPU_CAPABILITY_SSE2, "SSE2" );
613 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
614 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
615 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
618 * Choose the best memcpy module
620 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy", 0 );
622 if( p_vlc->pf_memcpy == NULL )
624 p_vlc->pf_memcpy = memcpy;
627 if( p_vlc->pf_memset == NULL )
629 p_vlc->pf_memset = memset;
633 * Initialize hotkey handling
635 var_Create( p_vlc, "key-pressed", VLC_VAR_INTEGER );
636 p_vlc->p_hotkeys = malloc( sizeof(p_hotkeys) );
637 /* Do a copy (we don't need to modify the strings) */
638 memcpy( p_vlc->p_hotkeys, p_hotkeys, sizeof(p_hotkeys) );
641 * Initialize playlist and get commandline files
643 p_playlist = playlist_Create( p_vlc );
646 msg_Err( p_vlc, "playlist initialization failed" );
647 if( p_vlc->p_memcpy_module != NULL )
649 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
651 module_EndBank( p_vlc );
652 if( i_object ) vlc_object_release( p_vlc );
656 psz_modules = config_GetPsz( p_playlist, "services-discovery" );
657 if( psz_modules && *psz_modules )
659 /* Add service discovery modules */
660 playlist_AddSDModules( p_playlist, psz_modules );
662 if( psz_modules ) free( psz_modules );
665 * Load background interfaces
667 psz_modules = config_GetPsz( p_vlc, "extraintf" );
668 psz_control = config_GetPsz( p_vlc, "control" );
670 if( psz_modules && *psz_modules && psz_control && *psz_control )
672 psz_modules = (char *)realloc( psz_modules, strlen( psz_modules ) +
673 strlen( psz_control ) + 1 );
674 sprintf( psz_modules, "%s:%s", psz_modules, psz_control );
676 else if( psz_control && *psz_control )
678 if( psz_modules ) free( psz_modules );
679 psz_modules = strdup( psz_control );
682 psz_parser = psz_modules;
683 while ( psz_parser && *psz_parser )
685 char *psz_module, *psz_temp;
686 psz_module = psz_parser;
687 psz_parser = strchr( psz_module, ':' );
693 psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
696 sprintf( psz_temp, "%s,none", psz_module );
697 VLC_AddIntf( 0, psz_temp, VLC_FALSE, VLC_FALSE );
707 * Allways load the hotkeys interface if it exists
709 VLC_AddIntf( 0, "hotkeys,none", VLC_FALSE, VLC_FALSE );
712 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
714 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
715 var_Create( p_vlc, "drawableredraw", VLC_VAR_INTEGER );
716 var_Create( p_vlc, "drawablet", VLC_VAR_INTEGER );
717 var_Create( p_vlc, "drawablel", VLC_VAR_INTEGER );
718 var_Create( p_vlc, "drawableb", VLC_VAR_INTEGER );
719 var_Create( p_vlc, "drawabler", VLC_VAR_INTEGER );
720 var_Create( p_vlc, "drawablex", VLC_VAR_INTEGER );
721 var_Create( p_vlc, "drawabley", VLC_VAR_INTEGER );
722 var_Create( p_vlc, "drawablew", VLC_VAR_INTEGER );
723 var_Create( p_vlc, "drawableh", VLC_VAR_INTEGER );
724 var_Create( p_vlc, "drawableportx", VLC_VAR_INTEGER );
725 var_Create( p_vlc, "drawableporty", VLC_VAR_INTEGER );
728 * Get input filenames given as commandline arguments
730 GetFilenames( p_vlc, i_argc, ppsz_argv );
733 * Get --open argument
735 var_Create( p_vlc, "open", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
736 var_Get( p_vlc, "open", &val );
737 if ( val.psz_string != NULL && *val.psz_string )
739 VLC_AddTarget( p_vlc->i_object_id, val.psz_string, NULL, 0,
740 PLAYLIST_INSERT, 0 );
742 if ( val.psz_string != NULL ) free( val.psz_string );
744 if( i_object ) vlc_object_release( p_vlc );
748 /*****************************************************************************
749 * VLC_AddIntf: add an interface
750 *****************************************************************************
751 * This function opens an interface plugin and runs it. If b_block is set
752 * to 0, VLC_AddIntf will return immediately and let the interface run in a
753 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
754 * user requests to quit. If b_play is set to 1, VLC_AddIntf will start playing
755 * the playlist when it is completely initialised.
756 *****************************************************************************/
757 int VLC_AddIntf( int i_object, char const *psz_module,
758 vlc_bool_t b_block, vlc_bool_t b_play )
761 intf_thread_t *p_intf;
762 vlc_t *p_vlc = vlc_current_object( i_object );
770 if( p_vlc->p_libvlc->b_daemon && b_block && !psz_module )
773 * We prefer the dummy interface if none is specified. */
774 char *psz_interface = config_GetPsz( p_vlc, "intf" );
775 if( !psz_interface || !*psz_interface ) psz_module = "dummy";
776 if( psz_interface ) free( psz_interface );
780 /* Try to create the interface */
781 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
785 msg_Err( p_vlc, "interface \"%s\" initialization failed", psz_module );
786 if( i_object ) vlc_object_release( p_vlc );
790 /* Interface doesn't handle play on start so do it ourselves */
791 if( !p_intf->b_play && b_play ) VLC_Play( i_object );
793 /* Try to run the interface */
794 p_intf->b_play = b_play;
795 p_intf->b_block = b_block;
796 i_err = intf_RunThread( p_intf );
799 vlc_object_detach( p_intf );
800 intf_Destroy( p_intf );
801 if( i_object ) vlc_object_release( p_vlc );
805 if( i_object ) vlc_object_release( p_vlc );
809 /*****************************************************************************
810 * VLC_Die: ask vlc to die.
811 *****************************************************************************
812 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
813 * task. It is your duty to call VLC_CleanUp and VLC_Destroy afterwards.
814 *****************************************************************************/
815 int VLC_Die( int i_object )
817 vlc_t *p_vlc = vlc_current_object( i_object );
824 p_vlc->b_die = VLC_TRUE;
826 if( i_object ) vlc_object_release( p_vlc );
830 /*****************************************************************************
831 * VLC_CleanUp: CleanUp all the intf, playlist, vout, aout
832 *****************************************************************************/
833 int VLC_CleanUp( int i_object )
835 intf_thread_t * p_intf;
836 playlist_t * p_playlist;
837 vout_thread_t * p_vout;
838 aout_instance_t * p_aout;
839 announce_handler_t * p_announce;
840 vlc_t *p_vlc = vlc_current_object( i_object );
842 /* Check that the handle is valid */
849 * Ask the interfaces to stop and destroy them
851 msg_Dbg( p_vlc, "removing all interfaces" );
852 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
854 intf_StopThread( p_intf );
855 vlc_object_detach( p_intf );
856 vlc_object_release( p_intf );
857 intf_Destroy( p_intf );
863 msg_Dbg( p_vlc, "removing all playlists" );
864 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
867 vlc_object_detach( p_playlist );
868 vlc_object_release( p_playlist );
869 playlist_Destroy( p_playlist );
875 msg_Dbg( p_vlc, "removing all video outputs" );
876 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
878 vlc_object_detach( p_vout );
879 vlc_object_release( p_vout );
880 vout_Destroy( p_vout );
886 msg_Dbg( p_vlc, "removing all audio outputs" );
887 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
889 vlc_object_detach( (vlc_object_t *)p_aout );
890 vlc_object_release( (vlc_object_t *)p_aout );
891 aout_Delete( p_aout );
895 * Free announce handler(s?)
897 msg_Dbg( p_vlc, "removing announce handler" );
898 while( (p_announce = vlc_object_find( p_vlc, VLC_OBJECT_ANNOUNCE,
901 vlc_object_detach( p_announce );
902 vlc_object_release( p_announce );
903 announce_HandlerDestroy( p_announce );
906 if( i_object ) vlc_object_release( p_vlc );
910 /*****************************************************************************
911 * VLC_Destroy: Destroy everything.
912 *****************************************************************************
913 * This function requests the running threads to finish, waits for their
914 * termination, and destroys their structure.
915 *****************************************************************************/
916 int VLC_Destroy( int i_object )
918 vlc_t *p_vlc = vlc_current_object( i_object );
926 * Free allocated memory
928 if( p_vlc->p_memcpy_module )
930 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
931 p_vlc->p_memcpy_module = NULL;
937 module_EndBank( p_vlc );
939 if( p_vlc->psz_homedir )
941 free( p_vlc->psz_homedir );
942 p_vlc->psz_homedir = NULL;
945 if( p_vlc->psz_configfile )
947 free( p_vlc->psz_configfile );
948 p_vlc->psz_configfile = NULL;
951 if( p_vlc->p_hotkeys )
953 free( p_vlc->p_hotkeys );
954 p_vlc->p_hotkeys = NULL;
958 * System specific cleaning code
962 /* Destroy mutexes */
963 vlc_mutex_destroy( &p_vlc->config_lock );
965 vlc_object_detach( p_vlc );
967 /* Release object before destroying it */
968 if( i_object ) vlc_object_release( p_vlc );
970 vlc_object_destroy( p_vlc );
972 /* Stop thread system: last one out please shut the door! */
973 vlc_threads_end( p_libvlc );
978 /*****************************************************************************
979 * VLC_VariableSet: set a vlc variable
980 *****************************************************************************/
981 int VLC_VariableSet( int i_object, char const *psz_var, vlc_value_t value )
983 vlc_t *p_vlc = vlc_current_object( i_object );
991 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
992 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
993 if( !strncmp( psz_var, "conf::", 6 ) )
995 module_config_t *p_item;
996 char const *psz_newvar = psz_var + 6;
998 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
1002 switch( p_item->i_type )
1004 case CONFIG_ITEM_BOOL:
1005 config_PutInt( p_vlc, psz_newvar, value.b_bool );
1007 case CONFIG_ITEM_INTEGER:
1008 config_PutInt( p_vlc, psz_newvar, value.i_int );
1010 case CONFIG_ITEM_FLOAT:
1011 config_PutFloat( p_vlc, psz_newvar, value.f_float );
1014 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
1017 if( i_object ) vlc_object_release( p_vlc );
1022 i_ret = var_Set( p_vlc, psz_var, value );
1024 if( i_object ) vlc_object_release( p_vlc );
1028 /*****************************************************************************
1029 * VLC_VariableGet: get a vlc variable
1030 *****************************************************************************/
1031 int VLC_VariableGet( int i_object, char const *psz_var, vlc_value_t *p_value )
1033 vlc_t *p_vlc = vlc_current_object( i_object );
1041 i_ret = var_Get( p_vlc , psz_var, p_value );
1043 if( i_object ) vlc_object_release( p_vlc );
1047 /*****************************************************************************
1048 * VLC_VariableType: get a vlc variable type
1049 *****************************************************************************/
1050 int VLC_VariableType( int i_object, char const *psz_var, int *pi_type )
1053 vlc_t *p_vlc = vlc_current_object( i_object );
1060 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
1061 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
1062 if( !strncmp( psz_var, "conf::", 6 ) )
1064 module_config_t *p_item;
1065 char const *psz_newvar = psz_var + 6;
1067 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
1071 switch( p_item->i_type )
1073 case CONFIG_ITEM_BOOL:
1074 i_type = VLC_VAR_BOOL;
1076 case CONFIG_ITEM_INTEGER:
1077 i_type = VLC_VAR_INTEGER;
1079 case CONFIG_ITEM_FLOAT:
1080 i_type = VLC_VAR_FLOAT;
1083 i_type = VLC_VAR_STRING;
1091 i_type = VLC_VAR_TYPE & var_Type( p_vlc , psz_var );
1093 if( i_object ) vlc_object_release( p_vlc );
1103 /*****************************************************************************
1104 * VLC_AddTarget: adds a target for playing.
1105 *****************************************************************************
1106 * This function adds psz_target to the current playlist. If a playlist does
1107 * not exist, it will create one.
1108 *****************************************************************************/
1109 int VLC_AddTarget( int i_object, char const *psz_target,
1110 char const **ppsz_options, int i_options,
1111 int i_mode, int i_pos )
1114 playlist_t *p_playlist;
1115 vlc_t *p_vlc = vlc_current_object( i_object );
1122 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
1124 if( p_playlist == NULL )
1126 msg_Dbg( p_vlc, "no playlist present, creating one" );
1127 p_playlist = playlist_Create( p_vlc );
1129 if( p_playlist == NULL )
1131 if( i_object ) vlc_object_release( p_vlc );
1132 return VLC_EGENERIC;
1135 vlc_object_yield( p_playlist );
1138 i_err = playlist_AddExt( p_playlist, psz_target, psz_target,
1139 i_mode, i_pos, -1, ppsz_options, i_options);
1141 vlc_object_release( p_playlist );
1143 if( i_object ) vlc_object_release( p_vlc );
1147 /*****************************************************************************
1149 *****************************************************************************/
1150 int VLC_Play( int i_object )
1152 playlist_t * p_playlist;
1153 vlc_t *p_vlc = vlc_current_object( i_object );
1155 /* Check that the handle is valid */
1161 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1165 if( i_object ) vlc_object_release( p_vlc );
1169 playlist_Play( p_playlist );
1170 vlc_object_release( p_playlist );
1172 if( i_object ) vlc_object_release( p_vlc );
1176 /*****************************************************************************
1177 * VLC_Pause: toggle pause
1178 *****************************************************************************/
1179 int VLC_Pause( int i_object )
1181 playlist_t * p_playlist;
1182 vlc_t *p_vlc = vlc_current_object( i_object );
1184 /* Check that the handle is valid */
1190 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1194 if( i_object ) vlc_object_release( p_vlc );
1198 playlist_Pause( p_playlist );
1199 vlc_object_release( p_playlist );
1201 if( i_object ) vlc_object_release( p_vlc );
1205 /*****************************************************************************
1206 * VLC_Pause: toggle pause
1207 *****************************************************************************/
1208 int VLC_Stop( int i_object )
1210 playlist_t * p_playlist;
1211 vlc_t *p_vlc = vlc_current_object( i_object );
1213 /* Check that the handle is valid */
1219 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1223 if( i_object ) vlc_object_release( p_vlc );
1227 playlist_Stop( p_playlist );
1228 vlc_object_release( p_playlist );
1230 if( i_object ) vlc_object_release( p_vlc );
1234 /*****************************************************************************
1235 * VLC_IsPlaying: Query for Playlist Status
1236 *****************************************************************************/
1237 vlc_bool_t VLC_IsPlaying( int i_object )
1239 playlist_t * p_playlist;
1240 vlc_bool_t b_playing;
1242 vlc_t *p_vlc = vlc_current_object( i_object );
1244 /* Check that the handle is valid */
1250 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1254 if( i_object ) vlc_object_release( p_vlc );
1258 b_playing = playlist_IsPlaying( p_playlist );
1259 vlc_object_release( p_playlist );
1261 if( i_object ) vlc_object_release( p_vlc );
1266 * Get the current position in a input
1268 * Return the current position as a float
1269 * \note For some inputs, this will be unknown.
1271 * \param i_object a vlc object id
1272 * \return a float in the range of 0.0 - 1.0
1274 float VLC_PositionGet( int i_object )
1276 input_thread_t *p_input;
1278 vlc_t *p_vlc = vlc_current_object( i_object );
1280 /* Check that the handle is valid */
1286 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1290 if( i_object ) vlc_object_release( p_vlc );
1294 var_Get( p_input, "position", &val );
1295 vlc_object_release( p_input );
1297 if( i_object ) vlc_object_release( p_vlc );
1302 * Set the current position in a input
1304 * Set the current position in a input and then return
1305 * the current position as a float.
1306 * \note For some inputs, this will be unknown.
1308 * \param i_object a vlc object id
1309 * \param i_position a float in the range of 0.0 - 1.0
1310 * \return a float in the range of 0.0 - 1.0
1312 float VLC_PositionSet( int i_object, float i_position )
1314 input_thread_t *p_input;
1316 vlc_t *p_vlc = vlc_current_object( i_object );
1318 /* Check that the handle is valid */
1324 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1328 if( i_object ) vlc_object_release( p_vlc );
1332 val.f_float = i_position;
1333 var_Set( p_input, "position", val );
1334 var_Get( p_input, "position", &val );
1335 vlc_object_release( p_input );
1337 if( i_object ) vlc_object_release( p_vlc );
1342 * Get the current position in a input
1344 * Return the current position in seconds from the start.
1345 * \note For some inputs, this will be unknown.
1347 * \param i_object a vlc object id
1348 * \return the offset from 0:00 in seconds
1350 int VLC_TimeGet( int i_object )
1352 input_thread_t *p_input;
1354 vlc_t *p_vlc = vlc_current_object( i_object );
1356 /* Check that the handle is valid */
1362 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1366 if( i_object ) vlc_object_release( p_vlc );
1370 var_Get( p_input, "time", &val );
1371 vlc_object_release( p_input );
1373 if( i_object ) vlc_object_release( p_vlc );
1374 return val.i_time / 1000000;
1378 * Seek to a position in the current input
1380 * Seek i_seconds in the current input. If b_relative is set,
1381 * then the seek will be relative to the current position, otherwise
1382 * it will seek to i_seconds from the beginning of the input.
1383 * \note For some inputs, this will be unknown.
1385 * \param i_object a vlc object id
1386 * \param i_seconds seconds from current position or from beginning of input
1387 * \param b_relative seek relative from current position
1388 * \return VLC_SUCCESS on success
1390 int VLC_TimeSet( int i_object, int i_seconds, vlc_bool_t b_relative )
1392 input_thread_t *p_input;
1394 vlc_t *p_vlc = vlc_current_object( i_object );
1396 /* Check that the handle is valid */
1402 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1406 if( i_object ) vlc_object_release( p_vlc );
1412 val.i_time = i_seconds;
1413 val.i_time = val.i_time * 1000000L;
1414 var_Set( p_input, "time-offset", val );
1418 val.i_time = i_seconds;
1419 val.i_time = val.i_time * 1000000L;
1420 var_Set( p_input, "time", val );
1422 vlc_object_release( p_input );
1424 if( i_object ) vlc_object_release( p_vlc );
1429 * Get the total length of a input
1431 * Return the total length in seconds from the current input.
1432 * \note For some inputs, this will be unknown.
1434 * \param i_object a vlc object id
1435 * \return the length in seconds
1437 int VLC_LengthGet( int i_object )
1439 input_thread_t *p_input;
1441 vlc_t *p_vlc = vlc_current_object( i_object );
1443 /* Check that the handle is valid */
1449 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1453 if( i_object ) vlc_object_release( p_vlc );
1457 var_Get( p_input, "length", &val );
1458 vlc_object_release( p_input );
1460 if( i_object ) vlc_object_release( p_vlc );
1461 return val.i_time / 1000000L;
1465 * Play the input faster than realtime
1467 * 2x, 4x, 8x faster than realtime
1468 * \note For some inputs, this will be impossible.
1470 * \param i_object a vlc object id
1471 * \return the current speedrate
1473 float VLC_SpeedFaster( int i_object )
1475 input_thread_t *p_input;
1477 vlc_t *p_vlc = vlc_current_object( i_object );
1479 /* Check that the handle is valid */
1485 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1489 if( i_object ) vlc_object_release( p_vlc );
1493 val.b_bool = VLC_TRUE;
1494 var_Set( p_input, "rate-faster", val );
1495 var_Get( p_input, "rate", &val );
1496 vlc_object_release( p_input );
1498 if( i_object ) vlc_object_release( p_vlc );
1499 return val.f_float / INPUT_RATE_DEFAULT;
1503 * Play the input slower than realtime
1505 * 1/2x, 1/4x, 1/8x slower than realtime
1506 * \note For some inputs, this will be impossible.
1508 * \param i_object a vlc object id
1509 * \return the current speedrate
1511 float VLC_SpeedSlower( int i_object )
1513 input_thread_t *p_input;
1515 vlc_t *p_vlc = vlc_current_object( i_object );
1517 /* Check that the handle is valid */
1523 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
1527 if( i_object ) vlc_object_release( p_vlc );
1531 val.b_bool = VLC_TRUE;
1532 var_Set( p_input, "rate-slower", val );
1533 var_Get( p_input, "rate", &val );
1534 vlc_object_release( p_input );
1536 if( i_object ) vlc_object_release( p_vlc );
1537 return val.f_float / INPUT_RATE_DEFAULT;
1541 * Return the current playlist item
1543 * Returns the index of the playlistitem that is currently selected for play.
1544 * This is valid even if nothing is currently playing.
1546 * \param i_object a vlc object id
1547 * \return the current index
1549 int VLC_PlaylistIndex( int i_object )
1552 playlist_t * p_playlist;
1553 vlc_t *p_vlc = vlc_current_object( i_object );
1555 /* Check that the handle is valid */
1561 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1565 if( i_object ) vlc_object_release( p_vlc );
1569 i_index = p_playlist->i_index;
1570 vlc_object_release( p_playlist );
1572 if( i_object ) vlc_object_release( p_vlc );
1577 * Total amount of items in the playlist
1579 * \param i_object a vlc object id
1580 * \return amount of playlist items
1582 int VLC_PlaylistNumberOfItems( int i_object )
1585 playlist_t * p_playlist;
1586 vlc_t *p_vlc = vlc_current_object( i_object );
1588 /* Check that the handle is valid */
1594 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1598 if( i_object ) vlc_object_release( p_vlc );
1602 i_size = p_playlist->i_size;
1603 vlc_object_release( p_playlist );
1605 if( i_object ) vlc_object_release( p_vlc );
1610 * Next playlist item
1612 * Skip to the next playlistitem and play it.
1614 * \param i_object a vlc object id
1615 * \return VLC_SUCCESS on success
1617 int VLC_PlaylistNext( int i_object )
1619 playlist_t * p_playlist;
1620 vlc_t *p_vlc = vlc_current_object( i_object );
1622 /* Check that the handle is valid */
1628 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1632 if( i_object ) vlc_object_release( p_vlc );
1636 playlist_Next( p_playlist );
1637 vlc_object_release( p_playlist );
1639 if( i_object ) vlc_object_release( p_vlc );
1644 * Previous playlist item
1646 * Skip to the previous playlistitem and play it.
1648 * \param i_object a vlc object id
1649 * \return VLC_SUCCESS on success
1651 int VLC_PlaylistPrev( int i_object )
1653 playlist_t * p_playlist;
1654 vlc_t *p_vlc = vlc_current_object( i_object );
1656 /* Check that the handle is valid */
1662 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1666 if( i_object ) vlc_object_release( p_vlc );
1670 playlist_Prev( p_playlist );
1671 vlc_object_release( p_playlist );
1673 if( i_object ) vlc_object_release( p_vlc );
1678 /*****************************************************************************
1679 * VLC_PlaylistClear: Empty the playlist
1680 *****************************************************************************/
1681 int VLC_PlaylistClear( int i_object )
1684 playlist_t * p_playlist;
1685 vlc_t *p_vlc = vlc_current_object( i_object );
1687 /* Check that the handle is valid */
1693 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
1697 if( i_object ) vlc_object_release( p_vlc );
1701 i_err = playlist_Clear( p_playlist );
1703 vlc_object_release( p_playlist );
1705 if( i_object ) vlc_object_release( p_vlc );
1712 * \param i_object a vlc object id
1713 * \param i_volume something in a range from 0-200
1714 * \return the new volume (range 0-200 %)
1716 int VLC_VolumeSet( int i_object, int i_volume )
1718 audio_volume_t i_vol = 0;
1719 vlc_t *p_vlc = vlc_current_object( i_object );
1721 /* Check that the handle is valid */
1727 if( i_volume >= 0 && i_volume <= 200 )
1729 i_vol = i_volume * AOUT_VOLUME_MAX / 200;
1730 aout_VolumeSet( p_vlc, i_vol );
1733 if( i_object ) vlc_object_release( p_vlc );
1734 return i_vol * 200 / AOUT_VOLUME_MAX;
1738 * Get the current volume
1740 * Retrieve the current volume.
1742 * \param i_object a vlc object id
1743 * \return the current volume (range 0-200 %)
1745 int VLC_VolumeGet( int i_object )
1747 audio_volume_t i_volume;
1748 vlc_t *p_vlc = vlc_current_object( i_object );
1750 /* Check that the handle is valid */
1756 aout_VolumeGet( p_vlc, &i_volume );
1758 if( i_object ) vlc_object_release( p_vlc );
1759 return i_volume*200/AOUT_VOLUME_MAX;
1763 * Mute/Unmute the volume
1765 * \param i_object a vlc object id
1766 * \return VLC_SUCCESS on success
1768 int VLC_VolumeMute( int i_object )
1770 vlc_t *p_vlc = vlc_current_object( i_object );
1772 /* Check that the handle is valid */
1778 aout_VolumeMute( p_vlc, NULL );
1780 if( i_object ) vlc_object_release( p_vlc );
1784 /*****************************************************************************
1785 * VLC_FullScreen: toggle fullscreen mode
1786 *****************************************************************************/
1787 int VLC_FullScreen( int i_object )
1789 vout_thread_t *p_vout;
1790 vlc_t *p_vlc = vlc_current_object( i_object );
1797 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
1801 if( i_object ) vlc_object_release( p_vlc );
1805 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1806 vlc_object_release( p_vout );
1808 if( i_object ) vlc_object_release( p_vlc );
1812 /* following functions are local */
1814 /*****************************************************************************
1815 * SetLanguage: set the interface language.
1816 *****************************************************************************
1817 * We set the LC_MESSAGES locale category for interface messages and buttons,
1818 * as well as the LC_CTYPE category for string sorting and possible wide
1819 * character support.
1820 *****************************************************************************/
1821 static void SetLanguage ( char const *psz_lang )
1823 #if defined( ENABLE_NLS ) \
1824 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1827 #if defined( SYS_DARWIN ) || defined ( WIN32 ) || defined( SYS_BEOS )
1831 if( psz_lang && !*psz_lang )
1833 # if defined( HAVE_LC_MESSAGES )
1834 setlocale( LC_MESSAGES, psz_lang );
1836 setlocale( LC_CTYPE, psz_lang );
1841 /* I need that under Darwin, please check it doesn't disturb
1842 * other platforms. --Meuuh */
1843 setenv( "LANG", psz_lang, 1 );
1845 #elif defined( SYS_BEOS ) || defined( WIN32 )
1846 /* We set LC_ALL manually because it is the only way to set
1847 * the language at runtime under eg. Windows. Beware that this
1848 * makes the environment unconsistent when libvlc is unloaded and
1849 * should probably be moved to a safer place like vlc.c. */
1850 static char psz_lcall[20];
1851 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1852 psz_lcall[19] = '\0';
1853 putenv( psz_lcall );
1856 setlocale( LC_ALL, psz_lang );
1859 /* Specify where to find the locales for current domain */
1860 #if !defined( SYS_DARWIN ) && !defined( WIN32 ) && !defined( SYS_BEOS )
1861 psz_path = LOCALEDIR;
1863 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1867 if( !bindtextdomain( PACKAGE_NAME, psz_path ) )
1869 fprintf( stderr, "warning: no domain %s in directory %s\n",
1870 PACKAGE_NAME, psz_path );
1873 /* Set the default domain */
1874 textdomain( PACKAGE_NAME );
1876 #if defined( ENABLE_UTF8 )
1877 bind_textdomain_codeset( PACKAGE_NAME, "UTF-8" );
1883 /*****************************************************************************
1884 * GetFilenames: parse command line options which are not flags
1885 *****************************************************************************
1886 * Parse command line for input files as well as their associated options.
1887 * An option always follows its associated input and begins with a ":".
1888 *****************************************************************************/
1889 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1891 int i_opt, i_options;
1893 /* We assume that the remaining parameters are filenames
1894 * and their input options */
1895 for( i_opt = i_argc - 1; i_opt >= optind; i_opt-- )
1899 /* Count the input options */
1900 while( *ppsz_argv[ i_opt ] == ':' && i_opt > optind )
1906 /* TODO: write an internal function of this one, to avoid
1907 * unnecessary lookups. */
1908 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1909 (char const **)( i_options ? &ppsz_argv[i_opt + 1] :
1911 PLAYLIST_INSERT, 0 );
1917 /*****************************************************************************
1918 * Help: print program help
1919 *****************************************************************************
1920 * Print a short inline help. Message interface is initialized at this stage.
1921 *****************************************************************************/
1922 static void Help( vlc_t *p_this, char const *psz_help_name )
1928 if( psz_help_name && !strcmp( psz_help_name, "help" ) )
1930 fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
1931 Usage( p_this, "help" );
1932 Usage( p_this, "main" );
1934 else if( psz_help_name && !strcmp( psz_help_name, "longhelp" ) )
1936 fprintf( stdout, VLC_USAGE, p_this->psz_object_name );
1937 Usage( p_this, NULL );
1939 else if( psz_help_name )
1941 Usage( p_this, psz_help_name );
1944 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1949 /*****************************************************************************
1950 * Usage: print module usage
1951 *****************************************************************************
1952 * Print a short inline help. Message interface is initialized at this stage.
1953 *****************************************************************************/
1954 static void Usage( vlc_t *p_this, char const *psz_module_name )
1956 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1957 /* short option ------' | | | | | | |
1958 * option name ------------' | | | | | |
1959 * <bra -------------------------' | | | | |
1960 * option type or "" --------------' | | | |
1961 * ket> -----------------------------' | | |
1962 * padding spaces ---------------------' | |
1963 * comment -------------------------------' |
1964 * comment suffix --------------------------'
1966 * The purpose of having bra and ket is that we might i18n them as well.
1968 #define LINE_START 8
1969 #define PADDING_SPACES 25
1972 module_config_t *p_item;
1973 char psz_spaces_text[PADDING_SPACES+LINE_START+1];
1974 char psz_spaces_longtext[LINE_START+3];
1975 char psz_format[sizeof(FORMAT_STRING)];
1976 char psz_buffer[10000];
1979 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1980 vlc_bool_t b_advanced = config_GetInt( p_this, "advanced" );
1981 vlc_bool_t b_description;
1983 memset( psz_spaces_text, ' ', PADDING_SPACES+LINE_START );
1984 psz_spaces_text[PADDING_SPACES+LINE_START] = '\0';
1985 memset( psz_spaces_longtext, ' ', LINE_START+2 );
1986 psz_spaces_longtext[LINE_START+2] = '\0';
1988 strcpy( psz_format, FORMAT_STRING );
1990 /* List all modules */
1991 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1993 /* Enumerate the config for each module */
1994 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1996 vlc_bool_t b_help_module;
1998 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2000 if( psz_module_name && strcmp( psz_module_name,
2001 p_parser->psz_object_name ) )
2006 /* Ignore modules without config options */
2007 if( !p_parser->i_config_items )
2012 /* Ignore modules with only advanced config options if requested */
2015 for( p_item = p_parser->p_config;
2016 p_item->i_type != CONFIG_HINT_END;
2019 if( (p_item->i_type & CONFIG_ITEM) &&
2020 !p_item->b_advanced ) break;
2022 if( p_item->i_type == CONFIG_HINT_END ) continue;
2025 /* Print name of module */
2026 if( strcmp( "main", p_parser->psz_object_name ) )
2027 fprintf( stdout, "\n %s\n", p_parser->psz_longname );
2029 b_help_module = !strcmp( "help", p_parser->psz_object_name );
2031 /* Print module options */
2032 for( p_item = p_parser->p_config;
2033 p_item->i_type != CONFIG_HINT_END;
2036 char *psz_text, *psz_spaces = psz_spaces_text;
2037 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
2038 char *psz_suf = "", *psz_prefix = NULL;
2041 /* Skip deprecated options */
2042 if( p_item->psz_current )
2046 /* Skip advanced options if requested */
2047 if( p_item->b_advanced && !b_advanced )
2052 switch( p_item->i_type )
2054 case CONFIG_HINT_CATEGORY:
2055 case CONFIG_HINT_USAGE:
2056 if( !strcmp( "main", p_parser->psz_object_name ) )
2057 fprintf( stdout, "\n %s\n", p_item->psz_text );
2060 case CONFIG_ITEM_STRING:
2061 case CONFIG_ITEM_FILE:
2062 case CONFIG_ITEM_DIRECTORY:
2063 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
2064 case CONFIG_ITEM_MODULE_CAT:
2065 case CONFIG_ITEM_MODULE_LIST:
2066 case CONFIG_ITEM_MODULE_LIST_CAT:
2067 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
2069 if( p_item->ppsz_list )
2072 psz_type = psz_buffer;
2074 for( i = 0; p_item->ppsz_list[i]; i++ )
2076 if( i ) strcat( psz_type, "," );
2077 strcat( psz_type, p_item->ppsz_list[i] );
2082 case CONFIG_ITEM_INTEGER:
2083 case CONFIG_ITEM_KEY: /* FIXME: do something a bit more clever */
2084 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
2086 if( p_item->i_list )
2089 psz_type = psz_buffer;
2091 for( i = 0; p_item->ppsz_list_text[i]; i++ )
2093 if( i ) strcat( psz_type, ", " );
2094 sprintf( psz_type + strlen(psz_type), "%i (%s)",
2096 p_item->ppsz_list_text[i] );
2101 case CONFIG_ITEM_FLOAT:
2102 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
2104 case CONFIG_ITEM_BOOL:
2105 psz_bra = ""; psz_type = ""; psz_ket = "";
2106 if( !b_help_module )
2108 psz_suf = p_item->i_value ? _(" (default enabled)") :
2109 _(" (default disabled)");
2119 /* Add short option if any */
2120 if( p_item->i_short )
2122 sprintf( psz_short, "-%c,", p_item->i_short );
2126 strcpy( psz_short, " " );
2129 i = PADDING_SPACES - strlen( p_item->psz_name )
2130 - strlen( psz_bra ) - strlen( psz_type )
2131 - strlen( psz_ket ) - 1;
2133 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2135 psz_prefix = ", --no-";
2136 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
2141 psz_spaces[0] = '\n';
2146 psz_spaces[i] = '\0';
2149 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
2151 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2152 psz_prefix, p_item->psz_name, psz_bra, psz_type,
2153 psz_ket, psz_spaces );
2157 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
2158 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
2161 psz_spaces[i] = ' ';
2163 /* We wrap the rest of the output */
2164 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
2165 b_description = config_GetInt( p_this, "help-verbose" );
2168 psz_text = psz_buffer;
2171 char *psz_parser, *psz_word;
2172 size_t i_end = strlen( psz_text );
2174 /* If the remaining text fits in a line, print it. */
2175 if( i_end <= (size_t)i_width )
2177 fprintf( stdout, "%s\n", psz_text );
2181 /* Otherwise, eat as many words as possible */
2182 psz_parser = psz_text;
2185 psz_word = psz_parser;
2186 psz_parser = strchr( psz_word, ' ' );
2187 /* If no space was found, we reached the end of the text
2188 * block; otherwise, we skip the space we just found. */
2189 psz_parser = psz_parser ? psz_parser + 1
2192 } while( psz_parser - psz_text <= i_width );
2194 /* We cut a word in one of these cases:
2195 * - it's the only word in the line and it's too long.
2196 * - we used less than 80% of the width and the word we are
2197 * going to wrap is longer than 40% of the width, and even
2198 * if the word would have fit in the next line. */
2199 if( psz_word == psz_text
2200 || ( psz_word - psz_text < 80 * i_width / 100
2201 && psz_parser - psz_word > 40 * i_width / 100 ) )
2203 char c = psz_text[i_width];
2204 psz_text[i_width] = '\0';
2205 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2206 psz_text += i_width;
2211 psz_word[-1] = '\0';
2212 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
2213 psz_text = psz_word;
2217 if( b_description && p_item->psz_longtext )
2219 sprintf( psz_buffer, "%s%s", p_item->psz_longtext, psz_suf );
2220 b_description = VLC_FALSE;
2221 psz_spaces = psz_spaces_longtext;
2222 fprintf( stdout, "%s", psz_spaces );
2228 /* Release the module list */
2229 vlc_list_release( p_list );
2232 /*****************************************************************************
2233 * ListModules: list the available modules with their description
2234 *****************************************************************************
2235 * Print a list of all available modules (builtins and plugins) and a short
2236 * description for each one.
2237 *****************************************************************************/
2238 static void ListModules( vlc_t *p_this )
2242 char psz_spaces[22];
2245 memset( psz_spaces, ' ', 22 );
2251 /* List all modules */
2252 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
2254 /* Enumerate each module */
2255 for( i_index = 0; i_index < p_list->i_count; i_index++ )
2259 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
2261 /* Nasty hack, but right now I'm too tired to think about a nice
2263 i = 22 - strlen( p_parser->psz_object_name ) - 1;
2267 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
2268 psz_spaces, p_parser->psz_longname );
2270 psz_spaces[i] = ' ';
2273 vlc_list_release( p_list );
2275 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2280 /*****************************************************************************
2281 * Version: print complete program version
2282 *****************************************************************************
2283 * Print complete program version and build number.
2284 *****************************************************************************/
2285 static void Version( void )
2291 fprintf( stdout, VERSION_MESSAGE "\n" );
2293 _("This program comes with NO WARRANTY, to the extent permitted by "
2294 "law.\nYou may redistribute it under the terms of the GNU General "
2295 "Public License;\nsee the file named COPYING for details.\n"
2296 "Written by the VideoLAN team; see the AUTHORS file.\n") );
2298 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
2303 /*****************************************************************************
2304 * ShowConsole: On Win32, create an output console for debug messages
2305 *****************************************************************************
2306 * This function is useful only on Win32.
2307 *****************************************************************************/
2309 static void ShowConsole( void )
2313 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2316 freopen( "CONOUT$", "w", stdout );
2317 freopen( "CONOUT$", "w", stderr );
2318 freopen( "CONIN$", "r", stdin );
2324 /*****************************************************************************
2325 * PauseConsole: On Win32, wait for a key press before closing the console
2326 *****************************************************************************
2327 * This function is useful only on Win32.
2328 *****************************************************************************/
2330 static void PauseConsole( void )
2334 if( getenv( "PWD" ) && getenv( "PS1" ) ) return; /* cygwin shell */
2335 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
2342 /*****************************************************************************
2343 * ConsoleWidth: Return the console width in characters
2344 *****************************************************************************
2345 * We use the stty shell command to get the console width; if this fails or
2346 * if the width is less than 80, we default to 80.
2347 *****************************************************************************/
2348 static int ConsoleWidth( void )
2353 char buf[20], *psz_parser;
2357 file = popen( "stty size 2>/dev/null", "r" );
2360 i_ret = fread( buf, 1, 20, file );
2364 psz_parser = strchr( buf, ' ' );
2367 i_ret = atoi( psz_parser + 1 );
2382 static int VerboseCallback( vlc_object_t *p_this, const char *psz_variable,
2383 vlc_value_t old_val, vlc_value_t new_val, void *param)
2385 vlc_t *p_vlc = (vlc_t *)p_this;
2387 if( new_val.i_int >= -1 )
2389 p_vlc->p_libvlc->i_verbose = __MIN( new_val.i_int, 2 );
2394 /*****************************************************************************
2395 * InitDeviceValues: initialize device values
2396 *****************************************************************************
2397 * This function inits the dvd, vcd and cd-audio values
2398 *****************************************************************************/
2399 static void InitDeviceValues( vlc_t *p_vlc )
2402 LibHalContext * ctx;
2408 if( ( ctx = hal_initialize( NULL, FALSE ) ) )
2410 if( ( devices = hal_get_all_devices( ctx, &i_devices ) ) )
2412 for( i = 0; i < i_devices; i++ )
2414 if( !hal_device_property_exists( ctx, devices[ i ],
2415 "storage.cdrom.dvd" ) )
2420 b_dvd = hal_device_get_property_bool( ctx, devices[ i ],
2421 "storage.cdrom.dvd" );
2422 block_dev = hal_device_get_property_string( ctx, devices[ i ],
2427 config_PutPsz( p_vlc, "dvd", block_dev );
2430 config_PutPsz( p_vlc, "vcd", block_dev );
2431 config_PutPsz( p_vlc, "cd-audio", block_dev );
2433 hal_free_string( block_dev );
2435 hal_free_string_array( devices );
2438 hal_shutdown( ctx );