1 /*****************************************************************************
2 * main.c: main vlc source
3 * Includes the main() function for vlc. Parses command line, start interface
5 *****************************************************************************
6 * Copyright (C) 1998, 1999, 2000 VideoLAN
7 * $Id: main.c,v 1.107 2001/07/16 22:00:45 gbazin Exp $
9 * Authors: Vincent Seguin <seguin@via.ecp.fr>
10 * Samuel Hocevar <sam@zoy.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
32 #include <signal.h> /* SIGHUP, SIGINT, SIGKILL */
33 #include <stdio.h> /* sprintf() */
34 #include <setjmp.h> /* longjmp, setjmp */
36 #ifdef HAVE_GETOPT_LONG
38 # include <getopt.h> /* getopt() */
41 # include "GNUgetopt/getopt.h"
45 # include <mach/mach.h> /* Altivec detection */
46 # include <mach/mach_error.h> /* some day the header files||compiler *
47 will define it for us */
48 # include <mach/bootstrap.h>
52 #include <netinet/in.h> /* BSD: struct in_addr */
59 #include <errno.h> /* ENOMEM */
60 #include <stdlib.h> /* getenv(), strtol(), */
61 #include <string.h> /* strerror() */
62 #include <fcntl.h> /* open(), O_WRONLY */
63 #include <sys/stat.h> /* S_IREAD */
70 #include "tests.h" /* TestCPU() */
73 #include "stream_control.h"
74 #include "input_ext-intf.h"
77 #include "intf_playlist.h"
78 #include "interface.h"
80 #include "audio_output.h"
83 #include "video_output.h"
86 # include "beos_specific.h"
90 # include "darwin_specific.h"
93 #include "netutils.h" /* network_ChannelJoin */
97 /*****************************************************************************
98 * Command line options constants. If something is changed here, be sure that
99 * GetConfiguration and Usage are also changed.
100 *****************************************************************************/
102 /* Long options return values - note that values corresponding to short options
103 * chars, and in general any regular char, should be avoided */
104 #define OPT_NOAUDIO 150
105 #define OPT_STEREO 151
107 #define OPT_SPDIF 153
109 #define OPT_NOVIDEO 160
110 #define OPT_DISPLAY 161
111 #define OPT_WIDTH 162
112 #define OPT_HEIGHT 163
113 #define OPT_COLOR 164
114 #define OPT_FULLSCREEN 165
115 #define OPT_OVERLAY 166
117 #define OPT_CHANNELS 170
118 #define OPT_SERVER 171
120 #define OPT_BROADCAST 173
122 #define OPT_INPUT 180
123 #define OPT_MOTION 181
126 #define OPT_DOWNMIX 184
127 #define OPT_IMDCT 185
129 #define OPT_SYNCHRO 190
130 #define OPT_WARNING 191
131 #define OPT_VERSION 192
132 #define OPT_STDOUT 193
139 /* Needed for x86 CPU capabilities detection */
141 asm volatile ( "cpuid" \
150 static const struct option longopts[] =
152 /* name, has_arg, flag, val */
154 /* General/common options */
155 { "help", 0, 0, 'h' },
156 { "longhelp", 0, 0, 'H' },
157 { "version", 0, 0, OPT_VERSION },
159 /* Interface options */
160 { "intf", 1, 0, 'I' },
161 { "warning", 1, 0, OPT_WARNING },
162 { "stdout", 1, 0, OPT_STDOUT },
165 { "noaudio", 0, 0, OPT_NOAUDIO },
166 { "aout", 1, 0, 'A' },
167 { "stereo", 0, 0, OPT_STEREO },
168 { "mono", 0, 0, OPT_MONO },
169 { "spdif", 0, 0, OPT_SPDIF },
170 { "downmix", 1, 0, OPT_DOWNMIX },
171 { "imdct", 1, 0, OPT_IMDCT },
174 { "novideo", 0, 0, OPT_NOVIDEO },
175 { "vout", 1, 0, 'V' },
176 { "display", 1, 0, OPT_DISPLAY },
177 { "width", 1, 0, OPT_WIDTH },
178 { "height", 1, 0, OPT_HEIGHT },
179 { "grayscale", 0, 0, 'g' },
180 { "color", 0, 0, OPT_COLOR },
181 { "motion", 1, 0, OPT_MOTION },
182 { "idct", 1, 0, OPT_IDCT },
183 { "yuv", 1, 0, OPT_YUV },
184 { "fullscreen", 0, 0, OPT_FULLSCREEN },
185 { "overlay", 0, 0, OPT_OVERLAY },
188 { "dvdtitle", 1, 0, 't' },
189 { "dvdchapter", 1, 0, 'T' },
190 { "dvdangle", 1, 0, 'u' },
191 { "dvdaudio", 1, 0, 'a' },
192 { "dvdchannel", 1, 0, 'c' },
193 { "dvdsubtitle", 1, 0, 's' },
196 { "input", 1, 0, OPT_INPUT },
197 { "server", 1, 0, OPT_SERVER },
198 { "port", 1, 0, OPT_PORT },
199 { "broadcast", 1, 0, OPT_BROADCAST },
200 { "channels", 0, 0, OPT_CHANNELS },
202 /* Synchro options */
203 { "synchro", 1, 0, OPT_SYNCHRO },
208 static const char *psz_shortopts = "hHvgt:T:u:a:s:c:I:A:V:";
210 /*****************************************************************************
211 * Global variable program_data - these are the only ones, see main.h and
213 *****************************************************************************/
215 module_bank_t *p_module_bank;
216 aout_bank_t *p_aout_bank;
217 vout_bank_t *p_vout_bank;
219 /*****************************************************************************
221 *****************************************************************************/
222 static int GetConfiguration ( int *pi_argc, char *ppsz_argv[],
224 static int GetFilenames ( int i_argc, char *ppsz_argv[] );
225 static void Usage ( int i_fashion );
226 static void Version ( void );
228 static void InitSignalHandler ( void );
229 static void SimpleSignalHandler ( int i_signal );
230 static void FatalSignalHandler ( int i_signal );
231 static void InstructionSignalHandler( int i_signal );
232 static int CPUCapabilities ( void );
234 static int RedirectSTDOUT ( void );
235 static void ShowConsole ( void );
238 static int i_illegal;
240 /*****************************************************************************
241 * main: parse command line, start interface and spawn threads
242 *****************************************************************************
243 * Steps during program execution are:
244 * -configuration parsing and messages interface initialization
245 * -opening of audio output device and some global modules
246 * -execution of interface, which exit on error or on user request
247 * -closing of audio output device and some global modules
248 * On error, the spawned threads are canceled, and the open devices closed.
249 *****************************************************************************/
250 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
252 main_t main_data; /* root of all data - see main.h */
253 module_bank_t module_bank;
254 aout_bank_t aout_bank;
255 vout_bank_t vout_bank;
257 p_main = &main_data; /* set up the global variables */
258 p_module_bank = &module_bank;
259 p_aout_bank = &aout_bank;
260 p_vout_bank = &vout_bank;
263 * Initialize threads system
268 * Test if our code is likely to run on this CPU
270 p_main->i_cpu_capabilities = CPUCapabilities();
272 #if defined( __pentium__ ) || defined( __pentiumpro__ )
273 if( ! TestCPU( CPU_CAPABILITY_586 ) )
275 fprintf( stderr, "error: this program needs a Pentium CPU,\n"
276 "please try a version without Pentium support\n" );
282 * System specific initialization code
284 #if defined( SYS_BEOS ) || defined( SYS_DARWIN )
285 system_Init( &i_argc, ppsz_argv, ppsz_env );
289 * Initialize messages interface
291 p_main->p_msg = intf_MsgCreate();
292 if( !p_main->p_msg ) /* start messages interface */
294 fprintf( stderr, "error: can't initialize messages interface (%s)\n",
299 intf_MsgImm( COPYRIGHT_MESSAGE );
304 if( GetConfiguration( &i_argc, ppsz_argv, ppsz_env ) ) /* parse cmd line */
311 * Redirect the standard output if required by the user, and on Win32 we
312 * also open a console to display the debug messages.
317 * Initialize playlist and get commandline files
319 p_main->p_playlist = intf_PlaylistCreate();
320 if( !p_main->p_playlist )
322 intf_ErrMsg( "playlist error: playlist initialization failed" );
326 intf_PlaylistInit( p_main->p_playlist );
329 * Get input filenames given as commandline arguments
331 GetFilenames( i_argc, ppsz_argv );
334 * Initialize module, aout and vout banks
341 * Initialize shared resources and libraries
343 if( main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
344 INPUT_NETWORK_CHANNEL_DEFAULT ) &&
345 network_ChannelCreate() )
347 /* On error during Channels initialization, switch off channels */
348 intf_Msg( "Channels initialization failed : "
349 "Channel management is deactivated" );
350 main_PutIntVariable( INPUT_NETWORK_CHANNEL_VAR, 0 );
354 * Try to run the interface
356 p_main->p_intf = intf_Create();
357 if( p_main->p_intf == NULL )
359 intf_ErrMsg( "intf error: interface initialization failed" );
364 * Set signal handling policy for all threads
369 * This is the main loop
371 p_main->p_intf->pf_run( p_main->p_intf );
374 * Finished, destroy the interface
376 intf_Destroy( p_main->p_intf );
379 * Go back into channel 0 which is the network
381 if( main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
382 INPUT_NETWORK_CHANNEL_DEFAULT ) )
384 network_ChannelJoin( COMMON_CHANNEL );
389 * Free module, aout and vout banks
398 intf_PlaylistDestroy( p_main->p_playlist );
401 * System specific cleaning code
403 #if defined( SYS_BEOS ) || defined( SYS_DARWIN )
409 * Terminate messages interface and program
411 intf_Msg( "intf: program terminated" );
415 * Stop threads system
422 /*****************************************************************************
423 * main_GetIntVariable: get the int value of an environment variable
424 *****************************************************************************
425 * This function is used to read some default parameters in modules.
426 *****************************************************************************/
427 int main_GetIntVariable( char *psz_name, int i_default )
429 char * psz_env; /* environment value */
430 char * psz_end; /* end of parsing index */
431 long int i_value; /* value */
433 psz_env = getenv( psz_name );
436 i_value = strtol( psz_env, &psz_end, 0 );
437 if( (*psz_env != '\0') && (*psz_end == '\0') )
445 /*****************************************************************************
446 * main_GetPszVariable: get the string value of an environment variable
447 *****************************************************************************
448 * This function is used to read some default parameters in modules.
449 *****************************************************************************/
450 char * main_GetPszVariable( char *psz_name, char *psz_default )
454 psz_env = getenv( psz_name );
459 return( psz_default );
462 /*****************************************************************************
463 * main_PutPszVariable: set the string value of an environment variable
464 *****************************************************************************
465 * This function is used to set some default parameters in modules. The use of
466 * this function will cause some memory leak: since some systems use the pointer
467 * passed to putenv to store the environment string, it can't be freed.
468 *****************************************************************************/
469 void main_PutPszVariable( char *psz_name, char *psz_value )
473 psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
474 if( psz_env == NULL )
476 intf_ErrMsg( "intf error: cannot create psz_env (%s)",
481 sprintf( psz_env, "%s=%s", psz_name, psz_value );
482 if( putenv( psz_env ) )
484 intf_ErrMsg( "intf error: cannot putenv (%s)", strerror(errno) );
489 /*****************************************************************************
490 * main_PutIntVariable: set the integer value of an environment variable
491 *****************************************************************************
492 * This function is used to set some default parameters in modules. The use of
493 * this function will cause some memory leak: since some systems use the pointer
494 * passed to putenv to store the environment string, it can't be freed.
495 *****************************************************************************/
496 void main_PutIntVariable( char *psz_name, int i_value )
498 char psz_value[ 256 ]; /* buffer for value */
500 sprintf( psz_value, "%d", i_value );
501 main_PutPszVariable( psz_name, psz_value );
504 /* following functions are local */
506 /*****************************************************************************
507 * GetConfiguration: parse command line
508 *****************************************************************************
509 * Parse command line and configuration file for configuration. If the inline
510 * help is requested, the function Usage() is called and the function returns
511 * -1 (causing main() to exit). The messages interface is initialized at this
512 * stage, but most structures are not allocated, so only environment should
514 *****************************************************************************/
515 static int GetConfiguration( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
520 /* Set default configuration and copy arguments */
521 p_main->i_argc = *pi_argc;
522 p_main->ppsz_argv = ppsz_argv;
523 p_main->ppsz_env = ppsz_env;
528 p_main->i_warning_level = 0;
530 p_main->p_channel = NULL;
532 /* Get the executable name (similar to the basename command) */
533 p_main->psz_arg0 = p_tmp = ppsz_argv[ 0 ];
538 p_main->psz_arg0 = ++p_tmp;
547 /* When vlc.app is run by double clicking in Mac OS X, the 2nd arg
548 * is the PSN - process serial number (a unique PID-ish thingie)
549 * still ok for real Darwin & when run from command line */
550 if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
551 /* for example -psn_0_9306113 */
553 /* GDMF!... I can't do this or else the MacOSX window server will
554 * not pick up the PSN and not register the app and we crash...
555 * hence the following kludge otherwise we'll get confused w/ argv[1]
556 * being an input file name */
558 ppsz_argv[ 1 ] = NULL;
560 *pi_argc = *pi_argc - 1;
566 /* Parse command line options */
568 while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv,
569 psz_shortopts, longopts, 0 ) ) != EOF )
573 /* General/common options */
574 case 'h': /* -h, --help */
578 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
579 if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
580 INTF_STDOUT_DEFAULT ) ) == 0 )
582 /* No stdout redirection has been asked for */
583 intf_MsgImm( "\nPress the RETURN key to continue..." );
589 case 'H': /* -H, --longhelp */
593 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
594 if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
595 INTF_STDOUT_DEFAULT ) ) == 0 )
597 /* No stdout redirection has been asked for */
598 intf_MsgImm( "\nPress the RETURN key to continue..." );
604 case OPT_VERSION: /* --version */
608 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
609 if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
610 INTF_STDOUT_DEFAULT ) ) == 0 )
612 /* No stdout redirection has been asked for */
613 intf_MsgImm( "\nPress the RETURN key to continue..." );
619 case 'v': /* -v, --verbose */
620 p_main->i_warning_level++;
623 /* Interface warning messages level */
624 case 'I': /* -I, --intf */
625 main_PutPszVariable( INTF_METHOD_VAR, optarg );
627 case OPT_WARNING: /* --warning */
628 intf_ErrMsg( "intf error: `--warning' is deprecated, use `-v'" );
629 p_main->i_warning_level = atoi(optarg);
632 case OPT_STDOUT: /* --stdout */
633 main_PutPszVariable( INTF_STDOUT_VAR, optarg );
637 case OPT_NOAUDIO: /* --noaudio */
640 case 'A': /* -A, --aout */
641 main_PutPszVariable( AOUT_METHOD_VAR, optarg );
643 case OPT_STEREO: /* --stereo */
644 main_PutIntVariable( AOUT_STEREO_VAR, 1 );
646 case OPT_MONO: /* --mono */
647 main_PutIntVariable( AOUT_STEREO_VAR, 0 );
649 case OPT_SPDIF: /* --spdif */
650 main_PutIntVariable( AOUT_SPDIF_VAR, 1 );
652 case OPT_DOWNMIX: /* --downmix */
653 main_PutPszVariable( DOWNMIX_METHOD_VAR, optarg );
655 case OPT_IMDCT: /* --imdct */
656 main_PutPszVariable( IMDCT_METHOD_VAR, optarg );
660 case OPT_NOVIDEO: /* --novideo */
663 case 'V': /* -V, --vout */
664 main_PutPszVariable( VOUT_METHOD_VAR, optarg );
666 case OPT_DISPLAY: /* --display */
667 main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
669 case OPT_WIDTH: /* --width */
670 main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
672 case OPT_HEIGHT: /* --height */
673 main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
675 case 'g': /* -g, --grayscale */
676 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
678 case OPT_COLOR: /* --color */
679 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
681 case OPT_FULLSCREEN: /* --fullscreen */
682 main_PutIntVariable( VOUT_FULLSCREEN_VAR, 1 );
684 case OPT_OVERLAY: /* --overlay */
685 main_PutIntVariable( VOUT_OVERLAY_VAR, 1 );
687 case OPT_MOTION: /* --motion */
688 main_PutPszVariable( MOTION_METHOD_VAR, optarg );
690 case OPT_IDCT: /* --idct */
691 main_PutPszVariable( IDCT_METHOD_VAR, optarg );
693 case OPT_YUV: /* --yuv */
694 main_PutPszVariable( YUV_METHOD_VAR, optarg );
699 main_PutIntVariable( INPUT_TITLE_VAR, atoi(optarg) );
702 main_PutIntVariable( INPUT_CHAPTER_VAR, atoi(optarg) );
705 main_PutIntVariable( INPUT_ANGLE_VAR, atoi(optarg) );
708 if ( ! strcmp(optarg, "ac3") )
709 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_AC3 );
710 else if ( ! strcmp(optarg, "lpcm") )
711 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_LPCM );
712 else if ( ! strcmp(optarg, "mpeg") )
713 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_MPEG );
715 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_NOAUDIO );
718 main_PutIntVariable( INPUT_CHANNEL_VAR, atoi(optarg) );
721 main_PutIntVariable( INPUT_SUBTITLE_VAR, atoi(optarg) );
725 case OPT_INPUT: /* --input */
726 main_PutPszVariable( INPUT_METHOD_VAR, optarg );
728 case OPT_CHANNELS: /* --channels */
729 main_PutIntVariable( INPUT_NETWORK_CHANNEL_VAR, 1 );
731 case OPT_SERVER: /* --server */
732 main_PutPszVariable( INPUT_SERVER_VAR, optarg );
734 case OPT_PORT: /* --port */
735 main_PutPszVariable( INPUT_PORT_VAR, optarg );
737 case OPT_BROADCAST: /* --broadcast */
738 main_PutIntVariable( INPUT_BROADCAST_VAR, 1 );
739 main_PutPszVariable( INPUT_BCAST_ADDR_VAR, optarg );
742 /* Synchro options */
744 main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
747 /* Internal error: unknown option */
752 intf_ErrMsg( "intf error: unknown option `%s'",
753 ppsz_argv[optind - 1] );
755 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
756 if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
757 INTF_STDOUT_DEFAULT ) ) == 0 )
759 /* No stdout redirection has been asked for */
760 intf_MsgImm( "\nPress the RETURN key to continue..." );
769 if( p_main->i_warning_level < 0 )
771 p_main->i_warning_level = 0;
777 /*****************************************************************************
778 * GetFilenames: parse command line options which are not flags
779 *****************************************************************************
780 * Parse command line for input files.
781 *****************************************************************************/
782 static int GetFilenames( int i_argc, char *ppsz_argv[] )
786 /* We assume that the remaining parameters are filenames */
787 for( i_opt = optind; i_opt < i_argc; i_opt++ )
789 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
790 ppsz_argv[ i_opt ] );
796 /*****************************************************************************
797 * Usage: print program usage
798 *****************************************************************************
799 * Print a short inline help. Message interface is initialized at this stage.
800 *****************************************************************************/
801 static void Usage( int i_fashion )
804 intf_MsgImm( "Usage: %s [options] [parameters] [file]...",
807 if( i_fashion == USAGE )
809 intf_MsgImm( "Try `%s --help' for more information.",
815 intf_MsgImm( "\nOptions:"
816 "\n -I, --intf <module> \tinterface method"
817 "\n -v, --verbose \tverbose mode (cumulative)"
818 "\n --stdout <filename> \tredirect console stdout"
820 "\n --noaudio \tdisable audio"
821 "\n -A, --aout <module> \taudio output method"
822 "\n --stereo, --mono \tstereo/mono audio"
823 "\n --spdif \tAC3 pass-through mode"
824 "\n --downmix <module> \tAC3 downmix method"
825 "\n --imdct <module> \tAC3 IMDCT method"
827 "\n --novideo \tdisable video"
828 "\n -V, --vout <module> \tvideo output method"
829 "\n --display <display> \tdisplay string"
830 "\n --width <w>, --height <h> \tdisplay dimensions"
831 "\n -g, --grayscale \tgrayscale output"
832 "\n --fullscreen \tfullscreen output"
833 "\n --overlay \taccelerated display"
834 "\n --color \tcolor output"
835 "\n --motion <module> \tmotion compensation method"
836 "\n --idct <module> \tIDCT method"
837 "\n --yuv <module> \tYUV method"
838 "\n --synchro <type> \tforce synchro algorithm"
840 "\n -t, --dvdtitle <num> \tchoose DVD title"
841 "\n -T, --dvdchapter <num> \tchoose DVD chapter"
842 "\n -u, --dvdangle <num> \tchoose DVD angle"
843 "\n -a, --dvdaudio <type> \tchoose DVD audio type"
844 "\n -c, --dvdchannel <channel> \tchoose DVD audio channel"
845 "\n -s, --dvdsubtitle <channel> \tchoose DVD subtitle channel"
847 "\n --input \tinput method"
848 "\n --channels \tenable channels"
849 "\n --server <host> \tvideo server address"
850 "\n --port <port> \tvideo server port"
851 "\n --broadcast \tlisten to a broadcast"
853 "\n -h, --help \tprint help and exit"
854 "\n -H, --longhelp \tprint long help and exit"
855 "\n --version \toutput version information and exit" );
857 if( i_fashion == SHORT_HELP )
860 /* Interface parameters */
861 intf_MsgImm( "\nInterface parameters:"
862 "\n " INTF_METHOD_VAR "=<method name> \tinterface method"
863 "\n " INTF_INIT_SCRIPT_VAR "=<filename> \tinitialization script"
864 "\n " INTF_CHANNELS_VAR "=<filename> \tchannels list"
865 "\n " INTF_STDOUT_VAR "=<filename> \tredirect console stdout" );
867 /* Audio parameters */
868 intf_MsgImm( "\nAudio parameters:"
869 "\n " AOUT_METHOD_VAR "=<method name> \taudio method"
870 "\n " AOUT_DSP_VAR "=<filename> \tdsp device path"
871 "\n " AOUT_STEREO_VAR "={1|0} \tstereo or mono output"
872 "\n " AOUT_SPDIF_VAR "={1|0} \tAC3 pass-through mode"
873 "\n " DOWNMIX_METHOD_VAR "=<method name> \tAC3 downmix method"
874 "\n " IMDCT_METHOD_VAR "=<method name> \tAC3 IMDCT method"
875 "\n " AOUT_RATE_VAR "=<rate> \toutput rate" );
877 /* Video parameters */
878 intf_MsgImm( "\nVideo parameters:"
879 "\n " VOUT_METHOD_VAR "=<method name> \tdisplay method"
880 "\n " VOUT_DISPLAY_VAR "=<display name> \tdisplay used"
881 "\n " VOUT_WIDTH_VAR "=<width> \tdisplay width"
882 "\n " VOUT_HEIGHT_VAR "=<height> \tdislay height"
883 "\n " VOUT_FB_DEV_VAR "=<filename> \tframebuffer device path"
884 "\n " VOUT_GRAYSCALE_VAR "={1|0} \tgrayscale or color output"
885 "\n " VOUT_FULLSCREEN_VAR "={1|0} \tfullscreen"
886 "\n " VOUT_OVERLAY_VAR "={1|0} \toverlay"
887 "\n " MOTION_METHOD_VAR "=<method name> \tmotion compensation method"
888 "\n " IDCT_METHOD_VAR "=<method name> \tIDCT method"
889 "\n " YUV_METHOD_VAR "=<method name> \tYUV method"
890 "\n " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB} \tsynchro algorithm" );
893 intf_MsgImm( "\nDVD parameters:"
894 "\n " INPUT_DVD_DEVICE_VAR "=<device> \tDVD device"
895 "\n " INPUT_TITLE_VAR "=<title> \ttitle number"
896 "\n " INPUT_CHAPTER_VAR "=<chapter> \tchapter number"
897 "\n " INPUT_ANGLE_VAR "=<angle> \tangle number"
898 "\n " INPUT_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type"
899 "\n " INPUT_CHANNEL_VAR "=[0-15] \taudio channel"
900 "\n " INPUT_SUBTITLE_VAR "=[0-31] \tsubtitle channel" );
902 /* Input parameters */
903 intf_MsgImm( "\nInput parameters:"
904 "\n " INPUT_SERVER_VAR "=<hostname> \tvideo server"
905 "\n " INPUT_PORT_VAR "=<port> \tvideo server port"
906 "\n " INPUT_IFACE_VAR "=<interface> \tnetwork interface"
907 "\n " INPUT_BCAST_ADDR_VAR "=<addr> \tbroadcast mode"
908 "\n " INPUT_CHANNEL_SERVER_VAR "=<hostname> \tchannel server"
909 "\n " INPUT_CHANNEL_PORT_VAR "=<port> \tchannel server port" );
913 /*****************************************************************************
914 * Version: print complete program version
915 *****************************************************************************
916 * Print complete program version and build number.
917 *****************************************************************************/
918 static void Version( void )
920 intf_MsgImm( VERSION_MESSAGE
921 "This program comes with NO WARRANTY, to the extent permitted by law.\n"
922 "You may redistribute it under the terms of the GNU General Public License;\n"
923 "see the file named COPYING for details.\n"
924 "Written by the VideoLAN team at Ecole Centrale, Paris." );
927 /*****************************************************************************
928 * InitSignalHandler: system signal handler initialization
929 *****************************************************************************
930 * Set the signal handlers. SIGTERM is not intercepted, because we need at
931 * at least a method to kill the program when all other methods failed, and
932 * when we don't want to use SIGKILL.
933 *****************************************************************************/
934 static void InitSignalHandler( void )
936 /* Termination signals */
938 signal( SIGINT, FatalSignalHandler );
939 signal( SIGHUP, FatalSignalHandler );
940 signal( SIGQUIT, FatalSignalHandler );
943 signal( SIGALRM, SimpleSignalHandler );
944 signal( SIGPIPE, SimpleSignalHandler );
949 /*****************************************************************************
950 * SimpleSignalHandler: system signal handler
951 *****************************************************************************
952 * This function is called when a non fatal signal is received by the program.
953 *****************************************************************************/
954 static void SimpleSignalHandler( int i_signal )
956 /* Acknowledge the signal received */
957 intf_WarnMsg( 0, "intf: ignoring signal %d", i_signal );
961 /*****************************************************************************
962 * FatalSignalHandler: system signal handler
963 *****************************************************************************
964 * This function is called when a fatal signal is received by the program.
965 * It tries to end the program in a clean way.
966 *****************************************************************************/
967 static void FatalSignalHandler( int i_signal )
969 /* Once a signal has been trapped, the termination sequence will be
970 * armed and following signals will be ignored to avoid sending messages
971 * to an interface having been destroyed */
973 signal( SIGINT, SIG_IGN );
974 signal( SIGHUP, SIG_IGN );
975 signal( SIGQUIT, SIG_IGN );
978 /* Acknowledge the signal received */
979 intf_ErrMsgImm( "intf error: signal %d received, exiting", i_signal );
981 /* Try to terminate everything - this is done by requesting the end of the
982 * interface thread */
983 p_main->p_intf->b_die = 1;
986 /*****************************************************************************
987 * InstructionSignalHandler: system signal handler
988 *****************************************************************************
989 * This function is called when a illegal instruction signal is received by
991 * We use this function to test OS and CPU_Capabilities
992 *****************************************************************************/
993 static void InstructionSignalHandler( int i_signal )
995 /* Once a signal has been trapped, the termination sequence will be
996 * armed and following signals will be ignored to avoid sending messages
997 * to an interface having been destroyed */
999 /* Acknowledge the signal received */
1000 fprintf( stderr, "illegal instruction : optimization disabled\n" );
1004 #ifdef HAVE_SIGRELSE
1005 sigrelse( i_signal );
1010 /*****************************************************************************
1011 * CPUCapabilities: list the processors MMX support and other capabilities
1012 *****************************************************************************
1013 * This function is called to list extensions the CPU may have.
1014 *****************************************************************************/
1015 static int CPUCapabilities( void )
1017 volatile int i_capabilities = CPU_CAPABILITY_NONE;
1019 #if defined( SYS_BEOS )
1020 i_capabilities |= CPU_CAPABILITY_486
1021 | CPU_CAPABILITY_586
1022 | CPU_CAPABILITY_MMX;
1024 return( i_capabilities );
1026 #elif defined( SYS_DARWIN )
1027 struct host_basic_info hi;
1029 host_name_port_t host;
1032 char *psz_name, *psz_subname;
1034 /* Should 'never' fail? */
1035 host = mach_host_self();
1037 i_size = sizeof( hi ) / sizeof( int );
1038 ret = host_info( host, HOST_BASIC_INFO, ( host_info_t )&hi, &i_size );
1040 if( ret != KERN_SUCCESS )
1042 intf_ErrMsg( "error: couldn't get CPU information" );
1043 return( i_capabilities );
1046 slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
1047 /* FIXME: need better way to detect newer proccessors.
1048 * could do strncmp(a,b,5), but that's real ugly */
1049 if( strcmp(psz_name, "ppc7400") || strcmp(psz_name, "ppc7450") )
1051 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
1054 return( i_capabilities );
1056 #elif defined( __i386__ )
1057 volatile unsigned int i_eax, i_ebx, i_ecx, i_edx;
1058 volatile boolean_t b_amd;
1060 signal( SIGILL, InstructionSignalHandler );
1062 /* test for a 486 CPU */
1063 asm volatile ( "pushfl\n\t"
1065 "movl %%eax, %%ebx\n\t"
1066 "xorl $0x200000, %%eax\n\t"
1076 if( i_eax == i_ebx )
1078 signal( SIGILL, NULL );
1079 return( i_capabilities );
1082 i_capabilities |= CPU_CAPABILITY_486;
1084 /* the CPU supports the CPUID instruction - get its level */
1085 cpuid( 0x00000000 );
1089 signal( SIGILL, NULL );
1090 return( i_capabilities );
1093 /* FIXME: this isn't correct, since some 486s have cpuid */
1094 i_capabilities |= CPU_CAPABILITY_586;
1096 /* borrowed from mpeg2dec */
1097 b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
1098 && ( i_edx == 0x69746e65 );
1100 /* test for the MMX flag */
1101 cpuid( 0x00000001 );
1103 if( ! (i_edx & 0x00800000) )
1105 signal( SIGILL, NULL );
1106 return( i_capabilities );
1109 i_capabilities |= CPU_CAPABILITY_MMX;
1111 if( i_edx & 0x02000000 )
1113 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1115 /* We test if OS support the SSE instructions */
1117 if( setjmp( env ) == 0 )
1119 /* Test a SSE instruction */
1120 __asm__ __volatile__ ( "xorps %%xmm0,%%xmm0\n" : : );
1123 if( i_illegal == 0 )
1125 i_capabilities |= CPU_CAPABILITY_SSE;
1129 /* test for additional capabilities */
1130 cpuid( 0x80000000 );
1132 if( i_eax < 0x80000001 )
1134 signal( SIGILL, NULL );
1135 return( i_capabilities );
1138 /* list these additional capabilities */
1139 cpuid( 0x80000001 );
1141 if( i_edx & 0x80000000 )
1144 if( setjmp( env ) == 0 )
1146 /* Test a 3D Now! instruction */
1147 __asm__ __volatile__ ( "pfadd %%mm0,%%mm0\n" "femms\n" : : );
1150 if( i_illegal == 0 )
1152 i_capabilities |= CPU_CAPABILITY_3DNOW;
1156 if( b_amd && ( i_edx & 0x00400000 ) )
1158 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1161 signal( SIGILL, NULL );
1162 return( i_capabilities );
1165 /* default behaviour */
1166 return( i_capabilities );
1171 /*****************************************************************************
1172 * RedirectSTDOUT: redirect stdout and stderr to a file
1173 *****************************************************************************
1174 * This function will redirect stdout and stderr to a file if the user has
1176 *****************************************************************************/
1177 static int RedirectSTDOUT( void )
1179 int i_stdout_filedesc;
1180 char *psz_stdout_filename;
1182 psz_stdout_filename = main_GetPszVariable( INTF_STDOUT_VAR,
1183 INTF_STDOUT_DEFAULT );
1184 if( strcmp( "", psz_stdout_filename ) != 0 )
1187 i_stdout_filedesc = open( psz_stdout_filename,
1188 O_CREAT | O_TRUNC | O_RDWR,
1189 S_IREAD | S_IWRITE );
1190 if( dup2( i_stdout_filedesc, fileno(stdout) ) == -1 )
1191 intf_ErrMsg("Unable to redirect stdout!\n");
1192 if( dup2( i_stdout_filedesc, fileno(stderr) ) == -1 )
1193 intf_ErrMsg("Unable to redirect stderr!\n");
1194 close( i_stdout_filedesc );
1198 /* No stdout redirection has been asked so open a console */
1199 if( p_main->i_warning_level )
1209 /*****************************************************************************
1210 * ShowConsole: On Win32, create an output console for debug messages
1211 *****************************************************************************
1212 * This function is usefull only on Win32.
1213 *****************************************************************************/
1214 static void ShowConsole( void )
1218 freopen( "CONOUT$", "w", stdout );
1219 freopen( "CONOUT$", "w", stderr );
1220 freopen( "CONIN$", "r", stdin );