1 /*****************************************************************************
2 * libvlc.c: main libvlc source
3 * Includes the main() function for vlc. Parses command line, starts playlist
5 *****************************************************************************
6 * Copyright (C) 1998-2001 VideoLAN
7 * $Id: libvlc.c,v 1.4 2002/06/01 18:04:49 sam Exp $
9 * Authors: Vincent Seguin <seguin@via.ecp.fr>
10 * Samuel Hocevar <sam@zoy.org>
11 * Gildas Bazin <gbazin@netcourrier.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
26 *****************************************************************************/
28 /*****************************************************************************
29 * Pretend we are a builtin module
30 *****************************************************************************/
31 #define MODULE_NAME main
34 /*****************************************************************************
36 *****************************************************************************/
37 #include <errno.h> /* ENOMEM */
38 #include <stdio.h> /* sprintf() */
39 #include <string.h> /* strerror() */
40 #include <stdlib.h> /* free() */
41 #include <signal.h> /* SIGHUP, SIGINT, SIGKILL */
45 #ifdef HAVE_GETOPT_LONG
47 # include <getopt.h> /* getopt() */
50 # include "GNUgetopt/getopt.h"
54 # include <netinet/in.h> /* BSD: struct in_addr */
59 #elif defined( _MSC_VER ) && defined( _WIN32 )
67 #include "vlc_cpu.h" /* CPU detection */
68 #include "os_specific.h"
70 #include "netutils.h" /* network_ChannelJoin */
72 #include "stream_control.h"
73 #include "input_ext-intf.h"
76 #include "interface.h"
78 #include "audio_output.h"
81 #include "video_output.h"
85 /*****************************************************************************
86 * The evil global variables. We handle them with care, don't worry.
87 *****************************************************************************/
89 /* This global lock is used for critical sections - don't abuse it! */
90 static vlc_mutex_t global_lock;
93 /* A list of all the currently allocated vlc objects */
94 static volatile int i_vlc = 0;
95 static volatile vlc_t **pp_vlc = NULL;
97 /*****************************************************************************
99 *****************************************************************************/
100 static int GetFilenames ( vlc_t *, int, char *[] );
101 static void Usage ( vlc_t *, const char *psz_module_name );
102 static void ListModules ( vlc_t * );
103 static void Version ( void );
104 static void Build ( void );
107 static void InitSignalHandler ( void );
108 static void SimpleSignalHandler ( int i_signal );
109 static void FatalSignalHandler ( int i_signal );
113 static void ShowConsole ( void );
116 /*****************************************************************************
117 * vlc_create: allocate a vlc_t structure, and initialize libvlc if needed.
118 *****************************************************************************
119 * This function allocates a vlc_t structure and returns NULL in case of
120 * failure. Also, the thread system and the signal handlers are initialized.
121 *****************************************************************************/
122 vlc_t * vlc_create( void )
124 vlc_t * p_vlc = NULL;
126 /* Allocate the main structure */
127 p_vlc = vlc_object_create( p_vlc, VLC_OBJECT_ROOT );
133 p_vlc->psz_object_name = "root";
135 p_vlc->p_global_lock = &global_lock;
136 p_vlc->pp_global_data = &p_global_data;
138 p_vlc->b_verbose = 0;
139 p_vlc->b_quiet = 0; /* FIXME: delay message queue output! */
141 /* Initialize the threads system */
142 vlc_threads_init( p_vlc );
144 /* Initialize mutexes */
145 vlc_mutex_init( p_vlc, &p_vlc->config_lock );
146 vlc_mutex_init( p_vlc, &p_vlc->structure_lock );
148 /* Set signal handling policy for all threads */
150 InitSignalHandler( );
153 /* Store our newly allocated structure in the global list */
154 vlc_mutex_lock( p_vlc->p_global_lock );
155 pp_vlc = realloc( pp_vlc, (i_vlc+1) * sizeof( vlc_t * ) );
156 pp_vlc[ i_vlc ] = p_vlc;
158 vlc_mutex_unlock( p_vlc->p_global_lock );
160 /* Update the handle status */
161 p_vlc->i_status = VLC_STATUS_CREATED;
166 /*****************************************************************************
167 * vlc_init: initialize a vlc_t structure.
168 *****************************************************************************
169 * This function initializes a previously allocated vlc_t structure:
171 * - gettext initialization
172 * - message queue, module bank and playlist initialization
173 * - configuration and commandline parsing
174 *****************************************************************************/
175 vlc_error_t vlc_init( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
177 char p_capabilities[200];
180 module_t *p_help_module;
181 playlist_t *p_playlist;
183 /* Check that the handle is valid */
184 if( !p_vlc || p_vlc->i_status != VLC_STATUS_CREATED )
186 fprintf( stderr, "error: invalid status\n" );
190 fprintf( stderr, COPYRIGHT_MESSAGE "\n" );
192 /* Guess what CPU we have */
193 p_vlc->i_cpu_capabilities = CPUCapabilities( p_vlc );
196 * Support for gettext
198 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT )
199 # if defined( HAVE_LOCALE_H ) && defined( HAVE_LC_MESSAGES )
200 if( !setlocale( LC_MESSAGES, "" ) )
202 fprintf( stderr, "warning: unsupported locale settings\n" );
205 setlocale( LC_CTYPE, "" );
208 if( !bindtextdomain( PACKAGE, LOCALEDIR ) )
210 fprintf( stderr, "warning: no domain %s in directory %s\n",
211 PACKAGE, LOCALEDIR );
214 textdomain( PACKAGE );
218 * System specific initialization code
220 system_Init( p_vlc, &i_argc, ppsz_argv );
223 * Initialize message queue
227 /* Get the executable name (similar to the basename command) */
230 p_vlc->psz_object_name = p_tmp = ppsz_argv[ 0 ];
233 if( *p_tmp == '/' ) p_vlc->psz_object_name = ++p_tmp;
239 p_vlc->psz_object_name = "vlc";
243 * Initialize the module bank and and load the configuration of the main
244 * module. We need to do this at this stage to be able to display a short
245 * help if required by the user. (short help == main module options)
247 module_InitBank( p_vlc );
248 module_LoadMain( p_vlc );
250 /* Hack: insert the help module here */
251 p_help_module = vlc_object_create( p_vlc, VLC_OBJECT_MODULE );
252 if( p_help_module == NULL )
254 module_EndBank( p_vlc );
255 msg_Destroy( p_vlc );
258 p_help_module->psz_object_name = "help";
259 config_Duplicate( p_help_module, p_help_config );
260 p_help_module->next = p_vlc->module_bank.first;
261 p_vlc->module_bank.first = p_help_module;
264 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, 1 ) )
266 p_vlc->module_bank.first = p_help_module->next;
267 config_Free( p_help_module );
268 vlc_object_destroy( p_help_module );
269 module_EndBank( p_vlc );
270 msg_Destroy( p_vlc );
274 /* Check for short help option */
275 if( config_GetInt( p_vlc, "help" ) )
277 fprintf( stderr, _("Usage: %s [options] [parameters] [file]...\n"),
278 p_vlc->psz_object_name );
280 Usage( p_vlc, "help" );
281 Usage( p_vlc, "main" );
282 p_vlc->module_bank.first = p_help_module->next;
283 config_Free( p_help_module );
284 vlc_object_destroy( p_help_module );
285 module_EndBank( p_vlc );
286 msg_Destroy( p_vlc );
290 /* Check for version option */
291 if( config_GetInt( p_vlc, "version" ) )
294 p_vlc->module_bank.first = p_help_module->next;
295 config_Free( p_help_module );
296 vlc_object_destroy( p_help_module );
297 module_EndBank( p_vlc );
298 msg_Destroy( p_vlc );
302 /* Check for build option */
303 if( config_GetInt( p_vlc, "build" ) )
306 p_vlc->module_bank.first = p_help_module->next;
307 config_Free( p_help_module );
308 vlc_object_destroy( p_help_module );
309 module_EndBank( p_vlc );
310 msg_Destroy( p_vlc );
314 /* Hack: remove the help module here */
315 p_vlc->module_bank.first = p_help_module->next;
319 * Load the builtins and plugins into the module_bank.
320 * We have to do it before config_Load*() because this also gets the
321 * list of configuration options exported by each module and loads their
324 module_LoadBuiltins( p_vlc );
325 module_LoadPlugins( p_vlc );
326 msg_Dbg( p_vlc, "module bank initialized, found %i modules",
327 p_vlc->module_bank.i_count );
329 /* Hack: insert the help module here */
330 p_help_module->next = p_vlc->module_bank.first;
331 p_vlc->module_bank.first = p_help_module;
334 /* Check for help on modules */
335 if( (p_tmp = config_GetPsz( p_vlc, "module" )) )
337 Usage( p_vlc, p_tmp );
339 p_vlc->module_bank.first = p_help_module->next;
340 config_Free( p_help_module );
341 vlc_object_destroy( p_help_module );
342 module_EndBank( p_vlc );
343 msg_Destroy( p_vlc );
347 /* Check for long help option */
348 if( config_GetInt( p_vlc, "longhelp" ) )
350 Usage( p_vlc, NULL );
351 p_vlc->module_bank.first = p_help_module->next;
352 config_Free( p_help_module );
353 vlc_object_destroy( p_help_module );
354 module_EndBank( p_vlc );
355 msg_Destroy( p_vlc );
359 /* Check for module list option */
360 if( config_GetInt( p_vlc, "list" ) )
362 ListModules( p_vlc );
363 p_vlc->module_bank.first = p_help_module->next;
364 config_Free( p_help_module );
365 vlc_object_destroy( p_help_module );
366 module_EndBank( p_vlc );
367 msg_Destroy( p_vlc );
371 /* Hack: remove the help module here */
372 p_vlc->module_bank.first = p_help_module->next;
373 config_Free( p_help_module );
374 vlc_object_destroy( p_help_module );
378 * Override default configuration with config file settings
380 p_vlc->psz_homedir = config_GetHomeDir();
381 config_LoadConfigFile( p_vlc, NULL );
384 * Override configuration with command line settings
386 if( config_LoadCmdLine( p_vlc, &i_argc, ppsz_argv, 0 ) )
390 /* Pause the console because it's destroyed when we exit */
391 fprintf( stderr, "The command line options couldn't be loaded, check "
392 "that they are valid.\nPress the RETURN key to continue..." );
395 module_EndBank( p_vlc );
396 msg_Destroy( p_vlc );
402 * System specific configuration
404 system_Configure( p_vlc );
406 /* p_vlc inititalization. FIXME ? */
407 p_vlc->i_desync = config_GetInt( p_vlc, "desync" ) * (mtime_t)1000;
408 p_vlc->b_verbose = config_GetInt( p_vlc, "verbose" );
409 p_vlc->b_quiet = config_GetInt( p_vlc, "quiet" );
410 p_vlc->b_color = config_GetInt( p_vlc, "color" );
411 if( !config_GetInt( p_vlc, "mmx" ) )
412 p_vlc->i_cpu_capabilities &= ~CPU_CAPABILITY_MMX;
413 if( !config_GetInt( p_vlc, "3dn" ) )
414 p_vlc->i_cpu_capabilities &= ~CPU_CAPABILITY_3DNOW;
415 if( !config_GetInt( p_vlc, "mmxext" ) )
416 p_vlc->i_cpu_capabilities &= ~CPU_CAPABILITY_MMXEXT;
417 if( !config_GetInt( p_vlc, "sse" ) )
418 p_vlc->i_cpu_capabilities &= ~CPU_CAPABILITY_SSE;
419 if( !config_GetInt( p_vlc, "altivec" ) )
420 p_vlc->i_cpu_capabilities &= ~CPU_CAPABILITY_ALTIVEC;
422 #define PRINT_CAPABILITY( capability, string ) \
423 if( p_vlc->i_cpu_capabilities & capability ) \
425 strncat( p_capabilities, string " ", \
426 sizeof(p_capabilities) - strlen(p_capabilities) ); \
427 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
430 p_capabilities[0] = '\0';
431 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
432 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
433 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
434 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
435 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
436 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
437 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
438 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "AltiVec" );
439 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
440 msg_Dbg( p_vlc, "CPU has capabilities %s", p_capabilities );
443 * Choose the best memcpy module
445 psz_module = config_GetPsz( p_vlc, "memcpy" );
446 p_vlc->p_memcpy_module =
447 module_Need( p_vlc, MODULE_CAPABILITY_MEMCPY, psz_module, NULL );
448 if( psz_module ) free( psz_module );
449 if( p_vlc->p_memcpy_module == NULL )
451 msg_Err( p_vlc, "no suitable memcpy module, using libc default" );
452 p_vlc->pf_memcpy = memcpy;
456 p_vlc->pf_memcpy = p_vlc->p_memcpy_module->p_functions
457 ->memcpy.functions.memcpy.pf_memcpy;
461 * Initialize shared resources and libraries
463 if( config_GetInt( p_vlc, "network-channel" )
464 && network_ChannelCreate( p_vlc ) )
466 /* On error during Channels initialization, switch off channels */
468 "channels initialization failed, deactivating channels" );
469 config_PutInt( p_vlc, "network-channel", 0 );
472 /* Update the handle status */
473 p_vlc->i_status = VLC_STATUS_STOPPED;
475 /* XXX XXX XXX XXX XXX XXX XXX XXX */
476 /* XXX XXX XXX XXX XXX XXX XXX XXX */
477 /* XXX XXX XXX XXX XXX XXX XXX XXX */
479 * Initialize playlist and get commandline files
481 p_playlist = playlist_Create( p_vlc );
484 msg_Err( p_vlc, "playlist initialization failed" );
485 module_EndBank( p_vlc );
486 msg_Destroy( p_vlc );
491 * Get input filenames given as commandline arguments
493 GetFilenames( p_vlc, i_argc, ppsz_argv );
494 /* XXX XXX XXX XXX XXX XXX XXX XXX */
495 /* XXX XXX XXX XXX XXX XXX XXX XXX */
496 /* XXX XXX XXX XXX XXX XXX XXX XXX */
501 /*****************************************************************************
503 *****************************************************************************
504 * XXX: This function opens an interface plugin and runs it. If b_block is set
505 * to 0, vlc_add_intf will return immediately and let the interface run in a
506 * separate thread. If b_block is set to 1, vlc_add_intf will continue until
507 * user requests to quit.
508 *****************************************************************************/
509 vlc_error_t vlc_run( vlc_t *p_vlc )
511 /* Check that the handle is valid */
512 if( !p_vlc || p_vlc->i_status != VLC_STATUS_STOPPED )
514 fprintf( stderr, "error: invalid status\n" );
518 /* Update the handle status */
519 p_vlc->i_status = VLC_STATUS_RUNNING;
524 /*****************************************************************************
525 * vlc_add_intf: add an interface
526 *****************************************************************************
527 * This function opens an interface plugin and runs it. If b_block is set
528 * to 0, vlc_add_intf will return immediately and let the interface run in a
529 * separate thread. If b_block is set to 1, vlc_add_intf will continue until
530 * user requests to quit.
531 *****************************************************************************/
532 vlc_error_t vlc_add_intf( vlc_t *p_vlc, char *psz_module, vlc_bool_t b_block )
535 intf_thread_t *p_intf;
536 char *psz_oldmodule = NULL;
538 /* Check that the handle is valid */
539 if( !p_vlc || p_vlc->i_status != VLC_STATUS_RUNNING )
541 fprintf( stderr, "error: invalid status\n" );
547 psz_oldmodule = config_GetPsz( p_vlc, "intf" );
548 config_PutPsz( p_vlc, "intf", psz_module );
551 /* Try to create the interface */
552 p_intf = intf_Create( p_vlc );
556 config_PutPsz( p_vlc, "intf", psz_oldmodule );
559 free( psz_oldmodule );
565 msg_Err( p_vlc, "interface initialization failed" );
569 /* Try to run the interface */
570 p_intf->b_block = b_block;
571 err = intf_RunThread( p_intf );
574 intf_Destroy( p_intf );
581 /*****************************************************************************
582 * vlc_stop: stop playing.
583 *****************************************************************************
584 * This function requests the interface threads to finish, waits for their
585 * termination, and destroys their structure.
586 *****************************************************************************/
587 vlc_error_t vlc_stop( vlc_t *p_vlc )
589 intf_thread_t *p_intf;
590 playlist_t *p_playlist;
591 vout_thread_t *p_vout;
592 aout_thread_t *p_aout;
594 /* Check that the handle is valid */
595 if( !p_vlc || p_vlc->i_status != VLC_STATUS_RUNNING )
597 fprintf( stderr, "error: invalid status\n" );
602 * Ask the interfaces to stop and destroy them
604 msg_Dbg( p_vlc, "removing all interfaces" );
605 while( (p_intf = vlc_object_find( p_vlc, VLC_OBJECT_INTF, FIND_CHILD )) )
607 intf_StopThread( p_intf );
608 vlc_object_unlink_all( p_intf );
609 vlc_object_release( p_intf );
610 intf_Destroy( p_intf );
616 msg_Dbg( p_vlc, "removing all playlists" );
617 while( (p_playlist = vlc_object_find( p_vlc, VLC_OBJECT_PLAYLIST,
620 vlc_object_unlink_all( p_playlist );
621 vlc_object_release( p_playlist );
622 playlist_Destroy( p_playlist );
628 msg_Dbg( p_vlc, "removing all video outputs" );
629 while( (p_vout = vlc_object_find( p_vlc, VLC_OBJECT_VOUT, FIND_CHILD )) )
631 vlc_object_unlink_all( p_vout );
632 vlc_object_release( p_vout );
633 vout_DestroyThread( p_vout );
639 msg_Dbg( p_vlc, "removing all audio outputs" );
640 while( (p_aout = vlc_object_find( p_vlc, VLC_OBJECT_AOUT, FIND_CHILD )) )
642 vlc_object_unlink_all( p_aout );
643 vlc_object_release( p_aout );
644 aout_DestroyThread( p_aout );
647 /* Update the handle status */
648 p_vlc->i_status = VLC_STATUS_STOPPED;
653 /*****************************************************************************
654 * vlc_end: uninitialize everything.
655 *****************************************************************************
656 * This function uninitializes every vlc component that was activated in
657 * vlc_init: audio and video outputs, playlist, module bank and message queue.
658 *****************************************************************************/
659 vlc_error_t vlc_end( vlc_t *p_vlc )
661 /* Check that the handle is valid */
662 if( !p_vlc || p_vlc->i_status != VLC_STATUS_STOPPED )
664 fprintf( stderr, "error: invalid status\n" );
669 * Go back into channel 0 which is the network
671 if( config_GetInt( p_vlc, "network-channel" ) && p_vlc->p_channel )
673 network_ChannelJoin( p_vlc, COMMON_CHANNEL );
677 * Free allocated memory
679 if( p_vlc->p_memcpy_module != NULL )
681 module_Unneed( p_vlc->p_memcpy_module );
684 free( p_vlc->psz_homedir );
689 module_EndBank( p_vlc );
692 * System specific cleaning code
697 * Terminate messages interface and program
699 msg_Destroy( p_vlc );
701 /* Update the handle status */
702 p_vlc->i_status = VLC_STATUS_CREATED;
707 /*****************************************************************************
708 * vlc_destroy: free allocated resources.
709 *****************************************************************************
710 * This function frees the previously allocated vlc_t structure.
711 *****************************************************************************/
712 vlc_error_t vlc_destroy( vlc_t *p_vlc )
716 /* Check that the handle is valid */
717 if( !p_vlc || p_vlc->i_status != VLC_STATUS_CREATED )
719 fprintf( stderr, "error: invalid status\n" );
723 /* Update the handle status, just in case */
724 p_vlc->i_status = VLC_STATUS_NONE;
726 /* Remove our structure from the global list */
727 vlc_mutex_lock( p_vlc->p_global_lock );
728 for( i_index = 0 ; i_index < i_vlc ; i_index++ )
730 if( pp_vlc[ i_index ] == p_vlc )
736 if( i_index == i_vlc )
738 fprintf( stderr, "error: trying to unregister %p which is not in "
739 "the list\n", p_vlc );
740 vlc_mutex_unlock( p_vlc->p_global_lock );
741 vlc_object_destroy( p_vlc );
745 for( i_index++ ; i_index < i_vlc ; i_index++ )
747 pp_vlc[ i_index - 1 ] = pp_vlc[ i_index ];
753 pp_vlc = realloc( pp_vlc, i_vlc * sizeof( vlc_t * ) );
760 vlc_mutex_unlock( p_vlc->p_global_lock );
762 /* Stop thread system FIXME: last one out please shut the door! */
763 //vlc_threads_end( );
765 /* Destroy mutexes */
766 vlc_mutex_destroy( &p_vlc->structure_lock );
767 vlc_mutex_destroy( &p_vlc->config_lock );
769 vlc_object_destroy( p_vlc );
774 vlc_status_t vlc_status( vlc_t *p_vlc )
778 return VLC_STATUS_NONE;
781 return p_vlc->i_status;
784 vlc_error_t vlc_add_target( vlc_t *p_vlc, char *psz_target )
786 if( !p_vlc || ( p_vlc->i_status != VLC_STATUS_STOPPED
787 && p_vlc->i_status != VLC_STATUS_RUNNING ) )
789 fprintf( stderr, "error: invalid status\n" );
793 playlist_Add( p_vlc, PLAYLIST_END, psz_target );
798 /* following functions are local */
800 /*****************************************************************************
801 * GetFilenames: parse command line options which are not flags
802 *****************************************************************************
803 * Parse command line for input files.
804 *****************************************************************************/
805 static int GetFilenames( vlc_t *p_vlc, int i_argc, char *ppsz_argv[] )
809 /* We assume that the remaining parameters are filenames */
810 for( i_opt = optind; i_opt < i_argc; i_opt++ )
812 playlist_Add( p_vlc, PLAYLIST_END, ppsz_argv[ i_opt ] );
818 /*****************************************************************************
819 * Usage: print program usage
820 *****************************************************************************
821 * Print a short inline help. Message interface is initialized at this stage.
822 *****************************************************************************/
823 static void Usage( vlc_t *p_this, const char *psz_module_name )
825 #define FORMAT_STRING " --%s%s%s%s%s%s %s%s\n"
826 /* option name prefix ------' | | | | | | |
827 * option name ---------------' | | | | | |
828 * <bra ------------------------' | | | | |
829 * option type or "" -------------' | | | |
830 * ket> ----------------------------' | | |
831 * padding spaces --------------------' | |
832 * comment ------------------------------' |
833 * comment suffix -------------------------'
835 * The purpose of having bra and ket is that we might i18n them as well.
838 #define PADDING_SPACES 25
840 module_config_t *p_item;
841 char psz_spaces[PADDING_SPACES+LINE_START+1];
842 char psz_format[sizeof(FORMAT_STRING)];
844 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
845 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
847 strcpy( psz_format, FORMAT_STRING );
853 /* Enumerate the config for each module */
854 for( p_module = p_this->p_vlc->module_bank.first ;
856 p_module = p_module->next )
858 vlc_bool_t b_help_module = !strcmp( "help", p_module->psz_object_name );
860 if( psz_module_name && strcmp( psz_module_name,
861 p_module->psz_object_name ) )
864 /* Ignore modules without config options */
865 if( !p_module->i_config_items ) continue;
867 /* Print module name */
868 fprintf( stderr, _("%s module options:\n\n"),
869 p_module->psz_object_name );
871 for( p_item = p_module->p_config;
872 p_item->i_type != MODULE_CONFIG_HINT_END;
875 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
879 switch( p_item->i_type )
881 case MODULE_CONFIG_HINT_CATEGORY:
882 fprintf( stderr, " %s\n", p_item->psz_text );
885 case MODULE_CONFIG_ITEM_STRING:
886 case MODULE_CONFIG_ITEM_FILE:
887 case MODULE_CONFIG_ITEM_MODULE: /* We could also have "=<" here */
888 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
890 case MODULE_CONFIG_ITEM_INTEGER:
891 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
893 case MODULE_CONFIG_ITEM_FLOAT:
894 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
896 case MODULE_CONFIG_ITEM_BOOL:
897 psz_bra = ""; psz_type = ""; psz_ket = "";
900 psz_suf = p_item->i_value ? _(" (default enabled)") :
901 _(" (default disabled)");
906 /* Add short option */
907 if( p_item->i_short )
910 psz_format[3] = p_item->i_short;
922 i = PADDING_SPACES - strlen( p_item->psz_name )
923 - strlen( psz_bra ) - strlen( psz_type )
924 - strlen( psz_ket ) - 1;
925 if( p_item->i_type == MODULE_CONFIG_ITEM_BOOL
934 psz_spaces[i] = '\n';
938 psz_spaces[i] = '\0';
941 fprintf( stderr, psz_format,
942 ( p_item->i_type == MODULE_CONFIG_ITEM_BOOL
943 && !b_help_module ) ? "(no-)" : "",
944 p_item->psz_name, psz_bra, psz_type, psz_ket,
945 psz_spaces, p_item->psz_text, psz_suf );
950 /* Yet another nasty hack.
951 * Maybe we could use MODULE_CONFIG_ITEM_END to display tail messages
952 * for each module?? */
953 if( !strcmp( "main", p_module->psz_object_name ) )
955 fprintf( stderr, _("\nPlaylist items:"
956 "\n *.mpg, *.vob plain MPEG-1/2 files"
957 "\n [dvd:][device][@raw_device][@[title][,[chapter][,angle]]]"
959 "\n [vcd:][device][@[title][,[chapter]]"
961 "\n udpstream:[@[<bind address>][:<bind port>]]"
962 "\n UDP stream sent by VLS"
963 "\n vlc:loop loop execution of the "
965 "\n vlc:pause pause execution of "
967 "\n vlc:quit quit VLC"
971 fprintf( stderr, "\n" );
975 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
976 fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
981 /*****************************************************************************
982 * ListModules: list the available modules with their description
983 *****************************************************************************
984 * Print a list of all available modules (builtins and plugins) and a short
985 * description for each one.
986 *****************************************************************************/
987 static void ListModules( vlc_t *p_this )
992 memset( psz_spaces, ' ', 22 );
999 fprintf( stderr, _("Usage: %s [options] [parameters] [file]...\n\n"),
1000 p_this->p_vlc->psz_object_name );
1002 fprintf( stderr, _("[module] [description]\n") );
1004 /* Enumerate each module */
1005 for( p_module = p_this->p_vlc->module_bank.first ;
1007 p_module = p_module->next )
1011 /* Nasty hack, but right now I'm too tired to think about a nice
1013 i = 22 - strlen( p_module->psz_object_name ) - 1;
1017 fprintf( stderr, " %s%s %s\n", p_module->psz_object_name, psz_spaces,
1018 p_module->psz_longname );
1020 psz_spaces[i] = ' ';
1024 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1025 fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
1030 /*****************************************************************************
1031 * Version: print complete program version
1032 *****************************************************************************
1033 * Print complete program version and build number.
1034 *****************************************************************************/
1035 static void Version( void )
1041 fprintf( stderr, VERSION_MESSAGE "\n" );
1043 _("This program comes with NO WARRANTY, to the extent permitted by "
1044 "law.\nYou may redistribute it under the terms of the GNU General "
1045 "Public License;\nsee the file named COPYING for details.\n"
1046 "Written by the VideoLAN team at Ecole Centrale, Paris.\n") );
1048 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1049 fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
1054 /*****************************************************************************
1055 * Build: print information about the vlc build
1056 *****************************************************************************
1057 * Print the ./configure command line and other information.
1058 *****************************************************************************/
1059 static void Build( void )
1065 fprintf( stderr, "configured with %s\n", CONFIGURE_LINE );
1067 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1068 fprintf( stderr, _("\nPress the RETURN key to continue...\n") );
1073 /*****************************************************************************
1074 * ShowConsole: On Win32, create an output console for debug messages
1075 *****************************************************************************
1076 * This function is useful only on Win32.
1077 *****************************************************************************/
1079 static void ShowConsole( void )
1082 freopen( "CONOUT$", "w", stdout );
1083 freopen( "CONOUT$", "w", stderr );
1084 freopen( "CONIN$", "r", stdin );
1090 /*****************************************************************************
1091 * InitSignalHandler: system signal handler initialization
1092 *****************************************************************************
1093 * Set the signal handlers. SIGTERM is not intercepted, because we need at
1094 * at least a method to kill the program when all other methods failed, and
1095 * when we don't want to use SIGKILL.
1096 *****************************************************************************/
1097 static void InitSignalHandler( void )
1099 /* Termination signals */
1100 signal( SIGINT, FatalSignalHandler );
1101 signal( SIGHUP, FatalSignalHandler );
1102 signal( SIGQUIT, FatalSignalHandler );
1105 signal( SIGALRM, SimpleSignalHandler );
1106 signal( SIGPIPE, SimpleSignalHandler );
1109 /*****************************************************************************
1110 * SimpleSignalHandler: system signal handler
1111 *****************************************************************************
1112 * This function is called when a non fatal signal is received by the program.
1113 *****************************************************************************/
1114 static void SimpleSignalHandler( int i_signal )
1118 /* Acknowledge the signal received and warn all the p_vlc structures */
1119 vlc_mutex_lock( &global_lock );
1120 for( i_index = 0 ; i_index < i_vlc ; i_index++ )
1122 msg_Warn( pp_vlc[ i_index ], "ignoring signal %d", i_signal );
1124 vlc_mutex_unlock( &global_lock );
1127 /*****************************************************************************
1128 * FatalSignalHandler: system signal handler
1129 *****************************************************************************
1130 * This function is called when a fatal signal is received by the program.
1131 * It tries to end the program in a clean way.
1132 *****************************************************************************/
1133 static void FatalSignalHandler( int i_signal )
1135 static mtime_t abort_time = 0;
1136 static volatile vlc_bool_t b_die = 0;
1139 /* Once a signal has been trapped, the termination sequence will be
1140 * armed and following signals will be ignored to avoid sending messages
1141 * to an interface having been destroyed */
1143 vlc_mutex_lock( &global_lock );
1147 abort_time = mdate();
1149 /* Try to terminate everything - this is done by requesting the end of
1150 * all the p_vlc structures */
1151 for( i_index = 0 ; i_index < i_vlc ; i_index++ )
1153 /* Acknowledge the signal received */
1154 msg_Err( pp_vlc[ i_index ], "signal %d received, exiting - do it "
1155 "again in case vlc gets stuck", i_signal );
1156 pp_vlc[ i_index ]->b_die = 1;
1159 else if( mdate() > abort_time + 1000000 )
1161 /* If user asks again 1 second later, die badly */
1162 signal( SIGINT, SIG_IGN );
1163 signal( SIGHUP, SIG_IGN );
1164 signal( SIGQUIT, SIG_IGN );
1166 for( i_index = 0 ; i_index < i_vlc ; i_index++ )
1168 msg_Err( pp_vlc[ i_index ], "user insisted too much, dying badly" );
1171 vlc_mutex_unlock( &global_lock );
1175 vlc_mutex_unlock( &global_lock );