main.c 27.1 KB
Newer Older
1
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
2
3
4
 * main.c: main vlc source
 * Includes the main() function for vlc. Parses command line, start interface
 * and spawn threads.
5
6
7
8
9
10
11
12
13
 *****************************************************************************
 * Copyright (C) 1998, 1999, 2000 VideoLAN
 *
 * Authors:
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
14
 * 
15
16
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
19
 *
20
21
22
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
24

25
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
26
 * Preamble
27
 *****************************************************************************/
28
29
#include "defs.h"

30
31
32
#include <signal.h>                               /* SIGHUP, SIGINT, SIGKILL */
#include <stdio.h>                                              /* sprintf() */

Benoit Steiner's avatar
   
Benoit Steiner committed
33
#ifdef HAVE_GETOPT_H
Benoit Steiner's avatar
Benoit Steiner committed
34
35
36
#include <getopt.h>                                              /* getopt() */
#endif

37
38
39
#include <errno.h>                                                 /* ENOMEM */
#include <stdlib.h>                                  /* getenv(), strtol(),  */
#include <string.h>                                            /* strerror() */
Vincent Seguin's avatar
Vincent Seguin committed
40

Michel Kaempf's avatar
Michel Kaempf committed
41
42
#include "config.h"
#include "common.h"
43
#include "threads.h"
Michel Kaempf's avatar
Michel Kaempf committed
44
#include "mtime.h"
Sam Hocevar's avatar
Sam Hocevar committed
45
#include "tests.h"                                              /* TestMMX() */
46
#include "plugins.h"
47
#include "playlist.h"
48
49
#include "stream_control.h"
#include "input_ext-intf.h"
50

Vincent Seguin's avatar
Vincent Seguin committed
51
#include "intf_msg.h"
Michel Kaempf's avatar
Michel Kaempf committed
52
#include "interface.h"
53

Vincent Seguin's avatar
Vincent Seguin committed
54
#include "audio_output.h"
55

56
57
58
59
#ifdef SYS_BEOS
#include "beos_specific.h"
#endif

Vincent Seguin's avatar
Vincent Seguin committed
60
#include "main.h"
Michel Kaempf's avatar
Michel Kaempf committed
61

62
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
63
64
 * Command line options constants. If something is changed here, be sure that
 * GetConfiguration and Usage are also changed.
65
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
66
67
68
69

/* Long options return values - note that values corresponding to short options
 * chars, and in general any regular char, should be avoided */
#define OPT_NOAUDIO             150
70
71
72
#define OPT_AOUT                151
#define OPT_STEREO              152
#define OPT_MONO                153
Michel Kaempf's avatar
Michel Kaempf committed
73
74

#define OPT_NOVIDEO             160
75
76
77
78
79
#define OPT_VOUT                161
#define OPT_DISPLAY             162
#define OPT_WIDTH               163
#define OPT_HEIGHT              164
#define OPT_COLOR               165
Sam Hocevar's avatar
Sam Hocevar committed
80
#define OPT_YUV                 166
Michel Kaempf's avatar
Michel Kaempf committed
81

82
#define OPT_VLANS               170
83
84
#define OPT_SERVER              171
#define OPT_PORT                172
85
#define OPT_BROADCAST           173
86

87
88
#define OPT_SYNCHRO             180

89
90
#define OPT_WARNING             190

91
/* Usage fashion */
92
93
94
#define USAGE                     0
#define SHORT_HELP                1
#define LONG_HELP                 2
95

Michel Kaempf's avatar
Michel Kaempf committed
96
/* Long options */
Benoit Steiner's avatar
   
Benoit Steiner committed
97
#ifdef HAVE_GETOPT_H
Michel Kaempf's avatar
Michel Kaempf committed
98
static const struct option longopts[] =
99
100
{
    /*  name,               has_arg,    flag,   val */
Michel Kaempf's avatar
Michel Kaempf committed
101
102

    /* General/common options */
103
    {   "help",             0,          0,      'h' },
104
    {   "longhelp",         0,          0,      'H' },
105
    {   "version",          0,          0,      'v' },
Michel Kaempf's avatar
Michel Kaempf committed
106
107

    /* Audio options */
108
    {   "noaudio",          0,          0,      OPT_NOAUDIO },
109
    {   "aout",             1,          0,      OPT_AOUT },
Michel Kaempf's avatar
Michel Kaempf committed
110
    {   "stereo",           0,          0,      OPT_STEREO },
111
    {   "mono",             0,          0,      OPT_MONO },
Michel Kaempf's avatar
Michel Kaempf committed
112
113

    /* Video options */
114
    {   "novideo",          0,          0,      OPT_NOVIDEO },
115
    {   "vout",             1,          0,      OPT_VOUT },
116
    {   "display",          1,          0,      OPT_DISPLAY },
117
    {   "width",            1,          0,      OPT_WIDTH },
118
119
120
    {   "height",           1,          0,      OPT_HEIGHT },
    {   "grayscale",        0,          0,      'g' },
    {   "color",            0,          0,      OPT_COLOR },
Sam Hocevar's avatar
Sam Hocevar committed
121
    {   "yuv",              1,          0,      OPT_YUV },
Michel Kaempf's avatar
Michel Kaempf committed
122

123
124
125
126
127
    /* DVD options */
    {   "dvdaudio",         1,          0,      'a' },
    {   "dvdchannel",       1,          0,      'c' },
    {   "dvdsubtitle",      1,          0,      's' },
    
128
    /* Input options */
129
    {   "vlans",            0,          0,      OPT_VLANS },
130
131
    {   "server",           1,          0,      OPT_SERVER },
    {   "port",             1,          0,      OPT_PORT },
132
    {   "broadcast",        0,          0,      OPT_BROADCAST },
Michel Kaempf's avatar
Michel Kaempf committed
133

134
135
136
    /* Synchro options */
    {   "synchro",          1,          0,      OPT_SYNCHRO },

137
138
    /* Interface messages */
    {   "warning",          1,          0,      OPT_WARNING },
Michel Kaempf's avatar
Michel Kaempf committed
139
140
141
142
    {   0,                  0,          0,      0 }
};

/* Short options */
143
static const char *psz_shortopts = "hHvga:s:c:";
Benoit Steiner's avatar
Benoit Steiner committed
144
145
#endif

Michel Kaempf's avatar
Michel Kaempf committed
146

147
/*****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
148
 * Global variable program_data - this is the one and only, see main.h
149
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
150
main_t *p_main;
Michel Kaempf's avatar
Michel Kaempf committed
151

152
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
153
 * Local prototypes
154
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
155
static void SetDefaultConfiguration ( void );
156
157
static int  GetConfiguration        ( int i_argc, char *ppsz_argv[],
                                      char *ppsz_env[] );
158
static void Usage                   ( int i_fashion );
Vincent Seguin's avatar
Vincent Seguin committed
159
static void Version                 ( void );
Vincent Seguin's avatar
Vincent Seguin committed
160

Michel Kaempf's avatar
Michel Kaempf committed
161
162
static void InitSignalHandler       ( void );
static void SignalHandler           ( int i_signal );
163
#ifdef HAVE_MMX
164
       int  TestMMX                 ( void );
165
#endif
Michel Kaempf's avatar
Michel Kaempf committed
166

167
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
168
 * main: parse command line, start interface and spawn threads
169
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
170
171
 * Steps during program execution are:
 *      -configuration parsing and messages interface initialization
172
 *      -opening of audio output device and some global modules
Michel Kaempf's avatar
Michel Kaempf committed
173
 *      -execution of interface, which exit on error or on user request
Vincent Seguin's avatar
Vincent Seguin committed
174
 *      -closing of audio output device and some global modules
175
 * On error, the spawned threads are canceled, and the open devices closed.
176
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
177
178
int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
{
179
    main_t  main_data;                      /* root of all data - see main.h */
180

181
    p_main = &main_data;                       /* set up the global variable */
Vincent Seguin's avatar
Vincent Seguin committed
182

183
184
185
    /*
     * System specific initialization code
     */
Sam Hocevar's avatar
Sam Hocevar committed
186
#ifdef SYS_BEOS
187
    beos_Create();
188
189
#endif

Michel Kaempf's avatar
Michel Kaempf committed
190
    /*
191
     * Test if our code is likely to run on this CPU 
192
     */
Sam Hocevar's avatar
Sam Hocevar committed
193
#ifdef HAVE_MMX
194
195
    if( !TestMMX() )
    {
196
197
        fprintf( stderr, "Sorry, this program needs an MMX processor. "
                         "Please run the non-MMX version.\n" );
198
        return( 1 );
199
200
    }
#endif
201
202
203
204

    /*
     * Initialize messages interface
     */
Vincent Seguin's avatar
Vincent Seguin committed
205
    p_main->p_msg = intf_MsgCreate();
206
    if( !p_main->p_msg )                         /* start messages interface */
Michel Kaempf's avatar
Michel Kaempf committed
207
    {
208
        fprintf( stderr, "error: can't initialize messages interface (%s)\n",
209
210
                strerror(errno) );
        return( errno );
Michel Kaempf's avatar
Michel Kaempf committed
211
    }
212
213
214
215

    /*
     * Read configuration
     */
216
    if( GetConfiguration( i_argc, ppsz_argv, ppsz_env ) )  /* parse cmd line */
Michel Kaempf's avatar
Michel Kaempf committed
217
    {
Vincent Seguin's avatar
Vincent Seguin committed
218
        intf_MsgDestroy();
219
        return( errno );
Michel Kaempf's avatar
Michel Kaempf committed
220
    }
221

222
223
224
225
226
    /*
     * Initialize playlist and get commandline files
     */
    p_main->p_playlist = playlist_Create( );
    if( !p_main->p_playlist )
227
    {
228
229
230
        intf_Msg( "Playlist initialization failed\n" );
        intf_MsgDestroy();
        return( errno );
231
    }
232
233
234
235
236
237
238
    playlist_Init( p_main->p_playlist, optind );

    /*
     * Initialize plugin bank
     */
    p_main->p_bank = bank_Create( );
    if( !p_main->p_bank )
239
    {
240
241
242
243
        intf_Msg( "Plugin bank initialization failed\n" );
        playlist_Destroy( p_main->p_playlist );
        intf_MsgDestroy();
        return( errno );
244
    }
245
    bank_Init( p_main->p_bank );
Michel Kaempf's avatar
Michel Kaempf committed
246
247
248
249

    /*
     * Initialize shared resources and libraries
     */
250
251
    /* FIXME: no VLANs */
#if 0
252
    if( p_main->b_vlans && input_VlanCreate() )
Michel Kaempf's avatar
Michel Kaempf committed
253
    {
254
255
256
257
        /* On error during vlans initialization, switch off vlans */
        intf_Msg( "Virtual LANs initialization failed : "
                  "vlans management is deactivated\n" );
        p_main->b_vlans = 0;
Michel Kaempf's avatar
Michel Kaempf committed
258
    }
259
#endif
260

Michel Kaempf's avatar
Michel Kaempf committed
261
    /*
Vincent Seguin's avatar
Vincent Seguin committed
262
     * Open audio device and start aout thread
Michel Kaempf's avatar
Michel Kaempf committed
263
     */
264
    if( p_main->b_audio )
Vincent Seguin's avatar
Vincent Seguin committed
265
    {
266
267
        p_main->p_aout = aout_CreateThread( NULL );
        if( p_main->p_aout == NULL )
268
        {
269
            /* On error during audio initialization, switch off audio */
270
            intf_Msg( "Audio initialization failed : audio is deactivated\n" );
271
            p_main->b_audio = 0;
272
        }
Michel Kaempf's avatar
Michel Kaempf committed
273
    }
274

Michel Kaempf's avatar
Michel Kaempf committed
275
276
277
    /*
     * Run interface
     */
278
279
    p_main->p_intf = intf_Create();
    if( p_main->p_intf != NULL )
Vincent Seguin's avatar
Vincent Seguin committed
280
    {
281
        InitSignalHandler();             /* prepare signals for interception */
282

Sam Hocevar's avatar
Sam Hocevar committed
283
284
285
        /*
         * This is the main loop
         */
286
287
288
        intf_Run( p_main->p_intf );

        intf_Destroy( p_main->p_intf );
Vincent Seguin's avatar
Vincent Seguin committed
289
    }
Michel Kaempf's avatar
Michel Kaempf committed
290

Michel Kaempf's avatar
Michel Kaempf committed
291
    /*
Michel Kaempf's avatar
Michel Kaempf committed
292
293
     * Close audio device
     */
294
    if( p_main->b_audio )
Michel Kaempf's avatar
Michel Kaempf committed
295
    {
296
        aout_DestroyThread( p_main->p_aout, NULL );
Michel Kaempf's avatar
Michel Kaempf committed
297
    }
Michel Kaempf's avatar
Michel Kaempf committed
298
299
300
301

    /*
     * Free shared resources and libraries
     */
302
303
    /* FIXME */
#if 0
304
    if( p_main->b_vlans )
305
306
307
    {
        input_VlanDestroy();
    }
308
#endif
Michel Kaempf's avatar
Michel Kaempf committed
309

310
    /*
311
     * Free plugin bank
312
     */
313
314
315
316
317
318
319
    bank_Destroy( p_main->p_bank );

    /*
     * Free playlist
     */
    playlist_Destroy( p_main->p_playlist );

320
#ifdef SYS_BEOS
321
322
323
324
    /*
     * System specific cleaning code
     */
    beos_Destroy();
325
326
#endif

Michel Kaempf's avatar
Michel Kaempf committed
327
328
329
    /*
     * Terminate messages interface and program
     */
Vincent Seguin's avatar
Vincent Seguin committed
330
331
    intf_Msg( "Program terminated.\n" );
    intf_MsgDestroy();
332

Michel Kaempf's avatar
Michel Kaempf committed
333
334
335
    return( 0 );
}

336
/*****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
337
 * main_GetIntVariable: get the int value of an environment variable
338
 *****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
339
 * This function is used to read some default parameters in modules.
340
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
341
342
int main_GetIntVariable( char *psz_name, int i_default )
{
343
344
345
    char *      psz_env;                                /* environment value */
    char *      psz_end;                             /* end of parsing index */
    long int    i_value;                                            /* value */
Vincent Seguin's avatar
Vincent Seguin committed
346
347
348

    psz_env = getenv( psz_name );
    if( psz_env )
349
    {
350
351
352
353
        i_value = strtol( psz_env, &psz_end, 0 );
        if( (*psz_env != '\0') && (*psz_end == '\0') )
        {
            return( i_value );
354
        }
355
    }
Vincent Seguin's avatar
Vincent Seguin committed
356
357
358
    return( i_default );
}

359
/*****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
360
 * main_GetPszVariable: get the string value of an environment variable
361
 *****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
362
 * This function is used to read some default parameters in modules.
363
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
364
365
366
367
368
369
370
char * main_GetPszVariable( char *psz_name, char *psz_default )
{
    char *psz_env;

    psz_env = getenv( psz_name );
    if( psz_env )
    {
371
        return( psz_env );
Vincent Seguin's avatar
Vincent Seguin committed
372
    }
373
    return( psz_default );
Vincent Seguin's avatar
Vincent Seguin committed
374
375
}

376
/*****************************************************************************
377
 * main_PutPszVariable: set the string value of an environment variable
378
 *****************************************************************************
379
380
381
 * This function is used to set some default parameters in modules. The use of
 * this function will cause some memory leak: since some systems use the pointer
 * passed to putenv to store the environment string, it can't be freed.
382
 *****************************************************************************/
383
384
385
386
387
388
389
void main_PutPszVariable( char *psz_name, char *psz_value )
{
    char *psz_env;

    psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
    if( psz_env == NULL )
    {
390
        intf_ErrMsg( "error: %s\n", strerror(ENOMEM) );
391
392
393
394
395
396
    }
    else
    {
        sprintf( psz_env, "%s=%s", psz_name, psz_value );
        if( putenv( psz_env ) )
        {
397
            intf_ErrMsg( "error: %s\n", strerror(errno) );
398
        }
399
400
401
    }
}

402
/*****************************************************************************
403
 * main_PutIntVariable: set the integer value of an environment variable
404
 *****************************************************************************
405
406
407
 * This function is used to set some default parameters in modules. The use of
 * this function will cause some memory leak: since some systems use the pointer
 * passed to putenv to store the environment string, it can't be freed.
408
 *****************************************************************************/
409
410
void main_PutIntVariable( char *psz_name, int i_value )
{
411
    char psz_value[ 256 ];                               /* buffer for value */
412

413
    sprintf( psz_value, "%d", i_value );
414
    main_PutPszVariable( psz_name, psz_value );
415
416
}

Michel Kaempf's avatar
Michel Kaempf committed
417
418
/* following functions are local */

419
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
420
 * SetDefaultConfiguration: set default options
421
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
422
 * This function is called by GetConfiguration before command line is parsed.
Vincent Seguin's avatar
Vincent Seguin committed
423
424
425
 * It sets all the default values required later by the program. At this stage,
 * most structure are not yet allocated, so initialization must be done using
 * environment.
426
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
427
static void SetDefaultConfiguration( void )
Michel Kaempf's avatar
Michel Kaempf committed
428
429
{
    /*
430
     * All features are activated by default execpted vlans
Michel Kaempf's avatar
Michel Kaempf committed
431
     */
Vincent Seguin's avatar
Vincent Seguin committed
432
433
    p_main->b_audio  = 1;
    p_main->b_video  = 1;
434
    p_main->b_vlans  = 0;
Michel Kaempf's avatar
Michel Kaempf committed
435
436
}

437
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
438
 * GetConfiguration: parse command line
439
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
440
441
 * Parse command line and configuration file for configuration. If the inline
 * help is requested, the function Usage() is called and the function returns
442
 * -1 (causing main() to exit). The messages interface is initialized at this
Vincent Seguin's avatar
Vincent Seguin committed
443
444
 * stage, but most structures are not allocated, so only environment should
 * be used.
445
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
446
static int GetConfiguration( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
Michel Kaempf's avatar
Michel Kaempf committed
447
{
Vincent Seguin's avatar
Vincent Seguin committed
448
    int c, i_opt;
Sam Hocevar's avatar
Sam Hocevar committed
449
    char * p_pointer;
Michel Kaempf's avatar
Michel Kaempf committed
450
451

    /* Set default configuration and copy arguments */
Vincent Seguin's avatar
Vincent Seguin committed
452
453
    p_main->i_argc    = i_argc;
    p_main->ppsz_argv = ppsz_argv;
454
    p_main->ppsz_env  = ppsz_env;
Vincent Seguin's avatar
Vincent Seguin committed
455
    SetDefaultConfiguration();
Michel Kaempf's avatar
Michel Kaempf committed
456

Sam Hocevar's avatar
Sam Hocevar committed
457
458
    intf_MsgImm( COPYRIGHT_MESSAGE "\n" );

459
    /* Get the executable name (similar to the basename command) */
Sam Hocevar's avatar
Sam Hocevar committed
460
461
462
463
464
465
466
467
468
469
470
471
472
    p_main->psz_arg0 = p_pointer = ppsz_argv[ 0 ];
    while( *p_pointer )
    {
        if( *p_pointer == '/' )
        {
            p_main->psz_arg0 = ++p_pointer;
        }
        else
        {
            ++p_pointer;
        }
    }

Vincent Seguin's avatar
Vincent Seguin committed
473
    /* Parse command line options */
Benoit Steiner's avatar
   
Benoit Steiner committed
474
#ifdef HAVE_GETOPT_H
Michel Kaempf's avatar
Michel Kaempf committed
475
476
477
478
479
    opterr = 0;
    while( ( c = getopt_long( i_argc, ppsz_argv, psz_shortopts, longopts, 0 ) ) != EOF )
    {
        switch( c )
        {
480
481
        /* General/common options */
        case 'h':                                              /* -h, --help */
482
483
484
            Usage( SHORT_HELP );
            return( -1 );
            break;
485
        case 'H':                                          /* -H, --longhelp */
486
            Usage( LONG_HELP );
Michel Kaempf's avatar
Michel Kaempf committed
487
488
            return( -1 );
            break;
489
        case 'v':                                           /* -v, --version */
Vincent Seguin's avatar
Vincent Seguin committed
490
491
            Version();
            return( -1 );
492
            break;
Michel Kaempf's avatar
Michel Kaempf committed
493
494

        /* Audio options */
495
        case OPT_NOAUDIO:                                       /* --noaudio */
496
            p_main->b_audio = 0;
Michel Kaempf's avatar
Michel Kaempf committed
497
            break;
498
499
500
        case OPT_AOUT:                                             /* --aout */
            main_PutPszVariable( AOUT_METHOD_VAR, optarg );
            break;
501
        case OPT_STEREO:                                         /* --stereo */
502
            main_PutIntVariable( AOUT_STEREO_VAR, 1 );
Michel Kaempf's avatar
Michel Kaempf committed
503
            break;
504
        case OPT_MONO:                                             /* --mono */
505
            main_PutIntVariable( AOUT_STEREO_VAR, 0 );
Michel Kaempf's avatar
Michel Kaempf committed
506
507
508
            break;

        /* Video options */
509
        case OPT_NOVIDEO:                                       /* --novideo */
Vincent Seguin's avatar
Vincent Seguin committed
510
            p_main->b_video = 0;
511
            break;
512
513
514
        case OPT_VOUT:                                             /* --vout */
            main_PutPszVariable( VOUT_METHOD_VAR, optarg );
            break;
515
        case OPT_DISPLAY:                                       /* --display */
516
            main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
517
518
            break;
        case OPT_WIDTH:                                           /* --width */
519
            main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
520
521
522
523
524
525
            break;
        case OPT_HEIGHT:                                         /* --height */
            main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
            break;

        case 'g':                                         /* -g, --grayscale */
526
            main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
527
528
            break;
        case OPT_COLOR:                                           /* --color */
529
            main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
530
            break;
Sam Hocevar's avatar
Sam Hocevar committed
531
532
533
        case OPT_YUV:                                               /* --yuv */
            main_PutPszVariable( YUV_METHOD_VAR, optarg );
            break;
Michel Kaempf's avatar
Michel Kaempf committed
534

535
536
            /* FIXME */
#if 0
537
538
539
540
541
542
543
544
545
546
547
        /* DVD options */
        case 'a':
            if ( ! strcmp(optarg, "mpeg") )
                main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_MPEG );
            else if ( ! strcmp(optarg, "lpcm") )
                main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_LPCM );
            else if ( ! strcmp(optarg, "off") )
                main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_NOAUDIO );
            else
                main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_AC3 );
            break;
