]> git.sesse.net Git - vlc/blobdiff - src/interface/main.c
. kludge con pour �viter que �a segfaulte plus en sortant
[vlc] / src / interface / main.c
index 5b6967e9305cbe76d6e35761487878e810084073..df32efe6ad942fbce7d6cbe779cf4d0ab265e665 100644 (file)
  * 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.
+ * 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.
+ * 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.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <getopt.h>                                              /* getopt() */
+#include "defs.h"
+
 #include <signal.h>                               /* SIGHUP, SIGINT, SIGKILL */
+#include <getopt.h>                                              /* getopt() */
 #include <stdio.h>                                              /* sprintf() */
 
 #include <errno.h>                                                 /* ENOMEM */
 
 #include "config.h"
 #include "common.h"
-#include "mtime.h"
 #include "threads.h"
+#include "mtime.h"
+#include "plugins.h"
 #include "input_vlan.h"
+#include "input_ps.h"
 
 #include "intf_msg.h"
 #include "interface.h"
 
 #include "audio_output.h"
 
+#ifdef SYS_BEOS
+#include "beos_specific.h"
+#endif
+
 #include "main.h"
 
 /*****************************************************************************
@@ -71,8 +78,9 @@
 #define OPT_PORT                172
 
 /* Usage fashion */
-#define SHORT_HELP                0
-#define LONG_HELP                 1
+#define USAGE                     0
+#define SHORT_HELP                1
+#define LONG_HELP                 2
 
 /* Long options */
 static const struct option longopts[] =
@@ -99,6 +107,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 },
@@ -108,7 +121,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
@@ -125,7 +138,9 @@ static void Version                 ( void );
 
 static void InitSignalHandler       ( void );
 static void SignalHandler           ( int i_signal );
+#ifdef HAVE_MMX
 static int  TestMMX                 ( void );
+#endif
 
 /*****************************************************************************
  * main: parse command line, start interface and spawn threads
@@ -140,8 +155,18 @@ static int  TestMMX                 ( void );
 int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
 {
     main_t  main_data;                      /* root of all data - see main.h */
+    char **p_playlist;
+    int i_list_index;
+
     p_main = &main_data;                       /* set up the global variable */
 
+    /*
+     * System specific initialization code
+     */
+#ifdef SYS_BEOS
+    beos_Init();
+#endif
+
     /*
      * Read configuration, initialize messages interface and set up program
      */
@@ -155,15 +180,36 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
     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",
-                strerror(errno));
-        return(errno);
+        fprintf( stderr, "critical error: can't initialize messages interface (%s)\n",
+                strerror(errno) );
+        return( errno );
     }
     if( GetConfiguration( i_argc, ppsz_argv, ppsz_env ) )  /* parse cmd line */
     {
         intf_MsgDestroy();
-        return(errno);
+        return( errno );
+    }
+
+    /* get command line files */
+    i_list_index = 0;
+
+    if( optind < i_argc )
+    {
+        int i_index = 0;
+        p_playlist = malloc( (i_list_index = i_argc - optind)
+                                        * sizeof(int) );
+
+        while( i_argc - i_index > optind )
+        {
+            p_playlist[ i_index ] = ppsz_argv[ i_argc - i_index - 1];
+            i_index++;
+        }
     }
+    else
+    {
+        p_playlist = NULL;
+    }
+
     intf_MsgImm( COPYRIGHT_MESSAGE "\n" );          /* print welcome message */
 
     /*
@@ -172,7 +218,7 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
     if( main_data.b_vlans && input_VlanCreate() )
     {
         /* On error during vlans initialization, switch of vlans */
-        intf_Msg("Virtual LANs initialization failed : vlans management is deactivated\n");
+        intf_Msg( "Virtual LANs initialization failed : vlans management is deactivated\n" );
         main_data.b_vlans = 0;
     }
 
