]> git.sesse.net Git - vlc/blobdiff - src/interface/main.c
Bon, puisque �a semble commiter sous BeOS, je commite.
[vlc] / src / interface / main.c
index 018dc54072c301ae51b0b6c03c4d787d29a30fb3..b991a4e896ddd24c9ebf03de0aee48270dbfdeae 100644 (file)
@@ -40,7 +40,9 @@
 #include "threads.h"
 #include "mtime.h"
 #include "plugins.h"
+#include "playlist.h"
 #include "input_vlan.h"
+#include "input_ps.h"
 
 #include "intf_msg.h"
 #include "interface.h"
@@ -106,6 +108,11 @@ static const struct option longopts[] =
     {   "grayscale",        0,          0,      'g' },
     {   "color",            0,          0,      OPT_COLOR },
 
+    /* DVD options */
+    {   "dvdaudio",         1,          0,      'a' },
+    {   "dvdchannel",       1,          0,      'c' },
+    {   "dvdsubtitle",      1,          0,      's' },
+    
     /* Input options */
     {   "novlans",          0,          0,      OPT_NOVLANS },
     {   "server",           1,          0,      OPT_SERVER },
@@ -115,7 +122,7 @@ static const struct option longopts[] =
 };
 
 /* Short options */
-static const char *psz_shortopts = "hHvg";
+static const char *psz_shortopts = "hHvga:s:c:";
 
 /*****************************************************************************
  * Global variable program_data - this is the one and only, see main.h
@@ -126,7 +133,8 @@ main_t *p_main;
  * Local prototypes
  *****************************************************************************/
 static void SetDefaultConfiguration ( void );
-static int  GetConfiguration        ( int i_argc, char *ppsz_argv[], char *ppsz_env[] );
+static int  GetConfiguration        ( int i_argc, char *ppsz_argv[],
+                                      char *ppsz_env[] );
 static void Usage                   ( int i_fashion );
 static void Version                 ( void );
 
@@ -141,103 +149,152 @@ static int  TestMMX                 ( void );
  *****************************************************************************
  * Steps during program execution are:
  *      -configuration parsing and messages interface initialization
- *      -openning of audio output device and some global modules
+ *      -opening of audio output device and some global modules
  *      -execution of interface, which exit on error or on user request
  *      -closing of audio output device and some global modules
