]> git.sesse.net Git - vlc/blob - src/interface/main.c
1e4df4711d6363e3c68f36eef7c6f20fcb98bedd
[vlc] / src / interface / main.c
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  *
8  * Authors:
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #include "defs.h"
29
30 #include <signal.h>                               /* SIGHUP, SIGINT, SIGKILL */
31 #include <stdio.h>                                              /* sprintf() */
32
33 #ifdef HAVE_GETOPT_H
34 #include <getopt.h>                                              /* getopt() */
35 #endif
36
37 #include <errno.h>                                                 /* ENOMEM */
38 #include <stdlib.h>                                  /* getenv(), strtol(),  */
39 #include <string.h>                                            /* strerror() */
40
41 #include "config.h"
42 #include "common.h"
43 #include "debug.h"
44 #include "threads.h"
45 #include "mtime.h"
46 #include "tests.h"                                              /* TestCPU() */
47 #include "plugins.h"
48 #include "modules.h"
49 #include "playlist.h"
50 #include "stream_control.h"
51 #include "input_ext-intf.h"
52
53 #include "intf_msg.h"
54 #include "interface.h"
55
56 #include "audio_output.h"
57
58 #ifdef SYS_BEOS
59 #include "beos_specific.h"
60 #endif
61
62 #include "main.h"
63
64 /*****************************************************************************
65  * Command line options constants. If something is changed here, be sure that
66  * GetConfiguration and Usage are also changed.
67  *****************************************************************************/
68
69 /* Long options return values - note that values corresponding to short options
70  * chars, and in general any regular char, should be avoided */
71 #define OPT_NOAUDIO             150
72 #define OPT_AOUT                151
73 #define OPT_STEREO              152
74 #define OPT_MONO                153
75
76 #define OPT_NOVIDEO             160
77 #define OPT_VOUT                161
78 #define OPT_DISPLAY             162
79 #define OPT_WIDTH               163
80 #define OPT_HEIGHT              164
81 #define OPT_COLOR               165
82 #define OPT_IDCT                166
83 #define OPT_YUV                 167
84
85 #define OPT_VLANS               170
86 #define OPT_SERVER              171
87 #define OPT_PORT                172
88 #define OPT_BROADCAST           173
89 #define OPT_DVD                 174
90
91 #define OPT_SYNCHRO             180
92
93 #define OPT_WARNING             190
94
95 /* Usage fashion */
96 #define USAGE                     0
97 #define SHORT_HELP                1
98 #define LONG_HELP                 2
99
100 /* Long options */
101 #ifdef HAVE_GETOPT_H
102 static const struct option longopts[] =
103 {
104     /*  name,               has_arg,    flag,   val */
105
106     /* General/common options */
107     {   "help",             0,          0,      'h' },
108     {   "longhelp",         0,          0,      'H' },
109     {   "version",          0,          0,      'v' },
110
111     /* Audio options */
112     {   "noaudio",          0,          0,      OPT_NOAUDIO },
113     {   "aout",             1,          0,      OPT_AOUT },
114     {   "stereo",           0,          0,      OPT_STEREO },
115     {   "mono",             0,          0,      OPT_MONO },
116
117     /* Video options */
118     {   "novideo",          0,          0,      OPT_NOVIDEO },
119     {   "vout",             1,          0,      OPT_VOUT },
120     {   "display",          1,          0,      OPT_DISPLAY },
121     {   "width",            1,          0,      OPT_WIDTH },
122     {   "height",           1,          0,      OPT_HEIGHT },
123     {   "grayscale",        0,          0,      'g' },
124     {   "color",            0,          0,      OPT_COLOR },
125     {   "idct",             1,          0,      OPT_IDCT },
126     {   "yuv",              1,          0,      OPT_YUV },
127
128     /* DVD options */
129     {   "dvdaudio",         1,          0,      'a' },
130     {   "dvdchannel",       1,          0,      'c' },
131     {   "dvdsubtitle",      1,          0,      's' },
132     
133     /* Input options */
134     {   "vlans",            0,          0,      OPT_VLANS },
135     {   "server",           1,          0,      OPT_SERVER },
136     {   "port",             1,          0,      OPT_PORT },
137     {   "broadcast",        0,          0,      OPT_BROADCAST },
138     {   "dvd",              0,          0,      OPT_DVD },
139
140     /* Synchro options */
141     {   "synchro",          1,          0,      OPT_SYNCHRO },
142
143     /* Interface messages */
144     {   "warning",          1,          0,      OPT_WARNING },
145     {   0,                  0,          0,      0 }
146 };
147
148 /* Short options */
149 static const char *psz_shortopts = "hHvga:s:c:";
150 #endif
151
152
153 /*****************************************************************************
154  * Global variable program_data - this is the one and only, see main.h
155  *****************************************************************************/
156 main_t *p_main;
157
158 /*****************************************************************************
159  * Local prototypes
160  *****************************************************************************/
161 static void SetDefaultConfiguration ( void );
162 static int  GetConfiguration        ( int i_argc, char *ppsz_argv[],
163                                       char *ppsz_env[] );
164 static void Usage                   ( int i_fashion );
165 static void Version                 ( void );
166
167 static void InitSignalHandler       ( void );
168 static void SimpleSignalHandler     ( int i_signal );
169 static void FatalSignalHandler      ( int i_signal );
170
171 /*****************************************************************************
172  * main: parse command line, start interface and spawn threads
173  *****************************************************************************
174  * Steps during program execution are:
175  *      -configuration parsing and messages interface initialization
176  *      -opening of audio output device and some global modules
177  *      -execution of interface, which exit on error or on user request
178  *      -closing of audio output device and some global modules
179  * On error, the spawned threads are canceled, and the open devices closed.
180  *****************************************************************************/
181 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
182 {
183     main_t  main_data;                      /* root of all data - see main.h */
184
185     p_main = &main_data;                       /* set up the global variable */
186
187     /*
188      * System specific initialization code
189      */
190 #ifdef SYS_BEOS
191     beos_Create();
192 #endif
193
194     p_main->i_cpu_capabilities = CPUCapabilities();
195
196     /*
197      * Test if our code is likely to run on this CPU 
198      */
199 #if defined( __pentium__ ) || defined( __pentiumpro__ )
200     if( ! TestCPU( CPU_CAPABILITY_586 ) )
201     {
202         fprintf( stderr, "Sorry, this program needs a Pentium CPU.\n"
203                          "Please try a version without Pentium support.\n" );
204         return( 1 );
205     }
206 #endif
207
208 #ifdef HAVE_MMX
209     if( ! TestCPU( CPU_CAPABILITY_MMX ) )
210     {
211         fprintf( stderr, "Sorry, this program needs MMX extensions.\n"
212                          "Please try a version without MMX support.\n" );
213         return( 1 );
214     }
215 #endif
216
217     /*
218      * Initialize messages interface
219      */
220     p_main->p_msg = intf_MsgCreate();
221     if( !p_main->p_msg )                         /* start messages interface */
222     {
223         fprintf( stderr, "error: can't initialize messages interface (%s)\n",
224                  strerror(errno) );
225         return( errno );
226     }
227
228     /*
229      * Read configuration
230      */
231     if( GetConfiguration( i_argc, ppsz_argv, ppsz_env ) )  /* parse cmd line */
232     {
233         intf_MsgDestroy();
234         return( errno );
235     }
236
237     /*
238      * Initialize playlist and get commandline files
239      */
240     p_main->p_playlist = playlist_Create( );
241     if( !p_main->p_playlist )
242     {
243         intf_ErrMsg( "playlist error: playlist initialization failed" );
244         intf_MsgDestroy();
245         return( errno );
246     }
247     playlist_Init( p_main->p_playlist, optind );
248
249     /*
250      * Initialize plugin bank
251      */
252     p_main->p_bank = bank_Create( );
253     if( !p_main->p_bank )
254     {
255         intf_ErrMsg( "plugin error: plugin bank initialization failed" );
256         playlist_Destroy( p_main->p_playlist );
257         intf_MsgDestroy();
258         return( errno );
259     }
260     bank_Init( p_main->p_bank );
261
262     /*
263      * Initialize module bank
264      */
265     p_main->p_module_bank = module_CreateBank( );
266     if( !p_main->p_module_bank )
267     {
268         intf_ErrMsg( "module error: module bank initialization failed" );
269         bank_Destroy( p_main->p_bank );
270         playlist_Destroy( p_main->p_playlist );
271         intf_MsgDestroy();
272         return( errno );
273     }
274     module_InitBank( p_main->p_module_bank );
275
276     /*
277      * Initialize shared resources and libraries
278      */
279     /* FIXME: no VLANs */
280 #if 0
281     if( p_main->b_vlans && input_VlanCreate() )
282     {
283         /* On error during vlans initialization, switch off vlans */
284         intf_Msg( "Virtual LANs initialization failed : "
285                   "vlans management is deactivated" );
286         p_main->b_vlans = 0;
287     }
288 #endif
289
290     /*
291      * Run interface
292      */
293     p_main->p_intf = intf_Create();
294
295     if( p_main->p_intf != NULL )
296     {
297         /*
298          * Set signal handling policy for all threads
299          */
300         InitSignalHandler();
301
302         /*
303          * Open audio device and start aout thread
304          */
305         if( p_main->b_audio )
306         {
307             p_main->p_aout = aout_CreateThread( NULL );
308             if( p_main->p_aout == NULL )
309             {
310                 /* On error during audio initialization, switch off audio */
311                 intf_ErrMsg( "aout error: audio initialization failed,"
312                              " audio is deactivated" );
313                 p_main->b_audio = 0;
314             }
315         }
316
317         /*
318          * This is the main loop
319          */
320         intf_Run( p_main->p_intf );
321
322         intf_Destroy( p_main->p_intf );
323
324         /*
325          * Close audio device
326          */
327         if( p_main->b_audio )
328         {
329             aout_DestroyThread( p_main->p_aout, NULL );
330         }
331     }
332
333     /*
334      * Free shared resources and libraries
335      */
336     /* FIXME */
337 #if 0
338     if( p_main->b_vlans )
339     {
340         input_VlanDestroy();
341     }
342 #endif
343
344     /*
345      * Free module bank
346      */
347     module_DestroyBank( p_main->p_module_bank );
348
349     /*
350      * Free plugin bank
351      */
352     bank_Destroy( p_main->p_bank );
353
354     /*
355      * Free playlist
356      */
357     playlist_Destroy( p_main->p_playlist );
358
359 #ifdef SYS_BEOS
360     /*
361      * System specific cleaning code
362      */
363     beos_Destroy();
364 #endif
365
366     /*
367      * Terminate messages interface and program
368      */
369     intf_Msg( "intf: program terminated." );
370     intf_MsgDestroy();
371
372     return( 0 );
373 }
374
375 /*****************************************************************************
376  * main_GetIntVariable: get the int value of an environment variable
377  *****************************************************************************
378  * This function is used to read some default parameters in modules.
379  *****************************************************************************/
380 int main_GetIntVariable( char *psz_name, int i_default )
381 {
382     char *      psz_env;                                /* environment value */
383     char *      psz_end;                             /* end of parsing index */
384     long int    i_value;                                            /* value */
385
386     psz_env = getenv( psz_name );
387     if( psz_env )
388     {
389         i_value = strtol( psz_env, &psz_end, 0 );
390         if( (*psz_env != '\0') && (*psz_end == '\0') )
391         {
392             return( i_value );
393         }
394     }
395     return( i_default );
396 }
397
398 /*****************************************************************************
399  * main_GetPszVariable: get the string value of an environment variable
400  *****************************************************************************
401  * This function is used to read some default parameters in modules.
402  *****************************************************************************/
403 char * main_GetPszVariable( char *psz_name, char *psz_default )
404 {
405     char *psz_env;
406
407     psz_env = getenv( psz_name );
408     if( psz_env )
409     {
410         return( psz_env );
411     }
412     return( psz_default );
413 }
414
415 /*****************************************************************************
416  * main_PutPszVariable: set the string value of an environment variable
417  *****************************************************************************
418  * This function is used to set some default parameters in modules. The use of
419  * this function will cause some memory leak: since some systems use the pointer
420  * passed to putenv to store the environment string, it can't be freed.
421  *****************************************************************************/
422 void main_PutPszVariable( char *psz_name, char *psz_value )
423 {
424     char *psz_env;
425
426     psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
427     if( psz_env == NULL )
428     {
429         intf_ErrMsg( "intf error: cannot create psz_env (%s)",
430                      strerror(ENOMEM) );
431     }
432     else
433     {
434         sprintf( psz_env, "%s=%s", psz_name, psz_value );
435         if( putenv( psz_env ) )
436         {
437             intf_ErrMsg( "intf error: cannot putenv (%s)", strerror(errno) );
438         }
439     }
440 }
441
442 /*****************************************************************************
443  * main_PutIntVariable: set the integer value of an environment variable
444  *****************************************************************************
445  * This function is used to set some default parameters in modules. The use of
446  * this function will cause some memory leak: since some systems use the pointer
447  * passed to putenv to store the environment string, it can't be freed.
448  *****************************************************************************/
449 void main_PutIntVariable( char *psz_name, int i_value )
450 {
451     char psz_value[ 256 ];                               /* buffer for value */
452
453     sprintf( psz_value, "%d", i_value );
454     main_PutPszVariable( psz_name, psz_value );
455 }
456
457 /* following functions are local */
458
459 /*****************************************************************************
460  * SetDefaultConfiguration: set default options
461  *****************************************************************************
462  * This function is called by GetConfiguration before command line is parsed.
463  * It sets all the default values required later by the program. At this stage,
464  * most structure are not yet allocated, so initialization must be done using
465  * environment.
466  *****************************************************************************/
467 static void SetDefaultConfiguration( void )
468 {
469     /*
470      * All features are activated by default except vlans
471      */
472     p_main->b_audio  = 1;
473     p_main->b_video  = 1;
474     p_main->b_vlans  = 0;
475     p_main->b_dvd    = 0;
476 }
477
478 /*****************************************************************************
479  * GetConfiguration: parse command line
480  *****************************************************************************
481  * Parse command line and configuration file for configuration. If the inline
482  * help is requested, the function Usage() is called and the function returns
483  * -1 (causing main() to exit). The messages interface is initialized at this
484  * stage, but most structures are not allocated, so only environment should
485  * be used.
486  *****************************************************************************/
487 static int GetConfiguration( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
488 {
489     int c, i_opt;
490     char * p_pointer;
491
492     /* Set default configuration and copy arguments */
493     p_main->i_argc    = i_argc;
494     p_main->ppsz_argv = ppsz_argv;
495     p_main->ppsz_env  = ppsz_env;
496     SetDefaultConfiguration();
497
498     intf_MsgImm( COPYRIGHT_MESSAGE );
499
500     /* Get the executable name (similar to the basename command) */
501     p_main->psz_arg0 = p_pointer = ppsz_argv[ 0 ];
502     while( *p_pointer )
503     {
504         if( *p_pointer == '/' )
505         {
506             p_main->psz_arg0 = ++p_pointer;
507         }
508         else
509         {
510             ++p_pointer;
511         }
512     }
513
514     /* Parse command line options */
515 #ifdef HAVE_GETOPT_H
516     opterr = 0;
517     while( ( c = getopt_long( i_argc, ppsz_argv, psz_shortopts, longopts, 0 ) ) != EOF )
518     {
519         switch( c )
520         {
521         /* General/common options */
522         case 'h':                                              /* -h, --help */
523             Usage( SHORT_HELP );
524             return( -1 );
525             break;
526         case 'H':                                          /* -H, --longhelp */
527             Usage( LONG_HELP );
528             return( -1 );
529             break;
530         case 'v':                                           /* -v, --version */
531             Version();
532             return( -1 );
533             break;
534
535         /* Audio options */
536         case OPT_NOAUDIO:                                       /* --noaudio */
537             p_main->b_audio = 0;
538             break;
539         case OPT_AOUT:                                             /* --aout */
540             main_PutPszVariable( AOUT_METHOD_VAR, optarg );
541             break;
542         case OPT_STEREO:                                         /* --stereo */
543             main_PutIntVariable( AOUT_STEREO_VAR, 1 );
544             break;
545         case OPT_MONO:                                             /* --mono */
546             main_PutIntVariable( AOUT_STEREO_VAR, 0 );
547             break;
548
549         /* Video options */
550         case OPT_NOVIDEO:                                       /* --novideo */
551             p_main->b_video = 0;
552             break;
553         case OPT_VOUT:                                             /* --vout */
554             main_PutPszVariable( VOUT_METHOD_VAR, optarg );
555             break;
556         case OPT_DISPLAY:                                       /* --display */
557             main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
558             break;
559         case OPT_WIDTH:                                           /* --width */
560             main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
561             break;
562         case OPT_HEIGHT:                                         /* --height */
563             main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
564             break;
565
566         case 'g':                                         /* -g, --grayscale */
567             main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
568             break;
569         case OPT_COLOR:                                           /* --color */
570             main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
571             break;
572         case OPT_IDCT:                                             /* --idct */
573             main_PutPszVariable( IDCT_METHOD_VAR, optarg );
574             break;
575         case OPT_YUV:                                               /* --yuv */
576             main_PutPszVariable( YUV_METHOD_VAR, optarg );
577             break;
578
579         /* DVD options */
580         case 'a':
581             if ( ! strcmp(optarg, "ac3") )
582                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_AC3 );
583             else if ( ! strcmp(optarg, "lpcm") )
584                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_LPCM );
585             else if ( ! strcmp(optarg, "off") )
586                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_NOAUDIO );
587             else
588                 main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_MPEG );
589             break;
590         case 'c':
591             main_PutIntVariable( INPUT_DVD_CHANNEL_VAR, atoi(optarg) );
592             break;
593         case 's':
594             main_PutIntVariable( INPUT_DVD_SUBTITLE_VAR, atoi(optarg) );
595             break;
596
597         /* Input options */
598         case OPT_VLANS:                                           /* --vlans */
599             p_main->b_vlans = 1;
600             break;
601         case OPT_SERVER:                                         /* --server */
602             main_PutPszVariable( INPUT_SERVER_VAR, optarg );
603             break;
604         case OPT_PORT:                                             /* --port */
605             main_PutPszVariable( INPUT_PORT_VAR, optarg );
606             break;
607         case OPT_BROADCAST:                                   /* --broadcast */
608             main_PutIntVariable( INPUT_BROADCAST_VAR, 1 );
609             break;
610         case OPT_DVD:                                               /* --dvd */
611             p_main->b_dvd = 1;
612             break;
613
614         /* Synchro options */
615         case OPT_SYNCHRO:                                      
616             main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
617             break;
618
619         /* Interface warning messages level */
620         case OPT_WARNING:                                       /* --warning */
621             main_PutIntVariable( INTF_WARNING_VAR, atoi(optarg) );
622             break;
623             
624         /* Internal error: unknown option */
625         case '?':
626         default:
627             intf_ErrMsg( "intf error: unknown option `%s'", ppsz_argv[optind - 1] );
628             Usage( USAGE );
629             return( EINVAL );
630             break;
631         }
632     }
633 #endif
634
635     /* Parse command line parameters - no check is made for these options */
636     for( i_opt = optind; i_opt < i_argc; i_opt++ )
637     {
638         putenv( ppsz_argv[ i_opt ] );
639     }
640     return( 0 );
641 }
642
643 /*****************************************************************************
644  * Usage: print program usage
645  *****************************************************************************
646  * Print a short inline help. Message interface is initialized at this stage.
647  *****************************************************************************/
648 static void Usage( int i_fashion )
649 {
650     /* Usage */
651     intf_Msg( "Usage: %s [options] [parameters] [file]...",
652               p_main->psz_arg0 );
653
654     if( i_fashion == USAGE )
655     {
656         intf_Msg( "Try `%s --help' for more information.",
657                   p_main->psz_arg0 );
658         return;
659     }
660
661     /* Options */
662     intf_Msg( "\nOptions:"
663               "\n      --noaudio                  \tdisable audio"
664               "\n      --aout <module>            \taudio output method"
665               "\n      --stereo, --mono           \tstereo/mono audio"
666               "\n"
667               "\n      --novideo                  \tdisable video"
668               "\n      --vout <module>            \tvideo output method"
669               "\n      --display <display>        \tdisplay string"
670               "\n      --width <w>, --height <h>  \tdisplay dimensions"
671               "\n  -g, --grayscale                \tgrayscale output"
672               "\n      --color                    \tcolor output"
673               "\n      --idct <module>            \tIDCT method"
674               "\n      --yuv <module>             \tYUV method"
675               "\n      --synchro <type>           \tforce synchro algorithm"
676               "\n"
677               "\n      --dvd                      \tDVD mode"
678               "\n  -a, --dvdaudio <type>          \tchoose DVD audio type"
679               "\n  -c, --dvdchannel <channel>     \tchoose DVD audio channel"
680               "\n  -s, --dvdsubtitle <channel>    \tchoose DVD subtitle channel"
681               "\n"
682               "\n      --vlans                    \tenable vlans"
683               "\n      --server <host>            \tvideo server address"
684               "\n      --port <port>              \tvideo server port"
685               "\n      --broadcast                \tlisten to a broadcast"
686               "\n"
687               "\n      --warning <level>          \tdisplay warning messages"
688               "\n"
689               "\n  -h, --help                     \tprint help and exit"
690               "\n  -H, --longhelp                 \tprint long help and exit"
691               "\n  -v, --version                  \toutput version information and exit" );
692
693     if( i_fashion == SHORT_HELP )
694         return;
695
696     /* Interface parameters */
697     intf_Msg( "\nInterface parameters:\n"
698               "\n  " INTF_INIT_SCRIPT_VAR "=<filename>               \tinitialization script"
699               "\n  " INTF_CHANNELS_VAR "=<filename>            \tchannels list"
700               "\n  " INTF_WARNING_VAR "=<level>                \twarning level" );
701
702     /* Audio parameters */
703     intf_Msg( "\nAudio parameters:"
704               "\n  " AOUT_METHOD_VAR "=<method name>        \taudio method"
705               "\n  " AOUT_DSP_VAR "=<filename>              \tdsp device path"
706               "\n  " AOUT_STEREO_VAR "={1|0}                \tstereo or mono output"
707               "\n  " AOUT_RATE_VAR "=<rate>             \toutput rate" );
708
709     /* Video parameters */
710     intf_Msg( "\nVideo parameters:"
711               "\n  " VOUT_METHOD_VAR "=<method name>        \tdisplay method"
712               "\n  " VOUT_DISPLAY_VAR "=<display name>      \tdisplay used"
713               "\n  " VOUT_WIDTH_VAR "=<width>               \tdisplay width"
714               "\n  " VOUT_HEIGHT_VAR "=<height>             \tdislay height"
715               "\n  " VOUT_FB_DEV_VAR "=<filename>           \tframebuffer device path"
716               "\n  " VOUT_GRAYSCALE_VAR "={1|0}             \tgrayscale or color output"
717               "\n  " IDCT_METHOD_VAR "=<method name>        \tIDCT method"
718               "\n  " YUV_METHOD_VAR "=<method name>         \tYUV method"
719               "\n  " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB}   \tsynchro algorithm" );
720
721     /* DVD parameters */
722     intf_Msg( "\nDVD parameters:"
723               "\n  " INPUT_DVD_DEVICE_VAR "=<device>           \tDVD device"
724               "\n  " INPUT_DVD_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type"
725               "\n  " INPUT_DVD_CHANNEL_VAR "=[0-15]            \taudio channel"
726               "\n  " INPUT_DVD_SUBTITLE_VAR "=[0-31]           \tsubtitle channel" );
727
728     /* Input parameters */
729     intf_Msg( "\nInput parameters:\n"
730               "\n  " INPUT_SERVER_VAR "=<hostname>          \tvideo server"
731               "\n  " INPUT_PORT_VAR "=<port>            \tvideo server port"
732               "\n  " INPUT_IFACE_VAR "=<interface>          \tnetwork interface"
733               "\n  " INPUT_BROADCAST_VAR "={1|0}            \tbroadcast mode"
734               "\n  " INPUT_VLAN_SERVER_VAR "=<hostname>     \tvlan server"
735               "\n  " INPUT_VLAN_PORT_VAR "=<port>           \tvlan server port"
736  );
737
738 }
739
740 /*****************************************************************************
741  * Version: print complete program version
742  *****************************************************************************
743  * Print complete program version and build number.
744  *****************************************************************************/
745 static void Version( void )
746 {
747     intf_Msg( VERSION_MESSAGE
748               "This program comes with NO WARRANTY, to the extent permitted by law.\n"
749               "You may redistribute it under the terms of the GNU General Public License;\n"
750               "see the file named COPYING for details.\n"
751               "Written by the VideoLAN team at Ecole Centrale, Paris." );
752
753 }
754
755 /*****************************************************************************
756  * InitSignalHandler: system signal handler initialization
757  *****************************************************************************
758  * Set the signal handlers. SIGTERM is not intercepted, because we need at
759  * at least a method to kill the program when all other methods failed, and
760  * when we don't want to use SIGKILL.
761  *****************************************************************************/
762 static void InitSignalHandler( void )
763 {
764     /* Termination signals */
765     signal( SIGHUP,  FatalSignalHandler );
766     signal( SIGINT,  FatalSignalHandler );
767     signal( SIGQUIT, FatalSignalHandler );
768
769     /* Other signals */
770     signal( SIGALRM, SimpleSignalHandler );
771     signal( SIGPIPE, SimpleSignalHandler );
772 }
773
774
775 /*****************************************************************************
776  * SimpleSignalHandler: system signal handler
777  *****************************************************************************
778  * This function is called when a non fatal signal is received by the program.
779  *****************************************************************************/
780 static void SimpleSignalHandler( int i_signal )
781 {
782     /* Acknowledge the signal received */
783     intf_WarnMsg(0, "intf: ignoring signal %d", i_signal );
784 }
785
786
787 /*****************************************************************************
788  * FatalSignalHandler: system signal handler
789  *****************************************************************************
790  * This function is called when a fatal signal is received by the program.
791  * It tries to end the program in a clean way.
792  *****************************************************************************/
793 static void FatalSignalHandler( int i_signal )
794 {
795     /* Once a signal has been trapped, the termination sequence will be armed and
796      * following signals will be ignored to avoid sending messages to an interface
797      * having been destroyed */
798     signal( SIGHUP,  SIG_IGN );
799     signal( SIGINT,  SIG_IGN );
800     signal( SIGQUIT, SIG_IGN );
801
802     /* Acknowledge the signal received */
803     intf_ErrMsgImm("intf error: signal %d received, exiting", i_signal );
804
805     /* Try to terminate everything - this is done by requesting the end of the
806      * interface thread */
807     p_main->p_intf->b_die = 1;
808 }
809