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.83 2001/04/11 02:01:24 henri 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"
79 #include "netutils.h" /* network_ChannelJoin */
83 /*****************************************************************************
84 * Command line options constants. If something is changed here, be sure that
85 * GetConfiguration and Usage are also changed.
86 *****************************************************************************/
88 /* Long options return values - note that values corresponding to short options
89 * chars, and in general any regular char, should be avoided */
90 #define OPT_NOAUDIO 150
91 #define OPT_STEREO 151
94 #define OPT_NOVIDEO 160
95 #define OPT_DISPLAY 161
97 #define OPT_HEIGHT 163
99 #define OPT_FULLSCREEN 165
100 #define OPT_OVERLAY 166
102 #define OPT_CHANNELS 170
103 #define OPT_SERVER 171
105 #define OPT_BROADCAST 173
107 #define OPT_INPUT 180
108 #define OPT_MOTION 181
112 #define OPT_SYNCHRO 190
113 #define OPT_WARNING 191
114 #define OPT_VERSION 192
122 static const struct option longopts[] =
124 /* name, has_arg, flag, val */
126 /* General/common options */
127 { "help", 0, 0, 'h' },
128 { "longhelp", 0, 0, 'H' },
129 { "version", 0, 0, OPT_VERSION },
131 /* Interface options */
132 { "intf", 1, 0, 'I' },
133 { "warning", 1, 0, OPT_WARNING },
136 { "noaudio", 0, 0, OPT_NOAUDIO },
137 { "aout", 1, 0, 'A' },
138 { "stereo", 0, 0, OPT_STEREO },
139 { "mono", 0, 0, OPT_MONO },
142 { "novideo", 0, 0, OPT_NOVIDEO },
143 { "vout", 1, 0, 'V' },
144 { "display", 1, 0, OPT_DISPLAY },
145 { "width", 1, 0, OPT_WIDTH },
146 { "height", 1, 0, OPT_HEIGHT },
147 { "grayscale", 0, 0, 'g' },
148 { "color", 0, 0, OPT_COLOR },
149 { "motion", 1, 0, OPT_MOTION },
150 { "idct", 1, 0, OPT_IDCT },
151 { "yuv", 1, 0, OPT_YUV },
152 { "fullscreen", 0, 0, OPT_FULLSCREEN },
153 { "overlay", 0, 0, OPT_OVERLAY },
156 { "dvdtitle", 1, 0, 't' },
157 { "dvdchapter", 1, 0, 'T' },
158 { "dvdaudio", 1, 0, 'a' },
159 { "dvdchannel", 1, 0, 'c' },
160 { "dvdsubtitle", 1, 0, 's' },
163 { "input", 1, 0, OPT_INPUT },
164 { "channels", 0, 0, OPT_CHANNELS },
165 { "server", 1, 0, OPT_SERVER },
166 { "port", 1, 0, OPT_PORT },
167 { "broadcast", 0, 0, OPT_BROADCAST },
169 /* Synchro options */
170 { "synchro", 1, 0, OPT_SYNCHRO },
175 static const char *psz_shortopts = "hHvgt:T:a:s:c:I:A:V:";
177 /*****************************************************************************
178 * Global variable program_data - this is the one and only, see main.h
179 *****************************************************************************/
182 /*****************************************************************************
184 *****************************************************************************/
185 static int GetConfiguration ( int i_argc, char *ppsz_argv[],
187 static int GetFilenames ( int i_argc, char *ppsz_argv[] );
188 static void Usage ( int i_fashion );
189 static void Version ( void );
191 static void InitSignalHandler ( void );
192 static void SimpleSignalHandler ( int i_signal );
193 static void FatalSignalHandler ( int i_signal );
195 static int CPUCapabilities ( void );
197 /*****************************************************************************
198 * main: parse command line, start interface and spawn threads
199 *****************************************************************************
200 * Steps during program execution are:
201 * -configuration parsing and messages interface initialization
202 * -opening of audio output device and some global modules
203 * -execution of interface, which exit on error or on user request
204 * -closing of audio output device and some global modules
205 * On error, the spawned threads are canceled, and the open devices closed.
206 *****************************************************************************/
207 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
209 main_t main_data; /* root of all data - see main.h */
211 p_main = &main_data; /* set up the global variable */
214 * System specific initialization code
220 p_main->i_cpu_capabilities = CPUCapabilities();
223 * Test if our code is likely to run on this CPU
225 #if defined( __pentium__ ) || defined( __pentiumpro__ )
226 if( ! TestCPU( CPU_CAPABILITY_586 ) )
228 fprintf( stderr, "error: this program needs a Pentium CPU,\n"
229 "please try a version without Pentium support\n" );
235 if( ! TestCPU( CPU_CAPABILITY_MMX ) )
237 fprintf( stderr, "error: this program needs MMX extensions,\n"
238 "please try a version without MMX support\n" );
244 * Initialize messages interface
246 p_main->p_msg = intf_MsgCreate();
247 if( !p_main->p_msg ) /* start messages interface */
249 fprintf( stderr, "error: can't initialize messages interface (%s)\n",
254 intf_MsgImm( COPYRIGHT_MESSAGE );
259 if( GetConfiguration( i_argc, ppsz_argv, ppsz_env ) ) /* parse cmd line */
266 * Initialize playlist and get commandline files
268 p_main->p_playlist = intf_PlaylistCreate( );
269 if( !p_main->p_playlist )
271 intf_ErrMsg( "playlist error: playlist initialization failed" );
275 intf_PlaylistInit( p_main->p_playlist );
278 * Get input filenames given as commandline arguments
280 GetFilenames( i_argc, ppsz_argv );
283 * Initialize module bank
285 p_main->p_bank = module_CreateBank( );
286 if( !p_main->p_bank )
288 intf_ErrMsg( "module error: module bank initialization failed" );
289 intf_PlaylistDestroy( p_main->p_playlist );
293 module_InitBank( p_main->p_bank );
296 * Initialize shared resources and libraries
298 if( p_main->b_channels && network_ChannelCreate() )
300 /* On error during Channels initialization, switch off channels */
301 intf_Msg( "Channels initialization failed : "
302 "Channel management is deactivated" );
303 p_main->b_channels = 0;
309 p_main->p_intf = intf_Create();
310 if( !p_main->p_intf )
312 intf_ErrMsg( "intf error: interface initialization failed" );
313 module_DestroyBank( p_main->p_bank );
314 intf_PlaylistDestroy( p_main->p_playlist );
320 * Set signal handling policy for all threads
325 * Open audio device and start aout thread
327 if( p_main->b_audio )
329 p_main->p_aout = aout_CreateThread( NULL );
330 if( p_main->p_aout == NULL )
332 /* On error during audio initialization, switch off audio */
333 intf_ErrMsg( "aout error: audio initialization failed,"
334 " audio is deactivated" );
340 * Open video device and start vout thread
342 if( p_main->b_video )
344 p_main->p_vout = vout_CreateThread( NULL );
345 if( p_main->p_vout == NULL )
347 /* On error during video initialization, switch off video */
348 intf_ErrMsg( "vout error: video initialization failed,"
349 " video is deactivated" );
354 /* Flush messages before entering the main loop */
358 * This is the main loop
360 p_main->p_intf->pf_run( p_main->p_intf );
362 intf_Destroy( p_main->p_intf );
367 if( p_main->b_video )
369 vout_DestroyThread( p_main->p_vout, NULL );
375 if( p_main->b_audio )
377 aout_DestroyThread( p_main->p_aout, NULL );
381 * Go back into channel 0 which is the network
383 if( p_main->b_channels )
385 network_ChannelJoin( COMMON_CHANNEL );
391 module_DestroyBank( p_main->p_bank );
396 intf_PlaylistDestroy( p_main->p_playlist );
400 * System specific cleaning code
406 * Terminate messages interface and program
408 intf_Msg( "intf: program terminated" );
414 /*****************************************************************************
415 * main_GetIntVariable: get the int value of an environment variable
416 *****************************************************************************
417 * This function is used to read some default parameters in modules.
418 *****************************************************************************/
419 int main_GetIntVariable( char *psz_name, int i_default )
421 char * psz_env; /* environment value */
422 char * psz_end; /* end of parsing index */
423 long int i_value; /* value */
425 psz_env = getenv( psz_name );
428 i_value = strtol( psz_env, &psz_end, 0 );
429 if( (*psz_env != '\0') && (*psz_end == '\0') )
437 /*****************************************************************************
438 * main_GetPszVariable: get the string value of an environment variable
439 *****************************************************************************
440 * This function is used to read some default parameters in modules.
441 *****************************************************************************/
442 char * main_GetPszVariable( char *psz_name, char *psz_default )
446 psz_env = getenv( psz_name );
451 return( psz_default );
454 /*****************************************************************************
455 * main_PutPszVariable: set the string value of an environment variable
456 *****************************************************************************
457 * This function is used to set some default parameters in modules. The use of
458 * this function will cause some memory leak: since some systems use the pointer
459 * passed to putenv to store the environment string, it can't be freed.
460 *****************************************************************************/
461 void main_PutPszVariable( char *psz_name, char *psz_value )
465 psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
466 if( psz_env == NULL )
468 intf_ErrMsg( "intf error: cannot create psz_env (%s)",
473 sprintf( psz_env, "%s=%s", psz_name, psz_value );
474 if( putenv( psz_env ) )
476 intf_ErrMsg( "intf error: cannot putenv (%s)", strerror(errno) );
481 /*****************************************************************************
482 * main_PutIntVariable: set the integer value of an environment variable
483 *****************************************************************************
484 * This function is used to set some default parameters in modules. The use of
485 * this function will cause some memory leak: since some systems use the pointer
486 * passed to putenv to store the environment string, it can't be freed.
487 *****************************************************************************/
488 void main_PutIntVariable( char *psz_name, int i_value )
490 char psz_value[ 256 ]; /* buffer for value */
492 sprintf( psz_value, "%d", i_value );
493 main_PutPszVariable( psz_name, psz_value );
496 /* following functions are local */
498 /*****************************************************************************
499 * GetConfiguration: parse command line
500 *****************************************************************************
501 * Parse command line and configuration file for configuration. If the inline
502 * help is requested, the function Usage() is called and the function returns
503 * -1 (causing main() to exit). The messages interface is initialized at this
504 * stage, but most structures are not allocated, so only environment should
506 *****************************************************************************/
507 static int GetConfiguration( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
512 /* Set default configuration and copy arguments */
513 p_main->i_argc = i_argc;
514 p_main->ppsz_argv = ppsz_argv;
515 p_main->ppsz_env = ppsz_env;
519 p_main->b_channels = 0;
521 p_main->i_warning_level = 4;
523 /* Get the executable name (similar to the basename command) */
524 p_main->psz_arg0 = p_tmp = ppsz_argv[ 0 ];
529 p_main->psz_arg0 = ++p_tmp;
537 /* Parse command line options */
539 while( ( i_cmd = getopt_long( i_argc, ppsz_argv,
540 psz_shortopts, longopts, 0 ) ) != EOF )
544 /* General/common options */
545 case 'h': /* -h, --help */
549 case 'H': /* -H, --longhelp */
553 case OPT_VERSION: /* --version */
557 case 'v': /* -v, --verbose */
558 p_main->i_warning_level--;
561 /* Interface warning messages level */
562 case 'I': /* -I, --intf */
563 main_PutPszVariable( INTF_METHOD_VAR, optarg );
565 case OPT_WARNING: /* --warning */
566 intf_ErrMsg( "intf error: `--warning' is deprecated, use `-v'" );
567 p_main->i_warning_level = atoi(optarg);
571 case OPT_NOAUDIO: /* --noaudio */
574 case 'A': /* -A, --aout */
575 main_PutPszVariable( AOUT_METHOD_VAR, optarg );
577 case OPT_STEREO: /* --stereo */
578 main_PutIntVariable( AOUT_STEREO_VAR, 1 );
580 case OPT_MONO: /* --mono */
581 main_PutIntVariable( AOUT_STEREO_VAR, 0 );
585 case OPT_NOVIDEO: /* --novideo */
588 case 'V': /* -V, --vout */
589 main_PutPszVariable( VOUT_METHOD_VAR, optarg );
591 case OPT_DISPLAY: /* --display */
592 main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
594 case OPT_WIDTH: /* --width */
595 main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
597 case OPT_HEIGHT: /* --height */
598 main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
600 case 'g': /* -g, --grayscale */
601 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
603 case OPT_COLOR: /* --color */
604 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
606 case OPT_FULLSCREEN: /* --fullscreen */
607 main_PutIntVariable( VOUT_FULLSCREEN_VAR, 1 );
609 case OPT_OVERLAY: /* --overlay */
610 main_PutIntVariable( VOUT_OVERLAY_VAR, 1 );
612 case OPT_MOTION: /* --motion */
613 main_PutPszVariable( MOTION_METHOD_VAR, optarg );
615 case OPT_IDCT: /* --idct */
616 main_PutPszVariable( IDCT_METHOD_VAR, optarg );
618 case OPT_YUV: /* --yuv */
619 main_PutPszVariable( YUV_METHOD_VAR, optarg );
624 main_PutIntVariable( INPUT_TITLE_VAR, atoi(optarg) );
627 main_PutIntVariable( INPUT_CHAPTER_VAR, atoi(optarg) );
630 if ( ! strcmp(optarg, "ac3") )
631 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_AC3 );
632 else if ( ! strcmp(optarg, "lpcm") )
633 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_LPCM );
634 else if ( ! strcmp(optarg, "mpeg") )
635 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_MPEG );
637 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_NOAUDIO );
640 main_PutIntVariable( INPUT_CHANNEL_VAR, atoi(optarg) );
643 main_PutIntVariable( INPUT_SUBTITLE_VAR, atoi(optarg) );
647 case OPT_INPUT: /* --input */
648 main_PutPszVariable( INPUT_METHOD_VAR, optarg );
650 case OPT_CHANNELS: /* --channels */
651 p_main->b_channels = 1;
653 case OPT_SERVER: /* --server */
654 main_PutPszVariable( INPUT_SERVER_VAR, optarg );
656 case OPT_PORT: /* --port */
657 main_PutPszVariable( INPUT_PORT_VAR, optarg );
659 case OPT_BROADCAST: /* --broadcast */
660 main_PutIntVariable( INPUT_BROADCAST_VAR, 1 );
663 /* Synchro options */
665 main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
668 /* Internal error: unknown option */
671 intf_ErrMsg( "intf error: unknown option `%s'",
672 ppsz_argv[optind - 1] );
679 if( p_main->i_warning_level < 0 )
681 p_main->i_warning_level = 0;
687 /*****************************************************************************
688 * GetFilenames: parse command line options which are not flags
689 *****************************************************************************
690 * Parse command line for input files.
691 *****************************************************************************/
692 static int GetFilenames( int i_argc, char *ppsz_argv[] )
696 /* We assume that the remaining parameters are filenames */
697 for( i_opt = optind; i_opt < i_argc; i_opt++ )
699 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
700 ppsz_argv[ i_opt ] );
706 /*****************************************************************************
707 * Usage: print program usage
708 *****************************************************************************
709 * Print a short inline help. Message interface is initialized at this stage.
710 *****************************************************************************/
711 static void Usage( int i_fashion )
714 intf_MsgImm( "Usage: %s [options] [parameters] [file]...",
717 if( i_fashion == USAGE )
719 intf_MsgImm( "Try `%s --help' for more information.",
725 intf_MsgImm( "\nOptions:"
726 "\n -I, --intf <module> \tinterface method"
727 "\n -v, --verbose \tverbose mode (cumulative)"
729 "\n --noaudio \tdisable audio"
730 "\n -A, --aout <module> \taudio output method"
731 "\n --stereo, --mono \tstereo/mono audio"
733 "\n --novideo \tdisable video"
734 "\n -V, --vout <module> \tvideo output method"
735 "\n --display <display> \tdisplay string"
736 "\n --width <w>, --height <h> \tdisplay dimensions"
737 "\n -g, --grayscale \tgrayscale output"
738 "\n --fullscreen \tfullscreen output"
739 "\n --overlay \taccelerated display"
740 "\n --color \tcolor output"
741 "\n --motion <module> \tmotion compensation method"
742 "\n --idct <module> \tIDCT method"
743 "\n --yuv <module> \tYUV method"
744 "\n --synchro <type> \tforce synchro algorithm"
746 "\n -t, --dvdtitle <num> \tchoose DVD title"
747 "\n -T, --dvdchapter <num> \tchoose DVD chapter"
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_RATE_VAR "=<rate> \toutput rate" );
778 /* Video parameters */
779 intf_MsgImm( "\nVideo parameters:"
780 "\n " VOUT_METHOD_VAR "=<method name> \tdisplay method"
781 "\n " VOUT_DISPLAY_VAR "=<display name> \tdisplay used"
782 "\n " VOUT_WIDTH_VAR "=<width> \tdisplay width"
783 "\n " VOUT_HEIGHT_VAR "=<height> \tdislay height"
784 "\n " VOUT_FB_DEV_VAR "=<filename> \tframebuffer device path"
785 "\n " VOUT_GRAYSCALE_VAR "={1|0} \tgrayscale or color output"
786 "\n " VOUT_FULLSCREEN_VAR "={1|0} \tfullscreen"
787 "\n " VOUT_OVERLAY_VAR "={1|0} \toverlay"
788 "\n " MOTION_METHOD_VAR "=<method name> \tmotion compensation method"
789 "\n " IDCT_METHOD_VAR "=<method name> \tIDCT method"
790 "\n " YUV_METHOD_VAR "=<method name> \tYUV method"
791 "\n " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB} \tsynchro algorithm" );
794 intf_MsgImm( "\nDVD parameters:"
795 "\n " INPUT_DVD_DEVICE_VAR "=<device> \tDVD device"
796 "\n " INPUT_TITLE_VAR "=<title> \ttitle number"
797 "\n " INPUT_CHAPTER_VAR "=<chapter> \tchapter number"
798 "\n " INPUT_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type"
799 "\n " INPUT_CHANNEL_VAR "=[0-15] \taudio channel"
800 "\n " INPUT_SUBTITLE_VAR "=[0-31] \tsubtitle channel" );
802 /* Input parameters */
803 intf_MsgImm( "\nInput parameters:"
804 "\n " INPUT_SERVER_VAR "=<hostname> \tvideo server"
805 "\n " INPUT_PORT_VAR "=<port> \tvideo server port"
806 "\n " INPUT_IFACE_VAR "=<interface> \tnetwork interface"
807 "\n " INPUT_BROADCAST_VAR "={1|0} \tbroadcast mode"
808 "\n " INPUT_CHANNEL_SERVER_VAR "=<hostname> \tchannel server"
809 "\n " INPUT_CHANNEL_PORT_VAR "=<port> \tchannel server port" );
813 /*****************************************************************************
814 * Version: print complete program version
815 *****************************************************************************
816 * Print complete program version and build number.
817 *****************************************************************************/
818 static void Version( void )
820 intf_MsgImm( VERSION_MESSAGE
821 "This program comes with NO WARRANTY, to the extent permitted by law.\n"
822 "You may redistribute it under the terms of the GNU General Public License;\n"
823 "see the file named COPYING for details.\n"
824 "Written by the VideoLAN team at Ecole Centrale, Paris." );
827 /*****************************************************************************
828 * InitSignalHandler: system signal handler initialization
829 *****************************************************************************
830 * Set the signal handlers. SIGTERM is not intercepted, because we need at
831 * at least a method to kill the program when all other methods failed, and
832 * when we don't want to use SIGKILL.
833 *****************************************************************************/
834 static void InitSignalHandler( void )
836 /* Termination signals */
837 signal( SIGHUP, FatalSignalHandler );
838 signal( SIGINT, FatalSignalHandler );
839 signal( SIGQUIT, FatalSignalHandler );
842 signal( SIGALRM, SimpleSignalHandler );
843 signal( SIGPIPE, SimpleSignalHandler );
847 /*****************************************************************************
848 * SimpleSignalHandler: system signal handler
849 *****************************************************************************
850 * This function is called when a non fatal signal is received by the program.
851 *****************************************************************************/
852 static void SimpleSignalHandler( int i_signal )
854 /* Acknowledge the signal received */
855 intf_WarnMsg( 0, "intf: ignoring signal %d", i_signal );
859 /*****************************************************************************
860 * FatalSignalHandler: system signal handler
861 *****************************************************************************
862 * This function is called when a fatal signal is received by the program.
863 * It tries to end the program in a clean way.
864 *****************************************************************************/
865 static void FatalSignalHandler( int i_signal )
867 /* Once a signal has been trapped, the termination sequence will be
868 * armed and following signals will be ignored to avoid sending messages
869 * to an interface having been destroyed */
870 signal( SIGHUP, SIG_IGN );
871 signal( SIGINT, SIG_IGN );
872 signal( SIGQUIT, SIG_IGN );
874 /* Acknowledge the signal received */
875 intf_ErrMsgImm( "intf error: signal %d received, exiting", i_signal );
877 /* Try to terminate everything - this is done by requesting the end of the
878 * interface thread */
879 p_main->p_intf->b_die = 1;
882 /*****************************************************************************
883 * CPUCapabilities: list the processors MMX support and other capabilities
884 *****************************************************************************
885 * This function is called to list extensions the CPU may have.
886 *****************************************************************************/
887 static int CPUCapabilities( void )
889 int i_capabilities = CPU_CAPABILITY_NONE;
891 #if defined( SYS_BEOS )
892 i_capabilities |= CPU_CAPABILITY_486
894 | CPU_CAPABILITY_MMX;
896 #elif defined( SYS_DARWIN1_3 )
898 struct host_basic_info hi;
900 host_name_port_t host;
903 char *psz_name, *psz_subname;
905 /* Should 'never' fail? */
906 host = mach_host_self();
908 i_size = sizeof( hi ) / sizeof( int );
909 ret = host_info( host, HOST_BASIC_INFO, ( host_info_t )&hi, &i_size );
911 if( ret != KERN_SUCCESS )
913 intf_ErrMsg( "error: couldn't get CPU information" );
914 return( i_capabilities );
917 slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
918 /* FIXME: need better way to detect newer proccessors.
919 * could do strncmp(a,b,5), but that's real ugly */
920 if( strcmp(psz_name, "ppc7400") || strcmp(psz_name, "ppc7450") )
922 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
925 #elif defined( __i386__ )
926 unsigned int i_eax, i_ebx, i_ecx, i_edx;
929 # define cpuid( a ) \
930 asm volatile ( "cpuid" \
938 /* test for a 486 CPU */
939 asm volatile ( "pushfl\n\t"
941 "movl %%eax, %%ebx\n\t"
942 "xorl $0x200000, %%eax\n\t"
954 return( i_capabilities );
957 i_capabilities |= CPU_CAPABILITY_486;
959 /* the CPU supports the CPUID instruction - get its level */
964 return( i_capabilities );
967 /* FIXME: this isn't correct, since some 486s have cpuid */
968 i_capabilities |= CPU_CAPABILITY_586;
970 /* borrowed from mpeg2dec */
971 b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
972 && ( i_edx == 0x69746e65 );
974 /* test for the MMX flag */
977 if( ! (i_edx & 0x00800000) )
979 return( i_capabilities );
982 i_capabilities |= CPU_CAPABILITY_MMX;
984 if( i_edx & 0x02000000 )
986 i_capabilities |= CPU_CAPABILITY_MMXEXT;
989 /* test for additional capabilities */
992 if( i_eax < 0x80000001 )
994 return( i_capabilities );
997 /* list these additional capabilities */
1000 if( i_edx & 0x80000000 )
1002 i_capabilities |= CPU_CAPABILITY_3DNOW;
1005 if( b_amd && ( i_edx & 0x00400000 ) )
1007 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1011 /* default behaviour */
1014 return( i_capabilities );