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