548
#endif
549
550
551
552
553
554
555
        case 'c':
            main_PutIntVariable( INPUT_DVD_CHANNEL_VAR, atoi(optarg) );
            break;
        case 's':
            main_PutIntVariable( INPUT_DVD_SUBTITLE_VAR, atoi(optarg) );
            break;

556
        /* Input options */
557
        case OPT_VLANS:                                           /* --vlans */
558
            p_main->b_vlans = 1;
559
560
            break;
        case OPT_SERVER:                                         /* --server */
561
            main_PutPszVariable( INPUT_SERVER_VAR, optarg );
562
563
            break;
        case OPT_PORT:                                             /* --port */
564
            main_PutPszVariable( INPUT_PORT_VAR, optarg );
565
            break;
566
567
568
        case OPT_BROADCAST:                                   /* --broadcast */
            main_PutIntVariable( INPUT_BROADCAST_VAR, 1 );
            break;
569

570
        /* Synchro options */
571
        case OPT_SYNCHRO:                                      
572
573
574
            main_PutPszVariable( VPAR_SYNCHRO_VAR, optarg );
            break;

575
576
577
578
579
        /* Interface warning messages level */
        case OPT_WARNING:                                       /* --warning */
            main_PutIntVariable( INTF_WARNING_VAR, atoi(optarg) );
            break;
            
Michel Kaempf's avatar
Michel Kaempf committed
580
        /* Internal error: unknown option */
581
        case '?':
Michel Kaempf's avatar
Michel Kaempf committed
582
        default:
583
584
            intf_ErrMsg( "intf error: unknown option `%s'\n", ppsz_argv[optind - 1] );
            Usage( USAGE );
Michel Kaempf's avatar
Michel Kaempf committed
585
586
587
588
            return( EINVAL );
            break;
        }
    }
Benoit Steiner's avatar
Benoit Steiner committed
589
#endif
Michel Kaempf's avatar
Michel Kaempf committed
590

