main.c 23.9 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 14 15 16 17 18 19 20 21 22 23
 *****************************************************************************
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * 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-1307, USA.
24
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
25

26
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
27
 * Preamble
28
 *****************************************************************************/
29 30 31 32 33 34 35
#include <getopt.h>                                              /* getopt() */
#include <signal.h>                               /* SIGHUP, SIGINT, SIGKILL */
#include <stdio.h>                                              /* sprintf() */

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

Michel Kaempf's avatar
Michel Kaempf committed
37 38 39
#include "config.h"
#include "common.h"
#include "mtime.h"
40
#include "threads.h"
Michel Kaempf's avatar
Michel Kaempf committed
41
#include "input_vlan.h"
42

Vincent Seguin's avatar
Vincent Seguin committed
43
#include "intf_msg.h"
Michel Kaempf's avatar
Michel Kaempf committed
44
#include "interface.h"
45

Vincent Seguin's avatar
Vincent Seguin committed
46
#include "audio_output.h"
47

Vincent Seguin's avatar
Vincent Seguin committed
48
#include "main.h"
Michel Kaempf's avatar
Michel Kaempf committed
49

50
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
51 52
 * Command line options constants. If something is changed here, be sure that
 * GetConfiguration and Usage are also changed.
53
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
54 55 56 57

/* 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
58 59 60
#define OPT_AOUT                151
#define OPT_STEREO              152
#define OPT_MONO                153
Michel Kaempf's avatar
Michel Kaempf committed
61 62

#define OPT_NOVIDEO             160
63 64 65 66 67
#define OPT_VOUT                161
#define OPT_DISPLAY             162
#define OPT_WIDTH               163
#define OPT_HEIGHT              164
#define OPT_COLOR               165
Michel Kaempf's avatar
Michel Kaempf committed
68 69

#define OPT_NOVLANS             170
70 71
#define OPT_SERVER              171
#define OPT_PORT                172
72

73 74 75 76
/* Usage fashion */
#define SHORT_HELP                0
#define LONG_HELP                 1

Michel Kaempf's avatar
Michel Kaempf committed
77 78
/* Long options */
static const struct option longopts[] =
79 80
{
    /*  name,               has_arg,    flag,   val */
Michel Kaempf's avatar
Michel Kaempf committed
81 82

    /* General/common options */
83
    {   "help",             0,          0,      'h' },
84
    {   "longhelp",         0,          0,      'H' },
85
    {   "version",          0,          0,      'v' },
Michel Kaempf's avatar
Michel Kaempf committed
86 87

    /* Audio options */
88
    {   "noaudio",          0,          0,      OPT_NOAUDIO },
89
    {   "aout",             1,          0,      OPT_AOUT },
Michel Kaempf's avatar
Michel Kaempf committed
90
    {   "stereo",           0,          0,      OPT_STEREO },
91
    {   "mono",             0,          0,      OPT_MONO },
Michel Kaempf's avatar
Michel Kaempf committed
92 93

    /* Video options */
94
    {   "novideo",          0,          0,      OPT_NOVIDEO },
95
    {   "vout",             1,          0,      OPT_VOUT },
96
    {   "display",          1,          0,      OPT_DISPLAY },
97
    {   "width",            1,          0,      OPT_WIDTH },
98 99 100
    {   "height",           1,          0,      OPT_HEIGHT },
    {   "grayscale",        0,          0,      'g' },
    {   "color",            0,          0,      OPT_COLOR },
Michel Kaempf's avatar
Michel Kaempf committed
101

102
    /* Input options */
Michel Kaempf's avatar
Michel Kaempf committed
103
    {   "novlans",          0,          0,      OPT_NOVLANS },
104 105
    {   "server",           1,          0,      OPT_SERVER },
    {   "port",             1,          0,      OPT_PORT },
Michel Kaempf's avatar
Michel Kaempf committed
106 107 108 109 110

    {   0,                  0,          0,      0 }
};

