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.90 2001/04/29 02:48:51 stef 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 - this is the one and only, see main.h
186 *****************************************************************************/
189 /*****************************************************************************
191 *****************************************************************************/
192 static int GetConfiguration ( int *pi_argc, char *ppsz_argv[],
194 static int GetFilenames ( int i_argc, char *ppsz_argv[] );
195 static void Usage ( int i_fashion );
196 static void Version ( void );
198 static void InitSignalHandler ( void );
199 static void SimpleSignalHandler ( int i_signal );
200 static void FatalSignalHandler ( int i_signal );
202 static int CPUCapabilities ( void );
204 /*****************************************************************************
205 * main: parse command line, start interface and spawn threads
206 *****************************************************************************
207 * Steps during program execution are:
208 * -configuration parsing and messages interface initialization
209 * -opening of audio output device and some global modules
210 * -execution of interface, which exit on error or on user request
211 * -closing of audio output device and some global modules
212 * On error, the spawned threads are canceled, and the open devices closed.
213 *****************************************************************************/
214 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
216 main_t main_data; /* root of all data - see main.h */
218 p_main = &main_data; /* set up the global variable */
221 * System specific initialization code
223 #if defined( SYS_BEOS ) || defined( SYS_DARWIN1_3 )
224 system_Create( &i_argc, ppsz_argv, ppsz_env );
227 p_main->i_cpu_capabilities = CPUCapabilities();
230 * Test if our code is likely to run on this CPU
232 #if defined( __pentium__ ) || defined( __pentiumpro__ )
233 if( ! TestCPU( CPU_CAPABILITY_586 ) )
235 fprintf( stderr, "error: this program needs a Pentium CPU,\n"
236 "please try a version without Pentium support\n" );
242 if( ! TestCPU( CPU_CAPABILITY_MMX ) )
244 fprintf( stderr, "error: this program needs MMX extensions,\n"
245 "please try a version without MMX support\n" );
251 * Initialize messages interface
253 p_main->p_msg = intf_MsgCreate();
254 if( !p_main->p_msg ) /* start messages interface */
256 fprintf( stderr, "error: can't initialize messages interface (%s)\n",
261 intf_MsgImm( COPYRIGHT_MESSAGE );
266 if( GetConfiguration( &i_argc, ppsz_argv, ppsz_env ) ) /* parse cmd line */
273 * Initialize playlist and get commandline files
275 p_main->p_playlist = intf_PlaylistCreate( );
276 if( !p_main->p_playlist )
278 intf_ErrMsg( "playlist error: playlist initialization failed" );
282 intf_PlaylistInit( p_main->p_playlist );
285 * Get input filenames given as commandline arguments
287 GetFilenames( i_argc, ppsz_argv );
290 * Initialize module bank
292 p_main->p_bank = module_CreateBank( );
293 if( !p_main->p_bank )
295 intf_ErrMsg( "module error: module bank initialization failed" );
296 intf_PlaylistDestroy( p_main->p_playlist );
300 module_InitBank( p_main->p_bank );
303 * Initialize shared resources and libraries
305 if( p_main->b_channels && network_ChannelCreate() )
307 /* On error during Channels initialization, switch off channels */
308 intf_Msg( "Channels initialization failed : "
309 "Channel management is deactivated" );
310 p_main->b_channels = 0;
316 p_main->p_intf = intf_Create();
317 if( !p_main->p_intf )
319 intf_ErrMsg( "intf error: interface initialization failed" );
320 module_DestroyBank( p_main->p_bank );
321 intf_PlaylistDestroy( p_main->p_playlist );
327 * Set signal handling policy for all threads
332 * Open audio device and start aout thread
334 if( p_main->b_audio )
336 p_main->p_aout = aout_CreateThread( NULL );
337 if( p_main->p_aout == NULL )
339 /* On error during audio initialization, switch off audio */
340 intf_ErrMsg( "aout error: audio initialization failed,"
341 " audio is deactivated" );
347 * Open video device and start vout thread
349 if( p_main->b_video )
351 p_main->p_vout = vout_CreateThread( NULL );
352 if( p_main->p_vout == NULL )
354 /* On error during video initialization, switch off video */
355 intf_ErrMsg( "vout error: video initialization failed,"
356 " video is deactivated" );
361 /* Flush messages before entering the main loop */
365 * This is the main loop
367 p_main->p_intf->pf_run( p_main->p_intf );
369 intf_Destroy( p_main->p_intf );
374 if( p_main->b_video )
376 vout_DestroyThread( p_main->p_vout, NULL );
382 if( p_main->b_audio )
384 aout_DestroyThread( p_main->p_aout, NULL );
388 * Go back into channel 0 which is the network
390 if( p_main->b_channels )
392 network_ChannelJoin( COMMON_CHANNEL );
398 module_DestroyBank( p_main->p_bank );
403 intf_PlaylistDestroy( p_main->p_playlist );
406 * System specific cleaning code
408 #if defined( SYS_BEOS ) || defined( SYS_DARWIN1_3 )
413 * Terminate messages interface and program
415 intf_Msg( "intf: program terminated" );
421 /*****************************************************************************
422 * main_GetIntVariable: get the int value of an environment variable
423 *****************************************************************************
424 * This function is used to read some default parameters in modules.
425 *****************************************************************************/
426 int main_GetIntVariable( char *psz_name, int i_default )
428 char * psz_env; /* environment value */
429 char * psz_end; /* end of parsing index */
430 long int i_value; /* value */
432 psz_env = getenv( psz_name );
435 i_value = strtol( psz_env, &psz_end, 0 );
436 if( (*psz_env != '\0') && (*psz_end == '\0') )
444 /*****************************************************************************
445 * main_GetPszVariable: get the string value of an environment variable
446 *****************************************************************************
447 * This function is used to read some default parameters in modules.
448 *****************************************************************************/
449 char * main_GetPszVariable( char *psz_name, char *psz_default )
453 psz_env = getenv( psz_name );
458 return( psz_default );
461 /*****************************************************************************
462 * main_PutPszVariable: set the string value of an environment variable
463 *****************************************************************************
464 * This function is used to set some default parameters in modules. The use of
465 * this function will cause some memory leak: since some systems use the pointer
466 * passed to putenv to store the environment string, it can't be freed.
467 *****************************************************************************/
468 void main_PutPszVariable( char *psz_name, char *psz_value )
472 psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
473 if( psz_env == NULL )
475 intf_ErrMsg( "intf error: cannot create psz_env (%s)",
480 sprintf( psz_env, "%s=%s", psz_name, psz_value );
481 if( putenv( psz_env ) )
483 intf_ErrMsg( "intf error: cannot putenv (%s)", strerror(errno) );
488 /*****************************************************************************
489 * main_PutIntVariable: set the integer value of an environment variable
490 *****************************************************************************
491 * This function is used to set some default parameters in modules. The use of
492 * this function will cause some memory leak: since some systems use the pointer
493 * passed to putenv to store the environment string, it can't be freed.
494 *****************************************************************************/
495 void main_PutIntVariable( char *psz_name, int i_value )
497 char psz_value[ 256 ]; /* buffer for value */
499 sprintf( psz_value, "%d", i_value );
500 main_PutPszVariable( psz_name, psz_value );
503 /* following functions are local */
505 /*****************************************************************************
506 * GetConfiguration: parse command line
507 *****************************************************************************
508 * Parse command line and configuration file for configuration. If the inline
509 * help is requested, the function Usage() is called and the function returns
510 * -1 (causing main() to exit). The messages interface is initialized at this
511 * stage, but most structures are not allocated, so only environment should
513 *****************************************************************************/
514 static int GetConfiguration( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
519 /* Set default configuration and copy arguments */
520 p_main->i_argc = *pi_argc;
521 p_main->ppsz_argv = ppsz_argv;
522 p_main->ppsz_env = ppsz_env;
526 p_main->b_channels = 0;
529 p_main->i_warning_level = 4;
531 /* Get the executable name (similar to the basename command) */
532 p_main->psz_arg0 = p_tmp = ppsz_argv[ 0 ];
537 p_main->psz_arg0 = ++p_tmp;
546 /* When vlc.app is run by double clicking in Mac OS X, the 2nd arg
547 * is the PSN - process serial number (a unique PID-ish thingie)
548 * still ok for real Darwin & when run from command line */
549 if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
550 /* for example -psn_0_9306113 */
552 /* GDMF!... I can't do this or else the MacOSX window server will
553 * not pick up the PSN and not register the app and we crash...
554 * hence the following kludge otherwise we'll get confused w/ argv[1]
555 * being an input file name */
557 ppsz_argv[ 1 ] = NULL;
559 *pi_argc = *pi_argc - 1;
565 /* Parse command line options */
567 while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv,
568 psz_shortopts, longopts, 0 ) ) != EOF )
572 /* General/common options */
573 case 'h': /* -h, --help */
577 case 'H': /* -H, --longhelp */
581 case OPT_VERSION: /* --version */
585 case 'v': /* -v, --verbose */
586 p_main->i_warning_level--;
589 /* Interface warning messages level */
590 case 'I': /* -I, --intf */
591 main_PutPszVariable( INTF_METHOD_VAR, optarg );
593 case OPT_WARNING: /* --warning */
594 intf_ErrMsg( "intf error: `--warning' is deprecated, use `-v'" );
595 p_main->i_warning_level = atoi(optarg);
599 case OPT_NOAUDIO: /* --noaudio */
602 case 'A': /* -A, --aout */
603 main_PutPszVariable( AOUT_METHOD_VAR, optarg );
605 case OPT_STEREO: /* --stereo */
606 main_PutIntVariable( AOUT_STEREO_VAR, 1 );
608 case OPT_MONO: /* --mono */
609 main_PutIntVariable( AOUT_STEREO_VAR, 0 );
611 case OPT_SPDIF: /* --spdif */
616 case OPT_NOVIDEO: /* --novideo */
619 case 'V': /* -V, --vout */
620 main_PutPszVariable( VOUT_METHOD_VAR, optarg );
622 case OPT_DISPLAY: /* --display */
623 main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
625 case OPT_WIDTH: /* --width */
626 main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
628 case OPT_HEIGHT: /* --height */
629 main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
631 case 'g': /* -g, --grayscale */
632 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
634 case OPT_COLOR: /* --color */
635 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
637 case OPT_FULLSCREEN: /* --fullscreen */
638 main_PutIntVariable( VOUT_FULLSCREEN_VAR, 1 );
640 case OPT_OVERLAY: /* --overlay */
641 main_PutIntVariable( VOUT_OVERLAY_VAR, 1 );
643 case OPT_MOTION: /* --motion */
644 main_PutPszVariable( MOTION_METHOD_VAR, optarg );
646 case OPT_IDCT: /* --idct */
647 main_PutPszVariable( IDCT_METHOD_VAR, optarg );
649 case OPT_YUV: /* --yuv */
650 main_PutPszVariable( YUV_METHOD_VAR, optarg );
655 main_PutIntVariable( INPUT_TITLE_VAR, atoi(optarg) );
658 main_PutIntVariable( INPUT_CHAPTER_VAR, atoi(optarg) );
661 main_PutIntVariable( INPUT_ANGLE_VAR, atoi(optarg) );
664 if ( ! strcmp(optarg, "ac3") )
665 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_AC3 );
666 else if ( ! strcmp(optarg, "lpcm") )
667 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_LPCM );
668 else if ( ! strcmp(optarg, "mpeg") )
669 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_MPEG );
671 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_NOAUDIO );
674 main_PutIntVariable( INPUT_CHANNEL_VAR, atoi(optarg) );
677 main_PutIntVariable( INPUT_SUBTITLE_VAR, atoi(optarg) );
681 case OPT_INPUT: /* --input */
682 main_PutPszVariable( INPUT_METHOD_VAR, optarg );
684 case OPT_CHANNELS: /* --channels */
685 p_main->b_channels = 1;
687 case OPT_SERVER: /* --server */
688 main_PutPszVariable( INPUT_SERVER_VAR, optarg );
690 case OPT_PORT: /* --port */
691 main_PutPszVariable( INPUT_PORT_VAR, optarg );
693 case OPT_BROADCAST: /* --broadcast */
694 main_PutPszVariable( INPUT_BROADCAST_VAR, optarg );
697 /* Synchro options */
699 main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
702 /* Internal error: unknown option */
705 intf_ErrMsg( "intf error: unknown option `%s'",
706 ppsz_argv[optind - 1] );
713 if( p_main->i_warning_level < 0 )
715 p_main->i_warning_level = 0;
721 /*****************************************************************************
722 * GetFilenames: parse command line options which are not flags
723 *****************************************************************************
724 * Parse command line for input files.
725 *****************************************************************************/
726 static int GetFilenames( int i_argc, char *ppsz_argv[] )
730 /* We assume that the remaining parameters are filenames */
731 for( i_opt = optind; i_opt < i_argc; i_opt++ )
733 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
734 ppsz_argv[ i_opt ] );
740 /*****************************************************************************
741 * Usage: print program usage
742 *****************************************************************************
743 * Print a short inline help. Message interface is initialized at this stage.
744 *****************************************************************************/
745 static void Usage( int i_fashion )
748 intf_MsgImm( "Usage: %s [options] [parameters] [file]...",
751 if( i_fashion == USAGE )
753 intf_MsgImm( "Try `%s --help' for more information.",
759 intf_MsgImm( "\nOptions:"
760 "\n -I, --intf <module> \tinterface method"
761 "\n -v, --verbose \tverbose mode (cumulative)"
763 "\n --noaudio \tdisable audio"
764 "\n -A, --aout <module> \taudio output method"
765 "\n --stereo, --mono \tstereo/mono audio"
766 "\n --spdif \tac3 pass-through mode"
768 "\n --novideo \tdisable video"
769 "\n -V, --vout <module> \tvideo output method"
770 "\n --display <display> \tdisplay string"
771 "\n --width <w>, --height <h> \tdisplay dimensions"
772 "\n -g, --grayscale \tgrayscale output"
773 "\n --fullscreen \tfullscreen output"
774 "\n --overlay \taccelerated display"
775 "\n --color \tcolor output"
776 "\n --motion <module> \tmotion compensation method"
777 "\n --idct <module> \tIDCT method"
778 "\n --yuv <module> \tYUV method"
779 "\n --synchro <type> \tforce synchro algorithm"
781 "\n -t, --dvdtitle <num> \tchoose DVD title"
782 "\n -T, --dvdchapter <num> \tchoose DVD chapter"
783 "\n -u, --dvdangle <num> \tchoose DVD angle"
784 "\n -a, --dvdaudio <type> \tchoose DVD audio type"
785 "\n -c, --dvdchannel <channel> \tchoose DVD audio channel"
786 "\n -s, --dvdsubtitle <channel> \tchoose DVD subtitle channel"
788 "\n --input \tinput method"
789 "\n --channels \tenable channels"
790 "\n --server <host> \tvideo server address"
791 "\n --port <port> \tvideo server port"
792 "\n --broadcast \tlisten to a broadcast"
794 "\n -h, --help \tprint help and exit"
795 "\n -H, --longhelp \tprint long help and exit"
796 "\n --version \toutput version information and exit" );
798 if( i_fashion == SHORT_HELP )
801 /* Interface parameters */
802 intf_MsgImm( "\nInterface parameters:"
803 "\n " INTF_METHOD_VAR "=<method name> \tinterface method"
804 "\n " INTF_INIT_SCRIPT_VAR "=<filename> \tinitialization script"
805 "\n " INTF_CHANNELS_VAR "=<filename> \tchannels list" );
807 /* Audio parameters */
808 intf_MsgImm( "\nAudio parameters:"
809 "\n " AOUT_METHOD_VAR "=<method name> \taudio method"
810 "\n " AOUT_DSP_VAR "=<filename> \tdsp device path"
811 "\n " AOUT_STEREO_VAR "={1|0} \tstereo or mono output"
812 "\n " AOUT_RATE_VAR "=<rate> \toutput rate" );
814 /* Video parameters */
815 intf_MsgImm( "\nVideo parameters:"
816 "\n " VOUT_METHOD_VAR "=<method name> \tdisplay method"
817 "\n " VOUT_DISPLAY_VAR "=<display name> \tdisplay used"
818 "\n " VOUT_WIDTH_VAR "=<width> \tdisplay width"
819 "\n " VOUT_HEIGHT_VAR "=<height> \tdislay height"
820 "\n " VOUT_FB_DEV_VAR "=<filename> \tframebuffer device path"
821 "\n " VOUT_GRAYSCALE_VAR "={1|0} \tgrayscale or color output"
822 "\n " VOUT_FULLSCREEN_VAR "={1|0} \tfullscreen"
823 "\n " VOUT_OVERLAY_VAR "={1|0} \toverlay"
824 "\n " MOTION_METHOD_VAR "=<method name> \tmotion compensation method"
825 "\n " IDCT_METHOD_VAR "=<method name> \tIDCT method"
826 "\n " YUV_METHOD_VAR "=<method name> \tYUV method"
827 "\n " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB} \tsynchro algorithm" );
830 intf_MsgImm( "\nDVD parameters:"
831 "\n " INPUT_DVD_DEVICE_VAR "=<device> \tDVD device"
832 "\n " INPUT_TITLE_VAR "=<title> \ttitle number"
833 "\n " INPUT_CHAPTER_VAR "=<chapter> \tchapter number"
834 "\n " INPUT_ANGLE_VAR "=<angle> \tangle number"
835 "\n " INPUT_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type"
836 "\n " INPUT_CHANNEL_VAR "=[0-15] \taudio channel"
837 "\n " INPUT_SUBTITLE_VAR "=[0-31] \tsubtitle channel" );
839 /* Input parameters */
840 intf_MsgImm( "\nInput parameters:"
841 "\n " INPUT_SERVER_VAR "=<hostname> \tvideo server"
842 "\n " INPUT_PORT_VAR "=<port> \tvideo server port"
843 "\n " INPUT_IFACE_VAR "=<interface> \tnetwork interface"
844 "\n " INPUT_BROADCAST_VAR "=<addr> \tbroadcast mode"
845 "\n " INPUT_CHANNEL_SERVER_VAR "=<hostname> \tchannel server"
846 "\n " INPUT_CHANNEL_PORT_VAR "=<port> \tchannel server port" );
850 /*****************************************************************************
851 * Version: print complete program version
852 *****************************************************************************
853 * Print complete program version and build number.
854 *****************************************************************************/
855 static void Version( void )
857 intf_MsgImm( VERSION_MESSAGE
858 "This program comes with NO WARRANTY, to the extent permitted by law.\n"
859 "You may redistribute it under the terms of the GNU General Public License;\n"
860 "see the file named COPYING for details.\n"
861 "Written by the VideoLAN team at Ecole Centrale, Paris." );
864 /*****************************************************************************
865 * InitSignalHandler: system signal handler initialization
866 *****************************************************************************
867 * Set the signal handlers. SIGTERM is not intercepted, because we need at
868 * at least a method to kill the program when all other methods failed, and
869 * when we don't want to use SIGKILL.
870 *****************************************************************************/
871 static void InitSignalHandler( void )
873 /* Termination signals */
875 signal( SIGINT, FatalSignalHandler );
876 signal( SIGHUP, FatalSignalHandler );
877 signal( SIGQUIT, FatalSignalHandler );
880 signal( SIGALRM, SimpleSignalHandler );
881 signal( SIGPIPE, SimpleSignalHandler );
886 /*****************************************************************************
887 * SimpleSignalHandler: system signal handler
888 *****************************************************************************
889 * This function is called when a non fatal signal is received by the program.
890 *****************************************************************************/
891 static void SimpleSignalHandler( int i_signal )
893 /* Acknowledge the signal received */
894 intf_WarnMsg( 0, "intf: ignoring signal %d", i_signal );
898 /*****************************************************************************
899 * FatalSignalHandler: system signal handler
900 *****************************************************************************
901 * This function is called when a fatal signal is received by the program.
902 * It tries to end the program in a clean way.
903 *****************************************************************************/
904 static void FatalSignalHandler( int i_signal )
906 /* Once a signal has been trapped, the termination sequence will be
907 * armed and following signals will be ignored to avoid sending messages
908 * to an interface having been destroyed */
910 signal( SIGINT, SIG_IGN );
911 signal( SIGHUP, SIG_IGN );
912 signal( SIGQUIT, SIG_IGN );
915 /* Acknowledge the signal received */
916 intf_ErrMsgImm( "intf error: signal %d received, exiting", i_signal );
918 /* Try to terminate everything - this is done by requesting the end of the
919 * interface thread */
920 p_main->p_intf->b_die = 1;
923 /*****************************************************************************
924 * CPUCapabilities: list the processors MMX support and other capabilities
925 *****************************************************************************
926 * This function is called to list extensions the CPU may have.
927 *****************************************************************************/
928 static int CPUCapabilities( void )
930 int i_capabilities = CPU_CAPABILITY_NONE;
932 #if defined( SYS_BEOS )
933 i_capabilities |= CPU_CAPABILITY_486
935 | CPU_CAPABILITY_MMX;
937 #elif defined( SYS_DARWIN1_3 )
939 struct host_basic_info hi;
941 host_name_port_t host;
944 char *psz_name, *psz_subname;
946 /* Should 'never' fail? */
947 host = mach_host_self();
949 i_size = sizeof( hi ) / sizeof( int );
950 ret = host_info( host, HOST_BASIC_INFO, ( host_info_t )&hi, &i_size );
952 if( ret != KERN_SUCCESS )
954 intf_ErrMsg( "error: couldn't get CPU information" );
955 return( i_capabilities );
958 slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
959 /* FIXME: need better way to detect newer proccessors.
960 * could do strncmp(a,b,5), but that's real ugly */
961 if( strcmp(psz_name, "ppc7400") || strcmp(psz_name, "ppc7450") )
963 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
966 #elif defined( __i386__ )
967 unsigned int i_eax, i_ebx, i_ecx, i_edx;
970 # define cpuid( a ) \
971 asm volatile ( "cpuid" \
979 /* test for a 486 CPU */
980 asm volatile ( "pushfl\n\t"
982 "movl %%eax, %%ebx\n\t"
983 "xorl $0x200000, %%eax\n\t"
995 return( i_capabilities );
998 i_capabilities |= CPU_CAPABILITY_486;
1000 /* the CPU supports the CPUID instruction - get its level */
1001 cpuid( 0x00000000 );
1005 return( i_capabilities );
1008 /* FIXME: this isn't correct, since some 486s have cpuid */
1009 i_capabilities |= CPU_CAPABILITY_586;
1011 /* borrowed from mpeg2dec */
1012 b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
1013 && ( i_edx == 0x69746e65 );
1015 /* test for the MMX flag */
1016 cpuid( 0x00000001 );
1018 if( ! (i_edx & 0x00800000) )
1020 return( i_capabilities );
1023 i_capabilities |= CPU_CAPABILITY_MMX;
1025 if( i_edx & 0x02000000 )
1027 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1030 /* test for additional capabilities */
1031 cpuid( 0x80000000 );
1033 if( i_eax < 0x80000001 )
1035 return( i_capabilities );
1038 /* list these additional capabilities */
1039 cpuid( 0x80000001 );
1041 if( i_edx & 0x80000000 )
1043 i_capabilities |= CPU_CAPABILITY_3DNOW;
1046 if( b_amd && ( i_edx & 0x00400000 ) )
1048 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1052 /* default behaviour */
1055 return( i_capabilities );