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

📄 vlmshell.c

📁 VLC Player Source Code
💻 C
📖 第 1 页 / 共 4 页
字号:
            }        }        else        {            i_result = VLC_EGENERIC;        }    }    else if( !strcmp( psz_control, "rewind" ) )    {        if( psz_argument )        {            const double d_scale = us_atof( psz_argument );            double d_position;            vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );            d_position -= (d_scale / 1000.0);            if( d_position < 0.0 )                d_position = 0.0;            i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );        }        else        {            i_result = VLC_EGENERIC;        }    }    else if( !strcmp( psz_control, "forward" ) )    {        if( psz_argument )        {            const double d_scale = us_atof( psz_argument );            double d_position;            vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, &d_position );            d_position += (d_scale / 1000.0);            if( d_position > 1.0 )                d_position = 1.0;            i_result = vlm_ControlInternal( p_vlm, VLM_SET_MEDIA_INSTANCE_POSITION, p_media->cfg.id, psz_instance, d_position );        }        else        {            i_result = VLC_EGENERIC;        }    }    else if( !strcmp( psz_control, "stop" ) )    {        i_result = vlm_ControlInternal( p_vlm, VLM_STOP_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );    }    else if( !strcmp( psz_control, "pause" ) )    {        i_result = vlm_ControlInternal( p_vlm, VLM_PAUSE_MEDIA_INSTANCE, p_media->cfg.id, psz_instance );    }    else    {        i_result = VLC_EGENERIC;    }    if( i_result )    {        *pp_status = vlm_MessageNew( "control", "unknown error" );        return VLC_SUCCESS;    }    *pp_status = vlm_MessageNew( "control", vlm_NULL );    return VLC_SUCCESS;}static int ExecuteExport( vlm_t *p_vlm, vlm_message_t **pp_status ){    char *psz_export = Save( p_vlm );    *pp_status = vlm_MessageNew( "export", psz_export );    free( psz_export );    return VLC_SUCCESS;}static int ExecuteSave( vlm_t *p_vlm, const char *psz_file, vlm_message_t **pp_status ){    FILE *f = utf8_fopen( psz_file, "wt" );    char *psz_save = NULL;    if( !f )        goto error;    psz_save = Save( p_vlm );    if( psz_save == NULL )        goto error;    if( fputs( psz_save, f ) == EOF )        goto error;;    if( fclose( f ) )    {        f = NULL;        goto error;    }    free( psz_save );    *pp_status = vlm_MessageNew( "save", vlm_NULL );    return VLC_SUCCESS;error:    free( psz_save );    if( f )         fclose( f );    *pp_status = vlm_MessageNew( "save", "Unable to save to file");    return VLC_EGENERIC;}static int ExecuteLoad( vlm_t *p_vlm, const char *psz_url, vlm_message_t **pp_status ){    stream_t *p_stream = stream_UrlNew( p_vlm, psz_url );    int64_t i_size;    char *psz_buffer;    if( !p_stream )    {        *pp_status = vlm_MessageNew( "load", "Unable to load from file" );        return VLC_EGENERIC;    }    /* FIXME needed ? */    if( stream_Seek( p_stream, 0 ) != 0 )    {        stream_Delete( p_stream );        *pp_status = vlm_MessageNew( "load", "Read file error" );        return VLC_EGENERIC;    }    i_size = stream_Size( p_stream );    psz_buffer = malloc( i_size + 1 );    if( !psz_buffer )    {        stream_Delete( p_stream );        *pp_status = vlm_MessageNew( "load", "Read file error" );        return VLC_EGENERIC;    }    stream_Read( p_stream, psz_buffer, i_size );    psz_buffer[i_size] = '\0';    stream_Delete( p_stream );    if( Load( p_vlm, psz_buffer ) )    {        free( psz_buffer );        *pp_status = vlm_MessageNew( "load", "Error while loading file" );        return VLC_EGENERIC;    }    free( psz_buffer );    *pp_status = vlm_MessageNew( "load", vlm_NULL );    return VLC_SUCCESS;}static int ExecuteScheduleProperty( vlm_t *p_vlm, vlm_schedule_sys_t *p_schedule, bool b_new,                                    const int i_property, char *ppsz_property[], vlm_message_t **pp_status ){    const char *psz_cmd = b_new ? "new" : "setup";    int i;    for( i = 0; i < i_property; i++ )    {        if( !strcmp( ppsz_property[i], "enabled" ) ||            !strcmp( ppsz_property[i], "disabled" ) )        {            if ( vlm_ScheduleSetup( p_schedule, ppsz_property[i], NULL ) )                goto error;        }        else if( !strcmp( ppsz_property[i], "append" ) )        {            char *psz_line;            int j;            /* Beware: everything behind append is considered as             * command line */            if( ++i >= i_property )                break;            psz_line = strdup( ppsz_property[i] );            for( j = i+1; j < i_property; j++ )            {                psz_line = realloc( psz_line, strlen(psz_line) + strlen(ppsz_property[j]) + 1 + 1 );                strcat( psz_line, " " );                strcat( psz_line, ppsz_property[j] );            }            if( vlm_ScheduleSetup( p_schedule, "append", psz_line ) )                goto error;            break;        }        else        {            if( i + 1 >= i_property )            {                if( b_new )                    vlm_ScheduleDelete( p_vlm, p_schedule );                return ExecuteSyntaxError( psz_cmd, pp_status );            }            if( vlm_ScheduleSetup( p_schedule, ppsz_property[i], ppsz_property[i+1] ) )                goto error;            i++;        }    }    *pp_status = vlm_MessageNew( psz_cmd, vlm_NULL );    return VLC_SUCCESS;error:    *pp_status = vlm_MessageNew( psz_cmd, "Error while setting the property '%s' to the schedule",                                 ppsz_property[i] );    return VLC_EGENERIC;}static int ExecuteMediaProperty( vlm_t *p_vlm, int64_t id, bool b_new,                                 const int i_property, char *ppsz_property[], vlm_message_t **pp_status ){    const char *psz_cmd = b_new ? "new" : "setup";    vlm_media_t *p_cfg = NULL;    int i_result;    int i;#undef ERROR#undef MISSING#define ERROR( txt ) do { *pp_status = vlm_MessageNew( psz_cmd, txt); goto error; } while(0)    if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA, id, &p_cfg ) )        ERROR( "unknown media" );#define MISSING(cmd) do { if( !psz_value ) ERROR( "missing argument for " cmd ); } while(0)    for( i = 0; i < i_property; i++ )    {        const char *psz_option = ppsz_property[i];        const char *psz_value = i+1 < i_property ? ppsz_property[i+1] :  NULL;        if( !strcmp( psz_option, "enabled" ) )        {            p_cfg->b_enabled = true;        }        else if( !strcmp( psz_option, "disabled" ) )        {            p_cfg->b_enabled = false;        }        else if( !strcmp( psz_option, "input" ) )        {            MISSING( "input" );            TAB_APPEND( p_cfg->i_input, p_cfg->ppsz_input, strdup(psz_value) );            i++;        }        else if( !strcmp( psz_option, "inputdel" ) && psz_value && !strcmp( psz_value, "all" ) )        {            while( p_cfg->i_input > 0 )                TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[0] );            i++;        }        else if( !strcmp( psz_option, "inputdel" ) )        {            int j;            MISSING( "inputdel" );            for( j = 0; j < p_cfg->i_input; j++ )            {                if( !strcmp( p_cfg->ppsz_input[j], psz_value ) )                {                    TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[j] );                    break;                }            }            i++;        }        else if( !strcmp( psz_option, "inputdeln" ) )        {            int i_index;            MISSING( "inputdeln" );             i_index = atoi( psz_value );            if( i_index > 0 && i_index <= p_cfg->i_input )                TAB_REMOVE( p_cfg->i_input, p_cfg->ppsz_input, p_cfg->ppsz_input[i_index-1] );            i++;        }        else if( !strcmp( psz_option, "output" ) )        {            MISSING( "output" );            free( p_cfg->psz_output );            p_cfg->psz_output = *psz_value ? strdup( psz_value ) : NULL;            i++;        }        else if( !strcmp( psz_option, "option" ) )        {            MISSING( "option" );            TAB_APPEND( p_cfg->i_option, p_cfg->ppsz_option, strdup( psz_value ) );            i++;        }        else if( !strcmp( psz_option, "loop" ) )        {            if( p_cfg->b_vod )                ERROR( "invalid loop option for vod" );            p_cfg->broadcast.b_loop = true;        }        else if( !strcmp( psz_option, "unloop" ) )        {            if( p_cfg->b_vod )                ERROR( "invalid unloop option for vod" );            p_cfg->broadcast.b_loop = false;        }        else if( !strcmp( psz_option, "mux" ) )        {            MISSING( "mux" );            if( !p_cfg->b_vod )                ERROR( "invalid mux option for broadcast" );            free( p_cfg->vod.psz_mux );            p_cfg->vod.psz_mux = *psz_value ? strdup( psz_value ) : NULL;            i++;        }        else        {            fprintf( stderr, "PROP: name=%s unknown\n", psz_option );            ERROR( "Wrong command syntax" );        }    }#undef MISSING#undef ERROR    /* */    i_result = vlm_ControlInternal( p_vlm, VLM_CHANGE_MEDIA, p_cfg );    vlm_media_Delete( p_cfg );    *pp_status = vlm_MessageNew( psz_cmd, vlm_NULL );    return i_result;error:    if( p_cfg )    {        if( b_new )            vlm_ControlInternal( p_vlm, VLM_DEL_MEDIA, p_cfg->id );        vlm_media_Delete( p_cfg );    }    return VLC_EGENERIC;}static int ExecuteNew( vlm_t *p_vlm, const char *psz_name, const char *psz_type, const int i_property, char *ppsz_property[], vlm_message_t **pp_status ){    /* Check name */    if( !strcmp( psz_name, "all" ) || !strcmp( psz_name, "media" ) || !strcmp( psz_name, "schedule" ) )    {        *pp_status = vlm_MessageNew( "new", "\"all\", \"media\" and \"schedule\" are reserved names" );        return VLC_EGENERIC;    }    if( ExecuteIsMedia( p_vlm, psz_name ) || ExecuteIsSchedule( p_vlm, psz_name ) )    {        *pp_status = vlm_MessageNew( "new", "%s: Name already in use", psz_name );        return VLC_EGENERIC;    }    /* */    if( !strcmp( psz_type, "schedule" ) )    {        vlm_schedule_sys_t *p_schedule = vlm_ScheduleNew( p_vlm, psz_name );        if( !p_schedule )        {            *pp_status = vlm_MessageNew( "new", "could not create schedule" );            return VLC_EGENERIC;        }        return ExecuteScheduleProperty( p_vlm, p_schedule, true, i_property, ppsz_property, pp_status );    }    else if( !strcmp( psz_type, "vod" ) || !strcmp( psz_type, "broadcast" ) )    {        vlm_media_t cfg;        int64_t id;        vlm_media_Init( &cfg );        cfg.psz_name = strdup( psz_name );        cfg.b_vod = !strcmp( psz_type, "vod" );        if( vlm_ControlInternal( p_vlm, VLM_ADD_MEDIA, &cfg, &id ) )        {            vlm_media_Clean( &cfg );            *pp_status = vlm_MessageNew( "new", "could not create media" );            return VLC_EGENERIC;        }        vlm_media_Clean( &cfg );        return ExecuteMediaProperty( p_vlm, id, true, i_property, ppsz_property, pp_status );    }    else    {        *pp_status = vlm_MessageNew( "new", "%s: Choose between vod, broadcast or schedule", psz_type );        return VLC_EGENERIC;    }}static int ExecuteSetup( vlm_t *p_vlm, const char *psz_name, const int i_property, char *ppsz_property[], vlm_message_t **pp_status ){    if( ExecuteIsSchedule( p_vlm, psz_name ) )    {        vlm_schedule_sys_t *p_schedule = vlm_ScheduleSearch( p_vlm, psz_name );        return ExecuteScheduleProperty( p_vlm, p_schedule, false, i_property, ppsz_property, pp_status );    }    else if( ExecuteIsMedia( p_vlm, psz_name ) )    {        int64_t id;        if( vlm_ControlInternal( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) )            goto error;        return ExecuteMediaProperty( p_vlm, id, false, i_property, ppsz_property, pp_status );    }error:    *pp_status = vlm_MessageNew( "setup", "%s unknown", psz_name );    return VLC_EGENERIC;}int ExecuteCommand( vlm_t *p_vlm, const char *psz_command,                           vlm_message_t **pp_message ){    size_t i_command = 0;    char buf[strlen (psz_command) + 1], *psz_buf = buf;    char *ppsz_command[3+sizeof (buf) / 2];    vlm_message_t *p_message = NULL;    /* First, parse the line and cut it */    while( *psz_command != '\0' )    {        const char *psz_temp;        if(isspace (*psz_command))        {            psz_command++;            continue;        }        /* support for comments */        if( i_command == 0 && *psz_command == '#')        {            p_message = vlm_MessageNew( "", vlm_NULL );            goto success;        }        psz_temp = FindCommandEnd( psz_command );        if( psz_temp == NULL )        {            p_message = vlm_MessageNew( "Incomplete command", psz_command );            goto error;        }        assert (i_command < (sizeof (ppsz_command) / sizeof (ppsz_command[0])));        ppsz_command[i_command] = psz_buf;        memcpy (psz_buf, psz_command, psz_temp - psz_command);

⌨️ 快捷键说明

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