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.113 2001/09/05 16:07:50 massiot 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 */
57 #elif defined( _MSC_VER ) && defined( _WIN32 )
61 #include <errno.h> /* ENOMEM */
62 #include <stdlib.h> /* getenv(), strtol(), */
63 #include <string.h> /* strerror() */
64 #include <fcntl.h> /* open(), O_WRONLY */
65 #include <sys/stat.h> /* S_IREAD */
72 #include "tests.h" /* TestCPU() */
75 #include "stream_control.h"
76 #include "input_ext-intf.h"
79 #include "intf_playlist.h"
80 #include "interface.h"
82 #include "audio_output.h"
85 #include "video_output.h"
88 # include "beos_specific.h"
92 # include "darwin_specific.h"
95 #include "netutils.h" /* network_ChannelJoin */
99 /*****************************************************************************
100 * Command line options constants. If something is changed here, be sure that
101 * GetConfiguration and Usage are also changed.
102 *****************************************************************************/
104 /* Long options return values - note that values corresponding to short options
105 * chars, and in general any regular char, should be avoided */
106 #define OPT_NOAUDIO 150
107 #define OPT_STEREO 151
109 #define OPT_SPDIF 153
111 #define OPT_NOVIDEO 160
112 #define OPT_DISPLAY 161
113 #define OPT_WIDTH 162
114 #define OPT_HEIGHT 163
115 #define OPT_COLOR 164
116 #define OPT_FULLSCREEN 165
117 #define OPT_OVERLAY 166
118 #define OPT_XVADAPTOR 167
121 #define OPT_CHANNELS 170
122 #define OPT_SERVER 171
124 #define OPT_BROADCAST 173
126 #define OPT_INPUT 180
127 #define OPT_MOTION 181
130 #define OPT_DOWNMIX 184
131 #define OPT_IMDCT 185
133 #define OPT_SYNCHRO 190
134 #define OPT_WARNING 191
135 #define OPT_VERSION 192
136 #define OPT_STDOUT 193
143 /* Needed for x86 CPU capabilities detection */
145 asm volatile ( "cpuid" \
154 static const struct option longopts[] =
156 /* name, has_arg, flag, val */
158 /* General/common options */
159 { "help", 0, 0, 'h' },
160 { "longhelp", 0, 0, 'H' },
161 { "version", 0, 0, OPT_VERSION },
163 /* Interface options */
164 { "intf", 1, 0, 'I' },
165 { "warning", 1, 0, OPT_WARNING },
166 { "stdout", 1, 0, OPT_STDOUT },
169 { "noaudio", 0, 0, OPT_NOAUDIO },
170 { "aout", 1, 0, 'A' },
171 { "stereo", 0, 0, OPT_STEREO },
172 { "mono", 0, 0, OPT_MONO },
173 { "spdif", 0, 0, OPT_SPDIF },
174 { "downmix", 1, 0, OPT_DOWNMIX },
175 { "imdct", 1, 0, OPT_IMDCT },
178 { "novideo", 0, 0, OPT_NOVIDEO },
179 { "vout", 1, 0, 'V' },
180 { "display", 1, 0, OPT_DISPLAY },
181 { "width", 1, 0, OPT_WIDTH },
182 { "height", 1, 0, OPT_HEIGHT },
183 { "grayscale", 0, 0, 'g' },
184 { "color", 0, 0, OPT_COLOR },
185 { "motion", 1, 0, OPT_MOTION },
186 { "idct", 1, 0, OPT_IDCT },
187 { "yuv", 1, 0, OPT_YUV },
188 { "fullscreen", 0, 0, OPT_FULLSCREEN },
189 { "overlay", 0, 0, OPT_OVERLAY },
190 { "xvadaptor", 1, 0, OPT_XVADAPTOR },
191 { "smp", 1, 0, OPT_SMP },
194 { "dvdtitle", 1, 0, 't' },
195 { "dvdchapter", 1, 0, 'T' },
196 { "dvdangle", 1, 0, 'u' },
197 { "dvdaudio", 1, 0, 'a' },
198 { "dvdchannel", 1, 0, 'c' },
199 { "dvdsubtitle", 1, 0, 's' },
202 { "input", 1, 0, OPT_INPUT },
203 { "server", 1, 0, OPT_SERVER },
204 { "port", 1, 0, OPT_PORT },
205 { "broadcast", 1, 0, OPT_BROADCAST },
206 { "channels", 0, 0, OPT_CHANNELS },
208 /* Synchro options */
209 { "synchro", 1, 0, OPT_SYNCHRO },
214 static const char *psz_shortopts = "hHvgt:T:u:a:s:c:I:A:V:";
216 /*****************************************************************************
217 * Global variable program_data - these are the only ones, see main.h and
219 *****************************************************************************/
221 module_bank_t *p_module_bank;
222 aout_bank_t *p_aout_bank;
223 vout_bank_t *p_vout_bank;
225 /*****************************************************************************
227 *****************************************************************************/
228 static int GetConfiguration ( int *pi_argc, char *ppsz_argv[],
230 static int GetFilenames ( int i_argc, char *ppsz_argv[] );
231 static void Usage ( int i_fashion );
232 static void Version ( void );
234 static void InitSignalHandler ( void );
235 static void SimpleSignalHandler ( int i_signal );
236 static void FatalSignalHandler ( int i_signal );
237 static void InstructionSignalHandler( int i_signal );
238 static int CPUCapabilities ( void );
240 static int RedirectSTDOUT ( void );
241 static void ShowConsole ( void );
244 static int i_illegal;
246 /*****************************************************************************
247 * main: parse command line, start interface and spawn threads
248 *****************************************************************************
249 * Steps during program execution are:
250 * -configuration parsing and messages interface initialization
251 * -opening of audio output device and some global modules
252 * -execution of interface, which exit on error or on user request
253 * -closing of audio output device and some global modules
254 * On error, the spawned threads are canceled, and the open devices closed.
255 *****************************************************************************/
256 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
258 main_t main_data; /* root of all data - see main.h */
259 module_bank_t module_bank;
260 aout_bank_t aout_bank;
261 vout_bank_t vout_bank;
263 p_main = &main_data; /* set up the global variables */
264 p_module_bank = &module_bank;
265 p_aout_bank = &aout_bank;
266 p_vout_bank = &vout_bank;
269 * Initialize threads system
274 * Test if our code is likely to run on this CPU
276 p_main->i_cpu_capabilities = CPUCapabilities();
278 #if defined( __pentium__ ) || defined( __pentiumpro__ )
279 if( ! TestCPU( CPU_CAPABILITY_586 ) )
281 fprintf( stderr, "error: this program needs a Pentium CPU,\n"
282 "please try a version without Pentium support\n" );
288 * System specific initialization code
290 #if defined( SYS_BEOS ) || defined( SYS_DARWIN )
291 system_Init( &i_argc, ppsz_argv, ppsz_env );
292 #elif defined( WIN32 )
293 _fmode = _O_BINARY; /* sets the default file-translation mode on Win32 */
297 * Initialize messages interface
299 p_main->p_msg = intf_MsgCreate();
300 if( !p_main->p_msg ) /* start messages interface */
302 fprintf( stderr, "error: can't initialize messages interface (%s)\n",
307 intf_MsgImm( COPYRIGHT_MESSAGE );
312 if( GetConfiguration( &i_argc, ppsz_argv, ppsz_env ) ) /* parse cmd line */
319 * Redirect the standard output if required by the user, and on Win32 we
320 * also open a console to display the debug messages.
325 * Initialize playlist and get commandline files
327 p_main->p_playlist = intf_PlaylistCreate();
328 if( !p_main->p_playlist )
330 intf_ErrMsg( "playlist error: playlist initialization failed" );
334 intf_PlaylistInit( p_main->p_playlist );
337 * Get input filenames given as commandline arguments
339 GetFilenames( i_argc, ppsz_argv );
342 * Initialize module, aout and vout banks
349 * Initialize shared resources and libraries
351 if( main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
352 INPUT_NETWORK_CHANNEL_DEFAULT ) &&
353 network_ChannelCreate() )
355 /* On error during Channels initialization, switch off channels */
356 intf_Msg( "Channels initialization failed : "
357 "Channel management is deactivated" );
358 main_PutIntVariable( INPUT_NETWORK_CHANNEL_VAR, 0 );
362 * Try to run the interface
364 p_main->p_intf = intf_Create();
365 if( p_main->p_intf == NULL )
367 intf_ErrMsg( "intf error: interface initialization failed" );
372 * Set signal handling policy for all threads
377 * This is the main loop
379 p_main->p_intf->pf_run( p_main->p_intf );
382 * Finished, destroy the interface
384 intf_Destroy( p_main->p_intf );
387 * Go back into channel 0 which is the network
389 if( main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
390 INPUT_NETWORK_CHANNEL_DEFAULT ) )
392 network_ChannelJoin( COMMON_CHANNEL );
397 * Free module, aout and vout banks
406 intf_PlaylistDestroy( p_main->p_playlist );
409 * System specific cleaning code
411 #if defined( SYS_BEOS ) || defined( SYS_DARWIN )
417 * Terminate messages interface and program
419 intf_Msg( "intf: program terminated" );
423 * Stop threads system
430 /*****************************************************************************
431 * main_GetIntVariable: get the int value of an environment variable
432 *****************************************************************************
433 * This function is used to read some default parameters in modules.
434 *****************************************************************************/
435 int main_GetIntVariable( char *psz_name, int i_default )
437 char * psz_env; /* environment value */
438 char * psz_end; /* end of parsing index */
439 long int i_value; /* value */
441 psz_env = getenv( psz_name );
444 i_value = strtol( psz_env, &psz_end, 0 );
445 if( (*psz_env != '\0') && (*psz_end == '\0') )
453 /*****************************************************************************
454 * main_GetPszVariable: get the string value of an environment variable
455 *****************************************************************************
456 * This function is used to read some default parameters in modules.
457 *****************************************************************************/
458 char * main_GetPszVariable( char *psz_name, char *psz_default )
462 psz_env = getenv( psz_name );
467 return( psz_default );
470 /*****************************************************************************
471 * main_PutPszVariable: set the string value of an environment variable
472 *****************************************************************************
473 * This function is used to set some default parameters in modules. The use of
474 * this function will cause some memory leak: since some systems use the pointer
475 * passed to putenv to store the environment string, it can't be freed.
476 *****************************************************************************/
477 void main_PutPszVariable( char *psz_name, char *psz_value )
481 psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
482 if( psz_env == NULL )
484 intf_ErrMsg( "intf error: cannot create psz_env (%s)",
489 sprintf( psz_env, "%s=%s", psz_name, psz_value );
490 if( putenv( psz_env ) )
492 intf_ErrMsg( "intf error: cannot putenv (%s)", strerror(errno) );
497 /*****************************************************************************
498 * main_PutIntVariable: set the integer value of an environment variable
499 *****************************************************************************
500 * This function is used to set some default parameters in modules. The use of
501 * this function will cause some memory leak: since some systems use the pointer
502 * passed to putenv to store the environment string, it can't be freed.
503 *****************************************************************************/
504 void main_PutIntVariable( char *psz_name, int i_value )
506 char psz_value[ 256 ]; /* buffer for value */
508 sprintf( psz_value, "%d", i_value );
509 main_PutPszVariable( psz_name, psz_value );
512 /* following functions are local */
514 /*****************************************************************************
515 * GetConfiguration: parse command line
516 *****************************************************************************
517 * Parse command line and configuration file for configuration. If the inline
518 * help is requested, the function Usage() is called and the function returns
519 * -1 (causing main() to exit). The messages interface is initialized at this
520 * stage, but most structures are not allocated, so only environment should
522 *****************************************************************************/
523 static int GetConfiguration( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
528 /* Set default configuration and copy arguments */
529 p_main->i_argc = *pi_argc;
530 p_main->ppsz_argv = ppsz_argv;
531 p_main->ppsz_env = ppsz_env;
536 p_main->i_warning_level = 0;
538 p_main->p_channel = NULL;
540 /* Get the executable name (similar to the basename command) */
541 p_main->psz_arg0 = p_tmp = ppsz_argv[ 0 ];
546 p_main->psz_arg0 = ++p_tmp;
555 /* When vlc.app is run by double clicking in Mac OS X, the 2nd arg
556 * is the PSN - process serial number (a unique PID-ish thingie)
557 * still ok for real Darwin & when run from command line */
558 if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
559 /* for example -psn_0_9306113 */
561 /* GDMF!... I can't do this or else the MacOSX window server will
562 * not pick up the PSN and not register the app and we crash...
563 * hence the following kludge otherwise we'll get confused w/ argv[1]
564 * being an input file name */
566 ppsz_argv[ 1 ] = NULL;
568 *pi_argc = *pi_argc - 1;
574 /* Parse command line options */
576 while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv,
577 psz_shortopts, longopts, 0 ) ) != EOF )
581 /* General/common options */
582 case 'h': /* -h, --help */
586 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
587 if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
588 INTF_STDOUT_DEFAULT ) ) == 0 )
590 /* No stdout redirection has been asked for */
591 intf_MsgImm( "\nPress the RETURN key to continue..." );
597 case 'H': /* -H, --longhelp */
601 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
602 if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
603 INTF_STDOUT_DEFAULT ) ) == 0 )
605 /* No stdout redirection has been asked for */
606 intf_MsgImm( "\nPress the RETURN key to continue..." );
612 case OPT_VERSION: /* --version */
616 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
617 if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
618 INTF_STDOUT_DEFAULT ) ) == 0 )
620 /* No stdout redirection has been asked for */
621 intf_MsgImm( "\nPress the RETURN key to continue..." );
627 case 'v': /* -v, --verbose */
628 p_main->i_warning_level++;
631 /* Interface warning messages level */
632 case 'I': /* -I, --intf */
633 main_PutPszVariable( INTF_METHOD_VAR, optarg );
635 case OPT_WARNING: /* --warning */
636 intf_ErrMsg( "intf error: `--warning' is deprecated, use `-v'" );
637 p_main->i_warning_level = atoi(optarg);
640 case OPT_STDOUT: /* --stdout */
641 main_PutPszVariable( INTF_STDOUT_VAR, optarg );
645 case OPT_NOAUDIO: /* --noaudio */
648 case 'A': /* -A, --aout */
649 main_PutPszVariable( AOUT_METHOD_VAR, optarg );
651 case OPT_STEREO: /* --stereo */
652 main_PutIntVariable( AOUT_STEREO_VAR, 1 );
654 case OPT_MONO: /* --mono */
655 main_PutIntVariable( AOUT_STEREO_VAR, 0 );
657 case OPT_SPDIF: /* --spdif */
658 main_PutIntVariable( AOUT_SPDIF_VAR, 1 );
660 case OPT_DOWNMIX: /* --downmix */
661 main_PutPszVariable( DOWNMIX_METHOD_VAR, optarg );
663 case OPT_IMDCT: /* --imdct */
664 main_PutPszVariable( IMDCT_METHOD_VAR, optarg );
668 case OPT_NOVIDEO: /* --novideo */
671 case 'V': /* -V, --vout */
672 main_PutPszVariable( VOUT_METHOD_VAR, optarg );
674 case OPT_DISPLAY: /* --display */
675 main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
677 case OPT_WIDTH: /* --width */
678 main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
680 case OPT_HEIGHT: /* --height */
681 main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
683 case 'g': /* -g, --grayscale */
684 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
686 case OPT_COLOR: /* --color */
687 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
689 case OPT_FULLSCREEN: /* --fullscreen */
690 main_PutIntVariable( VOUT_FULLSCREEN_VAR, 1 );
692 case OPT_OVERLAY: /* --overlay */
693 main_PutIntVariable( VOUT_OVERLAY_VAR, 1 );
695 case OPT_XVADAPTOR: /* --xvadaptor */
696 main_PutIntVariable( VOUT_XVADAPTOR_VAR, atoi(optarg) );
698 case OPT_MOTION: /* --motion */
699 main_PutPszVariable( MOTION_METHOD_VAR, optarg );
701 case OPT_IDCT: /* --idct */
702 main_PutPszVariable( IDCT_METHOD_VAR, optarg );
704 case OPT_YUV: /* --yuv */
705 main_PutPszVariable( YUV_METHOD_VAR, optarg );
707 case OPT_SMP: /* --smp */
708 main_PutIntVariable( VDEC_SMP_VAR, atoi(optarg) );
713 main_PutIntVariable( INPUT_TITLE_VAR, atoi(optarg) );
716 main_PutIntVariable( INPUT_CHAPTER_VAR, atoi(optarg) );
719 main_PutIntVariable( INPUT_ANGLE_VAR, atoi(optarg) );
722 if ( ! strcmp(optarg, "ac3") )
723 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_AC3 );
724 else if ( ! strcmp(optarg, "lpcm") )
725 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_LPCM );
726 else if ( ! strcmp(optarg, "mpeg") )
727 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_MPEG );
729 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_NOAUDIO );
732 main_PutIntVariable( INPUT_CHANNEL_VAR, atoi(optarg) );
735 main_PutIntVariable( INPUT_SUBTITLE_VAR, atoi(optarg) );
739 case OPT_INPUT: /* --input */
740 main_PutPszVariable( INPUT_METHOD_VAR, optarg );
742 case OPT_CHANNELS: /* --channels */
743 main_PutIntVariable( INPUT_NETWORK_CHANNEL_VAR, 1 );
745 case OPT_SERVER: /* --server */
746 main_PutPszVariable( INPUT_SERVER_VAR, optarg );
748 case OPT_PORT: /* --port */
749 main_PutPszVariable( INPUT_PORT_VAR, optarg );
751 case OPT_BROADCAST: /* --broadcast */
752 main_PutIntVariable( INPUT_BROADCAST_VAR, 1 );
753 main_PutPszVariable( INPUT_BCAST_ADDR_VAR, optarg );
756 /* Synchro options */
758 main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
761 /* Internal error: unknown option */
766 intf_ErrMsg( "intf error: unknown option `%s'",
767 ppsz_argv[optind - 1] );
769 #ifdef WIN32 /* Pause the console because it's destroyed when we exit */
770 if( strcmp( "", main_GetPszVariable( INTF_STDOUT_VAR,
771 INTF_STDOUT_DEFAULT ) ) == 0 )
773 /* No stdout redirection has been asked for */
774 intf_MsgImm( "\nPress the RETURN key to continue..." );
783 if( p_main->i_warning_level < 0 )
785 p_main->i_warning_level = 0;
791 /*****************************************************************************
792 * GetFilenames: parse command line options which are not flags
793 *****************************************************************************
794 * Parse command line for input files.
795 *****************************************************************************/
796 static int GetFilenames( int i_argc, char *ppsz_argv[] )
800 /* We assume that the remaining parameters are filenames */
801 for( i_opt = optind; i_opt < i_argc; i_opt++ )
803 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
804 ppsz_argv[ i_opt ] );
810 /*****************************************************************************
811 * Usage: print program usage
812 *****************************************************************************
813 * Print a short inline help. Message interface is initialized at this stage.
814 *****************************************************************************/
815 static void Usage( int i_fashion )
818 intf_MsgImm( "Usage: %s [options] [parameters] [file]...",
821 if( i_fashion == USAGE )
823 intf_MsgImm( "Try `%s --help' for more information.",
829 intf_MsgImm( "\nOptions:"
830 "\n -I, --intf <module> \tinterface method"
831 "\n -v, --verbose \tverbose mode (cumulative)"
832 "\n --stdout <filename> \tredirect console stdout"
834 "\n --noaudio \tdisable audio"
835 "\n -A, --aout <module> \taudio output method"
836 "\n --stereo, --mono \tstereo/mono audio"
837 "\n --spdif \tAC3 pass-through mode"
838 "\n --downmix <module> \tAC3 downmix method"
839 "\n --imdct <module> \tAC3 IMDCT method"
841 "\n --novideo \tdisable video"
842 "\n -V, --vout <module> \tvideo output method"
843 "\n --display <display> \tdisplay string"
844 "\n --width <w>, --height <h> \tdisplay dimensions"
845 "\n -g, --grayscale \tgrayscale output"
846 "\n --fullscreen \tfullscreen output"
847 "\n --overlay \taccelerated display"
848 "\n --xvadaptor <adaptor> \tXVideo adaptor"
849 "\n --color \tcolor output"
850 "\n --motion <module> \tmotion compensation method"
851 "\n --idct <module> \tIDCT method"
852 "\n --yuv <module> \tYUV method"
853 "\n --synchro <type> \tforce synchro algorithm"
854 "\n --smp <number of threads> \tuse several processors"
856 "\n -t, --dvdtitle <num> \tchoose DVD title"
857 "\n -T, --dvdchapter <num> \tchoose DVD chapter"
858 "\n -u, --dvdangle <num> \tchoose DVD angle"
859 "\n -a, --dvdaudio <type> \tchoose DVD audio type"
860 "\n -c, --dvdchannel <channel> \tchoose DVD audio channel"
861 "\n -s, --dvdsubtitle <channel> \tchoose DVD subtitle channel"
863 "\n --input \tinput method"
864 "\n --channels \tenable channels"
865 "\n --server <host> \tvideo server address"
866 "\n --port <port> \tvideo server port"
867 "\n --broadcast \tlisten to a broadcast"
869 "\n -h, --help \tprint help and exit"
870 "\n -H, --longhelp \tprint long help and exit"
871 "\n --version \toutput version information and exit" );
873 if( i_fashion == SHORT_HELP )
876 /* Interface parameters */
877 intf_MsgImm( "\nInterface parameters:"
878 "\n " INTF_METHOD_VAR "=<method name> \tinterface method"
879 "\n " INTF_INIT_SCRIPT_VAR "=<filename> \tinitialization script"
880 "\n " INTF_CHANNELS_VAR "=<filename> \tchannels list"
881 "\n " INTF_STDOUT_VAR "=<filename> \tredirect console stdout" );
883 /* Audio parameters */
884 intf_MsgImm( "\nAudio parameters:"
885 "\n " AOUT_METHOD_VAR "=<method name> \taudio method"
886 "\n " AOUT_DSP_VAR "=<filename> \tdsp device path"
887 "\n " AOUT_STEREO_VAR "={1|0} \tstereo or mono output"
888 "\n " AOUT_SPDIF_VAR "={1|0} \tAC3 pass-through mode"
889 "\n " DOWNMIX_METHOD_VAR "=<method name> \tAC3 downmix method"
890 "\n " IMDCT_METHOD_VAR "=<method name> \tAC3 IMDCT method"
891 "\n " AOUT_RATE_VAR "=<rate> \toutput rate" );
893 /* Video parameters */
894 intf_MsgImm( "\nVideo parameters:"
895 "\n " VOUT_METHOD_VAR "=<method name> \tdisplay method"
896 "\n " VOUT_DISPLAY_VAR "=<display name> \tdisplay used"
897 "\n " VOUT_WIDTH_VAR "=<width> \tdisplay width"
898 "\n " VOUT_HEIGHT_VAR "=<height> \tdislay height"
899 "\n " VOUT_FB_DEV_VAR "=<filename> \tframebuffer device path"
900 "\n " VOUT_GRAYSCALE_VAR "={1|0} \tgrayscale or color output"
901 "\n " VOUT_FULLSCREEN_VAR "={1|0} \tfullscreen"
902 "\n " VOUT_OVERLAY_VAR "={1|0} \toverlay"
903 "\n " VOUT_XVADAPTOR_VAR "=<adaptor> \tXVideo adaptor"
904 "\n " MOTION_METHOD_VAR "=<method name> \tmotion compensation method"
905 "\n " IDCT_METHOD_VAR "=<method name> \tIDCT method"
906 "\n " YUV_METHOD_VAR "=<method name> \tYUV method"
907 "\n " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB} \tsynchro algorithm"
908 "\n " VDEC_SMP_VAR "=<number of threads> \tuse several processors" );
911 intf_MsgImm( "\nDVD parameters:"
912 "\n " INPUT_DVD_DEVICE_VAR "=<device> \tDVD device"
913 "\n " INPUT_TITLE_VAR "=<title> \ttitle number"
914 "\n " INPUT_CHAPTER_VAR "=<chapter> \tchapter number"
915 "\n " INPUT_ANGLE_VAR "=<angle> \tangle number"
916 "\n " INPUT_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type"
917 "\n " INPUT_CHANNEL_VAR "=[0-15] \taudio channel"
918 "\n " INPUT_SUBTITLE_VAR "=[0-31] \tsubtitle channel" );
920 /* Input parameters */
921 intf_MsgImm( "\nInput parameters:"
922 "\n " INPUT_SERVER_VAR "=<hostname> \tvideo server"
923 "\n " INPUT_PORT_VAR "=<port> \tvideo server port"
924 "\n " INPUT_IFACE_VAR "=<interface> \tnetwork interface"
925 "\n " INPUT_BCAST_ADDR_VAR "=<addr> \tbroadcast mode"
926 "\n " INPUT_CHANNEL_SERVER_VAR "=<hostname> \tchannel server"
927 "\n " INPUT_CHANNEL_PORT_VAR "=<port> \tchannel server port" );
931 /*****************************************************************************
932 * Version: print complete program version
933 *****************************************************************************
934 * Print complete program version and build number.
935 *****************************************************************************/
936 static void Version( void )
938 intf_MsgImm( VERSION_MESSAGE
939 "This program comes with NO WARRANTY, to the extent permitted by law.\n"
940 "You may redistribute it under the terms of the GNU General Public License;\n"
941 "see the file named COPYING for details.\n"
942 "Written by the VideoLAN team at Ecole Centrale, Paris." );
945 /*****************************************************************************
946 * InitSignalHandler: system signal handler initialization
947 *****************************************************************************
948 * Set the signal handlers. SIGTERM is not intercepted, because we need at
949 * at least a method to kill the program when all other methods failed, and
950 * when we don't want to use SIGKILL.
951 *****************************************************************************/
952 static void InitSignalHandler( void )
954 /* Termination signals */
956 signal( SIGINT, FatalSignalHandler );
957 signal( SIGHUP, FatalSignalHandler );
958 signal( SIGQUIT, FatalSignalHandler );
961 signal( SIGALRM, SimpleSignalHandler );
962 signal( SIGPIPE, SimpleSignalHandler );
967 /*****************************************************************************
968 * SimpleSignalHandler: system signal handler
969 *****************************************************************************
970 * This function is called when a non fatal signal is received by the program.
971 *****************************************************************************/
972 static void SimpleSignalHandler( int i_signal )
974 /* Acknowledge the signal received */
975 intf_WarnMsg( 0, "intf: ignoring signal %d", i_signal );
979 /*****************************************************************************
980 * FatalSignalHandler: system signal handler
981 *****************************************************************************
982 * This function is called when a fatal signal is received by the program.
983 * It tries to end the program in a clean way.
984 *****************************************************************************/
985 static void FatalSignalHandler( int i_signal )
987 /* Once a signal has been trapped, the termination sequence will be
988 * armed and following signals will be ignored to avoid sending messages
989 * to an interface having been destroyed */
991 signal( SIGINT, SIG_IGN );
992 signal( SIGHUP, SIG_IGN );
993 signal( SIGQUIT, SIG_IGN );
996 /* Acknowledge the signal received */
997 intf_ErrMsgImm( "intf error: signal %d received, exiting", i_signal );
999 /* Try to terminate everything - this is done by requesting the end of the
1000 * interface thread */
1001 p_main->p_intf->b_die = 1;
1004 /*****************************************************************************
1005 * InstructionSignalHandler: system signal handler
1006 *****************************************************************************
1007 * This function is called when a illegal instruction signal is received by
1009 * We use this function to test OS and CPU_Capabilities
1010 *****************************************************************************/
1011 static void InstructionSignalHandler( int i_signal )
1013 /* Once a signal has been trapped, the termination sequence will be
1014 * armed and following signals will be ignored to avoid sending messages
1015 * to an interface having been destroyed */
1017 /* Acknowledge the signal received */
1018 fprintf( stderr, "warning: extended instructions unsupported, "
1019 "some optimizations will be disabled\n" );
1021 fprintf( stderr, "upgrade to kernel 2.4.x to get rid of this warning\n" );
1026 #ifdef HAVE_SIGRELSE
1027 sigrelse( i_signal );
1032 /*****************************************************************************
1033 * CPUCapabilities: list the processors MMX support and other capabilities
1034 *****************************************************************************
1035 * This function is called to list extensions the CPU may have.
1036 *****************************************************************************/
1037 static int CPUCapabilities( void )
1039 volatile int i_capabilities = CPU_CAPABILITY_NONE;
1041 #if defined( SYS_BEOS )
1042 i_capabilities |= CPU_CAPABILITY_486
1043 | CPU_CAPABILITY_586
1044 | CPU_CAPABILITY_MMX;
1046 return( i_capabilities );
1048 #elif defined( SYS_DARWIN )
1049 struct host_basic_info hi;
1051 host_name_port_t host;
1054 char *psz_name, *psz_subname;
1056 /* Should 'never' fail? */
1057 host = mach_host_self();
1059 i_size = sizeof( hi ) / sizeof( int );
1060 ret = host_info( host, HOST_BASIC_INFO, ( host_info_t )&hi, &i_size );
1062 if( ret != KERN_SUCCESS )
1064 fprintf( stderr, "error: couldn't get CPU information\n" );
1065 return( i_capabilities );
1068 slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
1069 /* FIXME: need better way to detect newer proccessors.
1070 * could do strncmp(a,b,5), but that's real ugly */
1071 if( !strcmp(psz_name, "ppc7400") || !strcmp(psz_name, "ppc7450") )
1073 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
1076 return( i_capabilities );
1078 #elif defined( __i386__ )
1079 volatile unsigned int i_eax, i_ebx, i_ecx, i_edx;
1080 volatile boolean_t b_amd;
1082 signal( SIGILL, InstructionSignalHandler );
1084 /* test for a 486 CPU */
1085 asm volatile ( "pushfl\n\t"
1087 "movl %%eax, %%ebx\n\t"
1088 "xorl $0x200000, %%eax\n\t"
1098 if( i_eax == i_ebx )
1100 signal( SIGILL, NULL );
1101 return( i_capabilities );
1104 i_capabilities |= CPU_CAPABILITY_486;
1106 /* the CPU supports the CPUID instruction - get its level */
1107 cpuid( 0x00000000 );
1111 signal( SIGILL, NULL );
1112 return( i_capabilities );
1115 /* FIXME: this isn't correct, since some 486s have cpuid */
1116 i_capabilities |= CPU_CAPABILITY_586;
1118 /* borrowed from mpeg2dec */
1119 b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
1120 && ( i_edx == 0x69746e65 );
1122 /* test for the MMX flag */
1123 cpuid( 0x00000001 );
1125 if( ! (i_edx & 0x00800000) )
1127 signal( SIGILL, NULL );
1128 return( i_capabilities );
1131 i_capabilities |= CPU_CAPABILITY_MMX;
1133 if( i_edx & 0x02000000 )
1135 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1137 /* We test if OS support the SSE instructions */
1139 if( setjmp( env ) == 0 )
1141 /* Test a SSE instruction */
1142 __asm__ __volatile__ ( "xorps %%xmm0,%%xmm0\n" : : );
1145 if( i_illegal == 0 )
1147 i_capabilities |= CPU_CAPABILITY_SSE;
1151 /* test for additional capabilities */
1152 cpuid( 0x80000000 );
1154 if( i_eax < 0x80000001 )
1156 signal( SIGILL, NULL );
1157 return( i_capabilities );
1160 /* list these additional capabilities */
1161 cpuid( 0x80000001 );
1163 if( i_edx & 0x80000000 )
1166 if( setjmp( env ) == 0 )
1168 /* Test a 3D Now! instruction */
1169 __asm__ __volatile__ ( "pfadd %%mm0,%%mm0\n" "femms\n" : : );
1172 if( i_illegal == 0 )
1174 i_capabilities |= CPU_CAPABILITY_3DNOW;
1178 if( b_amd && ( i_edx & 0x00400000 ) )
1180 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1183 signal( SIGILL, NULL );
1184 return( i_capabilities );
1186 #elif defined( __powerpc__ )
1187 # if defined( vector )
1188 /* Test for Altivec */
1189 signal( SIGILL, InstructionSignalHandler );
1192 if( setjmp( env ) == 0 )
1195 vec_mtvscr( (vector unsigned int)(0) );
1196 /* Set the VRSAVE register in case the kernel looks at it */
1197 asm volatile ("mtspr 256,%0" : : "r" (-1));
1200 if( i_illegal == 0 )
1202 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
1205 signal( SIGILL, NULL );
1208 return( i_capabilities );
1211 /* default behaviour */
1212 return( i_capabilities );
1217 /*****************************************************************************
1218 * RedirectSTDOUT: redirect stdout and stderr to a file
1219 *****************************************************************************
1220 * This function will redirect stdout and stderr to a file if the user has
1222 *****************************************************************************/
1223 static int RedirectSTDOUT( void )
1225 int i_stdout_filedesc;
1226 char *psz_stdout_filename;
1228 psz_stdout_filename = main_GetPszVariable( INTF_STDOUT_VAR,
1229 INTF_STDOUT_DEFAULT );
1230 if( strcmp( "", psz_stdout_filename ) != 0 )
1233 i_stdout_filedesc = open( psz_stdout_filename,
1234 O_CREAT | O_TRUNC | O_RDWR,
1235 S_IREAD | S_IWRITE );
1237 if( dup2( i_stdout_filedesc, fileno(stdout) ) == -1 )
1239 intf_ErrMsg( "warning: unable to redirect stdout" );
1242 if( dup2( i_stdout_filedesc, fileno(stderr) ) == -1 )
1244 intf_ErrMsg( "warning: unable to redirect stderr" );
1247 close( i_stdout_filedesc );
1251 /* No stdout redirection has been asked so open a console */
1252 if( p_main->i_warning_level )
1262 /*****************************************************************************
1263 * ShowConsole: On Win32, create an output console for debug messages
1264 *****************************************************************************
1265 * This function is usefull only on Win32.
1266 *****************************************************************************/
1267 static void ShowConsole( void )
1271 freopen( "CONOUT$", "w", stdout );
1272 freopen( "CONOUT$", "w", stderr );
1273 freopen( "CONIN$", "r", stdin );