📄 vlm.c
字号:
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; media->item.psz_uri = strdup( psz_name ); 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, 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, char *psz_cmd, 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; if( psz_value != NULL && strlen(psz_value) > 1 && ( psz_value[0] == '\'' || psz_value[0] == '\"' ) && ( psz_value[ strlen(psz_value) - 1 ] == '\'' || psz_value[ strlen(psz_value) - 1 ] == '\"' ) ) { input = malloc( strlen(psz_value) - 1 ); memcpy( input, psz_value + 1, strlen(psz_value) - 2 ); input[ strlen(psz_value) - 2 ] = '\0'; } else { 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; if( psz_value != NULL && strlen(psz_value) > 1 && ( psz_value[0] == '\'' || psz_value[0] == '\"' ) && ( psz_value[ strlen(psz_value) - 1 ] == '\'' || psz_value[ strlen(psz_value) - 1 ] == '\"' ) ) { input = malloc( strlen(psz_value) - 1 ); memcpy( input, psz_value + 1, strlen(psz_value) - 2 ); input[ strlen(psz_value) - 2 ] = '\0'; } else { 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; 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] ); } if( (p_input = input_CreateThread( vlm, &media->item ) ) ) { 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 ); 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, char *psz_id, char *psz_command, char *psz_args ){ vlm_media_instance_t *p_instance; int i; 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 ); } p_instance->p_input = input_CreateThread( vlm, &p_instance->item ); 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 ); } return VLC_SUCCESS; } if( !p_instance ) return VLC_EGENERIC; if( !strcmp( psz_command, "seek" ) ) { vlc_value_t val; float f_percentage; if( psz_args && sscanf( psz_args, "%f", &f_percentage ) == 1 ) { val.f_float = f_percentage / 100.0 ; var_Set( p_instance->p_input, "position", val ); return VLC_SUCCESS; } } else if( !strcmp( psz_command, "stop" ) ) { TAB_REMOVE( media->i_instance, media->instance, p_instance ); 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 ); } vlc_input_item_Clean( &p_instance->item ); if( p_instance->psz_name ) free( p_instance->psz_name ); free( p_instance ); return VLC_SUCCESS; } else if( !strcmp( psz_command, "pause" ) ) { vlc_value_t val; if( !p_instance->p_input ) return VLC_SUCCESS; var_Get( p_instance->p_input, "state", &val ); if( val.i_int == PAUSE_S ) val.i_int = PLAYING_S; else val.i_int = PAUSE_S; var_Set( p_instance->p_input, "state", val ); return VLC_SUCCESS; } return VLC_EGENERIC;}/***************************************************************************** * Schedule handling *****************************************************************************/static int64_t vlm_Date(){#ifdef WIN32 struct timeb tm; ftime( &tm ); return ((int64_t)tm.time) * 1000000 + ((int64_t)tm.millitm) * 1000;#else return mdate();#endif}vlm_schedule_t *vlm_ScheduleNew( vlm_t *vlm, char *psz_name ){ vlm_schedule_t *p_sched = malloc( sizeof( vlm_schedule_t ) ); if( !p_sched ) { return NULL; } if( !psz_name ) { return NULL; } p_sched->psz_name = strdup( psz_name ); p_sched->b_enabled = VLC_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_t *sched, char *psz_name ){ if( sched == NULL ) return; TAB_REMOVE( vlm->i_schedule, vlm->schedule, sched ); if( vlm->i_schedule == 0 && vlm->schedule ) free( vlm->schedule ); free( sched->psz_name ); while( sched->i_command-- ) free( sched->command[sched->i_command] ); free( sched );}static vlm_schedule_t *vlm_ScheduleSearch( vlm_t *vlm, char *psz_name ){ int i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -