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.94 2001/05/14 15:58:04 reno 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 <errno.h> /* ENOMEM */
52 #include <stdlib.h> /* getenv(), strtol(), */
53 #include <string.h> /* strerror() */
60 #include "tests.h" /* TestCPU() */
63 #include "stream_control.h"
64 #include "input_ext-intf.h"
67 #include "intf_playlist.h"
68 #include "interface.h"
70 #include "audio_output.h"
73 #include "video_output.h"
76 # include "beos_specific.h"
80 # include "darwin_specific.h"
83 #include "netutils.h" /* network_ChannelJoin */
87 /*****************************************************************************
88 * Command line options constants. If something is changed here, be sure that
89 * GetConfiguration and Usage are also changed.
90 *****************************************************************************/
92 /* Long options return values - note that values corresponding to short options
93 * chars, and in general any regular char, should be avoided */
94 #define OPT_NOAUDIO 150
95 #define OPT_STEREO 151
99 #define OPT_NOVIDEO 160
100 #define OPT_DISPLAY 161
101 #define OPT_WIDTH 162
102 #define OPT_HEIGHT 163
103 #define OPT_COLOR 164
104 #define OPT_FULLSCREEN 165
105 #define OPT_OVERLAY 166
107 #define OPT_CHANNELS 170
108 #define OPT_SERVER 171
110 #define OPT_BROADCAST 173
112 #define OPT_INPUT 180
113 #define OPT_MOTION 181
117 #define OPT_SYNCHRO 190
118 #define OPT_WARNING 191
119 #define OPT_VERSION 192
127 static const struct option longopts[] =
129 /* name, has_arg, flag, val */
131 /* General/common options */
132 { "help", 0, 0, 'h' },
133 { "longhelp", 0, 0, 'H' },
134 { "version", 0, 0, OPT_VERSION },
136 /* Interface options */
137 { "intf", 1, 0, 'I' },
138 { "warning", 1, 0, OPT_WARNING },
141 { "noaudio", 0, 0, OPT_NOAUDIO },
142 { "aout", 1, 0, 'A' },
143 { "stereo", 0, 0, OPT_STEREO },
144 { "mono", 0, 0, OPT_MONO },
145 { "spdif", 0, 0, OPT_SPDIF },
148 { "novideo", 0, 0, OPT_NOVIDEO },
149 { "vout", 1, 0, 'V' },
150 { "display", 1, 0, OPT_DISPLAY },
151 { "width", 1, 0, OPT_WIDTH },
152 { "height", 1, 0, OPT_HEIGHT },
153 { "grayscale", 0, 0, 'g' },
154 { "color", 0, 0, OPT_COLOR },
155 { "motion", 1, 0, OPT_MOTION },
156 { "idct", 1, 0, OPT_IDCT },
157 { "yuv", 1, 0, OPT_YUV },
158 { "fullscreen", 0, 0, OPT_FULLSCREEN },
159 { "overlay", 0, 0, OPT_OVERLAY },
162 { "dvdtitle", 1, 0, 't' },
163 { "dvdchapter", 1, 0, 'T' },
164 { "dvdangle", 1, 0, 'u' },
165 { "dvdaudio", 1, 0, 'a' },
166 { "dvdchannel", 1, 0, 'c' },
167 { "dvdsubtitle", 1, 0, 's' },
170 { "input", 1, 0, OPT_INPUT },
171 { "channels", 0, 0, OPT_CHANNELS },
172 { "server", 1, 0, OPT_SERVER },
173 { "port", 1, 0, OPT_PORT },
174 { "broadcast", 1, 0, OPT_BROADCAST },
176 /* Synchro options */
177 { "synchro", 1, 0, OPT_SYNCHRO },
182 static const char *psz_shortopts = "hHvgt:T:u:a:s:c:I:A:V:";
184 /*****************************************************************************
185 * Global variable program_data - these are the only ones, see main.h and
187 *****************************************************************************/
189 module_bank_t *p_module_bank;
190 aout_bank_t *p_aout_bank;
191 vout_bank_t *p_vout_bank;
193 /*****************************************************************************
195 *****************************************************************************/
196 static int GetConfiguration ( int *pi_argc, char *ppsz_argv[],
198 static int GetFilenames ( int i_argc, char *ppsz_argv[] );
199 static void Usage ( int i_fashion );
200 static void Version ( void );
202 static void InitSignalHandler ( void );
203 static void SimpleSignalHandler ( int i_signal );
204 static void FatalSignalHandler ( int i_signal );
206 static int CPUCapabilities ( void );
208 /*****************************************************************************
209 * main: parse command line, start interface and spawn threads
210 *****************************************************************************
211 * Steps during program execution are:
212 * -configuration parsing and messages interface initialization
213 * -opening of audio output device and some global modules
214 * -execution of interface, which exit on error or on user request
215 * -closing of audio output device and some global modules
216 * On error, the spawned threads are canceled, and the open devices closed.
217 *****************************************************************************/
218 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
220 main_t main_data; /* root of all data - see main.h */
221 module_bank_t module_bank;
222 aout_bank_t aout_bank;
223 vout_bank_t vout_bank;
225 p_main = &main_data; /* set up the global variables */
226 p_module_bank = &module_bank;
227 p_aout_bank = &aout_bank;
228 p_vout_bank = &vout_bank;
231 * Test if our code is likely to run on this CPU
233 p_main->i_cpu_capabilities = CPUCapabilities();
235 #if defined( __pentium__ ) || defined( __pentiumpro__ )
236 if( ! TestCPU( CPU_CAPABILITY_586 ) )
238 fprintf( stderr, "error: this program needs a Pentium CPU,\n"
239 "please try a version without Pentium support\n" );
245 * System specific initialization code
247 #if defined( SYS_BEOS ) || defined( SYS_DARWIN1_3 )
248 system_Init( &i_argc, ppsz_argv, ppsz_env );
252 * Initialize messages interface
254 p_main->p_msg = intf_MsgCreate();
255 if( !p_main->p_msg ) /* start messages interface */
257 fprintf( stderr, "error: can't initialize messages interface (%s)\n",
262 intf_MsgImm( COPYRIGHT_MESSAGE );
267 if( GetConfiguration( &i_argc, ppsz_argv, ppsz_env ) ) /* parse cmd line */
274 * Initialize playlist and get commandline files
276 p_main->p_playlist = intf_PlaylistCreate();
277 if( !p_main->p_playlist )
279 intf_ErrMsg( "playlist error: playlist initialization failed" );
283 intf_PlaylistInit( p_main->p_playlist );
286 * Get input filenames given as commandline arguments
288 GetFilenames( i_argc, ppsz_argv );
291 * Initialize module, aout and vout banks
298 * Initialize shared resources and libraries
300 if( p_main->b_channels && network_ChannelCreate() )
302 /* On error during Channels initialization, switch off channels */
303 intf_Msg( "Channels initialization failed : "
304 "Channel management is deactivated" );
305 p_main->b_channels = 0;
309 * Try to run the interface
311 p_main->p_intf = intf_Create();
312 if( p_main->p_intf == NULL )
314 intf_ErrMsg( "intf error: interface initialization failed" );
319 * Set signal handling policy for all threads
324 * This is the main loop
326 p_main->p_intf->pf_run( p_main->p_intf );
329 * Finished, destroy the interface
331 intf_Destroy( p_main->p_intf );
334 * Go back into channel 0 which is the network
336 if( p_main->b_channels )
338 network_ChannelJoin( COMMON_CHANNEL );
343 * Free module, aout and vout banks
352 intf_PlaylistDestroy( p_main->p_playlist );
355 * System specific cleaning code
357 #if defined( SYS_BEOS ) || defined( SYS_DARWIN1_3 )
362 * Terminate messages interface and program
364 intf_Msg( "intf: program terminated" );
370 /*****************************************************************************
371 * main_GetIntVariable: get the int value of an environment variable
372 *****************************************************************************
373 * This function is used to read some default parameters in modules.
374 *****************************************************************************/
375 int main_GetIntVariable( char *psz_name, int i_default )
377 char * psz_env; /* environment value */
378 char * psz_end; /* end of parsing index */
379 long int i_value; /* value */
381 psz_env = getenv( psz_name );
384 i_value = strtol( psz_env, &psz_end, 0 );
385 if( (*psz_env != '\0') && (*psz_end == '\0') )
393 /*****************************************************************************
394 * main_GetPszVariable: get the string value of an environment variable
395 *****************************************************************************
396 * This function is used to read some default parameters in modules.
397 *****************************************************************************/
398 char * main_GetPszVariable( char *psz_name, char *psz_default )
402 psz_env = getenv( psz_name );
407 return( psz_default );
410 /*****************************************************************************
411 * main_PutPszVariable: set the string value of an environment variable
412 *****************************************************************************
413 * This function is used to set some default parameters in modules. The use of
414 * this function will cause some memory leak: since some systems use the pointer
415 * passed to putenv to store the environment string, it can't be freed.
416 *****************************************************************************/
417 void main_PutPszVariable( char *psz_name, char *psz_value )
421 psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
422 if( psz_env == NULL )
424 intf_ErrMsg( "intf error: cannot create psz_env (%s)",
429 sprintf( psz_env, "%s=%s", psz_name, psz_value );
430 if( putenv( psz_env ) )
432 intf_ErrMsg( "intf error: cannot putenv (%s)", strerror(errno) );
437 /*****************************************************************************
438 * main_PutIntVariable: set the integer value of an environment variable
439 *****************************************************************************
440 * This function is used to set some default parameters in modules. The use of
441 * this function will cause some memory leak: since some systems use the pointer
442 * passed to putenv to store the environment string, it can't be freed.
443 *****************************************************************************/
444 void main_PutIntVariable( char *psz_name, int i_value )
446 char psz_value[ 256 ]; /* buffer for value */
448 sprintf( psz_value, "%d", i_value );
449 main_PutPszVariable( psz_name, psz_value );
452 /* following functions are local */
454 /*****************************************************************************
455 * GetConfiguration: parse command line
456 *****************************************************************************
457 * Parse command line and configuration file for configuration. If the inline
458 * help is requested, the function Usage() is called and the function returns
459 * -1 (causing main() to exit). The messages interface is initialized at this
460 * stage, but most structures are not allocated, so only environment should
462 *****************************************************************************/
463 static int GetConfiguration( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
468 /* Set default configuration and copy arguments */
469 p_main->i_argc = *pi_argc;
470 p_main->ppsz_argv = ppsz_argv;
471 p_main->ppsz_env = ppsz_env;
475 p_main->b_channels = 0;
477 p_main->i_warning_level = 0;
479 /* Get the executable name (similar to the basename command) */
480 p_main->psz_arg0 = p_tmp = ppsz_argv[ 0 ];
485 p_main->psz_arg0 = ++p_tmp;
494 /* When vlc.app is run by double clicking in Mac OS X, the 2nd arg
495 * is the PSN - process serial number (a unique PID-ish thingie)
496 * still ok for real Darwin & when run from command line */
497 if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
498 /* for example -psn_0_9306113 */
500 /* GDMF!... I can't do this or else the MacOSX window server will
501 * not pick up the PSN and not register the app and we crash...
502 * hence the following kludge otherwise we'll get confused w/ argv[1]
503 * being an input file name */
505 ppsz_argv[ 1 ] = NULL;
507 *pi_argc = *pi_argc - 1;
513 /* Parse command line options */
515 while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv,
516 psz_shortopts, longopts, 0 ) ) != EOF )
520 /* General/common options */
521 case 'h': /* -h, --help */
525 case 'H': /* -H, --longhelp */
529 case OPT_VERSION: /* --version */
533 case 'v': /* -v, --verbose */
534 p_main->i_warning_level++;
537 /* Interface warning messages level */
538 case 'I': /* -I, --intf */
539 main_PutPszVariable( INTF_METHOD_VAR, optarg );
541 case OPT_WARNING: /* --warning */
542 intf_ErrMsg( "intf error: `--warning' is deprecated, use `-v'" );
543 p_main->i_warning_level = atoi(optarg);
547 case OPT_NOAUDIO: /* --noaudio */
550 case 'A': /* -A, --aout */
551 main_PutPszVariable( AOUT_METHOD_VAR, optarg );
553 case OPT_STEREO: /* --stereo */
554 main_PutIntVariable( AOUT_STEREO_VAR, 1 );
556 case OPT_MONO: /* --mono */
557 main_PutIntVariable( AOUT_STEREO_VAR, 0 );
559 case OPT_SPDIF: /* --spdif */
560 main_PutIntVariable( AOUT_SPDIF_VAR, 1 );
564 case OPT_NOVIDEO: /* --novideo */
567 case 'V': /* -V, --vout */
568 main_PutPszVariable( VOUT_METHOD_VAR, optarg );
570 case OPT_DISPLAY: /* --display */
571 main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
573 case OPT_WIDTH: /* --width */
574 main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
576 case OPT_HEIGHT: /* --height */
577 main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
579 case 'g': /* -g, --grayscale */
580 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
582 case OPT_COLOR: /* --color */
583 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
585 case OPT_FULLSCREEN: /* --fullscreen */
586 main_PutIntVariable( VOUT_FULLSCREEN_VAR, 1 );
588 case OPT_OVERLAY: /* --overlay */
589 main_PutIntVariable( VOUT_OVERLAY_VAR, 1 );
591 case OPT_MOTION: /* --motion */
592 main_PutPszVariable( MOTION_METHOD_VAR, optarg );
594 case OPT_IDCT: /* --idct */
595 main_PutPszVariable( IDCT_METHOD_VAR, optarg );
597 case OPT_YUV: /* --yuv */
598 main_PutPszVariable( YUV_METHOD_VAR, optarg );
603 main_PutIntVariable( INPUT_TITLE_VAR, atoi(optarg) );
606 main_PutIntVariable( INPUT_CHAPTER_VAR, atoi(optarg) );
609 main_PutIntVariable( INPUT_ANGLE_VAR, atoi(optarg) );
612 if ( ! strcmp(optarg, "ac3") )
613 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_AC3 );
614 else if ( ! strcmp(optarg, "lpcm") )
615 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_LPCM );
616 else if ( ! strcmp(optarg, "mpeg") )
617 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_MPEG );
619 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_NOAUDIO );
622 main_PutIntVariable( INPUT_CHANNEL_VAR, atoi(optarg) );
625 main_PutIntVariable( INPUT_SUBTITLE_VAR, atoi(optarg) );
629 case OPT_INPUT: /* --input */
630 main_PutPszVariable( INPUT_METHOD_VAR, optarg );
632 case OPT_CHANNELS: /* --channels */
633 p_main->b_channels = 1;
635 case OPT_SERVER: /* --server */
636 main_PutPszVariable( INPUT_SERVER_VAR, optarg );
638 case OPT_PORT: /* --port */
639 main_PutPszVariable( INPUT_PORT_VAR, optarg );
641 case OPT_BROADCAST: /* --broadcast */
642 main_PutPszVariable( INPUT_BROADCAST_VAR, optarg );
645 /* Synchro options */
647 main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
650 /* Internal error: unknown option */
653 intf_ErrMsg( "intf error: unknown option `%s'",
654 ppsz_argv[optind - 1] );
661 if( p_main->i_warning_level < 0 )
663 p_main->i_warning_level = 0;
669 /*****************************************************************************
670 * GetFilenames: parse command line options which are not flags
671 *****************************************************************************
672 * Parse command line for input files.
673 *****************************************************************************/
674 static int GetFilenames( int i_argc, char *ppsz_argv[] )
678 /* We assume that the remaining parameters are filenames */
679 for( i_opt = optind; i_opt < i_argc; i_opt++ )
681 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
682 ppsz_argv[ i_opt ] );
688 /*****************************************************************************
689 * Usage: print program usage
690 *****************************************************************************
691 * Print a short inline help. Message interface is initialized at this stage.
692 *****************************************************************************/
693 static void Usage( int i_fashion )
696 intf_MsgImm( "Usage: %s [options] [parameters] [file]...",
699 if( i_fashion == USAGE )
701 intf_MsgImm( "Try `%s --help' for more information.",
707 intf_MsgImm( "\nOptions:"
708 "\n -I, --intf <module> \tinterface method"
709 "\n -v, --verbose \tverbose mode (cumulative)"
711 "\n --noaudio \tdisable audio"
712 "\n -A, --aout <module> \taudio output method"
713 "\n --stereo, --mono \tstereo/mono audio"
714 "\n --spdif \tAC3 pass-through mode"
716 "\n --novideo \tdisable video"
717 "\n -V, --vout <module> \tvideo output method"
718 "\n --display <display> \tdisplay string"
719 "\n --width <w>, --height <h> \tdisplay dimensions"
720 "\n -g, --grayscale \tgrayscale output"
721 "\n --fullscreen \tfullscreen output"
722 "\n --overlay \taccelerated display"
723 "\n --color \tcolor output"
724 "\n --motion <module> \tmotion compensation method"
725 "\n --idct <module> \tIDCT method"
726 "\n --yuv <module> \tYUV method"
727 "\n --synchro <type> \tforce synchro algorithm"
729 "\n -t, --dvdtitle <num> \tchoose DVD title"
730 "\n -T, --dvdchapter <num> \tchoose DVD chapter"
731 "\n -u, --dvdangle <num> \tchoose DVD angle"
732 "\n -a, --dvdaudio <type> \tchoose DVD audio type"
733 "\n -c, --dvdchannel <channel> \tchoose DVD audio channel"
734 "\n -s, --dvdsubtitle <channel> \tchoose DVD subtitle channel"
736 "\n --input \tinput method"
737 "\n --channels \tenable channels"
738 "\n --server <host> \tvideo server address"
739 "\n --port <port> \tvideo server port"
740 "\n --broadcast \tlisten to a broadcast"
742 "\n -h, --help \tprint help and exit"
743 "\n -H, --longhelp \tprint long help and exit"
744 "\n --version \toutput version information and exit" );
746 if( i_fashion == SHORT_HELP )
749 /* Interface parameters */
750 intf_MsgImm( "\nInterface parameters:"
751 "\n " INTF_METHOD_VAR "=<method name> \tinterface method"
752 "\n " INTF_INIT_SCRIPT_VAR "=<filename> \tinitialization script"
753 "\n " INTF_CHANNELS_VAR "=<filename> \tchannels list" );
755 /* Audio parameters */
756 intf_MsgImm( "\nAudio parameters:"
757 "\n " AOUT_METHOD_VAR "=<method name> \taudio method"
758 "\n " AOUT_DSP_VAR "=<filename> \tdsp device path"
759 "\n " AOUT_STEREO_VAR "={1|0} \tstereo or mono output"
760 "\n " AOUT_SPDIF_VAR "={1|0} \tAC3 pass-through mode"
761 "\n " AOUT_RATE_VAR "=<rate> \toutput rate" );
763 /* Video parameters */
764 intf_MsgImm( "\nVideo parameters:"
765 "\n " VOUT_METHOD_VAR "=<method name> \tdisplay method"
766 "\n " VOUT_DISPLAY_VAR "=<display name> \tdisplay used"
767 "\n " VOUT_WIDTH_VAR "=<width> \tdisplay width"
768 "\n " VOUT_HEIGHT_VAR "=<height> \tdislay height"
769 "\n " VOUT_FB_DEV_VAR "=<filename> \tframebuffer device path"
770 "\n " VOUT_GRAYSCALE_VAR "={1|0} \tgrayscale or color output"
771 "\n " VOUT_FULLSCREEN_VAR "={1|0} \tfullscreen"
772 "\n " VOUT_OVERLAY_VAR "={1|0} \toverlay"
773 "\n " MOTION_METHOD_VAR "=<method name> \tmotion compensation method"
774 "\n " IDCT_METHOD_VAR "=<method name> \tIDCT method"
775 "\n " YUV_METHOD_VAR "=<method name> \tYUV method"
776 "\n " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB} \tsynchro algorithm" );
779 intf_MsgImm( "\nDVD parameters:"
780 "\n " INPUT_DVD_DEVICE_VAR "=<device> \tDVD device"
781 "\n " INPUT_TITLE_VAR "=<title> \ttitle number"
782 "\n " INPUT_CHAPTER_VAR "=<chapter> \tchapter number"
783 "\n " INPUT_ANGLE_VAR "=<angle> \tangle number"
784 "\n " INPUT_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type"
785 "\n " INPUT_CHANNEL_VAR "=[0-15] \taudio channel"
786 "\n " INPUT_SUBTITLE_VAR "=[0-31] \tsubtitle channel" );
788 /* Input parameters */
789 intf_MsgImm( "\nInput parameters:"
790 "\n " INPUT_SERVER_VAR "=<hostname> \tvideo server"
791 "\n " INPUT_PORT_VAR "=<port> \tvideo server port"
792 "\n " INPUT_IFACE_VAR "=<interface> \tnetwork interface"
793 "\n " INPUT_BROADCAST_VAR "=<addr> \tbroadcast mode"
794 "\n " INPUT_CHANNEL_SERVER_VAR "=<hostname> \tchannel server"
795 "\n " INPUT_CHANNEL_PORT_VAR "=<port> \tchannel server port" );
799 /*****************************************************************************
800 * Version: print complete program version
801 *****************************************************************************
802 * Print complete program version and build number.
803 *****************************************************************************/
804 static void Version( void )
806 intf_MsgImm( VERSION_MESSAGE
807 "This program comes with NO WARRANTY, to the extent permitted by law.\n"
808 "You may redistribute it under the terms of the GNU General Public License;\n"
809 "see the file named COPYING for details.\n"
810 "Written by the VideoLAN team at Ecole Centrale, Paris." );
813 /*****************************************************************************
814 * InitSignalHandler: system signal handler initialization
815 *****************************************************************************
816 * Set the signal handlers. SIGTERM is not intercepted, because we need at
817 * at least a method to kill the program when all other methods failed, and
818 * when we don't want to use SIGKILL.
819 *****************************************************************************/
820 static void InitSignalHandler( void )
822 /* Termination signals */
824 signal( SIGINT, FatalSignalHandler );
825 signal( SIGHUP, FatalSignalHandler );
826 signal( SIGQUIT, FatalSignalHandler );
829 signal( SIGALRM, SimpleSignalHandler );
830 signal( SIGPIPE, SimpleSignalHandler );
835 /*****************************************************************************
836 * SimpleSignalHandler: system signal handler
837 *****************************************************************************
838 * This function is called when a non fatal signal is received by the program.
839 *****************************************************************************/
840 static void SimpleSignalHandler( int i_signal )
842 /* Acknowledge the signal received */
843 intf_WarnMsg( 0, "intf: ignoring signal %d", i_signal );
847 /*****************************************************************************
848 * FatalSignalHandler: system signal handler
849 *****************************************************************************
850 * This function is called when a fatal signal is received by the program.
851 * It tries to end the program in a clean way.
852 *****************************************************************************/
853 static void FatalSignalHandler( int i_signal )
855 /* Once a signal has been trapped, the termination sequence will be
856 * armed and following signals will be ignored to avoid sending messages
857 * to an interface having been destroyed */
859 signal( SIGINT, SIG_IGN );
860 signal( SIGHUP, SIG_IGN );
861 signal( SIGQUIT, SIG_IGN );
864 /* Acknowledge the signal received */
865 intf_ErrMsgImm( "intf error: signal %d received, exiting", i_signal );
867 /* Try to terminate everything - this is done by requesting the end of the
868 * interface thread */
869 p_main->p_intf->b_die = 1;
872 /*****************************************************************************
873 * CPUCapabilities: list the processors MMX support and other capabilities
874 *****************************************************************************
875 * This function is called to list extensions the CPU may have.
876 *****************************************************************************/
877 static int CPUCapabilities( void )
879 int i_capabilities = CPU_CAPABILITY_NONE;
881 #if defined( SYS_BEOS )
882 i_capabilities |= CPU_CAPABILITY_486
884 | CPU_CAPABILITY_MMX;
886 #elif defined( SYS_DARWIN1_3 )
888 struct host_basic_info hi;
890 host_name_port_t host;
893 char *psz_name, *psz_subname;
895 /* Should 'never' fail? */
896 host = mach_host_self();
898 i_size = sizeof( hi ) / sizeof( int );
899 ret = host_info( host, HOST_BASIC_INFO, ( host_info_t )&hi, &i_size );
901 if( ret != KERN_SUCCESS )
903 intf_ErrMsg( "error: couldn't get CPU information" );
904 return( i_capabilities );
907 slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
908 /* FIXME: need better way to detect newer proccessors.
909 * could do strncmp(a,b,5), but that's real ugly */
910 if( strcmp(psz_name, "ppc7400") || strcmp(psz_name, "ppc7450") )
912 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
915 #elif defined( __i386__ )
916 unsigned int i_eax, i_ebx, i_ecx, i_edx;
919 # define cpuid( a ) \
920 asm volatile ( "cpuid" \
928 /* test for a 486 CPU */
929 asm volatile ( "pushfl\n\t"
931 "movl %%eax, %%ebx\n\t"
932 "xorl $0x200000, %%eax\n\t"
944 return( i_capabilities );
947 i_capabilities |= CPU_CAPABILITY_486;
949 /* the CPU supports the CPUID instruction - get its level */
954 return( i_capabilities );
957 /* FIXME: this isn't correct, since some 486s have cpuid */
958 i_capabilities |= CPU_CAPABILITY_586;
960 /* borrowed from mpeg2dec */
961 b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
962 && ( i_edx == 0x69746e65 );
964 /* test for the MMX flag */
967 if( ! (i_edx & 0x00800000) )
969 return( i_capabilities );
972 i_capabilities |= CPU_CAPABILITY_MMX;
974 if( i_edx & 0x02000000 )
976 i_capabilities |= CPU_CAPABILITY_MMXEXT;
977 i_capabilities |= CPU_CAPABILITY_SSE;
980 /* test for additional capabilities */
983 if( i_eax < 0x80000001 )
985 return( i_capabilities );
988 /* list these additional capabilities */
991 if( i_edx & 0x80000000 )
993 i_capabilities |= CPU_CAPABILITY_3DNOW;
996 if( b_amd && ( i_edx & 0x00400000 ) )
998 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1001 /* default behaviour */
1004 return( i_capabilities );