/* Short options */
111
static const char *psz_shortopts = "hHvg";
Michel Kaempf's avatar
Michel Kaempf committed
112

113
/*****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
114
 * Global variable program_data - this is the one and only, see main.h
115
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
116
main_t *p_main;
Michel Kaempf's avatar
Michel Kaempf committed
117

118
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
119
 * Local prototypes
120
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
121 122
static void SetDefaultConfiguration ( void );
static int  GetConfiguration        ( int i_argc, char *ppsz_argv[], char *ppsz_env[] );
123
static void Usage                   ( int i_fashion );
Vincent Seguin's avatar
Vincent Seguin committed
124
static void Version                 ( void );
Vincent Seguin's avatar
Vincent Seguin committed
125

Michel Kaempf's avatar
Michel Kaempf committed
126 127
static void InitSignalHandler       ( void );
static void SignalHandler           ( int i_signal );
128
static int  TestMMX                 ( void );
Michel Kaempf's avatar
Michel Kaempf committed
129

130
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
131
 * main: parse command line, start interface and spawn threads
132
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
133 134
 * Steps during program execution are:
 *      -configuration parsing and messages interface initialization
Vincent Seguin's avatar
Vincent Seguin committed
135
 *      -openning of audio output device and some global modules
Michel Kaempf's avatar
Michel Kaempf committed
136
 *      -execution of interface, which exit on error or on user request
Vincent Seguin's avatar
Vincent Seguin committed
137
 *      -closing of audio output device and some global modules
138
 * On error, the spawned threads are cancelled, and the open devices closed.
139
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
140 141
int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
{
142 143
    main_t  main_data;                      /* root of all data - see main.h */
    p_main = &main_data;                       /* set up the global variable */
Vincent Seguin's avatar
Vincent Seguin committed
144

Michel Kaempf's avatar
Michel Kaempf committed
145 146
    /*
     * Read configuration, initialize messages interface and set up program
147
     */
148 149 150 151
#ifdef HAVE_MMX
    if( !TestMMX() )
    {
        fprintf( stderr, "Sorry, this program needs an MMX processor. Please run the non-MMX version.\n" );
152
        return( 1 );
153 154
    }
#endif
Vincent Seguin's avatar
Vincent Seguin committed
155
    p_main->p_msg = intf_MsgCreate();
156
    if( !p_main->p_msg )                         /* start messages interface */
Michel Kaempf's avatar
Michel Kaempf committed
157
    {
Vincent Seguin's avatar
Vincent Seguin committed
158
        fprintf(stderr, "critical error: can't initialize messages interface (%s)\n",
Michel Kaempf's avatar
Michel Kaempf committed
159 160 161
                strerror(errno));
        return(errno);
    }
162
    if( GetConfiguration( i_argc, ppsz_argv, ppsz_env ) )  /* parse cmd line */
Michel Kaempf's avatar
Michel Kaempf committed
163
    {
Vincent Seguin's avatar
Vincent Seguin committed
164
        intf_MsgDestroy();
Michel Kaempf's avatar
Michel Kaempf committed
165 166
        return(errno);
    }
167
    intf_MsgImm( COPYRIGHT_MESSAGE "\n" );          /* print welcome message */
Michel Kaempf's avatar
Michel Kaempf committed
168 169 170 171

    /*
     * Initialize shared resources and libraries
     */
Vincent Seguin's avatar
Vincent Seguin committed
172
    if( main_data.b_vlans && input_VlanCreate() )
Michel Kaempf's avatar
Michel Kaempf committed
173 174
    {
        /* On error during vlans initialization, switch of vlans */
175
        intf_Msg("Virtual LANs initialization failed : vlans management is deactivated\n");
Vincent Seguin's avatar
Vincent Seguin committed
176
        main_data.b_vlans = 0;
Michel Kaempf's avatar
Michel Kaempf committed
177
    }
