1 /*****************************************************************************
2 * vlc.c: the vlc player
3 *****************************************************************************
4 * Copyright (C) 1998-2004 the VideoLAN team
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * Gildas Bazin <gbazin@videolan.org>
10 * Derk-Jan Hartman <hartman at videolan dot org>
11 * Lots of other people, see the libvlc AUTHORS file
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
26 *****************************************************************************/
30 #include <stdio.h> /* fprintf() */
31 #include <stdlib.h> /* putenv(), strtol(), */
33 # include <signal.h> /* SIGHUP, SIGINT, SIGKILL */
36 # include <time.h> /* time() */
41 /*****************************************************************************
43 *****************************************************************************/
44 #if !defined(WIN32) && !defined(UNDER_CE)
45 static void SigHandler ( int i_signal );
48 extern void rootwrap( void );
50 /*****************************************************************************
51 * main: parse command line, start interface and spawn threads.
52 *****************************************************************************/
53 int main( int i_argc, char *ppsz_argv[] )
58 /* This clutters OSX GUI error logs */
59 fprintf( stderr, "VLC media player %s\n", VLC_Version() );
64 /* Activate malloc checking routines to detect heap corruptions. */
65 putenv( "MALLOC_CHECK_=2" );
67 /* Disable the ugly Gnome crash dialog so that we properly segfault */
68 putenv( "GNOME_DISABLE_CRASH_DIALOG=1" );
71 /* If the user isn't using VLC_VERBOSE, set it to 0 by default */
72 if( getenv( "VLC_VERBOSE" ) == NULL )
74 putenv( "VLC_VERBOSE=0" );
80 /* Create a libvlc structure */
87 #if !defined(WIN32) && !defined(UNDER_CE)
88 /* Set the signal handlers. SIGTERM is not intercepted, because we need at
89 * least one method to kill the program when all other methods failed, and
90 * when we don't want to use SIGKILL.
91 * Note that we set the signals after the vlc_create call. */
92 signal( SIGINT, SigHandler );
93 signal( SIGHUP, SigHandler );
94 signal( SIGQUIT, SigHandler );
97 signal( SIGALRM, SIG_IGN );
98 signal( SIGPIPE, SIG_IGN );
101 /* Initialize libvlc */
102 i_ret = VLC_Init( 0, i_argc, ppsz_argv );
106 return i_ret == VLC_EEXITSUCCESS ? 0 : i_ret;
109 i_ret = VLC_AddIntf( 0, NULL, VLC_TRUE, VLC_TRUE );
111 /* Finish the threads */
114 /* Destroy the libvlc structure */
120 #if !defined(WIN32) && !defined(UNDER_CE)
121 /*****************************************************************************
122 * SigHandler: system signal handler
123 *****************************************************************************
124 * This function is called when a fatal signal is received by the program.
125 * It tries to end the program in a clean way.
126 *****************************************************************************/
127 static void SigHandler( int i_signal )
129 static time_t abort_time = 0;
130 static volatile vlc_bool_t b_die = VLC_FALSE;
132 /* Once a signal has been trapped, the termination sequence will be
133 * armed and subsequent signals will be ignored to avoid sending signals
134 * to a libvlc structure having been destroyed */
139 abort_time = time( NULL );
141 fprintf( stderr, "signal %d received, terminating vlc - do it "
142 "again in case it gets stuck\n", i_signal );
144 /* Acknowledge the signal received */
147 else if( time( NULL ) > abort_time + 2 )
149 /* If user asks again 1 or 2 seconds later, die badly */
150 signal( SIGINT, SIG_DFL );
151 signal( SIGHUP, SIG_DFL );
152 signal( SIGQUIT, SIG_DFL );
153 signal( SIGALRM, SIG_DFL );
154 signal( SIGPIPE, SIG_DFL );
156 fprintf( stderr, "user insisted too much, dying badly\n" );
163 #if defined(UNDER_CE)
164 # if defined( _MSC_VER ) && defined( UNDER_CE )
165 # include "vlc_common.h"
167 /*****************************************************************************
168 * WinMain: parse command line, start interface and spawn threads. (WinCE only)
169 *****************************************************************************/
170 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
171 LPTSTR lpCmdLine, int nCmdShow )
173 char **argv, psz_cmdline[MAX_PATH];
176 WideCharToMultiByte( CP_ACP, 0, lpCmdLine, -1,
177 psz_cmdline, MAX_PATH, NULL, NULL );
179 argv = vlc_parse_cmdline( psz_cmdline, &argc );
180 argv = realloc( argv, (argc + 1) * sizeof(char *) );
181 if( !argv ) return -1;
183 if( argc ) memmove( argv + 1, argv, argc * sizeof(char *) );
184 argv[0] = ""; /* Fake program path */
186 i_ret = main( argc + 1, argv );
188 /* No need to free the argv memory */