Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

vlc.c

00001 /*****************************************************************************
00002  * vlc.c: the vlc player
00003  *****************************************************************************
00004  * Copyright (C) 1998-2004 the VideoLAN team
00005  * $Id: vlc.c 11664 2005-07-09 06:17:09Z courmisch $
00006  *
00007  * Authors: Vincent Seguin <[email protected]>
00008  *          Samuel Hocevar <[email protected]>
00009  *          Gildas Bazin <[email protected]>
00010  *          Derk-Jan Hartman <hartman at videolan dot org>
00011  *          Lots of other people, see the libvlc AUTHORS file
00012  *
00013  * This program is free software; you can redistribute it and/or modify
00014  * it under the terms of the GNU General Public License as published by
00015  * the Free Software Foundation; either version 2 of the License, or
00016  * (at your option) any later version.
00017  *
00018  * This program is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License
00024  * along with this program; if not, write to the Free Software
00025  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00026  *****************************************************************************/
00027 
00028 #include "config.h"
00029 
00030 #include <stdio.h>                                              /* fprintf() */
00031 #include <stdlib.h>                                  /* putenv(), strtol(),  */
00032 #ifdef HAVE_SIGNAL_H
00033 #   include <signal.h>                            /* SIGHUP, SIGINT, SIGKILL */
00034 #endif
00035 #ifdef HAVE_TIME_H
00036 #   include <time.h>                                               /* time() */
00037 #endif
00038 
00039 #include <vlc/vlc.h>
00040 
00041 /*****************************************************************************
00042  * Local prototypes.
00043  *****************************************************************************/
00044 #if !defined(WIN32) && !defined(UNDER_CE)
00045 static void SigHandler  ( int i_signal );
00046 #endif
00047 
00048 /*****************************************************************************
00049  * main: parse command line, start interface and spawn threads.
00050  *****************************************************************************/
00051 int main( int i_argc, char *ppsz_argv[] )
00052 {
00053     int i_ret;
00054 
00055 #ifndef SYS_DARWIN
00056     /* This clutters OSX GUI error logs */
00057     fprintf( stderr, "VLC media player %s\n", VLC_Version() );
00058 #endif
00059 
00060 #ifdef HAVE_PUTENV
00061 #   ifdef DEBUG
00062     /* Activate malloc checking routines to detect heap corruptions. */
00063     putenv( "MALLOC_CHECK_=2" );
00064 
00065     /* Disable the ugly Gnome crash dialog so that we properly segfault */
00066     putenv( "GNOME_DISABLE_CRASH_DIALOG=1" );
00067 #   endif
00068 
00069     /* If the user isn't using VLC_VERBOSE, set it to 0 by default */
00070     if( getenv( "VLC_VERBOSE" ) == NULL )
00071     {
00072         putenv( "VLC_VERBOSE=0" );
00073     }
00074 #endif
00075 
00076     /* Create a libvlc structure */
00077     i_ret = VLC_Create();
00078     if( i_ret < 0 )
00079     {
00080         return i_ret;
00081     }
00082 
00083 #if !defined(WIN32) && !defined(UNDER_CE)
00084     /* Set the signal handlers. SIGTERM is not intercepted, because we need at
00085      * least one method to kill the program when all other methods failed, and
00086      * when we don't want to use SIGKILL.
00087      * Note that we set the signals after the vlc_create call. */
00088     signal( SIGINT,  SigHandler );
00089     signal( SIGHUP,  SigHandler );
00090     signal( SIGQUIT, SigHandler );
00091 
00092     /* Other signals */
00093     signal( SIGALRM, SIG_IGN );
00094     signal( SIGPIPE, SIG_IGN );
00095 #endif
00096 
00097     /* Initialize libvlc */
00098     i_ret = VLC_Init( 0, i_argc, ppsz_argv );
00099     if( i_ret < 0 )
00100     {
00101         VLC_Destroy( 0 );
00102         return i_ret;
00103     }
00104 
00105     i_ret = VLC_AddIntf( 0, NULL, VLC_TRUE, VLC_TRUE );
00106 
00107     /* Finish the threads */
00108     VLC_CleanUp( 0 );
00109 
00110     /* Destroy the libvlc structure */
00111     VLC_Destroy( 0 );
00112 
00113     return i_ret;
00114 }
00115 
00116 #if !defined(WIN32) && !defined(UNDER_CE)
00117 /*****************************************************************************
00118  * SigHandler: system signal handler
00119  *****************************************************************************
00120  * This function is called when a fatal signal is received by the program.
00121  * It tries to end the program in a clean way.
00122  *****************************************************************************/
00123 static void SigHandler( int i_signal )
00124 {
00125     static time_t abort_time = 0;
00126     static volatile vlc_bool_t b_die = VLC_FALSE;
00127 
00128     /* Once a signal has been trapped, the termination sequence will be
00129      * armed and subsequent signals will be ignored to avoid sending signals
00130      * to a libvlc structure having been destroyed */
00131 
00132     if( !b_die )
00133     {
00134         b_die = VLC_TRUE;
00135         abort_time = time( NULL );
00136 
00137         fprintf( stderr, "signal %d received, terminating vlc - do it "
00138                          "again in case it gets stuck\n", i_signal );
00139 
00140         /* Acknowledge the signal received */
00141         VLC_Die( 0 );
00142     }
00143     else if( time( NULL ) > abort_time + 2 )
00144     {
00145         /* If user asks again 1 or 2 seconds later, die badly */
00146         signal( SIGINT,  SIG_DFL );
00147         signal( SIGHUP,  SIG_DFL );
00148         signal( SIGQUIT, SIG_DFL );
00149         signal( SIGALRM, SIG_DFL );
00150         signal( SIGPIPE, SIG_DFL );
00151 
00152         fprintf( stderr, "user insisted too much, dying badly\n" );
00153 
00154         abort();
00155     }
00156 }
00157 #endif
00158 
00159 #if defined(UNDER_CE)
00160 #   if defined( _MSC_VER ) && defined( UNDER_CE )
00161 #       include "vlc_common.h"
00162 #   endif
00163 /*****************************************************************************
00164  * WinMain: parse command line, start interface and spawn threads. (WinCE only)
00165  *****************************************************************************/
00166 int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
00167                     LPTSTR lpCmdLine, int nCmdShow )
00168 {
00169     char **argv, psz_cmdline[MAX_PATH];
00170     int argc, i_ret;
00171 
00172     WideCharToMultiByte( CP_ACP, 0, lpCmdLine, -1,
00173                          psz_cmdline, MAX_PATH, NULL, NULL );
00174 
00175     argv = vlc_parse_cmdline( psz_cmdline, &argc );
00176     argv = realloc( argv, (argc + 1) * sizeof(char *) );
00177     if( !argv ) return -1;
00178 
00179     if( argc ) memmove( argv + 1, argv, argc * sizeof(char *) );
00180     argv[0] = ""; /* Fake program path */
00181 
00182     i_ret = main( argc + 1, argv );
00183 
00184     /* No need to free the argv memory */
00185     return i_ret;
00186 }
00187 #endif

Generated on Tue Dec 20 10:15:02 2005 for vlc-0.8.4a by  doxygen 1.4.2