1 /*****************************************************************************
2 * libvlc.c: main libvlc source
3 *****************************************************************************
4 * Copyright (C) 1998-2002 VideoLAN
5 * $Id: libvlc.c,v 1.62 2003/02/01 23:39:02 sam 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 );
101 /*****************************************************************************
102 * VLC_Version: return the libvlc version.
103 *****************************************************************************
104 * This function returns full version string (numeric version and codename).
105 *****************************************************************************/
106 char const * VLC_Version( void )
108 return VERSION_MESSAGE;
111 /*****************************************************************************
112 * VLC_Error: strerror() equivalent
113 *****************************************************************************
114 * This function returns full version string (numeric version and codename).
115 *****************************************************************************/
116 char const * VLC_Error( int i_err )
118 return vlc_error( i_err );
121 /*****************************************************************************
122 * VLC_Create: allocate a vlc_t structure, and initialize libvlc if needed.
123 *****************************************************************************
124 * This function allocates a vlc_t structure and returns a negative value
125 * in case of failure. Also, the thread system is initialized.
126 *****************************************************************************/
127 int VLC_Create( void )
130 vlc_t * p_vlc = NULL;
133 /* vlc_threads_init *must* be the first internal call! No other call is
134 * allowed before the thread system has been initialized. */
135 i_ret = vlc_threads_init( &libvlc );
141 /* Now that the thread system is initialized, we don't have much, but
142 * at least we have var_Create */
143 var_Create( &libvlc, "libvlc", VLC_VAR_MUTEX );
144 var_Get( &libvlc, "libvlc", &lockval );
145 vlc_mutex_lock( lockval.p_address );
146 if( !libvlc.b_ready )
150 /* Guess what CPU we have */
151 libvlc.i_cpu = CPUCapabilities();
153 /* Find verbosity from VLC_VERBOSE environment variable */
154 psz_env = getenv( "VLC_VERBOSE" );
155 libvlc.i_verbose = psz_env ? atoi( psz_env ) : -1;
158 libvlc.b_color = isatty( 2 ); /* 2 is for stderr */
160 libvlc.b_color = VLC_FALSE;
163 /* Initialize message queue */
164 msg_Create( &libvlc );
166 /* Announce who we are */
167 msg_Dbg( &libvlc, COPYRIGHT_MESSAGE );
168 msg_Dbg( &libvlc, "libvlc was configured with %s", CONFIGURE_LINE );
170 /* The module bank will be initialized later */
171 libvlc.p_module_bank = NULL;
173 libvlc.b_ready = VLC_TRUE;
175 vlc_mutex_unlock( lockval.p_address );
176 var_Destroy( &libvlc, "libvlc" );
178 /* Allocate a vlc object */
179 p_vlc = vlc_object_create( &libvlc, VLC_OBJECT_VLC );
185 p_vlc->psz_object_name = "root";
187 /* Initialize mutexes */
188 vlc_mutex_init( p_vlc, &p_vlc->config_lock );
190 /* Store our newly allocated structure in the global list */
191 vlc_object_attach( p_vlc, &libvlc );
193 /* Store data for the non-reentrant API */
194 p_static_vlc = p_vlc;
196 return p_vlc->i_object_id;
199 /*****************************************************************************
200 * VLC_Init: initialize a vlc_t structure.
201 *****************************************************************************
202 * This function initializes a previously allocated vlc_t structure:
204 * - gettext initialization
205 * - message queue, module bank and playlist initialization
206 * - configuration and commandline parsing
207 *****************************************************************************/
208 int VLC_Init( int i_object, int i_argc, char *ppsz_argv[] )
210 char p_capabilities[200];
214 vlc_bool_t b_exit = VLC_FALSE;
216 module_t *p_help_module;
217 playlist_t *p_playlist;
220 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
228 * System specific initialization code
230 system_Init( p_vlc, &i_argc, ppsz_argv );
232 /* Get the executable name (similar to the basename command) */
235 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
238 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
244 p_vlc->psz_object_name = "vlc";
248 * Support for gettext
252 /* Translate "C" to the language code: "fr", "en_GB", "nl", "ru"... */
253 msg_Dbg( p_vlc, "translation test: code is \"%s\"", _("C") );
255 /* Initialize the module bank and load the configuration of the
256 * main module. We need to do this at this stage to be able to display
257 * a short help if required by the user. (short help == main module
259 var_Create( &libvlc, "libvlc", VLC_VAR_MUTEX );
260 var_Get( &libvlc, "libvlc", &lockval );
261 vlc_mutex_lock( lockval.p_address );
262 if( libvlc.p_module_bank == NULL )
264 module_InitBank( &libvlc );
265 module_LoadMain( &libvlc );
267 vlc_mutex_unlock( lockval.p_address );
268 var_Destroy( &libvlc, "libvlc" );
270 /* Hack: insert the help module here */
271 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
272 if( p_help_module == NULL )
274 //module_EndBank( p_vlc );
275 if( i_object ) vlc_object_release( p_vlc );
278 p_help_module->psz_object_name = "help";
279 config_Duplicate( p_help_module, p_help_config );
280 vlc_object_attach( p_help_module, libvlc.p_module_bank );
283 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_TRUE ) )
285 vlc_object_detach( p_help_module );
286 config_Free( p_help_module );
287 vlc_object_destroy( p_help_module );
288 //module_EndBank( p_vlc );
289 if( i_object ) vlc_object_release( p_vlc );
293 /* Check for short help option */
294 if( config_GetInt( p_vlc, "help" ) )
296 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
297 p_vlc->psz_object_name );
298 Usage( p_vlc, "main" );
299 Usage( p_vlc, "help" );
302 /* Check for version option */
303 else if( config_GetInt( p_vlc, "version" ) )
309 /* Hack: remove the help module here */
310 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 );
323 * Load the builtins and plugins into the module_bank.
324 * We have to do it before config_Load*() because this also gets the
325 * list of configuration options exported by each module and loads their
328 module_LoadBuiltins( &libvlc );
329 module_LoadPlugins( &libvlc );
330 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
331 libvlc.p_module_bank->i_children );
333 /* Hack: insert the help module here */
334 vlc_object_attach( p_help_module, libvlc.p_module_bank );
337 /* Check for help on modules */
338 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
340 Usage( p_vlc, p_tmp );
344 /* Check for long help option */
345 else if( config_GetInt( p_vlc, "longhelp" ) )
347 Usage( p_vlc, NULL );
350 /* Check for module list option */
351 else if( config_GetInt( p_vlc, "list" ) )
353 ListModules( p_vlc );
357 /* Hack: remove the help module here */
358 vlc_object_detach( p_help_module );
359 config_Free( p_help_module );
360 vlc_object_destroy( p_help_module );
365 //module_EndBank( p_vlc );
366 if( i_object ) vlc_object_release( p_vlc );
371 * Override default configuration with config file settings
373 p_vlc->psz_homedir = config_GetHomeDir();
374 config_LoadConfigFile( p_vlc, NULL );
377 * Override configuration with command line settings
379 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, VLC_FALSE ) )
383 /* Pause the console because it's destroyed when we exit */
384 fprintf( stderr, "The command line options couldn't be loaded, check "
385 "that they are valid.\nPress the RETURN key to continue..." );
388 //module_EndBank( p_vlc );
389 if( i_object ) vlc_object_release( p_vlc );
394 * System specific configuration
396 system_Configure( p_vlc );
399 * Message queue options
401 if( config_GetInt( p_vlc, "quiet" ) )
403 libvlc.i_verbose = -1;
407 int i_tmp = config_GetInt( p_vlc, "verbose" );
410 libvlc.i_verbose = __MIN( i_tmp, 2 );
413 libvlc.b_color = libvlc.b_color || config_GetInt( p_vlc, "color" );
416 * Output messages that may still be in the queue
420 /* p_vlc inititalization. FIXME ? */
421 p_vlc->i_desync = config_GetInt( p_vlc, "desync" ) * (mtime_t)1000;
423 #if defined( __i386__ )
424 if( !config_GetInt( p_vlc, "mmx" ) )
425 libvlc.i_cpu &= ~CPU_CAPABILITY_MMX;
426 if( !config_GetInt( p_vlc, "3dn" ) )
427 libvlc.i_cpu &= ~CPU_CAPABILITY_3DNOW;
428 if( !config_GetInt( p_vlc, "mmxext" ) )
429 libvlc.i_cpu &= ~CPU_CAPABILITY_MMXEXT;
430 if( !config_GetInt( p_vlc, "sse" ) )
431 libvlc.i_cpu &= ~CPU_CAPABILITY_SSE;
433 #if defined( __powerpc__ ) || defined( SYS_DARWIN )
434 if( !config_GetInt( p_vlc, "altivec" ) )
435 libvlc.i_cpu &= ~CPU_CAPABILITY_ALTIVEC;
438 #define PRINT_CAPABILITY( capability, string ) \
439 if( libvlc.i_cpu & capability ) \
441 strncat( p_capabilities, string " ", \
442 sizeof(p_capabilities) - strlen(p_capabilities) ); \
443 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
446 p_capabilities[0] = '\0';
447 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
448 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
449 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
450 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
451 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
452 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
453 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
454 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
455 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
456 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
459 * Choose the best memcpy module
461 p_vlc->p_memcpy_module = module_Need( p_vlc, "memcpy", "$memcpy" );
463 if( p_vlc->pf_memcpy == NULL )
465 p_vlc->pf_memcpy = memcpy;
468 if( p_vlc->pf_memset == NULL )
470 p_vlc->pf_memset = memset;
474 * Initialize shared resources and libraries
476 if( config_GetInt( p_vlc, "network-channel" )
477 && network_ChannelCreate( p_vlc ) )
479 /* On error during Channels initialization, switch off channels */
481 "channels initialization failed, deactivating channels" );
482 config_PutInt( p_vlc, "network-channel", VLC_FALSE );
486 * Initialize playlist and get commandline files
488 p_playlist = playlist_Create( p_vlc );
491 msg_Err( p_vlc, "playlist initialization failed" );
492 if( p_vlc->p_memcpy_module != NULL )
494 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
496 //module_EndBank( p_vlc );
497 if( i_object ) vlc_object_release( p_vlc );
502 * Load background interfaces
504 psz_modules = config_GetPsz( p_vlc, "extraintf" );
505 psz_parser = psz_modules;
506 while ( psz_parser && *psz_parser )
509 psz_module = psz_parser;
510 psz_parser = strchr( psz_module, ',' );
516 VLC_AddIntf( 0, psz_module, VLC_FALSE );
524 * FIXME: kludge to use a p_vlc-local variable for the Mozilla plugin
526 var_Create( p_vlc, "drawable", VLC_VAR_INTEGER );
529 * Get input filenames given as commandline arguments
531 GetFilenames( p_vlc, i_argc, ppsz_argv );
533 if( i_object ) vlc_object_release( p_vlc );
537 /*****************************************************************************
538 * VLC_AddIntf: add an interface
539 *****************************************************************************
540 * This function opens an interface plugin and runs it. If b_block is set
541 * to 0, VLC_AddIntf will return immediately and let the interface run in a
542 * separate thread. If b_block is set to 1, VLC_AddIntf will continue until
543 * user requests to quit.
544 *****************************************************************************/
545 int VLC_AddIntf( int i_object, char const *psz_module, vlc_bool_t b_block )
548 intf_thread_t *p_intf;
550 char *psz_oldmodule = NULL;
552 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
561 psz_oldmodule = config_GetPsz( p_vlc, "intf" );
562 config_PutPsz( p_vlc, "intf", psz_module );
565 /* Try to create the interface */
566 p_intf = intf_Create( p_vlc );
570 config_PutPsz( p_vlc, "intf", psz_oldmodule );
573 free( psz_oldmodule );
579 msg_Err( p_vlc, "interface initialization failed" );
580 if( i_object ) vlc_object_release( p_vlc );
584 /* Try to run the interface */
585 p_intf->b_block = b_block;
586 i_err = intf_RunThread( p_intf );
589 vlc_object_detach( p_intf );
590 intf_Destroy( p_intf );
591 if( i_object ) vlc_object_release( p_vlc );
595 if( i_object ) vlc_object_release( p_vlc );
599 /*****************************************************************************
600 * VLC_Destroy: stop playing and destroy everything.
601 *****************************************************************************
602 * This function requests the running threads to finish, waits for their
603 * termination, and destroys their structure.
604 *****************************************************************************/
605 int VLC_Destroy( int i_object )
609 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
617 * Go back into channel 0 which is the network
619 if( config_GetInt( p_vlc, "network-channel" ) && p_vlc->p_channel )
621 network_ChannelJoin( p_vlc, COMMON_CHANNEL );
625 * Free allocated memory
627 if( p_vlc->p_memcpy_module )
629 module_Unneed( p_vlc, p_vlc->p_memcpy_module );
630 p_vlc->p_memcpy_module = NULL;
633 if( p_vlc->psz_homedir )
635 free( p_vlc->psz_homedir );
636 p_vlc->psz_homedir = NULL;
640 * XXX: Free module bank !
642 //module_EndBank( p_vlc );
645 * System specific cleaning code
649 /* Destroy mutexes */
650 vlc_mutex_destroy( &p_vlc->config_lock );
652 vlc_object_detach( p_vlc );
654 /* Release object before destroying it */
655 if( i_object ) vlc_object_release( p_vlc );
657 vlc_object_destroy( p_vlc );
659 /* Stop thread system: last one out please shut the door! */
660 vlc_threads_end( &libvlc );
665 /*****************************************************************************
666 * VLC_Die: ask vlc to die.
667 *****************************************************************************
668 * This function sets p_vlc->b_die to VLC_TRUE, but does not do any other
669 * task. It is your duty to call vlc_end and VLC_Destroy afterwards.
670 *****************************************************************************/
671 int VLC_Die( int i_object )
675 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
682 p_vlc->b_die = VLC_TRUE;
684 if( i_object ) vlc_object_release( p_vlc );
688 /*****************************************************************************
689 * VLC_AddTarget: adds a target for playing.
690 *****************************************************************************
691 * This function adds psz_target to the current playlist. If a playlist does
692 * not exist, it will create one.
693 *****************************************************************************/
694 int VLC_AddTarget( int i_object, char const *psz_target, int i_mode, int i_pos )
697 playlist_t *p_playlist;
700 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
707 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
709 if( p_playlist == NULL )
711 msg_Dbg( p_vlc, "no playlist present, creating one" );
712 p_playlist = playlist_Create( p_vlc );
714 if( p_playlist == NULL )
716 if( i_object ) vlc_object_release( p_vlc );
720 vlc_object_yield( p_playlist );
723 i_err = playlist_Add( p_playlist, psz_target, i_mode, i_pos );
725 vlc_object_release( p_playlist );
727 if( i_object ) vlc_object_release( p_vlc );
731 /*****************************************************************************
732 * VLC_Set: set a vlc variable
733 *****************************************************************************
735 *****************************************************************************/
736 int VLC_Set( int i_object, char const *psz_var, vlc_value_t value )
741 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
748 /* FIXME: Temporary hack for Mozilla, if variable starts with conf:: then
749 * we handle it as a configuration variable. Don't tell Gildas :) -- sam */
750 if( !strncmp( psz_var, "conf::", 6 ) )
752 module_config_t *p_item;
753 char const *psz_newvar = psz_var + 6;
755 p_item = config_FindConfig( VLC_OBJECT(p_vlc), psz_newvar );
759 switch( p_item->i_type )
761 case CONFIG_ITEM_BOOL:
762 config_PutInt( p_vlc, psz_newvar, value.b_bool );
764 case CONFIG_ITEM_INTEGER:
765 config_PutInt( p_vlc, psz_newvar, value.i_int );
767 case CONFIG_ITEM_FLOAT:
768 config_PutFloat( p_vlc, psz_newvar, value.f_float );
771 config_PutPsz( p_vlc, psz_newvar, value.psz_string );
774 if( i_object ) vlc_object_release( p_vlc );
779 i_ret = var_Set( p_vlc, psz_var, value );
781 if( i_object ) vlc_object_release( p_vlc );
785 /*****************************************************************************
786 * VLC_Get: get a vlc variable
787 *****************************************************************************
789 *****************************************************************************/
790 int VLC_Get( int i_object, char const *psz_var, vlc_value_t *p_value )
795 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
802 i_ret = var_Get( p_vlc, psz_var, p_value );
804 if( i_object ) vlc_object_release( p_vlc );
808 /* FIXME: temporary hacks */
810 /*****************************************************************************
812 *****************************************************************************/
813 int VLC_Play( int i_object )
815 playlist_t * p_playlist;
818 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
820 /* Check that the handle is valid */
826 vlc_thread_set_priority( p_vlc, VLC_THREAD_PRIORITY_LOW );
828 p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST, FIND_CHILD );
832 if( i_object ) vlc_object_release( p_vlc );
836 vlc_mutex_lock( &p_playlist->object_lock );
837 if( p_playlist->i_size )
839 vlc_mutex_unlock( &p_playlist->object_lock );
840 playlist_Play( p_playlist );
844 vlc_mutex_unlock( &p_playlist->object_lock );
847 vlc_object_release( p_playlist );
849 if( i_object ) vlc_object_release( p_vlc );
853 /*****************************************************************************
855 *****************************************************************************/
856 int VLC_Stop( int i_object )
858 intf_thread_t * p_intf;
859 playlist_t * p_playlist;
860 vout_thread_t * p_vout;
861 aout_instance_t * p_aout;
864 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
866 /* Check that the handle is valid */
873 * Ask the interfaces to stop and destroy them
875 msg_Dbg( p_vlc, "removing all interfaces" );
876 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
878 intf_StopThread( p_intf );
879 vlc_object_detach( p_intf );
880 vlc_object_release( p_intf );
881 intf_Destroy( p_intf );
887 msg_Dbg( p_vlc, "removing all playlists" );
888 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
891 vlc_object_detach( p_playlist );
892 vlc_object_release( p_playlist );
893 playlist_Destroy( p_playlist );
899 msg_Dbg( p_vlc, "removing all video outputs" );
900 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
902 vlc_object_detach( p_vout );
903 vlc_object_release( p_vout );
904 vout_Destroy( p_vout );
910 msg_Dbg( p_vlc, "removing all audio outputs" );
911 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
913 vlc_object_detach( (vlc_object_t *)p_aout );
914 vlc_object_release( (vlc_object_t *)p_aout );
915 aout_Delete( p_aout );
918 if( i_object ) vlc_object_release( p_vlc );
922 /*****************************************************************************
923 * VLC_Pause: toggle pause
924 *****************************************************************************/
925 int VLC_Pause( int i_object )
927 input_thread_t *p_input;
930 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
937 p_input = vlc_object_find( p_vlc, VLC_OBJECT_INPUT, FIND_CHILD );
941 if( i_object ) vlc_object_release( p_vlc );
945 input_SetStatus( p_input, INPUT_STATUS_PAUSE );
946 vlc_object_release( p_input );
948 if( i_object ) vlc_object_release( p_vlc );
952 /*****************************************************************************
953 * VLC_FullScreen: toggle fullscreen mode
954 *****************************************************************************/
955 int VLC_FullScreen( int i_object )
957 vout_thread_t *p_vout;
960 p_vlc = i_object ? vlc_object_get( &libvlc, i_object ) : p_static_vlc;
967 p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD );
971 if( i_object ) vlc_object_release( p_vlc );
975 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
976 vlc_object_release( p_vout );
978 if( i_object ) vlc_object_release( p_vlc );
982 /* following functions are local */
984 /*****************************************************************************
985 * SetLanguage: set the interface language.
986 *****************************************************************************
987 * We set the LC_MESSAGES locale category for interface messages and buttons,
988 * as well as the LC_CTYPE category for string sorting and possible wide
990 *****************************************************************************/
991 static void SetLanguage ( char const *psz_lang )
993 #if defined( ENABLE_NLS ) \
994 && ( defined( HAVE_GETTEXT ) || defined( HAVE_INCLUDED_GETTEXT ) )
1001 # if defined( HAVE_INCLUDED_GETTEXT ) && !defined( HAVE_LC_MESSAGES )
1004 /* We set LC_ALL manually because it is the only way to set
1005 * the language at runtime under eg. Windows. Beware that this
1006 * makes the environment unconsistent when libvlc is unloaded and
1007 * should probably be moved to a safer place like vlc.c. */
1008 static char psz_lcall[20];
1009 snprintf( psz_lcall, 19, "LC_ALL=%s", psz_lang );
1010 psz_lcall[19] = '\0';
1011 putenv( psz_lcall );
1015 # if defined( HAVE_LC_MESSAGES )
1016 setlocale( LC_MESSAGES, psz_lang );
1018 setlocale( LC_CTYPE, psz_lang );
1020 /* Specify where to find the locales for current domain */
1022 psz_path = LOCALEDIR;
1024 snprintf( psz_tmp, sizeof(psz_tmp), "%s/%s", libvlc.psz_vlcpath,
1028 if( !bindtextdomain( PACKAGE, psz_path ) )
1030 fprintf( stderr, "warning: no domain %s in directory %s\n",
1031 PACKAGE, psz_path );
1034 /* Set the default domain */
1035 textdomain( PACKAGE );
1039 /*****************************************************************************
1040 * GetFilenames: parse command line options which are not flags
1041 *****************************************************************************
1042 * Parse command line for input files.
1043 *****************************************************************************/
1044 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
1048 /* We assume that the remaining parameters are filenames */
1049 for( i_opt = i_argc - 1; i_opt > optind; i_opt-- )
1051 /* TODO: write an internal function of this one, to avoid
1052 * unnecessary lookups. */
1053 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ i_opt ],
1054 PLAYLIST_INSERT, 0 );
1057 /* If there is at least one target, play it */
1058 if( i_argc > optind )
1060 VLC_AddTarget( p_vlc->i_object_id, ppsz_argv[ optind ],
1061 PLAYLIST_INSERT | PLAYLIST_GO, 0 );
1067 /*****************************************************************************
1068 * Usage: print program usage
1069 *****************************************************************************
1070 * Print a short inline help. Message interface is initialized at this stage.
1071 *****************************************************************************/
1072 static void Usage( vlc_t *p_this, char const *psz_module_name )
1074 #define FORMAT_STRING " --%s%s%s%s%s%s%s %s%s\n"
1075 /* option name -------------' | | | | | |
1076 * <bra --------------------------' | | | | |
1077 * option type or "" ---------------' | | | |
1078 * ket> ------------------------------' | | |
1079 * padding spaces ----------------------' | |
1080 * comment --------------------------------' |
1081 * comment suffix ---------------------------'
1083 * The purpose of having bra and ket is that we might i18n them as well.
1085 #define LINE_START 8
1086 #define PADDING_SPACES 25
1089 module_config_t *p_item;
1090 char psz_spaces[PADDING_SPACES+LINE_START+1];
1091 char psz_format[sizeof(FORMAT_STRING)];
1094 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
1095 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
1097 strcpy( psz_format, FORMAT_STRING );
1103 /* List all modules */
1104 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1106 /* Enumerate the config for each module */
1107 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1109 vlc_bool_t b_help_module;
1111 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1113 if( psz_module_name && strcmp( psz_module_name,
1114 p_parser->psz_object_name ) )
1119 /* Ignore modules without config options */
1120 if( !p_parser->i_config_items )
1125 b_help_module = !strcmp( "help", p_parser->psz_object_name );
1127 /* Print module options */
1128 for( p_item = p_parser->p_config;
1129 p_item->i_type != CONFIG_HINT_END;
1132 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
1133 char *psz_suf = "", *psz_prefix = NULL;
1136 switch( p_item->i_type )
1138 case CONFIG_HINT_CATEGORY:
1139 case CONFIG_HINT_USAGE:
1140 fprintf( stdout, " %s\n", p_item->psz_text );
1143 case CONFIG_ITEM_STRING:
1144 case CONFIG_ITEM_FILE:
1145 case CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1146 if( !p_item->ppsz_list )
1148 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1154 psz_type = malloc( 1000 );
1155 memset( psz_type, 0, 1000 );
1156 for( i=0; p_item->ppsz_list[i]; i++ )
1158 strcat( psz_type, p_item->ppsz_list[i] );
1159 strcat( psz_type, "|" );
1161 psz_type[ strlen( psz_type ) - 1 ] = '\0';
1165 case CONFIG_ITEM_INTEGER:
1166 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1168 case CONFIG_ITEM_FLOAT:
1169 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1171 case CONFIG_ITEM_BOOL:
1172 psz_bra = ""; psz_type = ""; psz_ket = "";
1173 if( !b_help_module )
1175 psz_suf = p_item->i_value ? _(" (default enabled)") :
1176 _(" (default disabled)");
1181 /* Add short option if any */
1182 if( p_item->i_short )
1184 psz_format[2] = '-';
1185 psz_format[3] = p_item->i_short;
1186 psz_format[4] = ',';
1190 psz_format[2] = ' ';
1191 psz_format[3] = ' ';
1192 psz_format[4] = ' ';
1197 i = PADDING_SPACES - strlen( p_item->psz_name )
1198 - strlen( psz_bra ) - strlen( psz_type )
1199 - strlen( psz_ket ) - 1;
1200 if( p_item->i_type == CONFIG_ITEM_BOOL
1203 /* If option is of type --foo-bar, we print its counterpart
1204 * as --no-foo-bar, but if it is of type --foobar (without
1205 * dashes in the name) we print it as --nofoobar. Both
1206 * values are of course valid, only the display changes. */
1207 vlc_bool_t b_dash = VLC_FALSE;
1208 psz_prefix = p_item->psz_name;
1209 while( *psz_prefix )
1211 if( *psz_prefix++ == '-' )
1220 psz_prefix = ", --no-";
1221 i -= strlen( p_item->psz_name ) + strlen( ", --no-" );
1225 psz_prefix = ", --no";
1226 i -= strlen( p_item->psz_name ) + strlen( ", --no" );
1233 psz_spaces[i] = '\n';
1237 psz_spaces[i] = '\0';
1240 if( p_item->i_type == CONFIG_ITEM_BOOL &&
1243 fprintf( stdout, psz_format, p_item->psz_name, psz_prefix,
1244 p_item->psz_name, psz_bra, psz_type, psz_ket,
1245 psz_spaces, p_item->psz_text, psz_suf );
1249 fprintf( stdout, psz_format, p_item->psz_name, "", "",
1250 psz_bra, psz_type, psz_ket, psz_spaces,
1251 p_item->psz_text, psz_suf );
1253 psz_spaces[i] = ' ';
1254 if ( p_item->ppsz_list )
1262 /* Release the module list */
1263 vlc_list_release( p_list );
1265 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1266 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1271 /*****************************************************************************
1272 * ListModules: list the available modules with their description
1273 *****************************************************************************
1274 * Print a list of all available modules (builtins and plugins) and a short
1275 * description for each one.
1276 *****************************************************************************/
1277 static void ListModules( vlc_t *p_this )
1281 char psz_spaces[22];
1284 memset( psz_spaces, ' ', 22 );
1291 fprintf( stdout, _("Usage: %s [options] [items]...\n\n"),
1292 p_this->p_vlc->psz_object_name );
1294 fprintf( stdout, _("[module] [description]\n") );
1296 /* List all modules */
1297 p_list = vlc_list_find( p_this, VLC_OBJECT_MODULE, FIND_ANYWHERE );
1299 /* Enumerate each module */
1300 for( i_index = 0; i_index < p_list->i_count; i_index++ )
1304 p_parser = (module_t *)p_list->p_values[i_index].p_object ;
1306 /* Nasty hack, but right now I'm too tired to think about a nice
1308 i = 22 - strlen( p_parser->psz_object_name ) - 1;
1312 fprintf( stdout, " %s%s %s\n", p_parser->psz_object_name,
1313 psz_spaces, p_parser->psz_longname );
1315 psz_spaces[i] = ' ';
1318 vlc_list_release( p_list );
1320 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1321 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1326 /*****************************************************************************
1327 * Version: print complete program version
1328 *****************************************************************************
1329 * Print complete program version and build number.
1330 *****************************************************************************/
1331 static void Version( void )
1337 fprintf( stdout, VERSION_MESSAGE "\n" );
1339 _("This program comes with NO WARRANTY, to the extent permitted by "
1340 "law.\nYou may redistribute it under the terms of the GNU General "
1341 "Public License;\nsee the file named COPYING for details.\n"
1342 "Written by the VideoLAN team at Ecole Centrale, Paris.\n") );
1344 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1345 fprintf( stdout, _("\nPress the RETURN key to continue...\n") );
1350 /*****************************************************************************
1351 * ShowConsole: On Win32, create an output console for debug messages
1352 *****************************************************************************
1353 * This function is useful only on Win32.
1354 *****************************************************************************/
1356 static void ShowConsole( void )
1360 freopen( "CONOUT$", "w", stdout );
1361 freopen( "CONOUT$", "w", stderr );
1362 freopen( "CONIN$", "r", stdin );