Vincent Seguin's avatar
Vincent Seguin committed
591
592
593
    /* Parse command line parameters - no check is made for these options */
    for( i_opt = optind; i_opt < i_argc; i_opt++ )
    {
594
        putenv( ppsz_argv[ i_opt ] );
Vincent Seguin's avatar
Vincent Seguin committed
595
    }
Michel Kaempf's avatar
Michel Kaempf committed
596
597
598
    return( 0 );
}

599
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
600
 * Usage: print program usage
601
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
602
 * Print a short inline help. Message interface is initialized at this stage.
603
 *****************************************************************************/
604
static void Usage( int i_fashion )
Michel Kaempf's avatar
Michel Kaempf committed
605
{
Vincent Seguin's avatar
Vincent Seguin committed
606
    /* Usage */
Sam Hocevar's avatar
Sam Hocevar committed
607
608
    intf_Msg( "Usage: %s [options] [parameters] [file]...\n",
              p_main->psz_arg0 );
609
610
611

    if( i_fashion == USAGE )
    {
Sam Hocevar's avatar
Sam Hocevar committed
612
613
        intf_Msg( "Try `%s --help' for more information.\n",
                  p_main->psz_arg0 );
614
615
616
        return;
    }

Vincent Seguin's avatar
Vincent Seguin committed
617
    /* Options */
618
619
620
621
622
623
    intf_Msg( "\n"
              "Options:\n"
              "      --noaudio                  \tdisable audio\n"
              "      --aout <plugin>            \taudio output method\n"
              "      --stereo, --mono           \tstereo/mono audio\n"
              "\n"
624
              "      --novideo                  \tdisable video\n"
625
626
627
628
629
630
              "      --vout <plugin>            \tvideo output method\n"
              "      --display <display>        \tdisplay string\n"
              "      --width <w>, --height <h>  \tdisplay dimensions\n"
              "  -g, --grayscale                \tgrayscale output\n"
              "      --color                    \tcolor output\n"
              "\n"
631
632
633
              "  -a, --dvdaudio <type>          \tchoose DVD audio type\n"
              "  -c, --dvdchannel <channel>     \tchoose DVD audio channel\n"
              "  -s, --dvdsubtitle <channel>    \tchoose DVD subtitle channel\n"
634
              "\n"
635
              "      --vlans                    \tenable vlans\n"
636
637
              "      --server <host>            \tvideo server address\n"
              "      --port <port>              \tvideo server port\n"
638
              "      --broadcast                \tlisten to a broadcast\n"
639
              "\n"
640
641
              "      --synchro <type>           \tforce synchro algorithm\n"
              "\n"
642
643
              "      --warning <level>          \tdisplay warning messages\n"
              "\n"
644
645
646
              "  -h, --help                     \tprint help and exit\n"
              "  -H, --longhelp                 \tprint long help and exit\n"
              "  -v, --version                  \toutput version information and exit\n" );
Michel Kaempf's avatar
Michel Kaempf committed
647

648
649
650
    if( i_fashion == SHORT_HELP )
        return;

Vincent Seguin's avatar
Vincent Seguin committed
651
    /* Interface parameters */
652
653
    intf_Msg( "\n"
              "Interface parameters:\n"
654
              "  " INTF_INIT_SCRIPT_VAR "=<filename>               \tinitialization script\n"
655
656
              "  " INTF_CHANNELS_VAR "=<filename>            \tchannels list\n"
              "  " INTF_WARNING_VAR "=<level>                \twarning level\n" );
Vincent Seguin's avatar
Vincent Seguin committed
657
658

    /* Audio parameters */
659
660
661
662
663
664
    intf_Msg( "\n"
              "Audio parameters:\n"
              "  " AOUT_METHOD_VAR "=<method name>        \taudio method\n"
              "  " AOUT_DSP_VAR "=<filename>              \tdsp device path\n"
              "  " AOUT_STEREO_VAR "={1|0}                \tstereo or mono output\n"
              "  " AOUT_RATE_VAR "=<rate>             \toutput rate\n" );
Vincent Seguin's avatar
Vincent Seguin committed
665
666

    /* Video parameters */
667
668
669
670
671
672
673
674
    intf_Msg( "\n"
              "Video parameters:\n"
              "  " VOUT_METHOD_VAR "=<method name>        \tdisplay method\n"
              "  " VOUT_DISPLAY_VAR "=<display name>      \tdisplay used\n"
              "  " VOUT_WIDTH_VAR "=<width>               \tdisplay width\n"
              "  " VOUT_HEIGHT_VAR "=<height>             \tdislay height\n"
              "  " VOUT_FB_DEV_VAR "=<filename>           \tframebuffer device path\n"
              "  " VOUT_GRAYSCALE_VAR "={1|0}             \tgrayscale or color output\n" );
Vincent Seguin's avatar
Vincent Seguin committed
675

676
677
678
679
680
681
682
    /* DVD parameters */
    intf_Msg( "\n"
              "DVD parameters:\n"
              "  " INPUT_DVD_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type\n"
              "  " INPUT_DVD_CHANNEL_VAR "=[0-15]            \taudio channel\n"
              "  " INPUT_DVD_SUBTITLE_VAR "=[0-31]           \tsubtitle channel\n" );

683
    /* Input parameters */
684
685
686
687
688
    intf_Msg( "\n"
              "Input parameters:\n"
              "  " INPUT_SERVER_VAR "=<hostname>          \tvideo server\n"
              "  " INPUT_PORT_VAR "=<port>            \tvideo server port\n"
              "  " INPUT_IFACE_VAR "=<interface>          \tnetwork interface\n"
689
              "  " INPUT_BROADCAST_VAR "={1|0}            \tbroadcast mode\n"
690
691
              "  " INPUT_VLAN_SERVER_VAR "=<hostname>     \tvlan server\n"
              "  " INPUT_VLAN_PORT_VAR "=<port>           \tvlan server port\n" );
692
693
694
695

    /* Synchro parameters */
    intf_Msg( "\n"
              "Synchro parameters:\n"
696
              "  " VPAR_SYNCHRO_VAR "={I|I+|IP|IP+|IPB}   \tsynchro algorithm\n");
Michel Kaempf's avatar
Michel Kaempf committed
697
698
}

