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