@@ -185,7 +231,7 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
         if( main_data.p_aout == NULL )
         {
             /* On error during audio initialization, switch of audio */
-            intf_Msg("Audio initialization failed : audio is deactivated\n");
+            intf_Msg( "Audio initialization failed : audio is deactivated\n" );
             main_data.b_audio = 0;
         }
     }
@@ -196,7 +242,11 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
     main_data.p_intf = intf_Create();
     if( main_data.p_intf != NULL )
     {
+        main_data.p_intf->p_playlist = p_playlist;
+        main_data.p_intf->i_list_index = i_list_index;
+
         InitSignalHandler();             /* prepare signals for interception */
+
         intf_Run( main_data.p_intf );
         intf_Destroy( main_data.p_intf );
     }
@@ -217,6 +267,13 @@ int main( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
         input_VlanDestroy();
     }
 
+    /*
+     * System specific cleaning code
+     */
+#ifdef SYS_BEOS
+    beos_Clean();
+#endif
+
     /*
      * Terminate messages interface and program
      */
@@ -279,14 +336,14 @@ void main_PutPszVariable( char *psz_name, char *psz_value )
     psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );
     if( psz_env == NULL )
     {
-        intf_ErrMsg("error: %s\n", strerror(ENOMEM));
+        intf_ErrMsg( "error: %s\n", strerror(ENOMEM) );
     }
     else
     {
         sprintf( psz_env, "%s=%s", psz_name, psz_value );
         if( putenv( psz_env ) )
         {
-            intf_ErrMsg("error: %s\n", strerror(errno));
+            intf_ErrMsg( "error: %s\n", strerror(errno) );
         }
     }
 }
@@ -302,7 +359,7 @@ void main_PutIntVariable( char *psz_name, int i_value )
 {
     char psz_value[ 256 ];                               /* buffer for value */
 
-    sprintf(psz_value, "%d", i_value );
+    sprintf( psz_value, "%d", i_value );
     main_PutPszVariable( psz_name, psz_value );
 }
 
@@ -403,6 +460,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;
@@ -417,7 +492,8 @@ static int GetConfiguration( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
         /* Internal error: unknown option */
         case '?':
         default:
-            intf_ErrMsg("intf error: unknown option '%s'\n", ppsz_argv[optind - 1]);
+            intf_ErrMsg( "intf error: unknown option `%s'\n", ppsz_argv[optind - 1] );
+            Usage( USAGE );
             return( EINVAL );
             break;
         }
