main.c 46.7 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
 * Copyright (C) 1998-2001 VideoLAN
Sam Hocevar's avatar
 
Sam Hocevar committed
7
 * $Id: main.c,v 1.179 2002/04/17 11:43:31 sam Exp $
8
 *
Sam Hocevar's avatar
 
Sam Hocevar committed
9 10
 * Authors: Vincent Seguin <seguin@via.ecp.fr>
 *          Samuel Hocevar <sam@zoy.org>
gbazin's avatar
 
gbazin committed
11
 *          Gildas Bazin <gbazin@netcourrier.com>
12 13 14 15 16
 *
 * 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.
17
 * 
18 19
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
22
 *
23 24 25
 * 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.
26
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
27

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

Sam Hocevar's avatar
 
Sam Hocevar committed
35 36
#include <videolan/vlc.h>

Sam Hocevar's avatar
 
Sam Hocevar committed
37 38 39 40 41 42
#ifdef HAVE_GETOPT_LONG
#   ifdef HAVE_GETOPT_H
#       include <getopt.h>                                       /* getopt() */
#   endif
#else
#   include "GNUgetopt/getopt.h"
Benoit Steiner's avatar
Benoit Steiner committed
43 44
#endif

Sam Hocevar's avatar
 
Sam Hocevar committed
45
#ifdef SYS_DARWIN
Sam Hocevar's avatar
 
Sam Hocevar committed
46 47
#   include <mach/mach.h>                               /* Altivec detection */
#   include <mach/mach_error.h>       /* some day the header files||compiler *
Sam Hocevar's avatar
 
Sam Hocevar committed
48
                                                       will define it for us */
Sam Hocevar's avatar
 
Sam Hocevar committed
49
#   include <mach/bootstrap.h>
Sam Hocevar's avatar
 
Sam Hocevar committed
50
#endif
Sam Hocevar's avatar
 
Sam Hocevar committed
51 52

#ifndef WIN32
Sam Hocevar's avatar
 
Sam Hocevar committed
53
#   include <netinet/in.h>                            /* BSD: struct in_addr */
Sam Hocevar's avatar
 
Sam Hocevar committed
54
#endif
Sam Hocevar's avatar
 
Sam Hocevar committed
55

Sam Hocevar's avatar
 
Sam Hocevar committed
56
#ifdef HAVE_UNISTD_H
Sam Hocevar's avatar
 
Sam Hocevar committed
57 58 59
#   include <unistd.h>
#elif defined( _MSC_VER ) && defined( _WIN32 )
#   include <io.h>
Sam Hocevar's avatar
 
Sam Hocevar committed
60 61
#endif

Sam Hocevar's avatar
 
Sam Hocevar committed
62 63 64 65
#ifdef HAVE_LOCALE_H
#    include <locale.h>
#endif

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

Sam Hocevar's avatar
 
Sam Hocevar committed
70
#include "netutils.h"                                 /* network_ChannelJoin */
Sam Hocevar's avatar
 
Sam Hocevar committed
71

72 73
#include "stream_control.h"
#include "input_ext-intf.h"
74

Sam Hocevar's avatar
 
Sam Hocevar committed
75
#include "intf_playlist.h"
Michel Kaempf's avatar
Michel Kaempf committed
76
#include "interface.h"
77

Vincent Seguin's avatar
Vincent Seguin committed
78
#include "audio_output.h"
79

Sam Hocevar's avatar
 
Sam Hocevar committed
80 81 82
#include "video.h"
#include "video_output.h"

Sam Hocevar's avatar
 
Sam Hocevar committed
83
#include "debug.h"
Henri Fallon's avatar
 
Henri Fallon committed
84

85
/*****************************************************************************
gbazin's avatar
 
gbazin committed
86 87 88 89
 * Configuration options for the main program. Each plugin will also separatly
 * define its own configuration options.
 * Look into configuration.h if you need to know more about the following
 * macros.
Loïc Minier's avatar
Loïc Minier committed
90
 *
gbazin's avatar
 
gbazin committed
91 92 93 94 95
 *****************************************************************************/
#define BUILTIN
#define MODULE_NAME main
#include "modules_inner.h"                        /* for configuration stuff */

gbazin's avatar
 
gbazin committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112

#define INTF_TEXT "interface method"
#define INTF_LONGTEXT "This option allows you to select the interface used by"\
                      " vlc.\nNote that the default behaviour is to" \
                      " automatically select the best method available"

#define WARNING_TEXT "warning level (or use -v, -vv, etc...)"
#define WARNING_LONGTEXT "Increasing the warning level will allow you to see" \
                         " more debug messages and can sometimes help you to" \
                         " troubleshoot a problem"

#define STATS_TEXT "output statistics"
#define STATS_LONGTEXT "Enabling the stats mode will flood your log console" \
                       " with various statistics messages"

#define INTF_PATH_TEXT "interface default search path"
#define INTF_PATH_LONGTEXT "This option allows you to set the default path" \
Loïc Minier's avatar
Loïc Minier committed
113
                           " that the interface will open when looking for a" \
gbazin's avatar
 
gbazin committed
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
                           " file"

#define AOUT_TEXT "audio output method"
#define AOUT_LONGTEXT "This option allows you to select the audio" \
                      " audio output method used by vlc.\nNote that the" \
                      " default behaviour is to automatically select the best"\
                      " method available"

#define NOAUDIO_TEXT "disable audio"
#define NOAUDIO_LONGTEXT "This will completely disable the audio output. The" \
                         " audio decoding stage shouldn't even be done, so it"\
                         " can allow you to save some processing power"

#define MONO_TEXT "mono audio"
#define MONO_LONGTEXT "This will force a mono audio output"

#define VOLUME_TEXT "audio output volume"
Stéphane Borel's avatar
 
Stéphane Borel committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144
#define VOLUME_LONGTEXT "You can set the default audio output volume here," \
                        " in a range from 0 to 1024"

#define FORMAT_TEXT "audio output format"
#define FORMAT_LONGTEXT "You can force the audio output format here.\n" \
                        "0 -> 16 bits signed native endian (default)\n" \
                        "1 ->  8 bits unsigned\n"                       \
                        "2 -> 16 bits signed little endian\n"           \
                        "3 -> 16 bits signed big endian\n"              \
                        "4 ->  8 bits signed\n"                         \
                        "5 -> 16 bits unsigned little endian\n"         \
                        "6 -> 16 bits unsigned big endian\n"            \
                        "7 -> mpeg2 audio (unsupported)\n"              \
                        "8 -> ac3 pass-through"
Loïc Minier's avatar
Loïc Minier committed
145

Stéphane Borel's avatar
 
Stéphane Borel committed
146 147 148 149
#define RATE_TEXT "audio output frequency (Hz)"
#define RATE_LONGTEXT "You can force the audio output frequency here.\n"    \
                      "Common values are 48000, 44100, 32000, 22050,"       \
                      " 16000, 11025, 8000"
gbazin's avatar
 
gbazin committed
150 151

#define DESYNC_TEXT "Compensate desynchronization of audio (in ms)"
Loïc Minier's avatar
Loïc Minier committed
152 153
#define DESYNC_LONGTEXT "This option allows you to delay the audio output."  \
                        " This can be handy if you notice a lag between the" \
gbazin's avatar
 
gbazin committed
154 155 156
                        " video and the audio"

