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