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.192 2002/05/19 11:02:46 massiot 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"
83 /*****************************************************************************
84 * Configuration options for the main program. Each module will also separatly
85 * define its own configuration options.
86 * Look into configuration.h if you need to know more about the following
89 *****************************************************************************/
91 #define MODULE_NAME main
92 #include "modules_inner.h" /* for configuration stuff */
95 #define INTF_TEXT N_("interface module")
96 #define INTF_LONGTEXT N_( \
97 "This option allows you to select the interface used by vlc.\nNote that " \
98 "the default behavior is to automatically select the best method " \
101 #define WARNING_TEXT N_("warning level (or use -v, -vv, etc...)")
102 #define WARNING_LONGTEXT N_( \
103 "Increasing the warning level will allow you to see more debug messages " \
104 "and can sometimes help you to troubleshoot a problem.")
106 #define STATS_TEXT N_("output statistics")
107 #define STATS_LONGTEXT N_( \
108 "Enabling the stats mode will flood your log console with various " \
109 "statistics messages.")
111 #define INTF_PATH_TEXT N_("interface default search path")
112 #define INTF_PATH_LONGTEXT N_( \
113 "This option allows you to set the default path that the interface will " \
114 "open when looking for a file.")
116 #define AOUT_TEXT N_("audio output module")
117 #define AOUT_LONGTEXT N_( \
118 "This option allows you to select the audio audio output method used by " \
119 "vlc.\nNote that the default behavior is to automatically select the " \
120 "best method available.")
122 #define NOAUDIO_TEXT N_("disable audio")
123 #define NOAUDIO_LONGTEXT N_( \
124 "This will completely disable the audio output. The audio decoding " \
125 "stage shouldn't even be done, so it can allow you to save some " \
128 #define MONO_TEXT N_("mono audio")
129 #define MONO_LONGTEXT N_("This will force a mono audio output")
131 #define VOLUME_TEXT N_("audio output volume")
132 #define VOLUME_LONGTEXT N_( \
133 "You can set the default audio output volume here, in a range from 0 to " \
136 #define FORMAT_TEXT N_("audio output format")
137 #define FORMAT_LONGTEXT N_( \
138 "You can force the audio output format here.\n" \
139 "0 -> 16 bits signed native endian (default)\n" \
140 "1 -> 8 bits unsigned\n" \
141 "2 -> 16 bits signed little endian\n" \
142 "3 -> 16 bits signed big endian\n" \
143 "4 -> 8 bits signed\n" \
144 "5 -> 16 bits unsigned little endian\n" \
145 "6 -> 16 bits unsigned big endian\n" \
146 "7 -> mpeg2 audio (unsupported)\n" \
147 "8 -> ac3 pass-through")
149 #define RATE_TEXT N_("audio output frequency (Hz)")
150 #define RATE_LONGTEXT N_( \
151 "You can force the audio output frequency here.\nCommon values are " \
152 "48000, 44100, 32000, 22050, 16000, 11025, 8000.")
154 #define DESYNC_TEXT N_("compensate desynchronization of audio (in ms)")
155 #define DESYNC_LONGTEXT N_( \
156 "This option allows you to delay the audio output. This can be handy if " \
157 "you notice a lag between the video and the audio.")
159 #define VOUT_TEXT N_("video output module")
160 #define VOUT_LONGTEXT N_( \
161 "This option allows you to select the video output method used by vlc.\n" \
162 "Note that the default behavior is to automatically select the best " \
165 #define NOVIDEO_TEXT N_("disable video")
166 #define NOVIDEO_LONGTEXT N_( \
167 "This will completely disable the video output. The video decoding " \
168 "stage shouldn't even be done, so it can allow you to save some " \
171 #define DISPLAY_TEXT N_("display identifier")
172 #define DISPLAY_LONGTEXT N_( \
173 "This is the local display port that will be used for X11 drawing. " \
174 "For instance :0.1.")
176 #define WIDTH_TEXT N_("video width")
177 #define WIDTH_LONGTEXT N_( \
178 "You can enforce the video width here.\nNote that by default vlc will " \
179 "adapt to the video characteristics.")
181 #define HEIGHT_TEXT N_("video height")
182 #define HEIGHT_LONGTEXT N_( \
183 "You can enforce the video height here.\nNote that by default vlc will " \
184 "adapt to the video characteristics.")
186 #define ZOOM_TEXT N_("zoom video")
187 #define ZOOM_LONGTEXT N_( \
188 "You can zoom the video by the specified factor.")
190 #define GRAYSCALE_TEXT N_("grayscale video output")
191 #define GRAYSCALE_LONGTEXT N_( \
192 "Using this option, vlc will not decode the color information from the " \
193 "video (this can also allow you to save some processing power).")
195 #define FULLSCREEN_TEXT N_("fullscreen video output")
196 #define FULLSCREEN_LONGTEXT N_( \
197 "If this option is enabled, vlc will always start a video in fullscreen " \
200 #define NOOVERLAY_TEXT N_("disable hardware acceleration for the video output")
201 #define NOOVERLAY_LONGTEXT N_( \
202 "By default vlc will try to take advantage of the overlay capabilities " \
203 "of you graphics card.")
205 #define SPUMARGIN_TEXT N_("force SPU position")
206 #define SPUMARGIN_LONGTEXT N_( \
207 "You can use this option to place the sub-titles under the movie, " \
208 "instead of over the movie. Try several positions.")
210 #define FILTER_TEXT N_("video filter module")
211 #define FILTER_LONGTEXT N_( \
212 "This will allow you to add a post-processing filter to enhance the " \
213 "picture quality, for instance deinterlacing, or to clone or distort " \
216 #define SERVER_PORT_TEXT N_("server port")
217 #define SERVER_PORT_LONGTEXT N_( \
218 "This is the port used for UDP streams. By default, we chose 1234.")
220 #define NETCHANNEL_TEXT N_("enable network channel mode")
221 #define NETCHANNEL_LONGTEXT N_( \
222 "Activate this option if you want to use the VideoLAN Channel Server.")
224 #define CHAN_SERV_TEXT N_("channel server address")
225 #define CHAN_SERV_LONGTEXT N_( \
226 "Indicate here the address of the VideoLAN Channel Server.")
228 #define CHAN_PORT_TEXT N_("channel server port")
229 #define CHAN_PORT_LONGTEXT N_( \
230 "Indicate here the port on which the VideoLAN Channel Server runs.")
232 #define IFACE_TEXT N_("network interface")
233 #define IFACE_LONGTEXT N_( \
234 "If you have several interfaces on your Linux machine and use the " \
235 "VLAN solution, you may indicate here which interface to use.")
237 #define INPUT_PROGRAM_TEXT N_("choose program (SID)")
238 #define INPUT_PROGRAM_LONGTEXT N_( \
239 "Choose the program to select by giving its Service ID.")
241 #define INPUT_AUDIO_TEXT N_("choose audio")
242 #define INPUT_AUDIO_LONGTEXT N_( \
243 "Give the default type of audio you want to use in a DVD.")
245 #define INPUT_CHAN_TEXT N_("choose channel")
246 #define INPUT_CHAN_LONGTEXT N_( \
247 "Give the stream number of the audio channel you want to use in a DVD " \
250 #define INPUT_SUBT_TEXT N_("choose subtitles")
251 #define INPUT_SUBT_LONGTEXT N_( \
252 "Give the stream number of the subtitle channel you want to use in a DVD " \
255 #define DVD_DEV_TEXT N_("DVD device")
256 #define DVD_DEV_LONGTEXT N_( \
257 "This is the default DVD device to use. Under UNIX it is /dev/dvd, under " \
260 #define VCD_DEV_TEXT N_("VCD device")
261 #define VCD_DEV_LONGTEXT N_( \
262 "This is the default VCD device to use. Under UNIX it is /dev/dvd, under " \
265 #define IPV6_TEXT N_("force IPv6")
266 #define IPV6_LONGTEXT N_( \
267 "If you check this box, IPv6 will be used by default for all UDP and " \
270 #define IPV4_TEXT N_("force IPv4")
271 #define IPV4_LONGTEXT N_( \
272 "If you check this box, IPv4 will be used by default for all UDP and " \
275 #define ADEC_MPEG_TEXT N_("choose MPEG audio decoder")
276 #define ADEC_MPEG_LONGTEXT N_( \
277 "This allows you to select the MPEG audio decoder you want to use. " \
278 "Common choices are builtin and mad.")
280 #define ADEC_AC3_TEXT N_("choose AC3 audio decoder")
281 #define ADEC_AC3_LONGTEXT N_( \
282 "This allows you to select the AC3/A52 audio decoder you want to use. " \
283 "Common choices are builtin and a52.")
285 #define VDEC_SMP_TEXT N_("use additional processors")
286 #define VDEC_SMP_LONGTEXT N_( \
287 "This option is deprecated.")
289 #define VPAR_SYNCHRO_TEXT N_("force synchro algorithm {I|I+|IP|IP+|IPB}")
290 #define VPAR_SYNCHRO_LONGTEXT N_( \
291 "This allows you to force the synchro algorithm, by directly selecting " \
292 "the types of picture you want to decode. Please bear in mind that if " \
293 "you select more pictures than what your CPU is capable to decode, " \
294 "you won't get anything.")
296 #define NOMMX_TEXT N_("disable CPU's MMX support")
297 #define NOMMX_LONGTEXT N_( \
298 "If your processor supports the MMX instructions set but you don't want " \
299 "vlc to use them, you can use this option.")
301 #define NO3DN_TEXT N_("disable CPU's 3D Now! support")
302 #define NO3DN_LONGTEXT N_( \
303 "If your processor supports the 3D Now! instructions set but you don't " \
304 "want vlc to use them, you can use this option.")
306 #define NOMMXEXT_TEXT N_("disable CPU's MMX EXT support")
307 #define NOMMXEXT_LONGTEXT N_( \
308 "If your processor supports the MMX EXT instructions set but you don't " \
309 "want vlc to use them, you can use this option.")
311 #define NOSSE_TEXT N_("disable CPU's SSE support")
312 #define NOSSE_LONGTEXT N_( \
313 "If your processor supports the SSE instructions set but you don't want " \
314 "vlc to use them, you can use this option.")
316 #define NOALTIVEC_TEXT N_("disable CPU's AltiVec support")
317 #define NOALTIVEC_LONGTEXT N_( \
318 "If your processor supports the AltiVec instructions set but you don't " \
319 "want vlc to use them, you can use this option.")
321 #define PLAYLIST_LAUNCH_TEXT N_("launch playlist on startup")
322 #define PLAYLIST_LAUNCH_LONGTEXT N_( \
323 "If you want vlc to start playing on startup, then enable this option.")
325 #define PLAYLIST_ENQUEUE_TEXT N_("enqueue playlist as default")
326 #define PLAYLIST_ENQUEUE_LONGTEXT N_( \
327 "If you want vlc to add items to the playlist as you open them, then " \
328 "enable this option.")
330 #define PLAYLIST_LOOP_TEXT N_("loop playlist on end")
331 #define PLAYLIST_LOOP_LONGTEXT N_( \
332 "If you want vlc to keep playing the playlist indefinitely then enable " \
335 #define MEMCPY_TEXT N_("memory copy module")
336 #define MEMCPY_LONGTEXT N_( \
337 "You can select wich memory copy module you want to use. By default vlc " \
338 "will select the fastest one supported by your hardware.")
340 #define FAST_PTHREAD_TEXT N_("fast pthread on NT/2K/XP (developpers only)")
341 #define FAST_PTHREAD_LONGTEXT N_( \
342 "On Windows NT/2K/XP we use a slow but correct pthread implementation, " \
343 "you can also use this faster implementation but you might experience " \
347 * Quick usage guide for the configuration options:
349 * MODULE_CONFIG_START
351 * ADD_CATEGORY_HINT( N_(text), longtext )
352 * ADD_SUBCATEGORY_HINT( N_(text), longtext )
353 * ADD_STRING( option_name, value, p_callback, N_(text), N_(longtext) )
354 * ADD_FILE( option_name, psz_value, p_callback, N_(text), N_(longtext) )
355 * ADD_MODULE( option_name, psz_value, i_capability, p_callback,
356 * N_(text), N_(longtext) )
357 * ADD_INTEGER( option_name, i_value, p_callback, N_(text), N_(longtext) )
358 * ADD_BOOL( option_name, p_callback, N_(text), N_(longtext) )
363 /* Interface options */
364 ADD_CATEGORY_HINT( N_("Interface"), NULL)
365 ADD_MODULE_WITH_SHORT ( "intf", 'I', MODULE_CAPABILITY_INTF, NULL, NULL, INTF_TEXT, INTF_LONGTEXT )
366 ADD_INTEGER ( "warning", 0, NULL, WARNING_TEXT, WARNING_LONGTEXT )
367 ADD_BOOL ( "stats", NULL, STATS_TEXT, STATS_LONGTEXT )
368 ADD_STRING ( "search-path", NULL, NULL, INTF_PATH_TEXT, INTF_PATH_LONGTEXT )
371 ADD_CATEGORY_HINT( N_("Audio"), NULL)
372 ADD_MODULE_WITH_SHORT ( "aout", 'A', MODULE_CAPABILITY_AOUT, NULL, NULL, AOUT_TEXT, AOUT_LONGTEXT )
373 ADD_BOOL ( "noaudio", NULL, NOAUDIO_TEXT, NOAUDIO_LONGTEXT )
374 ADD_BOOL ( "mono", NULL, MONO_TEXT, MONO_LONGTEXT )
375 ADD_INTEGER ( "volume", VOLUME_DEFAULT, NULL, VOLUME_TEXT, VOLUME_LONGTEXT )
376 ADD_INTEGER ( "rate", 44100, NULL, RATE_TEXT, RATE_LONGTEXT )
377 ADD_INTEGER ( "desync", 0, NULL, DESYNC_TEXT, DESYNC_LONGTEXT )
378 ADD_INTEGER ( "audio-format", 0, NULL, FORMAT_TEXT,
382 ADD_CATEGORY_HINT( N_("Video"), NULL )
383 ADD_MODULE_WITH_SHORT ( "vout", 'V', MODULE_CAPABILITY_VOUT, NULL, NULL, VOUT_TEXT, VOUT_LONGTEXT )
384 ADD_BOOL ( "novideo", NULL, NOVIDEO_TEXT, NOVIDEO_LONGTEXT )
385 ADD_INTEGER ( "width", -1, NULL, WIDTH_TEXT, WIDTH_LONGTEXT )
386 ADD_INTEGER ( "height", -1, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT )
387 ADD_FLOAT ( "zoom", 1, NULL, ZOOM_TEXT, ZOOM_LONGTEXT )
388 ADD_BOOL ( "grayscale", NULL, GRAYSCALE_TEXT, GRAYSCALE_LONGTEXT )
389 ADD_BOOL ( "fullscreen", NULL, FULLSCREEN_TEXT, FULLSCREEN_LONGTEXT )
390 ADD_BOOL ( "nooverlay", NULL, NOOVERLAY_TEXT, NOOVERLAY_LONGTEXT )
391 ADD_INTEGER ( "spumargin", -1, NULL, SPUMARGIN_TEXT, SPUMARGIN_LONGTEXT )
392 ADD_MODULE ( "filter", MODULE_CAPABILITY_VOUT, NULL, NULL, FILTER_TEXT, FILTER_LONGTEXT )
395 ADD_CATEGORY_HINT( N_("Input"), NULL )
396 ADD_INTEGER ( "server-port", 1234, NULL, SERVER_PORT_TEXT, SERVER_PORT_LONGTEXT )
397 ADD_BOOL ( "network-channel", NULL, NETCHANNEL_TEXT, NETCHANNEL_LONGTEXT )
398 ADD_STRING ( "channel-server", "localhost", NULL, CHAN_SERV_TEXT, CHAN_SERV_LONGTEXT )
399 ADD_INTEGER ( "channel-port", 6010, NULL, CHAN_PORT_TEXT, CHAN_PORT_LONGTEXT )
400 ADD_STRING ( "iface", "eth0", NULL, IFACE_TEXT, IFACE_LONGTEXT )
402 ADD_INTEGER ( "program", 0, NULL, INPUT_PROGRAM_TEXT, INPUT_PROGRAM_LONGTEXT )
403 ADD_INTEGER ( "audio-type", -1, NULL, INPUT_AUDIO_TEXT, INPUT_AUDIO_LONGTEXT )
404 ADD_INTEGER ( "audio-channel", -1, NULL, INPUT_CHAN_TEXT, INPUT_CHAN_LONGTEXT )
405 ADD_INTEGER ( "spu-channel", -1, NULL, INPUT_SUBT_TEXT, INPUT_SUBT_LONGTEXT )
407 ADD_STRING ( "dvd", DVD_DEVICE, NULL, DVD_DEV_TEXT, DVD_DEV_LONGTEXT )
408 ADD_STRING ( "vcd", VCD_DEVICE, NULL, VCD_DEV_TEXT, VCD_DEV_LONGTEXT )
410 ADD_BOOL_WITH_SHORT ( "ipv6", '6', NULL, IPV6_TEXT, IPV6_LONGTEXT )
411 ADD_BOOL_WITH_SHORT ( "ipv4", '4', NULL, IPV4_TEXT, IPV4_LONGTEXT )
413 /* Decoder options */
414 ADD_CATEGORY_HINT( N_("Decoders"), NULL )
415 ADD_MODULE ( "mpeg-adec", MODULE_CAPABILITY_DECODER, NULL, NULL, ADEC_MPEG_TEXT, ADEC_MPEG_LONGTEXT )
416 ADD_MODULE ( "ac3-adec", MODULE_CAPABILITY_DECODER, NULL, NULL, ADEC_AC3_TEXT, ADEC_AC3_LONGTEXT )
419 ADD_CATEGORY_HINT( N_("CPU"), NULL )
420 ADD_BOOL ( "nommx", NULL, NOMMX_TEXT, NOMMX_LONGTEXT )
421 ADD_BOOL ( "no3dn", NULL, NO3DN_TEXT, NO3DN_LONGTEXT )
422 ADD_BOOL ( "nommxext", NULL, NOMMXEXT_TEXT, NOMMXEXT_LONGTEXT )
423 ADD_BOOL ( "nosse", NULL, NOSSE_TEXT, NOSSE_LONGTEXT )
424 ADD_BOOL ( "noaltivec", NULL, NOALTIVEC_TEXT, NOALTIVEC_LONGTEXT )
426 /* Playlist options */
427 ADD_CATEGORY_HINT( N_("Playlist"), NULL )
428 ADD_BOOL ( "launch-playlist", NULL, PLAYLIST_LAUNCH_TEXT, PLAYLIST_LAUNCH_LONGTEXT )
429 ADD_BOOL ( "enqueue-playlist", NULL, PLAYLIST_ENQUEUE_TEXT, PLAYLIST_ENQUEUE_LONGTEXT )
430 ADD_BOOL ( "loop-playlist", NULL, PLAYLIST_LOOP_TEXT, PLAYLIST_LOOP_LONGTEXT )
433 ADD_CATEGORY_HINT( N_("Miscellaneous"), NULL )
434 ADD_MODULE ( "memcpy", MODULE_CAPABILITY_MEMCPY, NULL, NULL, MEMCPY_TEXT, MEMCPY_LONGTEXT )
435 ADD_MODULE ( "access", MODULE_CAPABILITY_ACCESS, NULL, NULL, "access module", "This is a legacy entry to let you configure access modules" )
436 ADD_MODULE ( "demux", MODULE_CAPABILITY_DEMUX, NULL, NULL, "demux module", "This is a legacy entry to let you configure demux modules" )
439 ADD_BOOL ( "fast_pthread", NULL, FAST_PTHREAD_TEXT, FAST_PTHREAD_LONGTEXT )
445 SET_DESCRIPTION( N_("main program") )
446 ADD_CAPABILITY( MAIN, 100/*whatever*/ )
449 MODULE_ACTIVATE_START
452 MODULE_DEACTIVATE_START
453 MODULE_DEACTIVATE_STOP
455 /* Hack for help options */
456 static module_t help_module;
457 static module_config_t p_help_config[] =
459 { MODULE_CONFIG_ITEM_BOOL, "help", 'h', N_("print help"),
460 NULL, NULL, 0, 0, NULL, NULL, 0 },
461 { MODULE_CONFIG_ITEM_BOOL, "longhelp", 'H', N_("print detailed help"),
462 NULL, NULL, 0, 0, NULL, NULL, 0 },
463 { MODULE_CONFIG_ITEM_BOOL, "list", 'l', N_("print a list of available "
464 "modules"), NULL, NULL, 0, 0, NULL, NULL, 0 },
465 { MODULE_CONFIG_ITEM_STRING, "module", 'p', N_("print help on module "
466 "<string>"), NULL, NULL, 0, 0, NULL, &help_module.config_lock, 0 },
467 { MODULE_CONFIG_ITEM_BOOL, "version", '\0',
468 N_("print version information"), NULL, NULL, 0, 0, NULL, NULL, 0 },
469 { MODULE_CONFIG_HINT_END, NULL, '\0', NULL, NULL, NULL, 0, 0,
473 /*****************************************************************************
475 *****************************************************************************/
477 /*****************************************************************************
478 * Global variables - these are the only ones, see main.h and modules.h
479 *****************************************************************************/
481 module_bank_t *p_module_bank;
482 input_bank_t *p_input_bank;
483 aout_bank_t *p_aout_bank;
484 vout_bank_t *p_vout_bank;
486 /*****************************************************************************
488 *****************************************************************************/
489 static int GetFilenames ( int i_argc, char *ppsz_argv[] );
490 static void Usage ( const char *psz_module_name );
491 static void ListModules ( void );
492 static void Version ( void );
494 static void InitSignalHandler ( void );
495 static void SimpleSignalHandler ( int i_signal );
496 static void FatalSignalHandler ( int i_signal );
497 static void IllegalSignalHandler ( int i_signal );
498 static u32 CPUCapabilities ( void );
501 static void ShowConsole ( void );
505 static int i_illegal;
506 static char *psz_capability;
508 /*****************************************************************************
509 * main: parse command line, start interface and spawn threads
510 *****************************************************************************
511 * Steps during program execution are:
512 * -configuration parsing and messages interface initialization
513 * -opening of audio output device and some global modules
514 * -execution of interface, which exit on error or on user request
515 * -closing of audio output device and some global modules
516 * On error, the spawned threads are canceled, and the open devices closed.
517 *****************************************************************************/
518 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
520 main_t main_data; /* root of all data - see main.h */
521 module_bank_t module_bank;
522 input_bank_t input_bank;
523 aout_bank_t aout_bank;
524 vout_bank_t vout_bank;
527 struct module_config_s *p_item;
529 p_main = &main_data; /* set up the global variables */
530 p_module_bank = &module_bank;
531 p_input_bank = &input_bank;
532 p_aout_bank = &aout_bank;
533 p_vout_bank = &vout_bank;
535 p_main->i_warning_level = 0;
538 * Support for gettext
540 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT )
541 # if defined( HAVE_LOCALE_H ) && defined( HAVE_LC_MESSAGES )
542 if( !setlocale( LC_MESSAGES, "" ) )
544 fprintf( stderr, "warning: unsupported locale settings\n" );
547 setlocale( LC_CTYPE, "" );
550 if( !bindtextdomain( PACKAGE, LOCALEDIR ) )
552 fprintf( stderr, "warning: no domain %s in directory %s\n",
553 PACKAGE, LOCALEDIR );
556 textdomain( PACKAGE );
560 * Initialize threads system
565 * Test if our code is likely to run on this CPU
567 p_main->i_cpu_capabilities = CPUCapabilities();
570 * System specific initialization code
572 #if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
573 system_Init( &i_argc, ppsz_argv, ppsz_env );
575 #elif defined( SYS_LINUX )
577 /* Activate malloc checking routines to detect heap corruptions. */
578 putenv( "MALLOC_CHECK_=2" );
579 putenv( "GNOME_DISABLE_CRASH_DIALOG=1" );
584 * Initialize messages interface
588 intf_Msg( COPYRIGHT_MESSAGE "\n" );
591 /* Get the executable name (similar to the basename command) */
594 p_main->psz_arg0 = p_tmp = ppsz_argv[ 0 ];
597 if( *p_tmp == '/' ) p_main->psz_arg0 = ++p_tmp;
603 p_main->psz_arg0 = "vlc";
607 * Initialize the module bank and and load the configuration of the main
608 * module. We need to do this at this stage to be able to display a short
609 * help if required by the user. (short help == main module options)
614 /* Hack: insert the help module here */
615 help_module.psz_name = "help";
616 help_module.psz_longname = _( "help module" );
617 help_module.i_config_items =
618 sizeof(p_help_config) / sizeof(module_config_t) - 1;
619 vlc_mutex_init( &help_module.config_lock );
620 help_module.p_config = config_Duplicate( p_help_config );
621 for( p_item = help_module.p_config;
622 p_item->i_type != MODULE_CONFIG_HINT_END;
625 p_item->p_lock = &help_module.config_lock;
627 help_module.next = p_module_bank->first;
628 p_module_bank->first = &help_module;
631 if( config_LoadCmdLine( &i_argc, ppsz_argv, 1 ) )
637 /* Check for short help option */
638 if( config_GetIntVariable( "help" ) )
640 intf_Msg( _("Usage: %s [options] [parameters] [file]...\n"),
648 /* Check for version option */
649 if( config_GetIntVariable( "version" ) )
655 /* Hack: remove the help module here */
656 p_module_bank->first = help_module.next;
660 * Load the builtins and plugins into the module_bank.
661 * We have to do it before config_Load*() because this also gets the
662 * list of configuration options exported by each module and loads their
665 module_LoadBuiltins();
666 module_LoadPlugins();
667 intf_WarnMsg( 2, "module: module bank initialized, found %i modules",
668 p_module_bank->i_count );
670 /* Hack: insert the help module here */
671 help_module.next = p_module_bank->first;
672 p_module_bank->first = &help_module;
675 /* Check for help on modules */
676 if( (p_tmp = config_GetPszVariable( "module" )) )
683 /* Check for long help option */
684 if( config_GetIntVariable( "longhelp" ) )
690 /* Check for module list option */
691 if( config_GetIntVariable( "list" ) )
697 /* Hack: remove the help module here */
698 p_module_bank->first = help_module.next;
703 * Override default configuration with config file settings
705 vlc_mutex_init( &p_main->config_lock );
706 p_main->psz_homedir = config_GetHomeDir();
707 config_LoadConfigFile( NULL );
710 * Override configuration with command line settings
712 if( config_LoadCmdLine( &i_argc, ppsz_argv, 0 ) )
716 /* Pause the console because it's destroyed when we exit */
717 intf_Msg( "The command line options couldn't be loaded, check that "
718 "they are valid.\nPress the RETURN key to continue..." );
727 * System specific configuration
731 /* p_main inititalization. FIXME ? */
732 p_main->i_warning_level = config_GetIntVariable( "warning" );
733 p_main->i_desync = config_GetIntVariable( "desync" ) * (mtime_t)1000;
734 p_main->b_stats = config_GetIntVariable( "stats" );
735 p_main->b_audio = !config_GetIntVariable( "noaudio" );
736 p_main->b_stereo= !config_GetIntVariable( "mono" );
737 p_main->b_video = !config_GetIntVariable( "novideo" );
738 if( config_GetIntVariable( "nommx" ) )
739 p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_MMX;
740 if( config_GetIntVariable( "no3dn" ) )
741 p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_3DNOW;
742 if( config_GetIntVariable( "nommxext" ) )
743 p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_MMXEXT;
744 if( config_GetIntVariable( "nosse" ) )
745 p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_SSE;
746 if( config_GetIntVariable( "noaltivec" ) )
747 p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_ALTIVEC;
750 if( p_main->b_stats )
752 char p_capabilities[200];
753 p_capabilities[0] = '\0';
755 #define PRINT_CAPABILITY( capability, string ) \
756 if( p_main->i_cpu_capabilities & capability ) \
758 strncat( p_capabilities, string " ", \
759 sizeof(p_capabilities) - strlen(p_capabilities) ); \
760 p_capabilities[sizeof(p_capabilities) - 1] = '\0'; \
763 PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
764 PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
765 PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
766 PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
767 PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
768 PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
769 PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
770 PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "Altivec" );
771 PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
772 intf_StatMsg( "info: CPU has capabilities : %s", p_capabilities );
776 * Initialize playlist and get commandline files
778 p_main->p_playlist = intf_PlaylistCreate();
779 if( !p_main->p_playlist )
781 intf_ErrMsg( "playlist error: playlist initialization failed" );
785 intf_PlaylistInit( p_main->p_playlist );
788 * Get input filenames given as commandline arguments
790 GetFilenames( i_argc, ppsz_argv );
793 * Initialize input, aout and vout banks
800 * Choose the best memcpy module
802 psz_module = config_GetPszVariable( "memcpy" );
803 p_main->p_memcpy_module = module_Need( MODULE_CAPABILITY_MEMCPY,
805 if( psz_module ) free( psz_module );
806 if( p_main->p_memcpy_module == NULL )
808 intf_ErrMsg( "intf error: no suitable memcpy module, "
809 "using libc default" );
810 p_main->pf_memcpy = memcpy;
814 p_main->pf_memcpy = p_main->p_memcpy_module->p_functions
815 ->memcpy.functions.memcpy.pf_memcpy;
819 * Initialize shared resources and libraries
821 if( config_GetIntVariable( "network-channel" ) &&
822 network_ChannelCreate() )
824 /* On error during Channels initialization, switch off channels */
825 intf_ErrMsg( "intf error: channels initialization failed, "
826 "deactivating channels" );
827 config_PutIntVariable( "network-channel", 0 );
831 * Try to run the interface
833 p_main->p_intf = intf_Create();
834 if( p_main->p_intf == NULL )
836 intf_ErrMsg( "intf error: interface initialization failed" );
841 * Set signal handling policy for all threads
846 * This is the main loop
848 p_main->p_intf->pf_run( p_main->p_intf );
851 * Finished, destroy the interface
853 intf_Destroy( p_main->p_intf );
856 * Go back into channel 0 which is the network
858 if( config_GetIntVariable( "network-channel" ) && p_main->p_channel )
860 network_ChannelJoin( COMMON_CHANNEL );
865 * Free input, aout and vout banks
874 intf_PlaylistDestroy( p_main->p_playlist );
877 * Free memcpy module if it was allocated
879 if( p_main->p_memcpy_module != NULL )
881 module_Unneed( p_main->p_memcpy_module );
890 * System specific cleaning code
895 * Terminate messages interface and program
897 intf_WarnMsg( 1, "intf: program terminated" );
901 * Stop threads system
909 /* following functions are local */
911 /*****************************************************************************
912 * GetFilenames: parse command line options which are not flags
913 *****************************************************************************
914 * Parse command line for input files.
915 *****************************************************************************/
916 static int GetFilenames( int i_argc, char *ppsz_argv[] )
920 /* We assume that the remaining parameters are filenames */
921 for( i_opt = optind; i_opt < i_argc; i_opt++ )
923 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
924 ppsz_argv[ i_opt ] );
930 /*****************************************************************************
931 * Usage: print program usage
932 *****************************************************************************
933 * Print a short inline help. Message interface is initialized at this stage.
934 *****************************************************************************/
935 static void Usage( const char *psz_module_name )
937 #define FORMAT_STRING " --%s%s%s%s%s %s"
938 /* option name ---------------' | | | | |
939 * <bra ------------------------' | | | |
940 * option type or "" -------------' | | |
941 * ket> ----------------------------' | |
942 * padding spaces --------------------' |
943 * comment ------------------------------'
945 * The purpose of having bra and ket is that we might i18n them as well.
948 #define PADDING_SPACES 25
950 module_config_t *p_item;
951 char psz_spaces[PADDING_SPACES+LINE_START+1];
952 char psz_format[sizeof(FORMAT_STRING)];
954 memset( psz_spaces, ' ', PADDING_SPACES+LINE_START );
955 psz_spaces[PADDING_SPACES+LINE_START] = '\0';
957 strcpy( psz_format, FORMAT_STRING );
963 /* Enumerate the config of each module */
964 for( p_module = p_module_bank->first ;
966 p_module = p_module->next )
968 if( psz_module_name && strcmp( psz_module_name, p_module->psz_name ) )
971 /* ignore modules without config options */
972 if( !p_module->i_config_items ) continue;
974 /* print module name */
975 intf_Msg( _("%s module options:\n"), p_module->psz_name );
977 for( p_item = p_module->p_config;
978 p_item->i_type != MODULE_CONFIG_HINT_END;
981 char *psz_bra = NULL, *psz_type = NULL, *psz_ket = NULL;
984 if( p_item->i_short )
987 psz_format[3] = p_item->i_short;
997 switch( p_item->i_type )
999 case MODULE_CONFIG_HINT_CATEGORY:
1000 intf_Msg( " %s", p_item->psz_text );
1003 case MODULE_CONFIG_ITEM_STRING:
1004 case MODULE_CONFIG_ITEM_FILE:
1005 case MODULE_CONFIG_ITEM_MODULE: /* We could also have "=<" here */
1006 psz_bra = " <"; psz_type = _("string"); psz_ket = ">";
1008 case MODULE_CONFIG_ITEM_INTEGER:
1009 psz_bra = " <"; psz_type = _("integer"); psz_ket = ">";
1011 case MODULE_CONFIG_ITEM_FLOAT:
1012 psz_bra = " <"; psz_type = _("float"); psz_ket = ">";
1014 case MODULE_CONFIG_ITEM_BOOL:
1015 psz_bra = ""; psz_type = ""; psz_ket = "";
1021 i = PADDING_SPACES - strlen( p_item->psz_name )
1022 - strlen( psz_bra ) - strlen( psz_type )
1023 - strlen( psz_ket ) - 1;
1027 psz_spaces[i] = '\n';
1031 psz_spaces[i] = '\0';
1034 intf_Msg( psz_format, p_item->psz_name, psz_bra, psz_type,
1035 psz_ket, psz_spaces, p_item->psz_text );
1036 psz_spaces[i] = ' ';
1040 /* Yet another nasty hack.
1041 * Maybe we could use MODULE_CONFIG_ITEM_END to display tail messages
1042 * for each module?? */
1043 if( !strcmp( "main", p_module->psz_name ) )
1045 intf_Msg( _("\nPlaylist items:"
1046 "\n *.mpg, *.vob plain MPEG-1/2 files"
1047 "\n [dvd:][device][@raw_device][@[title][,[chapter][,angle]]]"
1049 "\n [vcd:][device][@[title][,[chapter]]"
1051 "\n udpstream:[@[<bind address>][:<bind port>]]"
1052 "\n UDP stream sent by VLS"
1053 "\n vlc:loop loop execution of the "
1055 "\n vlc:pause pause execution of "
1057 "\n vlc:quit quit VLC") );
1064 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1065 intf_Msg( _("\nPress the RETURN key to continue...") );
1070 /*****************************************************************************
1071 * ListModules: list the available modules with their description
1072 *****************************************************************************
1073 * Print a list of all available modules (builtins and plugins) and a short
1074 * description for each one.
1075 *****************************************************************************/
1076 static void ListModules( void )
1079 char psz_spaces[22];
1081 memset( psz_spaces, ' ', 22 );
1088 intf_Msg( _("Usage: %s [options] [parameters] [file]...\n"),
1091 intf_Msg( _("[module] [description]") );
1093 /* Enumerate each module */
1094 for( p_module = p_module_bank->first ;
1096 p_module = p_module->next )
1100 /* Nasty hack, but right now I'm too tired to think about a nice
1102 i = 22 - strlen( p_module->psz_name ) - 1;
1106 intf_Msg( " %s%s %s", p_module->psz_name, psz_spaces,
1107 p_module->psz_longname );
1109 psz_spaces[i] = ' ';
1113 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1114 intf_Msg( _("\nPress the RETURN key to continue...") );
1119 /*****************************************************************************
1120 * Version: print complete program version
1121 *****************************************************************************
1122 * Print complete program version and build number.
1123 *****************************************************************************/
1124 static void Version( void )
1130 intf_Msg( VERSION_MESSAGE );
1132 _("This program comes with NO WARRANTY, to the extent permitted by "
1133 "law.\nYou may redistribute it under the terms of the GNU General "
1134 "Public License;\nsee the file named COPYING for details.\n"
1135 "Written by the VideoLAN team at Ecole Centrale, Paris.") );
1137 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
1138 intf_Msg( _("\nPress the RETURN key to continue...") );
1143 /*****************************************************************************
1144 * InitSignalHandler: system signal handler initialization
1145 *****************************************************************************
1146 * Set the signal handlers. SIGTERM is not intercepted, because we need at
1147 * at least a method to kill the program when all other methods failed, and
1148 * when we don't want to use SIGKILL.
1149 *****************************************************************************/
1150 static void InitSignalHandler( void )
1152 /* Termination signals */
1154 signal( SIGINT, FatalSignalHandler );
1155 signal( SIGHUP, FatalSignalHandler );
1156 signal( SIGQUIT, FatalSignalHandler );
1159 signal( SIGALRM, SimpleSignalHandler );
1160 signal( SIGPIPE, SimpleSignalHandler );
1164 /*****************************************************************************
1165 * SimpleSignalHandler: system signal handler
1166 *****************************************************************************
1167 * This function is called when a non fatal signal is received by the program.
1168 *****************************************************************************/
1169 static void SimpleSignalHandler( int i_signal )
1171 /* Acknowledge the signal received */
1172 intf_WarnMsg( 0, "intf: ignoring signal %d", i_signal );
1175 /*****************************************************************************
1176 * FatalSignalHandler: system signal handler
1177 *****************************************************************************
1178 * This function is called when a fatal signal is received by the program.
1179 * It tries to end the program in a clean way.
1180 *****************************************************************************/
1181 static void FatalSignalHandler( int i_signal )
1183 static mtime_t abort_time = 0;
1184 static volatile boolean_t b_die = 0;
1186 /* Once a signal has been trapped, the termination sequence will be
1187 * armed and following signals will be ignored to avoid sending messages
1188 * to an interface having been destroyed */
1192 abort_time = mdate();
1194 /* Acknowledge the signal received */
1195 intf_ErrMsg( "intf error: signal %d received, exiting - do it again "
1196 "if vlc gets stuck", i_signal );
1198 /* Try to terminate everything - this is done by requesting the end
1199 * of the interface thread */
1200 p_main->p_intf->b_die = 1;
1205 /* If user asks again 1 second later, die badly */
1206 if( mdate() > abort_time + 1000000 )
1209 signal( SIGINT, SIG_IGN );
1210 signal( SIGHUP, SIG_IGN );
1211 signal( SIGQUIT, SIG_IGN );
1214 intf_ErrMsg( "intf error: user insisted too much, dying badly" );
1219 /*****************************************************************************
1220 * IllegalSignalHandler: system signal handler
1221 *****************************************************************************
1222 * This function is called when an illegal instruction signal is received by
1223 * the program. We use this function to test OS and CPU capabilities
1224 *****************************************************************************/
1225 static void IllegalSignalHandler( int i_signal )
1227 /* Acknowledge the signal received */
1230 #ifdef HAVE_SIGRELSE
1231 sigrelse( i_signal );
1234 #if defined( __i386__ )
1235 fprintf( stderr, "warning: your CPU has %s instructions, but not your "
1236 "operating system.\n", psz_capability );
1237 fprintf( stderr, " some optimizations will be disabled unless "
1238 "you upgrade your OS\n" );
1239 # if defined( SYS_LINUX )
1240 fprintf( stderr, " (for instance Linux kernel 2.4.x or later)\n" );
1247 /*****************************************************************************
1248 * CPUCapabilities: list the processors MMX support and other capabilities
1249 *****************************************************************************
1250 * This function is called to list extensions the CPU may have.
1251 *****************************************************************************/
1252 static u32 CPUCapabilities( void )
1254 volatile u32 i_capabilities = CPU_CAPABILITY_NONE;
1256 #if defined( SYS_DARWIN )
1257 struct host_basic_info hi;
1259 host_name_port_t host;
1262 char *psz_name, *psz_subname;
1264 i_capabilities |= CPU_CAPABILITY_FPU;
1266 /* Should 'never' fail? */
1267 host = mach_host_self();
1269 i_size = sizeof( hi ) / sizeof( int );
1270 ret = host_info( host, HOST_BASIC_INFO, ( host_info_t )&hi, &i_size );
1272 if( ret != KERN_SUCCESS )
1274 fprintf( stderr, "error: couldn't get CPU information\n" );
1275 return( i_capabilities );
1278 slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
1279 /* FIXME: need better way to detect newer proccessors.
1280 * could do strncmp(a,b,5), but that's real ugly */
1281 if( !strcmp(psz_name, "ppc7400") || !strcmp(psz_name, "ppc7450") )
1283 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
1286 return( i_capabilities );
1288 #elif defined( __i386__ )
1289 volatile unsigned int i_eax, i_ebx, i_ecx, i_edx;
1290 volatile boolean_t b_amd;
1292 /* Needed for x86 CPU capabilities detection */
1293 # define cpuid( a ) \
1294 asm volatile ( "pushl %%ebx\n\t" \
1296 "movl %%ebx,%1\n\t" \
1305 i_capabilities |= CPU_CAPABILITY_FPU;
1307 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1308 signal( SIGILL, IllegalSignalHandler );
1311 /* test for a 486 CPU */
1312 asm volatile ( "pushl %%ebx\n\t"
1315 "movl %%eax, %%ebx\n\t"
1316 "xorl $0x200000, %%eax\n\t"
1328 if( i_eax == i_ebx )
1330 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1331 signal( SIGILL, NULL );
1333 return( i_capabilities );
1336 i_capabilities |= CPU_CAPABILITY_486;
1338 /* the CPU supports the CPUID instruction - get its level */
1339 cpuid( 0x00000000 );
1343 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1344 signal( SIGILL, NULL );
1346 return( i_capabilities );
1349 /* FIXME: this isn't correct, since some 486s have cpuid */
1350 i_capabilities |= CPU_CAPABILITY_586;
1352 /* borrowed from mpeg2dec */
1353 b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
1354 && ( i_edx == 0x69746e65 );
1356 /* test for the MMX flag */
1357 cpuid( 0x00000001 );
1359 if( ! (i_edx & 0x00800000) )
1361 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1362 signal( SIGILL, NULL );
1364 return( i_capabilities );
1367 i_capabilities |= CPU_CAPABILITY_MMX;
1369 if( i_edx & 0x02000000 )
1371 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1373 # ifdef CAN_COMPILE_SSE
1374 /* We test if OS supports the SSE instructions */
1375 psz_capability = "SSE";
1377 if( setjmp( env ) == 0 )
1379 /* Test a SSE instruction */
1380 __asm__ __volatile__ ( "xorps %%xmm0,%%xmm0\n" : : );
1383 if( i_illegal == 0 )
1385 i_capabilities |= CPU_CAPABILITY_SSE;
1390 /* test for additional capabilities */
1391 cpuid( 0x80000000 );
1393 if( i_eax < 0x80000001 )
1395 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1396 signal( SIGILL, NULL );
1398 return( i_capabilities );
1401 /* list these additional capabilities */
1402 cpuid( 0x80000001 );
1404 # ifdef CAN_COMPILE_3DNOW
1405 if( i_edx & 0x80000000 )
1407 psz_capability = "3D Now!";
1409 if( setjmp( env ) == 0 )
1411 /* Test a 3D Now! instruction */
1412 __asm__ __volatile__ ( "pfadd %%mm0,%%mm0\n" "femms\n" : : );
1415 if( i_illegal == 0 )
1417 i_capabilities |= CPU_CAPABILITY_3DNOW;
1422 if( b_amd && ( i_edx & 0x00400000 ) )
1424 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1427 # if defined( CAN_COMPILE_SSE ) || defined ( CAN_COMPILE_3DNOW )
1428 signal( SIGILL, NULL );
1430 return( i_capabilities );
1432 #elif defined( __powerpc__ )
1434 i_capabilities |= CPU_CAPABILITY_FPU;
1436 # ifdef CAN_COMPILE_ALTIVEC
1437 signal( SIGILL, IllegalSignalHandler );
1439 psz_capability = "AltiVec";
1441 if( setjmp( env ) == 0 )
1443 asm volatile ("mtspr 256, %0\n\t"
1444 "vand %%v0, %%v0, %%v0"
1449 if( i_illegal == 0 )
1451 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
1454 signal( SIGILL, NULL );
1457 return( i_capabilities );
1459 #elif defined( __sparc__ )
1461 i_capabilities |= CPU_CAPABILITY_FPU;
1462 return( i_capabilities );
1465 /* default behaviour */
1466 return( i_capabilities );
1471 /*****************************************************************************
1472 * ShowConsole: On Win32, create an output console for debug messages
1473 *****************************************************************************
1474 * This function is useful only on Win32.
1475 *****************************************************************************/
1477 static void ShowConsole( void )
1480 freopen( "CONOUT$", "w", stdout );
1481 freopen( "CONOUT$", "w", stderr );
1482 freopen( "CONIN$", "r", stdin );