178

Michel Kaempf's avatar
Michel Kaempf committed
179
    /*
Vincent Seguin's avatar
Vincent Seguin committed
180
     * Open audio device and start aout thread
Michel Kaempf's avatar
Michel Kaempf committed
181
     */
Vincent Seguin's avatar
Vincent Seguin committed
182 183 184
    if( main_data.b_audio )
    {
        main_data.p_aout = aout_CreateThread( NULL );
185 186 187
        if( main_data.p_aout == NULL )
        {
            /* On error during audio initialization, switch of audio */
188
            intf_Msg("Audio initialization failed : audio is deactivated\n");
Vincent Seguin's avatar
Vincent Seguin committed
189
            main_data.b_audio = 0;
190
        }
Michel Kaempf's avatar
Michel Kaempf committed
191
    }
192

Michel Kaempf's avatar
Michel Kaempf committed
193 194 195
    /*
     * Run interface
     */
Vincent Seguin's avatar
Vincent Seguin committed
196 197 198
    main_data.p_intf = intf_Create();
    if( main_data.p_intf != NULL )
    {
199
        InitSignalHandler();             /* prepare signals for interception */
200 201
        intf_Run( main_data.p_intf );
        intf_Destroy( main_data.p_intf );
Vincent Seguin's avatar
Vincent Seguin committed
202
    }
Michel Kaempf's avatar
Michel Kaempf committed
203

Michel Kaempf's avatar
Michel Kaempf committed
204
    /*
Michel Kaempf's avatar
Michel Kaempf committed
205 206
     * Close audio device
     */
Vincent Seguin's avatar
Vincent Seguin committed
207
    if( main_data.b_audio )
Michel Kaempf's avatar
Michel Kaempf committed
208
    {
Vincent Seguin's avatar
Vincent Seguin committed
209
        aout_DestroyThread( main_data.p_aout, NULL );
Michel Kaempf's avatar
Michel Kaempf committed
210
    }
Michel Kaempf's avatar
Michel Kaempf committed
211 212 213 214

    /*
     * Free shared resources and libraries
     */
Vincent Seguin's avatar
Vincent Seguin committed
215
    if( main_data.b_vlans )
216 217 218
    {
        input_VlanDestroy();
    }
Michel Kaempf's avatar
Michel Kaempf committed
219 220 221 222

    /*
     * Terminate messages interface and program
     */
Vincent Seguin's avatar
Vincent Seguin committed
223 224
    intf_Msg( "Program terminated.\n" );
    intf_MsgDestroy();
Michel Kaempf's avatar
Michel Kaempf committed
225 226 227
    return( 0 );
}

228
/*****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
229
 * main_GetIntVariable: get the int value of an environment variable
230
 *****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
231
 * This function is used to read some default parameters in modules.
232
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
233 234
int main_GetIntVariable( char *psz_name, int i_default )
{
235 236 237
    char *      psz_env;                                /* environment value */
    char *      psz_end;                             /* end of parsing index */
    long int    i_value;                                            /* value */
Vincent Seguin's avatar
Vincent Seguin committed
238 239 240

    psz_env = getenv( psz_name );
    if( psz_env )
241
    {
242 243 244 245
        i_value = strtol( psz_env, &psz_end, 0 );
        if( (*psz_env != '\0') && (*psz_end == '\0') )
        {
            return( i_value );
246
        }
247
    }
Vincent Seguin's avatar
Vincent Seguin committed
248 249 250
    return( i_default );
}

251
/*****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
252
 * main_GetPszVariable: get the string value of an environment variable
253
 *****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
254
 * This function is used to read some default parameters in modules.
255
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
256 257 258 259 260 261 262
char * main_GetPszVariable( char *psz_name, char *psz_default )
{
    char *psz_env;

    psz_env = getenv( psz_name );
    if( psz_env )
    {
263
        return( psz_env );
Vincent Seguin's avatar
Vincent Seguin committed
264
    }
265
    return( psz_default );
Vincent Seguin's avatar
Vincent Seguin committed
266 267
}

268
/*****************************************************************************
269
 * main_PutPszVariable: set the string value of an environment variable
270
 *****************************************************************************
271 272 273
 * 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.
274
 *****************************************************************************/
