⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 vlc stand 0.1.99 ist sehr einfach
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * main.c: main vlc source * Includes the main() function for vlc. Parses command line, start interface * and spawn threads. ***************************************************************************** * Copyright (C) 1998, 1999, 2000 VideoLAN * * Authors: * * 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. *  * 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. * * 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 "defs.h"#include <signal.h>                               /* SIGHUP, SIGINT, SIGKILL */#include <getopt.h>                                              /* getopt() */#include <stdio.h>                                              /* sprintf() */#include <errno.h>                                                 /* ENOMEM */#include <stdlib.h>                                  /* getenv(), strtol(),  */#include <string.h>                                            /* strerror() */#include "config.h"#include "common.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"/***************************************************************************** * Command line options constants. If something is changed here, be sure that * GetConfiguration and Usage are also changed. *****************************************************************************//* Long options return values - note that values corresponding to short options * chars, and in general any regular char, should be avoided */#define OPT_NOAUDIO             150#define OPT_AOUT                151#define OPT_STEREO              152#define OPT_MONO                153#define OPT_NOVIDEO             160#define OPT_VOUT                161#define OPT_DISPLAY             162#define OPT_WIDTH               163#define OPT_HEIGHT              164#define OPT_COLOR               165#define OPT_NOVLANS             170#define OPT_SERVER              171#define OPT_PORT                172/* Usage fashion */#define USAGE                     0#define SHORT_HELP                1#define LONG_HELP                 2/* Long options */static const struct option longopts[] ={    /*  name,               has_arg,    flag,   val */    /* General/common options */    {   "help",             0,          0,      'h' },    {   "longhelp",         0,          0,      'H' },    {   "version",          0,          0,      'v' },    /* Audio options */    {   "noaudio",          0,          0,      OPT_NOAUDIO },    {   "aout",             1,          0,      OPT_AOUT },    {   "stereo",           0,          0,      OPT_STEREO },    {   "mono",             0,          0,      OPT_MONO },    /* Video options */    {   "novideo",          0,          0,      OPT_NOVIDEO },    {   "vout",             1,          0,      OPT_VOUT },    {   "display",          1,          0,      OPT_DISPLAY },    {   "width",            1,          0,      OPT_WIDTH },    {   "height",           1,          0,      OPT_HEIGHT },    {   "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 },    {   "port",             1,          0,      OPT_PORT },    {   0,                  0,          0,      0 }};/* Short options */static const char *psz_shortopts = "hHvga:s:c:";/***************************************************************************** * Global variable program_data - this is the one and only, see main.h *****************************************************************************/main_t *p_main;/***************************************************************************** * Local prototypes *****************************************************************************/static void SetDefaultConfiguration ( void );static int  GetConfiguration        ( int i_argc, char *ppsz_argv[], char *ppsz_env[] );static void Usage                   ( int i_fashion );static void Version                 ( void );static void InitSignalHandler       ( void );static void SignalHandler           ( int i_signal );#ifdef HAVE_MMXstatic int  TestMMX                 ( void );#endif/***************************************************************************** * main: parse command line, start interface and spawn threads ***************************************************************************** * Steps during program execution are: *      -configuration parsing and messages interface initialization *      -openning 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. *****************************************************************************/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     */#ifdef HAVE_MMX    if( !TestMMX() )    {        fprintf( stderr, "Sorry, this program needs an MMX processor. Please run the non-MMX version.\n" );        return( 1 );    }#endif    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 );    }    if( GetConfiguration( i_argc, ppsz_argv, ppsz_env ) )  /* parse cmd line */    {        intf_MsgDestroy();        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 = malloc( sizeof(int) );        p_playlist[ 0 ] = "-";        i_list_index = 1;    }    intf_MsgImm( COPYRIGHT_MESSAGE "\n" );          /* print welcome message */    /*     * Initialize shared resources and libraries     */    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" );        main_data.b_vlans = 0;    }    /*     * Open audio device and start aout thread     */    if( main_data.b_audio )    {        main_data.p_aout = aout_CreateThread( NULL );        if( main_data.p_aout == NULL )        {            /* On error during audio initialization, switch of audio */            intf_Msg( "Audio initialization failed : audio is deactivated\n" );            main_data.b_audio = 0;        }    }    /*     * Run interface     */    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 );    }    /*     * Close audio device     */    if( main_data.b_audio )    {        aout_DestroyThread( main_data.p_aout, NULL );    }    /*     * Free shared resources and libraries     */    if( main_data.b_vlans )    {        input_VlanDestroy();    }    /*     * System specific cleaning code     */#ifdef SYS_BEOS    beos_Clean();#endif    /*     * Terminate messages interface and program     */    intf_Msg( "Program terminated.\n" );    intf_MsgDestroy();    return( 0 );}/***************************************************************************** * main_GetIntVariable: get the int value of an environment variable ***************************************************************************** * This function is used to read some default parameters in modules. *****************************************************************************/int main_GetIntVariable( char *psz_name, int i_default ){    char *      psz_env;                                /* environment value */    char *      psz_end;                             /* end of parsing index */    long int    i_value;                                            /* value */    psz_env = getenv( psz_name );    if( psz_env )    {        i_value = strtol( psz_env, &psz_end, 0 );        if( (*psz_env != '\0') && (*psz_end == '\0') )        {            return( i_value );        }    }    return( i_default );}/***************************************************************************** * main_GetPszVariable: get the string value of an environment variable ***************************************************************************** * This function is used to read some default parameters in modules. *****************************************************************************/char * main_GetPszVariable( char *psz_name, char *psz_default ){    char *psz_env;    psz_env = getenv( psz_name );    if( psz_env )    {        return( psz_env );    }    return( psz_default );}/***************************************************************************** * main_PutPszVariable: set the string value of an environment variable ***************************************************************************** * This function is used to set some default parameters in modules. The use of * this function will cause some memory leak: since some systems use the pointer * passed to putenv to store the environment string, it can't be freed. *****************************************************************************/void main_PutPszVariable( char *psz_name, char *psz_value ){    char *psz_env;    psz_env = malloc( strlen(psz_name) + strlen(psz_value) + 2 );    if( psz_env == NULL )    {        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) );        }    }}/***************************************************************************** * main_PutIntVariable: set the integer value of an environment variable ***************************************************************************** * This function is used to set some default parameters in modules. The use of * this function will cause some memory leak: since some systems use the pointer * passed to putenv to store the environment string, it can't be freed. *****************************************************************************/void main_PutIntVariable( char *psz_name, int i_value ){    char psz_value[ 256 ];                               /* buffer for value */    sprintf( psz_value, "%d", i_value );    main_PutPszVariable( psz_name, psz_value );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -