📄 file.c
字号:
TAB_APPEND( p_sys->i_file, p_sys->file, p_file ); } psz_name = psz_parser; if( psz_name ) psz_name++; } } free( psz ); return VLC_SUCCESS;}/***************************************************************************** * Close: close the target *****************************************************************************/static void Close( vlc_object_t * p_this ){ access_t *p_access = (access_t*)p_this; access_sys_t *p_sys = p_access->p_sys; int i; close( p_sys->fd ); for( i = 0; i < p_sys->i_file; i++ ) { free( p_sys->file[i]->psz_name ); free( p_sys->file[i] ); } free( p_sys->file ); free( p_sys );}/***************************************************************************** * Read: standard read on a file descriptor. *****************************************************************************/static int Read( access_t *p_access, uint8_t *p_buffer, int i_len ){ access_sys_t *p_sys = p_access->p_sys; int i_ret;#if !defined(WIN32) && !defined(UNDER_CE) if( !p_sys->b_pace_control ) { if( !p_sys->b_kfir ) { /* Find if some data is available. This won't work under Windows. */ struct timeval timeout; fd_set fds; /* Initialize file descriptor set */ FD_ZERO( &fds ); FD_SET( p_sys->fd, &fds ); /* We'll wait 0.5 second if nothing happens */ timeout.tv_sec = 0; timeout.tv_usec = 500000; /* Find if some data is available */ while( (i_ret = select( p_sys->fd + 1, &fds, NULL, NULL, &timeout )) == 0 || (i_ret < 0 && errno == EINTR) ) { FD_ZERO( &fds ); FD_SET( p_sys->fd, &fds ); timeout.tv_sec = 0; timeout.tv_usec = 500000; if( p_access->b_die ) return 0; } if( i_ret < 0 ) { msg_Err( p_access, "select error (%s)", strerror(errno) ); return -1; } i_ret = read( p_sys->fd, p_buffer, i_len ); } else { /* b_kfir ; work around a buggy poll() driver implementation */ while ( (i_ret = read( p_sys->fd, p_buffer, i_len )) == 0 && !p_access->b_die ) { msleep( INPUT_ERROR_SLEEP ); } } } else#endif /* WIN32 || UNDER_CE */ { /* b_pace_control || WIN32 */ i_ret = read( p_sys->fd, p_buffer, i_len ); } if( i_ret < 0 ) { if( errno != EINTR && errno != EAGAIN ) msg_Err( p_access, "read failed (%s)", strerror(errno) ); /* Delay a bit to avoid consuming all the CPU. This is particularly * useful when reading from an unconnected FIFO. */ msleep( INPUT_ERROR_SLEEP ); } p_sys->i_nb_reads++;#ifdef HAVE_SYS_STAT_H if( p_access->info.i_size != 0 && (p_sys->i_nb_reads % INPUT_FSTAT_NB_READS) == 0 ) { struct stat stat_info; int i_file = p_sys->i_index; if ( fstat( p_sys->fd, &stat_info ) == -1 ) { msg_Warn( p_access, "couldn't stat again the file (%s)", strerror(errno) ); } else if ( p_sys->file[i_file]->i_size != stat_info.st_size ) { p_access->info.i_size += (stat_info.st_size - p_sys->file[i_file]->i_size ); p_access->info.i_update |= INPUT_UPDATE_SIZE; } }#endif /* If we reached an EOF then switch to the next file in the list */ if ( i_ret == 0 && p_sys->i_index + 1 < p_sys->i_file ) { char *psz_name = p_sys->file[++p_sys->i_index]->psz_name; p_sys->fd_backup = p_sys->fd; msg_Dbg( p_access, "opening file `%s'", psz_name ); if ( _OpenFile( p_access, psz_name ) ) { p_sys->fd = p_sys->fd_backup; return 0; } close( p_sys->fd_backup ); /* We have to read some data */ return Read( p_access, p_buffer, i_len ); } if( i_ret > 0 ) p_access->info.i_pos += i_ret; else if( i_ret == 0 ) p_access->info.b_eof = VLC_TRUE; return i_ret;}/***************************************************************************** * Seek: seek to a specific location in a file *****************************************************************************/static int Seek( access_t *p_access, int64_t i_pos ){ access_sys_t *p_sys = p_access->p_sys; int64_t i_size = 0; /* Check which file we need to access */ if( p_sys->i_file > 1 ) { int i; char *psz_name; p_sys->fd_backup = p_sys->fd; for( i = 0; i < p_sys->i_file - 1; i++ ) { if( i_pos < p_sys->file[i]->i_size + i_size ) break; i_size += p_sys->file[i]->i_size; } psz_name = p_sys->file[i]->psz_name; msg_Dbg( p_access, "opening file `%s'", psz_name ); if ( i != p_sys->i_index && !_OpenFile( p_access, psz_name ) ) { /* Close old file */ close( p_sys->fd_backup ); p_sys->i_index = i; } else { p_sys->fd = p_sys->fd_backup; } } lseek( p_sys->fd, i_pos - i_size, SEEK_SET ); p_access->info.i_pos = i_pos; if( p_access->info.i_size < p_access->info.i_pos ) { msg_Err( p_access, "seeking too far" ); p_access->info.i_pos = p_access->info.i_size; } else if( p_access->info.i_pos < 0 ) { msg_Err( p_access, "seeking too early" ); p_access->info.i_pos = 0; } /* Reset eof */ p_access->info.b_eof = VLC_FALSE; /* FIXME */ return VLC_SUCCESS;}/***************************************************************************** * Control: *****************************************************************************/static int Control( access_t *p_access, int i_query, va_list args ){ access_sys_t *p_sys = p_access->p_sys; vlc_bool_t *pb_bool; int *pi_int; int64_t *pi_64; switch( i_query ) { /* */ case ACCESS_CAN_SEEK: case ACCESS_CAN_FASTSEEK: pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* ); *pb_bool = p_sys->b_seekable; break; case ACCESS_CAN_PAUSE: case ACCESS_CAN_CONTROL_PACE: pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* ); *pb_bool = p_sys->b_pace_control; break; /* */ case ACCESS_GET_MTU: pi_int = (int*)va_arg( args, int * ); *pi_int = 0; break; case ACCESS_GET_PTS_DELAY: pi_64 = (int64_t*)va_arg( args, int64_t * ); *pi_64 = var_GetInteger( p_access, "file-caching" ) * I64C(1000); break; /* */ case ACCESS_SET_PAUSE_STATE: /* Nothing to do */ break; case ACCESS_GET_TITLE_INFO: case ACCESS_SET_TITLE: case ACCESS_SET_SEEKPOINT: case ACCESS_SET_PRIVATE_ID_STATE: case ACCESS_GET_META: return VLC_EGENERIC; default: msg_Warn( p_access, "unimplemented query in control" ); return VLC_EGENERIC; } return VLC_SUCCESS;}/***************************************************************************** * OpenFile: Opens a specific file *****************************************************************************/static int _OpenFile( access_t * p_access, char * psz_name ){ access_sys_t *p_sys = p_access->p_sys;#ifdef UNDER_CE p_sys->fd = fopen( psz_name, "rb" ); if ( !p_sys->fd ) { msg_Err( p_access, "cannot open file %s", psz_name ); return VLC_EGENERIC; } fseek( p_sys->fd, 0, SEEK_END ); p_access->info.i_size = ftell( p_sys->fd ); p_access->info.i_update |= INPUT_UPDATE_SIZE; fseek( p_sys->fd, 0, SEEK_SET );#else p_sys->fd = open( psz_name, O_NONBLOCK /*| O_LARGEFILE*/ ); if ( p_sys->fd == -1 ) { msg_Err( p_access, "cannot open file %s (%s)", psz_name, strerror(errno) ); return VLC_EGENERIC; }#endif return VLC_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -