1 /*****************************************************************************
2 * libvlc.c: main libvlc source
3 *****************************************************************************
4 * Copyright (C) 1998-2002 VideoLAN
5 * $Id: libvlc.c,v 1.65 2003/02/19 10:02:57 gbazin Exp $
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Gildas Bazin <gbazin@netcourrier.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
27 * Pretend we are a builtin module
28 *****************************************************************************/
29 #define MODULE_NAME main
30 #define MODULE_PATH main
33 /*****************************************************************************
35 *****************************************************************************/
39 # 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( _MSC_VER ) && defined( _WIN32 ) && !defined( UNDER_CE )
55 #ifdef WIN32 /* optind, getopt(), included in unistd.h */
56 # include "extras/getopt.h"
63 #include "vlc_cpu.h" /* CPU detection */
64 #include "os_specific.h"
67 #include "netutils.h" /* network_ChannelJoin */
69 #include "stream_control.h"
70 #include "input_ext-intf.h"
72 #include "vlc_playlist.h"
73 #include "interface.h"
75 #include "audio_output.h"
78 #include "video_output.h"
82 /*****************************************************************************
83 * The evil global variable. We handle it with care, don't worry.
84 *****************************************************************************/
85 static libvlc_t libvlc;
86 static vlc_t * p_static_vlc;
88 /*****************************************************************************
90 *****************************************************************************/
91 static void SetLanguage ( char const * );
92 static int GetFilenames ( vlc_t *, int, char *[] );
93 static void Usage ( vlc_t *, char const *psz_module_name );
94 static void ListModules ( vlc_t * );
95 static void Version ( void );
98 static void ShowConsole ( void );
100 static int ConsoleWidth ( void );
102 /*****************************************************************************
103 * VLC_Version: return the libvlc version.
104 *****************************************************************************
105 * This function returns full version string (numeric version and codename).
106 *****************************************************************************/
107 char const * VLC_Version( void )
109 return VERSION_MESSAGE;
112 /*****************************************************************************
113 * VLC_Error: strerror() equivalent
114 *****************************************************************************
115 * This function returns full version string (numeric version and codename).
116 *****************************************************************************/
117 char const * VLC_Error( int i_err )
119 return vlc_error( i_err );
122 /*****************************************************************************
123 * VLC_Create: allocate a vlc_t structure, and initialize libvlc if needed.
124 *****************************************************************************
125 * This function allocates a vlc_t structure and returns a negative value
126 * in case of failure. Also, the thread system is initialized.
127 *****************************************************************************/
128 int VLC_Create( void )
131 vlc_t * p_vlc = NULL;
134 /* vlc_threads_init *must* be the first internal call! No other call is
135 * allowed before the thread system has been initialized. */
136 i_ret = vlc_threads_init( &libvlc );
142 /* Now that the thread system is initialized, we don't have much, but
143 * at least we have var_Create */
144 var_Create( &libvlc, "libvlc", VLC_VAR_MUTEX );
145 var_Get( &libvlc, "libvlc", &lockval );
146 vlc_mutex_lock( lockval.p_address );
147 if( !libvlc.b_ready )
151 /* Guess what CPU we have */
152 libvlc.i_cpu = CPUCapabilities();
154 /* Find verbosity from VLC_VERBOSE environment variable */
155 psz_env = getenv( "VLC_VERBOSE" );
156 libvlc.i_verbose = psz_env ? atoi( psz_env ) : -1;
159 libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
161 libvlc.b_color = VLC_FALSE;
164 /* Initialize message queue */
165 msg_Create( &libvlc );
167 /* Announce who we are */
168 msg_Dbg( &libvlc, COPYRIGHT_MESSAGE );
169 msg_Dbg( &libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
171 /* The module bank will be initialized later */
172 libvlc.p_module_bank = NULL;
174 libvlc.b_ready = VLC_TRUE;
176 vlc_mutex_unlock( lockval.p_address );
177 var_Destroy( &libvlc, "libvlc" );
179 /* Allocate a vlc object */
180 p_vlc = vlc_object_create( &libvlc, VLC_OBJECT_VLC );
186 p_vlc->psz_object_name = "root";
188 /* Initialize mutexes */
189 vlc_mutex_init( p_vlc, &p_vlc->config_lock );
191 /* Store our newly allocated structure in the global list */
192 vlc_object_attach( p_vlc, &libvlc );
194 /* Store data for the non-reentrant API */
195 p_static_vlc = p_vlc;
197 return p_vlc->i_object_id;
200 /*****************************************************************************
201 * VLC_Init: initialize a vlc_t structure.
202 *****************************************************************************
203 * This function initializes a previously allocated vlc_t structure:
205 * - gettext initialization
206 * - message queue, module bank and playlist initialization
207 * - configuration and commandline parsing
208 *****************************************************************************/
209 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
211 char p_capabilities[200];
215 vlc_bool_t b_exit = VLC_FALSE;
217 module_t *p_help_module;
218 playlist_t *p_playlist;
221 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
229 * System specific initialization code
231 system_Init( p_vlc, &i_argc, ppsz_argv );
233 /* Get the executable name (similar to the basename command) */
236 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
239 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
245 p_vlc->psz_object_name = "vlc";
249 * Support for gettext
253 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
254 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
256 /* Initialize the module bank and load the configuration of the
257 * main module. We need to do this at this stage to be able to display
258 * a short help if required by the user. (short help == main module
260 var_Create( &libvlc, "libvlc", VLC_VAR_MUTEX );
261 var_Get( &libvlc, "libvlc", &lockval );
262 vlc_mutex_lock( lockval.p_address );
263 if( libvlc.p_module_bank == NULL )
265 module_InitBank( &libvlc );
266 module_LoadMain( &libvlc );
268 vlc_mutex_unlock( lockval.p_address );
269 var_Destroy( &libvlc, "libvlc" );
271 /* Hack: insert the help module here */
272 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
273 if( p_help_module == NULL )
275 //module_EndBank( p_vlc );
276 if( i_object ) vlc_object_release( p_vlc );
279 p_help_module->psz_object_name = "help";
280 config_Duplicate( p_help_module, p_help_config );
281 vlc_object_attach( p_help_module, libvlc.p_module_bank );
284 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
286 vlc_object_detach( p_help_module );
287 config_Free( p_help_module );
288 vlc_object_destroy( p_help_module );
289 //module_EndBank( p_vlc );
290 if( i_object ) vlc_object_release( p_vlc );
294 /* Check for short help option */
295 if( config_GetInt( p_vlc, "help" ) )
297 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
298 p_vlc->psz_object_name );
299 Usage( p_vlc, "main" );
300 Usage( p_vlc, "help" );
303 /* Check for version option */
304 else if( config_GetInt( p_vlc, "version" ) )
310 /* Hack: remove the help module here */
311 vlc_object_detach( p_help_module );
316 config_Free( p_help_module );
317 vlc_object_destroy( p_help_module );
318 //module_EndBank( p_vlc );
319 if( i_object ) vlc_object_release( p_vlc );
324 * Load the builtins and plugins into the module_bank.
325 * We have to do it before config_Load*() because this also gets the
326 * list of configuration options exported by each module and loads their
329 module_LoadBuiltins( &libvlc );
330 module_LoadPlugins( &libvlc );
331 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
332 libvlc.p_module_bank->i_children );
334 /* Hack: insert the help module here */
335 vlc_object_attach( p_help_module, libvlc.p_module_bank );
338 /* Check for help on modules */
339 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
341 Usage( p_vlc, p_tmp );
345 /* Check for long help option */
346 else if( config_GetInt( p_vlc, "longhelp" ) )
348 Usage( p_vlc, NULL );
351 /* Check for module list option */
352 else if( config_GetInt( p_vlc, "list" ) )
354 ListModules( p_vlc );
358 /* Hack: remove the help module here */
359 vlc_object_detach( p_help_module );
360 config_Free( p_help_module );
361 vlc_object_destroy( p_help_module );
366 //module_EndBank( p_vlc );
367 if( i_object ) vlc_object_release( p_vlc );
372 * Override default configuration with config file settings
374 p_vlc->psz_homedir = config_GetHomeDir();
375 config_LoadConfigFile( p_vlc, NULL );
378 * Override configuration with command line settings
380 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
384 /* Pause the console because it's destroyed when we exit */
385 fprintf( stderr, "The command line options couldn't be loaded, check "
386 "that they are valid.\nPress the RETURN key to continue..." );
389 //module_EndBank( p_vlc );
390 if( i_object ) vlc_object_release( p_vlc );
395 * System specific configuration
397 system_Configure( p_vlc );
400 * Message queue options
402 if( config_GetInt( p_vlc, "quiet" ) )
404 libvlc.i_verbose = -1;
408 int i_tmp = config_GetInt( p_vlc, "verbose" );
411 libvlc.i_verbose = __MIN( i_tmp, 2 );
414 libvlc.b_color = libvlc.b_color || config_GetInt( p_vlc, "color" );
417 * Output messages that may still be in the queue
421 /* p_vlc initialization. FIXME ? */
422 p_vlc->i_desync = config_GetInt( p_vlc, "desync" ) * (mtime_t)1000;
424 #if defined( __i386__ )
425 if( !config_GetInt( p_vlc, "mmx" ) )
426 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
427 if( !config_GetInt( p_vlc, "3dn" ) )
428 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
429 if( !config_GetInt( p_vlc, "mmxext" ) )
430 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
431 if( !config_GetInt( p_vlc, "sse" ) )
432 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
434 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
435 if( !config_GetInt( p_vlc, "altivec" ) )
436 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
439 #define PRINT_CAPABILITY( capability, string ) \
440 if( libvlc.i_cpu & capability ) \
442 strncat( p_capabilities, string " ", \
443 sizeof(p_capabilities) - strlen(p_capabilities) ); \
444 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
447 p_capabilities[0] = '\0';
448 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
449 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
450 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
451 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
452 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
453 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
454 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
455 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
456 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
457 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
460 * Choose the best memcpy module
462 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy" );
464 if( p_vlc->pf_memcpy == NULL )
466 p_vlc->pf_memcpy = memcpy;
469 if( p_vlc->pf_memset == NULL )
471 p_vlc->pf_memset = memset;
475 * Initialize shared resources and libraries
477 if( config_GetInt( p_vlc, "network-channel" )
478 && network_ChannelCreate( p_vlc ) )
480 /* On error during Channels initialization, switch off channels */
482 "channels initialization failed, deactivating channels" );
483 config_PutInt( p_vlc, "network-channel", VLC_FALSE );
487 * Initialize playlist and get commandline files
489 p_playlist = playlist_Create( p_vlc );
492 msg_Err( p_vlc, "playlist initialization failed" );
493 if( p_vlc->p_memcpy_module != NULL )
495 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
497 //module_EndBank( p_vlc );
498 if( i_object ) vlc_object_release( p_vlc );
503 * Load background interfaces
505 psz_modules = config_GetPsz( p_vlc, "extraintf" );
506 psz_parser = psz_modules;
507 while ( psz_parser && *psz_parser )
510 psz_module = psz_parser;
511 psz_parser = strchr( psz_module, ',' );
517 VLC_AddIntf( 0, psz_module, VLC_FALSE );
525 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
527 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
530 * Get input filenames given as commandline arguments
532 GetFilenames( p_vlc, i_argc, ppsz_argv );
534 if( i_object ) vlc_object_release( p_vlc );
538 /*****************************************************************************
539 * VLC_AddIntf: add an interface
540 *****************************************************************************
541 * This function opens an interface plugin and runs it. If b_block is set
542 * to 0, VLC_AddIntf will return immediately and let the interface run in a
543 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
544 * user requests to quit.
545 *****************************************************************************/
546 int VLC_AddIntf( int i_object, char const *psz_module, vlc_bool_t b_block )
549 intf_thread_t *p_intf;
552 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
559 /* Try to create the interface */
560 p_intf = intf_Create( p_vlc, psz_module ? psz_module : "$intf" );
564 msg_Err( p_vlc, "interface initialization failed" );
565 if( i_object ) vlc_object_release( p_vlc );
569 /* Try to run the interface */
570 p_intf->b_block = b_block;
571 i_err = intf_RunThread( p_intf );
574 vlc_object_detach( p_intf );
575 intf_Destroy( p_intf );
576 if( i_object ) vlc_object_release( p_vlc );
580 if( i_object ) vlc_object_release( p_vlc );
584 /*****************************************************************************
585 * VLC_Destroy: stop playing and destroy everything.
586 *****************************************************************************
587 * This function requests the running threads to finish, waits for their
588 * termination, and destroys their structure.
589 *****************************************************************************/
590 int VLC_Destroy( int i_object )
594 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
602 * Go back into channel 0 which is the network
604 if( config_GetInt( p_vlc, "network-channel" ) && p_vlc->p_channel )
606 network_ChannelJoin( p_vlc, COMMON_CHANNEL );
610 * Free allocated memory
612 if( p_vlc->p_memcpy_module )
614 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
615 p_vlc->p_memcpy_module = NULL;
618 if( p_vlc->psz_homedir )
620 free( p_vlc->psz_homedir );
621 p_vlc->psz_homedir = NULL;
625 * XXX: Free module bank !
627 //module_EndBank( p_vlc );
630 * System specific cleaning code
634 /* Destroy mutexes */
635 vlc_mutex_destroy( &p_vlc->config_lock );
637 vlc_object_detach( p_vlc );
639 /* Release object before destroying it */
640 if( i_object ) vlc_object_release( p_vlc );
642 vlc_object_destroy( p_vlc );
644 /* Stop thread system: last one out please shut the door! */
645 vlc_threads_end( &libvlc );
650 /*****************************************************************************
651 * VLC_Die: ask vlc to die.
652 *****************************************************************************
653 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
654 * task. It is your duty to call vlc_end and VLC_Destroy afterwards.
655 *****************************************************************************/
656 int VLC_Die( int i_object )
660 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
667 p_vlc->b_die = VLC_TRUE;
669 if( i_object ) vlc_object_release( p_vlc );
673 /*****************************************************************************
674 * VLC_AddTarget: adds a target for playing.
675 *****************************************************************************
676 * This function adds psz_target to the current playlist. If a playlist does
677 * not exist, it will create one.
678 *****************************************************************************/
679 int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos )
682 playlist_t *p_playlist;
685 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
692 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
694 if( p_playlist == NULL )
696 msg_Dbg( p_vlc, "no playlist present, creating one" );
697 p_playlist = playlist_Create( p_vlc );
699 if( p_playlist == NULL )
701 if( i_object ) vlc_object_release( p_vlc );
705 vlc_object_yield( p_playlist );
708 i_err = playlist_Add( p_playlist, psz_target, i_mode, i_pos );
710 vlc_object_release( p_playlist );
712 if( i_object ) vlc_object_release( p_vlc );
716 /*****************************************************************************
717 * VLC_Set: set a vlc variable
718 *****************************************************************************
720 *****************************************************************************/
721 int VLC_Set( int i_object, char const *psz_var, vlc_value_t value )
726 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
733 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
734 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
735 if( !strncmp( psz_var, "conf::", 6 ) )
737 module_config_t *p_item;
738 char const *psz_newvar = psz_var + 6;
740 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
744 switch( p_item->i_type )
746 case CONFIG_ITEM_BOOL:
747 config_PutInt( p_vlc, psz_newvar, value.b_bool );
749 case CONFIG_ITEM_INTEGER:
750 config_PutInt( p_vlc, psz_newvar, value.i_int );
752 case CONFIG_ITEM_FLOAT:
753 config_PutFloat( p_vlc, psz_newvar, value.f_float );
756 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
759 if( i_object ) vlc_object_release( p_vlc );
764 i_ret = var_Set( p_vlc, psz_var, value );
766 if( i_object ) vlc_object_release( p_vlc );
770 /*****************************************************************************
771 * VLC_Get: get a vlc variable
772 *****************************************************************************
774 *****************************************************************************/
775 int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
780 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
787 i_ret = var_Get( p_vlc, psz_var, p_value );
789 if( i_object ) vlc_object_release( p_vlc );
793 /* FIXME: temporary hacks */
795 /*****************************************************************************
797 *****************************************************************************/
798 int VLC_Play( int i_object )
800 playlist_t * p_playlist;
803 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
805 /* Check that the handle is valid */
811 vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
813 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
817 if( i_object ) vlc_object_release( p_vlc );
821 vlc_mutex_lock( &p_playlist->object_lock );
822 if( p_playlist->i_size )
824 vlc_mutex_unlock( &p_playlist->object_lock );
825 playlist_Play( p_playlist );
829 vlc_mutex_unlock( &p_playlist->object_lock );
832 vlc_object_release( p_playlist );
834 if( i_object ) vlc_object_release( p_vlc );
838 /*****************************************************************************
840 *****************************************************************************/
841 int VLC_Stop( int i_object )
843 intf_thread_t * p_intf;
844 playlist_t * p_playlist;
845 vout_thread_t * p_vout;
846 aout_instance_t * p_aout;
849 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
851 /* Check that the handle is valid */
858 * Ask the interfaces to stop and destroy them
860 msg_Dbg( p_vlc, "removing all interfaces" );
861 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
863 intf_StopThread( p_intf );
864 vlc_object_detach( p_intf );
865 vlc_object_release( p_intf );
866 intf_Destroy( p_intf );
872 msg_Dbg( p_vlc, "removing all playlists" );
873 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
876 vlc_object_detach( p_playlist );
877 vlc_object_release( p_playlist );
878 playlist_Destroy( p_playlist );
884 msg_Dbg( p_vlc, "removing all video outputs" );
885 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
887 vlc_object_detach( p_vout );
888 vlc_object_release( p_vout );
889 vout_Destroy( p_vout );
895 msg_Dbg( p_vlc, "removing all audio outputs" );
896 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
898 vlc_object_detach( (vlc_object_t *)p_aout );
899 vlc_object_release( (vlc_object_t *)p_aout );
900 aout_Delete( p_aout );
903 if( i_object ) vlc_object_release( p_vlc );
907 /*****************************************************************************
908 * VLC_Pause: toggle pause
909 *****************************************************************************/
910 int VLC_Pause( int i_object )
912 input_thread_t *p_input;
915 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
922 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
926 if( i_object ) vlc_object_release( p_vlc );
930 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
931 vlc_object_release( p_input );
933 if( i_object ) vlc_object_release( p_vlc );
937 /*****************************************************************************
938 * VLC_FullScreen: toggle fullscreen mode
939 *****************************************************************************/
940 int VLC_FullScreen( int i_object )
942 vout_thread_t *p_vout;
945 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
952 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
956 if( i_object ) vlc_object_release( p_vlc );
960 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
961 vlc_object_release( p_vout );
963 if( i_object ) vlc_object_release( p_vlc );
967 /* following functions are local */
969 /*****************************************************************************
970 * SetLanguage: set the interface language.
971 *****************************************************************************
972 * We set the LC_MESSAGES locale category for interface messages and buttons,
973 * as well as the LC_CTYPE category for string sorting and possible wide
975 *****************************************************************************/
976 static void SetLanguage ( char const *psz_lang )
978 #if defined( ENABLE_NLS ) \
979 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
986 # if defined( HAVE_INCLUDED_GETTEXT ) && !defined( HAVE_LC_MESSAGES )
989 /* We set LC_ALL manually because it is the only way to set
990 * the language at runtime under eg. Windows. Beware that this
991 * makes the environment unconsistent when libvlc is unloaded and
992 * should probably be moved to a safer place like vlc.c. */
993 static char psz_lcall[20];
994 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
995 psz_lcall[19] = '\0';
1000 # if defined( HAVE_LC_MESSAGES )
1001 setlocale( LC_MESSAGES, psz_lang );
1003 setlocale( LC_CTYPE, psz_lang );
1005 /* Specify where to find the locales for current domain */
1007 psz_path = LOCALEDIR;
1009 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1013 if( !bindtextdomain( PACKAGE, psz_path ) )
1015 fprintf( stderr, "warning: no domain %s in directory %s\n",
1016 PACKAGE, psz_path );
1019 /* Set the default domain */
1020 textdomain( PACKAGE );
1024 /*****************************************************************************
1025 * GetFilenames: parse command line options which are not flags
1026 *****************************************************************************
1027 * Parse command line for input files.
1028 *****************************************************************************/
1029 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1033 /* We assume that the remaining parameters are filenames */
1034 for( i_opt = i_argc - 1; i_opt > optind; i_opt-- )
1036 /* TODO: write an internal function of this one, to avoid
1037 * unnecessary lookups. */
1038 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1039 PLAYLIST_INSERT, 0 );
1042 /* If there is at least one target, play it */
1043 if( i_argc > optind )
1045 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ optind ],
1046 PLAYLIST_INSERT | PLAYLIST_GO, 0 );
1052 /*****************************************************************************
1053 * Usage: print program usage
1054 *****************************************************************************
1055 * Print a short inline help. Message interface is initialized at this stage.
1056 *****************************************************************************/
1057 static void Usage( vlc_t *p_this, char const *psz_module_name )
1059 #define FORMAT_STRING " %s --%s%s%s%s%s%s%s "
1060 /* short option ------' | | | | | | |
1061 * option name ------------' | | | | | |
1062 * <bra -------------------------' | | | | |
1063 * option type or "" --------------' | | | |
1064 * ket> -----------------------------' | | |
1065 * padding spaces ---------------------' | |
1066 * comment -------------------------------' |
1067 * comment suffix --------------------------'
1069 * The purpose of having bra and ket is that we might i18n them as well.
1071 #define LINE_START 8
1072 #define PADDING_SPACES 25
1075 module_config_t *p_item;
1076 char psz_spaces[PADDING_SPACES+LINE_START+1];
1077 char psz_format[sizeof(FORMAT_STRING)];
1078 char psz_buffer[1000];
1081 int i_width = ConsoleWidth() - (PADDING_SPACES+LINE_START+1);
1083 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1084 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1086 strcpy( psz_format, FORMAT_STRING );
1092 /* List all modules */
1093 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1095 /* Enumerate the config for each module */
1096 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1098 vlc_bool_t b_help_module;
1100 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1102 if( psz_module_name && strcmp( psz_module_name,
1103 p_parser->psz_object_name ) )
1108 /* Ignore modules without config options */
1109 if( !p_parser->i_config_items )
1114 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1116 /* Print module options */
1117 for( p_item = p_parser->p_config;
1118 p_item->i_type != CONFIG_HINT_END;
1122 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1123 char *psz_suf = "", *psz_prefix = NULL;
1126 switch( p_item->i_type )
1128 case CONFIG_HINT_CATEGORY:
1129 case CONFIG_HINT_USAGE:
1130 fprintf( stdout, " %s\n", p_item->psz_text );
1133 case CONFIG_ITEM_STRING:
1134 case CONFIG_ITEM_FILE:
1135 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1136 if( !p_item->ppsz_list )
1138 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1144 psz_type = psz_buffer;
1146 for( i = 0; p_item->ppsz_list[i]; i++ )
1148 if( i ) strcat( psz_type, "," );
1149 strcat( psz_type, p_item->ppsz_list[i] );
1154 case CONFIG_ITEM_INTEGER:
1155 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1157 case CONFIG_ITEM_FLOAT:
1158 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1160 case CONFIG_ITEM_BOOL:
1161 psz_bra = ""; psz_type = ""; psz_ket = "";
1162 if( !b_help_module )
1164 psz_suf = p_item->i_value ? _(" (default enabled)") :
1165 _(" (default disabled)");
1175 /* Add short option if any */
1176 if( p_item->i_short )
1178 sprintf( psz_short, "-%c,", p_item->i_short );
1182 strcpy( psz_short, " " );
1185 i = PADDING_SPACES - strlen( p_item->psz_name )
1186 - strlen( psz_bra ) - strlen( psz_type )
1187 - strlen( psz_ket ) - 1;
1189 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1191 /* If option is of type --foo-bar, we print its counterpart
1192 * as --no-foo-bar, but if it is of type --foobar (without
1193 * dashes in the name) we print it as --nofoobar. Both
1194 * values are of course valid, only the display changes. */
1195 psz_prefix = strchr( p_item->psz_name, '-' ) ? ", --no-"
1197 i -= strlen( p_item->psz_name ) + strlen( psz_prefix );
1202 psz_spaces[0] = '\n';
1207 psz_spaces[i] = '\0';
1210 if( p_item->i_type == CONFIG_ITEM_BOOL && !b_help_module )
1212 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1213 psz_prefix, p_item->psz_name, psz_bra, psz_type,
1214 psz_ket, psz_spaces );
1218 fprintf( stdout, psz_format, psz_short, p_item->psz_name,
1219 "", "", psz_bra, psz_type, psz_ket, psz_spaces );
1222 psz_spaces[i] = ' ';
1224 /* We wrap the rest of the output */
1225 sprintf( psz_buffer, "%s%s", p_item->psz_text, psz_suf );
1226 psz_text = psz_buffer;
1229 char *psz_parser, *psz_word;
1230 int i_end = strlen( psz_text );
1232 /* If the remaining text fits in a line, print it. */
1233 if( i_end <= i_width )
1235 fprintf( stdout, "%s\n", psz_text );
1239 /* Otherwise, eat as many words as possible */
1240 psz_parser = psz_text;
1243 psz_word = psz_parser;
1244 psz_parser = strchr( psz_word, ' ' );
1245 /* If no space was found, we reached the end of the text
1246 * block; otherwise, we skip the space we just found. */
1247 psz_parser = psz_parser ? psz_parser + 1
1250 } while( psz_parser - psz_text <= i_width );
1252 /* We cut a word in one of these cases:
1253 * - it's the only word in the line and it's too long.
1254 * - we used less than 80% of the width and the word we are
1255 * going to wrap is longer than 40% of the width, and even
1256 * if the word would have fit in the next line. */
1257 if( psz_word == psz_text
1258 || ( psz_word - psz_text < 80 * i_width / 100
1259 && psz_parser - psz_word > 40 * i_width / 100 ) )
1261 char c = psz_text[i_width];
1262 psz_text[i_width] = '\0';
1263 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
1264 psz_text += i_width;
1269 psz_word[-1] = '\0';
1270 fprintf( stdout, "%s\n%s", psz_text, psz_spaces );
1271 psz_text = psz_word;
1277 /* Release the module list */
1278 vlc_list_release( p_list );
1280 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1281 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1286 /*****************************************************************************
1287 * ListModules: list the available modules with their description
1288 *****************************************************************************
1289 * Print a list of all available modules (builtins and plugins) and a short
1290 * description for each one.
1291 *****************************************************************************/
1292 static void ListModules( vlc_t *p_this )
1296 char psz_spaces[22];
1299 memset( psz_spaces, ' ', 22 );
1306 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
1307 p_this->p_vlc->psz_object_name );
1309 fprintf( stdout, _("[module] [description]\n") );
1311 /* List all modules */
1312 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1314 /* Enumerate each module */
1315 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1319 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1321 /* Nasty hack, but right now I'm too tired to think about a nice
1323 i = 22 - strlen( p_parser->psz_object_name ) - 1;
1327 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
1328 psz_spaces, p_parser->psz_longname );
1330 psz_spaces[i] = ' ';
1333 vlc_list_release( p_list );
1335 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1336 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1341 /*****************************************************************************
1342 * Version: print complete program version
1343 *****************************************************************************
1344 * Print complete program version and build number.
1345 *****************************************************************************/
1346 static void Version( void )
1352 fprintf( stdout, VERSION_MESSAGE "\n" );
1354 _("This program comes with NO WARRANTY, to the extent permitted by "
1355 "law.\nYou may redistribute it under the terms of the GNU General "
1356 "Public License;\nsee the file named COPYING for details.\n"
1357 "Written by the VideoLAN team at Ecole Centrale, Paris.\n") );
1359 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1360 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1365 /*****************************************************************************
1366 * ShowConsole: On Win32, create an output console for debug messages
1367 *****************************************************************************
1368 * This function is useful only on Win32.
1369 *****************************************************************************/
1371 static void ShowConsole( void )
1375 freopen( "CONOUT$", "w", stdout );
1376 freopen( "CONOUT$", "w", stderr );
1377 freopen( "CONIN$", "r", stdin );
1383 /*****************************************************************************
1384 * ConsoleWidth: Return the console width in characters
1385 *****************************************************************************
1386 * We use the stty shell command to get the console width; if this fails or
1387 * if the width is less than 80, we default to 80.
1388 *****************************************************************************/
1389 static int ConsoleWidth( void )
1394 char buf[20], *psz_parser;
1398 file = popen( "stty size 2>/dev/null", "r" );
1401 i_ret = fread( buf, 1, 20, file );
1405 psz_parser = strchr( buf, ' ' );
1408 i_ret = atoi( psz_parser + 1 );