- * On error, the spawned threads are cancelled, and the open devices closed.
+ * On error, the spawned threads are canceled, and the open devices closed.
  *****************************************************************************/
 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
 {
     main_t  main_data;                      /* root of all data - see main.h */
+
     p_main = &main_data;                       /* set up the global variable */
 
+#ifdef SYS_BEOS
     /*
      * System specific initialization code
      */
-#ifdef SYS_BEOS
-    beos_Init();
+    beos_Create();
 #endif
 
+#ifdef HAVE_MMX
     /*
-     * Read configuration, initialize messages interface and set up program
+     * Test if our code is likely to run on this CPU 
      */
-#ifdef HAVE_MMX
     if( !TestMMX() )
     {
-        fprintf( stderr, "Sorry, this program needs an MMX processor. Please run the non-MMX version.\n" );
+        fprintf( stderr, "Sorry, this program needs an MMX processor. "
+                         "Please run the non-MMX version.\n" );
         return( 1 );
     }
 #endif
+
+    /*
+     * Initialize messages interface
+     */
     p_main->p_msg = intf_MsgCreate();
     if( !p_main->p_msg )                         /* start messages interface */
     {
-        fprintf( stderr, "critical error: can't initialize messages interface (%s)\n",
+        fprintf( stderr, "error: can't initialize messages interface (%s)\n",
                 strerror(errno) );
         return( errno );
     }
+
+    /*
+     * Read configuration
+     */
     if( GetConfiguration( i_argc, ppsz_argv, ppsz_env ) )  /* parse cmd line */
     {
+        intf_MsgDestroy();
+        fprintf( stderr, "error: can't read configuration (%s)\n",
+                strerror(errno) );
+        return( errno );
+    }
+
+    /*
+     * Initialize playlist and get commandline files
+     */
+    p_main->p_playlist = playlist_Create( );
+    if( !p_main->p_playlist )
+    {
+        intf_Msg( "Playlist initialization failed\n" );
+        intf_MsgDestroy();
+        return( errno );
+    }
+    playlist_Init( p_main->p_playlist, optind );
+
+    /*
+     * Initialize plugin bank
+     */
+    p_main->p_bank = bank_Create( );
+    if( !p_main->p_bank )
+    {
+        intf_Msg( "Plugin bank initialization failed\n" );
+        playlist_Destroy( p_main->p_playlist );
         intf_MsgDestroy();
         return( errno );
     }
-    intf_MsgImm( COPYRIGHT_MESSAGE "\n" );          /* print welcome message */
+    bank_Init( p_main->p_bank );
 
     /*
      * Initialize shared resources and libraries
      */
-    if( main_data.b_vlans && input_VlanCreate() )
+    if( p_main->b_vlans && input_VlanCreate() )
     {
-        /* On error during vlans initialization, switch of vlans */
-        intf_Msg( "Virtual LANs initialization failed : vlans management is deactivated\n" );
-        main_data.b_vlans = 0;
+        /* On error during vlans initialization, switch off vlans */
+        intf_Msg( "Virtual LANs initialization failed : "
+                  "vlans management is deactivated\n" );
+        p_main->b_vlans = 0;
     }
 
     /*
      * Open audio device and start aout thread
      */
-    if( main_data.b_audio )
+    if( p_main->b_audio )
     {
-        main_data.p_aout = aout_CreateThread( NULL );
-        if( main_data.p_aout == NULL )
+        p_main->p_aout = aout_CreateThread( NULL );
+        if( p_main->p_aout == NULL )
         {
-            /* On error during audio initialization, switch of audio */
+            /* On error during audio initialization, switch off audio */
             intf_Msg( "Audio initialization failed : audio is deactivated\n" );
-            main_data.b_audio = 0;
+            p_main->b_audio = 0;
         }
     }
 
     /*
      * Run interface
      */
-    main_data.p_intf = intf_Create();
-    if( main_data.p_intf != NULL )
+    p_main->p_intf = intf_Create();
+    if( p_main->p_intf != NULL )
     {
         InitSignalHandler();             /* prepare signals for interception */
-        intf_Run( main_data.p_intf );
-        intf_Destroy( main_data.p_intf );
+
+        intf_Run( p_main->p_intf );
+
+        intf_Destroy( p_main->p_intf );
     }
 
     /*
      * Close audio device
      */
-    if( main_data.b_audio )
+    if( p_main->b_audio )
     {
-        aout_DestroyThread( main_data.p_aout, NULL );
+        aout_DestroyThread( p_main->p_aout, NULL );
     }
 
     /*
      * Free shared resources and libraries
      */
-    if( main_data.b_vlans )
+    if( p_main->b_vlans )
     {
         input_VlanDestroy();
     }
 
     /*
-     * System specific cleaning code
+     * Free plugin bank
+     */
+    bank_Destroy( p_main->p_bank );
+
+    /*
+     * Free playlist
      */
+    playlist_Destroy( p_main->p_playlist );
+
 #ifdef SYS_BEOS
-    beos_Clean();
+    /*
+     * System specific cleaning code
+     */
+    beos_Destroy();
 #endif
 
     /*
@@ -245,6 +302,7 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
      */
     intf_Msg( "Program terminated.\n" );
     intf_MsgDestroy();
+
     return( 0 );
 }
 
@@ -426,6 +484,24 @@ static int GetConfiguration( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
             main_PutIntVariable( VOUT_GRAYSCALE_VAR, 0 );
             break;
 
+        /* DVD options */
+        case 'a':
+            if ( ! strcmp(optarg, "mpeg") )
+                main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_MPEG );
+            else if ( ! strcmp(optarg, "lpcm") )
+                main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_LPCM );
+            else if ( ! strcmp(optarg, "off") )
+                main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_NOAUDIO );
+            else
+                main_PutIntVariable( INPUT_DVD_AUDIO_VAR, REQUESTED_AC3 );
+            break;
+        case 'c':
+            main_PutIntVariable( INPUT_DVD_CHANNEL_VAR, atoi(optarg) );
+            break;
+        case 's':
+            main_PutIntVariable( INPUT_DVD_SUBTITLE_VAR, atoi(optarg) );
+            break;
+
         /* Input options */
         case OPT_NOVLANS:                                       /* --novlans */
             p_main->b_vlans = 0;