#define VOUT_TEXT "video output method"
Loïc Minier's avatar
Loïc Minier committed
157 158 159
#define VOUT_LONGTEXT "This option allows you to select the video output"     \
                      " method used by vlc.\nNote that the default behaviour" \
                      " is to automatically select the best method available"
gbazin's avatar
 
gbazin committed
160 161 162

#define NOVIDEO_TEXT "disable video"
#define NOVIDEO_LONGTEXT "This will completely disable the video output. The" \
Loïc Minier's avatar
Loïc Minier committed
163 164 165 166 167
                         " video decoding stage shouldn't even be done, so"   \
                         " it can allow you to save some processing power"

#define DISPLAY_TEXT "display identifier"
#define DISPLAY_LONGTEXT NULL
gbazin's avatar
 
gbazin committed
168 169

#define WIDTH_TEXT "video width"
Loïc Minier's avatar
Loïc Minier committed
170 171 172
#define WIDTH_LONGTEXT "You can enforce the video width here.\nNote"  \
                       " that by default vlc will adapt to the video" \
                       " characteristics"
gbazin's avatar
 
gbazin committed
173 174

#define HEIGHT_TEXT "video height"
Loïc Minier's avatar
Loïc Minier committed
175 176 177
#define HEIGHT_LONGTEXT "You can enforce the video height here.\nNote"  \
                        " that by default vlc will adapt to the video " \
                        " characteristics"
gbazin's avatar
 
gbazin committed
178 179

#define GRAYSCALE_TEXT "grayscale video output"
gbazin's avatar
 
gbazin committed
180 181 182
#define GRAYSCALE_LONGTEXT "Using this option, vlc will not decode the color "\
                           "information from the video (this can also allow " \
                           "you to save some processing power)"
gbazin's avatar
 
gbazin committed
183 184

#define FULLSCREEN_TEXT "fullscreen video output"
gbazin's avatar
 
gbazin committed
185 186
#define FULLSCREEN_LONGTEXT "If this option is enabled, vlc will always " \
                            "start a video in fullscreen mode"
gbazin's avatar
 
gbazin committed
187

gbazin's avatar
 
gbazin committed
188 189 190
#define NOOVERLAY_TEXT "disable hardware acceleration for the video output"
#define NOOVERLAY_LONGTEXT "By default vlc will try to take advantage of the "\
                           "overlay capabilities of you graphics card.\n"
gbazin's avatar
 
gbazin committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212

#define SPUMARGIN_TEXT "force SPU position"
#define SPUMARGIN_LONGTEXT NULL

#define FILTER_TEXT "video filter module"
#define FILTER_LONGTEXT NULL

#define SERVER_PORT_TEXT "server port"
#define SERVER_PORT_LONGTEXT NULL

#define NETCHANNEL_TEXT "enable network channel mode"
#define NETCHANNEL_LONGTEXT NULL

#define CHAN_SERV_TEXT "channel server address"
#define CHAN_SERV_LONGTEXT NULL

#define CHAN_PORT_TEXT "channel server port"
#define CHAN_PORT_LONGTEXT NULL

#define IFACE_TEXT "network interface"
#define IFACE_LONGTEXT NULL

Johan Bilien's avatar
 
Johan Bilien committed
213 214 215 216
#define INPUT_PROGRAM_TEXT "choose program (SID)"
#define INPUT_PROGRAM_LONGTEXT "choose the program to select by giving its"\
                                "Service ID"

gbazin's avatar
 
gbazin committed
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
#define INPUT_AUDIO_TEXT "choose audio"
#define INPUT_AUDIO_LONGTEXT NULL

#define INPUT_CHAN_TEXT "choose channel"
#define INPUT_CHAN_LONGTEXT NULL

#define INPUT_SUBT_TEXT "choose subtitles"
#define INPUT_SUBT_LONGTEXT NULL

#define DVD_DEV_TEXT "DVD device"
#define DVD_DEV_LONGTEXT NULL

#define VCD_DEV_TEXT "VCD device"
#define VCD_DEV_LONGTEXT NULL

Johan Bilien's avatar
 
Johan Bilien committed
232 233 234 235 236 237
#define SAT_FREQ_TEXT "Satellite transponder frequency"
#define SAT_FREQ_LONGTEXT NULL

#define SAT_POL_TEXT "Satellite transponder polarization"
#define SAT_POL_LONGTEXT NULL

238 239 240
#define SAT_FEC_TEXT "Satellite transponder FEC"
#define SAT_FEC_LONGTEXT NULL

Johan Bilien's avatar
 
Johan Bilien committed
241 242
#define SAT_SRATE_TEXT "Satellite transponder symbol rate"
#define SAT_SRATE_LONGTEXT NULL
Loïc Minier's avatar
Loïc Minier committed
243

244 245 246 247 248 249 250 251 252 253 254 255
#define SAT_DISEQC_TEXT "Use diseqc with antenna"
#define SAT_DISEQC_LONGTEXT NULL

#define SAT_LNB_LOF1_TEXT "Antenna lnb_lof1 (kHz)"
#define SAT_LNB_LOF1_LONGTEXT NULL

#define SAT_LNB_LOF2_TEXT "Antenna lnb_lof2 (kHz)"
#define SAT_LNB_LOF2_LONGTEXT NULL

#define SAT_LNB_SLOF_TEXT "Antenna lnb_slof (kHz)"
#define SAT_LNB_SLOF_LONGTEXT NULL

gbazin's avatar
 
gbazin committed
256 257 258
#define IPV6_TEXT "force IPv6"
#define IPV6_LONGTEXT NULL

Sam Hocevar's avatar
 
Sam Hocevar committed
259
#define IPV4_TEXT "force IPv4"
gbazin's avatar
 
gbazin committed
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
#define IPV4_LONGTEXT NULL

#define ADEC_MPEG_TEXT "choose MPEG audio decoder"
#define ADEC_MPEG_LONGTEXT NULL

#define ADEC_AC3_TEXT "choose AC3 audio decoder"
#define ADEC_AC3_LONGTEXT NULL

#define VDEC_SMP_TEXT "use additional processors"
#define VDEC_SMP_LONGTEXT NULL

#define VPAR_SYNCHRO_TEXT "force synchro algorithm {I|I+|IP|IP+|IPB}"
#define VPAR_SYNCHRO_LONGTEXT NULL

#define NOMMX_TEXT "disable CPU's MMX support"
#define NOMMX_LONGTEXT NULL

#define NO3DN_TEXT "disable CPU's 3D Now! support"
#define NO3DN_LONGTEXT NULL

#define NOMMXEXT_TEXT "disable CPU's MMX EXT support"
#define NOMMXEXT_LONGTEXT NULL

#define NOSSE_TEXT "disable CPU's SSE support"
#define NOSSE_LONGTEXT NULL

#define NOALTIVEC_TEXT "disable CPU's AltiVec support"
#define NOALTIVEC_LONGTEXT NULL

#define PLAYLIST_LAUNCH_TEXT "launch playlist on startup"
#define PLAYLIST_LAUNCH_LONGTEXT NULL

Loïc Minier's avatar
Loïc Minier committed
292
#define PLAYLIST_ENQUEUE_TEXT "enqueue playlist as default"
gbazin's avatar
 
gbazin committed
293 294 295 296 297 298 299 300
#define PLAYLIST_ENQUEUE_LONGTEXT NULL

