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

📄 vlm.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
        p_message = vlm_MessageNew( ppsz_command[0], NULL );        goto success;    }success:    for( i = 0 ; i < i_command ; i++ ) FREE( ppsz_command[i] );    FREE( ppsz_command );    *pp_message = p_message;    return VLC_SUCCESS;syntax_error:    p_message = vlm_MessageNew( ppsz_command[0], "Wrong command syntax" );error:    for( i = 0 ; i < i_command ; i++ ) FREE( ppsz_command[i] );    FREE( ppsz_command );    *pp_message = p_message;    return VLC_EGENERIC;}vlm_media_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]->psz_name ) == 0 )        {            return vlm->media[i];        }    }    return NULL;}/***************************************************************************** * Media handling *****************************************************************************/static vlm_media_instance_t *vlm_MediaInstanceSearch( vlm_t *vlm, vlm_media_t *media,                         const char *psz_name ){    int i;    for( i = 0; i < media->i_instance; i++ )    {        if( ( !psz_name && !media->instance[i]->psz_name ) ||            ( psz_name && media->instance[i]->psz_name &&              !strcmp( psz_name, media->instance[i]->psz_name ) ) )        {            return media->instance[i];        }    }    return NULL;}vlm_media_t *vlm_MediaNew( vlm_t *vlm, const char *psz_name, int i_type ){    vlm_media_t *media = malloc( sizeof( vlm_media_t ) );    if( !media )    {        msg_Err( vlm, "out of memory" );        return NULL;    }    /* Check if we need to load the VOD server */    if( i_type == VOD_TYPE && !vlm->i_vod )    {        vlm->vod = vlc_object_create( vlm, VLC_OBJECT_VOD );        vlc_object_attach( vlm->vod, vlm );        vlm->vod->p_module = module_Need( vlm->vod, "vod server", 0, 0 );        if( !vlm->vod->p_module )        {            msg_Err( vlm, "cannot find vod server" );            vlc_object_detach( vlm->vod );            vlc_object_destroy( vlm->vod );            vlm->vod = 0;            free( media );            return NULL;        }        vlm->vod->p_data = vlm;        vlm->vod->pf_media_control = vlm_MediaVodControl;    }    if( i_type == VOD_TYPE ) vlm->i_vod++;    media->psz_name = strdup( psz_name );    media->b_enabled = VLC_FALSE;    media->b_loop = VLC_FALSE;    media->vod_media = NULL;    media->psz_vod_output = NULL;    media->psz_mux = NULL;    media->i_input = 0;    media->input = NULL;    media->psz_output = NULL;    media->i_option = 0;    media->option = NULL;    media->i_type = i_type;    media->i_instance = 0;    media->instance = NULL;    vlc_input_item_Init( VLC_OBJECT(vlm), &media->item );    TAB_APPEND( vlm->i_media, vlm->media, media );    return media;}/* for now, simple delete. After, del with options (last arg) */void vlm_MediaDelete( vlm_t *vlm, vlm_media_t *media, const char *psz_name ){    if( media == NULL ) return;    while( media->i_instance )    {        vlm_media_instance_t *p_instance = media->instance[0];        vlm_MediaControl( vlm, media, p_instance->psz_name, "stop", 0 );    }    TAB_REMOVE( vlm->i_media, vlm->media, media );    if( media->i_type == VOD_TYPE )    {        vlm_MediaSetup( vlm, media, "disabled", 0 );        vlm->i_vod--;    }    /* Check if we need to unload the VOD server */    if( media->i_type == VOD_TYPE && !vlm->i_vod )    {        module_Unneed( vlm->vod, vlm->vod->p_module );        vlc_object_detach( vlm->vod );        vlc_object_destroy( vlm->vod );        vlm->vod = 0;    }    if( vlm->i_media == 0 && vlm->media ) free( vlm->media );    free( media->psz_name );    while( media->i_input-- ) free( media->input[media->i_input] );    if( media->input ) free( media->input );    if( media->psz_output ) free( media->psz_output );    if( media->psz_mux ) free( media->psz_mux );    while( media->i_option-- ) free( media->option[media->i_option] );    if( media->option ) free( media->option );    vlc_input_item_Clean( &media->item );    free( media );}int vlm_MediaSetup( vlm_t *vlm, vlm_media_t *media, const char *psz_cmd,                    const char *psz_value ){    if( !psz_cmd) return VLC_EGENERIC;    if( !strcmp( psz_cmd, "loop" ) )    {        media->b_loop = VLC_TRUE;    }    else if( !strcmp( psz_cmd, "unloop" ) )    {        media->b_loop = VLC_FALSE;    }    else if( !strcmp( psz_cmd, "enabled" ) )    {        media->b_enabled = VLC_TRUE;    }    else if( !strcmp( psz_cmd, "disabled" ) )    {        media->b_enabled = VLC_FALSE;    }    else if( !strcmp( psz_cmd, "mux" ) )    {        if( media->psz_mux ) free( media->psz_mux );        media->psz_mux = NULL;        if( psz_value ) media->psz_mux = strdup( psz_value );    }    else if( !strcmp( psz_cmd, "input" ) )    {        char *input;        input = strdup( psz_value );        TAB_APPEND( media->i_input, media->input, input );    }    else if( !strcmp( psz_cmd, "inputdel" ) && !strcmp( psz_value, "all" ) )    {        while( media->i_input > 0 )        {            TAB_REMOVE( media->i_input, media->input, media->input[0] );        }    }    else if( !strcmp( psz_cmd, "inputdel" ) )    {        char *input;        int i;        input = strdup( psz_value );        for( i = 0; i < media->i_input; i++ )        {            if( !strcmp( input, media->input[i] ) )            {                TAB_REMOVE( media->i_input, media->input, media->input[i] );                break;            }        }    }    else if( !strcmp( psz_cmd, "inputdeln" ) )    {        int index = atoi( psz_value );        if( index > 0 && index <= media->i_input )        {            TAB_REMOVE( media->i_input, media->input, media->input[index-1] );        }    }    else if( !strcmp( psz_cmd, "output" ) )    {        if( media->psz_output != NULL )        {            free( media->psz_output );        }        media->psz_output = strdup( psz_value );    }    else if( !strcmp( psz_cmd, "option" ) )    {        char *psz_option;        psz_option = strdup( psz_value );        TAB_APPEND( media->i_option, media->option, psz_option );    }    else    {        return VLC_EGENERIC;    }    /* Check if we need to create/delete a vod media */    if( media->i_type == VOD_TYPE )    {        if( !media->b_enabled && media->vod_media )        {            vlm->vod->pf_media_del( vlm->vod, media->vod_media );            media->vod_media = 0;        }        else if( media->b_enabled && !media->vod_media && media->i_input )        {            /* Pre-parse the input */            input_thread_t *p_input;            char *psz_output;            char *psz_header;            int i;            vlc_input_item_Clean( &media->item );            vlc_input_item_Init( VLC_OBJECT(vlm), &media->item );            if( media->psz_output )                asprintf( &psz_output, "%s:description", media->psz_output );            else                asprintf( &psz_output, "#description" );            media->item.psz_uri = strdup( media->input[0] );            media->item.ppsz_options = malloc( sizeof( char* ) );            asprintf( &media->item.ppsz_options[0], "sout=%s", psz_output);            media->item.i_options = 1;            for( i = 0; i < media->i_option; i++ )            {                media->item.i_options++;                media->item.ppsz_options =                    realloc( media->item.ppsz_options,                             media->item.i_options * sizeof( char* ) );                media->item.ppsz_options[ media->item.i_options - 1 ] =                    strdup( media->option[i] );            }            asprintf( &psz_header, _("Media: %s"), media->psz_name );            if( (p_input = input_CreateThread2( vlm, &media->item, psz_header                                              ) ) )            {                while( !p_input->b_eof && !p_input->b_error ) msleep( 100000 );                input_StopThread( p_input );                input_DestroyThread( p_input );                vlc_object_detach( p_input );                vlc_object_destroy( p_input );            }            free( psz_output );            free( psz_header );            if( media->psz_mux )            {                input_item_t item;                es_format_t es, *p_es = &es;                char fourcc[5];                sprintf( fourcc, "%4.4s", media->psz_mux );                fourcc[0] = tolower(fourcc[0]); fourcc[1] = tolower(fourcc[1]);                fourcc[2] = tolower(fourcc[2]); fourcc[3] = tolower(fourcc[3]);                item = media->item;                item.i_es = 1;                item.es = &p_es;                es_format_Init( &es, VIDEO_ES, *((int *)fourcc) );                media->vod_media =                  vlm->vod->pf_media_new( vlm->vod, media->psz_name, &item );                return VLC_SUCCESS;            }            media->vod_media =                vlm->vod->pf_media_new( vlm->vod, media->psz_name,                                        &media->item );        }    }    return VLC_SUCCESS;}int vlm_MediaControl( vlm_t *vlm, vlm_media_t *media, const char *psz_id,                      const char *psz_command, const char *psz_args ){    vlm_media_instance_t *p_instance;    int i;    char *psz_header;    p_instance = vlm_MediaInstanceSearch( vlm, media, psz_id );    if( !strcmp( psz_command, "play" ) )    {        if( !media->b_enabled || media->i_input == 0 ) return 0;        if( !p_instance )        {            p_instance = malloc( sizeof(vlm_media_instance_t) );            if( !p_instance ) return VLC_EGENERIC;            memset( p_instance, 0, sizeof(vlm_media_instance_t) );            vlc_input_item_Init( VLC_OBJECT(vlm), &p_instance->item );            p_instance->p_input = NULL;            if( ( media->psz_output != NULL ) || ( media->psz_vod_output != NULL ) )            {                p_instance->item.ppsz_options = malloc( sizeof( char* ) );                asprintf( &p_instance->item.ppsz_options[0], "sout=%s%s%s",                          media->psz_output ? media->psz_output : "",                          (media->psz_output && media->psz_vod_output) ?                          ":" : media->psz_vod_output ? "#" : "",                          media->psz_vod_output ? media->psz_vod_output : "" );                p_instance->item.i_options = 1;            }            for( i = 0; i < media->i_option; i++ )            {                p_instance->item.i_options++;                p_instance->item.ppsz_options =                    realloc( p_instance->item.ppsz_options,                             p_instance->item.i_options * sizeof( char* ) );                p_instance->item.ppsz_options[p_instance->item.i_options - 1] =                    strdup( media->option[i] );            }            p_instance->psz_name = psz_id ? strdup( psz_id ) : NULL;            TAB_APPEND( media->i_instance, media->instance, p_instance );        }        if( ( psz_args && sscanf(psz_args, "%d", &i) == 1 ) && ( i < media->i_input ) )        {            p_instance->i_index = i;        }        if( p_instance->item.psz_uri ) free( p_instance->item.psz_uri );        p_instance->item.psz_uri =            strdup( media->input[p_instance->i_index] );        if( p_instance->p_input )        {            input_StopThread( p_instance->p_input );            input_DestroyThread( p_instance->p_input );            vlc_object_detach( p_instance->p_input );            vlc_object_destroy( p_instance->p_input );        }        asprintf( &psz_header, _("Media: %s"), media->psz_name );        p_instance->p_input = input_CreateThread2( vlm, &p_instance->item,                                                   psz_header );        if( !p_instance->p_input )        {            TAB_REMOVE( media->i_instance, media->instance, p_instance );            vlc_input_item_Clean( &p_instance->item );            if( p_instance->psz_name ) free( p_instance->psz_name );        }        free( psz_header );        return VLC_SUCCESS;    }    if( !p_instance ) return VLC_EGENERIC;    if( !strcmp( psz_command, "seek" ) )    {        vlc_value_t val;        if( psz_args )        {            vlc_bool_t i_rel;            float f_value = i18n_atof( psz_args );            if( psz_args[0] == '+' || psz_args[0] == '-' )               i_rel = VLC_TRUE;            else               i_rel = VLC_FALSE;            if( strstr( psz_args, "ms" ) )            {               /* milliseconds */               int64_t i_msec =  1000 * (int64_t)atoi( psz_args );               if( i_rel )               {                  var_SetTime( p_instance->p_input, "time-offset", i_msec );               }

⌨️ 快捷键说明

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