1 /*****************************************************************************
2 * main.c: main vlc source
3 * Includes the main() function for vlc. Parses command line, start interface
5 *****************************************************************************
6 * Copyright (C) 1998-2001 VideoLAN
7 * $Id: main.c,v 1.171 2002/03/26 23:08:40 gbazin 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 /*****************************************************************************
30 *****************************************************************************/
31 #include <signal.h> /* SIGHUP, SIGINT, SIGKILL */
32 #include <stdio.h> /* sprintf() */
33 #include <setjmp.h> /* longjmp, setjmp */
35 #include <videolan/vlc.h>
37 #ifdef HAVE_GETOPT_LONG
39 # include <getopt.h> /* getopt() */
42 # include "GNUgetopt/getopt.h"
46 # include <mach/mach.h> /* Altivec detection */
47 # include <mach/mach_error.h> /* some day the header files||compiler *
48 will define it for us */
49 # include <mach/bootstrap.h>
53 # include <netinet/in.h> /* BSD: struct in_addr */
58 #elif defined( _MSC_VER ) && defined( _WIN32 )
66 #include <errno.h> /* ENOMEM */
67 #include <stdlib.h> /* getenv(), strtol(), */
68 #include <string.h> /* strerror() */
70 #include "netutils.h" /* network_ChannelJoin */
72 #include "stream_control.h"
73 #include "input_ext-intf.h"
75 #include "intf_playlist.h"
76 #include "interface.h"
78 #include "audio_output.h"
81 #include "video_output.h"
85 /*****************************************************************************
86 * Configuration options for the main program. Each plugin will also separatly
87 * define its own configuration options.
88 * Look into configuration.h if you need to know more about the following
91 *****************************************************************************/
93 #define MODULE_NAME main
94 #include "modules_inner.h" /* for configuration stuff */
97 #define INTF_TEXT "interface method"
98 #define INTF_LONGTEXT "This option allows you to select the interface used by"\
99 " vlc.\nNote that the default behaviour is to" \
100 " automatically select the best method available"
102 #define WARNING_TEXT "warning level (or use -v, -vv, etc...)"
103 #define WARNING_LONGTEXT "Increasing the warning level will allow you to see" \
104 " more debug messages and can sometimes help you to" \
105 " troubleshoot a problem"
107 #define STATS_TEXT "output statistics"
108 #define STATS_LONGTEXT "Enabling the stats mode will flood your log console" \
109 " with various statistics messages"
111 #define INTF_PATH_TEXT "interface default search path"
112 #define INTF_PATH_LONGTEXT "This option allows you to set the default path" \
113 " that the interface will open when looking for a" \
116 #define AOUT_TEXT "audio output method"
117 #define AOUT_LONGTEXT "This option allows you to select the audio" \
118 " audio output method used by vlc.\nNote that the" \
119 " default behaviour is to automatically select the best"\
122 #define NOAUDIO_TEXT "disable audio"
123 #define NOAUDIO_LONGTEXT "This will completely disable the audio output. The" \
124 " audio decoding stage shouldn't even be done, so it"\
125 " can allow you to save some processing power"
127 #define MONO_TEXT "mono audio"
128 #define MONO_LONGTEXT "This will force a mono audio output"
130 #define VOLUME_TEXT "audio output volume"
131 #define VOLUME_LONGTEXT "You can set the default audio output volume here," \
132 " in a range from 0 to 1024"
134 #define FORMAT_TEXT "audio output format"
135 #define FORMAT_LONGTEXT "You can force the audio output format here.\n" \
136 "0 -> 16 bits signed native endian (default)\n" \
137 "1 -> 8 bits unsigned\n" \
138 "2 -> 16 bits signed little endian\n" \
139 "3 -> 16 bits signed big endian\n" \
140 "4 -> 8 bits signed\n" \
141 "5 -> 16 bits unsigned little endian\n" \
142 "6 -> 16 bits unsigned big endian\n" \
143 "7 -> mpeg2 audio (unsupported)\n" \
144 "8 -> ac3 pass-through"
146 #define RATE_TEXT "audio output frequency (Hz)"
147 #define RATE_LONGTEXT "You can force the audio output frequency here.\n" \
148 "Common values are 48000, 44100, 32000, 22050," \
149 " 16000, 11025, 8000"
151 #define DESYNC_TEXT "Compensate desynchronization of audio (in ms)"
152 #define DESYNC_LONGTEXT "This option allows you to delay the audio output." \
153 " This can be handy if you notice a lag between the" \
154 " video and the audio"
156 #define VOUT_TEXT "video output method"
157 #define VOUT_LONGTEXT "This option allows you to select the video output" \
158 " method used by vlc.\nNote that the default behaviour" \
159 " is to automatically select the best method available"
161 #define NOVIDEO_TEXT "disable video"
162 #define NOVIDEO_LONGTEXT "This will completely disable the video output. The" \
163 " video decoding stage shouldn't even be done, so" \
164 " it can allow you to save some processing power"
166 #define DISPLAY_TEXT "display identifier"
167 #define DISPLAY_LONGTEXT NULL
169 #define WIDTH_TEXT "video width"
170 #define WIDTH_LONGTEXT "You can enforce the video width here.\nNote" \
171 " that by default vlc will adapt to the video" \
174 #define HEIGHT_TEXT "video height"
175 #define HEIGHT_LONGTEXT "You can enforce the video height here.\nNote" \
176 " that by default vlc will adapt to the video " \
179 #define GRAYSCALE_TEXT "grayscale video output"
180 #define GRAYSCALE_LONGTEXT "Using this option, vlc will not decode the color "\
181 "information from the video (this can also allow " \
182 "you to save some processing power)"
184 #define FULLSCREEN_TEXT "fullscreen video output"
185 #define FULLSCREEN_LONGTEXT "If this option is enabled, vlc will always " \
186 "start a video in fullscreen mode"
188 #define NOOVERLAY_TEXT "disable hardware acceleration for the video output"
189 #define NOOVERLAY_LONGTEXT "By default vlc will try to take advantage of the "\
190 "overlay capabilities of you graphics card.\n"
192 #define SPUMARGIN_TEXT "force SPU position"
193 #define SPUMARGIN_LONGTEXT NULL
195 #define FILTER_TEXT "video filter module"
196 #define FILTER_LONGTEXT NULL
198 #define INPUT_TEXT "input method"
199 #define INPUT_LONGTEXT NULL
201 #define SERVER_PORT_TEXT "server port"
202 #define SERVER_PORT_LONGTEXT NULL
204 #define NETCHANNEL_TEXT "enable network channel mode"
205 #define NETCHANNEL_LONGTEXT NULL
207 #define CHAN_SERV_TEXT "channel server address"
208 #define CHAN_SERV_LONGTEXT NULL
210 #define CHAN_PORT_TEXT "channel server port"
211 #define CHAN_PORT_LONGTEXT NULL
213 #define IFACE_TEXT "network interface"
214 #define IFACE_LONGTEXT NULL
216 #define INPUT_AUDIO_TEXT "choose audio"
217 #define INPUT_AUDIO_LONGTEXT NULL
219 #define INPUT_CHAN_TEXT "choose channel"
220 #define INPUT_CHAN_LONGTEXT NULL
222 #define INPUT_SUBT_TEXT "choose subtitles"
223 #define INPUT_SUBT_LONGTEXT NULL
225 #define DVD_DEV_TEXT "DVD device"
226 #define DVD_DEV_LONGTEXT NULL
228 #define VCD_DEV_TEXT "VCD device"
229 #define VCD_DEV_LONGTEXT NULL
231 #define SAT_FREQ_TEXT "Satellite transponder frequency"
232 #define SAT_FREQ_LONGTEXT NULL
234 #define SAT_POL_TEXT "Satellite transponder polarization"
235 #define SAT_POL_LONGTEXT NULL
237 #define SAT_SRATE_TEXT "Satellite transponder symbol rate"
238 #define SAT_SRATE_LONGTEXT NULL
240 #define IPV6_TEXT "force IPv6"
241 #define IPV6_LONGTEXT NULL
243 #define IPV4_TEXT "force IPv4"
244 #define IPV4_LONGTEXT NULL
246 #define ADEC_MPEG_TEXT "choose MPEG audio decoder"
247 #define ADEC_MPEG_LONGTEXT NULL
249 #define ADEC_AC3_TEXT "choose AC3 audio decoder"
250 #define ADEC_AC3_LONGTEXT NULL
252 #define VDEC_SMP_TEXT "use additional processors"
253 #define VDEC_SMP_LONGTEXT NULL
255 #define VPAR_SYNCHRO_TEXT "force synchro algorithm {I|I+|IP|IP+|IPB}"
256 #define VPAR_SYNCHRO_LONGTEXT NULL
258 #define NOMMX_TEXT "disable CPU's MMX support"
259 #define NOMMX_LONGTEXT NULL
261 #define NO3DN_TEXT "disable CPU's 3D Now! support"
262 #define NO3DN_LONGTEXT NULL
264 #define NOMMXEXT_TEXT "disable CPU's MMX EXT support"
265 #define NOMMXEXT_LONGTEXT NULL
267 #define NOSSE_TEXT "disable CPU's SSE support"
268 #define NOSSE_LONGTEXT NULL
270 #define NOALTIVEC_TEXT "disable CPU's AltiVec support"
271 #define NOALTIVEC_LONGTEXT NULL
273 #define PLAYLIST_LAUNCH_TEXT "launch playlist on startup"
274 #define PLAYLIST_LAUNCH_LONGTEXT NULL
276 #define PLAYLIST_ENQUEUE_TEXT "enqueue playlist as default"
277 #define PLAYLIST_ENQUEUE_LONGTEXT NULL
279 #define PLAYLIST_LOOP_TEXT "loop playlist on end"
280 #define PLAYLIST_LOOP_LONGTEXT NULL
282 #define MEMCPY_TEXT "memory copy method"
283 #define MEMCPY_LONGTEXT NULL
288 ADD_CATEGORY_HINT( text, longtext )
289 ADD_SUBCATEGORY_HINT( text, longtext )
290 ADD_STRING( option_name, value, p_callback, text, longtext )
291 ADD_FILE( option_name, psz_value, p_callback, text, longtext )
292 ADD_PLUGIN( option_name, psz_value, i_capability, p_callback, text, longtext )
293 ADD_INTEGER( option_name, i_value, p_callback, text, longtext )
294 ADD_BOOL( option_name, p_callback, text, longtext )
299 /* Interface options */
300 ADD_CATEGORY_HINT( "Interface", NULL)
301 ADD_PLUGIN ( "intf", MODULE_CAPABILITY_INTF, NULL, NULL, INTF_TEXT, INTF_LONGTEXT )
302 ADD_INTEGER ( "warning", 0, NULL, WARNING_TEXT, WARNING_LONGTEXT )
303 ADD_BOOL ( "stats", NULL, STATS_TEXT, STATS_LONGTEXT )
304 ADD_STRING ( "search_path", NULL, NULL, INTF_PATH_TEXT, INTF_PATH_LONGTEXT )
307 ADD_CATEGORY_HINT( "Audio", NULL)
308 ADD_PLUGIN ( "aout", MODULE_CAPABILITY_AOUT, NULL, NULL, AOUT_TEXT, AOUT_LONGTEXT )
309 ADD_BOOL ( "noaudio", NULL, NOAUDIO_TEXT, NOAUDIO_LONGTEXT )
310 ADD_BOOL ( "mono", NULL, MONO_TEXT, MONO_LONGTEXT )
311 ADD_INTEGER ( "volume", VOLUME_DEFAULT, NULL, VOLUME_TEXT, VOLUME_LONGTEXT )
312 ADD_INTEGER ( "rate", 44100, NULL, RATE_TEXT, RATE_LONGTEXT )
313 ADD_INTEGER ( "desync", 0, NULL, DESYNC_TEXT, DESYNC_LONGTEXT )
314 ADD_INTEGER ( "aout_format", 0, NULL, FORMAT_TEXT,
318 ADD_CATEGORY_HINT( "Video", NULL )
319 ADD_PLUGIN ( "vout", MODULE_CAPABILITY_VOUT, NULL, NULL, VOUT_TEXT, VOUT_LONGTEXT )
320 ADD_BOOL ( "novideo", NULL, NOVIDEO_TEXT, NOVIDEO_LONGTEXT )
321 ADD_INTEGER ( "width", -1, NULL, WIDTH_TEXT, WIDTH_LONGTEXT )
322 ADD_INTEGER ( "height", -1, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT )
323 ADD_BOOL ( "grayscale", NULL, GRAYSCALE_TEXT, GRAYSCALE_LONGTEXT )
324 ADD_BOOL ( "fullscreen", NULL, FULLSCREEN_TEXT, FULLSCREEN_LONGTEXT )
325 ADD_BOOL ( "nooverlay", NULL, NOOVERLAY_TEXT, NOOVERLAY_LONGTEXT )
326 ADD_INTEGER ( "spumargin", -1, NULL, SPUMARGIN_TEXT, SPUMARGIN_LONGTEXT )
327 ADD_PLUGIN ( "filter", MODULE_CAPABILITY_VOUT, NULL, NULL, FILTER_TEXT, FILTER_LONGTEXT )
330 ADD_CATEGORY_HINT( "Input", NULL )
331 ADD_STRING ( "input", NULL, NULL, INPUT_TEXT, INPUT_LONGTEXT )
332 ADD_INTEGER ( "server_port", 1234, NULL, SERVER_PORT_TEXT, SERVER_PORT_LONGTEXT )
333 ADD_BOOL ( "network_channel", NULL, NETCHANNEL_TEXT, NETCHANNEL_LONGTEXT )
334 ADD_STRING ( "channel_server", "localhost", NULL, CHAN_SERV_TEXT, CHAN_SERV_LONGTEXT )
335 ADD_INTEGER ( "channel_port", 6010, NULL, CHAN_PORT_TEXT, CHAN_PORT_LONGTEXT )
336 ADD_STRING ( "iface", "eth0", NULL, IFACE_TEXT, IFACE_LONGTEXT )
338 ADD_INTEGER ( "input_audio", -1, NULL, INPUT_AUDIO_TEXT, INPUT_AUDIO_LONGTEXT )
339 ADD_INTEGER ( "input_channel", -1, NULL, INPUT_CHAN_TEXT, INPUT_CHAN_LONGTEXT )
340 ADD_INTEGER ( "input_subtitle", -1, NULL, INPUT_SUBT_TEXT, INPUT_SUBT_LONGTEXT )
342 ADD_STRING ( "dvd_device", "/dev/dvd", NULL, DVD_DEV_TEXT, DVD_DEV_LONGTEXT )
343 ADD_STRING ( "vcd_device", "/dev/cdrom", NULL, VCD_DEV_TEXT, VCD_DEV_LONGTEXT )
344 #ifdef HAVE_SATELLITE
345 ADD_INTEGER ( "sat_frequency", 12553, NULL, SAT_FREQ_TEXT, SAT_FREQ_LONGTEXT )
346 ADD_INTEGER ( "sat_polarization", 0, NULL, SAT_POL_TEXT, SAT_POL_LONGTEXT )
347 ADD_INTEGER ( "sat_symbol_rate", 27500, NULL, SAT_SRATE_TEXT,
351 ADD_BOOL ( "ipv6", NULL, IPV6_TEXT, IPV6_LONGTEXT )
352 ADD_BOOL ( "ipv4", NULL, IPV4_TEXT, IPV4_LONGTEXT )
354 /* Decoder options */
355 ADD_CATEGORY_HINT( "Decoders", NULL )
356 ADD_PLUGIN ( "mpeg_adec", MODULE_CAPABILITY_DECODER, NULL, NULL, ADEC_MPEG_TEXT, ADEC_MPEG_LONGTEXT )
357 ADD_PLUGIN ( "ac3_adec", MODULE_CAPABILITY_DECODER, NULL, NULL, ADEC_AC3_TEXT, ADEC_AC3_LONGTEXT )
358 ADD_INTEGER ( "vdec_smp", 0, NULL, VDEC_SMP_TEXT, VDEC_SMP_LONGTEXT )
359 ADD_STRING ( "vpar_synchro", NULL, NULL, VPAR_SYNCHRO_TEXT, VPAR_SYNCHRO_LONGTEXT )
362 ADD_CATEGORY_HINT( "CPU", NULL )
363 ADD_BOOL ( "nommx", NULL, NOMMX_TEXT, NOMMX_LONGTEXT )
364 ADD_BOOL ( "no3dn", NULL, NO3DN_TEXT, NO3DN_LONGTEXT )
365 ADD_BOOL ( "nommxext", NULL, NOMMXEXT_TEXT, NOMMXEXT_LONGTEXT )
366 ADD_BOOL ( "nosse", NULL, NOSSE_TEXT, NOSSE_LONGTEXT )
367 ADD_BOOL ( "noaltivec", NULL, NOALTIVEC_TEXT, NOALTIVEC_LONGTEXT )
369 /* Playlist options */
370 ADD_CATEGORY_HINT( "Playlist", NULL )
371 ADD_BOOL ( "playlist_launch", NULL, PLAYLIST_LAUNCH_TEXT, PLAYLIST_LAUNCH_LONGTEXT )
372 ADD_BOOL ( "playlist_enqueue", NULL, PLAYLIST_ENQUEUE_TEXT, PLAYLIST_ENQUEUE_LONGTEXT )
373 ADD_BOOL ( "playlist_loop", NULL, PLAYLIST_LOOP_TEXT, PLAYLIST_LOOP_LONGTEXT )
376 ADD_CATEGORY_HINT( "Miscellaneous", NULL )
377 ADD_PLUGIN ( "memcpy", MODULE_CAPABILITY_MEMCPY, NULL, NULL, MEMCPY_TEXT, MEMCPY_LONGTEXT )
382 SET_DESCRIPTION( "Main program" )
383 ADD_CAPABILITY( MAIN, 100/*whatever*/ )
386 MODULE_ACTIVATE_START
389 MODULE_DEACTIVATE_START
390 MODULE_DEACTIVATE_STOP
392 /* Hack for help options */
393 static module_t help_module;
394 static module_config_t p_help_config[] = {
395 { MODULE_CONFIG_ITEM_BOOL, "help", "print help (or use -h)",
396 NULL, NULL, 0, NULL, NULL, 0 },
397 { MODULE_CONFIG_ITEM_BOOL, "longhelp", "print detailed help (or use -H)",
398 NULL, NULL, 0, NULL, NULL, 0 },
399 { MODULE_CONFIG_ITEM_BOOL, "list", "print a list of available plugins "
400 "(or use -l)", NULL, NULL, 0, NULL, NULL, 0 },
401 { MODULE_CONFIG_ITEM_STRING, "plugin", "print help on plugin (or use -p)",
402 NULL, NULL, 0, NULL, &help_module.config_lock, 0 },
403 { MODULE_CONFIG_ITEM_BOOL, "version", "print version information",
404 NULL, NULL, 0, NULL, NULL, 0 },
405 { MODULE_CONFIG_HINT_END, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 } };
408 /*****************************************************************************
410 *****************************************************************************/
412 /*****************************************************************************
413 * Global variables - these are the only ones, see main.h and modules.h
414 *****************************************************************************/
416 module_bank_t *p_module_bank;
417 input_bank_t *p_input_bank;
418 aout_bank_t *p_aout_bank;
419 vout_bank_t *p_vout_bank;
421 /*****************************************************************************
423 *****************************************************************************/
424 static int GetFilenames ( int i_argc, char *ppsz_argv[] );
425 static void Usage ( const char *psz_module_name );
426 static void ListModules ( void );
427 static void Version ( void );
429 static void InitSignalHandler ( void );
430 static void SimpleSignalHandler ( int i_signal );
431 static void FatalSignalHandler ( int i_signal );
432 static void IllegalSignalHandler ( int i_signal );
433 static u32 CPUCapabilities ( void );
436 static void ShowConsole ( void );
440 static int i_illegal;
441 static char *psz_capability;
443 /*****************************************************************************
444 * main: parse command line, start interface and spawn threads
445 *****************************************************************************
446 * Steps during program execution are:
447 * -configuration parsing and messages interface initialization
448 * -opening of audio output device and some global modules
449 * -execution of interface, which exit on error or on user request
450 * -closing of audio output device and some global modules
451 * On error, the spawned threads are canceled, and the open devices closed.
452 *****************************************************************************/
453 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
455 main_t main_data; /* root of all data - see main.h */
456 module_bank_t module_bank;
457 input_bank_t input_bank;
458 aout_bank_t aout_bank;
459 vout_bank_t vout_bank;
463 p_main = &main_data; /* set up the global variables */
464 p_module_bank = &module_bank;
465 p_input_bank = &input_bank;
466 p_aout_bank = &aout_bank;
467 p_vout_bank = &vout_bank;
469 p_main->i_warning_level = 0;
471 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT )
475 #if defined( HAVE_LOCALE_H ) && defined( HAVE_LC_MESSAGES )
476 if( !setlocale( LC_MESSAGES, "" ) )
478 fprintf( stderr, "warning: unsupported locale.\n" );
482 if( !bindtextdomain( PACKAGE, LOCALEDIR ) )
484 fprintf( stderr, "warning: no domain %s in directory %s\n",
485 PACKAGE, LOCALEDIR );
488 textdomain( PACKAGE );
492 * Initialize threads system
497 * Test if our code is likely to run on this CPU
499 p_main->i_cpu_capabilities = CPUCapabilities();
502 * System specific initialization code
504 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
505 system_Init( &i_argc, ppsz_argv, ppsz_env );
507 #elif defined( SYS_LINUX )
509 /* Activate malloc checking routines to detect heap corruptions. */
510 putenv( "MALLOC_CHECK_=2" );
511 putenv( "GNOME_DISABLE_CRASH_DIALOG=1" );
516 * Initialize messages interface
520 intf_Msg( COPYRIGHT_MESSAGE "\n" );
523 /* Get the executable name (similar to the basename command) */
524 p_main->psz_arg0 = p_tmp = ppsz_argv[ 0 ];
527 if( *p_tmp == '/' ) p_main->psz_arg0 = ++p_tmp;
532 * Initialize the module bank and and load the configuration of the main
533 * module. We need to do this at this stage to be able to display a short
534 * help if required by the user. (short help == main module options)
539 /* Hack: insert the help module here */
540 help_module.psz_name = "help";
541 help_module.i_config_lines = sizeof(p_help_config) /
542 sizeof(module_config_t);
543 help_module.i_config_items = help_module.i_config_lines - 1;
544 vlc_mutex_init( &help_module.config_lock );
545 help_module.p_config = p_help_config;
546 help_module.next = p_module_bank->first;
547 p_module_bank->first = &help_module;
550 if( config_LoadCmdLine( &i_argc, ppsz_argv, 1 ) )
556 /* Check for short help option */
557 if( config_GetIntVariable( "help" ) )
559 intf_Msg( "Usage: %s [options] [parameters] [file]...\n",
567 /* Check for version option */
568 if( config_GetIntVariable( "version" ) )
574 /* Hack: remove the help module here */
575 p_module_bank->first = help_module.next;
579 * Load the builtins and plugins into the module_bank.
580 * We have to do it before config_Load*() because this also gets the
581 * list of configuration options exported by each plugin and loads their
584 module_LoadBuiltins();
585 module_LoadPlugins();
586 intf_WarnMsg( 2, "module: module bank initialized, found %i modules",
587 p_module_bank->i_count );
589 /* Hack: insert the help module here */
590 help_module.next = p_module_bank->first;
591 p_module_bank->first = &help_module;
594 /* Check for help on plugins */
595 if( (p_tmp = config_GetPszVariable( "plugin" )) )
602 /* Check for long help option */
603 if( config_GetIntVariable( "longhelp" ) )
609 /* Check for plugin list option */
610 if( config_GetIntVariable( "list" ) )
616 /* Hack: remove the help module here */
617 p_module_bank->first = help_module.next;
622 * Override default configuration with config file settings
624 vlc_mutex_init( &p_main->config_lock );
625 p_main->psz_homedir = config_GetHomeDir();
626 config_LoadConfigFile( NULL );
629 * Override configuration with command line settings
631 if( config_LoadCmdLine( &i_argc, ppsz_argv, 0 ) )
635 /* Pause the console because it's destroyed when we exit */
636 intf_Msg( "The command line options couldn't be loaded, check that "
637 "they are valid.\nPress the RETURN key to continue..." );
645 /* p_main inititalization. FIXME ? */
646 p_main->i_desync = (mtime_t)config_GetIntVariable( "desync" )
648 p_main->b_stats = config_GetIntVariable( "stats" );
649 p_main->b_audio = !config_GetIntVariable( "noaudio" );
650 p_main->b_stereo= !config_GetIntVariable( "mono" );
651 p_main->b_video = !config_GetIntVariable( "novideo" );
652 if( config_GetIntVariable( "nommx" ) )
653 p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_MMX;
654 if( config_GetIntVariable( "no3dn" ) )
655 p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_3DNOW;
656 if( config_GetIntVariable( "nommxext" ) )
657 p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_MMXEXT;
658 if( config_GetIntVariable( "nosse" ) )
659 p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_SSE;
660 if( config_GetIntVariable( "noaltivec" ) )
661 p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_ALTIVEC;
664 if( p_main->b_stats )
666 char p_capabilities[200];
667 p_capabilities[0] = '\0';
669 #define PRINT_CAPABILITY( capability, string ) \
670 if( p_main->i_cpu_capabilities & capability ) \
672 strncat( p_capabilities, string " ", \
673 sizeof(p_capabilities) - strlen(p_capabilities) ); \
674 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
677 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
678 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
679 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
680 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
681 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
682 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
683 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
684 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "Altivec" );
685 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
686 intf_StatMsg( "info: CPU has capabilities : %s", p_capabilities );
690 * Initialize playlist and get commandline files
692 p_main->p_playlist = intf_PlaylistCreate();
693 if( !p_main->p_playlist )
695 intf_ErrMsg( "playlist error: playlist initialization failed" );
699 intf_PlaylistInit( p_main->p_playlist );
702 * Get input filenames given as commandline arguments
704 GetFilenames( i_argc, ppsz_argv );
707 * Initialize input, aout and vout banks
714 * Choose the best memcpy module
716 psz_plugin = config_GetPszVariable( "memcpy" );
717 p_main->p_memcpy_module = module_Need( MODULE_CAPABILITY_MEMCPY, NULL,
719 if( psz_plugin ) free( psz_plugin );
720 if( p_main->p_memcpy_module == NULL )
722 intf_ErrMsg( "intf error: no suitable memcpy module, "
723 "using libc default" );
724 p_main->pf_memcpy = memcpy;
728 p_main->pf_memcpy = p_main->p_memcpy_module->p_functions
729 ->memcpy.functions.memcpy.pf_memcpy;
733 * Initialize shared resources and libraries
735 if( config_GetIntVariable( "network_channel" ) &&
736 network_ChannelCreate() )
738 /* On error during Channels initialization, switch off channels */
739 intf_ErrMsg( "intf error: channels initialization failed, "
740 "deactivating channels" );
741 config_PutIntVariable( "network_channel", 0 );
745 * Try to run the interface
747 p_main->p_intf = intf_Create();
748 if( p_main->p_intf == NULL )
750 intf_ErrMsg( "intf error: interface initialization failed" );
755 * Set signal handling policy for all threads
760 * This is the main loop
762 p_main->p_intf->pf_run( p_main->p_intf );
765 * Finished, destroy the interface
767 intf_Destroy( p_main->p_intf );
770 * Go back into channel 0 which is the network
772 if( config_GetIntVariable( "network_channel" ) )
774 network_ChannelJoin( COMMON_CHANNEL );
779 * Free input, aout and vout banks
788 intf_PlaylistDestroy( p_main->p_playlist );
791 * Free memcpy module if it was allocated
793 if( p_main->p_memcpy_module != NULL )
795 module_Unneed( p_main->p_memcpy_module );
804 * System specific cleaning code
806 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
812 * Terminate messages interface and program
814 intf_WarnMsg( 1, "intf: program terminated" );
818 * Stop threads system
826 /* following functions are local */
828 /*****************************************************************************
829 * GetFilenames: parse command line options which are not flags
830 *****************************************************************************
831 * Parse command line for input files.
832 *****************************************************************************/
833 static int GetFilenames( int i_argc, char *ppsz_argv[] )
837 /* We assume that the remaining parameters are filenames */
838 for( i_opt = optind; i_opt < i_argc; i_opt++ )
840 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
841 ppsz_argv[ i_opt ] );
847 /*****************************************************************************
848 * Usage: print program usage
849 *****************************************************************************
850 * Print a short inline help. Message interface is initialized at this stage.
851 *****************************************************************************/
852 static void Usage( const char *psz_module_name )
858 memset( psz_spaces, 32, 30 );
864 /* Enumerate the config of each module */
865 for( p_module = p_module_bank->first ;
867 p_module = p_module->next )
870 if( psz_module_name && strcmp( psz_module_name, p_module->psz_name ) )
873 /* ignore plugins without config options */
874 if( !p_module->i_config_items ) continue;
876 /* print module name */
877 intf_Msg( "%s options:\n", p_module->psz_name );
879 for( i = 0; i < p_module->i_config_lines; i++ )
883 switch( p_module->p_config[i].i_type )
885 case MODULE_CONFIG_HINT_CATEGORY:
886 intf_Msg( " %s", p_module->p_config[i].psz_text );
889 case MODULE_CONFIG_ITEM_STRING:
890 case MODULE_CONFIG_ITEM_FILE:
891 case MODULE_CONFIG_ITEM_PLUGIN:
892 /* Nasty hack, but right now I'm too tired to think about
894 j = 25 - strlen( p_module->p_config[i].psz_name )
895 - strlen(" <string>") - 1;
896 if( j < 0 ) j = 0; psz_spaces[j] = 0;
898 intf_Msg( " --%s <string>%s %s",
899 p_module->p_config[i].psz_name, psz_spaces,
900 p_module->p_config[i].psz_text );
903 case MODULE_CONFIG_ITEM_INTEGER:
904 /* Nasty hack, but right now I'm too tired to think about
906 j = 25 - strlen( p_module->p_config[i].psz_name )
907 - strlen(" <integer>") - 1;
908 if( j < 0 ) j = 0; psz_spaces[j] = 0;
910 intf_Msg( " --%s <integer>%s %s",
911 p_module->p_config[i].psz_name, psz_spaces,
912 p_module->p_config[i].psz_text );
915 case MODULE_CONFIG_ITEM_BOOL:
916 /* Nasty hack, but right now I'm too tired to think about
918 j = 25 - strlen( p_module->p_config[i].psz_name ) - 1;
919 if( j < 0 ) j = 0; psz_spaces[j] = 0;
921 intf_Msg( " --%s%s %s",
922 p_module->p_config[i].psz_name, psz_spaces,
923 p_module->p_config[i].psz_text );
929 /* Yet another nasty hack.
930 * Maybe we could use MODULE_CONFIG_ITEM_END to display tail messages
931 * for each module?? */
932 if( !strcmp( "main", p_module->psz_name ) )
933 intf_Msg( "\nPlaylist items:"
934 "\n *.mpg, *.vob \tPlain MPEG-1/2 files"
935 "\n [dvd:][device][@raw_device][@[title][,[chapter][,angle]]]"
937 "\n [vcd:][device][@[title][,[chapter]]"
939 "\n udpstream:[<server>[:<server port>]][@[<bind address>]"
941 "\n \tUDP stream sent by VLS"
942 "\n vlc:loop \tLoop execution of the "
944 "\n vlc:pause \tPause execution of "
946 "\n vlc:quit \tQuit VLC" );
952 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
953 intf_Msg( "\nPress the RETURN key to continue..." );
958 /*****************************************************************************
959 * ListModules: list the available modules with their description
960 *****************************************************************************
961 * Print a list of all available modules (builtins and plugins) and a short
962 * description for each one.
963 *****************************************************************************/
964 static void ListModules( void )
969 memset( psz_spaces, 32, 20 );
976 intf_Msg( "Usage: %s [options] [parameters] [file]...\n",
979 intf_Msg( "[plugin] [description]" );
981 /* Enumerate each module */
982 for( p_module = p_module_bank->first ;
984 p_module = p_module->next )
988 /* Nasty hack, but right now I'm too tired to think about a nice
990 i = 20 - strlen( p_module->psz_name ) - 1;
994 intf_Msg( " %s%s %s", p_module->psz_name, psz_spaces,
995 p_module->psz_longname );
1001 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1002 intf_Msg( "\nPress the RETURN key to continue..." );
1007 /*****************************************************************************
1008 * Version: print complete program version
1009 *****************************************************************************
1010 * Print complete program version and build number.
1011 *****************************************************************************/
1012 static void Version( void )
1018 intf_Msg( VERSION_MESSAGE
1019 "This program comes with NO WARRANTY, to the extent permitted by "
1020 "law.\nYou may redistribute it under the terms of the GNU General "
1021 "Public License;\nsee the file named COPYING for details.\n"
1022 "Written by the VideoLAN team at Ecole Centrale, Paris." );
1024 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1025 intf_Msg( "\nPress the RETURN key to continue..." );
1030 /*****************************************************************************
1031 * InitSignalHandler: system signal handler initialization
1032 *****************************************************************************
1033 * Set the signal handlers. SIGTERM is not intercepted, because we need at
1034 * at least a method to kill the program when all other methods failed, and
1035 * when we don't want to use SIGKILL.
1036 *****************************************************************************/
1037 static void InitSignalHandler( void )
1039 /* Termination signals */
1041 signal( SIGINT, FatalSignalHandler );
1042 signal( SIGHUP, FatalSignalHandler );
1043 signal( SIGQUIT, FatalSignalHandler );
1046 signal( SIGALRM, SimpleSignalHandler );
1047 signal( SIGPIPE, SimpleSignalHandler );
1051 /*****************************************************************************
1052 * SimpleSignalHandler: system signal handler
1053 *****************************************************************************
1054 * This function is called when a non fatal signal is received by the program.
1055 *****************************************************************************/
1056 static void SimpleSignalHandler( int i_signal )
1058 /* Acknowledge the signal received */
1059 intf_WarnMsg( 0, "intf: ignoring signal %d", i_signal );
1062 /*****************************************************************************
1063 * FatalSignalHandler: system signal handler
1064 *****************************************************************************
1065 * This function is called when a fatal signal is received by the program.
1066 * It tries to end the program in a clean way.
1067 *****************************************************************************/
1068 static void FatalSignalHandler( int i_signal )
1070 /* Once a signal has been trapped, the termination sequence will be
1071 * armed and following signals will be ignored to avoid sending messages
1072 * to an interface having been destroyed */
1074 signal( SIGINT, SIG_IGN );
1075 signal( SIGHUP, SIG_IGN );
1076 signal( SIGQUIT, SIG_IGN );
1079 /* Acknowledge the signal received */
1080 intf_ErrMsg( "intf error: signal %d received, exiting", i_signal );
1082 /* Try to terminate everything - this is done by requesting the end of the
1083 * interface thread */
1084 p_main->p_intf->b_die = 1;
1087 /*****************************************************************************
1088 * IllegalSignalHandler: system signal handler
1089 *****************************************************************************
1090 * This function is called when an illegal instruction signal is received by
1091 * the program. We use this function to test OS and CPU capabilities
1092 *****************************************************************************/
1093 static void IllegalSignalHandler( int i_signal )
1095 /* Acknowledge the signal received */
1098 #ifdef HAVE_SIGRELSE
1099 sigrelse( i_signal );
1102 fprintf( stderr, "warning: your CPU has %s instructions, but not your "
1103 "operating system.\n", psz_capability );
1104 fprintf( stderr, " some optimizations will be disabled unless "
1105 "you upgrade your OS\n" );
1107 fprintf( stderr, " (for instance Linux kernel 2.4.x or later)" );
1113 /*****************************************************************************
1114 * CPUCapabilities: list the processors MMX support and other capabilities
1115 *****************************************************************************
1116 * This function is called to list extensions the CPU may have.
1117 *****************************************************************************/
1118 static u32 CPUCapabilities( void )
1120 volatile u32 i_capabilities = CPU_CAPABILITY_NONE;
1122 #if defined( SYS_DARWIN )
1123 struct host_basic_info hi;
1125 host_name_port_t host;
1128 char *psz_name, *psz_subname;
1130 i_capabilities |= CPU_CAPABILITY_FPU;
1132 /* Should 'never' fail? */
1133 host = mach_host_self();
1135 i_size = sizeof( hi ) / sizeof( int );
1136 ret = host_info( host, HOST_BASIC_INFO, ( host_info_t )&hi, &i_size );
1138 if( ret != KERN_SUCCESS )
1140 fprintf( stderr, "error: couldn't get CPU information\n" );
1141 return( i_capabilities );
1144 slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
1145 /* FIXME: need better way to detect newer proccessors.
1146 * could do strncmp(a,b,5), but that's real ugly */
1147 if( !strcmp(psz_name, "ppc7400") || !strcmp(psz_name, "ppc7450") )
1149 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
1152 return( i_capabilities );
1154 #elif defined( __i386__ )
1155 volatile unsigned int i_eax, i_ebx, i_ecx, i_edx;
1156 volatile boolean_t b_amd;
1158 /* Needed for x86 CPU capabilities detection */
1159 # define cpuid( a ) \
1160 asm volatile ( "pushl %%ebx\n\t" \
1162 "movl %%ebx,%1\n\t" \
1171 i_capabilities |= CPU_CAPABILITY_FPU;
1173 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1174 signal( SIGILL, IllegalSignalHandler );
1177 /* test for a 486 CPU */
1178 asm volatile ( "pushl %%ebx\n\t"
1181 "movl %%eax, %%ebx\n\t"
1182 "xorl $0x200000, %%eax\n\t"
1194 if( i_eax == i_ebx )
1196 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1197 signal( SIGILL, NULL );
1199 return( i_capabilities );
1202 i_capabilities |= CPU_CAPABILITY_486;
1204 /* the CPU supports the CPUID instruction - get its level */
1205 cpuid( 0x00000000 );
1209 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1210 signal( SIGILL, NULL );
1212 return( i_capabilities );
1215 /* FIXME: this isn't correct, since some 486s have cpuid */
1216 i_capabilities |= CPU_CAPABILITY_586;
1218 /* borrowed from mpeg2dec */
1219 b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
1220 && ( i_edx == 0x69746e65 );
1222 /* test for the MMX flag */
1223 cpuid( 0x00000001 );
1225 if( ! (i_edx & 0x00800000) )
1227 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1228 signal( SIGILL, NULL );
1230 return( i_capabilities );
1233 i_capabilities |= CPU_CAPABILITY_MMX;
1235 if( i_edx & 0x02000000 )
1237 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1239 # ifdef CAN_COMPILE_SSE
1240 /* We test if OS support the SSE instructions */
1241 psz_capability = "SSE";
1243 if( setjmp( env ) == 0 )
1245 /* Test a SSE instruction */
1246 __asm__ __volatile__ ( "xorps %%xmm0,%%xmm0\n" : : );
1249 if( i_illegal == 0 )
1251 i_capabilities |= CPU_CAPABILITY_SSE;
1256 /* test for additional capabilities */
1257 cpuid( 0x80000000 );
1259 if( i_eax < 0x80000001 )
1261 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1262 signal( SIGILL, NULL );
1264 return( i_capabilities );
1267 /* list these additional capabilities */
1268 cpuid( 0x80000001 );
1270 # ifdef CAN_COMPILE_3DNOW
1271 if( i_edx & 0x80000000 )
1273 psz_capability = "3D Now!";
1275 if( setjmp( env ) == 0 )
1277 /* Test a 3D Now! instruction */
1278 __asm__ __volatile__ ( "pfadd %%mm0,%%mm0\n" "femms\n" : : );
1281 if( i_illegal == 0 )
1283 i_capabilities |= CPU_CAPABILITY_3DNOW;
1288 if( b_amd && ( i_edx & 0x00400000 ) )
1290 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1293 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1294 signal( SIGILL, NULL );
1296 return( i_capabilities );
1298 #elif defined( __powerpc__ )
1300 i_capabilities |= CPU_CAPABILITY_FPU;
1302 # ifdef CAN_COMPILE_ALTIVEC
1303 signal( SIGILL, IllegalSignalHandler );
1305 psz_capability = "AltiVec";
1307 if( setjmp( env ) == 0 )
1309 asm volatile ("mtspr 256, %0\n\t"
1310 "vand %%v0, %%v0, %%v0"
1315 if( i_illegal == 0 )
1317 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
1320 signal( SIGILL, NULL );
1323 return( i_capabilities );
1326 /* default behaviour */
1327 return( i_capabilities );
1332 /*****************************************************************************
1333 * ShowConsole: On Win32, create an output console for debug messages
1334 *****************************************************************************
1335 * This function is usefull only on Win32.
1336 *****************************************************************************/
1338 static void ShowConsole( void )
1341 freopen( "CONOUT$", "w", stdout );
1342 freopen( "CONOUT$", "w", stderr );
1343 freopen( "CONIN$", "r", stdin );