#define PLAYLIST_LOOP_TEXT "loop playlist on end"
#define PLAYLIST_LOOP_LONGTEXT NULL

#define MEMCPY_TEXT "memory copy method"
#define MEMCPY_LONGTEXT NULL

gbazin's avatar
 
gbazin committed
301 302 303 304 305 306
#define FAST_PTHREAD_TEXT "fast pthread on NT/2K/XP (developpers only)"
#define FAST_PTHREAD_LONGTEXT "On Windows NT/2K/XP we use a slow but correct "\
                              "pthread implementation, you can also use this "\
                              "faster implementation but you might "\
                              "experience problems with it"

gbazin's avatar
 
gbazin committed
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
/* Quick usage guide
MODULE_CONFIG_START
MODULE_CONFIG_STOP
ADD_CATEGORY_HINT( text, longtext )
ADD_SUBCATEGORY_HINT( text, longtext )
ADD_STRING( option_name, value, p_callback, text, longtext )
ADD_FILE( option_name, psz_value, p_callback, text, longtext )
ADD_PLUGIN( option_name, psz_value, i_capability, p_callback, text, longtext )
ADD_INTEGER( option_name, i_value, p_callback, text, longtext )
ADD_BOOL( option_name, p_callback, text, longtext )
*/

MODULE_CONFIG_START

/* Interface options */
gbazin's avatar
 
gbazin committed
322 323 324 325 326 327 328 329 330 331 332 333 334 335
ADD_CATEGORY_HINT( "Interface", NULL)
ADD_PLUGIN  ( "intf", MODULE_CAPABILITY_INTF, NULL, NULL, INTF_TEXT, INTF_LONGTEXT )
ADD_INTEGER ( "warning", 0, NULL, WARNING_TEXT, WARNING_LONGTEXT )
ADD_BOOL    ( "stats", NULL, STATS_TEXT, STATS_LONGTEXT )
ADD_STRING  ( "search_path", NULL, NULL, INTF_PATH_TEXT, INTF_PATH_LONGTEXT )

/* Audio options */
ADD_CATEGORY_HINT( "Audio", NULL)
ADD_PLUGIN  ( "aout", MODULE_CAPABILITY_AOUT, NULL, NULL, AOUT_TEXT, AOUT_LONGTEXT )
ADD_BOOL    ( "noaudio", NULL, NOAUDIO_TEXT, NOAUDIO_LONGTEXT )
ADD_BOOL    ( "mono", NULL, MONO_TEXT, MONO_LONGTEXT )
ADD_INTEGER ( "volume", VOLUME_DEFAULT, NULL, VOLUME_TEXT, VOLUME_LONGTEXT )
ADD_INTEGER ( "rate", 44100, NULL, RATE_TEXT, RATE_LONGTEXT )
ADD_INTEGER ( "desync", 0, NULL, DESYNC_TEXT, DESYNC_LONGTEXT )
Stéphane Borel's avatar
 
Stéphane Borel committed
336 337
ADD_INTEGER ( "aout_format", 0, NULL, FORMAT_TEXT,
              FORMAT_LONGTEXT )
gbazin's avatar
 
gbazin committed
338 339

/* Video options */
gbazin's avatar
 
gbazin committed
340 341 342
ADD_CATEGORY_HINT( "Video", NULL )
ADD_PLUGIN  ( "vout", MODULE_CAPABILITY_VOUT, NULL, NULL, VOUT_TEXT, VOUT_LONGTEXT )
ADD_BOOL    ( "novideo", NULL, NOVIDEO_TEXT, NOVIDEO_LONGTEXT )
gbazin's avatar
 
gbazin committed
343 344
ADD_INTEGER ( "width", -1, NULL, WIDTH_TEXT, WIDTH_LONGTEXT )
ADD_INTEGER ( "height", -1, NULL, HEIGHT_TEXT, HEIGHT_LONGTEXT )
gbazin's avatar
 
gbazin committed
345 346 347 348 349
ADD_BOOL    ( "grayscale", NULL, GRAYSCALE_TEXT, GRAYSCALE_LONGTEXT )
ADD_BOOL    ( "fullscreen", NULL, FULLSCREEN_TEXT, FULLSCREEN_LONGTEXT )
ADD_BOOL    ( "nooverlay", NULL, NOOVERLAY_TEXT, NOOVERLAY_LONGTEXT )
ADD_INTEGER ( "spumargin", -1, NULL, SPUMARGIN_TEXT, SPUMARGIN_LONGTEXT )
ADD_PLUGIN  ( "filter", MODULE_CAPABILITY_VOUT, NULL, NULL, FILTER_TEXT, FILTER_LONGTEXT )
gbazin's avatar
 
gbazin committed
350 351

/* Input options */
gbazin's avatar
 
gbazin committed
352 353 354 355 356 357 358
ADD_CATEGORY_HINT( "Input", NULL )
ADD_INTEGER ( "server_port", 1234, NULL, SERVER_PORT_TEXT, SERVER_PORT_LONGTEXT )
ADD_BOOL    ( "network_channel", NULL, NETCHANNEL_TEXT, NETCHANNEL_LONGTEXT )
ADD_STRING  ( "channel_server", "localhost", NULL, CHAN_SERV_TEXT, CHAN_SERV_LONGTEXT )
ADD_INTEGER ( "channel_port", 6010, NULL, CHAN_PORT_TEXT, CHAN_PORT_LONGTEXT )
ADD_STRING  ( "iface", "eth0", NULL, IFACE_TEXT, IFACE_LONGTEXT )

Johan Bilien's avatar
 
Johan Bilien committed
359 360
ADD_INTEGER ( "input_program", 0, NULL, INPUT_PROGRAM_TEXT,
        INPUT_PROGRAM_LONGTEXT )
gbazin's avatar
 
gbazin committed
361
ADD_INTEGER ( "input_audio", -1, NULL, INPUT_AUDIO_TEXT, INPUT_AUDIO_LONGTEXT )
Stéphane Borel's avatar
 
Stéphane Borel committed
362
ADD_INTEGER ( "input_channel", -1, NULL, INPUT_CHAN_TEXT, INPUT_CHAN_LONGTEXT )
gbazin's avatar
 
gbazin committed
363 364 365 366
ADD_INTEGER ( "input_subtitle", -1, NULL, INPUT_SUBT_TEXT, INPUT_SUBT_LONGTEXT )

ADD_STRING  ( "dvd_device", "/dev/dvd", NULL, DVD_DEV_TEXT, DVD_DEV_LONGTEXT )
ADD_STRING  ( "vcd_device", "/dev/cdrom", NULL, VCD_DEV_TEXT, VCD_DEV_LONGTEXT )
Johan Bilien's avatar
 
Johan Bilien committed
367
#ifdef HAVE_SATELLITE
368
ADD_INTEGER ( "sat_frequency", 11954, NULL, SAT_FREQ_TEXT, SAT_FREQ_LONGTEXT )
Johan Bilien's avatar
 
Johan Bilien committed
369
ADD_INTEGER ( "sat_polarization", 0, NULL, SAT_POL_TEXT, SAT_POL_LONGTEXT )
370
ADD_INTEGER ( "sat_fec", 3, NULL, SAT_FEC_TEXT, SAT_FEC_LONGTEXT )
Loïc Minier's avatar
Loïc Minier committed
371
ADD_INTEGER ( "sat_symbol_rate", 27500, NULL, SAT_SRATE_TEXT,
Johan Bilien's avatar
 
Johan Bilien committed
372
            SAT_SRATE_LONGTEXT )