@@ -438,61 +514,85 @@ static int GetConfiguration( int i_argc, char *ppsz_argv[], char *ppsz_env[] )
  *****************************************************************************/
 static void Usage( int i_fashion )
 {
-    intf_Msg(COPYRIGHT_MESSAGE "\n");
-
     /* Usage */
-    intf_Msg("usage: vlc [options...] [parameters]\n" );
+    intf_Msg( "Usage: vlc [options] [parameters]\n" );
+
+    if( i_fashion == USAGE )
+    {
+        intf_Msg( "Try `vlc --help' for more information.\n" );
+        return;
+    }
+
+    intf_MsgImm( COPYRIGHT_MESSAGE "\n" );
 
     /* Options */
-    intf_Msg("Options:\n" \
-             "  -h, --help, -H, --longhelp        \tprint short/long usage\n" \
-             "  -v, --version                     \tprint version information\n"\
-             "  --noaudio, --novideo              \tdisable audio/video\n" \
-             "  --aout {" AUDIO_OPTIONS "}            \taudio output method\n"\
-             "  --stereo, --mono                  \tstereo/mono audio\n" \
-             "  --vout {" VIDEO_OPTIONS "}            \tvideo output method\n"\
-             "  --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" \
-             );
+    intf_Msg( "\n"
+              "Options:\n"
+              "      --noaudio                  \tdisable audio\n"
+              "      --aout <plugin>            \taudio output method\n"
+              "      --stereo, --mono           \tstereo/mono audio\n"
+              "\n"
+              "      --novideo                  \tdisable video\n"
+              "      --vout <plugin>            \tvideo output method\n"
+              "      --display <display>        \tdisplay string\n"
+              "      --width <w>, --height <h>  \tdisplay dimensions\n"
+              "  -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"
+              "\n"
+              "  -h, --help                     \tprint help and exit\n"
+              "  -H, --longhelp                 \tprint long help and exit\n"
+              "  -v, --version                  \toutput version information and exit\n" );
 
     if( i_fashion == SHORT_HELP )
         return;
 
     /* Interface parameters */
-    intf_Msg("Interface parameters:\n" \
-             "  " INTF_INIT_SCRIPT_VAR "=<filename>             \tinitialization script\n" \
-             "  " INTF_CHANNELS_VAR "=<filename>            \tchannels list\n"\
-             );
+    intf_Msg( "\n"
+              "Interface parameters:\n"
+              "  " INTF_INIT_SCRIPT_VAR "=<filename>             \tinitialization script\n"
+              "  " INTF_CHANNELS_VAR "=<filename>            \tchannels list\n" );
 
     /* Audio parameters */
-    intf_Msg("Audio parameters:\n" \
-             "  " AOUT_METHOD_VAR "=<method name>        \taudio method (" AUDIO_OPTIONS ")\n" \
-             "  " 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" \
-             );
+    intf_Msg( "\n"
+              "Audio parameters:\n"
+              "  " AOUT_METHOD_VAR "=<method name>        \taudio method\n"
+              "  " 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" );
 
     /* Video parameters */
-    intf_Msg("Video parameters:\n" \
-             "  " VOUT_METHOD_VAR "=<method name>        \tdisplay method (" VIDEO_OPTIONS ")\n" \
-             "  " 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" \
-             );
+    intf_Msg( "\n"
+              "Video parameters:\n"
+              "  " VOUT_METHOD_VAR "=<method name>        \tdisplay method\n"
+              "  " 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" );
+
+    /* 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("Input parameters:\n" \
-             "  " INPUT_SERVER_VAR "=<hostname>          \tvideo server\n" \
-             "  " INPUT_PORT_VAR "=<port>            \tvideo server port\n" \
-             "  " INPUT_IFACE_VAR "=<interface>          \tnetwork interface\n"\
-             "  " INPUT_VLAN_SERVER_VAR "=<hostname>     \tvlan server\n" \
-             "  " INPUT_VLAN_PORT_VAR "=<port>           \tvlan server port\n"\
-             );
+    intf_Msg( "\n"
+              "Input parameters:\n"
+              "  " INPUT_SERVER_VAR "=<hostname>          \tvideo server\n"
+              "  " INPUT_PORT_VAR "=<port>            \tvideo server port\n"
+              "  " INPUT_IFACE_VAR "=<interface>          \tnetwork interface\n"
+              "  " INPUT_VLAN_SERVER_VAR "=<hostname>     \tvlan server\n"
+              "  " INPUT_VLAN_PORT_VAR "=<port>           \tvlan server port\n" );
 }
 
 /*****************************************************************************
@@ -502,14 +602,12 @@ static void Usage( int i_fashion )
  *****************************************************************************/
 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" \
-            );
+    intf_Msg( VERSION_MESSAGE
+              "This program comes with NO WARRANTY, to the extent permitted by law.\n"
+              "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" );
+
 }
 
 /*****************************************************************************
@@ -559,6 +657,11 @@ static void SignalHandler( int i_signal )
  *****************************************************************************/
 static int TestMMX( void )
 {
+/* FIXME: under beos, gcc does not support the foolowing inline assembly */ 
+#ifdef SYS_BEOS
+    return( 1 );
+#else
+
     int i_reg, i_dummy = 0;
 
     /* test for a 386 cpu */
@@ -620,5 +723,7 @@ static int TestMMX( void )
         return( 0 );
 
     return( 1 );
+
+#endif
 }
 #endif