275 276 277 278 279 280 281
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 )
    {
282
        intf_ErrMsg("error: %s\n", strerror(ENOMEM));
283 284 285 286 287 288 289
    }
    else
    {
        sprintf( psz_env, "%s=%s", psz_name, psz_value );
        if( putenv( psz_env ) )
        {
            intf_ErrMsg("error: %s\n", strerror(errno));
290
        }
291 292 293
    }
}

294
/*****************************************************************************
295
 * main_PutIntVariable: set the integer value of an environment variable
296
 *****************************************************************************
297 298 299
 * 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.
300
 *****************************************************************************/
301 302
void main_PutIntVariable( char *psz_name, int i_value )
{
303
    char psz_value[ 256 ];                               /* buffer for value */
304

305 306
    sprintf(psz_value, "%d", i_value );
    main_PutPszVariable( psz_name, psz_value );
307 308
}

Michel Kaempf's avatar
Michel Kaempf committed
309 310
/* following functions are local */

311
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
312
 * SetDefaultConfiguration: set default options
313
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
314
 * This function is called by GetConfiguration before command line is parsed.
Vincent Seguin's avatar
Vincent Seguin committed
315 316 317
 * 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.
318
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
319
static void SetDefaultConfiguration( void )
Michel Kaempf's avatar
Michel Kaempf committed
320 321
{
    /*
Vincent Seguin's avatar
Vincent Seguin committed
322
     * All features are activated by default
Michel Kaempf's avatar
Michel Kaempf committed
323
     */
Vincent Seguin's avatar
Vincent Seguin committed
324 325 326
    p_main->b_audio  = 1;
    p_main->b_video  = 1;
    p_main->b_vlans  = 1;
Michel Kaempf's avatar
Michel Kaempf committed
327 328
}

329
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
330
 * GetConfiguration: parse command line
331
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
332 333
 * Parse command line and configuration file for configuration. If the inline
 * help is requested, the function Usage() is called and the function returns
334
 * -1 (causing main() to exit). The messages interface is initialized at this
Vincent Seguin's avatar
Vincent Seguin committed
335 336
 * stage, but most structures are not allocated, so only environment should
 * be used.
337
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
338
static int GetConfiguration( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
Michel Kaempf's avatar
Michel Kaempf committed
339
{
Vincent Seguin's avatar
Vincent Seguin committed
340
    int c, i_opt;
Michel Kaempf's avatar
Michel Kaempf committed
341 342

    /* Set default configuration and copy arguments */
Vincent Seguin's avatar
Vincent Seguin committed
343 344
    p_main->i_argc    = i_argc;
    p_main->ppsz_argv = ppsz_argv;
345
    p_main->ppsz_env  = ppsz_env;
Vincent Seguin's avatar
Vincent Seguin committed
346
    SetDefaultConfiguration();
Michel Kaempf's avatar
Michel Kaempf committed
347

Vincent Seguin's avatar
Vincent Seguin committed
348
    /* Parse command line options */
Michel Kaempf's avatar
Michel Kaempf committed
349 350 351 352 353
    opterr = 0;
    while( ( c = getopt_long( i_argc, ppsz_argv, psz_shortopts, longopts, 0 ) ) != EOF )
    {
        switch( c )
        {
354 355
        /* General/common options */
        case 'h':                                              /* -h, --help */
356 357 358
            Usage( SHORT_HELP );
            return( -1 );
            break;
359
        case 'H':                                          /* -H, --longhelp */
360
            Usage( LONG_HELP );
Michel Kaempf's avatar
Michel Kaempf committed
361 362
            return( -1 );
            break;
363
        case 'v':                                           /* -v, --version */
Vincent Seguin's avatar
Vincent Seguin committed
364 365
            Version();
            return( -1 );
366
            break;
Michel Kaempf's avatar
Michel Kaempf committed
367 368

        /* Audio options */
369
        case OPT_NOAUDIO:                                       /* --noaudio */
370
            p_main->b_audio = 0;
Michel Kaempf's avatar
Michel Kaempf committed
371
            break;
372 373 374
        case OPT_AOUT:                                             /* --aout */
            main_PutPszVariable( AOUT_METHOD_VAR, optarg );
            break;
375
        case OPT_STEREO:                                         /* --stereo */
376
            main_PutIntVariable( AOUT_STEREO_VAR, 1 );
Michel Kaempf's avatar
Michel Kaempf committed
377
            break;
378
        case OPT_MONO:                                             /* --mono */
379
            main_PutIntVariable( AOUT_STEREO_VAR, 0 );
Michel Kaempf's avatar
Michel Kaempf committed
380 381 382
            break;

        /* Video options */
383
        case OPT_NOVIDEO:                                       /* --novideo */
Vincent Seguin's avatar
Vincent Seguin committed
384
            p_main->b_video = 0;
385
            break;
386 387 388
        case OPT_VOUT:                                             /* --vout */
            main_PutPszVariable( VOUT_METHOD_VAR, optarg );
            break;
389
        case OPT_DISPLAY:                                       /* --display */
390
            main_PutPszVariable( VOUT_DISPLAY_VAR, optarg );
391 392
            break;
        case OPT_WIDTH:                                           /* --width */
393
            main_PutPszVariable( VOUT_WIDTH_VAR, optarg );
394 395 396 397 398 399
            break;
        case OPT_HEIGHT:                                         /* --height */
            main_PutPszVariable( VOUT_HEIGHT_VAR, optarg );
            break;

        case 'g':                                         /* -g, --grayscale */
400
            main_PutIntVariable( VOUT_GRAYSCALE_VAR, 1 );
401 402
            break;
        case OPT_COLOR:                                           /* --color */
403
            main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
404
            break;
Michel Kaempf's avatar
Michel Kaempf committed
405

406
        /* Input options */
407
        case OPT_NOVLANS:                                       /* --novlans */
Vincent Seguin's avatar
Vincent Seguin committed
408
            p_main->b_vlans = 0;
409 410
            break;
        case OPT_SERVER:                                         /* --server */
411
            main_PutPszVariable( INPUT_SERVER_VAR, optarg );
412 413
            break;
        case OPT_PORT:                                             /* --port */
414
            main_PutPszVariable( INPUT_PORT_VAR, optarg );
415
            break;
416

Michel Kaempf's avatar
Michel Kaempf committed
417
        /* Internal error: unknown option */
418
        case '?':
Michel Kaempf's avatar
Michel Kaempf committed
419 420 421 422 423 424 425
        default:
            intf_ErrMsg("intf error: unknown option '%s'\n", ppsz_argv[optind - 1]);
            return( EINVAL );
            break;
        }
    }

Vincent Seguin's avatar
Vincent Seguin committed
426 427 428
    /* Parse command line parameters - no check is made for these options */
    for( i_opt = optind; i_opt < i_argc; i_opt++ )
    {
429
        putenv( ppsz_argv[ i_opt ] );
Vincent Seguin's avatar
Vincent Seguin committed
430
    }
Michel Kaempf's avatar
Michel Kaempf committed
431 432 433
    return( 0 );
}

434
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
435
 * Usage: print program usage
436
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
437
 * Print a short inline help. Message interface is initialized at this stage.
438
 *****************************************************************************/
439
static void Usage( int i_fashion )
Michel Kaempf's avatar
Michel Kaempf committed
440
{
Vincent Seguin's avatar
Vincent Seguin committed
441 442
    intf_Msg(COPYRIGHT_MESSAGE "\n");

Vincent Seguin's avatar
Vincent Seguin committed
443
    /* Usage */
444
    intf_Msg("usage: vlc [options...] [parameters]\n" );
Vincent Seguin's avatar
Vincent Seguin committed
445 446

    /* Options */
Vincent Seguin's avatar
Vincent Seguin committed
447
    intf_Msg("Options:\n" \
448
             "  -h, --help, -H, --longhelp        \tprint short/long usage\n" \
449
             "  -v, --version                     \tprint version information\n"\
450
             "  --noaudio, --novideo              \tdisable audio/video\n" \
451
             "  --aout {" AUDIO_OPTIONS "}            \taudio output method\n"\
452
             "  --stereo, --mono                  \tstereo/mono audio\n" \
453
             "  --vout {" VIDEO_OPTIONS "}            \tvideo output method\n"\
454 455 456 457 458
             "  --display <display>               \tdisplay string\n" \
             "  --width <w>, --height <h>         \tdisplay dimensions\n" \
             "  -g, --grayscale, --color          \tgrayscale/color video\n" \
             "  --novlans                         \tdisable vlans\n" \
             "  --server <host>, --port <port>    \tvideo server adress\n" \
Michel Kaempf's avatar
Michel Kaempf committed
459 460
             );

461 462 463
    if( i_fashion == SHORT_HELP )
        return;

Vincent Seguin's avatar
Vincent Seguin committed
464 465
    /* Interface parameters */
    intf_Msg("Interface parameters:\n" \
466
             "  " INTF_INIT_SCRIPT_VAR "=<filename>             \tinitialization script\n" \
467
             "  " INTF_CHANNELS_VAR "=<filename>            \tchannels list\n"\
468
             );
Vincent Seguin's avatar
Vincent Seguin committed
469 470 471

    /* Audio parameters */
    intf_Msg("Audio parameters:\n" \
472
             "  " AOUT_METHOD_VAR "=<method name>        \taudio method (" AUDIO_OPTIONS ")\n" \
473 474 475
             "  " 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" \
476
             );
Vincent Seguin's avatar
Vincent Seguin committed
477 478 479

    /* Video parameters */
    intf_Msg("Video parameters:\n" \
480
             "  " VOUT_METHOD_VAR "=<method name>        \tdisplay method (" VIDEO_OPTIONS ")\n" \
481 482 483 484 485
             "  " 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" \
486
             );
Vincent Seguin's avatar
Vincent Seguin committed
487

488 489 490 491
    /* Input parameters */
    intf_Msg("Input parameters:\n" \
             "  " INPUT_SERVER_VAR "=<hostname>          \tvideo server\n" \
             "  " INPUT_PORT_VAR "=<port>            \tvideo server port\n" \
492
             "  " INPUT_IFACE_VAR "=<interface>          \tnetwork interface\n"\
493
             "  " INPUT_VLAN_SERVER_VAR "=<hostname>     \tvlan server\n" \
494
             "  " INPUT_VLAN_PORT_VAR "=<port>           \tvlan server port\n"\
495
             );
Michel Kaempf's avatar
Michel Kaempf committed
496 497
}

498
/*****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
499
 * Version: print complete program version
500
 *****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
501
 * Print complete program version and build number.
502
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
503 504 505 506 507 508 509 510 511 512
static void Version( void )
{
    intf_Msg(VERSION_MESSAGE "\n\n");
    intf_Msg("This is free software; see the documentation or contact <videolan@via.ecp.fr>\n" \
             "for use and copying conditions.\n" \
             "\n" \
             "This software is protected by the international copyright laws, and is\n" \
             "provided without any warranty, including the implied warranties of\n" \
             "merchantibility and fitness for a particular purpose.\n" \
            );
513
}
Vincent Seguin's avatar
Vincent Seguin committed
514

515
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
516
 * InitSignalHandler: system signal handler initialization
517
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
518
 * Set the signal handlers. SIGTERM is not intercepted, because we need at
519
 * at least a method to kill the program when all other methods failed, and
Michel Kaempf's avatar
Michel Kaempf committed
520
 * when we don't want to use SIGKILL.
521
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
522 523
static void InitSignalHandler( void )
{
Vincent Seguin's avatar
Vincent Seguin committed
524 525 526 527
    /* Termination signals */
    signal( SIGHUP,  SignalHandler );
    signal( SIGINT,  SignalHandler );
    signal( SIGQUIT, SignalHandler );
Michel Kaempf's avatar
Michel Kaempf committed
528 529
}

530
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
531
 * SignalHandler: system signal handler
532
 *****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
533 534
 * This function is called when a signal is received by the program. It tries to
 * end the program in a clean way.
535
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
536 537
static void SignalHandler( int i_signal )
{
538
    /* Once a signal has been trapped, the termination sequence will be armed and
Vincent Seguin's avatar
Vincent Seguin committed
539 540 541 542 543 544 545 546 547
     * 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 );

548
    /* Try to terminate everything - this is done by requesting the end of the
Vincent Seguin's avatar
Vincent Seguin committed
549 550 551 552
     * interface thread */
    p_main->p_intf->b_die = 1;
}

553 554 555 556 557 558 559 560 561
#ifdef HAVE_MMX
/*****************************************************************************
 * TestMMX: tests if the processor has MMX support.
 *****************************************************************************
 * This function is called if HAVE_MMX is enabled, to check whether the
 * cpu really supports MMX.
 *****************************************************************************/
static int TestMMX( void )
{
562
    int i_reg, i_dummy = 0;
563 564 565 566 567 568 569 570 571 572 573 574

    /* test for a 386 cpu */
    asm volatile ( "pushfl
                    popl %%eax
                    movl %%eax, %%ecx
                    xorl $0x40000, %%eax
                    pushl %%eax
                    popfl
                    pushfl
                    popl %%eax
                    xorl %%ecx, %%eax
                    andl $0x40000, %%eax"
575
                 : "=a" ( i_reg ) );
576

577
    if( !i_reg )
578 579 580 581 582 583 584 585 586 587
        return( 0 );

    /* test for a 486 cpu */
    asm volatile ( "movl %%ecx, %%eax
                    xorl $0x200000, %%eax
                    pushl %%eax
                    popfl
                    pushfl
                    popl %%eax
                    xorl %%ecx, %%eax
588
                    pushl %%ecx
589 590
                    popfl
                    andl $0x200000, %%eax"
591
                 : "=a" ( i_reg ) );
592

593
    if( !i_reg )
594 595 596 597
        return( 0 );

    /* the cpu supports the CPUID instruction - get its level */
    asm volatile ( "cpuid"
598 599 600 601 602 603
                 : "=a" ( i_reg ),
                   "=b" ( i_dummy ),
                   "=c" ( i_dummy ),
                   "=d" ( i_dummy )
                 : "a"  ( 0 ),       /* level 0 */
                   "b"  ( i_dummy ) ); /* buggy compiler shouldn't complain */
604 605

    /* this shouldn't happen on a normal cpu */
606
    if( !i_reg )
607 608 609 610 611
        return( 0 );

    /* test for the MMX flag */
    asm volatile ( "cpuid
                    andl $0x00800000, %%edx" /* X86_FEATURE_MMX */
612 613 614 615 616 617 618 619
                 : "=a" ( i_dummy ),
                   "=b" ( i_dummy ),
                   "=c" ( i_dummy ),
                   "=d" ( i_reg )
                 : "a"  ( 1 ),       /* level 1 */
                   "b"  ( i_dummy ) ); /* buggy compiler shouldn't complain */

    if( !i_reg )
620 621 622 623 624
        return( 0 );

    return( 1 );
}
#endif