373 374 375 376 377 378 379
ADD_BOOL    ( "sat_diseqc", 0, SAT_DISEQC_TEXT, SAT_DISEQC_LONGTEXT )
ADD_INTEGER ( "sat_lnb_lof1", 10000, NULL, SAT_LNB_LOF1_TEXT, 
            SAT_LNB_LOF1_LONGTEXT )
ADD_INTEGER ( "sat_lnb_lof2", 10000, NULL, SAT_LNB_LOF2_TEXT, 
            SAT_LNB_LOF2_LONGTEXT )
ADD_INTEGER ( "sat_lnb_slof", 11700, NULL, SAT_LNB_SLOF_TEXT, 
            SAT_LNB_SLOF_LONGTEXT )
Johan Bilien's avatar
 
Johan Bilien committed
380 381
#endif

gbazin's avatar
 
gbazin committed
382 383
ADD_BOOL    ( "ipv6", NULL, IPV6_TEXT, IPV6_LONGTEXT )
ADD_BOOL    ( "ipv4", NULL, IPV4_TEXT, IPV4_LONGTEXT )
gbazin's avatar
 
gbazin committed
384 385

/* Decoder options */
gbazin's avatar
 
gbazin committed
386 387 388 389 390
ADD_CATEGORY_HINT( "Decoders", NULL )
ADD_PLUGIN  ( "mpeg_adec", MODULE_CAPABILITY_DECODER, NULL, NULL, ADEC_MPEG_TEXT, ADEC_MPEG_LONGTEXT )
ADD_PLUGIN  ( "ac3_adec", MODULE_CAPABILITY_DECODER, NULL, NULL, ADEC_AC3_TEXT, ADEC_AC3_LONGTEXT )
ADD_INTEGER ( "vdec_smp", 0, NULL, VDEC_SMP_TEXT, VDEC_SMP_LONGTEXT )
ADD_STRING  ( "vpar_synchro", NULL, NULL, VPAR_SYNCHRO_TEXT, VPAR_SYNCHRO_LONGTEXT )
gbazin's avatar
 
gbazin committed
391 392

/* CPU options */
gbazin's avatar
 
gbazin committed
393 394 395 396 397 398
ADD_CATEGORY_HINT( "CPU", NULL )
ADD_BOOL    ( "nommx", NULL, NOMMX_TEXT, NOMMX_LONGTEXT )
ADD_BOOL    ( "no3dn", NULL, NO3DN_TEXT, NO3DN_LONGTEXT )
ADD_BOOL    ( "nommxext", NULL, NOMMXEXT_TEXT, NOMMXEXT_LONGTEXT )
ADD_BOOL    ( "nosse", NULL, NOSSE_TEXT, NOSSE_LONGTEXT )
ADD_BOOL    ( "noaltivec", NULL, NOALTIVEC_TEXT, NOALTIVEC_LONGTEXT )
gbazin's avatar
 
gbazin committed
399 400

/* Playlist options */
gbazin's avatar
 
gbazin committed
401 402 403 404
ADD_CATEGORY_HINT( "Playlist", NULL )
ADD_BOOL    ( "playlist_launch", NULL, PLAYLIST_LAUNCH_TEXT, PLAYLIST_LAUNCH_LONGTEXT )
ADD_BOOL    ( "playlist_enqueue", NULL, PLAYLIST_ENQUEUE_TEXT, PLAYLIST_ENQUEUE_LONGTEXT )
ADD_BOOL    ( "playlist_loop", NULL, PLAYLIST_LOOP_TEXT, PLAYLIST_LOOP_LONGTEXT )
gbazin's avatar
 
gbazin committed
405 406

/* Misc options */
gbazin's avatar
 
gbazin committed
407 408
ADD_CATEGORY_HINT( "Miscellaneous", NULL )
ADD_PLUGIN  ( "memcpy", MODULE_CAPABILITY_MEMCPY, NULL, NULL, MEMCPY_TEXT, MEMCPY_LONGTEXT )
gbazin's avatar
 
gbazin committed
409

gbazin's avatar
 
gbazin committed
410 411 412 413
#if defined(WIN32)
ADD_BOOL    ( "fast_pthread", NULL, FAST_PTHREAD_TEXT, FAST_PTHREAD_LONGTEXT )
#endif

gbazin's avatar
 
gbazin committed
414 415 416 417 418 419 420 421 422 423 424 425
MODULE_CONFIG_STOP

MODULE_INIT_START
    SET_DESCRIPTION( "Main program" )
    ADD_CAPABILITY( MAIN, 100/*whatever*/ )
MODULE_INIT_STOP

MODULE_ACTIVATE_START
MODULE_ACTIVATE_STOP

MODULE_DEACTIVATE_START
MODULE_DEACTIVATE_STOP
gbazin's avatar
 
gbazin committed
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442

/* Hack for help options */
static module_t help_module;
static module_config_t p_help_config[] = {
    { MODULE_CONFIG_ITEM_BOOL, "help", "print help (or use -h)",
      NULL, NULL, 0, NULL, NULL, 0 },
    { MODULE_CONFIG_ITEM_BOOL, "longhelp", "print detailed help (or use -H)",
      NULL, NULL, 0, NULL, NULL, 0 },
    { MODULE_CONFIG_ITEM_BOOL, "list", "print a list of available plugins "
      "(or use -l)", NULL, NULL, 0, NULL, NULL, 0 },
    { MODULE_CONFIG_ITEM_STRING, "plugin", "print help on plugin (or use -p)",
      NULL, NULL, 0, NULL, &help_module.config_lock, 0 },
    { MODULE_CONFIG_ITEM_BOOL, "version", "print version information",
      NULL, NULL, 0, NULL, NULL, 0 },
    { MODULE_CONFIG_HINT_END, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 } };


gbazin's avatar
 
gbazin committed
443 444
/*****************************************************************************
 * End configuration.
445
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
446

447
/*****************************************************************************
Sam Hocevar's avatar
 
Sam Hocevar committed
448
 * Global variables - these are the only ones, see main.h and modules.h
449
 *****************************************************************************/
Sam Hocevar's avatar
 
Sam Hocevar committed
450
main_t        *p_main;
gbazin's avatar
 
gbazin committed
451
p_main_sys_t  p_main_sys;
Sam Hocevar's avatar
 
Sam Hocevar committed
452
module_bank_t *p_module_bank;
Sam Hocevar's avatar
 
Sam Hocevar committed
453
input_bank_t  *p_input_bank;
Sam Hocevar's avatar
 
Sam Hocevar committed
454 455
aout_bank_t   *p_aout_bank;
vout_bank_t   *p_vout_bank;
Michel Kaempf's avatar
Michel Kaempf committed
456

457
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
458
 * Local prototypes
459
 *****************************************************************************/
gbazin's avatar
 
gbazin committed
460 461 462 463 464 465 466 467 468 469 470 471 472 473
static int  GetFilenames                ( int i_argc, char *ppsz_argv[] );
static void Usage                       ( const char *psz_module_name );
static void ListModules                 ( void );
static void Version                     ( void );

