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