* Applied patch from Jon Lech Johansen <jon-vl@nanocrew.net> to compile
[vlc.git] / src / interface / main.c
blob3f86e43a6317797bd6124466ed1bcb4c9a552eb1
1 /*****************************************************************************
2 * main.c: main vlc source
3 * Includes the main() function for vlc. Parses command line, start interface
4 * and spawn threads.
5 *****************************************************************************
6 * Copyright (C) 1998, 1999, 2000 VideoLAN
7 * $Id: main.c,v 1.99 2001/05/31 01:37:08 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 /*****************************************************************************
28 * Preamble
29 *****************************************************************************/
30 #include "defs.h"
32 #include <signal.h> /* SIGHUP, SIGINT, SIGKILL */
33 #include <stdio.h> /* sprintf() */
35 #ifdef HAVE_GETOPT_LONG
36 # ifdef HAVE_GETOPT_H
37 # include <getopt.h> /* getopt() */
38 # endif
39 #else
40 # include "GNUgetopt/getopt.h"
41 #endif
43 #ifdef SYS_DARWIN1_3
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>
48 #endif
50 #ifndef WIN32
51 #include <netinet/in.h> /* BSD: struct in_addr */
52 #endif
54 #ifdef HAVE_UNISTD_H
55 #include <unistd.h>
56 #endif
58 #include <errno.h> /* ENOMEM */
59 #include <stdlib.h> /* getenv(), strtol(), */
60 #include <string.h> /* strerror() */
62 #include "config.h"
63 #include "common.h"
64 #include "debug.h"
65 #include "threads.h"
66 #include "mtime.h"
67 #include "tests.h" /* TestCPU() */
68 #include "modules.h"
70 #include "stream_control.h"
71 #include "input_ext-intf.h"
73 #include "intf_msg.h"
74 #include "intf_playlist.h"
75 #include "interface.h"
77 #include "audio_output.h"
79 #include "video.h"
80 #include "video_output.h"
82 #ifdef SYS_BEOS
83 # include "beos_specific.h"
84 #endif
86 #ifdef SYS_DARWIN1_3
87 # include "darwin_specific.h"
88 #endif
90 #include "netutils.h" /* network_ChannelJoin */
92 #include "main.h"
94 /*****************************************************************************
95 * Command line options constants. If something is changed here, be sure that
96 * GetConfiguration and Usage are also changed.
97 *****************************************************************************/
99 /* Long options return values - note that values corresponding to short options
100 * chars, and in general any regular char, should be avoided */
101 #define OPT_NOAUDIO 150
102 #define OPT_STEREO 151
103 #define OPT_MONO 152
104 #define OPT_SPDIF 153
106 #define OPT_NOVIDEO 160
107 #define OPT_DISPLAY 161
108 #define OPT_WIDTH 162
109 #define OPT_HEIGHT 163
110 #define OPT_COLOR 164
111 #define OPT_FULLSCREEN 165
112 #define OPT_OVERLAY 166
114 #define OPT_CHANNELS 170
115 #define OPT_SERVER 171
116 #define OPT_PORT 172
117 #define OPT_BROADCAST 173
119 #define OPT_INPUT 180
120 #define OPT_MOTION 181
121 #define OPT_IDCT 182
122 #define OPT_YUV 183
123 #define OPT_DOWNMIX 184
124 #define OPT_IMDCT 185
126 #define OPT_SYNCHRO 190
127 #define OPT_WARNING 191
128 #define OPT_VERSION 192
130 /* Usage fashion */
131 #define USAGE 0
132 #define SHORT_HELP 1
133 #define LONG_HELP 2
135 /* Long options */
136 static const struct option longopts[] =
138 /* name, has_arg, flag, val */
140 /* General/common options */
141 { "help", 0, 0, 'h' },
142 { "longhelp", 0, 0, 'H' },
143 { "version", 0, 0, OPT_VERSION },
145 /* Interface options */
146 { "intf", 1, 0, 'I' },
147 { "warning", 1, 0, OPT_WARNING },
149 /* Audio options */
150 { "noaudio", 0, 0, OPT_NOAUDIO },
151 { "aout", 1, 0, 'A' },
152 { "stereo", 0, 0, OPT_STEREO },
153 { "mono", 0, 0, OPT_MONO },
154 { "spdif", 0, 0, OPT_SPDIF },
155 { "downmix", 1, 0, OPT_DOWNMIX },
156 { "imdct", 1, 0, OPT_IMDCT },
158 /* Video options */
159 { "novideo", 0, 0, OPT_NOVIDEO },
160 { "vout", 1, 0, 'V' },
161 { "display", 1, 0, OPT_DISPLAY },
162 { "width", 1, 0, OPT_WIDTH },
163 { "height", 1, 0, OPT_HEIGHT },
164 { "grayscale", 0, 0, 'g' },
165 { "color", 0, 0, OPT_COLOR },
166 { "motion", 1, 0, OPT_MOTION },
167 { "idct", 1, 0, OPT_IDCT },
168 { "yuv", 1, 0, OPT_YUV },
169 { "fullscreen", 0, 0, OPT_FULLSCREEN },
170 { "overlay", 0, 0, OPT_OVERLAY },
172 /* DVD options */
173 { "dvdtitle", 1, 0, 't' },
174 { "dvdchapter", 1, 0, 'T' },
175 { "dvdangle", 1, 0, 'u' },
176 { "dvdaudio", 1, 0, 'a' },
177 { "dvdchannel", 1, 0, 'c' },
178 { "dvdsubtitle", 1, 0, 's' },
180 /* Input options */
181 { "input", 1, 0, OPT_INPUT },
182 { "server", 1, 0, OPT_SERVER },
183 { "port", 1, 0, OPT_PORT },
184 { "broadcast", 1, 0, OPT_BROADCAST },
185 { "channels", 0, 0, OPT_CHANNELS },
187 /* Synchro options */
188 { "synchro", 1, 0, OPT_SYNCHRO },
189 { 0, 0, 0, 0 }
192 /* Short options */
193 static const char *psz_shortopts = "hHvgt:T:u:a:s:c:I:A:V:";
195 /*****************************************************************************
196 * Global variable program_data - these are the only ones, see main.h and
197 * modules.h
198 *****************************************************************************/
199 main_t *p_main;
200 module_bank_t *p_module_bank;
201 aout_bank_t *p_aout_bank;
202 vout_bank_t *p_vout_bank;
204 /*****************************************************************************
205 * Local prototypes
206 *****************************************************************************/
207 static int GetConfiguration ( int *pi_argc, char *ppsz_argv[],
208 char *ppsz_env[] );
209 static int GetFilenames ( int i_argc, char *ppsz_argv[] );
210 static void Usage ( int i_fashion );
211 static void Version ( void );
213 static void InitSignalHandler ( void );
214 static void SimpleSignalHandler ( int i_signal );
215 static void FatalSignalHandler ( int i_signal );
217 static int CPUCapabilities ( void );
219 /*****************************************************************************
220 * main: parse command line, start interface and spawn threads
221 *****************************************************************************
222 * Steps during program execution are:
223 * -configuration parsing and messages interface initialization
224 * -opening of audio output device and some global modules
225 * -execution of interface, which exit on error or on user request
226 * -closing of audio output device and some global modules
227 * On error, the spawned threads are canceled, and the open devices closed.
228 *****************************************************************************/
229 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
231 main_t main_data; /* root of all data - see main.h */
232 module_bank_t module_bank;
233 aout_bank_t aout_bank;
234 vout_bank_t vout_bank;
236 p_main = &main_data; /* set up the global variables */
237 p_module_bank = &module_bank;
238 p_aout_bank = &aout_bank;
239 p_vout_bank = &vout_bank;
242 * Test if our code is likely to run on this CPU
244 p_main->i_cpu_capabilities = CPUCapabilities();
246 #if defined( __pentium__ ) || defined( __pentiumpro__ )
247 if( ! TestCPU( CPU_CAPABILITY_586 ) )
249 fprintf( stderr, "error: this program needs a Pentium CPU,\n"
250 "please try a version without Pentium support\n" );
251 return( 1 );
253 #endif
256 * System specific initialization code
258 #if defined( SYS_BEOS ) || defined( SYS_DARWIN1_3 )
259 system_Init( &i_argc, ppsz_argv, ppsz_env );
260 #endif
263 * Initialize messages interface
265 p_main->p_msg = intf_MsgCreate();
266 if( !p_main->p_msg ) /* start messages interface */
268 fprintf( stderr, "error: can't initialize messages interface (%s)\n",
269 strerror(errno) );
270 return( errno );
273 intf_MsgImm( COPYRIGHT_MESSAGE );
276 * Read configuration
278 if( GetConfiguration( &i_argc, ppsz_argv, ppsz_env ) ) /* parse cmd line */
280 intf_MsgDestroy();
281 return( errno );
285 * Initialize playlist and get commandline files
287 p_main->p_playlist = intf_PlaylistCreate();
288 if( !p_main->p_playlist )
290 intf_ErrMsg( "playlist error: playlist initialization failed" );
291 intf_MsgDestroy();
292 return( errno );
294 intf_PlaylistInit( p_main->p_playlist );
297 * Get input filenames given as commandline arguments
299 GetFilenames( i_argc, ppsz_argv );
302 * Initialize module, aout and vout banks
304 module_InitBank();
305 aout_InitBank();
306 vout_InitBank();
309 * Initialize shared resources and libraries
311 if( main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
312 INPUT_NETWORK_CHANNEL_DEFAULT ) &&
313 network_ChannelCreate() )
315 /* On error during Channels initialization, switch off channels */
316 intf_Msg( "Channels initialization failed : "
317 "Channel management is deactivated" );
318 main_PutIntVariable( INPUT_NETWORK_CHANNEL_VAR, 0 );
322 * Try to run the interface
324 p_main->p_intf = intf_Create();
325 if( p_main->p_intf == NULL )
327 intf_ErrMsg( "intf error: interface initialization failed" );
329 else
332 * Set signal handling policy for all threads
334 InitSignalHandler();
337 * This is the main loop
339 p_main->p_intf->pf_run( p_main->p_intf );
342 * Finished, destroy the interface
344 intf_Destroy( p_main->p_intf );
347 * Go back into channel 0 which is the network
349 if( main_GetIntVariable( INPUT_NETWORK_CHANNEL_VAR,
350 INPUT_NETWORK_CHANNEL_DEFAULT ) )
352 network_ChannelJoin( COMMON_CHANNEL );
357 * Free module, aout and vout banks
359 vout_EndBank();
360 aout_EndBank();
361 module_EndBank();
364 * Free playlist
366 intf_PlaylistDestroy( p_main->p_playlist );
369 * System specific cleaning code
371 #if defined( SYS_BEOS ) || defined( SYS_DARWIN1_3 )
372 system_End();
373 #endif
376 * Terminate messages interface and program
378 intf_Msg( "intf: program terminated" );
379 intf_MsgDestroy();
381 return 0;
384 /*****************************************************************************
385 * main_GetIntVariable: get the int value of an environment variable
386 *****************************************************************************
387 * This function is used to read some default parameters in modules.
388 *****************************************************************************/
389 int main_GetIntVariable( char *psz_name, int i_default )
391 char * psz_env; /* environment value */
392 char * psz_end; /* end of parsing index */
393 long int i_value; /* value */
395 psz_env = getenv( psz_name );
396 if( psz_env )
398 i_value = strtol( psz_env, &psz_end, 0 );
399 if( (*psz_env != '\0') && (*psz_end == '\0') )
401 return( i_value );
404 return( i_default );
407 /*****************************************************************************
408 * main_GetPszVariable: get the string value of an environment variable
409 *****************************************************************************
410 * This function is used to read some default parameters in modules.
411 *****************************************************************************/
412 char * main_GetPszVariable( char *psz_name, char *psz_default )
414 char *psz_env;
416 psz_env = getenv( psz_name );
417 if( psz_env )
419 return( psz_env );
421 return( psz_default );
424 /*****************************************************************************
425 * main_PutPszVariable: set the string value of an environment variable
426 *****************************************************************************
427 * This function is used to set some default parameters in modules. The use of
428 * this function will cause some memory leak: since some systems use the pointer
429 * passed to putenv to store the environment string, it can't be freed.
430 *****************************************************************************/
431 void main_PutPszVariable( char *psz_name, char *psz_value )
433 char *psz_env;
435 psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
436 if( psz_env == NULL )
438 intf_ErrMsg( "intf error: cannot create psz_env (%s)",
439 strerror(ENOMEM) );
441 else
443 sprintf( psz_env, "%s=%s", psz_name, psz_value );
444 if( putenv( psz_env ) )
446 intf_ErrMsg( "intf error: cannot putenv (%s)", strerror(errno) );
451 /*****************************************************************************
452 * main_PutIntVariable: set the integer value of an environment variable
453 *****************************************************************************
454 * This function is used to set some default parameters in modules. The use of
455 * this function will cause some memory leak: since some systems use the pointer
456 * passed to putenv to store the environment string, it can't be freed.
457 *****************************************************************************/
458 void main_PutIntVariable( char *psz_name, int i_value )
460 char psz_value[ 256 ]; /* buffer for value */
462 sprintf( psz_value, "%d", i_value );
463 main_PutPszVariable( psz_name, psz_value );
466 /* following functions are local */
468 /*****************************************************************************
469 * GetConfiguration: parse command line
470 *****************************************************************************
471 * Parse command line and configuration file for configuration. If the inline
472 * help is requested, the function Usage() is called and the function returns
473 * -1 (causing main() to exit). The messages interface is initialized at this
474 * stage, but most structures are not allocated, so only environment should
475 * be used.
476 *****************************************************************************/
477 static int GetConfiguration( int *pi_argc, char *ppsz_argv[], char *ppsz_env[] )
479 int i_cmd;
480 char *p_tmp;
482 /* Set default configuration and copy arguments */
483 p_main->i_argc = *pi_argc;
484 p_main->ppsz_argv = ppsz_argv;
485 p_main->ppsz_env = ppsz_env;
487 p_main->b_audio = 1;
488 p_main->b_video = 1;
490 p_main->i_warning_level = 0;
492 p_main->p_channel = NULL;
494 /* Get the executable name (similar to the basename command) */
495 p_main->psz_arg0 = p_tmp = ppsz_argv[ 0 ];
496 while( *p_tmp )
498 if( *p_tmp == '/' )
500 p_main->psz_arg0 = ++p_tmp;
502 else
504 ++p_tmp;
508 #ifdef SYS_DARWIN1_3
509 /* When vlc.app is run by double clicking in Mac OS X, the 2nd arg
510 * is the PSN - process serial number (a unique PID-ish thingie)
511 * still ok for real Darwin & when run from command line */
512 if ( (*pi_argc > 1) && (strncmp( ppsz_argv[ 1 ] , "-psn" , 4 ) == 0) )
513 /* for example -psn_0_9306113 */
515 /* GDMF!... I can't do this or else the MacOSX window server will
516 * not pick up the PSN and not register the app and we crash...
517 * hence the following kludge otherwise we'll get confused w/ argv[1]
518 * being an input file name */
519 #if 0
520 ppsz_argv[ 1 ] = NULL;
521 #endif
522 *pi_argc = *pi_argc - 1;
523 pi_argc--;
524 return( 0 );
526 #endif
528 /* Parse command line options */
529 opterr = 0;
530 while( ( i_cmd = getopt_long( *pi_argc, ppsz_argv,
531 psz_shortopts, longopts, 0 ) ) != EOF )
533 switch( i_cmd )
535 /* General/common options */
536 case 'h': /* -h, --help */
537 Usage( SHORT_HELP );
538 return( -1 );
539 break;
540 case 'H': /* -H, --longhelp */
541 Usage( LONG_HELP );
542 return( -1 );
543 break;
544 case OPT_VERSION: /* --version */
545 Version();
546 return( -1 );
547 break;
548 case 'v': /* -v, --verbose */
549 p_main->i_warning_level++;
550 break;
552 /* Interface warning messages level */
553 case 'I': /* -I, --intf */
554 main_PutPszVariable( INTF_METHOD_VAR, optarg );
555 break;
556 case OPT_WARNING: /* --warning */
557 intf_ErrMsg( "intf error: `--warning' is deprecated, use `-v'" );
558 p_main->i_warning_level = atoi(optarg);
559 break;
561 /* Audio options */
562 case OPT_NOAUDIO: /* --noaudio */
563 p_main->b_audio = 0;
564 break;
565 case 'A': /* -A, --aout */
566 main_PutPszVariable( AOUT_METHOD_VAR, optarg );
567 break;
568 case OPT_STEREO: /* --stereo */
569 main_PutIntVariable( AOUT_STEREO_VAR, 1 );
570 break;
571 case OPT_MONO: /* --mono */
572 main_PutIntVariable( AOUT_STEREO_VAR, 0 );
573 break;
574 case OPT_SPDIF: /* --spdif */
575 main_PutIntVariable( AOUT_SPDIF_VAR, 1 );
576 break;
577 case OPT_DOWNMIX: /* --downmix */
578 main_PutPszVariable( DOWNMIX_METHOD_VAR, optarg );
579 break;
580 case OPT_IMDCT: /* --imdct */
581 main_PutPszVariable( IMDCT_METHOD_VAR, optarg );
582 break;
584 /* Video options */
585 case OPT_NOVIDEO: /* --novideo */
586 p_main->b_video = 0;
587 break;
588 case 'V': /* -V, --vout */
589 main_PutPszVariable( VOUT_METHOD_VAR, optarg );
590 break;
591 case OPT_DISPLAY: /* --display */
592 main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
593 break;
594 case OPT_WIDTH: /* --width */
595 main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
596 break;
597 case OPT_HEIGHT: /* --height */
598 main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
599 break;
600 case 'g': /* -g, --grayscale */
601 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
602 break;
603 case OPT_COLOR: /* --color */
604 main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
605 break;
606 case OPT_FULLSCREEN: /* --fullscreen */
607 main_PutIntVariable( VOUT_FULLSCREEN_VAR, 1 );
608 break;
609 case OPT_OVERLAY: /* --overlay */
610 main_PutIntVariable( VOUT_OVERLAY_VAR, 1 );
611 break;
612 case OPT_MOTION: /* --motion */
613 main_PutPszVariable( MOTION_METHOD_VAR, optarg );
614 break;
615 case OPT_IDCT: /* --idct */
616 main_PutPszVariable( IDCT_METHOD_VAR, optarg );
617 break;
618 case OPT_YUV: /* --yuv */
619 main_PutPszVariable( YUV_METHOD_VAR, optarg );
620 break;
622 /* DVD options */
623 case 't':
624 main_PutIntVariable( INPUT_TITLE_VAR, atoi(optarg) );
625 break;
626 case 'T':
627 main_PutIntVariable( INPUT_CHAPTER_VAR, atoi(optarg) );
628 break;
629 case 'u':
630 main_PutIntVariable( INPUT_ANGLE_VAR, atoi(optarg) );
631 break;
632 case 'a':
633 if ( ! strcmp(optarg, "ac3") )
634 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_AC3 );
635 else if ( ! strcmp(optarg, "lpcm") )
636 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_LPCM );
637 else if ( ! strcmp(optarg, "mpeg") )
638 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_MPEG );
639 else
640 main_PutIntVariable( INPUT_AUDIO_VAR, REQUESTED_NOAUDIO );
641 break;
642 case 'c':
643 main_PutIntVariable( INPUT_CHANNEL_VAR, atoi(optarg) );
644 break;
645 case 's':
646 main_PutIntVariable( INPUT_SUBTITLE_VAR, atoi(optarg) );
647 break;
649 /* Input options */
650 case OPT_INPUT: /* --input */
651 main_PutPszVariable( INPUT_METHOD_VAR, optarg );
652 break;
653 case OPT_CHANNELS: /* --channels */
654 main_PutIntVariable( INPUT_NETWORK_CHANNEL_VAR, 1 );
655 break;
656 case OPT_SERVER: /* --server */
657 main_PutPszVariable( INPUT_SERVER_VAR, optarg );
658 break;
659 case OPT_PORT: /* --port */
660 main_PutPszVariable( INPUT_PORT_VAR, optarg );
661 break;
662 case OPT_BROADCAST: /* --broadcast */
663 main_PutIntVariable( INPUT_BROADCAST_VAR, 1 );
664 main_PutPszVariable( INPUT_BCAST_ADDR_VAR, optarg );
665 break;
667 /* Synchro options */
668 case OPT_SYNCHRO:
669 main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
670 break;
672 /* Internal error: unknown option */
673 case '?':
674 default:
675 intf_ErrMsg( "intf error: unknown option `%s'",
676 ppsz_argv[optind - 1] );
677 Usage( USAGE );
678 return( EINVAL );
679 break;
683 if( p_main->i_warning_level < 0 )
685 p_main->i_warning_level = 0;
688 return( 0 );
691 /*****************************************************************************
692 * GetFilenames: parse command line options which are not flags
693 *****************************************************************************
694 * Parse command line for input files.
695 *****************************************************************************/
696 static int GetFilenames( int i_argc, char *ppsz_argv[] )
698 int i_opt;
700 /* We assume that the remaining parameters are filenames */
701 for( i_opt = optind; i_opt < i_argc; i_opt++ )
703 intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
704 ppsz_argv[ i_opt ] );
707 return( 0 );
710 /*****************************************************************************
711 * Usage: print program usage
712 *****************************************************************************
713 * Print a short inline help. Message interface is initialized at this stage.
714 *****************************************************************************/
715 static void Usage( int i_fashion )
717 /* Usage */
718 intf_MsgImm( "Usage: %s [options] [parameters] [file]...",
719 p_main->psz_arg0 );
721 if( i_fashion == USAGE )
723 intf_MsgImm( "Try `%s --help' for more information.",
724 p_main->psz_arg0 );
725 return;
728 /* Options */
729 intf_MsgImm( "\nOptions:"
730 "\n -I, --intf <module> \tinterface method"
731 "\n -v, --verbose \tverbose mode (cumulative)"
732 "\n"
733 "\n --noaudio \tdisable audio"
734 "\n -A, --aout <module> \taudio output method"
735 "\n --stereo, --mono \tstereo/mono audio"
736 "\n --spdif \tAC3 pass-through mode"
737 "\n --downmix <module> \tAC3 downmix method"
738 "\n --imdct <module> \tAC3 IMDCT method"
739 "\n"
740 "\n --novideo \tdisable video"
741 "\n -V, --vout <module> \tvideo output method"
742 "\n --display <display> \tdisplay string"
743 "\n --width <w>, --height <h> \tdisplay dimensions"
744 "\n -g, --grayscale \tgrayscale output"
745 "\n --fullscreen \tfullscreen output"
746 "\n --overlay \taccelerated display"
747 "\n --color \tcolor output"
748 "\n --motion <module> \tmotion compensation method"
749 "\n --idct <module> \tIDCT method"
750 "\n --yuv <module> \tYUV method"
751 "\n --synchro <type> \tforce synchro algorithm"
752 "\n"
753 "\n -t, --dvdtitle <num> \tchoose DVD title"
754 "\n -T, --dvdchapter <num> \tchoose DVD chapter"
755 "\n -u, --dvdangle <num> \tchoose DVD angle"
756 "\n -a, --dvdaudio <type> \tchoose DVD audio type"
757 "\n -c, --dvdchannel <channel> \tchoose DVD audio channel"
758 "\n -s, --dvdsubtitle <channel> \tchoose DVD subtitle channel"
759 "\n"
760 "\n --input \tinput method"
761 "\n --channels \tenable channels"
762 "\n --server <host> \tvideo server address"
763 "\n --port <port> \tvideo server port"
764 "\n --broadcast \tlisten to a broadcast"
765 "\n"
766 "\n -h, --help \tprint help and exit"
767 "\n -H, --longhelp \tprint long help and exit"
768 "\n --version \toutput version information and exit" );
770 if( i_fashion == SHORT_HELP )
771 return;
773 /* Interface parameters */
774 intf_MsgImm( "\nInterface parameters:"
775 "\n " INTF_METHOD_VAR "=<method name> \tinterface method"
776 "\n " INTF_INIT_SCRIPT_VAR "=<filename> \tinitialization script"
777 "\n " INTF_CHANNELS_VAR "=<filename> \tchannels list" );
779 /* Audio parameters */
780 intf_MsgImm( "\nAudio parameters:"
781 "\n " AOUT_METHOD_VAR "=<method name> \taudio method"
782 "\n " AOUT_DSP_VAR "=<filename> \tdsp device path"
783 "\n " AOUT_STEREO_VAR "={1|0} \tstereo or mono output"
784 "\n " AOUT_SPDIF_VAR "={1|0} \tAC3 pass-through mode"
785 "\n " DOWNMIX_METHOD_VAR "=<method name> \tAC3 downmix method"
786 "\n " IMDCT_METHOD_VAR "=<method name> \tAC3 IMDCT method"
787 "\n " AOUT_RATE_VAR "=<rate> \toutput rate" );
789 /* Video parameters */
790 intf_MsgImm( "\nVideo parameters:"
791 "\n " VOUT_METHOD_VAR "=<method name> \tdisplay method"
792 "\n " VOUT_DISPLAY_VAR "=<display name> \tdisplay used"
793 "\n " VOUT_WIDTH_VAR "=<width> \tdisplay width"
794 "\n " VOUT_HEIGHT_VAR "=<height> \tdislay height"
795 "\n " VOUT_FB_DEV_VAR "=<filename> \tframebuffer device path"
796 "\n " VOUT_GRAYSCALE_VAR "={1|0} \tgrayscale or color output"
797 "\n " VOUT_FULLSCREEN_VAR "={1|0} \tfullscreen"
798 "\n " VOUT_OVERLAY_VAR "={1|0} \toverlay"
799 "\n " MOTION_METHOD_VAR "=<method name> \tmotion compensation method"
800 "\n " IDCT_METHOD_VAR "=<method name> \tIDCT method"
801 "\n " YUV_METHOD_VAR "=<method name> \tYUV method"
802 "\n " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB} \tsynchro algorithm" );
804 /* DVD parameters */
805 intf_MsgImm( "\nDVD parameters:"
806 "\n " INPUT_DVD_DEVICE_VAR "=<device> \tDVD device"
807 "\n " INPUT_TITLE_VAR "=<title> \ttitle number"
808 "\n " INPUT_CHAPTER_VAR "=<chapter> \tchapter number"
809 "\n " INPUT_ANGLE_VAR "=<angle> \tangle number"
810 "\n " INPUT_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type"
811 "\n " INPUT_CHANNEL_VAR "=[0-15] \taudio channel"
812 "\n " INPUT_SUBTITLE_VAR "=[0-31] \tsubtitle channel" );
814 /* Input parameters */
815 intf_MsgImm( "\nInput parameters:"
816 "\n " INPUT_SERVER_VAR "=<hostname> \tvideo server"
817 "\n " INPUT_PORT_VAR "=<port> \tvideo server port"
818 "\n " INPUT_IFACE_VAR "=<interface> \tnetwork interface"
819 "\n " INPUT_BCAST_ADDR_VAR "=<addr> \tbroadcast mode"
820 "\n " INPUT_CHANNEL_SERVER_VAR "=<hostname> \tchannel server"
821 "\n " INPUT_CHANNEL_PORT_VAR "=<port> \tchannel server port" );
825 /*****************************************************************************
826 * Version: print complete program version
827 *****************************************************************************
828 * Print complete program version and build number.
829 *****************************************************************************/
830 static void Version( void )
832 intf_MsgImm( VERSION_MESSAGE
833 "This program comes with NO WARRANTY, to the extent permitted by law.\n"
834 "You may redistribute it under the terms of the GNU General Public License;\n"
835 "see the file named COPYING for details.\n"
836 "Written by the VideoLAN team at Ecole Centrale, Paris." );
839 /*****************************************************************************
840 * InitSignalHandler: system signal handler initialization
841 *****************************************************************************
842 * Set the signal handlers. SIGTERM is not intercepted, because we need at
843 * at least a method to kill the program when all other methods failed, and
844 * when we don't want to use SIGKILL.
845 *****************************************************************************/
846 static void InitSignalHandler( void )
848 /* Termination signals */
849 #ifndef WIN32
850 signal( SIGINT, FatalSignalHandler );
851 signal( SIGHUP, FatalSignalHandler );
852 signal( SIGQUIT, FatalSignalHandler );
854 /* Other signals */
855 signal( SIGALRM, SimpleSignalHandler );
856 signal( SIGPIPE, SimpleSignalHandler );
857 #endif
861 /*****************************************************************************
862 * SimpleSignalHandler: system signal handler
863 *****************************************************************************
864 * This function is called when a non fatal signal is received by the program.
865 *****************************************************************************/
866 static void SimpleSignalHandler( int i_signal )
868 /* Acknowledge the signal received */
869 intf_WarnMsg( 0, "intf: ignoring signal %d", i_signal );
873 /*****************************************************************************
874 * FatalSignalHandler: system signal handler
875 *****************************************************************************
876 * This function is called when a fatal signal is received by the program.
877 * It tries to end the program in a clean way.
878 *****************************************************************************/
879 static void FatalSignalHandler( int i_signal )
881 /* Once a signal has been trapped, the termination sequence will be
882 * armed and following signals will be ignored to avoid sending messages
883 * to an interface having been destroyed */
884 #ifndef WIN32
885 signal( SIGINT, SIG_IGN );
886 signal( SIGHUP, SIG_IGN );
887 signal( SIGQUIT, SIG_IGN );
888 #endif
890 /* Acknowledge the signal received */
891 intf_ErrMsgImm( "intf error: signal %d received, exiting", i_signal );
893 /* Try to terminate everything - this is done by requesting the end of the
894 * interface thread */
895 p_main->p_intf->b_die = 1;
898 /*****************************************************************************
899 * CPUCapabilities: list the processors MMX support and other capabilities
900 *****************************************************************************
901 * This function is called to list extensions the CPU may have.
902 *****************************************************************************/
903 static int CPUCapabilities( void )
905 int i_capabilities = CPU_CAPABILITY_NONE;
907 #if defined( SYS_BEOS )
908 i_capabilities |= CPU_CAPABILITY_486
909 | CPU_CAPABILITY_586
910 | CPU_CAPABILITY_MMX;
912 #elif defined( SYS_DARWIN1_3 )
914 struct host_basic_info hi;
915 kern_return_t ret;
916 host_name_port_t host;
918 int i_size;
919 char *psz_name, *psz_subname;
921 /* Should 'never' fail? */
922 host = mach_host_self();
924 i_size = sizeof( hi ) / sizeof( int );
925 ret = host_info( host, HOST_BASIC_INFO, ( host_info_t )&hi, &i_size );
927 if( ret != KERN_SUCCESS )
929 intf_ErrMsg( "error: couldn't get CPU information" );
930 return( i_capabilities );
933 slot_name( hi.cpu_type, hi.cpu_subtype, &psz_name, &psz_subname );
934 /* FIXME: need better way to detect newer proccessors.
935 * could do strncmp(a,b,5), but that's real ugly */
936 if( strcmp(psz_name, "ppc7400") || strcmp(psz_name, "ppc7450") )
938 i_capabilities |= CPU_CAPABILITY_ALTIVEC;
941 #elif defined( __i386__ )
942 unsigned int i_eax, i_ebx, i_ecx, i_edx;
943 boolean_t b_amd;
945 # define cpuid( a ) \
946 asm volatile ( "cpuid" \
947 : "=a" ( i_eax ), \
948 "=b" ( i_ebx ), \
949 "=c" ( i_ecx ), \
950 "=d" ( i_edx ) \
951 : "a" ( a ) \
952 : "cc" ); \
954 /* test for a 486 CPU */
955 asm volatile ( "pushfl\n\t"
956 "popl %%eax\n\t"
957 "movl %%eax, %%ebx\n\t"
958 "xorl $0x200000, %%eax\n\t"
959 "pushl %%eax\n\t"
960 "popfl\n\t"
961 "pushfl\n\t"
962 "popl %%eax"
963 : "=a" ( i_eax ),
964 "=b" ( i_ebx )
966 : "cc" );
968 if( i_eax == i_ebx )
970 return( i_capabilities );
973 i_capabilities |= CPU_CAPABILITY_486;
975 /* the CPU supports the CPUID instruction - get its level */
976 cpuid( 0x00000000 );
978 if( !i_eax )
980 return( i_capabilities );
983 /* FIXME: this isn't correct, since some 486s have cpuid */
984 i_capabilities |= CPU_CAPABILITY_586;
986 /* borrowed from mpeg2dec */
987 b_amd = ( i_ebx == 0x68747541 ) && ( i_ecx == 0x444d4163 )
988 && ( i_edx == 0x69746e65 );
990 /* test for the MMX flag */
991 cpuid( 0x00000001 );
993 if( ! (i_edx & 0x00800000) )
995 return( i_capabilities );
998 i_capabilities |= CPU_CAPABILITY_MMX;
1000 if( i_edx & 0x02000000 )
1002 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1003 i_capabilities |= CPU_CAPABILITY_SSE;
1006 /* test for additional capabilities */
1007 cpuid( 0x80000000 );
1009 if( i_eax < 0x80000001 )
1011 return( i_capabilities );
1014 /* list these additional capabilities */
1015 cpuid( 0x80000001 );
1017 if( i_edx & 0x80000000 )
1019 i_capabilities |= CPU_CAPABILITY_3DNOW;
1022 if( b_amd && ( i_edx & 0x00400000 ) )
1024 i_capabilities |= CPU_CAPABILITY_MMXEXT;
1026 #else
1027 /* default behaviour */
1029 #endif
1030 return( i_capabilities );