699
/*****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
700
 * Version: print complete program version
701
 *****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
702
 * Print complete program version and build number.
703
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
704
705
static void Version( void )
{
706
    intf_Msg( VERSION_MESSAGE
707
708
709
710
              "This program comes with NO WARRANTY, to the extent permitted by law.\n"
              "You may redistribute it under the terms of the GNU General Public License;\n"
              "see the file named COPYING for details.\n"
              "Written by the VideoLAN team at Ecole Centrale, Paris.\n" );
711

712
}
Vincent Seguin's avatar
Vincent Seguin committed
713

714
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
715
 * InitSignalHandler: system signal handler initialization
716
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
717
 * Set the signal handlers. SIGTERM is not intercepted, because we need at
718
 * at least a method to kill the program when all other methods failed, and
Michel Kaempf's avatar
Michel Kaempf committed
719
 * when we don't want to use SIGKILL.
720
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
721
722
static void InitSignalHandler( void )
{
Vincent Seguin's avatar
Vincent Seguin committed
723
724
725
726
    /* Termination signals */
    signal( SIGHUP,  SignalHandler );
    signal( SIGINT,  SignalHandler );
    signal( SIGQUIT, SignalHandler );
Michel Kaempf's avatar
Michel Kaempf committed
727
728
}

729
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
730
 * SignalHandler: system signal handler
731
 *****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
732
733
 * This function is called when a signal is received by the program. It tries to
 * end the program in a clean way.
734
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
735
736
static void SignalHandler( int i_signal )
{
737
    /* Once a signal has been trapped, the termination sequence will be armed and
Vincent Seguin's avatar
Vincent Seguin committed
738
739
740
741
742
743
744
745
746
     * following signals will be ignored to avoid sending messages to an interface
     * having been destroyed */
    signal( SIGHUP,  SIG_IGN );
    signal( SIGINT,  SIG_IGN );
    signal( SIGQUIT, SIG_IGN );

    /* Acknowledge the signal received */
    intf_ErrMsgImm("intf: signal %d received\n", i_signal );

747
    /* Try to terminate everything - this is done by requesting the end of the
Vincent Seguin's avatar
Vincent Seguin committed
748
749
750
751
     * interface thread */
    p_main->p_intf->b_die = 1;
}