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