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

📄 vlmshell.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 4 页
字号:
        psz_buf[psz_temp - psz_command] = '\0';        Unescape (psz_buf, psz_buf);        i_command++;        psz_buf += psz_temp - psz_command + 1;        psz_command = psz_temp;        assert (buf + sizeof (buf) >= psz_buf);    }    /*     * And then Interpret it     */#define IF_EXECUTE( name, check, cmd ) if( !strcmp(ppsz_command[0], name ) ) { if( (check) ) goto syntax_error;  if( (cmd) ) goto error; goto success; }    if( i_command == 0 )    {        p_message = vlm_MessageNew( "", vlm_NULL );        goto success;    }    else IF_EXECUTE( "del",     (i_command != 2),   ExecuteDel(p_vlm, ppsz_command[1], &p_message) )    else IF_EXECUTE( "show",    (i_command > 2),    ExecuteShow(p_vlm, i_command > 1 ? ppsz_command[1] : NULL, &p_message) )    else IF_EXECUTE( "help",    (i_command != 1),   ExecuteHelp( &p_message ) )    else IF_EXECUTE( "control", (i_command < 3),    ExecuteControl(p_vlm, ppsz_command[1], i_command - 2, &ppsz_command[2], &p_message) )    else IF_EXECUTE( "save",    (i_command != 2),   ExecuteSave(p_vlm, ppsz_command[1], &p_message) )    else IF_EXECUTE( "export",  (i_command != 1),   ExecuteExport(p_vlm, &p_message) )    else IF_EXECUTE( "load",    (i_command != 2),   ExecuteLoad(p_vlm, ppsz_command[1], &p_message) )    else IF_EXECUTE( "new",     (i_command < 3),    ExecuteNew(p_vlm, ppsz_command[1], ppsz_command[2], i_command-3, &ppsz_command[3], &p_message) )    else IF_EXECUTE( "setup",   (i_command < 2),    ExecuteSetup(p_vlm, ppsz_command[1], i_command-2, &ppsz_command[2], &p_message) )    else    {        p_message = vlm_MessageNew( ppsz_command[0], "Unknown command" );        goto error;    }#undef IF_EXECUTEsuccess:    *pp_message = p_message;    return VLC_SUCCESS;syntax_error:    return ExecuteSyntaxError( ppsz_command[0], pp_message );error:    *pp_message = p_message;    return VLC_EGENERIC;}/***************************************************************************** * Media handling *****************************************************************************/vlm_media_sys_t *vlm_MediaSearch( vlm_t *vlm, const char *psz_name ){    int i;    for( i = 0; i < vlm->i_media; i++ )    {        if( strcmp( psz_name, vlm->media[i]->cfg.psz_name ) == 0 )            return vlm->media[i];    }    return NULL;}/***************************************************************************** * Schedule handling *****************************************************************************/static vlm_schedule_sys_t *vlm_ScheduleNew( vlm_t *vlm, const char *psz_name ){    if( !psz_name )        return NULL;    vlm_schedule_sys_t *p_sched = malloc( sizeof( vlm_schedule_sys_t ) );    if( !p_sched )        return NULL;    p_sched->psz_name = strdup( psz_name );    p_sched->b_enabled = false;    p_sched->i_command = 0;    p_sched->command = NULL;    p_sched->i_date = 0;    p_sched->i_period = 0;    p_sched->i_repeat = -1;    TAB_APPEND( vlm->i_schedule, vlm->schedule, p_sched );    return p_sched;}/* for now, simple delete. After, del with options (last arg) */void vlm_ScheduleDelete( vlm_t *vlm, vlm_schedule_sys_t *sched ){    if( sched == NULL ) return;    TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched );    if( vlm->i_schedule == 0 ) free( vlm->schedule );    free( sched->psz_name );    while( sched->i_command )    {        char *psz_cmd = sched->command[0];        TAB_REMOVE( sched->i_command, sched->command, psz_cmd );        free( psz_cmd );    }    free( sched );}static vlm_schedule_sys_t *vlm_ScheduleSearch( vlm_t *vlm, const char *psz_name ){    int i;    for( i = 0; i < vlm->i_schedule; i++ )    {        if( strcmp( psz_name, vlm->schedule[i]->psz_name ) == 0 )        {            return vlm->schedule[i];        }    }    return NULL;}/* Ok, setup schedule command will be able to support only one (argument value) at a time  */static int vlm_ScheduleSetup( vlm_schedule_sys_t *schedule, const char *psz_cmd,                       const char *psz_value ){    if( !strcmp( psz_cmd, "enabled" ) )    {        schedule->b_enabled = true;    }    else if( !strcmp( psz_cmd, "disabled" ) )    {        schedule->b_enabled = false;    }    else if( !strcmp( psz_cmd, "date" ) )    {        struct tm time;        const char *p;        time_t date;        time.tm_sec = 0;         /* seconds */        time.tm_min = 0;         /* minutes */        time.tm_hour = 0;        /* hours */        time.tm_mday = 0;        /* day of the month */        time.tm_mon = 0;         /* month */        time.tm_year = 0;        /* year */        time.tm_wday = 0;        /* day of the week */        time.tm_yday = 0;        /* day in the year */        time.tm_isdst = -1;       /* daylight saving time */        /* date should be year/month/day-hour:minutes:seconds */        p = strchr( psz_value, '-' );        if( !strcmp( psz_value, "now" ) )        {            schedule->i_date = 0;        }        else if(p == NULL)        {            return 1;        }        else        {            unsigned i,j,k;            switch( sscanf( p + 1, "%u:%u:%u", &i, &j, &k ) )            {                case 1:                    time.tm_sec = i;                    break;                case 2:                    time.tm_min = i;                    time.tm_sec = j;                    break;                case 3:                    time.tm_hour = i;                    time.tm_min = j;                    time.tm_sec = k;                    break;                default:                    return 1;            }            switch( sscanf( psz_value, "%d/%d/%d", &i, &j, &k ) )            {                case 1:                    time.tm_mday = i;                    break;                case 2:                    time.tm_mon = i - 1;                    time.tm_mday = j;                    break;                case 3:                    time.tm_year = i - 1900;                    time.tm_mon = j - 1;                    time.tm_mday = k;                    break;                default:                    return 1;            }            date = mktime( &time );            schedule->i_date = ((mtime_t) date) * 1000000;        }    }    else if( !strcmp( psz_cmd, "period" ) )    {        struct tm time;        const char *p;        const char *psz_time = NULL, *psz_date = NULL;        time_t date;        unsigned i,j,k;        /* First, if date or period are modified, repeat should be equal to -1 */        schedule->i_repeat = -1;        time.tm_sec = 0;         /* seconds */        time.tm_min = 0;         /* minutes */        time.tm_hour = 0;        /* hours */        time.tm_mday = 0;        /* day of the month */        time.tm_mon = 0;         /* month */        time.tm_year = 0;        /* year */        time.tm_wday = 0;        /* day of the week */        time.tm_yday = 0;        /* day in the year */        time.tm_isdst = -1;       /* daylight saving time */        /* date should be year/month/day-hour:minutes:seconds */        p = strchr( psz_value, '-' );        if( p )        {            psz_date = psz_value;            psz_time = p + 1;        }        else        {            psz_time = psz_value;        }        switch( sscanf( psz_time, "%u:%u:%u", &i, &j, &k ) )        {            case 1:                time.tm_sec = i;                break;            case 2:                time.tm_min = i;                time.tm_sec = j;                break;            case 3:                time.tm_hour = i;                time.tm_min = j;                time.tm_sec = k;                break;            default:                return 1;        }        if( psz_date )        {            switch( sscanf( psz_date, "%u/%u/%u", &i, &j, &k ) )            {                case 1:                    time.tm_mday = i;                    break;                case 2:                    time.tm_mon = i;                    time.tm_mday = j;                    break;                case 3:                    time.tm_year = i;                    time.tm_mon = j;                    time.tm_mday = k;                    break;                default:                    return 1;            }        }        /* ok, that's stupid... who is going to schedule streams every 42 years ? */        date = (((( time.tm_year * 12 + time.tm_mon ) * 30 + time.tm_mday ) * 24 + time.tm_hour ) * 60 + time.tm_min ) * 60 + time.tm_sec ;        schedule->i_period = ((mtime_t) date) * 1000000;    }    else if( !strcmp( psz_cmd, "repeat" ) )    {        int i;        if( sscanf( psz_value, "%d", &i ) == 1 )        {            schedule->i_repeat = i;        }        else        {            return 1;        }    }    else if( !strcmp( psz_cmd, "append" ) )    {        char *command = strdup( psz_value );        TAB_APPEND( schedule->i_command, schedule->command, command );    }    else    {        return 1;    }    return 0;}/***************************************************************************** * Message handling functions *****************************************************************************/vlm_message_t *vlm_MessageNew( const char *psz_name,                               const char *psz_format, ... ){    vlm_message_t *p_message;    va_list args;    if( !psz_name ) return NULL;    p_message = malloc( sizeof(vlm_message_t) );    if( !p_message)    {        return NULL;    }    p_message->psz_value = 0;    if( psz_format )    {        va_start( args, psz_format );        if( vasprintf( &p_message->psz_value, psz_format, args ) == -1 )        {            va_end( args );            free( p_message );            return NULL;        }        va_end( args );    }    p_message->psz_name = strdup( psz_name );    p_message->i_child = 0;    p_message->child = NULL;    return p_message;}void vlm_MessageDelete( vlm_message_t *p_message ){    free( p_message->psz_name );    free( p_message->psz_value );    while( p_message->i_child-- )        vlm_MessageDelete( p_message->child[p_message->i_child] );    free( p_message->child );    free( p_message );}/* Add a child */vlm_message_t *vlm_MessageAdd( vlm_message_t *p_message,                               vlm_message_t *p_child ){    if( p_message == NULL ) return NULL;    if( p_child )    {        TAB_APPEND( p_message->i_child, p_message->child, p_child );    }    return p_child;}/***************************************************************************** * Misc utility functions *****************************************************************************/static vlm_message_t *vlm_ShowMedia( vlm_media_sys_t *p_media ){    vlm_media_t *p_cfg = &p_media->cfg;    vlm_message_t *p_msg;    vlm_message_t *p_msg_sub;    int i;    p_msg = vlm_MessageNew( p_cfg->psz_name, vlm_NULL );    vlm_MessageAdd( p_msg,                    vlm_MessageNew( "type", p_cfg->b_vod ? "vod" : "broadcast" ) );    vlm_MessageAdd( p_msg,                    vlm_MessageNew( "enabled", p_cfg->b_enabled ? "yes" : "no" ) );    if( p_cfg->b_vod )        vlm_MessageAdd( p_msg,                        vlm_MessageNew( "mux", p_cfg->vod.psz_mux ) );    else        vlm_MessageAdd( p_msg,                        vlm_MessageNew( "loop", p_cfg->broadcast.b_loop ? "yes" : "no" ) );    p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "inputs", vlm_NULL ) );    for( i = 0; i < p_cfg->i_input; i++ )    {        char *psz_tmp;        if( asprintf( &psz_tmp, "%d", i+1 ) != -1 )        {            vlm_MessageAdd( p_msg_sub,                            vlm_MessageNew( psz_tmp, p_cfg->ppsz_input[i] ) );            free( psz_tmp );        }    }    vlm_MessageAdd( p_msg,                    vlm_MessageNew( "output", p_cfg->psz_output ? p_cfg->psz_output : "" ) );    p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "options", vlm_NULL ) );    for( i = 0; i < p_cfg->i_option; i++ )        vlm_MessageAdd( p_msg_sub, vlm_MessageNew( p_cfg->ppsz_option[i], vlm_NULL ) );    p_msg_sub = vlm_MessageAdd( p_msg, vlm_MessageNew( "instances", vlm_NULL ) );    for( i = 0; i < p_media->i_instance; i++ )    {        vlm_media_instance_sys_t *p_instance = p_media->instance[i];        vlc_value_t val;        vlm_message_t *p_msg_instance;        char *psz_tmp;        val.i_int = END_S;        if( p_instance->p_input )            var_Get( p_instance->p_input, "state", &val );        p_msg_instance = vlm_MessageAdd( p_msg_sub, vlm_MessageNew( "instance" , vlm_NULL ) );        vlm_MessageAdd( p_msg_instance,                        vlm_MessageNew( "name" , p_instance->psz_name ? p_instance->psz_name : "default" ) );        vlm_MessageAdd( p_msg_instance,                        vlm_MessageNew( "state",                            val.i_int == PLAYING_S ? "playing" :                            val.i_int == PAUSE_S ? "paused" :                            "stopped" ) );        /* FIXME should not do that this way */        if( p_instance->p_input )        {#define APPEND_INPUT_INFO( a, format, type ) \            if( asprintf( &psz_tmp, format, \                      var_Get ## type( p_instance->p_input, a ) ) != -1 ) \            { \                vlm_MessageAdd( p_msg_instance, vlm_MessageNew( a, \                                psz_tmp ) ); \                free( psz_tmp ); \            }            APPEND_INPUT_INFO( "position", "%f", Float );            APPEND_INPUT_INFO( "time", "%"PRIi64, Time );            APPEND_INPUT_INFO( "length", "%"PRIi64, Time );            APPEND_INPUT_INFO( "rate", "%d", Integer );            APPEND_INPUT_INFO( "title", "%d", Integer );            APPEND_INPUT_INFO( "chapter", "%d", Integer );            APPEND_INPUT_INFO( "seekable", "%d", Bool );        }#undef APPEND_INPUT_INFO        if( asprintf( &psz_tmp, "%d", p_instance->i_index + 1 ) != -1 )

⌨️ 快捷键说明

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