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