static void InitSignalHandler           ( void );
static void SimpleSignalHandler         ( int i_signal );
static void FatalSignalHandler          ( int i_signal );
static void IllegalSignalHandler        ( int i_signal );
static u32  CPUCapabilities             ( void );

#ifdef WIN32
static void ShowConsole                 ( void );
#endif
gbazin's avatar
 
gbazin committed
474

475
static jmp_buf env;
Sam Hocevar's avatar
 
Sam Hocevar committed
476 477
static int     i_illegal;
static char   *psz_capability;
Sam Hocevar's avatar
 
Sam Hocevar committed
478

479
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
480
 * main: parse command line, start interface and spawn threads
481
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
482 483
 * Steps during program execution are:
 *      -configuration parsing and messages interface initialization
484
 *      -opening of audio output device and some global modules
Michel Kaempf's avatar
Michel Kaempf committed
485
 *      -execution of interface, which exit on error or on user request
Vincent Seguin's avatar
Vincent Seguin committed
486
 *      -closing of audio output device and some global modules
487
 * On error, the spawned threads are canceled, and the open devices closed.
488
 *****************************************************************************/
Michel Kaempf's avatar
Michel Kaempf committed
489 490
int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
{
Sam Hocevar's avatar
 
Sam Hocevar committed
491 492
    main_t        main_data;                /* root of all data - see main.h */
    module_bank_t module_bank;
Sam Hocevar's avatar
 
Sam Hocevar committed
493
    input_bank_t  input_bank;
Sam Hocevar's avatar
 
Sam Hocevar committed
494 495
    aout_bank_t   aout_bank;
    vout_bank_t   vout_bank;
gbazin's avatar
 
gbazin committed
496
    char *psz_plugin;
gbazin's avatar
 
gbazin committed
497
    char *p_tmp;
498

Sam Hocevar's avatar
 
Sam Hocevar committed
499 500
    p_main        = &main_data;               /* set up the global variables */
    p_module_bank = &module_bank;
Sam Hocevar's avatar
 
Sam Hocevar committed
501
    p_input_bank  = &input_bank;
Sam Hocevar's avatar
 
Sam Hocevar committed
502 503
    p_aout_bank   = &aout_bank;
    p_vout_bank   = &vout_bank;
Sam Hocevar's avatar
 
Sam Hocevar committed
504

gbazin's avatar
 
gbazin committed
505 506
    p_main->i_warning_level = 0;

Sam Hocevar's avatar
 
Sam Hocevar committed
507
#if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT )
Sam Hocevar's avatar
 
Sam Hocevar committed
508
    /*
Sam Hocevar's avatar
 
Sam Hocevar committed
509 510
     * Support for getext
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
511 512
#if defined( HAVE_LOCALE_H ) && defined( HAVE_LC_MESSAGES )
    if( !setlocale( LC_MESSAGES, "" ) )
Sam Hocevar's avatar
 
Sam Hocevar committed
513 514 515
    {
        fprintf( stderr, "warning: unsupported locale.\n" );
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
516
#endif
Sam Hocevar's avatar
 
Sam Hocevar committed
517

Sam Hocevar's avatar
 
Sam Hocevar committed
518
    if( !bindtextdomain( PACKAGE, LOCALEDIR ) )
Sam Hocevar's avatar
 
Sam Hocevar committed
519 520 521 522 523 524 525
    {
        fprintf( stderr, "warning: no domain %s in directory %s\n",
                 PACKAGE, LOCALEDIR );
    }

    textdomain( PACKAGE );
#endif
Sam Hocevar's avatar
 
Sam Hocevar committed
526

Sam Hocevar's avatar
 
Sam Hocevar committed
527
    /*
Sam Hocevar's avatar
 
Sam Hocevar committed
528
     * Initialize threads system
Sam Hocevar's avatar
 
Sam Hocevar committed
529
     */
gbazin's avatar
 
gbazin committed
530
    vlc_threads_init();
Sam Hocevar's avatar
 
Sam Hocevar committed
531

Sam Hocevar's avatar
 
Sam Hocevar committed
532
    /*
Sam Hocevar's avatar
 
Sam Hocevar committed
533
     * Test if our code is likely to run on this CPU
Sam Hocevar's avatar
 
Sam Hocevar committed
534 535
     */
    p_main->i_cpu_capabilities = CPUCapabilities();
Sam Hocevar's avatar
 
Sam Hocevar committed
536

Sam Hocevar's avatar
 
Sam Hocevar committed
537 538 539
    /*
     * System specific initialization code
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
540
#if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
Sam Hocevar's avatar
 
Sam Hocevar committed
541
    system_Init( &i_argc, ppsz_argv, ppsz_env );
542 543 544 545

#elif defined( SYS_LINUX )
#   ifdef DEBUG
    /* Activate malloc checking routines to detect heap corruptions. */
gbazin's avatar
 
gbazin committed
546
    putenv( "MALLOC_CHECK_=2" );
Sam Hocevar's avatar
 
Sam Hocevar committed
547
    putenv( "GNOME_DISABLE_CRASH_DIALOG=1" );
548
#   endif
549
#endif
550 551 552 553

    /*
     * Initialize messages interface
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
554
    intf_MsgCreate();
555

Sam Hocevar's avatar
 
Sam Hocevar committed
556
    intf_Msg( COPYRIGHT_MESSAGE "\n" );
Sam Hocevar's avatar
 
Sam Hocevar committed
557

gbazin's avatar
 
gbazin committed
558 559 560 561 562 563 564 565 566

    /* Get the executable name (similar to the basename command) */
    p_main->psz_arg0 = p_tmp = ppsz_argv[ 0 ];
    while( *p_tmp )
    {
        if( *p_tmp == '/' ) p_main->psz_arg0 = ++p_tmp;
        else ++p_tmp;
    }

567
    /*
gbazin's avatar
 
gbazin committed
568 569 570
     * Initialize the module bank and and load the configuration of the main
     * module. We need to do this at this stage to be able to display a short
     * help if required by the user. (short help == main module options)
571
     */
gbazin's avatar
 
gbazin committed
572 573 574
    module_InitBank();
    module_LoadMain();

gbazin's avatar
 
gbazin committed
575 576 577 578 579 580 581 582 583 584 585
    /* Hack: insert the help module here */
    help_module.psz_name = "help";
    help_module.i_config_lines = sizeof(p_help_config) /
                                     sizeof(module_config_t);
    help_module.i_config_items = help_module.i_config_lines - 1;
    vlc_mutex_init( &help_module.config_lock );
    help_module.p_config = p_help_config;
    help_module.next = p_module_bank->first;
    p_module_bank->first = &help_module;
    /* end hack */

gbazin's avatar
 
gbazin committed
586
    if( config_LoadCmdLine( &i_argc, ppsz_argv, 1 ) )
Michel Kaempf's avatar
Michel Kaempf committed
587
    {
Vincent Seguin's avatar
Vincent Seguin committed
588
        intf_MsgDestroy();
589
        return( errno );
Michel Kaempf's avatar
Michel Kaempf committed
590
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
591

gbazin's avatar
 
gbazin committed
592 593 594
    /* Check for short help option */
    if( config_GetIntVariable( "help" ) )
    {
gbazin's avatar
 
gbazin committed
595 596 597 598
        intf_Msg( "Usage: %s [options] [parameters] [file]...\n",
                  p_main->psz_arg0 );

        Usage( "help" );
gbazin's avatar
 
gbazin committed
599 600 601 602 603 604 605 606 607 608 609
        Usage( "main" );
        return( -1 );
    }

    /* Check for version option */
    if( config_GetIntVariable( "version" ) )
    {
        Version();
        return( -1 );
    }

gbazin's avatar
 
gbazin committed
610 611 612 613
    /* Hack: remove the help module here */
    p_module_bank->first = help_module.next;
    /* end hack */

gbazin's avatar
 
gbazin committed
614
    /*
gbazin's avatar
 
gbazin committed
615
     * Load the builtins and plugins into the module_bank.
gbazin's avatar
 
gbazin committed
616
     * We have to do it before config_Load*() because this also gets the
gbazin's avatar
 
gbazin committed
617 618
     * list of configuration options exported by each plugin and loads their
     * default values.
gbazin's avatar
 
gbazin committed
619
     */
gbazin's avatar
 
gbazin committed
620 621 622 623 624
    module_LoadBuiltins();
    module_LoadPlugins();
    intf_WarnMsg( 2, "module: module bank initialized, found %i modules",
                  p_module_bank->i_count );

gbazin's avatar
 
gbazin committed
625 626 627 628 629
    /* Hack: insert the help module here */
    help_module.next = p_module_bank->first;
    p_module_bank->first = &help_module;
    /* end hack */

gbazin's avatar
 
gbazin committed
630
    /* Check for help on plugins */
gbazin's avatar
 
gbazin committed
631
    if( (p_tmp = config_GetPszVariable( "plugin" )) )
gbazin's avatar
 
gbazin committed
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651
    {
        Usage( p_tmp );
        free( p_tmp );
        return( -1 );
    }

    /* Check for long help option */
    if( config_GetIntVariable( "longhelp" ) )
    {
        Usage( NULL );
        return( -1 );
    }

    /* Check for plugin list option */
    if( config_GetIntVariable( "list" ) )
    {
        ListModules();
        return( -1 );
    }

gbazin's avatar
 
gbazin committed
652 653 654 655 656
    /* Hack: remove the help module here */
    p_module_bank->first = help_module.next;
    /* end hack */


gbazin's avatar
 
gbazin committed
657 658 659
    /*
     * Override default configuration with config file settings
     */
gbazin's avatar
 
gbazin committed
660
    vlc_mutex_init( &p_main->config_lock );
gbazin's avatar
 
gbazin committed
661
    p_main->psz_homedir = config_GetHomeDir();
gbazin's avatar
 
gbazin committed
662
    config_LoadConfigFile( NULL );
gbazin's avatar
 
gbazin committed
663 664 665 666

    /*
     * Override configuration with command line settings
     */
gbazin's avatar
 
gbazin committed
667
    if( config_LoadCmdLine( &i_argc, ppsz_argv, 0 ) )
gbazin's avatar
 
gbazin committed
668
    {
gbazin's avatar
 
gbazin committed
669 670 671 672 673 674 675
#ifdef WIN32
        ShowConsole();
        /* Pause the console because it's destroyed when we exit */
        intf_Msg( "The command line options couldn't be loaded, check that "
                  "they are valid.\nPress the RETURN key to continue..." );
        getchar();
#endif
gbazin's avatar
 
gbazin committed
676 677 678 679
        intf_MsgDestroy();
        return( errno );
    }

gbazin's avatar
 
gbazin committed
680

gbazin's avatar
 
gbazin committed
681 682 683 684 685 686 687
    /*
     * System specific configuration
     */
#if defined( WIN32 )
    system_Configure();
#endif

gbazin's avatar
 
gbazin committed
688
    /* p_main inititalization. FIXME ? */
gbazin's avatar
 
gbazin committed
689
    p_main->i_desync = (mtime_t)config_GetIntVariable( "desync" )
gbazin's avatar
 
gbazin committed
690
      * (mtime_t)1000;
gbazin's avatar
 
gbazin committed
691 692 693 694 695
    p_main->b_stats = config_GetIntVariable( "stats" );
    p_main->b_audio = !config_GetIntVariable( "noaudio" );
    p_main->b_stereo= !config_GetIntVariable( "mono" );
    p_main->b_video = !config_GetIntVariable( "novideo" );
    if( config_GetIntVariable( "nommx" ) )
gbazin's avatar
 
gbazin committed
696
        p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_MMX;
gbazin's avatar
 
gbazin committed
697
    if( config_GetIntVariable( "no3dn" ) )
gbazin's avatar
 
gbazin committed
698
        p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_3DNOW;
gbazin's avatar
 
gbazin committed
699
    if( config_GetIntVariable( "nommxext" ) )
gbazin's avatar
 
gbazin committed
700
        p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_MMXEXT;
gbazin's avatar
 
gbazin committed
701
    if( config_GetIntVariable( "nosse" ) )
gbazin's avatar
 
gbazin committed
702
        p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_SSE;
gbazin's avatar
 
gbazin committed
703
    if( config_GetIntVariable( "noaltivec" ) )
gbazin's avatar
 
gbazin committed
704 705 706
        p_main->i_cpu_capabilities &= ~CPU_CAPABILITY_ALTIVEC;


707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
    if( p_main->b_stats )
    {
        char          p_capabilities[200];
        p_capabilities[0] = '\0';

#define PRINT_CAPABILITY( capability, string )                              \
        if( p_main->i_cpu_capabilities & capability )                       \
        {                                                                   \
            strncat( p_capabilities, string " ",                            \
                     sizeof(p_capabilities) - strlen(p_capabilities) );     \
            p_capabilities[sizeof(p_capabilities) - 1] = '\0';              \
        }

        PRINT_CAPABILITY( CPU_CAPABILITY_486, "486" );
        PRINT_CAPABILITY( CPU_CAPABILITY_586, "586" );
        PRINT_CAPABILITY( CPU_CAPABILITY_PPRO, "Pentium Pro" );
        PRINT_CAPABILITY( CPU_CAPABILITY_MMX, "MMX" );
        PRINT_CAPABILITY( CPU_CAPABILITY_3DNOW, "3DNow!" );
        PRINT_CAPABILITY( CPU_CAPABILITY_MMXEXT, "MMXEXT" );
        PRINT_CAPABILITY( CPU_CAPABILITY_SSE, "SSE" );
        PRINT_CAPABILITY( CPU_CAPABILITY_ALTIVEC, "Altivec" );
Sam Hocevar's avatar
 
Sam Hocevar committed
728
        PRINT_CAPABILITY( CPU_CAPABILITY_FPU, "FPU" );
Sam Hocevar's avatar
 
Sam Hocevar committed
729
        intf_StatMsg( "info: CPU has capabilities : %s", p_capabilities );
730 731
    }

732
    /*
Sam Hocevar's avatar
 
Sam Hocevar committed
733
     * Initialize playlist and get commandline files
734
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
735
    p_main->p_playlist = intf_PlaylistCreate();
Sam Hocevar's avatar
 
Sam Hocevar committed
736
    if( !p_main->p_playlist )
737
    {
Sam Hocevar's avatar
 
Sam Hocevar committed
738
        intf_ErrMsg( "playlist error: playlist initialization failed" );
739 740
        intf_MsgDestroy();
        return( errno );
741
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
742
    intf_PlaylistInit( p_main->p_playlist );
743 744

    /*
Sam Hocevar's avatar
 
Sam Hocevar committed
745
     * Get input filenames given as commandline arguments
746
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
747
    GetFilenames( i_argc, ppsz_argv );
Michel Kaempf's avatar
Michel Kaempf committed
748

Sam Hocevar's avatar
 
Sam Hocevar committed
749
    /*
gbazin's avatar
 
gbazin committed
750
     * Initialize input, aout and vout banks
Sam Hocevar's avatar
 
Sam Hocevar committed
751
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
752
    input_InitBank();
Sam Hocevar's avatar
 
Sam Hocevar committed
753 754
    aout_InitBank();
    vout_InitBank();
Sam Hocevar's avatar
 
Sam Hocevar committed
755

Sam Hocevar's avatar
 
Sam Hocevar committed
756 757 758
    /*
     * Choose the best memcpy module
     */
gbazin's avatar
 
gbazin committed
759
    psz_plugin = config_GetPszVariable( "memcpy" );
760 761
    p_main->p_memcpy_module = module_Need( MODULE_CAPABILITY_MEMCPY,
                                           psz_plugin, NULL );
gbazin's avatar
 
gbazin committed
762
    if( psz_plugin ) free( psz_plugin );
Sam Hocevar's avatar
 
Sam Hocevar committed
763
    if( p_main->p_memcpy_module == NULL )
Sam Hocevar's avatar
 
Sam Hocevar committed
764 765 766
    {
        intf_ErrMsg( "intf error: no suitable memcpy module, "
                     "using libc default" );
Sam Hocevar's avatar
 
Sam Hocevar committed
767 768 769 770 771 772
        p_main->pf_memcpy = memcpy;
    }
    else
    {
        p_main->pf_memcpy = p_main->p_memcpy_module->p_functions
                                  ->memcpy.functions.memcpy.pf_memcpy;
Sam Hocevar's avatar
 
Sam Hocevar committed
773
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
774

Michel Kaempf's avatar
Michel Kaempf committed
775 776 777
    /*
     * Initialize shared resources and libraries
     */
gbazin's avatar
 
gbazin committed
778
    if( config_GetIntVariable( "network_channel" ) &&
779
        network_ChannelCreate() )
Michel Kaempf's avatar
Michel Kaempf committed
780
    {
Henri Fallon's avatar
 
Henri Fallon committed
781
        /* On error during Channels initialization, switch off channels */
Loïc Minier's avatar
Loïc Minier committed
782
        intf_ErrMsg( "intf error: channels initialization failed, "
Sam Hocevar's avatar
 
Sam Hocevar committed
783
                                 "deactivating channels" );
gbazin's avatar
 
gbazin committed
784
        config_PutIntVariable( "network_channel", 0 );
Michel Kaempf's avatar
Michel Kaempf committed
785
    }
786

Michel Kaempf's avatar
Michel Kaempf committed
787
    /*
Sam Hocevar's avatar
 
Sam Hocevar committed
788
     * Try to run the interface
Michel Kaempf's avatar
Michel Kaempf committed
789
     */
790
    p_main->p_intf = intf_Create();
Sam Hocevar's avatar
 
Sam Hocevar committed
791
    if( p_main->p_intf == NULL )
Sam Hocevar's avatar
 
Sam Hocevar committed
792 793 794
    {
        intf_ErrMsg( "intf error: interface initialization failed" );
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
795
    else
796
    {
Sam Hocevar's avatar
 
Sam Hocevar committed
797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
        /*
         * Set signal handling policy for all threads
         */
        InitSignalHandler();

        /*
         * This is the main loop
         */
        p_main->p_intf->pf_run( p_main->p_intf );

        /*
         * Finished, destroy the interface
         */
        intf_Destroy( p_main->p_intf );

        /*
         * Go back into channel 0 which is the network
         */
ipkiss's avatar
 
ipkiss committed
815
        if( config_GetIntVariable( "network_channel" ) && p_main->p_channel )
Sam Hocevar's avatar
 
Sam Hocevar committed
816 817 818
        {
            network_ChannelJoin( COMMON_CHANNEL );
        }
819
    }
Michel Kaempf's avatar
Michel Kaempf committed
820

Sam Hocevar's avatar
 
Sam Hocevar committed
821
    /*
Sam Hocevar's avatar
 
Sam Hocevar committed
822
     * Free input, aout and vout banks
Sam Hocevar's avatar
 
Sam Hocevar committed
823
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
824
    input_EndBank();
Sam Hocevar's avatar
 
Sam Hocevar committed
825 826 827 828 829 830 831 832
    vout_EndBank();
    aout_EndBank();

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

Sam Hocevar's avatar
 
Sam Hocevar committed
833
    /*
Sam Hocevar's avatar
 
Sam Hocevar committed
834
     * Free memcpy module if it was allocated
Sam Hocevar's avatar
 
Sam Hocevar committed
835
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
836
    if( p_main->p_memcpy_module != NULL )
Sam Hocevar's avatar
 
Sam Hocevar committed
837
    {
Sam Hocevar's avatar
 
Sam Hocevar committed
838
        module_Unneed( p_main->p_memcpy_module );
Sam Hocevar's avatar
 
Sam Hocevar committed
839
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
840

Sam Hocevar's avatar
 
Sam Hocevar committed
841
    /*
Sam Hocevar's avatar
 
Sam Hocevar committed
842
     * Free module bank
Sam Hocevar's avatar
 
Sam Hocevar committed
843
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
844
    module_EndBank();
845 846 847 848

    /*
     * System specific cleaning code
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
849
#if defined( SYS_BEOS ) || defined( SYS_DARWIN ) || defined( WIN32 )
Sam Hocevar's avatar
 
Sam Hocevar committed
850
    system_End();
851 852
#endif

Sam Hocevar's avatar
 
Sam Hocevar committed
853

Michel Kaempf's avatar
Michel Kaempf committed
854 855 856
    /*
     * Terminate messages interface and program
     */
Sam Hocevar's avatar
 
Sam Hocevar committed
857
    intf_WarnMsg( 1, "intf: program terminated" );
Vincent Seguin's avatar
Vincent Seguin committed
858
    intf_MsgDestroy();
859

Sam Hocevar's avatar
 
Sam Hocevar committed
860 861 862 863
    /*
     * Stop threads system
     */
    vlc_threads_end( );
Sam Hocevar's avatar
 
Sam Hocevar committed
864

Sam Hocevar's avatar
 
Sam Hocevar committed
865
    return 0;
Michel Kaempf's avatar
Michel Kaempf committed
866 867
}

Vincent Seguin's avatar
Vincent Seguin committed
868

gbazin's avatar
 
gbazin committed
869
/* following functions are local */
870

Sam Hocevar's avatar
 
Sam Hocevar committed
871 872 873 874 875 876 877 878
/*****************************************************************************
 * GetFilenames: parse command line options which are not flags
 *****************************************************************************
 * Parse command line for input files.
 *****************************************************************************/
static int GetFilenames( int i_argc, char *ppsz_argv[] )
{
    int i_opt;
Michel Kaempf's avatar
Michel Kaempf committed
879

Sam Hocevar's avatar
 
Sam Hocevar committed
880
    /* We assume that the remaining parameters are filenames */
Vincent Seguin's avatar
Vincent Seguin committed
881 882
    for( i_opt = optind; i_opt < i_argc; i_opt++ )
    {
Sam Hocevar's avatar
 
Sam Hocevar committed
883 884
        intf_PlaylistAdd( p_main->p_playlist, PLAYLIST_END,
                          ppsz_argv[ i_opt ] );
Vincent Seguin's avatar
Vincent Seguin committed
885
    }
Sam Hocevar's avatar
 
Sam Hocevar committed
886

Michel Kaempf's avatar
Michel Kaempf committed
887 888 889
    return( 0 );
}

890
/*****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
891
 * Usage: print program usage
892
 *****************************************************************************
Michel Kaempf's avatar
Michel Kaempf committed
893
 * Print a short inline help. Message interface is initialized at this stage.
894
 *****************************************************************************/
gbazin's avatar
 
gbazin committed
895
static void Usage( const char *psz_module_name )
Michel Kaempf's avatar
Michel Kaempf committed
896
{
gbazin's avatar
 
gbazin committed
897 898 899 900 901 902 903 904 905 906 907 908 909 910
    int i;
    module_t *p_module;
    char psz_spaces[30];

    memset( psz_spaces, 32, 30 );

#ifdef WIN32
    ShowConsole();
#endif

    /* Enumerate the config of each module */
    for( p_module = p_module_bank->first ;
         p_module != NULL ;
         p_module = p_module->next )
911
    {
gbazin's avatar
 
gbazin committed
912 913 914 915

        if( psz_module_name && strcmp( psz_module_name, p_module->psz_name ) )
            continue;

gbazin's avatar
 
gbazin committed
916 917 918
        /* ignore plugins without config options */
        if( !p_module->i_config_items ) continue;

gbazin's avatar
 
gbazin committed
919
        /* print module name */
gbazin's avatar
 
gbazin committed
920
        intf_Msg( "%s options:\n", p_module->psz_name );
gbazin's avatar
 
gbazin committed
921

gbazin's avatar
 
gbazin committed
922
        for( i = 0; i < p_module->i_config_lines; i++ )
gbazin's avatar
 
gbazin committed
923 924 925 926 927
        {
            int j;

            switch( p_module->p_config[i].i_type )
            {
gbazin's avatar
 
gbazin committed
928
            case MODULE_CONFIG_HINT_CATEGORY:
gbazin's avatar
 
gbazin committed
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
                intf_Msg( " %s", p_module->p_config[i].psz_text );
                break;

            case MODULE_CONFIG_ITEM_STRING:
            case MODULE_CONFIG_ITEM_FILE:
            case MODULE_CONFIG_ITEM_PLUGIN:
                /* Nasty hack, but right now I'm too tired to think about
                 * a nice solution */
                j = 25 - strlen( p_module->p_config[i].psz_name )
                    - strlen(" <string>") - 1;
                if( j < 0 ) j = 0; psz_spaces[j] = 0;

                intf_Msg( "  --%s <string>%s %s",
                          p_module->p_config[i].psz_name, psz_spaces,
                          p_module->p_config[i].psz_text );
                psz_spaces[j] = 32;
                break;
            case MODULE_CONFIG_ITEM_INTEGER:
                /* Nasty hack, but right now I'm too tired to think about
                 * a nice solution */
                j = 25 - strlen( p_module->p_config[i].psz_name )
                    - strlen(" <integer>") - 1;
                if( j < 0 ) j = 0; psz_spaces[j] = 0;

                intf_Msg( "  --%s <integer>%s %s",
                          p_module->p_config[i].psz_name, psz_spaces,
                          p_module->p_config[i].psz_text );
                psz_spaces[j] = 32;
                break;
gbazin's avatar
 
gbazin committed
958
            case MODULE_CONFIG_ITEM_BOOL:
gbazin's avatar
 
gbazin committed
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977
                /* Nasty hack, but right now I'm too tired to think about
                 * a nice solution */
                j = 25 - strlen( p_module->p_config[i].psz_name ) - 1;
                if( j < 0 ) j = 0; psz_spaces[j] = 0;

                intf_Msg( "  --%s%s %s",
                          p_module->p_config[i].psz_name, psz_spaces,
                          p_module->p_config[i].psz_text );
                psz_spaces[j] = 32;
                break;
            }
        }

        /* Yet another nasty hack.
         * Maybe we could use MODULE_CONFIG_ITEM_END to display tail messages
         * for each module?? */
        if( !strcmp( "main", p_module->psz_name ) )
            intf_Msg( "\nPlaylist items:"
                "\n  *.mpg, *.vob                   \tPlain MPEG-1/2 files"
gbazin's avatar
 
gbazin committed
978 979
                "\n  [dvd:][device][@raw_device][@[title][,[chapter][,angle]]]"
                "\n                                 \tDVD device"
gbazin's avatar
 
gbazin committed
980 981
                "\n  [vcd:][device][@[title][,[chapter]]"
                "\n                                 \tVCD device"
982
                "\n  udpstream:[@[<bind address>][:<bind port>]]"
gbazin's avatar
 
gbazin committed
983 984 985 986 987 988 989 990 991
                "\n                                 \tUDP stream sent by VLS"
                "\n  vlc:loop                       \tLoop execution of the "
                      "playlist"
                "\n  vlc:pause                      \tPause execution of "
                      "playlist items"
                "\n  vlc:quit                       \tQuit VLC" );

        intf_Msg( "" );

992 993
    }

gbazin's avatar
 
gbazin committed
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
#ifdef WIN32        /* Pause the console because it's destroyed when we exit */
        intf_Msg( "\nPress the RETURN key to continue..." );
        getchar();
#endif
}

/*****************************************************************************
 * ListModules: list the available modules with their description
 *****************************************************************************
 * Print a list of all available modules (builtins and plugins) and a short
 * description for each one.
 *****************************************************************************/
static void ListModules( void )
{
    module_t *p_module;
    char psz_spaces[20];

    memset( psz_spaces, 32, 20 );

#ifdef WIN32
    ShowConsole();
#endif

    /* Usage */
    intf_Msg( "Usage: %s [options] [parameters] [file]...\n",
              p_main->psz_arg0 );

    intf_Msg( "[plugin]              [description]" );

    /* Enumerate each module */
    for( p_module = p_module_bank->first ;
         p_module != NULL ;
         p_module = p_module->next )
    {
        int i;

        /* Nasty hack, but right now I'm too tired to think about a nice
         * solution */
        i = 20 - strlen( p_module->psz_name ) - 1;
        if( i < 0 ) i = 0;
        psz_spaces[i] = 0;

        intf_Msg( "  %s%s %s", p_module->psz_name, psz_spaces,
                  p_module->psz_longname );

        psz_spaces[i] = 32;

    }

#ifdef WIN32        /* Pause the console because it's destroyed when we exit */
        intf_Msg( "\nPress the RETURN key to continue..." );
        getchar();
#endif
Michel Kaempf's avatar
Michel Kaempf committed
1047 1048
}

1049
/*****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
1050
 * Version: print complete program version
1051
 *****************************************************************************
Vincent Seguin's avatar
Vincent Seguin committed
1052
 * Print complete program version and build number.
1053
 *****************************************************************************/
Vincent Seguin's avatar
Vincent Seguin committed
1054 1055
static void Version( void )
{
gbazin's avatar
 
gbazin committed
1056 1057 1058
#ifdef WIN32
    ShowConsole();
#endif
gbazin's avatar
 
gbazin committed