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.96 2001/05/15 19:36:27 sam 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() */
35 #ifdef HAVE_GETOPT_LONG
37 # include <getopt.h> /* getopt() */
40 # include "GNUgetopt/getopt.h"
44 # include <mach/mach.h> /* Altivec detection */
45 # include <mach/mach_error.h> /* some day the header files||compiler *
46 will define it for us */
47 # include <mach/bootstrap.h>
51 #include <netinet/in.h> /* BSD: struct in_addr */
55 #include <errno.h> /* ENOMEM */
56 #include <stdlib.h> /* getenv(), strtol(), */
57 #include <string.h> /* strerror() */
64 #include "tests.h" /* TestCPU() */
67 #include "stream_control.h"
68 #include "input_ext-intf.h"
71 #include "intf_playlist.h"
72 #include "interface.h"
74 #include "audio_output.h"
77 #include "video_output.h"
80 # include "beos_specific.h"
84 # include "darwin_specific.h"
87 #include "netutils.h" /* network_ChannelJoin */
91 /*****************************************************************************
92 * Command line options constants. If something is changed here, be sure that
93 * GetConfiguration and Usage are also changed.
94 *****************************************************************************/
96 /* Long options return values - note that values corresponding to short options
97 * chars, and in general any regular char, should be avoided */
98 #define OPT_NOAUDIO 150
99 #define OPT_STEREO 151
101 #define OPT_SPDIF 153
103 #define OPT_NOVIDEO 160
104 #define OPT_DISPLAY 161
105 #define OPT_WIDTH 162
106 #define OPT_HEIGHT 163
107 #define OPT_COLOR 164
108 #define OPT_FULLSCREEN 165
109 #define OPT_OVERLAY 166
111 #define OPT_CHANNELS 170
112 #define OPT_SERVER 171
114 #define OPT_BROADCAST 173
116 #define OPT_INPUT 180
117 #define OPT_MOTION 181
120 #define OPT_DOWNMIX 184
121 #define OPT_IMDCT 185
123 #define OPT_SYNCHRO 190
124 #define OPT_WARNING 191
125 #define OPT_VERSION 192
133 static const struct option longopts[] =
135 /* name, has_arg, flag, val */
137 /* General/common options */
138 { "help", 0, 0, 'h' },
139 { "longhelp", 0, 0, 'H' },
140 { "version", 0, 0, OPT_VERSION },
142 /* Interface options */
143 { "intf", 1, 0, 'I' },
144 { "warning", 1, 0, OPT_WARNING },
147 { "noaudio", 0, 0, OPT_NOAUDIO },
148 { "aout", 1, 0, 'A' },
149 { "stereo", 0, 0, OPT_STEREO },
150 { "mono", 0, 0, OPT_MONO },
151 { "spdif", 0, 0, OPT_SPDIF },
152 { "downmix", 1, 0, OPT_DOWNMIX },
153 { "imdct", 1, 0, OPT_IMDCT },
156 { "novideo", 0, 0, OPT_NOVIDEO },
157 { "vout", 1, 0, 'V' },
158 { "display", 1, 0, OPT_DISPLAY },
159 { "width", 1, 0, OPT_WIDTH },
160 { "height", 1, 0, OPT_HEIGHT },
161 { "grayscale", 0, 0, 'g' },
162 { "color", 0, 0, OPT_COLOR },
163 { "motion", 1, 0, OPT_MOTION },
164 { "idct", 1, 0, OPT_IDCT },
165 { "yuv", 1, 0, OPT_YUV },
166 { "fullscreen", 0, 0, OPT_FULLSCREEN },
167 { "overlay", 0, 0, OPT_OVERLAY },
170 { "dvdtitle", 1, 0, 't' },
171 { "dvdchapter", 1, 0, 'T' },
172 { "dvdangle", 1, 0, 'u' },
173 { "dvdaudio", 1, 0, 'a' },
174 { "dvdchannel", 1, 0, 'c' },
175 { "dvdsubtitle", 1, 0, 's' },
178 { "input", 1, 0, OPT_INPUT },
179 { "channels", 0, 0, OPT_CHANNELS },
180 { "server", 1, 0, OPT_SERVER },
181 { "port", 1, 0, OPT_PORT },
182 { "broadcast", 1, 0, OPT_BROADCAST },
184 /* Synchro options */
185 { "synchro", 1, 0, OPT_SYNCHRO },
190 static const char *psz_shortopts = "hHvgt:T:u:a:s:c:I:A:V:";
192 /*****************************************************************************
193 * Global variable program_data - these are the only ones, see main.h and
195 *****************************************************************************/
197 module_bank_t *p_module_bank;
198 aout_bank_t *p_aout_bank;
199 vout_bank_t *p_vout_bank;
201 /*****************************************************************************
203 *****************************************************************************/
204 static int GetConfiguration ( int *pi_argc, char *ppsz_argv[],
206 static int GetFilenames ( int i_argc, char *ppsz_argv[] );
207 static void Usage ( int i_fashion );
208 static void Version ( void );
210 static void InitSignalHandler ( void );
211 static void SimpleSignalHandler ( int i_signal );
212 static void FatalSignalHandler ( int i_signal );
214 static int CPUCapabilities ( void );
216 /*****************************************************************************
217 * main: parse command line, start interface and spawn threads
218 *****************************************************************************
219 * Steps during program execution are:
220 * -configuration parsing and messages interface initialization
221 * -opening of audio output device and some global modules
222 * -execution of interface, which exit on error or on user request
223 * -closing of audio output device and some global modules
224 * On error, the spawned threads are canceled, and the open devices closed.
225 *****************************************************************************/
226 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
228 main_t main_data; /* root of all data - see main.h */
229 module_bank_t module_bank;
230 aout_bank_t aout_bank;
231 vout_bank_t vout_bank;
233 p_main = &main_data; /* set up the global variables */
234 p_module_bank = &module_bank;
235 p_aout_bank = &aout_bank;
236 p_vout_bank = &vout_bank;
239 * Test if our code is likely to run on this CPU
241 p_main->i_cpu_capabilities = CPUCapabilities();
243 #if defined( __pentium__ ) || defined( __pentiumpro__ )
244 if( ! TestCPU( CPU_CAPABILITY_586 ) )
246 fprintf( stderr, "error: this program needs a Pentium CPU,\n"
247 "please try a version without Pentium support\n" );
253 * System specific initialization code
255 #if defined( SYS_BEOS ) || defined( SYS_DARWIN1_3 )
256 system_Init( &i_argc, ppsz_argv, ppsz_env );
260 * Initialize messages interface
262 p_main->p_msg = intf_MsgCreate();
263 if( !p_main->p_msg ) /* start messages interface */
265 fprintf( stderr, "error: can't initialize messages interface (%s)\n",
270 intf_MsgImm( COPYRIGHT_MESSAGE );
275 if( GetConfiguration( &i_argc, ppsz_argv, ppsz_env ) ) /* parse cmd line */
282 * Initialize playlist and get commandline files
284 p_main->p_playlist = intf_PlaylistCreate();
285 if( !p_main->p_playlist )
287 intf_ErrMsg( "playlist error: playlist initialization failed" );
291 intf_PlaylistInit( p_main->p_playlist );
294 * Get input filenames given as commandline arguments
296 GetFilenames( i_argc, ppsz_argv );
299 * Initialize module, aout and vout banks
306 * Initialize shared resources and libraries
308 if( p_main->b_channels && network_ChannelCreate() )
310 /* On error during Channels initialization, switch off channels */
311 intf_Msg( "Channels initialization failed : "
312 "Channel management is deactivated" );
313 p_main->b_channels = 0;
317 * Try to run the interface
319 p_main->p_intf = intf_Create();
320 if( p_main->p_intf == NULL )
322 intf_ErrMsg( "intf error: interface initialization failed" );
327 * Set signal handling policy for all threads
332 * This is the main loop
334 p_main->p_intf->pf_run( p_main->p_intf );
337 * Finished, destroy the interface
339 intf_Destroy( p_main->p_intf );
342 * Go back into channel 0 which is the network
344 if( p_main->b_channels )
346 network_ChannelJoin( COMMON_CHANNEL );
351 * Free module, aout and vout banks
360 intf_PlaylistDestroy( p_main->p_playlist );
363 * System specific cleaning code
365 #if defined( SYS_BEOS ) || defined( SYS_DARWIN1_3 )
370 * Terminate messages interface and program
372 intf_Msg( "intf: program terminated" );
378 /*****************************************************************************
379 * main_GetIntVariable: get the int value of an environment variable
380 *****************************************************************************
381 * This function is used to read some default parameters in modules.
382 *****************************************************************************/
383 int main_GetIntVariable( char *psz_name, int i_default )
385 char * psz_env; /* environment value */
386 char * psz_end; /* end of parsing index */
387 long int i_value; /* value */
389 psz_env = getenv( psz_name );
392 i_value = strtol( psz_env, &psz_end, 0 );
393 if( (*psz_env != '\0') && (*psz_end == '\0') )
401 /*****************************************************************************
402 * main_GetPszVariable: get the string value of an environment variable
403 *****************************************************************************
404 * This function is used to read some default parameters in modules.
405 *****************************************************************************/
406 char * main_GetPszVariable( char *psz_name, char *psz_default )
410 psz_env = getenv( psz_name );
415 return( psz_default );
418 /*****************************************************************************
419 * main_PutPszVariable: set the string value of an environment variable
420 *****************************************************************************
421 * This function is used to set some default parameters in modules. The use of
422 * this function will cause some memory leak: since some systems use the pointer
423 * passed to putenv to store the environment string, it can't be freed.
424 *****************************************************************************/
425 void main_PutPszVariable( char *psz_name, char *psz_value )
429 psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
430 if( psz_env == NULL )
432 intf_ErrMsg( "intf error: cannot create psz_env (%s)",
437 sprintf( psz_env, "%s=%s", psz_name, psz_value );
438 if( putenv( psz_env ) )
440 intf_ErrMsg( "intf error: cannot putenv (%s)", strerror(errno) );
445 /*****************************************************************************
446 * main_PutIntVariable: set the integer value of an environment variable
447 *****************************************************************************
448 * This function is used to set some default parameters in modules. The use of
449 * this function will cause some memory leak: since some systems use the pointer
450 * passed to putenv to store the environment string, it can't be freed.
451 *****************************************************************************/
452 void main_PutIntVariable( char *psz_name, int i_value )
454 char psz_value[ 256 ]; /* buffer for value */
456 sprintf( psz_value, "%d", i_value );
457 main_PutPszVariable( psz_name, psz_value );
460 /* following functions are local */
462 /*****************************************************************************
463 * GetConfiguration: parse command line
464 *****************************************************************************
465 * Parse command line and configuration file for configuration. If the inline
466 * help is requested, the function Usage() is called and the function returns
467 * -1 (causing main() to exit). The messages interface is initialized at this
468 * stage, but most structures are not allocated, so only environment should
470 *****************************************************************************/
471 static int GetConfiguration( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
476 /* Set default configuration and copy arguments */
477 p_main->i_argc = *pi_argc;
478 p_main->ppsz_argv = ppsz_argv;
479 p_main->ppsz_env = ppsz_env;
483 p_main->b_channels = 0;
485 p_main->i_warning_level = 0;
487 /* Get the executable name (similar to the basename command) */
488 p_main->psz_arg0 = p_tmp = ppsz_argv[ 0 ];
493 p_main->psz_arg0 = ++p_tmp;
502 /* When vlc.app is run by double clicking in Mac OS X, the 2nd arg
503 * is the PSN - process serial number (a unique PID-ish thingie)
504 * still ok for real Darwin & when run from command line */
505 if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
506 /* for example -psn_0_9306113 */
508 /* GDMF!... I can't do this or else the MacOSX window server will
509 * not pick up the PSN and not register the app and we crash...
510 * hence the following kludge otherwise we'll get confused w/ argv[1]
511 * being an input file name */
513 ppsz_argv[ 1 ] = NULL;
515 *pi_argc = *pi_argc - 1;
521 /* Parse command line options */
523 while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv,
524 psz_shortopts, longopts, 0 ) ) != EOF )
528 /* General/common options */
529 case 'h': /* -h, --help */
533 case 'H': /* -H, --longhelp */
537 case OPT_VERSION: /* --version */
541 case 'v': /* -v, --verbose */
542 p_main->i_warning_level++;
545 /* Interface warning messages level */
546 case 'I': /* -I, --intf */
547 main_PutPszVariable( INTF_METHOD_VAR, optarg );
549 case OPT_WARNING: /* --warning */
550 intf_ErrMsg( "intf error: `--warning' is deprecated, use `-v'" );
551 p_main->i_warning_level = atoi(optarg);
555 case OPT_NOAUDIO: /* --noaudio */
558 case 'A': /* -A, --aout */
559 main_PutPszVariable( AOUT_METHOD_VAR, optarg );
561 case OPT_STEREO: /* --stereo */
562 main_PutIntVariable( AOUT_STEREO_VAR, 1 );
564 case OPT_MONO: /* --mono */
565 main_PutIntVariable( AOUT_STEREO_VAR, 0 );
567 case OPT_SPDIF: /* --spdif */
568 main_PutIntVariable( AOUT_SPDIF_VAR, 1 );
570 case OPT_DOWNMIX: /* --downmix */
571 main_PutPszVariable( DOWNMIX_METHOD_VAR, optarg );
573 case OPT_IMDCT: /* --imdct */
574 main_PutPszVariable( IMDCT_METHOD_VAR, optarg );
578 case OPT_NOVIDEO: /* --novideo */
581 case 'V': /* -V, --vout */
582 main_PutPszVariable( VOUT_METHOD_VAR, optarg );
584 case OPT_DISPLAY: /* --display */
585 main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
587 case OPT_WIDTH: /* --width */
588 main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
590 case OPT_HEIGHT: /* --height */
591 main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
593 case 'g': /* -g, --grayscale */
594 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
596 case OPT_COLOR: /* --color */
597 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
599 case OPT_FULLSCREEN: /* --fullscreen */
600 main_PutIntVariable( VOUT_FULLSCREEN_VAR, 1 );
602 case OPT_OVERLAY: /* --overlay */
603 main_PutIntVariable( VOUT_OVERLAY_VAR, 1 );
605 case OPT_MOTION: /* --motion */
606 main_PutPszVariable( MOTION_METHOD_VAR, optarg );
608 case OPT_IDCT: /* --idct */
609 main_PutPszVariable( IDCT_METHOD_VAR, optarg );
611 case OPT_YUV: /* --yuv */
612 main_PutPszVariable( YUV_METHOD_VAR, optarg );
617 main_PutIntVariable( INPUT_TITLE_VAR, atoi(optarg) );
620 main_PutIntVariable( INPUT_CHAPTER_VAR, atoi(optarg) );
623 main_PutIntVariable( INPUT_ANGLE_VAR, atoi(optarg) );
626 if ( ! strcmp(optarg, "ac3") )
627 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_AC3 );
628 else if ( ! strcmp(optarg, "lpcm") )
629 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_LPCM );
630 else if ( ! strcmp(optarg, "mpeg") )
631 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_MPEG );
633 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_NOAUDIO );
636 main_PutIntVariable( INPUT_CHANNEL_VAR, atoi(optarg) );
639 main_PutIntVariable( INPUT_SUBTITLE_VAR, atoi(optarg) );
643 case OPT_INPUT: /* --input */
644 main_PutPszVariable( INPUT_METHOD_VAR, optarg );
646 case OPT_CHANNELS: /* --channels */
647 p_main->b_channels = 1;
649 case OPT_SERVER: /* --server */
650 main_PutPszVariable( INPUT_SERVER_VAR, optarg );
652 case OPT_PORT: /* --port */
653 main_PutPszVariable( INPUT_PORT_VAR, optarg );
655 case OPT_BROADCAST: /* --broadcast */
656 main_PutPszVariable( INPUT_BROADCAST_VAR, optarg );
659 /* Synchro options */
661 main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
664 /* Internal error: unknown option */
667 intf_ErrMsg( "intf error: unknown option `%s'",
668 ppsz_argv[optind - 1] );
675 if( p_main->i_warning_level < 0 )
677 p_main->i_warning_level = 0;
683 /*****************************************************************************
684 * GetFilenames: parse command line options which are not flags
685 *****************************************************************************
686 * Parse command line for input files.
687 *****************************************************************************/
688 static int GetFilenames( int i_argc, char *ppsz_argv[] )
692 /* We assume that the remaining parameters are filenames */
693 for( i_opt = optind; i_opt < i_argc; i_opt++ )
695 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
696 ppsz_argv[ i_opt ] );
702 /*****************************************************************************
703 * Usage: print program usage
704 *****************************************************************************
705 * Print a short inline help. Message interface is initialized at this stage.
706 *****************************************************************************/
707 static void Usage( int i_fashion )
710 intf_MsgImm( "Usage: %s [options] [parameters] [file]...",
713 if( i_fashion == USAGE )
715 intf_MsgImm( "Try `%s --help' for more information.",
721 intf_MsgImm( "\nOptions:"
722 "\n -I, --intf <module> \tinterface method"
723 "\n -v, --verbose \tverbose mode (cumulative)"
725 "\n --noaudio \tdisable audio"
726 "\n -A, --aout <module> \taudio output method"
727 "\n --stereo, --mono \tstereo/mono audio"
728 "\n --spdif \tAC3 pass-through mode"
729 "\n --downmix <module> \tAC3 downmix method"
730 "\n --imdct <module> \tAC3 IMDCT method"
732 "\n --novideo \tdisable video"
733 "\n -V, --vout <module> \tvideo output method"
734 "\n --display <display> \tdisplay string"
735 "\n --width <w>, --height <h> \tdisplay dimensions"
736 "\n -g, --grayscale \tgrayscale output"
737 "\n --fullscreen \tfullscreen output"
738 "\n --overlay \taccelerated display"
739 "\n --color \tcolor output"
740 "\n --motion <module> \tmotion compensation method"
741 "\n --idct <module> \tIDCT method"
742 "\n --yuv <module> \tYUV method"
743 "\n --synchro <type> \tforce synchro algorithm"
745 "\n -t, --dvdtitle <num> \tchoose DVD title"
746 "\n -T, --dvdchapter <num> \tchoose DVD chapter"
747 "\n -u, --dvdangle <num> \tchoose DVD angle"
748 "\n -a, --dvdaudio <type> \tchoose DVD audio type"
749 "\n -c, --dvdchannel <channel> \tchoose DVD audio channel"
750 "\n -s, --dvdsubtitle <channel> \tchoose DVD subtitle channel"
752 "\n --input \tinput method"
753 "\n --channels \tenable channels"
754 "\n --server <host> \tvideo server address"
755 "\n --port <port> \tvideo server port"
756 "\n --broadcast \tlisten to a broadcast"
758 "\n -h, --help \tprint help and exit"
759 "\n -H, --longhelp \tprint long help and exit"
760 "\n --version \toutput version information and exit" );
762 if( i_fashion == SHORT_HELP )
765 /* Interface parameters */
766 intf_MsgImm( "\nInterface parameters:"
767 "\n " INTF_METHOD_VAR "=<method name> \tinterface method"
768 "\n " INTF_INIT_SCRIPT_VAR "=<filename> \tinitialization script"
769 "\n " INTF_CHANNELS_VAR "=<filename> \tchannels list" );
771 /* Audio parameters */
772 intf_MsgImm( "\nAudio parameters:"
773 "\n " AOUT_METHOD_VAR "=<method name> \taudio method"
774 "\n " AOUT_DSP_VAR "=<filename> \tdsp device path"
775 "\n " AOUT_STEREO_VAR "={1|0} \tstereo or mono output"
776 "\n " AOUT_SPDIF_VAR "={1|0} \tAC3 pass-through mode"
777 "\n " DOWNMIX_METHOD_VAR "=<method name> \tAC3 downmix method"
778 "\n " IMDCT_METHOD_VAR "=<method name> \tAC3 IMDCT method"
779 "\n " AOUT_RATE_VAR "=<rate> \toutput rate" );
781 /* Video parameters */
782 intf_MsgImm( "\nVideo parameters:"
783 "\n " VOUT_METHOD_VAR "=<method name> \tdisplay method"
784 "\n " VOUT_DISPLAY_VAR "=<display name> \tdisplay used"
785 "\n " VOUT_WIDTH_VAR "=<width> \tdisplay width"
786 "\n " VOUT_HEIGHT_VAR "=<height> \tdislay height"
787 "\n " VOUT_FB_DEV_VAR "=<filename> \tframebuffer device path"
788 "\n " VOUT_GRAYSCALE_VAR "={1|0} \tgrayscale or color output"
789 "\n " VOUT_FULLSCREEN_VAR "={1|0} \tfullscreen"
790 "\n " VOUT_OVERLAY_VAR "={1|0} \toverlay"
791 "\n " MOTION_METHOD_VAR "=<method name> \tmotion compensation method"
792 "\n " IDCT_METHOD_VAR "=<method name> \tIDCT method"
793 "\n " YUV_METHOD_VAR "=<method name> \tYUV method"
794 "\n " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB} \tsynchro algorithm" );
797 intf_MsgImm( "\nDVD parameters:"
798 "\n " INPUT_DVD_DEVICE_VAR "=<device> \tDVD device"
799 "\n " INPUT_TITLE_VAR "=<title> \ttitle number"
800 "\n " INPUT_CHAPTER_VAR "=<chapter> \tchapter number"
801 "\n " INPUT_ANGLE_VAR "=<angle> \tangle number"
802 "\n " INPUT_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type"
803 "\n " INPUT_CHANNEL_VAR "=[0-15] \taudio channel"
804 "\n " INPUT_SUBTITLE_VAR "=[0-31] \tsubtitle channel" );
806 /* Input parameters */
807 intf_MsgImm( "\nInput parameters:"
808 "\n " INPUT_SERVER_VAR "=<hostname> \tvideo server"
809 "\n " INPUT_PORT_VAR "=<port> \tvideo server port"
810 "\n " INPUT_IFACE_VAR "=<interface> \tnetwork interface"
811 "\n " INPUT_BROADCAST_VAR "=<addr> \tbroadcast mode"
812 "\n " INPUT_CHANNEL_SERVER_VAR "=<hostname> \tchannel server"
813 "\n " INPUT_CHANNEL_PORT_VAR "=<port> \tchannel server port" );
817 /*****************************************************************************
818 * Version: print complete program version
819 *****************************************************************************
820 * Print complete program version and build number.
821 *****************************************************************************/
822 static void Version( void )
824 intf_MsgImm( VERSION_MESSAGE
825 "This program comes with NO WARRANTY, to the extent permitted by law.\n"
826 "You may redistribute it under the terms of the GNU General Public License;\n"
827 "see the file named COPYING for details.\n"
828 "Written by the VideoLAN team at Ecole Centrale, Paris." );
831 /*****************************************************************************
832 * InitSignalHandler: system signal handler initialization
833 *****************************************************************************
834 * Set the signal handlers. SIGTERM is not intercepted, because we need at
835 * at least a method to kill the program when all other methods failed, and
836 * when we don't want to use SIGKILL.
837 *****************************************************************************/
838 static void InitSignalHandler( void )
840 /* Termination signals */
842 signal( SIGINT, FatalSignalHandler );
843 signal( SIGHUP, FatalSignalHandler );
844 signal( SIGQUIT, FatalSignalHandler );
847 signal( SIGALRM, SimpleSignalHandler );
848 signal( SIGPIPE, SimpleSignalHandler );
853 /*****************************************************************************
854 * SimpleSignalHandler: system signal handler
855 *****************************************************************************
856 * This function is called when a non fatal signal is received by the program.
857 *****************************************************************************/
858 static void SimpleSignalHandler( int i_signal )
860 /* Acknowledge the signal received */
861 intf_WarnMsg( 0, "intf: ignoring signal %d", i_signal );
865 /*****************************************************************************
866 * FatalSignalHandler: system signal handler
867 *****************************************************************************
868 * This function is called when a fatal signal is received by the program.
869 * It tries to end the program in a clean way.
870 *****************************************************************************/
871 static void FatalSignalHandler( int i_signal )
873 /* Once a signal has been trapped, the termination sequence will be
874 * armed and following signals will be ignored to avoid sending messages
875 * to an interface having been destroyed */
877 signal( SIGINT, SIG_IGN );
878 signal( SIGHUP, SIG_IGN );
879 signal( SIGQUIT, SIG_IGN );
882 /* Acknowledge the signal received */
883 intf_ErrMsgImm( "intf error: signal %d received, exiting", i_signal );
885 /* Try to terminate everything - this is done by requesting the end of the
886 * interface thread */
887 p_main->p_intf->b_die = 1;
890 /*****************************************************************************
891 * CPUCapabilities: list the processors MMX support and other capabilities
892 *****************************************************************************
893 * This function is called to list extensions the CPU may have.
894 *****************************************************************************/
895 static int CPUCapabilities( void )
897 int i_capabilities = CPU_CAPABILITY_NONE;
899 #if defined( SYS_BEOS )
900 i_capabilities |= CPU_CAPABILITY_486
902 | CPU_CAPABILITY_MMX;
904 #elif defined( SYS_DARWIN1_3 )
906 struct host_basic_info hi;
908 host_name_port_t host;
911 char *psz_name, *psz_subname;
913 /* Should 'never' fail? */
914 host = mach_host_self();
916 i_size = sizeof( hi ) / sizeof( int );
917 ret = host_info( host, HOST_BASIC_INFO, ( host_info_t )&hi, &i_size );
919 if( ret != KERN_SUCCESS )
921 intf_ErrMsg( "error: couldn't get CPU information" );
922 return( i_capabilities );
925 slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
926 /* FIXME: need better way to detect newer proccessors.
927 * could do strncmp(a,b,5), but that's real ugly */
928 if( strcmp(psz_name, "ppc7400") || strcmp(psz_name, "ppc7450") )
930 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
933 #elif defined( __i386__ )
934 unsigned int i_eax, i_ebx, i_ecx, i_edx;
937 # define cpuid( a ) \
938 asm volatile ( "cpuid" \
946 /* test for a 486 CPU */
947 asm volatile ( "pushfl\n\t"
949 "movl %%eax, %%ebx\n\t"
950 "xorl $0x200000, %%eax\n\t"
962 return( i_capabilities );
965 i_capabilities |= CPU_CAPABILITY_486;
967 /* the CPU supports the CPUID instruction - get its level */
972 return( i_capabilities );
975 /* FIXME: this isn't correct, since some 486s have cpuid */
976 i_capabilities |= CPU_CAPABILITY_586;
978 /* borrowed from mpeg2dec */
979 b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
980 && ( i_edx == 0x69746e65 );
982 /* test for the MMX flag */
985 if( ! (i_edx & 0x00800000) )
987 return( i_capabilities );
990 i_capabilities |= CPU_CAPABILITY_MMX;
992 if( i_edx & 0x02000000 )
994 i_capabilities |= CPU_CAPABILITY_MMXEXT;
995 i_capabilities |= CPU_CAPABILITY_SSE;
998 /* test for additional capabilities */
1001 if( i_eax < 0x80000001 )
1003 return( i_capabilities );
1006 /* list these additional capabilities */
1007 cpuid( 0x80000001 );
1009 if( i_edx & 0x80000000 )
1011 i_capabilities |= CPU_CAPABILITY_3DNOW;
1014 if( b_amd && ( i_edx & 0x00400000 ) )
1016 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1019 /* default behaviour */
1022 return( i_capabilities );