@@ -463,7 +539,7 @@ static int GetConfiguration( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
 static void Usage( int i_fashion )
 {
     /* Usage */
-    intf_Msg( "Usage: vlc [options] [parameters]\n" );
+    intf_Msg( "Usage: vlc [options] [parameters] [file]...\n" );
 
     if( i_fashion == USAGE )
     {
@@ -487,6 +563,10 @@ static void Usage( int i_fashion )
               "  -g, --grayscale                \tgrayscale output\n"
               "      --color                    \tcolor output\n"
               "\n"
+              "  -a, --dvdaudio                 \tchoose DVD audio type\n"
+              "  -c, --dvdchannel               \tchoose DVD audio channel\n"
+              "  -s, --dvdsubtitle              \tchoose DVD subtitle channel\n"
+              "\n"
               "      --novlans                  \tdisable vlans\n"
               "      --server <host>            \tvideo server address\n"
               "      --port <port>              \tvideo server port\n"
@@ -522,6 +602,13 @@ static void Usage( int i_fashion )
               "  " VOUT_FB_DEV_VAR "=<filename>           \tframebuffer device path\n"
               "  " VOUT_GRAYSCALE_VAR "={1|0}             \tgrayscale or color output\n" );
 
+    /* DVD parameters */
+    intf_Msg( "\n"
+              "DVD parameters:\n"
+              "  " INPUT_DVD_AUDIO_VAR "={ac3|lpcm|mpeg|off} \taudio type\n"
+              "  " INPUT_DVD_CHANNEL_VAR "=[0-15]            \taudio channel\n"
+              "  " INPUT_DVD_SUBTITLE_VAR "=[0-31]           \tsubtitle channel\n" );
+
     /* Input parameters */
     intf_Msg( "\n"
               "Input parameters:\n"
@@ -544,7 +631,7 @@ static void Version( void )
               "You may redistribute it under the terms of the GNU General Public License;\n"
               "see the file named COPYING for details.\n"
               "Written by the VideoLAN team at Ecole Centrale, Paris.\n" );
-           
+
 }
 
 /*****************************************************************************
@@ -590,18 +677,18 @@ static void SignalHandler( int i_signal )
  * 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.
+ * CPU really supports MMX.
  *****************************************************************************/
 static int TestMMX( void )
 {
-/* FIXME: under beos, gcc does not support the foolowing inline assembly */ 
+/* FIXME: under beos, gcc does not support the following inline assembly */ 
 #ifdef SYS_BEOS
     return( 1 );
 #else
 
     int i_reg, i_dummy = 0;
 
-    /* test for a 386 cpu */
+    /* test for a 386 CPU */
     asm volatile ( "pushfl
                     popl %%eax
                     movl %%eax, %%ecx
@@ -617,7 +704,7 @@ static int TestMMX( void )
     if( !i_reg )
         return( 0 );
 
-    /* test for a 486 cpu */
+    /* test for a 486 CPU */
     asm volatile ( "movl %%ecx, %%eax
                     xorl $0x200000, %%eax
                     pushl %%eax
@@ -633,7 +720,7 @@ static int TestMMX( void )
     if( !i_reg )
         return( 0 );
 
-    /* the cpu supports the CPUID instruction - get its level */
+    /* the CPU supports the CPUID instruction - get its level */
     asm volatile ( "cpuid"
                  : "=a" ( i_reg ),
                    "=b" ( i_dummy ),
@@ -642,7 +729,7 @@ static int TestMMX( void )
                  : "a"  ( 0 ),       /* level 0 */
                    "b"  ( i_dummy ) ); /* buggy compiler shouldn't complain */
 
-    /* this shouldn't happen on a normal cpu */
+    /* this shouldn't happen on a normal CPU */
     if( !i_reg )
         return( 0 );